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.
2016-03-29 17:50:15 +02:00
|
|
|
// 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() {
|
Refactor module _FIXTURE.js to have no harness dependencies (#2129)
rwaldron in ~/clonez/test262 on master
$ test262_runner test/language/module-code/instn-iee-bndng-{cls,const,fun,gen,let,var}.js
-----------------------------------------------------------------------------------------
V8 (jsvu)
test262-harness --hostArgs='' --hostType=d8 --hostPath=/Users/rwaldron/.jsvu/v8 test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
ChakraCore (jsvu)
test262-harness --hostArgs='' --hostType=ch --hostPath=/Users/rwaldron/.jsvu/chakra test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
JavaScriptCore (jsvu)
test262-harness --hostArgs='' --hostType=jsc --hostPath=/Users/rwaldron/.jsvu/javascriptcore test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
SpiderMonkey (jsvu)
test262-harness --hostArgs='' --hostType=jsshell --hostPath=/Users/rwaldron/.jsvu/sm test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
Moddable (jsvu)
test262-harness --hostArgs='' --hostType=xs --hostPath=/Users/rwaldron/.jsvu/xs test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
rwaldron in ~/clonez/test262 on refactor-fixtures-to-eliminate-harness-file-dependencies
$ test262_runner test/language/module-code/instn-iee-bndng-{cls,const,fun,gen,let,var}.js
-----------------------------------------------------------------------------------------
V8 (jsvu)
test262-harness --hostArgs='' --hostType=d8 --hostPath=/Users/rwaldron/.jsvu/v8 test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
ChakraCore (jsvu)
test262-harness --hostArgs='' --hostType=ch --hostPath=/Users/rwaldron/.jsvu/chakra test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
JavaScriptCore (jsvu)
test262-harness --hostArgs='' --hostType=jsc --hostPath=/Users/rwaldron/.jsvu/javascriptcore test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
SpiderMonkey (jsvu)
test262-harness --hostArgs='' --hostType=jsshell --hostPath=/Users/rwaldron/.jsvu/sm test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
Moddable (jsvu)
test262-harness --hostArgs='' --hostType=xs --hostPath=/Users/rwaldron/.jsvu/xs test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
2019-04-17 21:44:02 +02:00
|
|
|
typeof B;
|
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.
2016-03-29 17:50:15 +02:00
|
|
|
}, 'binding is created but not initialized');
|
|
|
|
|
Refactor module _FIXTURE.js to have no harness dependencies (#2129)
rwaldron in ~/clonez/test262 on master
$ test262_runner test/language/module-code/instn-iee-bndng-{cls,const,fun,gen,let,var}.js
-----------------------------------------------------------------------------------------
V8 (jsvu)
test262-harness --hostArgs='' --hostType=d8 --hostPath=/Users/rwaldron/.jsvu/v8 test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
ChakraCore (jsvu)
test262-harness --hostArgs='' --hostType=ch --hostPath=/Users/rwaldron/.jsvu/chakra test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
JavaScriptCore (jsvu)
test262-harness --hostArgs='' --hostType=jsc --hostPath=/Users/rwaldron/.jsvu/javascriptcore test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
SpiderMonkey (jsvu)
test262-harness --hostArgs='' --hostType=jsshell --hostPath=/Users/rwaldron/.jsvu/sm test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
Moddable (jsvu)
test262-harness --hostArgs='' --hostType=xs --hostPath=/Users/rwaldron/.jsvu/xs test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
rwaldron in ~/clonez/test262 on refactor-fixtures-to-eliminate-harness-file-dependencies
$ test262_runner test/language/module-code/instn-iee-bndng-{cls,const,fun,gen,let,var}.js
-----------------------------------------------------------------------------------------
V8 (jsvu)
test262-harness --hostArgs='' --hostType=d8 --hostPath=/Users/rwaldron/.jsvu/v8 test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
ChakraCore (jsvu)
test262-harness --hostArgs='' --hostType=ch --hostPath=/Users/rwaldron/.jsvu/chakra test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
JavaScriptCore (jsvu)
test262-harness --hostArgs='' --hostType=jsc --hostPath=/Users/rwaldron/.jsvu/javascriptcore test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
SpiderMonkey (jsvu)
test262-harness --hostArgs='' --hostType=jsshell --hostPath=/Users/rwaldron/.jsvu/sm test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
-----------------------------------------------------------------------------------------
Moddable (jsvu)
test262-harness --hostArgs='' --hostType=xs --hostPath=/Users/rwaldron/.jsvu/xs test/language/module-code/instn-iee-bndng-cls.js test/language/module-code/instn-iee-bndng-const.js test/language/module-code/instn-iee-bndng-fun.js test/language/module-code/instn-iee-bndng-gen.js test/language/module-code/instn-iee-bndng-let.js test/language/module-code/instn-iee-bndng-var.js
Ran 12 tests
12 passed
0 failed
2019-04-17 21:44:02 +02:00
|
|
|
import { B, results } from './instn-iee-bndng-const_FIXTURE.js';
|
|
|
|
export const A = null;
|
|
|
|
|
|
|
|
assert.sameValue(results.length, 4);
|
|
|
|
assert.sameValue(results[0], 'ReferenceError');
|
|
|
|
assert.sameValue(results[1], 'undefined');
|
|
|
|
assert.sameValue(results[2], 'ReferenceError');
|
|
|
|
assert.sameValue(results[3], 'undefined');
|