diff --git a/test/language/module-code/instn-iee-bndng-cls.js b/test/language/module-code/instn-iee-bndng-cls.js new file mode 100644 index 0000000000000000000000000000000000000000..07461cc0c32fc034cd3de55e92dd9e6ae68ab172 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-cls.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of indirectly-exported `class` binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof B; +}, 'binding is created but not initialized'); + +import { B } from './instn-iee-bndng-cls_.js'; +export class A {} diff --git a/test/language/module-code/instn-iee-bndng-cls_.js b/test/language/module-code/instn-iee-bndng-cls_.js new file mode 100644 index 0000000000000000000000000000000000000000..c32dc3bd5bda2b8e95b3dfe81d2a0a54c16504b5 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-cls_.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { A as B } from './instn-iee-bndng-cls.js'; + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ImportName: +assert.throws(ReferenceError, function() { + A; +}); +assert.sameValue(typeof A, 'undefined'); + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ExportName: +assert.throws(ReferenceError, function() { + B; +}); +assert.sameValue(typeof B, 'undefined'); diff --git a/test/language/module-code/instn-iee-bndng-const.js b/test/language/module-code/instn-iee-bndng-const.js new file mode 100644 index 0000000000000000000000000000000000000000..11cc633a5a74536581ecc24071216588f3a2d039 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-const.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of indirectly-exported `const` binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + 1. Perform ! envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof y; +}, 'binding is created but not initialized'); + +import { y } from './instn-iee-bndng-const_.js'; +export const x = null; diff --git a/test/language/module-code/instn-iee-bndng-const_.js b/test/language/module-code/instn-iee-bndng-const_.js new file mode 100644 index 0000000000000000000000000000000000000000..1cb195a07344fad344ffbb66bac0b19a00819e74 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-const_.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { x as y } from './instn-iee-bndng-const.js'; + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ImportName: +assert.throws(ReferenceError, function() { + x; +}); +assert.sameValue(typeof x, 'undefined'); + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ExportName: +assert.throws(ReferenceError, function() { + y; +}); +assert.sameValue(typeof y, 'undefined'); diff --git a/test/language/module-code/instn-iee-bndng-fun.js b/test/language/module-code/instn-iee-bndng-fun.js new file mode 100644 index 0000000000000000000000000000000000000000..1b2f761bd65e7892345f88709c61dc60baf55181 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-fun.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of indirectly-exported function binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.sameValue( + f2(), + 77, + 'binding is initialized to function value prior to module evaluation' +); + +assert.throws(TypeError, function() { + f2 = null; +}, 'binding rejects assignment'); + +assert.sameValue(f2(), 77, 'binding value is immutable'); + +import { f2 } from './instn-iee-bndng-fun_.js'; +export function f() { return 77; } diff --git a/test/language/module-code/instn-iee-bndng-fun_.js b/test/language/module-code/instn-iee-bndng-fun_.js new file mode 100644 index 0000000000000000000000000000000000000000..fb941814ba20a4a66ae8eeadd0ae2f02d93dfa8f --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-fun_.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { f as f2 } from './instn-iee-bndng-fun.js'; + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ImportName: +assert.throws(ReferenceError, function() { + f; +}); +assert.sameValue(typeof f, 'undefined'); + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ExportName: +assert.throws(ReferenceError, function() { + f2; +}); +assert.sameValue(typeof f2, 'undefined'); diff --git a/test/language/module-code/instn-iee-bndng-gen.js b/test/language/module-code/instn-iee-bndng-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..df3089f879926e4b3842a3661afd40aba1bfd240 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-gen.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of indirectly-exported generator function + binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.sameValue( + g2().next().value, + 455, + 'binding is initialized to function value prior to module evaluation' +); + +assert.throws(TypeError, function() { + g2 = null; +}); + +assert.sameValue(g2().next().value, 455, 'binding value is immutable'); + +import { g2 } from './instn-iee-bndng-gen_.js'; +export function* g () { return 455; } diff --git a/test/language/module-code/instn-iee-bndng-gen_.js b/test/language/module-code/instn-iee-bndng-gen_.js new file mode 100644 index 0000000000000000000000000000000000000000..8e06c457dd9ad73586075e3db37ab5b0bda84866 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-gen_.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { g as g2 } from './instn-iee-bndng-gen.js'; + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ImportName: +assert.throws(ReferenceError, function() { + g; +}); +assert.sameValue(typeof g, 'undefined'); + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ExportName: +assert.throws(ReferenceError, function() { + g2; +}); +assert.sameValue(typeof g2, 'undefined'); diff --git a/test/language/module-code/instn-iee-bndng-let.js b/test/language/module-code/instn-iee-bndng-let.js new file mode 100644 index 0000000000000000000000000000000000000000..2e3c7f3ab4dfabfba5d1148f27217f316524c220 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-let.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of indirectly-exported `let` binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof y; +}, 'binding is created but not initialized'); + +import { y } from './instn-iee-bndng-let_.js'; +export let x; diff --git a/test/language/module-code/instn-iee-bndng-let_.js b/test/language/module-code/instn-iee-bndng-let_.js new file mode 100644 index 0000000000000000000000000000000000000000..bfe3d7c51030f2af2664c4399583c6c4bc0cbb40 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-let_.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { x as y } from './instn-iee-bndng-let.js'; + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ImportName: +assert.throws(ReferenceError, function() { + x; +}); +assert.sameValue(typeof x, 'undefined'); + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ExportName: +assert.throws(ReferenceError, function() { + y; +}); +assert.sameValue(typeof y, 'undefined'); diff --git a/test/language/module-code/instn-iee-bndng-var.js b/test/language/module-code/instn-iee-bndng-var.js new file mode 100644 index 0000000000000000000000000000000000000000..762d0603c4fdbe1270719b3f4967a388573e7493 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-var.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of indirectly-exported `var` binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.sameValue( + y, + undefined, + 'binding is initialized to `undefined` prior to module evaulation' +); + +assert.throws(TypeError, function() { + y = null; +}, 'binding rejects assignment'); + +assert.sameValue(y, undefined, 'binding value is immutable'); + +import { y } from './instn-iee-bndng-var_.js'; +export var x = 99; diff --git a/test/language/module-code/instn-iee-bndng-var_.js b/test/language/module-code/instn-iee-bndng-var_.js new file mode 100644 index 0000000000000000000000000000000000000000..5cbe15a99f6f45c32dbb8c556706f5bd813df568 --- /dev/null +++ b/test/language/module-code/instn-iee-bndng-var_.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { x as y } from './instn-iee-bndng-var.js'; + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ImportName: +assert.throws(ReferenceError, function() { + x; +}); +assert.sameValue(typeof x, 'undefined'); + +// Taken together, the following two assertions demonstrate that there is no +// entry in the environment record for ExportName: +assert.throws(ReferenceError, function() { + y; +}); +assert.sameValue(typeof y, 'undefined'); diff --git a/test/language/module-code/instn-iee-err-ambiguous-1_.js b/test/language/module-code/instn-iee-err-ambiguous-1_.js new file mode 100644 index 0000000000000000000000000000000000000000..896bdff50a2e658637ae5144e883a22a8ac6c84c --- /dev/null +++ b/test/language/module-code/instn-iee-err-ambiguous-1_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var x; diff --git a/test/language/module-code/instn-iee-err-ambiguous-2_.js b/test/language/module-code/instn-iee-err-ambiguous-2_.js new file mode 100644 index 0000000000000000000000000000000000000000..896bdff50a2e658637ae5144e883a22a8ac6c84c --- /dev/null +++ b/test/language/module-code/instn-iee-err-ambiguous-2_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var x; diff --git a/test/language/module-code/instn-iee-err-ambiguous-as.js b/test/language/module-code/instn-iee-err-ambiguous-as.js new file mode 100644 index 0000000000000000000000000000000000000000..b231b3282bdea1c1329843f4d756cfe344d40579 --- /dev/null +++ b/test/language/module-code/instn-iee-err-ambiguous-as.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: IndirectExportEntries validation - ambiguous imported bindings +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + [...] + + 15.2.1.16.3 ResolveExport + + [...] + 9. Let starResolution be null. + 10. For each ExportEntry Record e in module.[[StarExportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + e.[[ModuleRequest]]). + b. Let resolution be ? importedModule.ResolveExport(exportName, + resolveSet, exportStarSet). + c. If resolution is "ambiguous", return "ambiguous". + d. If resolution is not null, then + i. If starResolution is null, let starResolution be resolution. + ii. Else, + 1. Assert: there is more than one * import that includes the + requested name. + 2. If resolution.[[Module]] and starResolution.[[Module]] are + not the same Module Record or + SameValue(resolution.[[BindingName]], + starResolution.[[BindingName]]) is false, return "ambiguous". +negative: SyntaxError +flags: [module] +---*/ + +export { x as y } from './instn-iee-err-ambiguous_.js'; diff --git a/test/language/module-code/instn-iee-err-ambiguous.js b/test/language/module-code/instn-iee-err-ambiguous.js new file mode 100644 index 0000000000000000000000000000000000000000..d3d1337440dea07751290ae8072fab9a952923c0 --- /dev/null +++ b/test/language/module-code/instn-iee-err-ambiguous.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: IndirectExportEntries validation - ambiguous imported bindings +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + [...] + + 15.2.1.16.3 ResolveExport + + [...] + 9. Let starResolution be null. + 10. For each ExportEntry Record e in module.[[StarExportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + e.[[ModuleRequest]]). + b. Let resolution be ? importedModule.ResolveExport(exportName, + resolveSet, exportStarSet). + c. If resolution is "ambiguous", return "ambiguous". + d. If resolution is not null, then + i. If starResolution is null, let starResolution be resolution. + ii. Else, + 1. Assert: there is more than one * import that includes the + requested name. + 2. If resolution.[[Module]] and starResolution.[[Module]] are + not the same Module Record or + SameValue(resolution.[[BindingName]], + starResolution.[[BindingName]]) is false, return "ambiguous". +negative: SyntaxError +flags: [module] +---*/ + +export { x } from './instn-iee-err-ambiguous_.js'; diff --git a/test/language/module-code/instn-iee-err-ambiguous_.js b/test/language/module-code/instn-iee-err-ambiguous_.js new file mode 100644 index 0000000000000000000000000000000000000000..6984d00947e81c0657d9e6381dd65cc000f62595 --- /dev/null +++ b/test/language/module-code/instn-iee-err-ambiguous_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-iee-err-ambiguous-1_.js'; +export * from './instn-iee-err-ambiguous-2_.js'; diff --git a/test/language/module-code/instn-iee-err-circular-as.js b/test/language/module-code/instn-iee-err-circular-as.js new file mode 100644 index 0000000000000000000000000000000000000000..28d0396ec097d7a159a23bfbab58d2e506896520 --- /dev/null +++ b/test/language/module-code/instn-iee-err-circular-as.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: IndirectExportEntries validation - circular imported bindings +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + [...] + + 15.2.1.16.3 ResolveExport + + [...] + 2. For each Record {[[Module]], [[ExportName]]} r in resolveSet, do: + a. If module and r.[[Module]] are the same Module Record and + SameValue(exportName, r.[[ExportName]]) is true, then + i. Assert: this is a circular import request. + ii. Return null. +negative: SyntaxError +flags: [module] +---*/ + +export { x as y } from './instn-iee-err-circular_.js'; diff --git a/test/language/module-code/instn-iee-err-circular.js b/test/language/module-code/instn-iee-err-circular.js new file mode 100644 index 0000000000000000000000000000000000000000..5336509498334e5d34c2724db05833dfc3c79fa6 --- /dev/null +++ b/test/language/module-code/instn-iee-err-circular.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: IndirectExportEntries validation - circular imported bindings +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + [...] + + 15.2.1.16.3 ResolveExport + + [...] + 2. For each Record {[[Module]], [[ExportName]]} r in resolveSet, do: + a. If module and r.[[Module]] are the same Module Record and + SameValue(exportName, r.[[ExportName]]) is true, then + i. Assert: this is a circular import request. + ii. Return null. +negative: SyntaxError +flags: [module] +---*/ + +export { x } from './instn-iee-err-circular_.js'; diff --git a/test/language/module-code/instn-iee-err-circular_.js b/test/language/module-code/instn-iee-err-circular_.js new file mode 100644 index 0000000000000000000000000000000000000000..3d7fcb9634eb698cc2bf0fbabb9c110b39bbb6cd --- /dev/null +++ b/test/language/module-code/instn-iee-err-circular_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { x } from './instn-iee-err-circular.js'; diff --git a/test/language/module-code/instn-iee-err-dflt-thru-star-as.js b/test/language/module-code/instn-iee-err-dflt-thru-star-as.js new file mode 100644 index 0000000000000000000000000000000000000000..cfcad271b76d355b8fca37bf82522ac4baf1de65 --- /dev/null +++ b/test/language/module-code/instn-iee-err-dflt-thru-star-as.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: IndirectExportEntries validation - default not found (excluding *) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + [...] + + 15.2.1.16.3 ResolveExport + + [...] + 6. If SameValue(exportName, "default") is true, then + a. Assert: A default export was not explicitly defined by this module. + b. Throw a SyntaxError exception. + c. NOTE A default export cannot be provided by an export *. +negative: SyntaxError +flags: [module] +---*/ + +export { default as x } from './instn-iee-err-dflt-thru-star-int_.js'; diff --git a/test/language/module-code/instn-iee-err-dflt-thru-star-dflt_.js b/test/language/module-code/instn-iee-err-dflt-thru-star-dflt_.js new file mode 100644 index 0000000000000000000000000000000000000000..b59a4bf511012d6ed54a30a97cb513dbc1cc8885 --- /dev/null +++ b/test/language/module-code/instn-iee-err-dflt-thru-star-dflt_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var x; +export { x as default }; diff --git a/test/language/module-code/instn-iee-err-dflt-thru-star-int_.js b/test/language/module-code/instn-iee-err-dflt-thru-star-int_.js new file mode 100644 index 0000000000000000000000000000000000000000..025035eba7aa94a97ab5beefb004d761b832464c --- /dev/null +++ b/test/language/module-code/instn-iee-err-dflt-thru-star-int_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-iee-err-dflt-thru-star-dflt_.js'; diff --git a/test/language/module-code/instn-iee-err-dflt-thru-star.js b/test/language/module-code/instn-iee-err-dflt-thru-star.js new file mode 100644 index 0000000000000000000000000000000000000000..45da1210ca6e32bd906e88c67494e3b49a92079f --- /dev/null +++ b/test/language/module-code/instn-iee-err-dflt-thru-star.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: IndirectExportEntries validation - default not found (excluding *) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + [...] + + 15.2.1.16.3 ResolveExport + + [...] + 6. If SameValue(exportName, "default") is true, then + a. Assert: A default export was not explicitly defined by this module. + b. Throw a SyntaxError exception. + c. NOTE A default export cannot be provided by an export *. +negative: SyntaxError +flags: [module] +---*/ + +export { default } from './instn-iee-err-dflt-thru-star-int_.js'; diff --git a/test/language/module-code/instn-iee-err-not-found-as.js b/test/language/module-code/instn-iee-err-not-found-as.js new file mode 100644 index 0000000000000000000000000000000000000000..d612a35cc9ba9adab2cfef0fb455456463434f7f --- /dev/null +++ b/test/language/module-code/instn-iee-err-not-found-as.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: IndirectExportEntries validation - undefined imported bindings +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + [...] + + 15.2.1.16.3 ResolveExport + + [...] + 9. Let starResolution be null. + 10. For each ExportEntry Record e in module.[[StarExportEntries]], do + [...] + 11. Return starResolution. +negative: SyntaxError +flags: [module] +---*/ + +export { x as y } from './instn-iee-err-not-found-empty_.js'; diff --git a/test/language/module-code/instn-iee-err-not-found-empty_.js b/test/language/module-code/instn-iee-err-not-found-empty_.js new file mode 100644 index 0000000000000000000000000000000000000000..e46c626cf4c891ec4017bc2ab2281b9114c22e91 --- /dev/null +++ b/test/language/module-code/instn-iee-err-not-found-empty_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +; diff --git a/test/language/module-code/instn-iee-err-not-found.js b/test/language/module-code/instn-iee-err-not-found.js new file mode 100644 index 0000000000000000000000000000000000000000..94f86463963690d095d4c25e46754e5d8797a830 --- /dev/null +++ b/test/language/module-code/instn-iee-err-not-found.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: IndirectExportEntries validation - undefined imported bindings +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + [...] + + 15.2.1.16.3 ResolveExport + + [...] + 9. Let starResolution be null. + 10. For each ExportEntry Record e in module.[[StarExportEntries]], do + [...] + 11. Return starResolution. +negative: SyntaxError +flags: [module] +---*/ + +export { x } from './instn-iee-err-not-found-empty_.js'; diff --git a/test/language/module-code/instn-iee-iee-cycle-2_.js b/test/language/module-code/instn-iee-iee-cycle-2_.js new file mode 100644 index 0000000000000000000000000000000000000000..e8e4e71bdcf5a1c50fa4b2e9522a673edc4883b9 --- /dev/null +++ b/test/language/module-code/instn-iee-iee-cycle-2_.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { b as a } from './instn-iee-iee-cycle.js'; +export { d as c } from './instn-iee-iee-cycle.js'; +export { f as e } from './instn-iee-iee-cycle.js'; +export { h as g } from './instn-iee-iee-cycle.js'; +export { j as i } from './instn-iee-iee-cycle.js'; +export { l as k } from './instn-iee-iee-cycle.js'; +export { n as m } from './instn-iee-iee-cycle.js'; +export { p as o } from './instn-iee-iee-cycle.js'; +export { r as q } from './instn-iee-iee-cycle.js'; +export { t as s } from './instn-iee-iee-cycle.js'; +export { v as u } from './instn-iee-iee-cycle.js'; +export { x as w } from './instn-iee-iee-cycle.js'; +export { z as y } from './instn-iee-iee-cycle.js'; diff --git a/test/language/module-code/instn-iee-iee-cycle.js b/test/language/module-code/instn-iee-iee-cycle.js new file mode 100644 index 0000000000000000000000000000000000000000..9607277b7900f45e2aa3e657b9eb7dee87c8d59f --- /dev/null +++ b/test/language/module-code/instn-iee-iee-cycle.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + There are no restrictions on the number of cycles during module traversal + during indirect export resolution, given unique export names. +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + + 15.2.1.16.3 ResolveExport( exportName, resolveSet, exportStarSet ) + + 2. For each Record {[[Module]], [[ExportName]]} r in resolveSet, do: + a. If module and r.[[Module]] are the same Module Record and + SameValue(exportName, r.[[ExportName]]) is true, then + i. Assert: this is a circular import request. + ii. Return null. + 3. Append the Record {[[Module]]: module, [[ExportName]]: exportName} to resolveSet. + [...] + 5. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. If SameValue(exportName, e.[[ExportName]]) is true, then + i. Assert: module imports a specific binding for this export. + ii. Let importedModule be ? HostResolveImportedModule(module, + e.[[ModuleRequest]]). + iii. Let indirectResolution be ? + importedModule.ResolveExport(e.[[ImportName]], resolveSet, + exportStarSet). + iv. If indirectResolution is not null, return indirectResolution. +flags: [module] +---*/ + +export { a } from './instn-iee-iee-cycle-2_.js'; +export { c as b } from './instn-iee-iee-cycle-2_.js'; +export { e as d } from './instn-iee-iee-cycle-2_.js'; +export { g as f } from './instn-iee-iee-cycle-2_.js'; +export { i as h } from './instn-iee-iee-cycle-2_.js'; +export { k as j } from './instn-iee-iee-cycle-2_.js'; +export { m as l } from './instn-iee-iee-cycle-2_.js'; +export { o as n } from './instn-iee-iee-cycle-2_.js'; +export { q as p } from './instn-iee-iee-cycle-2_.js'; +export { s as r } from './instn-iee-iee-cycle-2_.js'; +export { u as t } from './instn-iee-iee-cycle-2_.js'; +export { w as v } from './instn-iee-iee-cycle-2_.js'; +export { y as x } from './instn-iee-iee-cycle-2_.js'; +export var z; diff --git a/test/language/module-code/instn-iee-star-cycle-2_.js b/test/language/module-code/instn-iee-star-cycle-2_.js new file mode 100644 index 0000000000000000000000000000000000000000..1a023020ca1a353ab6d1a5da277beaaf54b45f32 --- /dev/null +++ b/test/language/module-code/instn-iee-star-cycle-2_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-iee-star-cycle-indirect-x_.js'; diff --git a/test/language/module-code/instn-iee-star-cycle-indirect-x_.js b/test/language/module-code/instn-iee-star-cycle-indirect-x_.js new file mode 100644 index 0000000000000000000000000000000000000000..f729e844685dd4b2626d1b3dd365f85ae259d5a3 --- /dev/null +++ b/test/language/module-code/instn-iee-star-cycle-indirect-x_.js @@ -0,0 +1,7 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// This module should be visited exactly one time during resolution of the "x" +// binding. +export { y as x } from './instn-iee-star-cycle-2_.js'; +export var y = 45; diff --git a/test/language/module-code/instn-iee-star-cycle.js b/test/language/module-code/instn-iee-star-cycle.js new file mode 100644 index 0000000000000000000000000000000000000000..f6bbfa69f59e33690bab89202b3be7c0c922e255 --- /dev/null +++ b/test/language/module-code/instn-iee-star-cycle.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Modules are visited no more than one time when resolving bindings through + "star" exports. +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + b. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + + 15.2.1.16.3 ResolveExport( exportName, resolveSet, exportStarSet ) + + [...] + 7. If exportStarSet contains module, return null. + 8. Append module to exportStarSet. + [...] +negative: SyntaxError +flags: [module] +---*/ + +export { x } from './instn-iee-star-cycle-2_.js'; diff --git a/test/language/module-code/instn-iee-trlng-comma.js b/test/language/module-code/instn-iee-trlng-comma.js new file mode 100644 index 0000000000000000000000000000000000000000..bcbd7000e115be8b3c08bfaf4e02901447fe82d4 --- /dev/null +++ b/test/language/module-code/instn-iee-trlng-comma.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ExportsList in ExportDeclaration may include a trailing comma +esid: sec-moduledeclarationinstantiation +info: | + [...] + 9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « », « »). + [...] +flags: [module] +---*/ + +export { a , } from './instn-iee-trlng-comma_.js'; +export { a as b , } from './instn-iee-trlng-comma_.js'; + +import { a, b } from './instn-iee-trlng-comma.js'; + +assert.sameValue(a, 333, 'comma following named export'); +assert.sameValue(b, 333, 'comma following re-named export'); diff --git a/test/language/module-code/instn-iee-trlng-comma_.js b/test/language/module-code/instn-iee-trlng-comma_.js new file mode 100644 index 0000000000000000000000000000000000000000..6a70bc9d17c3eed47358307ede6c5388dd22d421 --- /dev/null +++ b/test/language/module-code/instn-iee-trlng-comma_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var a = 333; diff --git a/test/language/module-code/instn-local-bndng-cls.js b/test/language/module-code/instn-local-bndng-cls.js new file mode 100644 index 0000000000000000000000000000000000000000..96f221ed0f3e1522ae98b5837eef7776623d0b1c --- /dev/null +++ b/test/language/module-code/instn-local-bndng-cls.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Mutable bindings are created in the lexical environment record prior to + execution for class declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.throws(ReferenceError, function() { + typeof test262; +}, 'Binding is created but not initialized.'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +class test262 {} + +assert.sameValue(typeof test262, 'function'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +test262 = null; + +assert.sameValue(test262, null, 'binding is mutable'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), + undefined, + 'global binding is not effected by modification' +); diff --git a/test/language/module-code/instn-local-bndng-const.js b/test/language/module-code/instn-local-bndng-const.js new file mode 100644 index 0000000000000000000000000000000000000000..d7b63243327ea1ffc3b7173e9acd41fe94bec11d --- /dev/null +++ b/test/language/module-code/instn-local-bndng-const.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Mutable bindings are created in the lexical environment record prior to + execution for `const` declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + 1. Perform ! envRec.CreateImmutableBinding(dn, true). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.throws(ReferenceError, function() { + typeof test262; +}, 'Binding is created but not initialized.'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +const test262 = 23; + +assert.sameValue(test262, 23); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +assert.throws(TypeError, function() { + test262 = null; +}); + +assert.sameValue(test262, 23, 'binding is not mutable'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), + undefined, + 'global binding is not effected by attempts to modify' +); diff --git a/test/language/module-code/instn-local-bndng-export-cls.js b/test/language/module-code/instn-local-bndng-export-cls.js new file mode 100644 index 0000000000000000000000000000000000000000..13196cf5d1ac261eeee52c769f06e640fa29b701 --- /dev/null +++ b/test/language/module-code/instn-local-bndng-export-cls.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Binding is created and initialized to `undefined` for exported `class` + declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.throws(ReferenceError, function() { + typeof test262; +}, 'Binding is created but not initialized.'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +export class test262 {} diff --git a/test/language/module-code/instn-local-bndng-export-const.js b/test/language/module-code/instn-local-bndng-export-const.js new file mode 100644 index 0000000000000000000000000000000000000000..184405e4f9e0004f0a4d65191116c89c3b29931e --- /dev/null +++ b/test/language/module-code/instn-local-bndng-export-const.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Binding is created but not initialized for exported `const` statements +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.throws(ReferenceError, function() { + typeof test262; +}, 'Binding is created but not initialized.'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +export const test262 = 23; diff --git a/test/language/module-code/instn-local-bndng-export-fun.js b/test/language/module-code/instn-local-bndng-export-fun.js new file mode 100644 index 0000000000000000000000000000000000000000..6f40586228d286cb7fb8900474c7e1e36d1036b7 --- /dev/null +++ b/test/language/module-code/instn-local-bndng-export-fun.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Binding is created and initialized to `undefined` for exported function + declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.sameValue(test262(), 23, 'initialized value'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +test262 = null; + +assert.sameValue(test262, null, 'binding is mutable'); + +export function test262() { return 23; } diff --git a/test/language/module-code/instn-local-bndng-export-gen.js b/test/language/module-code/instn-local-bndng-export-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..bcb10b78a2f909de6976ff0748766dd69bfc15f6 --- /dev/null +++ b/test/language/module-code/instn-local-bndng-export-gen.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Binding is created and initialized to `undefined` for exported generator + function declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.sameValue(test262().next().value, 23, 'initialized value'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +test262 = null; + +assert.sameValue(test262, null, 'binding is mutable'); + +export function* test262() { return 23; } diff --git a/test/language/module-code/instn-local-bndng-export-let.js b/test/language/module-code/instn-local-bndng-export-let.js new file mode 100644 index 0000000000000000000000000000000000000000..fdc74b75540283a188bbb585fcc4950b34331b06 --- /dev/null +++ b/test/language/module-code/instn-local-bndng-export-let.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Binding is created but not initialized for exported `let` statements +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.throws(ReferenceError, function() { + typeof test262; +}, 'Binding is created but not initialized.'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +export let test262 = 23; diff --git a/test/language/module-code/instn-local-bndng-export-var.js b/test/language/module-code/instn-local-bndng-export-var.js new file mode 100644 index 0000000000000000000000000000000000000000..f5b84e35e939aa8c64e5f1ad111c8f6fb535e2f1 --- /dev/null +++ b/test/language/module-code/instn-local-bndng-export-var.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Binding is created and initialized to `undefined` for exported `var` + declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.sameValue(test262, undefined, 'initialized value'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +test262 = null; + +assert.sameValue(test262, null, 'binding is mutable'); + +export var test262 = 23; diff --git a/test/language/module-code/instn-local-bndng-for-dup.js b/test/language/module-code/instn-local-bndng-for-dup.js new file mode 100644 index 0000000000000000000000000000000000000000..64c3892e8767f18d74bb6524ae4133192c3fd3a9 --- /dev/null +++ b/test/language/module-code/instn-local-bndng-for-dup.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Only one attempt is made to create a binding for any number of variable + declarations within `for` statements +esid: sec-moduledeclarationinstantiation +info: | + [...] + 13. Let varDeclarations be the VarScopedDeclarations of code. + 14. Let declaredVarNames be a new empty List. + 15. For each element d in varDeclarations do + a. For each element dn of the BoundNames of d do + i. If dn is not an element of declaredVarNames, then + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] + 3. Append dn to declaredVarNames. + [...] +flags: [module] +---*/ + +for (var test262; false; ) {} +for (var test262; false; ) {} diff --git a/test/language/module-code/instn-local-bndng-for.js b/test/language/module-code/instn-local-bndng-for.js new file mode 100644 index 0000000000000000000000000000000000000000..6da2854b050abf1af8fd8d9a67e905a94a54762e --- /dev/null +++ b/test/language/module-code/instn-local-bndng-for.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Mutable bindings are initialized in the lexical environment record prior to + execution for variable declarations within `for` statements +esid: sec-moduledeclarationinstantiation +info: | + [...] + 13. Let varDeclarations be the VarScopedDeclarations of code. + 14. Let declaredVarNames be a new empty List. + 15. For each element d in varDeclarations do + a. For each element dn of the BoundNames of d do + i. If dn is not an element of declaredVarNames, then + 1. Perform ! envRec.CreateMutableBinding(dn, false). + 2. Call envRec.InitializeBinding(dn, undefined). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.sameValue(test262, undefined, 'value is initialized to `undefined`'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +for (var test262 = null; false; ) {} + +assert.sameValue(test262, null, 'binding is mutable'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), + undefined, + 'global binding is not effected by evaluation of declaration' +); diff --git a/test/language/module-code/instn-local-bndng-fun.js b/test/language/module-code/instn-local-bndng-fun.js new file mode 100644 index 0000000000000000000000000000000000000000..fd5c23e1b1967d93f621e56c863f913d9e9a481c --- /dev/null +++ b/test/language/module-code/instn-local-bndng-fun.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Mutable bindings are initialized in the lexical environment record prior to + execution for function declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + 1. Let fo be the result of performing InstantiateFunctionObject + for d with argument env. + 2. Call envRec.InitializeBinding(dn, fo). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.sameValue(typeof test262, 'function', 'function value is hoisted'); +assert.sameValue(test262(), 'test262', 'hoisted function value is correct'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +test262 = null; +assert.sameValue(test262, null, 'binding is mutable'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +function test262() { return 'test262'; } + +assert.sameValue( + test262, null, 'binding is not effected by evaluation of declaration' +); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), + undefined, + 'global binding is not effected by evaluation of declaration' +); diff --git a/test/language/module-code/instn-local-bndng-gen.js b/test/language/module-code/instn-local-bndng-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..0fa2c34e99b5bcc9dc1779bb35f7611014b8c9b5 --- /dev/null +++ b/test/language/module-code/instn-local-bndng-gen.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Mutable bindings are initialized in the lexical environment record prior to + execution for generator function declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 15. For each element d in varDeclarations do + a. For each element dn of the BoundNames of d do + i. If dn is not an element of declaredVarNames, then + 1. Perform ! envRec.CreateMutableBinding(dn, false). + 2. Call envRec.InitializeBinding(dn, undefined). + 3. Append dn to declaredVarNames. + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.sameValue( + typeof test262, 'function', 'generator function value is hoisted' +); +assert.sameValue( + test262().next().value, + 'test262', + 'hoisted generator function value is correct' +); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +test262 = null; +assert.sameValue(test262, null, 'binding is mutable'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +function* test262() { return 'test262'; } + +assert.sameValue( + test262, null, 'binding is not effected by evaluation of declaration' +); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), + undefined, + 'global binding is not effected by evaluation of declaration' +); diff --git a/test/language/module-code/instn-local-bndng-let.js b/test/language/module-code/instn-local-bndng-let.js new file mode 100644 index 0000000000000000000000000000000000000000..ec1ad20cca9732d50e76cb4a5b48d4a6f2b3a04a --- /dev/null +++ b/test/language/module-code/instn-local-bndng-let.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Mutable bindings are created in the lexical environment record prior to + execution for `let` declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.throws(ReferenceError, function() { + typeof test262; +}, 'Binding is created but not initialized.'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +let test262; + +assert.sameValue(test262, undefined); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +test262 = null; + +assert.sameValue(test262, null, 'binding is mutable'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), + undefined, + 'global binding is not effected by modification' +); diff --git a/test/language/module-code/instn-local-bndng-var-dup.js b/test/language/module-code/instn-local-bndng-var-dup.js new file mode 100644 index 0000000000000000000000000000000000000000..c3fbf3ae7312e5c0e557b8df50ac2f485c672b0e --- /dev/null +++ b/test/language/module-code/instn-local-bndng-var-dup.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Only one attempt is made to create a binding for any number of variable + declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 13. Let varDeclarations be the VarScopedDeclarations of code. + 14. Let declaredVarNames be a new empty List. + 15. For each element d in varDeclarations do + a. For each element dn of the BoundNames of d do + i. If dn is not an element of declaredVarNames, then + 1. Perform ! envRec.CreateMutableBinding(dn, false). + [...] + 3. Append dn to declaredVarNames. + [...] +flags: [module] +---*/ + +var test262; +var test262; diff --git a/test/language/module-code/instn-local-bndng-var.js b/test/language/module-code/instn-local-bndng-var.js new file mode 100644 index 0000000000000000000000000000000000000000..3ff9e2b980929a3310c054ad0290ba421ccce01b --- /dev/null +++ b/test/language/module-code/instn-local-bndng-var.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Mutable bindings are initialized in the lexical environment record prior to + execution for variable declarations +esid: sec-moduledeclarationinstantiation +info: | + [...] + 13. Let varDeclarations be the VarScopedDeclarations of code. + 14. Let declaredVarNames be a new empty List. + 15. For each element d in varDeclarations do + a. For each element dn of the BoundNames of d do + i. If dn is not an element of declaredVarNames, then + 1. Perform ! envRec.CreateMutableBinding(dn, false). + 2. Call envRec.InitializeBinding(dn, undefined). + 3. Append dn to declaredVarNames. + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +var global = fnGlobalObject(); + +assert.sameValue(test262, undefined, 'value is initialized to `undefined`'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), undefined +); + +var test262 = null; + +assert.sameValue(test262, null, 'binding is mutable'); +assert.sameValue( + Object.getOwnPropertyDescriptor(global, 'test262'), + undefined, + 'global binding is not effected by evaluation of declaration' +); diff --git a/test/language/module-code/instn-named-bndng-cls.js b/test/language/module-code/instn-named-bndng-cls.js new file mode 100644 index 0000000000000000000000000000000000000000..f19daf7b71ba00aff2e2b6ef06f7ee106dc18599 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-cls.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Imported binding reflects state of exported `class` binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof D; +}, 'binding is created but not initialized'); + +import { C as D } from './instn-named-bndng-cls.js'; +export class C {} diff --git a/test/language/module-code/instn-named-bndng-const.js b/test/language/module-code/instn-named-bndng-const.js new file mode 100644 index 0000000000000000000000000000000000000000..c334fb9b48734dff50ab11df4be9ed3572e513fe --- /dev/null +++ b/test/language/module-code/instn-named-bndng-const.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Imported binding reflects state of exported `const` binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + 1. Perform ! envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof y; +}, 'binding is created but not initialized'); + +import { x as y } from './instn-named-bndng-const.js'; +export const x = 23; diff --git a/test/language/module-code/instn-named-bndng-dflt-cls.js b/test/language/module-code/instn-named-bndng-dflt-cls.js new file mode 100644 index 0000000000000000000000000000000000000000..92cfdb567170259d5e56be3e5e1153a9b36bdf85 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-dflt-cls.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of exported default binding ("anonymous" + class declaration) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + 1. Let fo be the result of performing InstantiateFunctionObject + for d with argument env. + 2. Call envRec.InitializeBinding(dn, fo). + [...] + + 14.5 Class Definitions + + Syntax + + ClassDeclaration[Yield, Default]: + + class BindingIdentifier[?Yield] ClassTail[?Yield] + [+Default] class ClassTail[?Yield] +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof C; +}, 'Binding is created but not initialized.'); + +export default class {}; +import C from './instn-named-bndng-dflt-cls.js'; diff --git a/test/language/module-code/instn-named-bndng-dflt-expr.js b/test/language/module-code/instn-named-bndng-dflt-expr.js new file mode 100644 index 0000000000000000000000000000000000000000..b6e2be52a406f3af7f223731305451bdf9a9b917 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-dflt-expr.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: + Imported binding reflects state of exported default binding (expressions) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof dflt; +}, 'binding is created but not initialized'); + +import dflt from './instn-named-bndng-dflt-expr.js'; +export default (function() {}); diff --git a/test/language/module-code/instn-named-bndng-dflt-fun-anon.js b/test/language/module-code/instn-named-bndng-dflt-fun-anon.js new file mode 100644 index 0000000000000000000000000000000000000000..6bf822ca7d4f5ec7e7dbd94e80ab9ad676e968fe --- /dev/null +++ b/test/language/module-code/instn-named-bndng-dflt-fun-anon.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of exported default binding ("anonymous" + function declaration) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + 1. Let fo be the result of performing InstantiateFunctionObject + for d with argument env. + 2. Call envRec.InitializeBinding(dn, fo). + [...] + + 14.1.20 Runtime Semantics: InstantiateFunctionObject + + FunctionDeclaration : function ( FormalParameters ) { FunctionBody } + + 1. If the function code for FunctionDeclaration is strict mode code, let + strict be true. Otherwise let strict be false. + 2. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody, scope, + strict). + 3. Perform MakeConstructor(F). + 4. Perform SetFunctionName(F, "default"). + 5. Return F. + + 14.1 Function Definitions + + Syntax + + FunctionDeclaration[Yield, Default] : + + function BindingIdentifier[?Yield] ( FormalParameters ) { FunctionBody } + [+Default] function ( FormalParameters ) { FunctionBody } +flags: [module] +---*/ + +assert.sameValue(f(), 23, 'function value is hoisted'); +assert.sameValue(f.name, 'default', 'correct name is assigned'); + +import f from './instn-named-bndng-dflt-fun-anon.js'; +export default function() { return 23; }; diff --git a/test/language/module-code/instn-named-bndng-dflt-fun-named.js b/test/language/module-code/instn-named-bndng-dflt-fun-named.js new file mode 100644 index 0000000000000000000000000000000000000000..193ae531a2f061a696ee295c854ff9fb7c0aa765 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-dflt-fun-named.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of exported default binding ("named" + function declaration) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + 1. Let fo be the result of performing InstantiateFunctionObject + for d with argument env. + 2. Call envRec.InitializeBinding(dn, fo). + [...] + + 14.1.20 Runtime Semantics: InstantiateFunctionObject + + FunctionDeclaration : function ( FormalParameters ) { FunctionBody } + + 1. If the function code for FunctionDeclaration is strict mode code, let + strict be true. Otherwise let strict be false. + 2. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody, scope, + strict). + 3. Perform MakeConstructor(F). + 4. Perform SetFunctionName(F, "default"). + 5. Return F. + + 14.1 Function Definitions + + Syntax + + FunctionDeclaration[Yield, Default] : + + function BindingIdentifier[?Yield] ( FormalParameters ) { FunctionBody } + [+Default] function ( FormalParameters ) { FunctionBody } +flags: [module] +---*/ + +assert.sameValue(f(), 23, 'function value is hoisted'); +assert.sameValue(f.name, 'fName', 'correct name is assigned'); + +import f from './instn-named-bndng-dflt-fun-named.js'; +export default function fName() { return 23; }; diff --git a/test/language/module-code/instn-named-bndng-dflt-gen-anon.js b/test/language/module-code/instn-named-bndng-dflt-gen-anon.js new file mode 100644 index 0000000000000000000000000000000000000000..e17ea4829bdc97b4091f3eb97d426ce6eb6e2139 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-dflt-gen-anon.js @@ -0,0 +1,52 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of exported default binding ("anonymous" + generator function declaration) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + 1. Let fo be the result of performing InstantiateFunctionObject + for d with argument env. + 2. Call envRec.InitializeBinding(dn, fo). + [...] + + 14.4.12 Runtime Semantics: InstantiateFunctionObject + + GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } + + 1. If the function code for GeneratorDeclaration is strict mode code, let + strict be true. Otherwise let strict be false. + 2. Let F be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + 3. Let prototype be ObjectCreate(%GeneratorPrototype%). + 4. Perform DefinePropertyOrThrow(F, "prototype", + PropertyDescriptor{[[Value]]: prototype, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: false}). + 5. Perform SetFunctionName(F, "default"). + 6. Return F. + + 14.4 Generator Function Definitions + + Syntax + + GeneratorDeclaration[Yield, Default] : + function * BindingIdentifier[?Yield] ( FormalParameters[Yield] ) { GeneratorBody } + [+Default] function * ( FormalParameters[Yield] ) { GeneratorBody } +flags: [module] +---*/ + +assert.sameValue(g().next().value, 23, 'generator function value is hoisted'); +assert.sameValue(g.name, 'default', 'correct name is assigned'); + +import g from './instn-named-bndng-dflt-gen-anon.js'; +export default function* () { return 23; }; diff --git a/test/language/module-code/instn-named-bndng-dflt-gen-named.js b/test/language/module-code/instn-named-bndng-dflt-gen-named.js new file mode 100644 index 0000000000000000000000000000000000000000..060f72c730e48d9598605800153f0d962f206ee0 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-dflt-gen-named.js @@ -0,0 +1,52 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of exported default binding ("named" + generator function declaration) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + 1. Let fo be the result of performing InstantiateFunctionObject + for d with argument env. + 2. Call envRec.InitializeBinding(dn, fo). + [...] + + 14.4.12 Runtime Semantics: InstantiateFunctionObject + + GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } + + 1. If the function code for GeneratorDeclaration is strict mode code, let + strict be true. Otherwise let strict be false. + 2. Let F be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + 3. Let prototype be ObjectCreate(%GeneratorPrototype%). + 4. Perform DefinePropertyOrThrow(F, "prototype", + PropertyDescriptor{[[Value]]: prototype, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: false}). + 5. Perform SetFunctionName(F, "default"). + 6. Return F. + + 14.4 Generator Function Definitions + + Syntax + + GeneratorDeclaration[Yield, Default] : + function * BindingIdentifier[?Yield] ( FormalParameters[Yield] ) { GeneratorBody } + [+Default] function * ( FormalParameters[Yield] ) { GeneratorBody } +flags: [module] +---*/ + +assert.sameValue(g().next().value, 23, 'generator function value is hoisted'); +assert.sameValue(g.name, 'gName', 'correct name is assigned'); + +import g from './instn-named-bndng-dflt-gen-named.js'; +export default function* gName() { return 23; }; diff --git a/test/language/module-code/instn-named-bndng-dflt-named.js b/test/language/module-code/instn-named-bndng-dflt-named.js new file mode 100644 index 0000000000000000000000000000000000000000..fae2a6ae896d393cbb73a2f7d26f40b8168e194a --- /dev/null +++ b/test/language/module-code/instn-named-bndng-dflt-named.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + An ImportClause may contain both an ImportedDefaultBinding and NamedImports +esid: sec-imports +info: | + Syntax + + ImportClause: + ImportedDefaultBinding + NameSpaceImport + NamedImports + ImportedDefaultBinding , NameSpaceImport + ImportedDefaultBinding , NamedImports +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof x; +}); + +assert.sameValue(y, undefined); + +export default 3; +export var attr; +import x, { attr as y } from './instn-named-bndng-dflt-named.js'; diff --git a/test/language/module-code/instn-named-bndng-dflt-star.js b/test/language/module-code/instn-named-bndng-dflt-star.js new file mode 100644 index 0000000000000000000000000000000000000000..a31216d95bf3d86edba65fbdd527b760ec1bab36 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-dflt-star.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + An ImportClause may contain both an ImportedDefaultBinding and a + NameSpaceImport +esid: sec-imports +info: | + Syntax + + ImportClause: + ImportedDefaultBinding + NameSpaceImport + NamedImports + ImportedDefaultBinding , NameSpaceImport + ImportedDefaultBinding , NamedImports +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof x; +}); + +assert('attr' in ns); + +export default 3; +export var attr; +import x, * as ns from './instn-named-bndng-dflt-star.js'; diff --git a/test/language/module-code/instn-named-bndng-fun.js b/test/language/module-code/instn-named-bndng-fun.js new file mode 100644 index 0000000000000000000000000000000000000000..43685aa8d7add6b8424d89c669acb7b53e0cab75 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-fun.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Imported binding reflects state of exported function binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + 1. Perform ! envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + 1. Let fo be the result of performing InstantiateFunctionObject + for d with argument env. + 2. Call envRec.InitializeBinding(dn, fo). + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.sameValue( + f2(), + 23, + 'binding is initialized to function value prior to module evaluation' +); + +assert.throws(TypeError, function() { + f2 = null; +}, 'binding rejects assignment'); + +assert.sameValue(f2(), 23, 'binding value is immutable'); + +import { f as f2 } from './instn-named-bndng-fun.js'; +export function f() { return 23; } diff --git a/test/language/module-code/instn-named-bndng-gen.js b/test/language/module-code/instn-named-bndng-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..0917e664ac3516e9ba5f7942a5e1d30b43fedf85 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-gen.js @@ -0,0 +1,58 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of exported generator function binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + 1. Perform ! envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + 1. Let fo be the result of performing InstantiateFunctionObject + for d with argument env. + 2. Call envRec.InitializeBinding(dn, fo). + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.sameValue( + g2().next().value, + 23, + 'binding is initialized to function value prior to module evaluation' +); + +assert.throws(TypeError, function() { + g2 = null; +}, 'binding rejects assignment'); + +assert.sameValue(g2().next().value, 23, 'binding value is immutable'); + +import { g as g2 } from './instn-named-bndng-gen.js'; +export function* g() { return 23; } diff --git a/test/language/module-code/instn-named-bndng-let.js b/test/language/module-code/instn-named-bndng-let.js new file mode 100644 index 0000000000000000000000000000000000000000..9dc7b66dc985f633e1af789b6bb97b118e075788 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-let.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Imported binding reflects state of exported `const` binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 16. Let lexDeclarations be the LexicallyScopedDeclarations of code. + 17. For each element d in lexDeclarations do + a. For each element dn of the BoundNames of d do + i, If IsConstantDeclaration of d is true, then + 1. Perform ! envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ! envRec.CreateMutableBinding(dn, false). + iii. If d is a GeneratorDeclaration production or a + FunctionDeclaration production, then + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.throws(ReferenceError, function() { + typeof y; +}, 'binding is created but not initialized'); + +import { x as y } from './instn-named-bndng-let.js'; +export let x = 23; diff --git a/test/language/module-code/instn-named-bndng-trlng-comma.js b/test/language/module-code/instn-named-bndng-trlng-comma.js new file mode 100644 index 0000000000000000000000000000000000000000..d0a9daf214c5df71fc523bb5e0550cbebeeb0314 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-trlng-comma.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported binding reflects state of exported `var` binding when ImportsList + has a trailing comma +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 14. Let declaredVarNames be a new empty List. + 15. For each element d in varDeclarations do + a. For each element dn of the BoundNames of d do + i. If dn is not an element of declaredVarNames, then + 1. Perform ! envRec.CreateMutableBinding(dn, false). + 2. Call envRec.InitializeBinding(dn, undefined). + 3. Append dn to declaredVarNames. + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.sameValue( + y, + undefined, + 'binding is initialized to `undefined` prior to module evaulation' +); + +assert.throws(TypeError, function() { + y = null; +}, 'binding rejects assignment'); + +assert.sameValue(y, undefined, 'binding value is immutable'); + +import { x as y , } from './instn-named-bndng-trlng-comma.js'; +export var x = 23; diff --git a/test/language/module-code/instn-named-bndng-var.js b/test/language/module-code/instn-named-bndng-var.js new file mode 100644 index 0000000000000000000000000000000000000000..eff20f6104a75e0e3d679a6bd8a854ab417478d9 --- /dev/null +++ b/test/language/module-code/instn-named-bndng-var.js @@ -0,0 +1,52 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Imported binding reflects state of exported `var` binding +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + 14. Let declaredVarNames be a new empty List. + 15. For each element d in varDeclarations do + a. For each element dn of the BoundNames of d do + i. If dn is not an element of declaredVarNames, then + 1. Perform ! envRec.CreateMutableBinding(dn, false). + 2. Call envRec.InitializeBinding(dn, undefined). + 3. Append dn to declaredVarNames. + [...] + + 8.1.1.5.5 CreateImportBinding + + [...] + 5. Create an immutable indirect binding in envRec for N that references M + and N2 as its target binding and record that the binding is initialized. + 6. Return NormalCompletion(empty). +flags: [module] +---*/ + +assert.sameValue( + y, + undefined, + 'binding is initialized to `undefined` prior to module evaulation' +); + +assert.throws(TypeError, function() { + y = null; +}, 'binding rejects assignment'); + +assert.sameValue(y, undefined, 'binding value is immutable'); + +import { x as y } from './instn-named-bndng-var.js'; +export var x = 23; diff --git a/test/language/module-code/instn-named-err-ambiguous-1_.js b/test/language/module-code/instn-named-err-ambiguous-1_.js new file mode 100644 index 0000000000000000000000000000000000000000..896bdff50a2e658637ae5144e883a22a8ac6c84c --- /dev/null +++ b/test/language/module-code/instn-named-err-ambiguous-1_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var x; diff --git a/test/language/module-code/instn-named-err-ambiguous-2_.js b/test/language/module-code/instn-named-err-ambiguous-2_.js new file mode 100644 index 0000000000000000000000000000000000000000..896bdff50a2e658637ae5144e883a22a8ac6c84c --- /dev/null +++ b/test/language/module-code/instn-named-err-ambiguous-2_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var x; diff --git a/test/language/module-code/instn-named-err-ambiguous-as.js b/test/language/module-code/instn-named-err-ambiguous-as.js new file mode 100644 index 0000000000000000000000000000000000000000..6ab232a4d04fc2faa829a6a77a9b7507885ec998 --- /dev/null +++ b/test/language/module-code/instn-named-err-ambiguous-as.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Named import binding - resolution failure (ambiguous name) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + + 15.2.1.16.3 ResolveExport + + [...] + 9. Let starResolution be null. + 10. For each ExportEntry Record e in module.[[StarExportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + e.[[ModuleRequest]]). + b. Let resolution be ? importedModule.ResolveExport(exportName, + resolveSet, exportStarSet). + c. If resolution is "ambiguous", return "ambiguous". + d. If resolution is not null, then + i. If starResolution is null, let starResolution be resolution. + ii. Else, + 1. Assert: there is more than one * import that includes the + requested name. + 2. If resolution.[[Module]] and starResolution.[[Module]] are + not the same Module Record or + SameValue(resolution.[[BindingName]], + starResolution.[[BindingName]]) is false, return "ambiguous". +negative: SyntaxError +flags: [module] +---*/ + +import { x as y } from './instn-named-err-ambiguous_.js'; diff --git a/test/language/module-code/instn-named-err-ambiguous.js b/test/language/module-code/instn-named-err-ambiguous.js new file mode 100644 index 0000000000000000000000000000000000000000..0c53a94ea6e84a1e4b7cb2eab2727fcf282e1841 --- /dev/null +++ b/test/language/module-code/instn-named-err-ambiguous.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Named import binding - resolution failure (ambiguous name) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + + 15.2.1.16.3 ResolveExport + + [...] + 9. Let starResolution be null. + 10. For each ExportEntry Record e in module.[[StarExportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + e.[[ModuleRequest]]). + b. Let resolution be ? importedModule.ResolveExport(exportName, + resolveSet, exportStarSet). + c. If resolution is "ambiguous", return "ambiguous". + d. If resolution is not null, then + i. If starResolution is null, let starResolution be resolution. + ii. Else, + 1. Assert: there is more than one * import that includes the + requested name. + 2. If resolution.[[Module]] and starResolution.[[Module]] are + not the same Module Record or + SameValue(resolution.[[BindingName]], + starResolution.[[BindingName]]) is false, return "ambiguous". +negative: SyntaxError +flags: [module] +---*/ + +import { x } from './instn-named-err-ambiguous_.js'; diff --git a/test/language/module-code/instn-named-err-ambiguous_.js b/test/language/module-code/instn-named-err-ambiguous_.js new file mode 100644 index 0000000000000000000000000000000000000000..9cb1b46cfc3729292a17d93b49129d1f328dabe6 --- /dev/null +++ b/test/language/module-code/instn-named-err-ambiguous_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-named-err-ambiguous-1_.js'; +export * from './instn-named-err-ambiguous-2_.js'; diff --git a/test/language/module-code/instn-named-err-dflt-thru-star-as.js b/test/language/module-code/instn-named-err-dflt-thru-star-as.js new file mode 100644 index 0000000000000000000000000000000000000000..16fc554cd7923e6584ca2a61444776f0dfc875e3 --- /dev/null +++ b/test/language/module-code/instn-named-err-dflt-thru-star-as.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Named import binding - default not found (excluding *) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + + 15.2.1.16.3 ResolveExport + + [...] + 6. If SameValue(exportName, "default") is true, then + a. Assert: A default export was not explicitly defined by this module. + b. Throw a SyntaxError exception. + c. NOTE A default export cannot be provided by an export *. +negative: SyntaxError +flags: [module] +---*/ + +import { default as x } from './instn-named-err-dflt-thru-star-int_.js'; diff --git a/test/language/module-code/instn-named-err-dflt-thru-star-dflt.js b/test/language/module-code/instn-named-err-dflt-thru-star-dflt.js new file mode 100644 index 0000000000000000000000000000000000000000..1312a81bc43a8d9c2351d2b988773d7c87a72bbe --- /dev/null +++ b/test/language/module-code/instn-named-err-dflt-thru-star-dflt.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Named import binding - default not found (excluding *) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + + 15.2.1.16.3 ResolveExport + + [...] + 6. If SameValue(exportName, "default") is true, then + a. Assert: A default export was not explicitly defined by this module. + b. Throw a SyntaxError exception. + c. NOTE A default export cannot be provided by an export *. +negative: SyntaxError +flags: [module] +---*/ + +import x from './instn-named-err-dflt-thru-star-int_.js'; diff --git a/test/language/module-code/instn-named-err-dflt-thru-star-dflt_.js b/test/language/module-code/instn-named-err-dflt-thru-star-dflt_.js new file mode 100644 index 0000000000000000000000000000000000000000..b59a4bf511012d6ed54a30a97cb513dbc1cc8885 --- /dev/null +++ b/test/language/module-code/instn-named-err-dflt-thru-star-dflt_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var x; +export { x as default }; diff --git a/test/language/module-code/instn-named-err-dflt-thru-star-int_.js b/test/language/module-code/instn-named-err-dflt-thru-star-int_.js new file mode 100644 index 0000000000000000000000000000000000000000..fcd60646efc457775369d75df671873586000162 --- /dev/null +++ b/test/language/module-code/instn-named-err-dflt-thru-star-int_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-named-err-dflt-thru-star-dflt_.js'; diff --git a/test/language/module-code/instn-named-err-not-found-as.js b/test/language/module-code/instn-named-err-not-found-as.js new file mode 100644 index 0000000000000000000000000000000000000000..df49d213d9112636c82daee77e519edfd77530ee --- /dev/null +++ b/test/language/module-code/instn-named-err-not-found-as.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Named import binding - resolution failure (not found) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + + 15.2.1.16.3 ResolveExport + + [...] + 9. Let starResolution be null. + 10. For each ExportEntry Record e in module.[[StarExportEntries]], do + [...] + 11. Return starResolution. +negative: SyntaxError +flags: [module] +---*/ + +import { x as y } from './instn-named-err-not-found-empty_.js'; diff --git a/test/language/module-code/instn-named-err-not-found-dflt.js b/test/language/module-code/instn-named-err-not-found-dflt.js new file mode 100644 index 0000000000000000000000000000000000000000..fc649aaf742175424c45ab7cc0ac3a2b471601a4 --- /dev/null +++ b/test/language/module-code/instn-named-err-not-found-dflt.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Named import binding - resolution failure (not found) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + + 15.2.1.16.3 ResolveExport + + [...] + 9. Let starResolution be null. + 10. For each ExportEntry Record e in module.[[StarExportEntries]], do + [...] + 11. Return starResolution. +negative: SyntaxError +flags: [module] +---*/ + +import x from './instn-named-err-not-found-empty_.js'; diff --git a/test/language/module-code/instn-named-err-not-found-empty_.js b/test/language/module-code/instn-named-err-not-found-empty_.js new file mode 100644 index 0000000000000000000000000000000000000000..e46c626cf4c891ec4017bc2ab2281b9114c22e91 --- /dev/null +++ b/test/language/module-code/instn-named-err-not-found-empty_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +; diff --git a/test/language/module-code/instn-named-err-not-found.js b/test/language/module-code/instn-named-err-not-found.js new file mode 100644 index 0000000000000000000000000000000000000000..2e442d0dd899f62de6b8e4deaa005ecf2ed649d7 --- /dev/null +++ b/test/language/module-code/instn-named-err-not-found.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Named import binding - resolution failure (not found) +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + + 15.2.1.16.3 ResolveExport + + [...] + 9. Let starResolution be null. + 10. For each ExportEntry Record e in module.[[StarExportEntries]], do + [...] + 11. Return starResolution. +negative: SyntaxError +flags: [module] +---*/ + +import { x } from './instn-named-err-not-found-empty_.js'; diff --git a/test/language/module-code/instn-named-id-name.js b/test/language/module-code/instn-named-id-name.js new file mode 100644 index 0000000000000000000000000000000000000000..985d58b26542fbba0e5a06975f7e88ff012177dc --- /dev/null +++ b/test/language/module-code/instn-named-id-name.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + The first identifier in an ImportSpecifier containing `as` may be any valid + IdentifierName +esid: sec-imports +info: | + ImportSpecifier: + ImportedBinding + IdentifierName as ImportedBinding +flags: [module] +---*/ + +var _if = 1; +var _import = 2; +var _export = 3; +var _await = 4; +var _arguments = 5; +var _eval = 6; +var _default = 7; +var _as = 8; + +export { + _if as if, + _import as import, + _export as export, + _await as await, + _arguments as arguments, + _eval as eval, + _default as default, + _as as as + }; + +import { + if as if_, + import as import_, + export as export_, + await as await_, + arguments as arguments_, + eval as eval_, + default as default_, + as as as + } from './instn-named-id-name.js'; + +assert.sameValue(if_, 1); +assert.sameValue(import_, 2); +assert.sameValue(export_, 3); +assert.sameValue(await_, 4); +assert.sameValue(arguments_, 5); +assert.sameValue(eval_, 6); +assert.sameValue(default_, 7); +assert.sameValue(as, 8); diff --git a/test/language/module-code/instn-named-iee-cycle-2_.js b/test/language/module-code/instn-named-iee-cycle-2_.js new file mode 100644 index 0000000000000000000000000000000000000000..887728551ac3e3496707d218c6f9b432679214d9 --- /dev/null +++ b/test/language/module-code/instn-named-iee-cycle-2_.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { b as a } from './instn-named-iee-cycle.js'; +export { d as c } from './instn-named-iee-cycle.js'; +export { f as e } from './instn-named-iee-cycle.js'; +export { h as g } from './instn-named-iee-cycle.js'; +export { j as i } from './instn-named-iee-cycle.js'; +export { l as k } from './instn-named-iee-cycle.js'; +export { n as m } from './instn-named-iee-cycle.js'; +export { p as o } from './instn-named-iee-cycle.js'; +export { r as q } from './instn-named-iee-cycle.js'; +export { t as s } from './instn-named-iee-cycle.js'; +export { v as u } from './instn-named-iee-cycle.js'; +export { x as w } from './instn-named-iee-cycle.js'; +export { z as y } from './instn-named-iee-cycle.js'; diff --git a/test/language/module-code/instn-named-iee-cycle.js b/test/language/module-code/instn-named-iee-cycle.js new file mode 100644 index 0000000000000000000000000000000000000000..ee4973adb8909004447fef54fa1a76c1785d7ed6 --- /dev/null +++ b/test/language/module-code/instn-named-iee-cycle.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + There are no restrictions on the number of cycles during module traversal + during indirect export resolution, given unique export names. +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + + 15.2.1.16.3 ResolveExport( exportName, resolveSet, exportStarSet ) + + 2. For each Record {[[Module]], [[ExportName]]} r in resolveSet, do: + a. If module and r.[[Module]] are the same Module Record and + SameValue(exportName, r.[[ExportName]]) is true, then + i. Assert: this is a circular import request. + ii. Return null. + 3. Append the Record {[[Module]]: module, [[ExportName]]: exportName} to resolveSet. + [...] + 5. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. If SameValue(exportName, e.[[ExportName]]) is true, then + i. Assert: module imports a specific binding for this export. + ii. Let importedModule be ? HostResolveImportedModule(module, + e.[[ModuleRequest]]). + iii. Let indirectResolution be ? + importedModule.ResolveExport(e.[[ImportName]], resolveSet, + exportStarSet). + iv. If indirectResolution is not null, return indirectResolution. +flags: [module] +---*/ + +import { a } from './instn-named-iee-cycle-2_.js'; +export { c as b } from './instn-named-iee-cycle-2_.js'; +export { e as d } from './instn-named-iee-cycle-2_.js'; +export { g as f } from './instn-named-iee-cycle-2_.js'; +export { i as h } from './instn-named-iee-cycle-2_.js'; +export { k as j } from './instn-named-iee-cycle-2_.js'; +export { m as l } from './instn-named-iee-cycle-2_.js'; +export { o as n } from './instn-named-iee-cycle-2_.js'; +export { q as p } from './instn-named-iee-cycle-2_.js'; +export { s as r } from './instn-named-iee-cycle-2_.js'; +export { u as t } from './instn-named-iee-cycle-2_.js'; +export { w as v } from './instn-named-iee-cycle-2_.js'; +export { y as x } from './instn-named-iee-cycle-2_.js'; +export var z = 23; + +assert.sameValue(a, 23); diff --git a/test/language/module-code/instn-named-star-cycle-2_.js b/test/language/module-code/instn-named-star-cycle-2_.js new file mode 100644 index 0000000000000000000000000000000000000000..daeedae49aafcb7264a00114b06baf4d4865ddb7 --- /dev/null +++ b/test/language/module-code/instn-named-star-cycle-2_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-named-star-cycle-indirect-x_.js'; diff --git a/test/language/module-code/instn-named-star-cycle-indirect-x_.js b/test/language/module-code/instn-named-star-cycle-indirect-x_.js new file mode 100644 index 0000000000000000000000000000000000000000..d212ba5fc317b6e00cff5811cea443f441ca6909 --- /dev/null +++ b/test/language/module-code/instn-named-star-cycle-indirect-x_.js @@ -0,0 +1,7 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// This module should be visited exactly one time during resolution of the "x" +// binding. +export { y as x } from './instn-named-star-cycle-2_.js'; +export var y = 45; diff --git a/test/language/module-code/instn-named-star-cycle.js b/test/language/module-code/instn-named-star-cycle.js new file mode 100644 index 0000000000000000000000000000000000000000..b08b57120f25511df9a14d6dea60bdfeb63ec656 --- /dev/null +++ b/test/language/module-code/instn-named-star-cycle.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Modules are visited no more than one time when resolving bindings through + "star" exports. +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + [...] + c. Else, + i. Let resolution be ? + importedModule.ResolveExport(in.[[ImportName]], « », « »). + ii. If resolution is null or resolution is "ambiguous", throw a + SyntaxError exception. + iii. Call envRec.CreateImportBinding(in.[[LocalName]], + resolution.[[Module]], resolution.[[BindingName]]). + [...] + + 15.2.1.16.3 ResolveExport( exportName, resolveSet, exportStarSet ) + + [...] + 7. If exportStarSet contains module, return null. + 8. Append module to exportStarSet. + [...] +negative: SyntaxError +flags: [module] +---*/ + +import { x } from './instn-named-star-cycle-2_.js'; diff --git a/test/language/module-code/instn-once.js b/test/language/module-code/instn-once.js new file mode 100644 index 0000000000000000000000000000000000000000..dd859ffa5c899e9a57e4b3eefcb1ba4de91cb1bf --- /dev/null +++ b/test/language/module-code/instn-once.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Module is instantiated exactly once +esid: sec-moduledeclarationinstantiation +info: | + [...] + 5. If module.[[Environment]] is not undefined, return + NormalCompletion(empty). + 6. Let env be NewModuleEnvironment(realm.[[GlobalEnv]]). + 7. Set module.[[Environment]] to env. + 8. For each String required that is an element of + module.[[RequestedModules]] do, + a. NOTE: Before instantiating a module, all of the modules it requested + must be available. An implementation may perform this test at any + time prior to this point. + b. Let requiredModule be ? HostResolveImportedModule(module, required). + c. Perform ? requiredModule.ModuleDeclarationInstantiation(). + [...] +flags: [module] +---*/ + +import {} from './instn-once.js'; +import './instn-once.js'; +import * as ns1 from './instn-once.js'; +import dflt1 from './instn-once.js'; +export {} from './instn-once.js'; +import dflt2, {} from './instn-once.js'; +export * from './instn-once.js'; +import dflt3, * as ns from './instn-once.js'; +export default null; + +let x; diff --git a/test/language/module-code/instn-resolve-empty-export.js b/test/language/module-code/instn-resolve-empty-export.js new file mode 100644 index 0000000000000000000000000000000000000000..24215e0d3c3c8fa8b950ad42439b65f2d647dc3c --- /dev/null +++ b/test/language/module-code/instn-resolve-empty-export.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + An ExportClause without an ExportsList contributes to the list of requested + modules +esid: sec-moduledeclarationinstantiation +info: | + [...] + 8. For each String required that is an element of + module.[[RequestedModules]] do, + a. NOTE: Before instantiating a module, all of the modules it requested + must be available. An implementation may perform this test at any + time prior to this point. + b. Let requiredModule be ? HostResolveImportedModule(module, required). + c. Perform ? requiredModule.ModuleDeclarationInstantiation(). + + 15.2.2.5 Static Semantics: ModuleRequests + + ImportDeclaration : import ImportClause FromClause; + + 1. Return ModuleRequests of FromClause. + + 15.2.3 Exports + + Syntax + + ExportClause: + { } + { ExportsList } + { ExportsList , } +negative: ReferenceError +flags: [module] +---*/ + +export {} from './instn-resolve-empty-export_.js'; diff --git a/test/language/module-code/instn-resolve-empty-export_.js b/test/language/module-code/instn-resolve-empty-export_.js new file mode 100644 index 0000000000000000000000000000000000000000..c0d877a8692871ebcbe30eac0fd7c19c4562744e --- /dev/null +++ b/test/language/module-code/instn-resolve-empty-export_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +0++; diff --git a/test/language/module-code/instn-resolve-empty-import.js b/test/language/module-code/instn-resolve-empty-import.js new file mode 100644 index 0000000000000000000000000000000000000000..87fd8a1ae4a18042e72e074cac96e4309411809d --- /dev/null +++ b/test/language/module-code/instn-resolve-empty-import.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + An ImportClause without an ImportsList contributes to the list of requested + modules +esid: sec-moduledeclarationinstantiation +info: | + [...] + 8. For each String required that is an element of + module.[[RequestedModules]] do, + a. NOTE: Before instantiating a module, all of the modules it requested + must be available. An implementation may perform this test at any + time prior to this point. + b. Let requiredModule be ? HostResolveImportedModule(module, required). + c. Perform ? requiredModule.ModuleDeclarationInstantiation(). + + 15.2.2.5 Static Semantics: ModuleRequests + + ImportDeclaration : import ImportClause FromClause; + + 1. Return ModuleRequests of FromClause. + + 15.2.3 Exports + + Syntax + ImportClause : + ImportedDefaultBinding + NameSpaceImport + NamedImports + ImportedDefaultBinding , NameSpaceImport + ImportedDefaultBinding , NamedImports + + NamedImports : + { } + { ImportsList } + { ImportsList , } +negative: ReferenceError +flags: [module] +---*/ + +import {} from './instn-resolve-empty-import_.js'; diff --git a/test/language/module-code/instn-resolve-empty-import_.js b/test/language/module-code/instn-resolve-empty-import_.js new file mode 100644 index 0000000000000000000000000000000000000000..c0d877a8692871ebcbe30eac0fd7c19c4562744e --- /dev/null +++ b/test/language/module-code/instn-resolve-empty-import_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +0++; diff --git a/test/language/module-code/instn-resolve-err-reference.js b/test/language/module-code/instn-resolve-err-reference.js new file mode 100644 index 0000000000000000000000000000000000000000..b691f71b69fb4c5dfab8b9c4dda10d178fdff5aa --- /dev/null +++ b/test/language/module-code/instn-resolve-err-reference.js @@ -0,0 +1,17 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Requested modules that produce an early ReferenceError +esid: sec-moduledeclarationinstantiation +info: | + [...] + 8. For each String required that is an element of + module.[[RequestedModules]] do, + [...] + b. Let requiredModule be ? HostResolveImportedModule(module, required). + [...] +negative: ReferenceError +flags: [module] +---*/ + +import './instn-resolve-err-reference_.js'; diff --git a/test/language/module-code/instn-resolve-err-reference_.js b/test/language/module-code/instn-resolve-err-reference_.js new file mode 100644 index 0000000000000000000000000000000000000000..c0d877a8692871ebcbe30eac0fd7c19c4562744e --- /dev/null +++ b/test/language/module-code/instn-resolve-err-reference_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +0++; diff --git a/test/language/module-code/instn-resolve-err-syntax.js b/test/language/module-code/instn-resolve-err-syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..b2787e788bcd9639c8c60b6006a8c5def7aa4c08 --- /dev/null +++ b/test/language/module-code/instn-resolve-err-syntax.js @@ -0,0 +1,17 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Requested modules that produce an early SyntaxError +esid: sec-moduledeclarationinstantiation +info: | + [...] + 8. For each String required that is an element of + module.[[RequestedModules]] do, + [...] + b. Let requiredModule be ? HostResolveImportedModule(module, required). + [...] +negative: SyntaxError +flags: [module] +---*/ + +import './instn-resolve-err-syntax_.js'; diff --git a/test/language/module-code/instn-resolve-err-syntax_.js b/test/language/module-code/instn-resolve-err-syntax_.js new file mode 100644 index 0000000000000000000000000000000000000000..6ab6af47de561d4928f2bc4e90d0bded082d1a96 --- /dev/null +++ b/test/language/module-code/instn-resolve-err-syntax_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +break; diff --git a/test/language/module-code/instn-resolve-order-depth-child_.js b/test/language/module-code/instn-resolve-order-depth-child_.js new file mode 100644 index 0000000000000000000000000000000000000000..b1b41e700078a7bd684505d5c33c6a02e5aba202 --- /dev/null +++ b/test/language/module-code/instn-resolve-order-depth-child_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import './instn-resolve-order-depth-reference_.js'; diff --git a/test/language/module-code/instn-resolve-order-depth-reference_.js b/test/language/module-code/instn-resolve-order-depth-reference_.js new file mode 100644 index 0000000000000000000000000000000000000000..c0d877a8692871ebcbe30eac0fd7c19c4562744e --- /dev/null +++ b/test/language/module-code/instn-resolve-order-depth-reference_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +0++; diff --git a/test/language/module-code/instn-resolve-order-depth-syntax_.js b/test/language/module-code/instn-resolve-order-depth-syntax_.js new file mode 100644 index 0000000000000000000000000000000000000000..6ab6af47de561d4928f2bc4e90d0bded082d1a96 --- /dev/null +++ b/test/language/module-code/instn-resolve-order-depth-syntax_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +break; diff --git a/test/language/module-code/instn-resolve-order-depth.js b/test/language/module-code/instn-resolve-order-depth.js new file mode 100644 index 0000000000000000000000000000000000000000..ffeb90a198597bceedaa5a369dee75fd66325c8e --- /dev/null +++ b/test/language/module-code/instn-resolve-order-depth.js @@ -0,0 +1,11 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Module dependencies are resolved following a depth-first strategy +esid: sec-moduledeclarationinstantiation +negative: ReferenceError +flags: [module] +---*/ + +import './instn-resolve-order-depth-child_.js'; +import './instn-resolve-order-depth-syntax_.js'; diff --git a/test/language/module-code/instn-resolve-order-src-reference_.js b/test/language/module-code/instn-resolve-order-src-reference_.js new file mode 100644 index 0000000000000000000000000000000000000000..c0d877a8692871ebcbe30eac0fd7c19c4562744e --- /dev/null +++ b/test/language/module-code/instn-resolve-order-src-reference_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +0++; diff --git a/test/language/module-code/instn-resolve-order-src-syntax_.js b/test/language/module-code/instn-resolve-order-src-syntax_.js new file mode 100644 index 0000000000000000000000000000000000000000..6ab6af47de561d4928f2bc4e90d0bded082d1a96 --- /dev/null +++ b/test/language/module-code/instn-resolve-order-src-syntax_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +break; diff --git a/test/language/module-code/instn-resolve-order-src-valid_.js b/test/language/module-code/instn-resolve-order-src-valid_.js new file mode 100644 index 0000000000000000000000000000000000000000..e46c626cf4c891ec4017bc2ab2281b9114c22e91 --- /dev/null +++ b/test/language/module-code/instn-resolve-order-src-valid_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +; diff --git a/test/language/module-code/instn-resolve-order-src.js b/test/language/module-code/instn-resolve-order-src.js new file mode 100644 index 0000000000000000000000000000000000000000..501ebe138a520d5ddec2526e843d5a9f73cd89dc --- /dev/null +++ b/test/language/module-code/instn-resolve-order-src.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Modules dependencies are resolved in source text order +esid: sec-moduledeclarationinstantiation +negative: ReferenceError +flags: [module] +---*/ + +import './instn-resolve-order-src-valid_.js'; +import './instn-resolve-order-src-reference_.js'; +import './instn-resolve-order-src-syntax_.js'; diff --git a/test/language/module-code/instn-same-global-set_.js b/test/language/module-code/instn-same-global-set_.js new file mode 100644 index 0000000000000000000000000000000000000000..73ca298c7fba7f78bc11ebd2079cdc5e18145071 --- /dev/null +++ b/test/language/module-code/instn-same-global-set_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +new Function('return this;')().test262 = 262; diff --git a/test/language/module-code/instn-same-global.js b/test/language/module-code/instn-same-global.js new file mode 100644 index 0000000000000000000000000000000000000000..f49d014b7f3c4b10ed6fd1ec4e037db6310d1358 --- /dev/null +++ b/test/language/module-code/instn-same-global.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Modules share the same global `this` value +esid: sec-moduledeclarationinstantiation +info: | + [...] + 6. Let env be NewModuleEnvironment(realm.[[GlobalEnv]]). + 7. Set module.[[Environment]] to env. + [...] +includes: [fnGlobalObject.js] +flags: [module] +---*/ + +import './instn-same-global-set_.js'; + +var global = fnGlobalObject(); + +assert.sameValue(global.test262, 262); diff --git a/test/language/module-code/instn-star-ambiguous-1_.js b/test/language/module-code/instn-star-ambiguous-1_.js new file mode 100644 index 0000000000000000000000000000000000000000..1c568f1f542082fd0e275a7f62956b696e22c6af --- /dev/null +++ b/test/language/module-code/instn-star-ambiguous-1_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var first = null; +export var both = null; diff --git a/test/language/module-code/instn-star-ambiguous-2_.js b/test/language/module-code/instn-star-ambiguous-2_.js new file mode 100644 index 0000000000000000000000000000000000000000..2f783f472a7ecb70f3c3fabb628f5748039571e8 --- /dev/null +++ b/test/language/module-code/instn-star-ambiguous-2_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var second = null; +export var both = null; diff --git a/test/language/module-code/instn-star-ambiguous.js b/test/language/module-code/instn-star-ambiguous.js new file mode 100644 index 0000000000000000000000000000000000000000..9e32067ee85205e4895a3f925005fe56ef7911b5 --- /dev/null +++ b/test/language/module-code/instn-star-ambiguous.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: + Ambiguous exports are not reflected in module namespace objects, nor do + they trigger an error upon resolution +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + [...] + + 15.2.1.18 Runtime Semantics: GetModuleNamespace + + [...] + 3. If namespace is undefined, then + [...] + c. For each name that is an element of exportedNames, + i. Let resolution be ? module.ResolveExport(name, « », « »). + ii. If resolution is null, throw a SyntaxError exception. + iii. If resolution is not "ambiguous", append name to + unambiguousNames. + d. Let namespace be ModuleNamespaceCreate(module, unambiguousNames). +flags: [module] +---*/ + +import * as ns from './instn-star-ambiguous_.js'; + +assert('first' in ns, 'Non-ambiguous exports from first module are present'); +assert('second' in ns, 'Non-ambiguous exports from second module are present'); +assert.sameValue('both' in ns, false, 'Ambiguous export is not present'); diff --git a/test/language/module-code/instn-star-ambiguous_.js b/test/language/module-code/instn-star-ambiguous_.js new file mode 100644 index 0000000000000000000000000000000000000000..ab96a95cbcf8a6775083316318a50cae5aa6a95f --- /dev/null +++ b/test/language/module-code/instn-star-ambiguous_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-star-ambiguous-1_.js'; +export * from './instn-star-ambiguous-2_.js'; diff --git a/test/language/module-code/instn-star-binding.js b/test/language/module-code/instn-star-binding.js new file mode 100644 index 0000000000000000000000000000000000000000..7b90bf32a79df9d284ca9a4c33b13ab9d29c76c3 --- /dev/null +++ b/test/language/module-code/instn-star-binding.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Immutable binding is created for module namespace object +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + ii. Perform ! envRec.CreateImmutableBinding(in.[[LocalName]], true). + iii. Call envRec.InitializeBinding(in.[[LocalName]], namespace). + [...] +flags: [module] +---*/ + +assert.sameValue( + typeof ns, 'object', 'binding is initialized prior to module evaluation' +); + +var original = ns; + +assert.throws(TypeError, function() { + ns = null; +}, 'binding rejects assignment'); + +assert.sameValue(ns, original, 'binding value is immutable'); + +import * as ns from './instn-star-binding.js'; diff --git a/test/language/module-code/instn-star-equality-other_.js b/test/language/module-code/instn-star-equality-other_.js new file mode 100644 index 0000000000000000000000000000000000000000..2169a1e48c89820e485b37b76f7f85ff75929125 --- /dev/null +++ b/test/language/module-code/instn-star-equality-other_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +import * as testNs from './instn-star-equality.js'; +export { testNs }; diff --git a/test/language/module-code/instn-star-equality.js b/test/language/module-code/instn-star-equality.js new file mode 100644 index 0000000000000000000000000000000000000000..f1b2e920fa22c118eb165e3287568e3541c68783 --- /dev/null +++ b/test/language/module-code/instn-star-equality.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: A single namespace is created for each module +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + ii. Perform ! envRec.CreateImmutableBinding(in.[[LocalName]], true). + iii. Call envRec.InitializeBinding(in.[[LocalName]], namespace). + [...] + + 15.2.1.18 Runtime Semantics: GetModuleNamespace + + 1. Assert: module is an instance of a concrete subclass of Module Record. + 2. Let namespace be module.[[Namespace]]. + 3. If namespace is undefined, then + [...] + 4. Return namespace. +flags: [module] +---*/ + +import * as self1 from './instn-star-equality.js'; +import * as self2 from './instn-star-equality.js'; +import * as other1 from './instn-star-equality-other_.js'; +import * as self3 from './instn-star-equality.js'; +import * as other2 from './instn-star-equality-other_.js'; +import { testNs } from './instn-star-equality-other_.js'; + +assert.sameValue( + self1, self2, 'Local namespace objects from consecutive declarations' +); +assert.sameValue( + self1, self3, 'Local namespace objects from non-consective declarations' +); +assert.sameValue(other1, other2, 'External namespace objects'); +assert.sameValue(self1, testNs, 'Re-exported namespace objects'); + +assert.notSameValue(self1, other1); diff --git a/test/language/module-code/instn-star-err-not-found-empty_.js b/test/language/module-code/instn-star-err-not-found-empty_.js new file mode 100644 index 0000000000000000000000000000000000000000..e46c626cf4c891ec4017bc2ab2281b9114c22e91 --- /dev/null +++ b/test/language/module-code/instn-star-err-not-found-empty_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +; diff --git a/test/language/module-code/instn-star-err-not-found-faulty_.js b/test/language/module-code/instn-star-err-not-found-faulty_.js new file mode 100644 index 0000000000000000000000000000000000000000..e4bef5ebd6dad9093952227b18062f2971075f90 --- /dev/null +++ b/test/language/module-code/instn-star-err-not-found-faulty_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { x } from './inst-import-star-err-not-found-empty_.js'; diff --git a/test/language/module-code/instn-star-err-not-found.js b/test/language/module-code/instn-star-err-not-found.js new file mode 100644 index 0000000000000000000000000000000000000000..ece6a63beb8d6cbf8311354c30ed520c1f233a75 --- /dev/null +++ b/test/language/module-code/instn-star-err-not-found.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Importing a namespace for a module which contains an unresolvable named + export +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + [...] + + 15.2.1.18 Runtime Semantics: GetModuleNamespace + + [...] + 3. If namespace is undefined, then + [...] + c. For each name that is an element of exportedNames, + i. Let resolution be ? module.ResolveExport(name, « », « »). + ii. If resolution is null, throw a SyntaxError exception. +negative: SyntaxError +flags: [module] +---*/ + +import * as ns from './inst-import-star-err-not-found-faulty_.js'; diff --git a/test/language/module-code/instn-star-id-name.js b/test/language/module-code/instn-star-id-name.js new file mode 100644 index 0000000000000000000000000000000000000000..8c83ddf21999eb2e58b3db92ae53a482bb05ec8d --- /dev/null +++ b/test/language/module-code/instn-star-id-name.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Namespace object reports properties for any valid exported IdentifierName. +esid: sec-imports +info: | + [...] + 5. For each ExportEntry Record e in module.[[LocalExportEntries]], do + a. Assert: module provides the direct binding for this export. + b. Append e.[[ExportName]] to exportedNames. + [...] +flags: [module] +---*/ + +var _if = null; +var _import = null; +var _export = null; +var _await = null; +var _arguments = null; +var _eval = null; +var _default = null; +var as = null; + +export { + _if as if, + _import as import, + _export as export, + _await as await, + _arguments as arguments, + _eval as eval, + _default as default, + as as as + }; + +import * as ns from './instn-star-id-name.js'; + +assert('if' in ns, 'property name: if'); +assert('import' in ns, 'property name: import'); +assert('export' in ns, 'property name: export'); +assert('await' in ns, 'property name: await'); +assert('arguments' in ns, 'property name: arguments'); +assert('eval' in ns, 'property name: eval'); +assert('default' in ns, 'property name: default'); +assert('as' in ns, 'property name: as'); diff --git a/test/language/module-code/instn-star-iee-cycle-2_.js b/test/language/module-code/instn-star-iee-cycle-2_.js new file mode 100644 index 0000000000000000000000000000000000000000..cb2cf219063020a1f595dbee51d3e1bd09e2c0cb --- /dev/null +++ b/test/language/module-code/instn-star-iee-cycle-2_.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { b as a } from './instn-star-iee-cycle.js'; +export { d as c } from './instn-star-iee-cycle.js'; +export { f as e } from './instn-star-iee-cycle.js'; +export { h as g } from './instn-star-iee-cycle.js'; +export { j as i } from './instn-star-iee-cycle.js'; +export { l as k } from './instn-star-iee-cycle.js'; +export { n as m } from './instn-star-iee-cycle.js'; +export { p as o } from './instn-star-iee-cycle.js'; +export { r as q } from './instn-star-iee-cycle.js'; +export { t as s } from './instn-star-iee-cycle.js'; +export { v as u } from './instn-star-iee-cycle.js'; +export { x as w } from './instn-star-iee-cycle.js'; +export { z as y } from './instn-star-iee-cycle.js'; diff --git a/test/language/module-code/instn-star-iee-cycle.js b/test/language/module-code/instn-star-iee-cycle.js new file mode 100644 index 0000000000000000000000000000000000000000..c8b58d0aefabe8b3e21a8257c2dece9771dd64d6 --- /dev/null +++ b/test/language/module-code/instn-star-iee-cycle.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + There are no restrictions on the number of cycles during module traversal + during indirect export resolution, given unique export names. +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + ii. Perform ! envRec.CreateImmutableBinding(in.[[LocalName]], true). + iii. Call envRec.InitializeBinding(in.[[LocalName]], namespace). + [...] + + 15.2.1.16.3 ResolveExport( exportName, resolveSet, exportStarSet ) + + 2. For each Record {[[Module]], [[ExportName]]} r in resolveSet, do: + a. If module and r.[[Module]] are the same Module Record and + SameValue(exportName, r.[[ExportName]]) is true, then + i. Assert: this is a circular import request. + ii. Return null. + 3. Append the Record {[[Module]]: module, [[ExportName]]: exportName} to resolveSet. + [...] + 5. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. If SameValue(exportName, e.[[ExportName]]) is true, then + i. Assert: module imports a specific binding for this export. + ii. Let importedModule be ? HostResolveImportedModule(module, + e.[[ModuleRequest]]). + iii. Let indirectResolution be ? + importedModule.ResolveExport(e.[[ImportName]], resolveSet, + exportStarSet). + iv. If indirectResolution is not null, return indirectResolution. +flags: [module] +---*/ + +import * as ns from './instn-star-iee-cycle-2_.js'; +export { c as b } from './instn-star-iee-cycle-2_.js'; +export { e as d } from './instn-star-iee-cycle-2_.js'; +export { g as f } from './instn-star-iee-cycle-2_.js'; +export { i as h } from './instn-star-iee-cycle-2_.js'; +export { k as j } from './instn-star-iee-cycle-2_.js'; +export { m as l } from './instn-star-iee-cycle-2_.js'; +export { o as n } from './instn-star-iee-cycle-2_.js'; +export { q as p } from './instn-star-iee-cycle-2_.js'; +export { s as r } from './instn-star-iee-cycle-2_.js'; +export { u as t } from './instn-star-iee-cycle-2_.js'; +export { w as v } from './instn-star-iee-cycle-2_.js'; +export { y as x } from './instn-star-iee-cycle-2_.js'; +export var z = 23; + +assert.sameValue(ns.a, 23); diff --git a/test/language/module-code/instn-star-props-circular-a_.js b/test/language/module-code/instn-star-props-circular-a_.js new file mode 100644 index 0000000000000000000000000000000000000000..165a825fb977064f9f0c21d7ed3dc9729c4db825 --- /dev/null +++ b/test/language/module-code/instn-star-props-circular-a_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-star-props-circular-b_.js'; +export var fromA; diff --git a/test/language/module-code/instn-star-props-circular-b_.js b/test/language/module-code/instn-star-props-circular-b_.js new file mode 100644 index 0000000000000000000000000000000000000000..b12e23fec09caa3b8addb6f3256f117739dfe068 --- /dev/null +++ b/test/language/module-code/instn-star-props-circular-b_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-star-props-circular-a_.js'; +export var fromB; diff --git a/test/language/module-code/instn-star-props-circular.js b/test/language/module-code/instn-star-props-circular.js new file mode 100644 index 0000000000000000000000000000000000000000..1e6ffdbac6214e620b6344bd617d0ccb165b0190 --- /dev/null +++ b/test/language/module-code/instn-star-props-circular.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: + Circular "star" imports do not trigger infinite recursion during name + enumeration. +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + [...] + + 15.2.1.18 Runtime Semantics: GetModuleNamespace + + [...] + 3. If namespace is undefined, then + a. Let exportedNames be ? module.GetExportedNames(« »). + [...] + + 15.2.1.16.2 GetExportedNames + + 1. Let module be this Source Text Module Record. + 2. If exportStarSet contains module, then + a. Assert: We've reached the starting point of an import * circularity. + b. Return a new empty List. +flags: [module] +---*/ + +import * as a from './instn-star-props-circular-a_.js'; +import * as b from './instn-star-props-circular-b_.js'; + +assert('fromA' in a, 'entry for binding from "a" in namespace of module A'); +assert('fromB' in a, 'entry for binding from "b" in namespace of module A'); + +assert('fromA' in b, 'entry for binding from "a" in namespace of module B'); +assert('fromB' in b, 'entry for binding from "b" in namespace of module B'); diff --git a/test/language/module-code/instn-star-props-dflt-keep-indirect-def_.js b/test/language/module-code/instn-star-props-dflt-keep-indirect-def_.js new file mode 100644 index 0000000000000000000000000000000000000000..ca281f94c695f205efe490ea175eb120c63347a5 --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-keep-indirect-def_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export default null; diff --git a/test/language/module-code/instn-star-props-dflt-keep-indirect-reexport_.js b/test/language/module-code/instn-star-props-dflt-keep-indirect-reexport_.js new file mode 100644 index 0000000000000000000000000000000000000000..16bd13970443810f7549db8808fbd6e0a9411256 --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-keep-indirect-reexport_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export { default } from './instn-star-props-dflt-keep-indirect-def_.js'; diff --git a/test/language/module-code/instn-star-props-dflt-keep-indirect.js b/test/language/module-code/instn-star-props-dflt-keep-indirect.js new file mode 100644 index 0000000000000000000000000000000000000000..896b4dfe9ea8e8787e27fc1a62d31f5a50efeb6b --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-keep-indirect.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: + Indirect default exports are included in the module namespace object +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + [...] + + 15.2.1.18 Runtime Semantics: GetModuleNamespace + + [...] + 3. If namespace is undefined, then + a. Let exportedNames be ? module.GetExportedNames(« »). + [...] + + 15.2.1.16.2 GetExportedNames + + [...] + 6. For each ExportEntry Record e in module.[[IndirectExportEntries]], do + a. Assert: module imports a specific binding for this export. + b. Append e.[[ExportName]] to exportedNames. + [...] +flags: [module] +---*/ + +import * as ns from './instn-star-props-dflt-keep-indirect-reexport_.js'; + +assert.sameValue('default' in ns, true); diff --git a/test/language/module-code/instn-star-props-dflt-keep-local-named_.js b/test/language/module-code/instn-star-props-dflt-keep-local-named_.js new file mode 100644 index 0000000000000000000000000000000000000000..fde22294b40b2e9623d098e8b7fae7896535f7bc --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-keep-local-named_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var x = null; +export { x as default }; diff --git a/test/language/module-code/instn-star-props-dflt-keep-local-prod_.js b/test/language/module-code/instn-star-props-dflt-keep-local-prod_.js new file mode 100644 index 0000000000000000000000000000000000000000..ca281f94c695f205efe490ea175eb120c63347a5 --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-keep-local-prod_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export default null; diff --git a/test/language/module-code/instn-star-props-dflt-keep-local.js b/test/language/module-code/instn-star-props-dflt-keep-local.js new file mode 100644 index 0000000000000000000000000000000000000000..e1f838a6e235b9df0101b2058b34fe1a8c3f213d --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-keep-local.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: + Local default exports are included in the module namespace object +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + [...] + + 15.2.1.18 Runtime Semantics: GetModuleNamespace + + [...] + 3. If namespace is undefined, then + a. Let exportedNames be ? module.GetExportedNames(« »). + [...] + + 15.2.1.16.2 GetExportedNames + + [...] + 5. For each ExportEntry Record e in module.[[LocalExportEntries]], do + a. Assert: module provides the direct binding for this export. + b. Append e.[[ExportName]] to exportedNames. + [...] +flags: [module] +---*/ + +import * as named from './instn-star-props-dflt-keep-local-named_.js'; +import * as production from './instn-star-props-dflt-keep-local-prod_.js'; + +assert.sameValue('default' in named, true, 'default specified via identifier'); + +assert.sameValue( + 'default' in production, true, 'default specified via dedicated production' +); diff --git a/test/language/module-code/instn-star-props-dflt-skip-named_.js b/test/language/module-code/instn-star-props-dflt-skip-named_.js new file mode 100644 index 0000000000000000000000000000000000000000..69647d741482bce3a43e025f8ce7679159510973 --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-skip-named_.js @@ -0,0 +1,6 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var x; +export var namedOther = null; +export { x as default }; diff --git a/test/language/module-code/instn-star-props-dflt-skip-prod_.js b/test/language/module-code/instn-star-props-dflt-skip-prod_.js new file mode 100644 index 0000000000000000000000000000000000000000..fd5927ef472e6ff6ace0165141b1b6e080be60fb --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-skip-prod_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var productionOther = null; +export default null; diff --git a/test/language/module-code/instn-star-props-dflt-skip-star-named_.js b/test/language/module-code/instn-star-props-dflt-skip-star-named_.js new file mode 100644 index 0000000000000000000000000000000000000000..05705983a9f9b0ad0fbe69700743c3e2f6c9fe17 --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-skip-star-named_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-star-props-dflt-skip-named_.js'; diff --git a/test/language/module-code/instn-star-props-dflt-skip-star-prod_.js b/test/language/module-code/instn-star-props-dflt-skip-star-prod_.js new file mode 100644 index 0000000000000000000000000000000000000000..e3ec18109ffe94d26dd33a18996e8be36dc0ab97 --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-skip-star-prod_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-star-props-dflt-skip-prod_.js'; diff --git a/test/language/module-code/instn-star-props-dflt-skip.js b/test/language/module-code/instn-star-props-dflt-skip.js new file mode 100644 index 0000000000000000000000000000000000000000..0e096b38ee1a24426abad63f48b528c8e1bc7740 --- /dev/null +++ b/test/language/module-code/instn-star-props-dflt-skip.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: + Default exports are not included in the module namespace object +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + [...] + + 15.2.1.18 Runtime Semantics: GetModuleNamespace + + [...] + 3. If namespace is undefined, then + a. Let exportedNames be ? module.GetExportedNames(« »). + [...] + + 15.2.1.16.2 GetExportedNames + + [...] + 7. For each ExportEntry Record e in module.[[StarExportEntries]], do + [...] + c. For each element n of starNames, do + i. If SameValue(n, "default") is false, then + [...] +flags: [module] +---*/ + +import * as named from './instn-star-props-dflt-skip-star-named_.js'; +import * as production from './instn-star-props-dflt-skip-star-prod_.js'; + +assert('namedOther' in named); +assert.sameValue( + 'default' in named, false, 'default specified via identifier' +); + +assert('productionOther' in production); +assert.sameValue( + 'default' in production, false, 'default specified via dedicated production' +); diff --git a/test/language/module-code/instn-star-props-nrml-1_.js b/test/language/module-code/instn-star-props-nrml-1_.js new file mode 100644 index 0000000000000000000000000000000000000000..5b70c0746c397de88a055be223239f3631eed82a --- /dev/null +++ b/test/language/module-code/instn-star-props-nrml-1_.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var notExportedVar1; +let notExportedLet1; +const notExportedConst1 = null; +function notExportedFunc1() {} +function* notExportedGen1() {} +class notExportedClass1 {} + +var localBindingId; + +export var localVarDecl; +export let localLetDecl; +export const localConstDecl = null; +export function localFuncDecl() {} +export function* localGenDecl() {} +export class localClassDecl {} +export { localBindingId }; +export { localBindingId as localIdName }; +export { indirectIdName } from './instn-star-props-nrml-indirect_.js'; +export { indirectIdName as indirectIdName2 } from './instn-star-props-nrml-indirect_.js'; + +export * from './instn-star-props-nrml-star_.js'; diff --git a/test/language/module-code/instn-star-props-nrml-indirect_.js b/test/language/module-code/instn-star-props-nrml-indirect_.js new file mode 100644 index 0000000000000000000000000000000000000000..cfdf45fe064744e5a2c16f6ef7def7710dc8f562 --- /dev/null +++ b/test/language/module-code/instn-star-props-nrml-indirect_.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var indirectIdName; +export var starIndirectIdName; diff --git a/test/language/module-code/instn-star-props-nrml-star_.js b/test/language/module-code/instn-star-props-nrml-star_.js new file mode 100644 index 0000000000000000000000000000000000000000..9ae922721a495ad8719cf151c2481c17df14bee3 --- /dev/null +++ b/test/language/module-code/instn-star-props-nrml-star_.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var notExportedVar2; +let notExportedLet2; +const notExportedConst2 = null; +function notExportedFunc2() {} +function* notExportedGen2() {} +class notExportedClass2 {} + +var starBindingId; + +export var starVarDecl; +export let starLetDecl; +export const starConstDecl = null; +export function starFuncDecl() {} +export function* starGenDecl() {} +export class starClassDecl {} +export { starBindingId }; +export { starBindingId as starIdName }; +export { starIndirectIdName } from './instn-star-props-nrml-indirect_.js'; +export { starIndirectIdName as starIndirectIdName2 } from './instn-star-props-nrml-indirect_.js'; diff --git a/test/language/module-code/instn-star-props-nrml.js b/test/language/module-code/instn-star-props-nrml.js new file mode 100644 index 0000000000000000000000000000000000000000..df2a9f1380f24acba094a25a771bc59f4a63dc40 --- /dev/null +++ b/test/language/module-code/instn-star-props-nrml.js @@ -0,0 +1,68 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Module namespace object reports properties for all ExportEntries of all + dependencies. +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + [...] + + + 3. If namespace is undefined, then + a. Let exportedNames be ? module.GetExportedNames(« »). + b. Let unambiguousNames be a new empty List. + c. For each name that is an element of exportedNames, + i. Let resolution be ? module.ResolveExport(name, « », « »). + ii. If resolution is null, throw a SyntaxError exception. + iii. If resolution is not "ambiguous", append name to + unambiguousNames. + d. Let namespace be ModuleNamespaceCreate(module, unambiguousNames). +flags: [module] +---*/ + +import * as ns from './instn-star-props-nrml-1_.js'; + +// Export entries defined by a directly-imported module +assert('localVarDecl' in ns, 'localVarDecl'); +assert('localLetDecl' in ns, 'localLetDecl'); +assert('localConstDecl' in ns, 'localConstDecl'); +assert('localFuncDecl' in ns, 'localFuncDecl'); +assert('localGenDecl' in ns, 'localGenDecl'); +assert('localClassDecl' in ns, 'localClassDecl'); +assert('localBindingId' in ns, 'localBindingId'); +assert('localIdName' in ns, 'localIdName'); +assert('indirectIdName' in ns, 'indirectIdName'); +assert('indirectIdName2' in ns, 'indirectIdName2'); + +// Export entries defined by a re-exported module +assert('starVarDecl' in ns, 'starVarDecl'); +assert('starLetDecl' in ns, 'starLetDecl'); +assert('starConstDecl' in ns, 'starConstDecl'); +assert('starFuncDecl' in ns, 'starFuncDecl'); +assert('starGenDecl' in ns, 'starGenDecl'); +assert('starClassDecl' in ns, 'starClassDecl'); +assert('starBindingId' in ns, 'starBindingId'); +assert('starIdName' in ns, 'starIdName'); +assert('starIndirectIdName' in ns, 'starIndirectIdName'); +assert('starIndirectIdName2' in ns, 'starIndirectIdName2'); + +// Bindings that were not exported from either module +assert.sameValue('nonExportedVar1' in ns, false, 'nonExportedVar1'); +assert.sameValue('nonExportedVar2' in ns, false, 'nonExportedVar2'); +assert.sameValue('nonExportedLet1' in ns, false, 'nonExportedLet1'); +assert.sameValue('nonExportedLet2' in ns, false, 'nonExportedLet2'); +assert.sameValue('nonExportedConst1' in ns, false, 'nonExportedConst1'); +assert.sameValue('nonExportedConst2' in ns, false, 'nonExportedConst2'); +assert.sameValue('nonExportedFunc1' in ns, false, 'nonExportedFunc1'); +assert.sameValue('nonExportedFunc2' in ns, false, 'nonExportedFunc2'); +assert.sameValue('nonExportedGen1' in ns, false, 'nonExportedGen1'); +assert.sameValue('nonExportedGen2' in ns, false, 'nonExportedGen2'); +assert.sameValue('nonExportedClass1' in ns, false, 'nonExportedClass1'); +assert.sameValue('nonExportedClass2' in ns, false, 'nonExportedClass2'); diff --git a/test/language/module-code/instn-star-star-cycle-2_.js b/test/language/module-code/instn-star-star-cycle-2_.js new file mode 100644 index 0000000000000000000000000000000000000000..fef0cb811dc1b4c06120fd1c87f63c32450d3bc7 --- /dev/null +++ b/test/language/module-code/instn-star-star-cycle-2_.js @@ -0,0 +1,4 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * from './instn-star-star-cycle-indirect-x_.js'; diff --git a/test/language/module-code/instn-star-star-cycle-indirect-x_.js b/test/language/module-code/instn-star-star-cycle-indirect-x_.js new file mode 100644 index 0000000000000000000000000000000000000000..d8f4f09c914a9e2ceb6a7e5a172e1a9404056c1a --- /dev/null +++ b/test/language/module-code/instn-star-star-cycle-indirect-x_.js @@ -0,0 +1,7 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// This module should be visited exactly one time during resolution of the "x" +// binding. +export { y as x } from './instn-star-star-cycle-2_.js'; +export var y = 45; diff --git a/test/language/module-code/instn-star-star-cycle.js b/test/language/module-code/instn-star-star-cycle.js new file mode 100644 index 0000000000000000000000000000000000000000..87282db6951f34d04093b1cf559a339a54ab4a46 --- /dev/null +++ b/test/language/module-code/instn-star-star-cycle.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Modules are visited no more than one time when resolving bindings through + "star" exports. +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + ii. Perform ! envRec.CreateImmutableBinding(in.[[LocalName]], true). + iii. Call envRec.InitializeBinding(in.[[LocalName]], namespace). + [...] + + 15.2.1.16.3 ResolveExport( exportName, resolveSet, exportStarSet ) + + [...] + 7. If exportStarSet contains module, return null. + 8. Append module to exportStarSet. + [...] +negative: SyntaxError +flags: [module] +---*/ + +import * as ns from './instn-star-star-cycle-2_.js'; diff --git a/test/language/module-code/instn-uniq-env-rec-other_.js b/test/language/module-code/instn-uniq-env-rec-other_.js new file mode 100644 index 0000000000000000000000000000000000000000..fefd111898265ef218645a37ef6eb33f2322bd2a --- /dev/null +++ b/test/language/module-code/instn-uniq-env-rec-other_.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var first = 4; +let second = 5; +const third = 6; +class fourth {} +function fifth() {} +function* sixth() {} + +var seventh = 7; +let eighth = 8; +const ninth = 9; +class tenth {} +function eleventh() {} +function *twelfth() {} diff --git a/test/language/module-code/instn-uniq-env-rec.js b/test/language/module-code/instn-uniq-env-rec.js new file mode 100644 index 0000000000000000000000000000000000000000..f413ed1c2d5135799b9cb3ef976c70f5b9763a8f --- /dev/null +++ b/test/language/module-code/instn-uniq-env-rec.js @@ -0,0 +1,70 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Modules have distinct environment records +esid: sec-moduledeclarationinstantiation +info: | + [...] + 6. Let env be NewModuleEnvironment(realm.[[GlobalEnv]]). + 7. Set module.[[Environment]] to env. + [...] + + 8.1.2.6 NewModuleEnvironment (E) + + 1. Let env be a new Lexical Environment. + [...] +flags: [module] +---*/ + +import './instn-uniq-env-rec-other_.js' +var first = 1; +let second = 2; +const third = 3; +class fourth {} +function fifth() { return 'fifth'; } +function* sixth() { return 'sixth'; } + +assert.sameValue(first, 1); +assert.sameValue(second, 2); +assert.sameValue(third, 3); +assert.sameValue(typeof fourth, 'function', 'class declaration'); +assert.sameValue(typeof fifth, 'function', 'function declaration'); +assert.sameValue(fifth(), 'fifth'); +assert.sameValue(typeof sixth, 'function', 'generator function declaration'); +assert.sameValue(sixth().next().value, 'sixth'); + +// Two separate mechanisms are required to ensure that no binding has been +// created for a given identifier. A "bare" reference should produce a +// ReferenceError for non-existent bindings and uninitialized bindings. A +// reference through the `typeof` operator should succeed for non-existent +// bindings and initialized bindings. Only non-existent bindings satisfy both +// tests. +typeof seventh; +assert.throws(ReferenceError, function() { + seventh; +}); + +typeof eight; +assert.throws(ReferenceError, function() { + eighth; +}); + +typeof ninth; +assert.throws(ReferenceError, function() { + ninth; +}); + +typeof tenth; +assert.throws(ReferenceError, function() { + tenth; +}); + +typeof eleventh; +assert.throws(ReferenceError, function() { + eleventh; +}); + +typeof twelfth; +assert.throws(ReferenceError, function() { + twelfth; +});