Skip to content

Commit 573058e

Browse files
Add syntax tests for import.defer (#4374)
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.
1 parent d405213 commit 573058e

File tree

130 files changed

+4610
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+4610
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2020 Rick Waldron. All rights reserved.
2+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
5+
/*---
6+
esid: sec-static-semantics-static-semantics-assignmenttargettype
7+
desc: >
8+
Static Semantics AssignmentTargetType, Return invalid.
9+
info: |
10+
ImportCall
11+
Static Semantics AssignmentTargetType, Return invalid.
12+
template: invalid
13+
flags: [module]
14+
features: [import-defer]
15+
negative:
16+
phase: parse
17+
type: SyntaxError
18+
---*/
19+
20+
//- assignmenttarget
21+
import.defer()
22+
//- operator
23+
=
24+
//- value
25+
1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: It's a SyntaxError if AssignmentExpression is omitted
7+
template: syntax/invalid
8+
info: |
9+
ImportCall[Yield, Await] :
10+
import . defer ( AssignmentExpression[+In, ?Yield, ?Await] )
11+
features: [import-defer]
12+
---*/
13+
//- import
14+
import.defer()
15+
//- teardown
16+
/* The params region intentionally empty */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: Calling import.defer('')
7+
template: syntax/valid
8+
features: [import-defer]
9+
---*/
10+
11+
//- import
12+
import.defer('./empty_FIXTURE.js')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// Copyright (C) 2018 Leo Balter. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
desc: ImportCall is a CallExpression, it can't be preceded by the new keyword
6+
template: syntax/invalid
7+
info: |
8+
CallExpression:
9+
ImportCall
10+
11+
ImportCall :
12+
import . defer ( AssignmentExpression[+In, ?Yield, ?Await] )
13+
14+
features: [import-defer]
15+
---*/
16+
17+
//- import
18+
new import.defer('./empty_FIXTURE.js')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// Copyright (C) 2018 Leo Balter. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
desc: ImportCall is not extensible - no rest parameter
6+
template: syntax/invalid
7+
info: |
8+
ImportCall :
9+
import . defer ( AssignmentExpression[+In, ?Yield] )
10+
11+
This production doesn't allow the following production from ArgumentsList:
12+
13+
... AssignmentExpression
14+
features: [import-defer]
15+
---*/
16+
17+
//- import
18+
import.defer(...['./empty_FIXTURE.js'])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// Copyright (C) 2018 Leo Balter. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
desc: import.defer() can be used in script code
6+
template: syntax/valid
7+
features: [import-defer]
8+
---*/
9+
10+
//- import
11+
import.defer('./empty_FIXTURE.js')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: >
7+
Abrupt from ToString(specifier) rejects the promise
8+
esid: sec-moduleevaluation
9+
info: |
10+
Import Calls
11+
12+
Runtime Semantics: Evaluation
13+
14+
ImportCall : import . defer ( |AssignmentExpression| )
15+
1. Return ? EvaluateImportCall(|AssignmentExpression|, ~defer~)
16+
17+
EvaluateImportCall ( specifierExpression, phase )
18+
1. Let _referrer_ be GetActiveScriptOrModule().
19+
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record.
20+
1. Let _specifierRef_ be ? Evaluation of _specifierExpression_.
21+
1. Let _specifier_ be ? GetValue(_specifierRef_).
22+
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
23+
1. Let _specifierString_ be Completion(ToString(_specifier_)).
24+
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
25+
...
26+
template: catch
27+
features: [import-defer]
28+
---*/
29+
30+
//- setup
31+
const obj = {
32+
toString() {
33+
throw 'custom error';
34+
}
35+
};
36+
37+
//- import
38+
import.defer(obj)
39+
//- body
40+
assert.sameValue(error, 'custom error');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file was procedurally generated from the following sources:
2+
// - src/assignment-target-type/importcall-defer.case
3+
// - src/assignment-target-type/invalid/direct.template
4+
/*---
5+
description: Static Semantics AssignmentTargetType, Return invalid. (Direct assignment)
6+
features: [import-defer]
7+
flags: [generated, module]
8+
negative:
9+
phase: parse
10+
type: SyntaxError
11+
info: |
12+
Direct assignment
13+
14+
ImportCall
15+
Static Semantics AssignmentTargetType, Return invalid.
16+
17+
---*/
18+
19+
$DONOTEVALUATE();
20+
21+
import.defer() = 1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This file was procedurally generated from the following sources:
2+
// - src/assignment-target-type/importcall-defer.case
3+
// - src/assignment-target-type/invalid/parenthesized.template
4+
/*---
5+
description: Static Semantics AssignmentTargetType, Return invalid. (ParenthesizedExpression)
6+
esid: sec-grouping-operator-static-semantics-assignmenttargettype
7+
features: [import-defer]
8+
flags: [generated, module]
9+
negative:
10+
phase: parse
11+
type: SyntaxError
12+
info: |
13+
ParenthesizedExpression: (Expression)
14+
15+
Return AssignmentTargetType of Expression.
16+
17+
ImportCall
18+
Static Semantics AssignmentTargetType, Return invalid.
19+
20+
---*/
21+
22+
$DONOTEVALUATE();
23+
24+
(import.defer()) = 1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This file was procedurally generated from the following sources:
2+
// - src/dynamic-import/import-defer-specifier-tostring-abrupt-rejects.case
3+
// - src/dynamic-import/catch/nested-arrow.template
4+
/*---
5+
description: Abrupt from ToString(specifier) rejects the promise (nested arrow)
6+
esid: sec-import-call-runtime-semantics-evaluation
7+
features: [import-defer, dynamic-import]
8+
flags: [generated, async]
9+
info: |
10+
ImportCall :
11+
import( AssignmentExpression )
12+
13+
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule().
14+
2. Assert: referencingScriptOrModule is a Script Record or Module Record (i.e. is not null).
15+
3. Let argRef be the result of evaluating AssignmentExpression.
16+
4. Let specifier be ? GetValue(argRef).
17+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
18+
6. Let specifierString be ToString(specifier).
19+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
20+
8. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability).
21+
9. Return promiseCapability.[[Promise]].
22+
23+
24+
Import Calls
25+
26+
Runtime Semantics: Evaluation
27+
28+
ImportCall : import . defer ( |AssignmentExpression| )
29+
1. Return ? EvaluateImportCall(|AssignmentExpression|, ~defer~)
30+
31+
EvaluateImportCall ( specifierExpression, phase )
32+
1. Let _referrer_ be GetActiveScriptOrModule().
33+
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record.
34+
1. Let _specifierRef_ be ? Evaluation of _specifierExpression_.
35+
1. Let _specifier_ be ? GetValue(_specifierRef_).
36+
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
37+
1. Let _specifierString_ be Completion(ToString(_specifier_)).
38+
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
39+
...
40+
41+
---*/
42+
const obj = {
43+
toString() {
44+
throw 'custom error';
45+
}
46+
};
47+
48+
49+
let f = () => {
50+
import.defer(obj).catch(error => {
51+
52+
assert.sameValue(error, 'custom error');
53+
54+
}).then($DONE, $DONE);
55+
};
56+
57+
f();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This file was procedurally generated from the following sources:
2+
// - src/dynamic-import/import-defer-specifier-tostring-abrupt-rejects.case
3+
// - src/dynamic-import/catch/nested-async-arrow-fn-await.template
4+
/*---
5+
description: Abrupt from ToString(specifier) rejects the promise (nested in async arrow function, awaited)
6+
esid: sec-import-call-runtime-semantics-evaluation
7+
features: [import-defer, dynamic-import]
8+
flags: [generated, async]
9+
info: |
10+
ImportCall :
11+
import( AssignmentExpression )
12+
13+
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule().
14+
2. Assert: referencingScriptOrModule is a Script Record or Module Record (i.e. is not null).
15+
3. Let argRef be the result of evaluating AssignmentExpression.
16+
4. Let specifier be ? GetValue(argRef).
17+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
18+
6. Let specifierString be ToString(specifier).
19+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
20+
8. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability).
21+
9. Return promiseCapability.[[Promise]].
22+
23+
24+
Import Calls
25+
26+
Runtime Semantics: Evaluation
27+
28+
ImportCall : import . defer ( |AssignmentExpression| )
29+
1. Return ? EvaluateImportCall(|AssignmentExpression|, ~defer~)
30+
31+
EvaluateImportCall ( specifierExpression, phase )
32+
1. Let _referrer_ be GetActiveScriptOrModule().
33+
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record.
34+
1. Let _specifierRef_ be ? Evaluation of _specifierExpression_.
35+
1. Let _specifier_ be ? GetValue(_specifierRef_).
36+
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
37+
1. Let _specifierString_ be Completion(ToString(_specifier_)).
38+
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
39+
...
40+
41+
---*/
42+
const obj = {
43+
toString() {
44+
throw 'custom error';
45+
}
46+
};
47+
48+
49+
const f = async () => {
50+
await import.defer(obj);
51+
}
52+
53+
f().catch(error => {
54+
55+
assert.sameValue(error, 'custom error');
56+
57+
}).then($DONE, $DONE);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// This file was procedurally generated from the following sources:
2+
// - src/dynamic-import/import-defer-specifier-tostring-abrupt-rejects.case
3+
// - src/dynamic-import/catch/nested-async-arrow-fn-return-await.template
4+
/*---
5+
description: Abrupt from ToString(specifier) rejects the promise (nested in async arrow function, returned)
6+
esid: sec-import-call-runtime-semantics-evaluation
7+
features: [import-defer, dynamic-import]
8+
flags: [generated, async]
9+
info: |
10+
ImportCall :
11+
import( AssignmentExpression )
12+
13+
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule().
14+
2. Assert: referencingScriptOrModule is a Script Record or Module Record (i.e. is not null).
15+
3. Let argRef be the result of evaluating AssignmentExpression.
16+
4. Let specifier be ? GetValue(argRef).
17+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
18+
6. Let specifierString be ToString(specifier).
19+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
20+
8. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability).
21+
9. Return promiseCapability.[[Promise]].
22+
23+
24+
Import Calls
25+
26+
Runtime Semantics: Evaluation
27+
28+
ImportCall : import . defer ( |AssignmentExpression| )
29+
1. Return ? EvaluateImportCall(|AssignmentExpression|, ~defer~)
30+
31+
EvaluateImportCall ( specifierExpression, phase )
32+
1. Let _referrer_ be GetActiveScriptOrModule().
33+
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record.
34+
1. Let _specifierRef_ be ? Evaluation of _specifierExpression_.
35+
1. Let _specifier_ be ? GetValue(_specifierRef_).
36+
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
37+
1. Let _specifierString_ be Completion(ToString(_specifier_)).
38+
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
39+
...
40+
41+
---*/
42+
const obj = {
43+
toString() {
44+
throw 'custom error';
45+
}
46+
};
47+
48+
49+
const f = async () => await import.defer(obj);
50+
51+
f().catch(error => {
52+
53+
assert.sameValue(error, 'custom error');
54+
55+
}).then($DONE, $DONE);

0 commit comments

Comments
 (0)