forked from tc39/test262
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These tests are all based on the existing dynamic import syntax tests, just updated to use the new syntax. This PR does not contain any manually written tests -- they are all generated.
- Loading branch information
1 parent
d49db63
commit 919e9f8
Showing
130 changed files
with
4,699 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (C) 2020 Rick Waldron. All rights reserved. | ||
// Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-static-semantics-static-semantics-assignmenttargettype | ||
desc: > | ||
Static Semantics AssignmentTargetType, Return invalid. | ||
info: | | ||
ImportCall | ||
Static Semantics AssignmentTargetType, Return invalid. | ||
template: invalid | ||
flags: [module] | ||
features: [import-defer] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ | ||
|
||
//- assignmenttarget | ||
import.defer() | ||
//- operator | ||
= | ||
//- value | ||
1 |
16 changes: 16 additions & 0 deletions
16
src/dynamic-import/import-defer-assignment-expr-not-optional.case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
// Copyright (C) 2018 Rick Waldron. All rights reserved. | ||
// Copyright (C) 2018 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: It's a SyntaxError if AssignmentExpression is omitted | ||
template: syntax/invalid | ||
info: | | ||
ImportCall[Yield, Await] : | ||
import . defer ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
features: [import-defer] | ||
---*/ | ||
//- import | ||
import.defer() | ||
//- teardown | ||
/* The params region intentionally empty */ |
12 changes: 12 additions & 0 deletions
12
src/dynamic-import/import-defer-empty-str-is-valid-assign-expr.case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
// Copyright (C) 2018 Rick Waldron. All rights reserved. | ||
// Copyright (C) 2018 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: Calling import.defer('') | ||
template: syntax/valid | ||
features: [import-defer] | ||
---*/ | ||
|
||
//- import | ||
import.defer('./empty_FIXTURE.js') |
18 changes: 18 additions & 0 deletions
18
src/dynamic-import/import-defer-no-new-call-expression.case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
// Copyright (C) 2018 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: ImportCall is a CallExpression, it can't be preceded by the new keyword | ||
template: syntax/invalid | ||
info: | | ||
CallExpression: | ||
ImportCall | ||
|
||
ImportCall : | ||
import . defer ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
|
||
features: [import-defer] | ||
---*/ | ||
|
||
//- import | ||
new import.defer('./empty_FIXTURE.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
// 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 - no rest parameter | ||
template: syntax/invalid | ||
info: | | ||
ImportCall : | ||
import . source ( AssignmentExpression[+In, ?Yield] ) | ||
|
||
This production doesn't allow the following production from ArgumentsList: | ||
|
||
... AssignmentExpression | ||
features: [import-defer] | ||
---*/ | ||
|
||
//- import | ||
import.defer(...['./empty_FIXTURE.js']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
// Copyright (C) 2018 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: import.defer() can be used in script code | ||
template: syntax/valid | ||
features: [import-defer] | ||
---*/ | ||
|
||
//- setup | ||
// This is still valid in script code, and should not be valid for module code | ||
// https://tc39.github.io/ecma262/#sec-scripts-static-semantics-lexicallydeclarednames | ||
var smoosh; function smoosh() {} | ||
|
||
//- import | ||
import.defer('./empty_FIXTURE.js') |
40 changes: 40 additions & 0 deletions
40
src/dynamic-import/import-defer-specifier-tostring-abrupt-rejects.case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
// Copyright (C) 2018 Rick Waldron. All rights reserved. | ||
// Copyright (C) 2018 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: > | ||
Abrupt from ToString(specifier) rejects the promise | ||
esid: sec-moduleevaluation | ||
info: | | ||
Import Calls | ||
|
||
Runtime Semantics: Evaluation | ||
|
||
ImportCall : import . defer ( |AssignmentExpression| ) | ||
1. Return ? EvaluateImportCall(|AssignmentExpression|, ~defer~) | ||
|
||
EvaluateImportCall ( specifierExpression, phase ) | ||
1. Let _referrer_ be GetActiveScriptOrModule(). | ||
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record. | ||
1. Let _specifierRef_ be ? Evaluation of _specifierExpression_. | ||
1. Let _specifier_ be ? GetValue(_specifierRef_). | ||
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). | ||
1. Let _specifierString_ be Completion(ToString(_specifier_)). | ||
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_). | ||
... | ||
template: catch | ||
features: [import-defer] | ||
---*/ | ||
|
||
//- setup | ||
const obj = { | ||
toString() { | ||
throw 'custom error'; | ||
} | ||
}; | ||
|
||
//- import | ||
import.defer(obj) | ||
//- body | ||
assert.sameValue(error, 'custom error'); |
21 changes: 21 additions & 0 deletions
21
test/language/expressions/assignmenttargettype/direct-importcall-defer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This file was procedurally generated from the following sources: | ||
// - src/assignment-target-type/importcall-defer.case | ||
// - src/assignment-target-type/invalid/direct.template | ||
/*--- | ||
description: Static Semantics AssignmentTargetType, Return invalid. (Direct assignment) | ||
features: [import-defer] | ||
flags: [generated, module] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
info: | | ||
Direct assignment | ||
ImportCall | ||
Static Semantics AssignmentTargetType, Return invalid. | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
import.defer() = 1; |
24 changes: 24 additions & 0 deletions
24
test/language/expressions/assignmenttargettype/parenthesized-importcall-defer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This file was procedurally generated from the following sources: | ||
// - src/assignment-target-type/importcall-defer.case | ||
// - src/assignment-target-type/invalid/parenthesized.template | ||
/*--- | ||
description: Static Semantics AssignmentTargetType, Return invalid. (ParenthesizedExpression) | ||
esid: sec-grouping-operator-static-semantics-assignmenttargettype | ||
features: [import-defer] | ||
flags: [generated, module] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
info: | | ||
ParenthesizedExpression: (Expression) | ||
Return AssignmentTargetType of Expression. | ||
ImportCall | ||
Static Semantics AssignmentTargetType, Return invalid. | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
(import.defer()) = 1; |
57 changes: 57 additions & 0 deletions
57
...-import/catch/nested-arrow-import-catch-import-defer-specifier-tostring-abrupt-rejects.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// This file was procedurally generated from the following sources: | ||
// - src/dynamic-import/import-defer-specifier-tostring-abrupt-rejects.case | ||
// - src/dynamic-import/catch/nested-arrow.template | ||
/*--- | ||
description: Abrupt from ToString(specifier) rejects the promise (nested arrow) | ||
esid: sec-import-call-runtime-semantics-evaluation | ||
features: [import-defer, dynamic-import] | ||
flags: [generated, async] | ||
info: | | ||
ImportCall : | ||
import( AssignmentExpression ) | ||
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule(). | ||
2. Assert: referencingScriptOrModule is a Script Record or Module Record (i.e. is not null). | ||
3. Let argRef be the result of evaluating AssignmentExpression. | ||
4. Let specifier be ? GetValue(argRef). | ||
5. Let promiseCapability be ! NewPromiseCapability(%Promise%). | ||
6. Let specifierString be ToString(specifier). | ||
7. IfAbruptRejectPromise(specifierString, promiseCapability). | ||
8. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability). | ||
9. Return promiseCapability.[[Promise]]. | ||
Import Calls | ||
Runtime Semantics: Evaluation | ||
ImportCall : import . defer ( |AssignmentExpression| ) | ||
1. Return ? EvaluateImportCall(|AssignmentExpression|, ~defer~) | ||
EvaluateImportCall ( specifierExpression, phase ) | ||
1. Let _referrer_ be GetActiveScriptOrModule(). | ||
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record. | ||
1. Let _specifierRef_ be ? Evaluation of _specifierExpression_. | ||
1. Let _specifier_ be ? GetValue(_specifierRef_). | ||
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). | ||
1. Let _specifierString_ be Completion(ToString(_specifier_)). | ||
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_). | ||
... | ||
---*/ | ||
const obj = { | ||
toString() { | ||
throw 'custom error'; | ||
} | ||
}; | ||
|
||
|
||
let f = () => { | ||
import.defer(obj).catch(error => { | ||
|
||
assert.sameValue(error, 'custom error'); | ||
|
||
}).then($DONE, $DONE); | ||
}; | ||
|
||
f(); |
57 changes: 57 additions & 0 deletions
57
...catch/nested-async-arrow-function-await-import-defer-specifier-tostring-abrupt-rejects.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// This file was procedurally generated from the following sources: | ||
// - src/dynamic-import/import-defer-specifier-tostring-abrupt-rejects.case | ||
// - src/dynamic-import/catch/nested-async-arrow-fn-await.template | ||
/*--- | ||
description: Abrupt from ToString(specifier) rejects the promise (nested in async arrow function, awaited) | ||
esid: sec-import-call-runtime-semantics-evaluation | ||
features: [import-defer, dynamic-import] | ||
flags: [generated, async] | ||
info: | | ||
ImportCall : | ||
import( AssignmentExpression ) | ||
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule(). | ||
2. Assert: referencingScriptOrModule is a Script Record or Module Record (i.e. is not null). | ||
3. Let argRef be the result of evaluating AssignmentExpression. | ||
4. Let specifier be ? GetValue(argRef). | ||
5. Let promiseCapability be ! NewPromiseCapability(%Promise%). | ||
6. Let specifierString be ToString(specifier). | ||
7. IfAbruptRejectPromise(specifierString, promiseCapability). | ||
8. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability). | ||
9. Return promiseCapability.[[Promise]]. | ||
Import Calls | ||
Runtime Semantics: Evaluation | ||
ImportCall : import . defer ( |AssignmentExpression| ) | ||
1. Return ? EvaluateImportCall(|AssignmentExpression|, ~defer~) | ||
EvaluateImportCall ( specifierExpression, phase ) | ||
1. Let _referrer_ be GetActiveScriptOrModule(). | ||
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record. | ||
1. Let _specifierRef_ be ? Evaluation of _specifierExpression_. | ||
1. Let _specifier_ be ? GetValue(_specifierRef_). | ||
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). | ||
1. Let _specifierString_ be Completion(ToString(_specifier_)). | ||
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_). | ||
... | ||
---*/ | ||
const obj = { | ||
toString() { | ||
throw 'custom error'; | ||
} | ||
}; | ||
|
||
|
||
const f = async () => { | ||
await import.defer(obj); | ||
} | ||
|
||
f().catch(error => { | ||
|
||
assert.sameValue(error, 'custom error'); | ||
|
||
}).then($DONE, $DONE); |
55 changes: 55 additions & 0 deletions
55
...ested-async-arrow-function-return-await-import-defer-specifier-tostring-abrupt-rejects.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This file was procedurally generated from the following sources: | ||
// - src/dynamic-import/import-defer-specifier-tostring-abrupt-rejects.case | ||
// - src/dynamic-import/catch/nested-async-arrow-fn-return-await.template | ||
/*--- | ||
description: Abrupt from ToString(specifier) rejects the promise (nested in async arrow function, returned) | ||
esid: sec-import-call-runtime-semantics-evaluation | ||
features: [import-defer, dynamic-import] | ||
flags: [generated, async] | ||
info: | | ||
ImportCall : | ||
import( AssignmentExpression ) | ||
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule(). | ||
2. Assert: referencingScriptOrModule is a Script Record or Module Record (i.e. is not null). | ||
3. Let argRef be the result of evaluating AssignmentExpression. | ||
4. Let specifier be ? GetValue(argRef). | ||
5. Let promiseCapability be ! NewPromiseCapability(%Promise%). | ||
6. Let specifierString be ToString(specifier). | ||
7. IfAbruptRejectPromise(specifierString, promiseCapability). | ||
8. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability). | ||
9. Return promiseCapability.[[Promise]]. | ||
Import Calls | ||
Runtime Semantics: Evaluation | ||
ImportCall : import . defer ( |AssignmentExpression| ) | ||
1. Return ? EvaluateImportCall(|AssignmentExpression|, ~defer~) | ||
EvaluateImportCall ( specifierExpression, phase ) | ||
1. Let _referrer_ be GetActiveScriptOrModule(). | ||
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record. | ||
1. Let _specifierRef_ be ? Evaluation of _specifierExpression_. | ||
1. Let _specifier_ be ? GetValue(_specifierRef_). | ||
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). | ||
1. Let _specifierString_ be Completion(ToString(_specifier_)). | ||
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_). | ||
... | ||
---*/ | ||
const obj = { | ||
toString() { | ||
throw 'custom error'; | ||
} | ||
}; | ||
|
||
|
||
const f = async () => await import.defer(obj); | ||
|
||
f().catch(error => { | ||
|
||
assert.sameValue(error, 'custom error'); | ||
|
||
}).then($DONE, $DONE); |
Oops, something went wrong.