From e620039286cbbb04d02e93811644d1842b9d60c8 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Thu, 18 Oct 2018 15:21:00 -0400 Subject: [PATCH] Add some more cases for import() --- .../dynamic-import/empty_FIXTURE.js | 2 + .../dynamic-import/module-code_FIXTURE.js | 10 +++++ .../ns/default-property-not-set-own.js | 33 ++++++++++++++++ .../reuse-namespace-object-from-import.js | 38 +++++++++++++++++++ .../reuse-namespace-object-from-script.js | 36 ++++++++++++++++++ .../dynamic-import/reuse-namespace-object.js | 34 +++++++++++++++++ 6 files changed, 153 insertions(+) create mode 100644 test/language/module-code/dynamic-import/empty_FIXTURE.js create mode 100644 test/language/module-code/dynamic-import/module-code_FIXTURE.js create mode 100644 test/language/module-code/dynamic-import/ns/default-property-not-set-own.js create mode 100644 test/language/module-code/dynamic-import/reuse-namespace-object-from-import.js create mode 100644 test/language/module-code/dynamic-import/reuse-namespace-object-from-script.js create mode 100644 test/language/module-code/dynamic-import/reuse-namespace-object.js diff --git a/test/language/module-code/dynamic-import/empty_FIXTURE.js b/test/language/module-code/dynamic-import/empty_FIXTURE.js new file mode 100644 index 0000000000..96a3b85954 --- /dev/null +++ b/test/language/module-code/dynamic-import/empty_FIXTURE.js @@ -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. diff --git a/test/language/module-code/dynamic-import/module-code_FIXTURE.js b/test/language/module-code/dynamic-import/module-code_FIXTURE.js new file mode 100644 index 0000000000..62cb5ae821 --- /dev/null +++ b/test/language/module-code/dynamic-import/module-code_FIXTURE.js @@ -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; diff --git a/test/language/module-code/dynamic-import/ns/default-property-not-set-own.js b/test/language/module-code/dynamic-import/ns/default-property-not-set-own.js new file mode 100644 index 0000000000..d09ff13e6f --- /dev/null +++ b/test/language/module-code/dynamic-import/ns/default-property-not-set-own.js @@ -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); diff --git a/test/language/module-code/dynamic-import/reuse-namespace-object-from-import.js b/test/language/module-code/dynamic-import/reuse-namespace-object-from-import.js new file mode 100644 index 0000000000..ee932eb016 --- /dev/null +++ b/test/language/module-code/dynamic-import/reuse-namespace-object-from-import.js @@ -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); diff --git a/test/language/module-code/dynamic-import/reuse-namespace-object-from-script.js b/test/language/module-code/dynamic-import/reuse-namespace-object-from-script.js new file mode 100644 index 0000000000..bf30e85fb2 --- /dev/null +++ b/test/language/module-code/dynamic-import/reuse-namespace-object-from-script.js @@ -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); diff --git a/test/language/module-code/dynamic-import/reuse-namespace-object.js b/test/language/module-code/dynamic-import/reuse-namespace-object.js new file mode 100644 index 0000000000..1abec9297b --- /dev/null +++ b/test/language/module-code/dynamic-import/reuse-namespace-object.js @@ -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);