From 18834b2e19f46a05efa766c4013c98af8ef9acc3 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Thu, 29 Apr 2021 22:28:12 -0400 Subject: [PATCH] Add tests for import assertions --- features.txt | 4 ++ src/dynamic-import/not-extensible-args.case | 5 +- .../not-extensible-no-trailing-comma.case | 16 ----- src/dynamic-import/trailing-comma-first.case | 14 ++++ src/dynamic-import/trailing-comma-second.case | 14 ++++ .../2nd-param-assert-enumeration-abrupt.js | 43 ++++++++++++ .../2nd-param-assert-enumeration.js | 68 ++++++++++++++++++ .../2nd-param-assert-non-object.js | 47 +++++++++++++ .../2nd-param-assert-undefined.js | 36 ++++++++++ .../2nd-param-assert-value-abrupt.js | 34 +++++++++ .../2nd-param-assert-value-non-string.js | 47 +++++++++++++ .../dynamic-import/2nd-param-await-expr.js | 21 ++++++ .../dynamic-import/2nd-param-await-ident.js | 21 ++++++ .../2nd-param-evaluation-abrupt-return.js | 30 ++++++++ .../2nd-param-evaluation-abrupt-throw.js | 29 ++++++++ .../2nd-param-evaluation-sequence.js | 25 +++++++ .../2nd-param-get-assert-error.js | 36 ++++++++++ .../dynamic-import/2nd-param-in.js | 22 ++++++ .../dynamic-import/2nd-param-non-object.js | 40 +++++++++++ .../2nd-param-trailing-comma-fulfill.js | 20 ++++++ .../2nd-param-trailing-comma-reject.js | 24 +++++++ .../dynamic-import/2nd-param-yield-expr.js | 31 ++++++++ .../2nd-param-yield-ident-invalid.js | 19 +++++ .../2nd-param-yield-ident-valid.js | 21 ++++++ .../dynamic-import/2nd-param_FIXTURE.js | 3 + .../dynamic-import/trailing-comma-fulfill.js | 20 ++++++ .../dynamic-import/trailing-comma-reject.js | 24 +++++++ .../early-dup-assert-key-export.js | 24 +++++++ .../early-dup-assert-key-import-nobinding.js | 25 +++++++ ...early-dup-assert-key-import-withbinding.js | 25 +++++++ .../eval-gtbndng-indirect-faux-assertion.js | 70 +++++++++++++++++++ .../module-code/import-assertion-1_FIXTURE.js | 3 + .../module-code/import-assertion-2_FIXTURE.js | 3 + .../module-code/import-assertion-3_FIXTURE.js | 3 + .../module-code/import-assertion-empty.js | 30 ++++++++ .../import-assertion-key-identifiername.js | 31 ++++++++ .../import-assertion-key-string-double.js | 31 ++++++++ .../import-assertion-key-string-single.js | 31 ++++++++ .../module-code/import-assertion-many.js | 31 ++++++++ .../module-code/import-assertion-newlines.js | 49 +++++++++++++ .../import-assertion-trlng-comma.js | 31 ++++++++ .../import-assertion-value-string-double.js | 31 ++++++++ .../import-assertion-value-string-single.js | 31 ++++++++ 43 files changed, 1145 insertions(+), 18 deletions(-) delete mode 100644 src/dynamic-import/not-extensible-no-trailing-comma.case create mode 100644 src/dynamic-import/trailing-comma-first.case create mode 100644 src/dynamic-import/trailing-comma-second.case create mode 100644 test/language/expressions/dynamic-import/2nd-param-assert-enumeration-abrupt.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-assert-enumeration.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-assert-non-object.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-assert-undefined.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-assert-value-abrupt.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-assert-value-non-string.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-await-expr.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-await-ident.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-evaluation-abrupt-return.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-evaluation-abrupt-throw.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-evaluation-sequence.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-get-assert-error.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-in.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-non-object.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-trailing-comma-fulfill.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-trailing-comma-reject.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-yield-expr.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-yield-ident-invalid.js create mode 100644 test/language/expressions/dynamic-import/2nd-param-yield-ident-valid.js create mode 100644 test/language/expressions/dynamic-import/2nd-param_FIXTURE.js create mode 100644 test/language/expressions/dynamic-import/trailing-comma-fulfill.js create mode 100644 test/language/expressions/dynamic-import/trailing-comma-reject.js create mode 100644 test/language/module-code/early-dup-assert-key-export.js create mode 100644 test/language/module-code/early-dup-assert-key-import-nobinding.js create mode 100644 test/language/module-code/early-dup-assert-key-import-withbinding.js create mode 100644 test/language/module-code/eval-gtbndng-indirect-faux-assertion.js create mode 100644 test/language/module-code/import-assertion-1_FIXTURE.js create mode 100644 test/language/module-code/import-assertion-2_FIXTURE.js create mode 100644 test/language/module-code/import-assertion-3_FIXTURE.js create mode 100644 test/language/module-code/import-assertion-empty.js create mode 100644 test/language/module-code/import-assertion-key-identifiername.js create mode 100644 test/language/module-code/import-assertion-key-string-double.js create mode 100644 test/language/module-code/import-assertion-key-string-single.js create mode 100644 test/language/module-code/import-assertion-many.js create mode 100644 test/language/module-code/import-assertion-newlines.js create mode 100644 test/language/module-code/import-assertion-trlng-comma.js create mode 100644 test/language/module-code/import-assertion-value-string-double.js create mode 100644 test/language/module-code/import-assertion-value-string-single.js diff --git a/features.txt b/features.txt index 92b092009b2..3a755f224f7 100644 --- a/features.txt +++ b/features.txt @@ -307,3 +307,7 @@ class-fields-private-in # Error cause # https://github.com/tc39/proposal-error-cause error-cause + +# Import Assertions +# https://github.com/tc39/proposal-import-assertions/ +import-assertions diff --git a/src/dynamic-import/not-extensible-args.case b/src/dynamic-import/not-extensible-args.case index 655444498a3..13c296cb3a7 100644 --- a/src/dynamic-import/not-extensible-args.case +++ b/src/dynamic-import/not-extensible-args.case @@ -5,7 +5,8 @@ desc: ImportCall is not extensible - no arguments list template: syntax/invalid info: | ImportCall : - import( AssignmentExpression[+In, ?Yield] ) + import( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) Forbidden Extensions @@ -13,4 +14,4 @@ info: | ---*/ //- import -import('', '') +import('./empty_FIXTURE.js', {}, '') diff --git a/src/dynamic-import/not-extensible-no-trailing-comma.case b/src/dynamic-import/not-extensible-no-trailing-comma.case deleted file mode 100644 index 3d97a3b9d9c..00000000000 --- a/src/dynamic-import/not-extensible-no-trailing-comma.case +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2018 Leo Balter. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -desc: ImportCall is not extensible - trailing comma -template: syntax/invalid -info: | - ImportCall : - import( AssignmentExpression[+In, ?Yield] ) - - Forbidden Extensions - - - ImportCall must not be extended. ----*/ - -//- import -import('',) diff --git a/src/dynamic-import/trailing-comma-first.case b/src/dynamic-import/trailing-comma-first.case new file mode 100644 index 00000000000..dc33458cc8a --- /dev/null +++ b/src/dynamic-import/trailing-comma-first.case @@ -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. +/*--- +desc: ImportCall trailing comma following first parameter +template: syntax/valid +info: | + ImportCall : + import( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [import-assertions] +---*/ + +//- import +import('./empty_FIXTURE.js',) diff --git a/src/dynamic-import/trailing-comma-second.case b/src/dynamic-import/trailing-comma-second.case new file mode 100644 index 00000000000..f82af0a93ad --- /dev/null +++ b/src/dynamic-import/trailing-comma-second.case @@ -0,0 +1,14 @@ +// Copyright (C) 2021 V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: ImportCall trailing comma following second parameter +template: syntax/valid +info: | + ImportCall : + import( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [import-assertions] +---*/ + +//- import +import('./empty_FIXTURE.js', {},) diff --git a/test/language/expressions/dynamic-import/2nd-param-assert-enumeration-abrupt.js b/test/language/expressions/dynamic-import/2nd-param-assert-enumeration-abrupt.js new file mode 100644 index 00000000000..a181764e899 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-assert-enumeration-abrupt.js @@ -0,0 +1,43 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Reports abrupt completions produced by assertion enumeration +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + [...] + 6. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 7. Let specifierString be ToString(specifier). + 8. IfAbruptRejectPromise(specifierString, promiseCapability). + 9. Let assertions be a new empty List. + 10. If options is not undefined, then + a. If Type(options) is not Object, + [...] + b. Let assertionsObj be Get(options, "assert"). + c. IfAbruptRejectPromise(assertionsObj, promiseCapability). + d. If assertionsObj is not undefined, + i. If Type(assertionsObj) is not Object, + [...] + ii. Let keys be EnumerableOwnPropertyNames(assertionsObj, key). + iii. IfAbruptRejectPromise(keys, promiseCapability). + [...] +features: [dynamic-import, import-assertions, Proxy] +flags: [async] +---*/ + +var thrown = new Test262Error(); +var options = { + assert: new Proxy({}, { + ownKeys: function() { + throw thrown; + }, + }) +}; + +import('./2nd-param_FIXTURE.js', options) + .then(function() { + throw new Test262Error('Expected promise to be rejected, but promise was fulfilled.'); + }, function(error) { + assert.sameValue(error, thrown); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-assert-enumeration.js b/test/language/expressions/dynamic-import/2nd-param-assert-enumeration.js new file mode 100644 index 00000000000..ae31dcc0180 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-assert-enumeration.js @@ -0,0 +1,68 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Follows the semantics of the EnumerableOwnPropertyNames abstract operation + during assertion enumeration +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + [...] + 6. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 7. Let specifierString be ToString(specifier). + 8. IfAbruptRejectPromise(specifierString, promiseCapability). + 9. Let assertions be a new empty List. + 10. If options is not undefined, then + a. If Type(options) is not Object, + [...] + b. Let assertionsObj be Get(options, "assert"). + c. IfAbruptRejectPromise(assertionsObj, promiseCapability). + d. If assertionsObj is not undefined, + i. If Type(assertionsObj) is not Object, + [...] + ii. Let keys be EnumerableOwnPropertyNames(assertionsObj, key). + [...] +features: [dynamic-import, import-assertions, Symbol, Proxy] +flags: [async] +---*/ + +var symbol = Symbol(''); +var target = { + enumerable1: '', + enumerable2: '', + [symbol]: '', + unreported: '', + nonEnumerable: '' +}; +var descriptors = { + enumerable1: {configurable: true, enumerable: true}, + enumerable2: {configurable: true, enumerable: true}, + [symbol]: {configurable: true, enumerable: true}, + nonEnumerable: {configurable: true, enumerable: false} +}; +var log = []; + +var options = { + assert: new Proxy({}, { + ownKeys: function() { + return ['enumerable1', symbol, 'nonEnumerable', 'absent', 'enumerable2']; + }, + get(_, name) { + log.push(name); + return target[name]; + }, + getOwnPropertyDescriptor(target, name) { + return descriptors[name]; + } + }) +}; + +import('./2nd-param_FIXTURE.js', options) + .then(function(module) { + assert.sameValue(module.default, 262); + }) + .then($DONE, $DONE); + +assert.sameValue(log.length, 2); +assert.sameValue(log[0], 'enumerable1'); +assert.sameValue(log[1], 'enumerable2'); diff --git a/test/language/expressions/dynamic-import/2nd-param-assert-non-object.js b/test/language/expressions/dynamic-import/2nd-param-assert-non-object.js new file mode 100644 index 00000000000..d685ee83d3c --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-assert-non-object.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Rejects promise when the `assert` property of the second argument is neither + undefined nor an object +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + [...] + 6. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 7. Let specifierString be ToString(specifier). + 8. IfAbruptRejectPromise(specifierString, promiseCapability). + 9. Let assertions be a new empty List. + 10. If options is not undefined, then + a. If Type(options) is not Object, + [...] + b. Let assertionsObj be Get(options, "assert"). + c. IfAbruptRejectPromise(assertionsObj, promiseCapability). + d. If assertionsObj is not undefined, + i. If Type(assertionsObj) is not Object, + 1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a + newly created TypeError object »). + 2. Return promiseCapability.[[Promise]]. + [...] +features: [dynamic-import, import-assertions, Symbol, BigInt] +flags: [async] +---*/ + +function test(promise, valueType) { + return promise.then(function() { + throw new Test262Error('Promise for ' + valueType + ' was not rejected.'); + }, function(error) { + assert.sameValue(error.constructor, TypeError, valueType); + }); +} + +Promise.all([ + test(import('./2nd-param_FIXTURE.js', {assert:null}), 'null'), + test(import('./2nd-param_FIXTURE.js', {assert:false}), 'boolean'), + test(import('./2nd-param_FIXTURE.js', {assert:23}), 'number'), + test(import('./2nd-param_FIXTURE.js', {assert:''}), 'string'), + test(import('./2nd-param_FIXTURE.js', {assert:Symbol('')}), 'symbol'), + test(import('./2nd-param_FIXTURE.js', {assert:23n}), 'bigint') + ]) + .then(function() {}) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-assert-undefined.js b/test/language/expressions/dynamic-import/2nd-param-assert-undefined.js new file mode 100644 index 00000000000..bdd4003d386 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-assert-undefined.js @@ -0,0 +1,36 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Accepts undefined for the `assert` property of the second argument +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + [...] + 6. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 7. Let specifierString be ToString(specifier). + 8. IfAbruptRejectPromise(specifierString, promiseCapability). + 9. Let assertions be a new empty List. + 10. If options is not undefined, then + a. If Type(options) is not Object, + [...] + b. Let assertionsObj be Get(options, "assert"). + c. IfAbruptRejectPromise(assertionsObj, promiseCapability). + d. If assertionsObj is not undefined, + i. If Type(assertionsObj) is not Object, + 1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a + newly created TypeError object »). + 2. Return promiseCapability.[[Promise]]. + [...] +features: [dynamic-import, import-assertions, Symbol, BigInt] +flags: [async] +---*/ + +Promise.all([ + import('./2nd-param_FIXTURE.js', {}), + import('./2nd-param_FIXTURE.js', {assert:undefined}), + ]) + .then(function(values) { + assert.sameValue(values[0].default, 262); + assert.sameValue(values[1].default, 262); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-assert-value-abrupt.js b/test/language/expressions/dynamic-import/2nd-param-assert-value-abrupt.js new file mode 100644 index 00000000000..e840a719509 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-assert-value-abrupt.js @@ -0,0 +1,34 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Rejects promise when retrieving a value of the `assert` object produces an + abrupt completion +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + [...] + 10. If options is not undefined, then + [...] + d. If assertionsObj is not undefined, + [...] + ii. Let keys be EnumerableOwnPropertyNames(assertionsObj, key). + iii. IfAbruptRejectPromise(keys, promiseCapability). + iv. Let supportedAssertions be ! HostGetSupportedImportAssertions(). + v. For each String key of keys, + 1. Let value be Get(assertionsObj, key). + 2. IfAbruptRejectPromise(value, promiseCapability). + [...] +features: [dynamic-import, import-assertions] +flags: [async] +---*/ + +var thrown = new Test262Error(); + +import('./2nd-param_FIXTURE.js', {assert:{get ''() { throw thrown; }}}) + .then(function() { + throw new Test262Error('Expected promise to be rejected, but it was fulfilled'); + }, function(error) { + assert.sameValue(error, thrown); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-assert-value-non-string.js b/test/language/expressions/dynamic-import/2nd-param-assert-value-non-string.js new file mode 100644 index 00000000000..aa71b1c2826 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-assert-value-non-string.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Rejects promise when any property of the `assert` object is not a string +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + [...] + 10. If options is not undefined, then + [...] + d. If assertionsObj is not undefined, + [...] + ii. Let keys be EnumerableOwnPropertyNames(assertionsObj, key). + iii. IfAbruptRejectPromise(keys, promiseCapability). + iv. Let supportedAssertions be ! HostGetSupportedImportAssertions(). + v. For each String key of keys, + 1. Let value be Get(assertionsObj, key). + 2. IfAbruptRejectPromise(value, promiseCapability). + 3. If Type(value) is not String, then + a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a + newly created TypeError object »). + b. Return promiseCapability.[[Promise]]. + [...] +features: [dynamic-import, import-assertions, Symbol, BigInt] +flags: [async] +---*/ + +function test(promise, valueType) { + return promise.then(function() { + throw new Test262Error('Promise for ' + valueType + ' was not rejected.'); + }, function(error) { + assert.sameValue(error.constructor, TypeError, valueType); + }); +} + +Promise.all([ + test(import('./2nd-param_FIXTURE.js', {assert:{'': undefined}}), 'undefined'), + test(import('./2nd-param_FIXTURE.js', {assert:{'': null}}), 'null'), + test(import('./2nd-param_FIXTURE.js', {assert:{'': false}}), 'boolean'), + test(import('./2nd-param_FIXTURE.js', {assert:{'': 23}}), 'number'), + test(import('./2nd-param_FIXTURE.js', {assert:{'': Symbol('')}}), 'symbol'), + test(import('./2nd-param_FIXTURE.js', {assert:{'': 23n}}), 'bigint'), + test(import('./2nd-param_FIXTURE.js', {assert:{'': {}}}), 'object') + ]) + .then(function() {}) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-await-expr.js b/test/language/expressions/dynamic-import/2nd-param-await-expr.js new file mode 100644 index 00000000000..966ab943692 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-await-expr.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ImportCall parameter list forwards the Await production parameter - AwaitExpression +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions, async-functions] +flags: [async] +---*/ + +(async function () { + return import('./2nd-param_FIXTURE.js', await undefined); +}()) + .then(function(module) { + assert.sameValue(module.default, 262); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-await-ident.js b/test/language/expressions/dynamic-import/2nd-param-await-ident.js new file mode 100644 index 00000000000..d13ca53b20f --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-await-ident.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ImportCall parameter list forwards the Await production parameter - IdentifierReference +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions, async-functions] +flags: [async] +---*/ + +function await() {} + +import('./2nd-param_FIXTURE.js', await(undefined)) + .then(function(module) { + assert.sameValue(module.default, 262); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-evaluation-abrupt-return.js b/test/language/expressions/dynamic-import/2nd-param-evaluation-abrupt-return.js new file mode 100644 index 00000000000..6da4a5482b7 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-evaluation-abrupt-return.js @@ -0,0 +1,30 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Forwards "return" completion when evaluating second parameter +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + 1. Let referencingScriptOrModule be ! GetActiveScriptOrModule(). + 2. Let specifierRef be the result of evaluating specifierExpression. + 3. Let specifier be ? GetValue(specifierRef). + 4. If optionsExpression is present, then + a. Let optionsRef be the result of evaluating optionsExpression. + b. Let options be ? GetValue(optionsRef). + [...] +features: [dynamic-import, import-assertions] +---*/ + +var beforeCount = 0; +var afterCount = 0; +var iter = function*() { + beforeCount += 1, import('', yield), afterCount += 1; +}(); + +iter.next(); +var result = iter.return(595); + +assert.sameValue(result.done, true); +assert.sameValue(result.value, 595); +assert.sameValue(beforeCount, 1); +assert.sameValue(afterCount, 0); diff --git a/test/language/expressions/dynamic-import/2nd-param-evaluation-abrupt-throw.js b/test/language/expressions/dynamic-import/2nd-param-evaluation-abrupt-throw.js new file mode 100644 index 00000000000..e5e6619096d --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-evaluation-abrupt-throw.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Forwards "throw" completion when evaluating second parameter +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + 1. Let referencingScriptOrModule be ! GetActiveScriptOrModule(). + 2. Let specifierRef be the result of evaluating specifierExpression. + 3. Let specifier be ? GetValue(specifierRef). + 4. If optionsExpression is present, then + a. Let optionsRef be the result of evaluating optionsExpression. + b. Let options be ? GetValue(optionsRef). + [...] +features: [dynamic-import, import-assertions] +---*/ + +var beforeCount = 0; +var afterCount = 0; +function throwError() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + beforeCount += 1, import('', throwError()), afterCount += 1; +}); + +assert.sameValue(beforeCount, 1); +assert.sameValue(afterCount, 0); diff --git a/test/language/expressions/dynamic-import/2nd-param-evaluation-sequence.js b/test/language/expressions/dynamic-import/2nd-param-evaluation-sequence.js new file mode 100644 index 00000000000..9795c4bada9 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-evaluation-sequence.js @@ -0,0 +1,25 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Evaluates parameters in correct sequence +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + 1. Let referencingScriptOrModule be ! GetActiveScriptOrModule(). + 2. Let specifierRef be the result of evaluating specifierExpression. + 3. Let specifier be ? GetValue(specifierRef). + 4. If optionsExpression is present, then + a. Let optionsRef be the result of evaluating optionsExpression. + b. Let options be ? GetValue(optionsRef). + [...] +features: [dynamic-import, import-assertions] +---*/ + +var log = []; + +import(log.push('first'), (log.push('second'), undefined)) + .then(null, function() {}); + +assert.sameValue(log.length, 2); +assert.sameValue(log[0], 'first'); +assert.sameValue(log[1], 'second'); diff --git a/test/language/expressions/dynamic-import/2nd-param-get-assert-error.js b/test/language/expressions/dynamic-import/2nd-param-get-assert-error.js new file mode 100644 index 00000000000..d7bb7d8c046 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-get-assert-error.js @@ -0,0 +1,36 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejects promise when accessing "assert" property throws an error +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + [...] + 6. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 7. Let specifierString be ToString(specifier). + 8. IfAbruptRejectPromise(specifierString, promiseCapability). + 9. Let assertions be a new empty List. + 10. If options is not undefined, then + a. If Type(options) is not Object, + [...] + b. Let assertionsObj be Get(options, "assert"). + c. IfAbruptRejectPromise(assertionsObj, promiseCapability). + [...] +features: [dynamic-import, import-assertions] +flags: [async] +---*/ + +var thrown = new Test262Error(); +var options = { + get assert() { + throw thrown; + } +}; + +import('./2nd-param_FIXTURE.js', options) + .then(function() { + throw new Test262Error('Expected an error, but observed no error'); + }, function(caught) { + assert.sameValue(thrown, caught); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-in.js b/test/language/expressions/dynamic-import/2nd-param-in.js new file mode 100644 index 00000000000..6d8ac2b0eb2 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-in.js @@ -0,0 +1,22 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ImportCall parameter list enables the Yield production parameter +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions] +flags: [async] +---*/ + +var promise; + +for (promise = import('./2nd-param_FIXTURE.js', 'test262' in {} || undefined); false; ) ; + +promise + .then(function(module) { + assert.sameValue(module.default, 262); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-non-object.js b/test/language/expressions/dynamic-import/2nd-param-non-object.js new file mode 100644 index 00000000000..28b6e573d13 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-non-object.js @@ -0,0 +1,40 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Rejects promise when the second argument is neither undefined nor an object +esid: sec-import-call-runtime-semantics-evaluation +info: | + 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ) + [...] + 6. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 7. Let specifierString be ToString(specifier). + 8. IfAbruptRejectPromise(specifierString, promiseCapability). + 9. Let assertions be a new empty List. + 10. If options is not undefined, then + a. If Type(options) is not Object, + i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »). + ii. Return promiseCapability.[[Promise]]. + [...] +features: [dynamic-import, import-assertions, Symbol, BigInt] +flags: [async] +---*/ + +function test(promise, valueType) { + return promise.then(function() { + throw new Test262Error('Promise for ' + valueType + ' was not rejected.'); + }, function(error) { + assert.sameValue(error.constructor, TypeError, valueType); + }); +} + +Promise.all([ + test(import('./2nd-param_FIXTURE.js', null), 'null'), + test(import('./2nd-param_FIXTURE.js', false), 'boolean'), + test(import('./2nd-param_FIXTURE.js', 23), 'number'), + test(import('./2nd-param_FIXTURE.js', ''), 'string'), + test(import('./2nd-param_FIXTURE.js', Symbol('')), 'symbol'), + test(import('./2nd-param_FIXTURE.js', 23n), 'bigint') + ]) + .then(function() {}) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-trailing-comma-fulfill.js b/test/language/expressions/dynamic-import/2nd-param-trailing-comma-fulfill.js new file mode 100644 index 00000000000..c806f3e6837 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-trailing-comma-fulfill.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ImportCall parameter list supports an optional trailing comma (fulfillment + semantics) +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions] +flags: [async] +---*/ + +import('./2nd-param_FIXTURE.js', {},) + .then(function(module) { + assert.sameValue(module.default, 262); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-trailing-comma-reject.js b/test/language/expressions/dynamic-import/2nd-param-trailing-comma-reject.js new file mode 100644 index 00000000000..3970c745b62 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-trailing-comma-reject.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ImportCall parameter list supports an optional trailing comma (rejection + semantics) +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions] +flags: [async] +---*/ + +var thrown = new Test262Error(); + +import({toString: function() { throw thrown; } }, {},) + .then(function() { + throw new Test262Error('Expected promise to be rejected, but it was fulfilled.'); + }, function(caught) { + assert.sameValue(thrown, caught); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-yield-expr.js b/test/language/expressions/dynamic-import/2nd-param-yield-expr.js new file mode 100644 index 00000000000..b1482ac9e88 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-yield-expr.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ImportCall parameter list forwards the Yield production parameter - YieldExpression +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions] +flags: [async] +---*/ + +var promise; + +var iter = (function * () { + promise = import('./2nd-param_FIXTURE.js', yield); +}()); + +iter.next(); + +assert.sameValue(promise, undefined); + +iter.next(); + +promise + .then(function(module) { + assert.sameValue(module.default, 262); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param-yield-ident-invalid.js b/test/language/expressions/dynamic-import/2nd-param-yield-ident-invalid.js new file mode 100644 index 00000000000..56971e80316 --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-yield-ident-invalid.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ImportCall parameter list forwards the Yield production parameter - invalid IdentifierReference +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions] +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ +$DONOTEVALUATE(); + +import('./empty_FIXTURE.js', yield); diff --git a/test/language/expressions/dynamic-import/2nd-param-yield-ident-valid.js b/test/language/expressions/dynamic-import/2nd-param-yield-ident-valid.js new file mode 100644 index 00000000000..39a8fe7d6ea --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param-yield-ident-valid.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ImportCall parameter list forwards the Yield production parameter - valid IdentifierReference +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions] +flags: [async, noStrict] +---*/ + +var yield; + +import('./2nd-param_FIXTURE.js', yield) + .then(function(module) { + assert.sameValue(module.default, 262); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/2nd-param_FIXTURE.js b/test/language/expressions/dynamic-import/2nd-param_FIXTURE.js new file mode 100644 index 00000000000..fc9f2fa021e --- /dev/null +++ b/test/language/expressions/dynamic-import/2nd-param_FIXTURE.js @@ -0,0 +1,3 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +export default 262; diff --git a/test/language/expressions/dynamic-import/trailing-comma-fulfill.js b/test/language/expressions/dynamic-import/trailing-comma-fulfill.js new file mode 100644 index 00000000000..0d3689b37ed --- /dev/null +++ b/test/language/expressions/dynamic-import/trailing-comma-fulfill.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ImportCall parameter list supports an optional trailing comma (fulfillment + semantics) +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions] +flags: [async] +---*/ + +import('./2nd-param_FIXTURE.js',) + .then(function(module) { + assert.sameValue(module.default, 262); + }) + .then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/trailing-comma-reject.js b/test/language/expressions/dynamic-import/trailing-comma-reject.js new file mode 100644 index 00000000000..d257eccc324 --- /dev/null +++ b/test/language/expressions/dynamic-import/trailing-comma-reject.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + ImportCall parameter list supports an optional trailing comma (rejection + semantics) +esid: sec-import-call-runtime-semantics-evaluation +info: | + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ,opt ) + import ( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt ) +features: [dynamic-import, import-assertions] +flags: [async] +---*/ + +var thrown = new Test262Error(); + +import({toString: function() { throw thrown; } },) + .then(function() { + throw new Test262Error('Expected promise to be rejected, but it was fulfilled.'); + }, function(caught) { + assert.sameValue(thrown, caught); + }) + .then($DONE, $DONE); diff --git a/test/language/module-code/early-dup-assert-key-export.js b/test/language/module-code/early-dup-assert-key-export.js new file mode 100644 index 00000000000..f7ab23233ea --- /dev/null +++ b/test/language/module-code/early-dup-assert-key-export.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AssertClause may not have duplicate keys (export declaration) +esid: sec-modules +info: | + AssertClause:assert{AssertEntries,opt} + + - It is a Syntax Error if AssertClauseToAssertions of AssertClause has two + entries a and b such that a.[[Key]] is b.[[Key]]. +features: [import-assertions] +flags: [module] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +export * from './import-assertion-3_FIXTURE.js' assert { + test262_a: '', + test262_b: '', + 'test262_\u0061': '' +}; diff --git a/test/language/module-code/early-dup-assert-key-import-nobinding.js b/test/language/module-code/early-dup-assert-key-import-nobinding.js new file mode 100644 index 00000000000..7c8e6e3c39e --- /dev/null +++ b/test/language/module-code/early-dup-assert-key-import-nobinding.js @@ -0,0 +1,25 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause may not have duplicate keys (import declaration without binding) +esid: sec-modules +info: | + AssertClause:assert{AssertEntries,opt} + + - It is a Syntax Error if AssertClauseToAssertions of AssertClause has two + entries a and b such that a.[[Key]] is b.[[Key]]. +features: [import-assertions] +flags: [module] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +import './import-assertion-2_FIXTURE.js' assert { + test262_a: '', + test262_b: '', + 'test262_\u0061': '' +}; diff --git a/test/language/module-code/early-dup-assert-key-import-withbinding.js b/test/language/module-code/early-dup-assert-key-import-withbinding.js new file mode 100644 index 00000000000..57b66d59a44 --- /dev/null +++ b/test/language/module-code/early-dup-assert-key-import-withbinding.js @@ -0,0 +1,25 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause may not have duplicate keys (import declaration with binding) +esid: sec-modules +info: | + AssertClause:assert{AssertEntries,opt} + + - It is a Syntax Error if AssertClauseToAssertions of AssertClause has two + entries a and b such that a.[[Key]] is b.[[Key]]. +features: [import-assertions] +flags: [module] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +import x from './import-assertion-1_FIXTURE.js' assert { + test262_a: '', + test262_b: '', + 'test262_\u0061': '' +}; diff --git a/test/language/module-code/eval-gtbndng-indirect-faux-assertion.js b/test/language/module-code/eval-gtbndng-indirect-faux-assertion.js new file mode 100644 index 00000000000..09f6f3d6067 --- /dev/null +++ b/test/language/module-code/eval-gtbndng-indirect-faux-assertion.js @@ -0,0 +1,70 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause in ImportDeclaration may not be preceded by a line terminator +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral + + The restriction LineTerminator could be verified more simply with a negative + syntax test. This test is designed to parse successfully in order to verify + the restriction more precisely. +features: [import-assertions, globalThis] +flags: [module, raw] +---*/ + +var callCount = 0; + +// Define a property on the global "this" value so that the effect of the +// expected IdentifierReference can be observed. +Object.defineProperty(globalThis, 'assert', { + get: function() { + callCount += 1; + } +}); + +import x from './import-assertion-1_FIXTURE.js' +assert +{test262:''}; + +if (x !== 262.1) { + throw 'module value incorrectly imported - first declaration'; +} + +if (callCount !== 1) { + throw 'IdentifierReference not recognized - first declaration'; +} + +import './import-assertion-2_FIXTURE.js' +assert +{test262:''}; + +if (globalThis.test262 !== 262.2) { + throw 'module value incorrectly imported - second declaration'; +} + +if (callCount !== 2) { + throw 'IdentifierReference not recognized - second declaration'; +} + +export * from './import-assertion-3_FIXTURE.js' +assert +{test262:''}; + +if (callCount !== 3) { + throw 'IdentifierReference not recognized - third declaration'; +} diff --git a/test/language/module-code/import-assertion-1_FIXTURE.js b/test/language/module-code/import-assertion-1_FIXTURE.js new file mode 100644 index 00000000000..3e4b8af7ff7 --- /dev/null +++ b/test/language/module-code/import-assertion-1_FIXTURE.js @@ -0,0 +1,3 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +export default 262.1; diff --git a/test/language/module-code/import-assertion-2_FIXTURE.js b/test/language/module-code/import-assertion-2_FIXTURE.js new file mode 100644 index 00000000000..c05aa68d2e8 --- /dev/null +++ b/test/language/module-code/import-assertion-2_FIXTURE.js @@ -0,0 +1,3 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +globalThis.test262 = 262.2; diff --git a/test/language/module-code/import-assertion-3_FIXTURE.js b/test/language/module-code/import-assertion-3_FIXTURE.js new file mode 100644 index 00000000000..376f79094de --- /dev/null +++ b/test/language/module-code/import-assertion-3_FIXTURE.js @@ -0,0 +1,3 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +export default 262.3; diff --git a/test/language/module-code/import-assertion-empty.js b/test/language/module-code/import-assertion-empty.js new file mode 100644 index 00000000000..0df9911c522 --- /dev/null +++ b/test/language/module-code/import-assertion-empty.js @@ -0,0 +1,30 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AssertClause in ImportDeclaration may be empty +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral +features: [import-assertions, globalThis] +flags: [module] +---*/ + +import x from './import-assertion-1_FIXTURE.js' assert {}; +import './import-assertion-2_FIXTURE.js' assert {}; +export * from './import-assertion-3_FIXTURE.js' assert {}; + +assert.sameValue(x, 262.1); +assert.sameValue(globalThis.test262, 262.2); diff --git a/test/language/module-code/import-assertion-key-identifiername.js b/test/language/module-code/import-assertion-key-identifiername.js new file mode 100644 index 00000000000..dbb1d48f62f --- /dev/null +++ b/test/language/module-code/import-assertion-key-identifiername.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause in ImportDeclaration may use any valid IdentifierName as a key +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral +features: [import-assertions] +flags: [module] +---*/ + +import x from './import-assertion-1_FIXTURE.js' assert {if:''}; +import './import-assertion-2_FIXTURE.js' assert {if:''}; +export * from './import-assertion-3_FIXTURE.js' assert {if:''}; + +assert.sameValue(x, 262.1); +assert.sameValue(globalThis.test262, 262.2); diff --git a/test/language/module-code/import-assertion-key-string-double.js b/test/language/module-code/import-assertion-key-string-double.js new file mode 100644 index 00000000000..663ef220c30 --- /dev/null +++ b/test/language/module-code/import-assertion-key-string-double.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause in ImportDeclaration may use a string literal as a key (delimited with U+0022) +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral +features: [import-assertions, globalThis] +flags: [module] +---*/ + +import x from './import-assertion-1_FIXTURE.js' assert {"test262\u0078":''}; +import './import-assertion-2_FIXTURE.js' assert {"test262\u0078":''}; +export * from './import-assertion-3_FIXTURE.js' assert {"test262\u0078":''}; + +assert.sameValue(x, 262.1); +assert.sameValue(globalThis.test262, 262.2); diff --git a/test/language/module-code/import-assertion-key-string-single.js b/test/language/module-code/import-assertion-key-string-single.js new file mode 100644 index 00000000000..4b04c708779 --- /dev/null +++ b/test/language/module-code/import-assertion-key-string-single.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause in ImportDeclaration may use a string literal as a key (delimited with U+0027) +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral +features: [import-assertions, globalThis] +flags: [module] +---*/ + +import x from './import-assertion-1_FIXTURE.js' assert {'test262\u0078':''}; +import './import-assertion-2_FIXTURE.js' assert {'test262\u0078':''}; +export * from './import-assertion-3_FIXTURE.js' assert {'test262\u0078':''}; + +assert.sameValue(x, 262.1); +assert.sameValue(globalThis.test262, 262.2); diff --git a/test/language/module-code/import-assertion-many.js b/test/language/module-code/import-assertion-many.js new file mode 100644 index 00000000000..6f0a405740c --- /dev/null +++ b/test/language/module-code/import-assertion-many.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause in ImportDeclaration may contain multiple AssertEntries +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral +features: [import-assertions, globalThis] +flags: [module] +---*/ + +import x from './import-assertion-1_FIXTURE.js' assert {test262_1:'',test262_2:'',test262_3:'',test262_4:''}; +import './import-assertion-2_FIXTURE.js' assert {test262_1:'',test262_2:'',test262_3:'',test262_4:''}; +export * from './import-assertion-3_FIXTURE.js' assert {test262_1:'',test262_2:'',test262_3:'',test262_4:''}; + +assert.sameValue(x, 262.1); +assert.sameValue(globalThis.test262, 262.2); diff --git a/test/language/module-code/import-assertion-newlines.js b/test/language/module-code/import-assertion-newlines.js new file mode 100644 index 00000000000..80d42c736ce --- /dev/null +++ b/test/language/module-code/import-assertion-newlines.js @@ -0,0 +1,49 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause in ImportDeclaration may include line terminators +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral + + This test uses all four LineFeed characters in order to completely verify the + grammar. +features: [import-assertions, globalThis] +flags: [module] +---*/ + +import x from './import-assertion-1_FIXTURE.js' assert + 

{ + 

test262 + 

: + 

'' + 

}; +import './import-assertion-2_FIXTURE.js' assert + 

{ + 

test262 + 

: + 

'' + 

}; +export * from './import-assertion-3_FIXTURE.js' assert + 

{ + 

test262 + 

: + 

'' + 

}; + +assert.sameValue(x, 262.1); +assert.sameValue(globalThis.test262, 262.2); diff --git a/test/language/module-code/import-assertion-trlng-comma.js b/test/language/module-code/import-assertion-trlng-comma.js new file mode 100644 index 00000000000..1daceef77d7 --- /dev/null +++ b/test/language/module-code/import-assertion-trlng-comma.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause in ImportDeclaration may contain a trailing comma +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral +features: [import-assertions, globalThis] +flags: [module] +---*/ + +import x from './import-assertion-1_FIXTURE.js' assert {test262:'',}; +import './import-assertion-2_FIXTURE.js' assert {test262:'',}; +export * from './import-assertion-3_FIXTURE.js' assert {test262:'',}; + +assert.sameValue(x, 262.1); +assert.sameValue(globalThis.test262, 262.2); diff --git a/test/language/module-code/import-assertion-value-string-double.js b/test/language/module-code/import-assertion-value-string-double.js new file mode 100644 index 00000000000..59c810deabd --- /dev/null +++ b/test/language/module-code/import-assertion-value-string-double.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause in ImportDeclaration may use a string literal as a value (delimited with U+0022) +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral +features: [import-assertions, globalThis] +flags: [module] +---*/ + +import x from './import-assertion-1_FIXTURE.js' assert {test262:"\u0078"}; +import './import-assertion-2_FIXTURE.js' assert {test262:"\u0078"}; +export * from './import-assertion-3_FIXTURE.js' assert {test262:"\u0078"}; + +assert.sameValue(x, 262.1); +assert.sameValue(globalThis.test262, 262.2); diff --git a/test/language/module-code/import-assertion-value-string-single.js b/test/language/module-code/import-assertion-value-string-single.js new file mode 100644 index 00000000000..a6d473863ce --- /dev/null +++ b/test/language/module-code/import-assertion-value-string-single.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + AssertClause in ImportDeclaration may use a string literal as a value (delimited with U+0027) +esid: sec-modules +info: | + ImportDeclaration: + import ModuleSpecifier[no LineTerminator here] AssertClause; + + AssertClause: + assert {} + assert {AssertEntries ,opt} + + AssertEntries: + AssertionKey : StringLiteral + AssertionKey : StringLiteral , AssertEntries + + AssertionKey: + IdentifierName + StringLiteral +features: [import-assertions, globalThis] +flags: [module] +---*/ + +import x from './import-assertion-1_FIXTURE.js' assert {test262:'\u0078'}; +import './import-assertion-2_FIXTURE.js' assert {test262:'\u0078'}; +export * from './import-assertion-3_FIXTURE.js' assert {test262:'\u0078'}; + +assert.sameValue(x, 262.1); +assert.sameValue(globalThis.test262, 262.2);