From aebfbdd9dfa2c03cdb21f48d3d2dd262387638e0 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Mon, 22 Oct 2018 16:16:50 -0400 Subject: [PATCH] Add more edgy cases for import() Also rename test/language/expressions/dynamic-import/assignment-expression/ --- .../additive-expr.js | 0 .../array-literal.js | 0 .../arrow-function.js | 0 .../await-expr.js | 0 .../await-identifier.js | 0 .../call-expr-arguments.js | 0 .../call-expr-expr.js | 0 .../call-expr-identifier.js | 0 .../cover-call-expr.js | 0 .../cover-parenthesized-expr.js | 0 .../identifier.js | 0 .../lhs-assign-operator-assign-expr.js | 0 .../lhs-eq-assign-expr-nostrict.js | 0 .../lhs-eq-assign-expr.js | 0 .../logical-and-expr.js | 0 .../logical-or-expr.js | 0 .../member-expr.js | 0 .../module-code-other_FIXTURE.js | 2 +- .../module-code_FIXTURE.js | 0 .../new-target.js | 0 .../object-literal.js | 0 .../tagged-function-call.js | 0 .../ternary.js | 0 .../this.js | 0 .../unary-expr.js | 0 .../yield-assign-expr.js | 0 .../yield-expr.js | 0 .../yield-identifier.js | 0 .../yield-star.js | 0 .../dynamic-import/await-import-evaluation.js | 24 +++++++ .../await-import-evaluation_FIXTURE.js | 14 ++++ ...or-await-resolution-and-error-a_FIXTURE.js | 4 ++ ...r-await-resolution-and-error-agen-yield.js | 69 +++++++++++++++++++ .../for-await-resolution-and-error-agen.js | 51 ++++++++++++++ ...or-await-resolution-and-error-b_FIXTURE.js | 4 ++ ...t-resolution-and-error-poisoned_FIXTURE.js | 4 ++ .../for-await-resolution-and-error.js | 37 ++++++++++ .../dynamic-import/imported-self-update.js | 32 +++++++++ .../indirect-resolution-1_FIXTURE.js | 4 ++ .../indirect-resolution-2_FIXTURE.js | 4 ++ .../dynamic-import/indirect-resolution.js | 31 +++++++++ 41 files changed, 279 insertions(+), 1 deletion(-) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/additive-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/array-literal.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/arrow-function.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/await-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/await-identifier.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/call-expr-arguments.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/call-expr-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/call-expr-identifier.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/cover-call-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/cover-parenthesized-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/identifier.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/lhs-assign-operator-assign-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/lhs-eq-assign-expr-nostrict.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/lhs-eq-assign-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/logical-and-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/logical-or-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/member-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/module-code-other_FIXTURE.js (83%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/module-code_FIXTURE.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/new-target.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/object-literal.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/tagged-function-call.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/ternary.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/this.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/unary-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/yield-assign-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/yield-expr.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/yield-identifier.js (100%) rename test/language/expressions/dynamic-import/{assign-expr => assignment-expression}/yield-star.js (100%) create mode 100644 test/language/expressions/dynamic-import/await-import-evaluation.js create mode 100644 test/language/expressions/dynamic-import/await-import-evaluation_FIXTURE.js create mode 100644 test/language/expressions/dynamic-import/for-await-resolution-and-error-a_FIXTURE.js create mode 100644 test/language/expressions/dynamic-import/for-await-resolution-and-error-agen-yield.js create mode 100644 test/language/expressions/dynamic-import/for-await-resolution-and-error-agen.js create mode 100644 test/language/expressions/dynamic-import/for-await-resolution-and-error-b_FIXTURE.js create mode 100644 test/language/expressions/dynamic-import/for-await-resolution-and-error-poisoned_FIXTURE.js create mode 100644 test/language/expressions/dynamic-import/for-await-resolution-and-error.js create mode 100644 test/language/expressions/dynamic-import/imported-self-update.js create mode 100644 test/language/expressions/dynamic-import/indirect-resolution-1_FIXTURE.js create mode 100644 test/language/expressions/dynamic-import/indirect-resolution-2_FIXTURE.js create mode 100644 test/language/expressions/dynamic-import/indirect-resolution.js diff --git a/test/language/expressions/dynamic-import/assign-expr/additive-expr.js b/test/language/expressions/dynamic-import/assignment-expression/additive-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/additive-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/additive-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/array-literal.js b/test/language/expressions/dynamic-import/assignment-expression/array-literal.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/array-literal.js rename to test/language/expressions/dynamic-import/assignment-expression/array-literal.js diff --git a/test/language/expressions/dynamic-import/assign-expr/arrow-function.js b/test/language/expressions/dynamic-import/assignment-expression/arrow-function.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/arrow-function.js rename to test/language/expressions/dynamic-import/assignment-expression/arrow-function.js diff --git a/test/language/expressions/dynamic-import/assign-expr/await-expr.js b/test/language/expressions/dynamic-import/assignment-expression/await-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/await-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/await-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/await-identifier.js b/test/language/expressions/dynamic-import/assignment-expression/await-identifier.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/await-identifier.js rename to test/language/expressions/dynamic-import/assignment-expression/await-identifier.js diff --git a/test/language/expressions/dynamic-import/assign-expr/call-expr-arguments.js b/test/language/expressions/dynamic-import/assignment-expression/call-expr-arguments.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/call-expr-arguments.js rename to test/language/expressions/dynamic-import/assignment-expression/call-expr-arguments.js diff --git a/test/language/expressions/dynamic-import/assign-expr/call-expr-expr.js b/test/language/expressions/dynamic-import/assignment-expression/call-expr-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/call-expr-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/call-expr-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/call-expr-identifier.js b/test/language/expressions/dynamic-import/assignment-expression/call-expr-identifier.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/call-expr-identifier.js rename to test/language/expressions/dynamic-import/assignment-expression/call-expr-identifier.js diff --git a/test/language/expressions/dynamic-import/assign-expr/cover-call-expr.js b/test/language/expressions/dynamic-import/assignment-expression/cover-call-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/cover-call-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/cover-call-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/cover-parenthesized-expr.js b/test/language/expressions/dynamic-import/assignment-expression/cover-parenthesized-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/cover-parenthesized-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/cover-parenthesized-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/identifier.js b/test/language/expressions/dynamic-import/assignment-expression/identifier.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/identifier.js rename to test/language/expressions/dynamic-import/assignment-expression/identifier.js diff --git a/test/language/expressions/dynamic-import/assign-expr/lhs-assign-operator-assign-expr.js b/test/language/expressions/dynamic-import/assignment-expression/lhs-assign-operator-assign-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/lhs-assign-operator-assign-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/lhs-assign-operator-assign-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/lhs-eq-assign-expr-nostrict.js b/test/language/expressions/dynamic-import/assignment-expression/lhs-eq-assign-expr-nostrict.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/lhs-eq-assign-expr-nostrict.js rename to test/language/expressions/dynamic-import/assignment-expression/lhs-eq-assign-expr-nostrict.js diff --git a/test/language/expressions/dynamic-import/assign-expr/lhs-eq-assign-expr.js b/test/language/expressions/dynamic-import/assignment-expression/lhs-eq-assign-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/lhs-eq-assign-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/lhs-eq-assign-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/logical-and-expr.js b/test/language/expressions/dynamic-import/assignment-expression/logical-and-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/logical-and-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/logical-and-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/logical-or-expr.js b/test/language/expressions/dynamic-import/assignment-expression/logical-or-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/logical-or-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/logical-or-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/member-expr.js b/test/language/expressions/dynamic-import/assignment-expression/member-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/member-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/member-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/module-code-other_FIXTURE.js b/test/language/expressions/dynamic-import/assignment-expression/module-code-other_FIXTURE.js similarity index 83% rename from test/language/expressions/dynamic-import/assign-expr/module-code-other_FIXTURE.js rename to test/language/expressions/dynamic-import/assignment-expression/module-code-other_FIXTURE.js index 284528dbb0..7143b277c0 100644 --- a/test/language/expressions/dynamic-import/assign-expr/module-code-other_FIXTURE.js +++ b/test/language/expressions/dynamic-import/assignment-expression/module-code-other_FIXTURE.js @@ -6,5 +6,5 @@ export var local1 = 'one six one two'; var local2 = 'star'; export { local2 as renamed }; -export { local1 as indirect } from './module-code_FIXTURE.js'; +export { local1 as indirect } from './module-code-other_FIXTURE.js'; export default 1612; diff --git a/test/language/expressions/dynamic-import/assign-expr/module-code_FIXTURE.js b/test/language/expressions/dynamic-import/assignment-expression/module-code_FIXTURE.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/module-code_FIXTURE.js rename to test/language/expressions/dynamic-import/assignment-expression/module-code_FIXTURE.js diff --git a/test/language/expressions/dynamic-import/assign-expr/new-target.js b/test/language/expressions/dynamic-import/assignment-expression/new-target.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/new-target.js rename to test/language/expressions/dynamic-import/assignment-expression/new-target.js diff --git a/test/language/expressions/dynamic-import/assign-expr/object-literal.js b/test/language/expressions/dynamic-import/assignment-expression/object-literal.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/object-literal.js rename to test/language/expressions/dynamic-import/assignment-expression/object-literal.js diff --git a/test/language/expressions/dynamic-import/assign-expr/tagged-function-call.js b/test/language/expressions/dynamic-import/assignment-expression/tagged-function-call.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/tagged-function-call.js rename to test/language/expressions/dynamic-import/assignment-expression/tagged-function-call.js diff --git a/test/language/expressions/dynamic-import/assign-expr/ternary.js b/test/language/expressions/dynamic-import/assignment-expression/ternary.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/ternary.js rename to test/language/expressions/dynamic-import/assignment-expression/ternary.js diff --git a/test/language/expressions/dynamic-import/assign-expr/this.js b/test/language/expressions/dynamic-import/assignment-expression/this.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/this.js rename to test/language/expressions/dynamic-import/assignment-expression/this.js diff --git a/test/language/expressions/dynamic-import/assign-expr/unary-expr.js b/test/language/expressions/dynamic-import/assignment-expression/unary-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/unary-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/unary-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/yield-assign-expr.js b/test/language/expressions/dynamic-import/assignment-expression/yield-assign-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/yield-assign-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/yield-assign-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/yield-expr.js b/test/language/expressions/dynamic-import/assignment-expression/yield-expr.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/yield-expr.js rename to test/language/expressions/dynamic-import/assignment-expression/yield-expr.js diff --git a/test/language/expressions/dynamic-import/assign-expr/yield-identifier.js b/test/language/expressions/dynamic-import/assignment-expression/yield-identifier.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/yield-identifier.js rename to test/language/expressions/dynamic-import/assignment-expression/yield-identifier.js diff --git a/test/language/expressions/dynamic-import/assign-expr/yield-star.js b/test/language/expressions/dynamic-import/assignment-expression/yield-star.js similarity index 100% rename from test/language/expressions/dynamic-import/assign-expr/yield-star.js rename to test/language/expressions/dynamic-import/assignment-expression/yield-star.js diff --git a/test/language/expressions/dynamic-import/await-import-evaluation.js b/test/language/expressions/dynamic-import/await-import-evaluation.js new file mode 100644 index 0000000000..26326006f5 --- /dev/null +++ b/test/language/expressions/dynamic-import/await-import-evaluation.js @@ -0,0 +1,24 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Dynamic Import should await for evaluation +esid: sec-finishdynamicimport +info: | + Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion ) + + 2. Otherwise, + a. Assert: completion is a normal completion and completion.[[Value]] is undefined. + b. Let moduleRecord be ! HostResolveImportedModule(referencingScriptOrModule, specifier). + c. Assert: Evaluate has already been invoked on moduleRecord and successfully completed. +flags: [async] +features: [dynamic-import] +---*/ + +var startTime = Date.now(); + +import('./await-import-evaluation_FIXTURE.js').then(imported => { + var endTime = Date.now() - startTime; + assert(imported.time > 100, `${String(imported.time)} > 100`); + assert(imported.time <= endTime, `${String(imported.time)} > ${String(endTime)}`); +}).then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/await-import-evaluation_FIXTURE.js b/test/language/expressions/dynamic-import/await-import-evaluation_FIXTURE.js new file mode 100644 index 0000000000..084888a6ba --- /dev/null +++ b/test/language/expressions/dynamic-import/await-import-evaluation_FIXTURE.js @@ -0,0 +1,14 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var startTime = Date.now(); +var endTime; + +export { endTime as time } + +while (true) { + endTime = Date.now() - startTime; + if (endTime > 100) { + break; + } +} diff --git a/test/language/expressions/dynamic-import/for-await-resolution-and-error-a_FIXTURE.js b/test/language/expressions/dynamic-import/for-await-resolution-and-error-a_FIXTURE.js new file mode 100644 index 0000000000..4ed0ca32d9 --- /dev/null +++ b/test/language/expressions/dynamic-import/for-await-resolution-and-error-a_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var x = 42; diff --git a/test/language/expressions/dynamic-import/for-await-resolution-and-error-agen-yield.js b/test/language/expressions/dynamic-import/for-await-resolution-and-error-agen-yield.js new file mode 100644 index 0000000000..b42ee047bf --- /dev/null +++ b/test/language/expressions/dynamic-import/for-await-resolution-and-error-agen-yield.js @@ -0,0 +1,69 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Resolve multiple imports through a for await loop in an async generator yielding imports +esid: sec-finishdynamicimport +info: | + Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion ) + + 2. Otherwise, + a. Assert: completion is a normal completion and completion.[[Value]] is undefined. + b. Let moduleRecord be ! HostResolveImportedModule(referencingScriptOrModule, specifier). + c. Assert: Evaluate has already been invoked on moduleRecord and successfully completed. + d. Let namespace be GetModuleNamespace(moduleRecord). + ... + f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »). +flags: [async] +features: [dynamic-import, async-iteration] +---*/ + +async function * agen1() { + yield import('./for-await-resolution-and-error-a_FIXTURE.js'); + yield import('./for-await-resolution-and-error-b_FIXTURE.js'); + yield import('./for-await-resolution-and-error-poisoned_FIXTURE.js'); +} + +async function * agen2() { + yield await import('./for-await-resolution-and-error-a_FIXTURE.js'); + yield await import('./for-await-resolution-and-error-b_FIXTURE.js'); + yield await import('./for-await-resolution-and-error-poisoned_FIXTURE.js'); +} + +var aiter1 = agen1(); +var aiter2 = agen2(); + +async function fn() { + var a = aiter1.next(); + var b = aiter1.next(); + var c = aiter1.next(); + var d = aiter2.next(); + var e = aiter2.next(); + var f = aiter2.next(); + + assert.sameValue((await a).value.x, 42, 'a'); + assert.sameValue((await b).value.x, 39, 'b'); + + var error; + try { + await c; + } catch (err) { + error = err; + } + + assert.sameValue(error, 'foo', 'c'); + + assert.sameValue((await d).value.x, 42, 'd'); + assert.sameValue((await e).value.x, 39, 'e'); + + error = null; + try { + await f; + } catch (err) { + error = err; + } + + assert.sameValue(error, 'foo', 'f'); +} + +fn().then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/for-await-resolution-and-error-agen.js b/test/language/expressions/dynamic-import/for-await-resolution-and-error-agen.js new file mode 100644 index 0000000000..ca393f5b8a --- /dev/null +++ b/test/language/expressions/dynamic-import/for-await-resolution-and-error-agen.js @@ -0,0 +1,51 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Resolve multiple imports through a for await loop in an async generator +esid: sec-finishdynamicimport +info: | + Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion ) + + 2. Otherwise, + a. Assert: completion is a normal completion and completion.[[Value]] is undefined. + b. Let moduleRecord be ! HostResolveImportedModule(referencingScriptOrModule, specifier). + c. Assert: Evaluate has already been invoked on moduleRecord and successfully completed. + d. Let namespace be GetModuleNamespace(moduleRecord). + ... + f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »). +flags: [async] +features: [dynamic-import, async-iteration] +---*/ + +async function * agen() { + for await (let imported of [ + import('./for-await-resolution-and-error-a_FIXTURE.js'), + import('./for-await-resolution-and-error-b_FIXTURE.js'), + import('./for-await-resolution-and-error-poisoned_FIXTURE.js'), + ]) { + yield imported.x; + } +} + +var aiter = agen(); + +async function fn() { + var a = aiter.next(); + var b = aiter.next(); + var c = aiter.next(); + + assert.sameValue((await a).value, 42); + assert.sameValue((await b).value, 39); + + var error; + try { + await c; + } catch (e) { + error = e; + } + + assert.sameValue(error, 'foo'); +} + +fn().then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/for-await-resolution-and-error-b_FIXTURE.js b/test/language/expressions/dynamic-import/for-await-resolution-and-error-b_FIXTURE.js new file mode 100644 index 0000000000..d2f423ccd4 --- /dev/null +++ b/test/language/expressions/dynamic-import/for-await-resolution-and-error-b_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var x = 39; diff --git a/test/language/expressions/dynamic-import/for-await-resolution-and-error-poisoned_FIXTURE.js b/test/language/expressions/dynamic-import/for-await-resolution-and-error-poisoned_FIXTURE.js new file mode 100644 index 0000000000..e327968247 --- /dev/null +++ b/test/language/expressions/dynamic-import/for-await-resolution-and-error-poisoned_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +throw 'foo'; diff --git a/test/language/expressions/dynamic-import/for-await-resolution-and-error.js b/test/language/expressions/dynamic-import/for-await-resolution-and-error.js new file mode 100644 index 0000000000..ffbeaf4554 --- /dev/null +++ b/test/language/expressions/dynamic-import/for-await-resolution-and-error.js @@ -0,0 +1,37 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Resolve multiple imports through a for await loop +esid: sec-finishdynamicimport +info: | + Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion ) + + 2. Otherwise, + a. Assert: completion is a normal completion and completion.[[Value]] is undefined. + b. Let moduleRecord be ! HostResolveImportedModule(referencingScriptOrModule, specifier). + c. Assert: Evaluate has already been invoked on moduleRecord and successfully completed. + d. Let namespace be GetModuleNamespace(moduleRecord). + ... + f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »). +flags: [async] +features: [dynamic-import] +includes: [compareArray.js] +---*/ + +let r = []; +async function aiter() { + for await (let imported of [ + import('./for-await-resolution-and-error-a_FIXTURE.js'), + import('./for-await-resolution-and-error-b_FIXTURE.js'), + import('./for-await-resolution-and-error-poisoned_FIXTURE.js'), + import('./for-await-resolution-and-error-a_FIXTURE.js'), // this should be ignored + ]) { + r.push(imported.x); + } +} + +aiter().then(() => { throw 'The async function should not resolve' }, error => { + assert.compareArray(r, [42, 39]); + assert.sameValue(error, 'foo'); +}).then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/imported-self-update.js b/test/language/expressions/dynamic-import/imported-self-update.js new file mode 100644 index 0000000000..0af479b614 --- /dev/null +++ b/test/language/expressions/dynamic-import/imported-self-update.js @@ -0,0 +1,32 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Imported self bindings should update the references +esid: sec-finishdynamicimport +info: | + Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion ) + + 2. Otherwise, + a. Assert: completion is a normal completion and completion.[[Value]] is undefined. + b. Let moduleRecord be ! HostResolveImportedModule(referencingScriptOrModule, specifier). + c. Assert: Evaluate has already been invoked on moduleRecord and successfully completed. + d. Let namespace be GetModuleNamespace(moduleRecord). + ... + f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »). +flags: [async, module] +features: [dynamic-import] +---*/ + +let x = 0; +export { x, x as y }; +async function fn() { + var imported = await import('./imported-self-update.js'); + assert.sameValue(imported.x, 0, 'original value, direct binding'); + assert.sameValue(imported.y, 0, 'original value, indirect binding'); + x = 1; + assert.sameValue(imported.x, 1, 'updated value, direct binding'); + assert.sameValue(imported.y, 1, 'updated value, indirect binding'); +} + +fn().then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/indirect-resolution-1_FIXTURE.js b/test/language/expressions/dynamic-import/indirect-resolution-1_FIXTURE.js new file mode 100644 index 0000000000..c572460ea4 --- /dev/null +++ b/test/language/expressions/dynamic-import/indirect-resolution-1_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export default import('indirect-resolution-2_FIXTURE.js'); diff --git a/test/language/expressions/dynamic-import/indirect-resolution-2_FIXTURE.js b/test/language/expressions/dynamic-import/indirect-resolution-2_FIXTURE.js new file mode 100644 index 0000000000..4cc5fc922f --- /dev/null +++ b/test/language/expressions/dynamic-import/indirect-resolution-2_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export default 42; diff --git a/test/language/expressions/dynamic-import/indirect-resolution.js b/test/language/expressions/dynamic-import/indirect-resolution.js new file mode 100644 index 0000000000..e1b01a7497 --- /dev/null +++ b/test/language/expressions/dynamic-import/indirect-resolution.js @@ -0,0 +1,31 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Dynamic Import should resolve another import call +esid: sec-import-call-runtime-semantics-evaluation +info: | + Runtime Semantics: Evaluation + + ImportCall : import ( AssignmentExpression ) + + 1. Let referencingScriptOrModule be ! GetActiveScriptOrModule(). + 2. Let argRef be the result of evaluating AssignmentExpression. + 3. Let specifier be ? GetValue(argRef). + 4. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 5. Let specifierString be ToString(specifier). + 6. IfAbruptRejectPromise(specifierString, promiseCapability). + 7. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability). + 8. Return promiseCapability.[[Promise]]. +flags: [async] +features: [dynamic-import] +---*/ + +import('./indirect-resolution-1_FIXTURE.js').then(async imported => { + assert.sameValue(Promise.resolve(imported.default), imported.default, 'default is Promise instance'); + assert.sameValue(Object.getPrototypeOf(imported.default), Promise.prototype, 'default proto is Promise.prototype'); + assert.sameValue(imported.default.constructor, Promise, 'default.constructor is Promise'); + + var indirect = await imported.default; + assert.sameValue(indirect.default, 42); +}).then($DONE, $DONE);