Skip to content

Commit

Permalink
Add syntax tests for import.defer
Browse files Browse the repository at this point in the history
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
nicolo-ribaudo committed Jan 10, 2025
1 parent d49db63 commit 919e9f8
Show file tree
Hide file tree
Showing 130 changed files with 4,699 additions and 0 deletions.
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
16 changes: 16 additions & 0 deletions src/dynamic-import/import-defer-assignment-expr-not-optional.case
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 . source ( AssignmentExpression[+In, ?Yield] )

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

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

//- import
import.defer(...['./empty_FIXTURE.js'])
16 changes: 16 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,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')
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

0 comments on commit 919e9f8

Please sign in to comment.