Add some more cases for import()

This commit is contained in:
Leo Balter 2018-10-18 15:21:00 -04:00 committed by Rick Waldron
parent f1b337cf55
commit e620039286
6 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,2 @@
// Copyright (C) 2018 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

View File

@ -0,0 +1,10 @@
// Copyright (C) 2018 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
// exports: default === 42, local1 === 'Test262', renamed === 'TC39', indirect === 'Test262'
export var local1 = 'Test262';
var local2 = 'TC39';
export { local2 as renamed };
export { local1 as indirect } from './module-code_FIXTURE.js';
export default 42;

View File

@ -0,0 +1,33 @@
// Copyright (C) 2018 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The default property is not set the if the module doesn't export any default
esid: sec-finishdynamicimport
features: [dynamic-import]
flags: [async]
info: |
Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion )
1. If completion is an abrupt completion, ...
2. Otherwise,
...
d. Let namespace be GetModuleNamespace(moduleRecord).
e. If namespace is an abrupt completion, perform ! Call(promiseCapability.[[Reject]], undefined, « namespace.[[Value]] »).
f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »).
Runtime Semantics: GetModuleNamespace ( module )
...
3. Let namespace be module.[[Namespace]].
4. If namespace is undefined, then
...
d. Set namespace to ModuleNamespaceCreate(module, unambiguousNames).
5. Return namespace.
---*/
import('./default-property-not-set-own.js').then(ns => {
assert.sameValue(Object.prototype.hasOwnProperty.call(ns, 'default'), false);
}).then($DONE, $DONE).catch($DONE);

View File

@ -0,0 +1,38 @@
// Copyright (C) 2018 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Reuse the resolved namespace object already imported from a static import
esid: sec-import-call-runtime-semantics-evaluation
info: |
Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion )
1. If completion is an abrupt completion, ...
2. Otherwise,
...
d. Let namespace be GetModuleNamespace(moduleRecord).
e. If namespace is an abrupt completion, perform ! Call(promiseCapability.[[Reject]], undefined, « namespace.[[Value]] »).
f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »).
Runtime Semantics: GetModuleNamespace ( module )
...
3. Let namespace be module.[[Namespace]].
4. If namespace is undefined, then
...
d. Set namespace to ModuleNamespaceCreate(module, unambiguousNames).
5. Return namespace.
features: [dynamic-import]
flags: [async, module]
---*/
import * as ns from './module-code_FIXTURE.js';
Promise.all([
import('./module-code_FIXTURE.js'),
import('./module-code_FIXTURE.js'),
]).then(([a, b]) => {
assert.sameValue(a, b, 'it returns the same namespace are the same');
assert.sameValue(a, ns, 'dynamic imported a is the same object as ns');
assert.sameValue(b, ns, 'dynamic imported b is the same object as ns');
}).then($DONE, $DONE);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2018 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Reuse the resolved namespace object from a script code.
esid: sec-import-call-runtime-semantics-evaluation
info: |
Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion )
1. If completion is an abrupt completion, ...
2. Otherwise,
...
d. Let namespace be GetModuleNamespace(moduleRecord).
e. If namespace is an abrupt completion, perform ! Call(promiseCapability.[[Reject]], undefined, « namespace.[[Value]] »).
f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »).
Runtime Semantics: GetModuleNamespace ( module )
...
3. Let namespace be module.[[Namespace]].
4. If namespace is undefined, then
...
d. Set namespace to ModuleNamespaceCreate(module, unambiguousNames).
5. Return namespace.
features: [dynamic-import]
flags: [async]
---*/
// empty_FIXTURE.js does not export anything, so it wouldn't suit for a module code exported namespace
// we use this to assume it's a close example to a script code imported.
Promise.all([
import('./empty_FIXTURE.js'),
import('./empty_FIXTURE.js'),
]).then(([a, b]) => {
assert.sameValue(a, b, 'it returns the same namespace are the same');
}).then($DONE, $DONE);

View File

@ -0,0 +1,34 @@
// Copyright (C) 2018 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Reuse the resolved namespace object instead of creating a new one
esid: sec-import-call-runtime-semantics-evaluation
info: |
Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion )
1. If completion is an abrupt completion, ...
2. Otherwise,
...
d. Let namespace be GetModuleNamespace(moduleRecord).
e. If namespace is an abrupt completion, perform ! Call(promiseCapability.[[Reject]], undefined, « namespace.[[Value]] »).
f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »).
Runtime Semantics: GetModuleNamespace ( module )
...
3. Let namespace be module.[[Namespace]].
4. If namespace is undefined, then
...
d. Set namespace to ModuleNamespaceCreate(module, unambiguousNames).
5. Return namespace.
features: [dynamic-import]
flags: [async]
---*/
Promise.all([
import('./dynamic-import-module_FIXTURE.js'),
import('./dynamic-import-module_FIXTURE.js'),
]).then(([a, b]) => {
assert.sameValue(a, b, 'it returns the same namespace are the same');
}).then($DONE, $DONE);