Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add syntax tests for import.defer #4374

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/assignment-target-type/importcall-defer.case
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
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 */
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 src/dynamic-import/import-defer-no-new-call-expression.case
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')
18 changes: 18 additions & 0 deletions src/dynamic-import/import-defer-no-rest-param.case
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 . defer ( AssignmentExpression[+In, ?Yield] )

This production doesn't allow the following production from ArgumentsList:

... AssignmentExpression
features: [import-defer]
---*/

//- import
import.defer(...['./empty_FIXTURE.js'])
11 changes: 11 additions & 0 deletions src/dynamic-import/import-defer-script-code-valid.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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]
---*/

//- import
import.defer('./empty_FIXTURE.js')
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');
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;
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;
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();
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);
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);
Loading