From 4273ad1fa7311e16119920033f23faec0c2fe14c Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Tue, 29 Mar 2016 11:50:15 -0400 Subject: [PATCH] Module semantics: declaration instantiation Files whose name ends in `_.js` are not themselves valid Test262 tests and should not be interpreted as such by test runners. --- Because the tests in this patch concern declaration *instantiation*, care has been taken to avoid asserting binding values following evaluation. Because a given module's dependencies are evaluated prior to the module itself, this is only observable in modules which import their own bindings. A separate patch dedicated to the evaluation of module code asserts the behavior of bindings following evaluation. --- For tests that concern the creation of a module namespace object, this patch relies on the semantics of the `in` operator. The `in` operator uses the [[HasProperty]] internal method and avoids testing unrelated semantics concerning binding resolution. Those semantics should be explicitly asserted with a separate set of tests dedicated to that purpose. --- One test case which is notably missing is error resulting from a cycle due to an `import` declaration (under the current file naming scheme, such a test might be named `instn-named-err-circular.js`). Due to the recursive nature of ModuleDeclarationInstantiation, it is not technically possible for a circular request to be found in step 12.c.i. Cycles rely on at least 2 `export` declarations, and because these are resolved *before* imports, any cycle would trigger failure prior to step 12.c. --- One aspect of *module* resolution that makes ordering observable is the fact that resolution can fail in two distinct ways (i.e. with a SyntaxError or with a ReferenceError). This patch includes tests that leverage this detail in order to assert that modules are resolved in the correct sequence. However, from the perspective of the ECMA-262 specification, the ordering of *export* (e.g. binding) resolution is not observable. This is due to restrictions on the grammar, where each export is independent. When *export* resolution fails, it does so with instances of SyntaxError alone, precluding the above strategy. So while ModuleDeclarationInstantiation resolves the exports of the module's dependencies in the following order: 1. "Indirect" exports, e.g. - `export { x } from './y.js';` - `export { x as z } from './y.js';` - `import { x } from './y.js'; export { x };` 2. "Star" imports - `import * as ns from './y.js';` 3. "Named" (my word) imports - `import x from './y.js';` - `import { x } from './y.js';` - `import { x as z } from './y.js';` Intentional failures cannot be used to discern resolution ordering. --- .../module-code/instn-iee-bndng-cls.js | 47 +++++++++++++ .../module-code/instn-iee-bndng-cls_.js | 18 +++++ .../module-code/instn-iee-bndng-const.js | 47 +++++++++++++ .../module-code/instn-iee-bndng-const_.js | 18 +++++ .../module-code/instn-iee-bndng-fun.js | 55 +++++++++++++++ .../module-code/instn-iee-bndng-fun_.js | 18 +++++ .../module-code/instn-iee-bndng-gen.js | 56 +++++++++++++++ .../module-code/instn-iee-bndng-gen_.js | 18 +++++ .../module-code/instn-iee-bndng-let.js | 47 +++++++++++++ .../module-code/instn-iee-bndng-let_.js | 18 +++++ .../module-code/instn-iee-bndng-var.js | 55 +++++++++++++++ .../module-code/instn-iee-bndng-var_.js | 18 +++++ .../module-code/instn-iee-err-ambiguous-1_.js | 4 ++ .../module-code/instn-iee-err-ambiguous-2_.js | 4 ++ .../module-code/instn-iee-err-ambiguous-as.js | 37 ++++++++++ .../module-code/instn-iee-err-ambiguous.js | 37 ++++++++++ .../module-code/instn-iee-err-ambiguous_.js | 5 ++ .../module-code/instn-iee-err-circular-as.js | 26 +++++++ .../module-code/instn-iee-err-circular.js | 26 +++++++ .../module-code/instn-iee-err-circular_.js | 4 ++ .../instn-iee-err-dflt-thru-star-as.js | 25 +++++++ .../instn-iee-err-dflt-thru-star-dflt_.js | 5 ++ .../instn-iee-err-dflt-thru-star-int_.js | 4 ++ .../instn-iee-err-dflt-thru-star.js | 25 +++++++ .../module-code/instn-iee-err-not-found-as.js | 25 +++++++ .../instn-iee-err-not-found-empty_.js | 4 ++ .../module-code/instn-iee-err-not-found.js | 25 +++++++ .../module-code/instn-iee-iee-cycle-2_.js | 16 +++++ .../module-code/instn-iee-iee-cycle.js | 49 +++++++++++++ .../module-code/instn-iee-star-cycle-2_.js | 4 ++ .../instn-iee-star-cycle-indirect-x_.js | 7 ++ .../module-code/instn-iee-star-cycle.js | 25 +++++++ .../module-code/instn-iee-trlng-comma.js | 21 ++++++ .../module-code/instn-iee-trlng-comma_.js | 4 ++ .../module-code/instn-local-bndng-cls.js | 44 ++++++++++++ .../module-code/instn-local-bndng-const.js | 44 ++++++++++++ .../instn-local-bndng-export-cls.js | 30 ++++++++ .../instn-local-bndng-export-const.js | 29 ++++++++ .../instn-local-bndng-export-fun.js | 32 +++++++++ .../instn-local-bndng-export-gen.js | 32 +++++++++ .../instn-local-bndng-export-let.js | 29 ++++++++ .../instn-local-bndng-export-var.js | 32 +++++++++ .../module-code/instn-local-bndng-for-dup.js | 23 ++++++ .../module-code/instn-local-bndng-for.js | 36 ++++++++++ .../module-code/instn-local-bndng-fun.js | 49 +++++++++++++ .../module-code/instn-local-bndng-gen.js | 50 +++++++++++++ .../module-code/instn-local-bndng-let.js | 44 ++++++++++++ .../module-code/instn-local-bndng-var-dup.js | 23 ++++++ .../module-code/instn-local-bndng-var.js | 37 ++++++++++ .../module-code/instn-named-bndng-cls.js | 46 ++++++++++++ .../module-code/instn-named-bndng-const.js | 46 ++++++++++++ .../module-code/instn-named-bndng-dflt-cls.js | 39 +++++++++++ .../instn-named-bndng-dflt-expr.js | 37 ++++++++++ .../instn-named-bndng-dflt-fun-anon.js | 50 +++++++++++++ .../instn-named-bndng-dflt-fun-named.js | 50 +++++++++++++ .../instn-named-bndng-dflt-gen-anon.js | 52 ++++++++++++++ .../instn-named-bndng-dflt-gen-named.js | 52 ++++++++++++++ .../instn-named-bndng-dflt-named.js | 27 +++++++ .../instn-named-bndng-dflt-star.js | 28 ++++++++ .../module-code/instn-named-bndng-fun.js | 57 +++++++++++++++ .../module-code/instn-named-bndng-gen.js | 58 +++++++++++++++ .../module-code/instn-named-bndng-let.js | 46 ++++++++++++ .../instn-named-bndng-trlng-comma.js | 54 ++++++++++++++ .../module-code/instn-named-bndng-var.js | 52 ++++++++++++++ .../instn-named-err-ambiguous-1_.js | 4 ++ .../instn-named-err-ambiguous-2_.js | 4 ++ .../instn-named-err-ambiguous-as.js | 42 +++++++++++ .../module-code/instn-named-err-ambiguous.js | 42 +++++++++++ .../module-code/instn-named-err-ambiguous_.js | 5 ++ .../instn-named-err-dflt-thru-star-as.js | 30 ++++++++ .../instn-named-err-dflt-thru-star-dflt.js | 30 ++++++++ .../instn-named-err-dflt-thru-star-dflt_.js | 5 ++ .../instn-named-err-dflt-thru-star-int_.js | 4 ++ .../instn-named-err-not-found-as.js | 30 ++++++++ .../instn-named-err-not-found-dflt.js | 30 ++++++++ .../instn-named-err-not-found-empty_.js | 4 ++ .../module-code/instn-named-err-not-found.js | 30 ++++++++ .../module-code/instn-named-id-name.js | 53 ++++++++++++++ .../module-code/instn-named-iee-cycle-2_.js | 16 +++++ .../module-code/instn-named-iee-cycle.js | 60 ++++++++++++++++ .../module-code/instn-named-star-cycle-2_.js | 4 ++ .../instn-named-star-cycle-indirect-x_.js | 7 ++ .../module-code/instn-named-star-cycle.js | 34 +++++++++ test/language/module-code/instn-once.js | 33 +++++++++ .../module-code/instn-resolve-empty-export.js | 36 ++++++++++ .../instn-resolve-empty-export_.js | 4 ++ .../module-code/instn-resolve-empty-import.js | 42 +++++++++++ .../instn-resolve-empty-import_.js | 4 ++ .../instn-resolve-err-reference.js | 17 +++++ .../instn-resolve-err-reference_.js | 4 ++ .../module-code/instn-resolve-err-syntax.js | 17 +++++ .../module-code/instn-resolve-err-syntax_.js | 4 ++ .../instn-resolve-order-depth-child_.js | 4 ++ .../instn-resolve-order-depth-reference_.js | 4 ++ .../instn-resolve-order-depth-syntax_.js | 4 ++ .../module-code/instn-resolve-order-depth.js | 11 +++ .../instn-resolve-order-src-reference_.js | 4 ++ .../instn-resolve-order-src-syntax_.js | 4 ++ .../instn-resolve-order-src-valid_.js | 4 ++ .../module-code/instn-resolve-order-src.js | 12 ++++ .../module-code/instn-same-global-set_.js | 4 ++ .../language/module-code/instn-same-global.js | 19 +++++ .../module-code/instn-star-ambiguous-1_.js | 5 ++ .../module-code/instn-star-ambiguous-2_.js | 5 ++ .../module-code/instn-star-ambiguous.js | 35 ++++++++++ .../module-code/instn-star-ambiguous_.js | 5 ++ .../module-code/instn-star-binding.js | 31 ++++++++ .../module-code/instn-star-equality-other_.js | 5 ++ .../module-code/instn-star-equality.js | 43 ++++++++++++ .../instn-star-err-not-found-empty_.js | 4 ++ .../instn-star-err-not-found-faulty_.js | 4 ++ .../module-code/instn-star-err-not-found.js | 29 ++++++++ .../module-code/instn-star-id-name.js | 45 ++++++++++++ .../module-code/instn-star-iee-cycle-2_.js | 16 +++++ .../module-code/instn-star-iee-cycle.js | 55 +++++++++++++++ .../instn-star-props-circular-a_.js | 5 ++ .../instn-star-props-circular-b_.js | 5 ++ .../module-code/instn-star-props-circular.js | 40 +++++++++++ ...nstn-star-props-dflt-keep-indirect-def_.js | 4 ++ ...star-props-dflt-keep-indirect-reexport_.js | 4 ++ .../instn-star-props-dflt-keep-indirect.js | 35 ++++++++++ ...instn-star-props-dflt-keep-local-named_.js | 5 ++ .../instn-star-props-dflt-keep-local-prod_.js | 4 ++ .../instn-star-props-dflt-keep-local.js | 40 +++++++++++ .../instn-star-props-dflt-skip-named_.js | 6 ++ .../instn-star-props-dflt-skip-prod_.js | 5 ++ .../instn-star-props-dflt-skip-star-named_.js | 4 ++ .../instn-star-props-dflt-skip-star-prod_.js | 4 ++ .../module-code/instn-star-props-dflt-skip.js | 45 ++++++++++++ .../module-code/instn-star-props-nrml-1_.js | 24 +++++++ .../instn-star-props-nrml-indirect_.js | 5 ++ .../instn-star-props-nrml-star_.js | 22 ++++++ .../module-code/instn-star-props-nrml.js | 68 ++++++++++++++++++ .../module-code/instn-star-star-cycle-2_.js | 4 ++ .../instn-star-star-cycle-indirect-x_.js | 7 ++ .../module-code/instn-star-star-cycle.js | 29 ++++++++ .../module-code/instn-uniq-env-rec-other_.js | 16 +++++ .../module-code/instn-uniq-env-rec.js | 70 +++++++++++++++++++ 138 files changed, 3423 insertions(+) create mode 100644 test/language/module-code/instn-iee-bndng-cls.js create mode 100644 test/language/module-code/instn-iee-bndng-cls_.js create mode 100644 test/language/module-code/instn-iee-bndng-const.js create mode 100644 test/language/module-code/instn-iee-bndng-const_.js create mode 100644 test/language/module-code/instn-iee-bndng-fun.js create mode 100644 test/language/module-code/instn-iee-bndng-fun_.js create mode 100644 test/language/module-code/instn-iee-bndng-gen.js create mode 100644 test/language/module-code/instn-iee-bndng-gen_.js create mode 100644 test/language/module-code/instn-iee-bndng-let.js create mode 100644 test/language/module-code/instn-iee-bndng-let_.js create mode 100644 test/language/module-code/instn-iee-bndng-var.js create mode 100644 test/language/module-code/instn-iee-bndng-var_.js create mode 100644 test/language/module-code/instn-iee-err-ambiguous-1_.js create mode 100644 test/language/module-code/instn-iee-err-ambiguous-2_.js create mode 100644 test/language/module-code/instn-iee-err-ambiguous-as.js create mode 100644 test/language/module-code/instn-iee-err-ambiguous.js create mode 100644 test/language/module-code/instn-iee-err-ambiguous_.js create mode 100644 test/language/module-code/instn-iee-err-circular-as.js create mode 100644 test/language/module-code/instn-iee-err-circular.js create mode 100644 test/language/module-code/instn-iee-err-circular_.js create mode 100644 test/language/module-code/instn-iee-err-dflt-thru-star-as.js create mode 100644 test/language/module-code/instn-iee-err-dflt-thru-star-dflt_.js create mode 100644 test/language/module-code/instn-iee-err-dflt-thru-star-int_.js create mode 100644 test/language/module-code/instn-iee-err-dflt-thru-star.js create mode 100644 test/language/module-code/instn-iee-err-not-found-as.js create mode 100644 test/language/module-code/instn-iee-err-not-found-empty_.js create mode 100644 test/language/module-code/instn-iee-err-not-found.js create mode 100644 test/language/module-code/instn-iee-iee-cycle-2_.js create mode 100644 test/language/module-code/instn-iee-iee-cycle.js create mode 100644 test/language/module-code/instn-iee-star-cycle-2_.js create mode 100644 test/language/module-code/instn-iee-star-cycle-indirect-x_.js create mode 100644 test/language/module-code/instn-iee-star-cycle.js create mode 100644 test/language/module-code/instn-iee-trlng-comma.js create mode 100644 test/language/module-code/instn-iee-trlng-comma_.js create mode 100644 test/language/module-code/instn-local-bndng-cls.js create mode 100644 test/language/module-code/instn-local-bndng-const.js create mode 100644 test/language/module-code/instn-local-bndng-export-cls.js create mode 100644 test/language/module-code/instn-local-bndng-export-const.js create mode 100644 test/language/module-code/instn-local-bndng-export-fun.js create mode 100644 test/language/module-code/instn-local-bndng-export-gen.js create mode 100644 test/language/module-code/instn-local-bndng-export-let.js create mode 100644 test/language/module-code/instn-local-bndng-export-var.js create mode 100644 test/language/module-code/instn-local-bndng-for-dup.js create mode 100644 test/language/module-code/instn-local-bndng-for.js create mode 100644 test/language/module-code/instn-local-bndng-fun.js create mode 100644 test/language/module-code/instn-local-bndng-gen.js create mode 100644 test/language/module-code/instn-local-bndng-let.js create mode 100644 test/language/module-code/instn-local-bndng-var-dup.js create mode 100644 test/language/module-code/instn-local-bndng-var.js create mode 100644 test/language/module-code/instn-named-bndng-cls.js create mode 100644 test/language/module-code/instn-named-bndng-const.js create mode 100644 test/language/module-code/instn-named-bndng-dflt-cls.js create mode 100644 test/language/module-code/instn-named-bndng-dflt-expr.js create mode 100644 test/language/module-code/instn-named-bndng-dflt-fun-anon.js create mode 100644 test/language/module-code/instn-named-bndng-dflt-fun-named.js create mode 100644 test/language/module-code/instn-named-bndng-dflt-gen-anon.js create mode 100644 test/language/module-code/instn-named-bndng-dflt-gen-named.js create mode 100644 test/language/module-code/instn-named-bndng-dflt-named.js create mode 100644 test/language/module-code/instn-named-bndng-dflt-star.js create mode 100644 test/language/module-code/instn-named-bndng-fun.js create mode 100644 test/language/module-code/instn-named-bndng-gen.js create mode 100644 test/language/module-code/instn-named-bndng-let.js create mode 100644 test/language/module-code/instn-named-bndng-trlng-comma.js create mode 100644 test/language/module-code/instn-named-bndng-var.js create mode 100644 test/language/module-code/instn-named-err-ambiguous-1_.js create mode 100644 test/language/module-code/instn-named-err-ambiguous-2_.js create mode 100644 test/language/module-code/instn-named-err-ambiguous-as.js create mode 100644 test/language/module-code/instn-named-err-ambiguous.js create mode 100644 test/language/module-code/instn-named-err-ambiguous_.js create mode 100644 test/language/module-code/instn-named-err-dflt-thru-star-as.js create mode 100644 test/language/module-code/instn-named-err-dflt-thru-star-dflt.js create mode 100644 test/language/module-code/instn-named-err-dflt-thru-star-dflt_.js create mode 100644 test/language/module-code/instn-named-err-dflt-thru-star-int_.js create mode 100644 test/language/module-code/instn-named-err-not-found-as.js create mode 100644 test/language/module-code/instn-named-err-not-found-dflt.js create mode 100644 test/language/module-code/instn-named-err-not-found-empty_.js create mode 100644 test/language/module-code/instn-named-err-not-found.js create mode 100644 test/language/module-code/instn-named-id-name.js create mode 100644 test/language/module-code/instn-named-iee-cycle-2_.js create mode 100644 test/language/module-code/instn-named-iee-cycle.js create mode 100644 test/language/module-code/instn-named-star-cycle-2_.js create mode 100644 test/language/module-code/instn-named-star-cycle-indirect-x_.js create mode 100644 test/language/module-code/instn-named-star-cycle.js create mode 100644 test/language/module-code/instn-once.js create mode 100644 test/language/module-code/instn-resolve-empty-export.js create mode 100644 test/language/module-code/instn-resolve-empty-export_.js create mode 100644 test/language/module-code/instn-resolve-empty-import.js create mode 100644 test/language/module-code/instn-resolve-empty-import_.js create mode 100644 test/language/module-code/instn-resolve-err-reference.js create mode 100644 test/language/module-code/instn-resolve-err-reference_.js create mode 100644 test/language/module-code/instn-resolve-err-syntax.js create mode 100644 test/language/module-code/instn-resolve-err-syntax_.js create mode 100644 test/language/module-code/instn-resolve-order-depth-child_.js create mode 100644 test/language/module-code/instn-resolve-order-depth-reference_.js create mode 100644 test/language/module-code/instn-resolve-order-depth-syntax_.js create mode 100644 test/language/module-code/instn-resolve-order-depth.js create mode 100644 test/language/module-code/instn-resolve-order-src-reference_.js create mode 100644 test/language/module-code/instn-resolve-order-src-syntax_.js create mode 100644 test/language/module-code/instn-resolve-order-src-valid_.js create mode 100644 test/language/module-code/instn-resolve-order-src.js create mode 100644 test/language/module-code/instn-same-global-set_.js create mode 100644 test/language/module-code/instn-same-global.js create mode 100644 test/language/module-code/instn-star-ambiguous-1_.js create mode 100644 test/language/module-code/instn-star-ambiguous-2_.js create mode 100644 test/language/module-code/instn-star-ambiguous.js create mode 100644 test/language/module-code/instn-star-ambiguous_.js create mode 100644 test/language/module-code/instn-star-binding.js create mode 100644 test/language/module-code/instn-star-equality-other_.js create mode 100644 test/language/module-code/instn-star-equality.js create mode 100644 test/language/module-code/instn-star-err-not-found-empty_.js create mode 100644 test/language/module-code/instn-star-err-not-found-faulty_.js create mode 100644 test/language/module-code/instn-star-err-not-found.js create mode 100644 test/language/module-code/instn-star-id-name.js create mode 100644 test/language/module-code/instn-star-iee-cycle-2_.js create mode 100644 test/language/module-code/instn-star-iee-cycle.js create mode 100644 test/language/module-code/instn-star-props-circular-a_.js create mode 100644 test/language/module-code/instn-star-props-circular-b_.js create mode 100644 test/language/module-code/instn-star-props-circular.js create mode 100644 test/language/module-code/instn-star-props-dflt-keep-indirect-def_.js create mode 100644 test/language/module-code/instn-star-props-dflt-keep-indirect-reexport_.js create mode 100644 test/language/module-code/instn-star-props-dflt-keep-indirect.js create mode 100644 test/language/module-code/instn-star-props-dflt-keep-local-named_.js create mode 100644 test/language/module-code/instn-star-props-dflt-keep-local-prod_.js create mode 100644 test/language/module-code/instn-star-props-dflt-keep-local.js create mode 100644 test/language/module-code/instn-star-props-dflt-skip-named_.js create mode 100644 test/language/module-code/instn-star-props-dflt-skip-prod_.js create mode 100644 test/language/module-code/instn-star-props-dflt-skip-star-named_.js create mode 100644 test/language/module-code/instn-star-props-dflt-skip-star-prod_.js create mode 100644 test/language/module-code/instn-star-props-dflt-skip.js create mode 100644 test/language/module-code/instn-star-props-nrml-1_.js create mode 100644 test/language/module-code/instn-star-props-nrml-indirect_.js create mode 100644 test/language/module-code/instn-star-props-nrml-star_.js create mode 100644 test/language/module-code/instn-star-props-nrml.js create mode 100644 test/language/module-code/instn-star-star-cycle-2_.js create mode 100644 test/language/module-code/instn-star-star-cycle-indirect-x_.js create mode 100644 test/language/module-code/instn-star-star-cycle.js create mode 100644 test/language/module-code/instn-uniq-env-rec-other_.js create mode 100644 test/language/module-code/instn-uniq-env-rec.js 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 0000000000..07461cc0c3 --- /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 0000000000..c32dc3bd5b --- /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 0000000000..11cc633a5a --- /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 0000000000..1cb195a073 --- /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 0000000000..1b2f761bd6 --- /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 0000000000..fb941814ba --- /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 0000000000..df3089f879 --- /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 0000000000..8e06c457dd --- /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 0000000000..2e3c7f3ab4 --- /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 0000000000..bfe3d7c510 --- /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 0000000000..762d0603c4 --- /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 0000000000..5cbe15a99f --- /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 0000000000..896bdff50a --- /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 0000000000..896bdff50a --- /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 0000000000..b231b3282b --- /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 0000000000..d3d1337440 --- /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 0000000000..6984d00947 --- /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 0000000000..28d0396ec0 --- /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 0000000000..5336509498 --- /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 0000000000..3d7fcb9634 --- /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 0000000000..cfcad271b7 --- /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 0000000000..b59a4bf511 --- /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 0000000000..025035eba7 --- /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 0000000000..45da1210ca --- /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 0000000000..d612a35cc9 --- /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 0000000000..e46c626cf4 --- /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 0000000000..94f8646396 --- /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 0000000000..e8e4e71bdc --- /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 0000000000..9607277b79 --- /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 0000000000..1a023020ca --- /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 0000000000..f729e84468 --- /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 0000000000..f6bbfa69f5 --- /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 0000000000..bcbd7000e1 --- /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 0000000000..6a70bc9d17 --- /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 0000000000..96f221ed0f --- /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 0000000000..d7b6324332 --- /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 0000000000..13196cf5d1 --- /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 0000000000..184405e4f9 --- /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 0000000000..6f40586228 --- /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 0000000000..bcb10b78a2 --- /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 0000000000..fdc74b7554 --- /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 0000000000..f5b84e35e9 --- /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 0000000000..64c3892e87 --- /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 0000000000..6da2854b05 --- /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 0000000000..fd5c23e1b1 --- /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 0000000000..0fa2c34e99 --- /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 0000000000..ec1ad20cca --- /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 0000000000..c3fbf3ae73 --- /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 0000000000..3ff9e2b980 --- /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 0000000000..f19daf7b71 --- /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 0000000000..c334fb9b48 --- /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 0000000000..92cfdb5671 --- /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 0000000000..b6e2be52a4 --- /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 0000000000..6bf822ca7d --- /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 0000000000..193ae531a2 --- /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 0000000000..e17ea4829b --- /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 0000000000..060f72c730 --- /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 0000000000..fae2a6ae89 --- /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 0000000000..a31216d95b --- /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 0000000000..43685aa8d7 --- /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 0000000000..0917e664ac --- /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 0000000000..9dc7b66dc9 --- /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 0000000000..d0a9daf214 --- /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 0000000000..eff20f6104 --- /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 0000000000..896bdff50a --- /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 0000000000..896bdff50a --- /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 0000000000..6ab232a4d0 --- /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 0000000000..0c53a94ea6 --- /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 0000000000..9cb1b46cfc --- /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 0000000000..16fc554cd7 --- /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 0000000000..1312a81bc4 --- /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 0000000000..b59a4bf511 --- /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 0000000000..fcd60646ef --- /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 0000000000..df49d213d9 --- /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 0000000000..fc649aaf74 --- /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 0000000000..e46c626cf4 --- /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 0000000000..2e442d0dd8 --- /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 0000000000..985d58b265 --- /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 0000000000..887728551a --- /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 0000000000..ee4973adb8 --- /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 0000000000..daeedae49a --- /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 0000000000..d212ba5fc3 --- /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 0000000000..b08b57120f --- /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 0000000000..dd859ffa5c --- /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 0000000000..24215e0d3c --- /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 0000000000..c0d877a869 --- /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 0000000000..87fd8a1ae4 --- /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 0000000000..c0d877a869 --- /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 0000000000..b691f71b69 --- /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 0000000000..c0d877a869 --- /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 0000000000..b2787e788b --- /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 0000000000..6ab6af47de --- /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 0000000000..b1b41e7000 --- /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 0000000000..c0d877a869 --- /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 0000000000..6ab6af47de --- /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 0000000000..ffeb90a198 --- /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 0000000000..c0d877a869 --- /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 0000000000..6ab6af47de --- /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 0000000000..e46c626cf4 --- /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 0000000000..501ebe138a --- /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 0000000000..73ca298c7f --- /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 0000000000..f49d014b7f --- /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 0000000000..1c568f1f54 --- /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 0000000000..2f783f472a --- /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 0000000000..9e32067ee8 --- /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 0000000000..ab96a95cbc --- /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 0000000000..7b90bf32a7 --- /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 0000000000..2169a1e48c --- /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 0000000000..f1b2e920fa --- /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 0000000000..e46c626cf4 --- /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 0000000000..e4bef5ebd6 --- /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 0000000000..ece6a63beb --- /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 0000000000..8c83ddf219 --- /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 0000000000..cb2cf21906 --- /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 0000000000..c8b58d0aef --- /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 0000000000..165a825fb9 --- /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 0000000000..b12e23fec0 --- /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 0000000000..1e6ffdbac6 --- /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 0000000000..ca281f94c6 --- /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 0000000000..16bd139704 --- /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 0000000000..896b4dfe9e --- /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 0000000000..fde22294b4 --- /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 0000000000..ca281f94c6 --- /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 0000000000..e1f838a6e2 --- /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 0000000000..69647d7414 --- /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 0000000000..fd5927ef47 --- /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 0000000000..05705983a9 --- /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 0000000000..e3ec18109f --- /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 0000000000..0e096b38ee --- /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 0000000000..5b70c0746c --- /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 0000000000..cfdf45fe06 --- /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 0000000000..9ae922721a --- /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 0000000000..df2a9f1380 --- /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 0000000000..fef0cb811d --- /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 0000000000..d8f4f09c91 --- /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 0000000000..87282db695 --- /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 0000000000..fefd111898 --- /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 0000000000..f413ed1c2d --- /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; +});