| 1 |
// |reftest| module |
| 2 |
// Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
/*--- |
| 5 |
description: Modules have distinct environment records |
| 6 |
esid: sec-moduledeclarationinstantiation |
| 7 |
info: | |
| 8 |
[...] |
| 9 |
6. Let env be NewModuleEnvironment(realm.[[GlobalEnv]]). |
| 10 |
7. Set module.[[Environment]] to env. |
| 11 |
[...] |
| 12 |
|
| 13 |
8.1.2.6 NewModuleEnvironment (E) |
| 14 |
|
| 15 |
1. Let env be a new Lexical Environment. |
| 16 |
[...] |
| 17 |
flags: [module] |
| 18 |
features: [generators] |
| 19 |
---*/ |
| 20 |
|
| 21 |
import './instn-uniq-env-rec-other_FIXTURE.js' |
| 22 |
var first = 1; |
| 23 |
let second = 2; |
| 24 |
const third = 3; |
| 25 |
class fourth {} |
| 26 |
function fifth() { return 'fifth'; } |
| 27 |
function* sixth() { return 'sixth'; } |
| 28 |
|
| 29 |
assert.sameValue(first, 1); |
| 30 |
assert.sameValue(second, 2); |
| 31 |
assert.sameValue(third, 3); |
| 32 |
assert.sameValue(typeof fourth, 'function', 'class declaration'); |
| 33 |
assert.sameValue(typeof fifth, 'function', 'function declaration'); |
| 34 |
assert.sameValue(fifth(), 'fifth'); |
| 35 |
assert.sameValue(typeof sixth, 'function', 'generator function declaration'); |
| 36 |
assert.sameValue(sixth().next().value, 'sixth'); |
| 37 |
|
| 38 |
// Two separate mechanisms are required to ensure that no binding has been |
| 39 |
// created for a given identifier. A "bare" reference should produce a |
| 40 |
// ReferenceError for non-existent bindings and uninitialized bindings. A |
| 41 |
// reference through the `typeof` operator should succeed for non-existent |
| 42 |
// bindings and initialized bindings. Only non-existent bindings satisfy both |
| 43 |
// tests. |
| 44 |
typeof seventh; |
| 45 |
assert.throws(ReferenceError, function() { |
| 46 |
seventh; |
| 47 |
}); |
| 48 |
|
| 49 |
typeof eight; |
| 50 |
assert.throws(ReferenceError, function() { |
| 51 |
eighth; |
| 52 |
}); |
| 53 |
|
| 54 |
typeof ninth; |
| 55 |
assert.throws(ReferenceError, function() { |
| 56 |
ninth; |
| 57 |
}); |
| 58 |
|
| 59 |
typeof tenth; |
| 60 |
assert.throws(ReferenceError, function() { |
| 61 |
tenth; |
| 62 |
}); |
| 63 |
|
| 64 |
typeof eleventh; |
| 65 |
assert.throws(ReferenceError, function() { |
| 66 |
eleventh; |
| 67 |
}); |
| 68 |
|
| 69 |
typeof twelfth; |
| 70 |
assert.throws(ReferenceError, function() { |
| 71 |
twelfth; |
| 72 |
}); |
| 73 |
|
| 74 |
reportCompare(0, 0); |