-
Notifications
You must be signed in to change notification settings - Fork 481
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
Increase coverage for dynamic import and top-level await #4421
Open
nicolo-ribaudo
wants to merge
1
commit into
tc39:main
Choose a base branch
from
nicolo-ribaudo:top-level-await
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
test/language/expressions/dynamic-import/import-errored-module.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,46 @@ | ||
// Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-ContinueDynamicImport | ||
description: > | ||
Dynamic import of an already errored module should fail | ||
info: | | ||
ContinueDynamicImport ( _promiseCapability_, _moduleCompletion_ ) | ||
1. ... | ||
1. Let _module_ be _moduleCompletion_.[[Value]]. | ||
1. Let _loadPromise_ be _module_.LoadRequestedModules(). | ||
1. Let _rejectedClosure_ be a new Abstract Closure with parameters (_reason_) that captures _promiseCapability_ and performs the following steps when called: | ||
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _reason_ »). | ||
1. Return ~unused~. | ||
1. Let _onRejected_ be CreateBuiltinFunction(_rejectedClosure_, 1, *""*, « »). | ||
1. Let _linkAndEvaluateClosure_ be a new Abstract Closure with no parameters that captures _module_, _promiseCapability_, and _onRejected_ and performs the following steps when called: | ||
1. Let _link_ be Completion(_module_.Link()). | ||
1. ... | ||
1. Let _evaluatePromise_ be _module_.Evaluate(). | ||
1. Let _fulfilledClosure_ be a new Abstract Closure with no parameters that captures _module_ and _promiseCapability_ and performs the following steps when called: | ||
1. Let _namespace_ be GetModuleNamespace(_module_). | ||
1. Perform ! <emu-meta effects="user-code">Call</emu-meta>(_promiseCapability_.[[Resolve]], *undefined*, « _namespace_ »). | ||
1. Return ~unused~. | ||
1. Let _onFulfilled_ be CreateBuiltinFunction(_fulfilledClosure_, 0, *""*, « »). | ||
1. Perform PerformPromiseThen(_evaluatePromise_, _onFulfilled_, _onRejected_). | ||
1. Return ~unused~. | ||
1. Let _linkAndEvaluate_ be CreateBuiltinFunction(_linkAndEvaluateClosure_, 0, *""*, « »). | ||
1. Perform PerformPromiseThen(_loadPromise_, _linkAndEvaluate_, _onRejected_). | ||
1. Return ~unused~. | ||
|
||
_module_ . Evaluate ( ) | ||
4. If _module_.[[TopLevelCapability]] is not ~empty~, then | ||
a. Return _module_.[[TopLevelCapability]].[[Promise]]. | ||
|
||
flags: [async] | ||
features: [dynamic-import] | ||
---*/ | ||
|
||
import('./import-errored-module_FIXTURE.js').then(() => { | ||
$DONE(new Test262Error('The import should reject (first import)')); | ||
}, () => { | ||
import('./import-errored-module_FIXTURE.js').then(() => { | ||
$DONE(new Test262Error('The import should reject (second import)')); | ||
}, () => $DONE()); | ||
}); |
4 changes: 4 additions & 0 deletions
4
test/language/expressions/dynamic-import/import-errored-module_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,4 @@ | ||
// Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
throw new Error("boom"); |
3 changes: 3 additions & 0 deletions
3
test/language/module-code/top-level-await/dynamic-import-of-waiting-module-2_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,3 @@ | ||
// Copyright (C) 2025 Igalia. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
69 changes: 69 additions & 0 deletions
69
test/language/module-code/top-level-await/dynamic-import-of-waiting-module.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,69 @@ | ||
// Copyright (C) 2025 Igalia. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-ContinueDynamicImport | ||
description: > | ||
Dynamic import of an ~evaluating-async~ module waits for the module to finish its evaluation | ||
info: | | ||
ContinueDynamicImport ( _promiseCapability_, _moduleCompletion_ ) | ||
1. ... | ||
1. Let _module_ be _moduleCompletion_.[[Value]]. | ||
1. Let _loadPromise_ be _module_.LoadRequestedModules(). | ||
1. Let _rejectedClosure_ be a new Abstract Closure with parameters (_reason_) that captures _promiseCapability_ and performs the following steps when called: | ||
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _reason_ »). | ||
1. Return ~unused~. | ||
1. Let _onRejected_ be CreateBuiltinFunction(_rejectedClosure_, 1, *""*, « »). | ||
1. Let _linkAndEvaluateClosure_ be a new Abstract Closure with no parameters that captures _module_, _promiseCapability_, and _onRejected_ and performs the following steps when called: | ||
1. Let _link_ be Completion(_module_.Link()). | ||
1. ... | ||
1. Let _evaluatePromise_ be _module_.Evaluate(). | ||
1. Let _fulfilledClosure_ be a new Abstract Closure with no parameters that captures _module_ and _promiseCapability_ and performs the following steps when called: | ||
1. Let _namespace_ be GetModuleNamespace(_module_). | ||
1. Perform ! <emu-meta effects="user-code">Call</emu-meta>(_promiseCapability_.[[Resolve]], *undefined*, « _namespace_ »). | ||
1. Return ~unused~. | ||
1. Let _onFulfilled_ be CreateBuiltinFunction(_fulfilledClosure_, 0, *""*, « »). | ||
1. Perform PerformPromiseThen(_evaluatePromise_, _onFulfilled_, _onRejected_). | ||
1. Return ~unused~. | ||
1. Let _linkAndEvaluate_ be CreateBuiltinFunction(_linkAndEvaluateClosure_, 0, *""*, « »). | ||
1. Perform PerformPromiseThen(_loadPromise_, _linkAndEvaluate_, _onRejected_). | ||
1. Return ~unused~. | ||
|
||
_module_ . Evaluate ( ) | ||
4. If _module_.[[TopLevelCapability]] is not ~empty~, then | ||
a. Return _module_.[[TopLevelCapability]].[[Promise]]. | ||
|
||
flags: [async] | ||
features: [dynamic-import] | ||
---*/ | ||
|
||
let continueExecution; | ||
globalThis.promise = new Promise(res => continueExecution = res); | ||
|
||
const executionStartPromise = new Promise(res => globalThis.executionStarted = res); | ||
|
||
const promiseForNamespace = import("./dynamic-import-of-waiting-module_FIXTURE.js"); | ||
|
||
executionStartPromise.then(() => { | ||
const promiseForNamespace2 = import("./dynamic-import-of-waiting-module_FIXTURE.js"); | ||
|
||
// We only continuye execution of the first fixture file after importing a second, | ||
// empty, fixture file. This is so that if the implementation uses a separate | ||
// queue to resolve dynamic import promises, if dynamic-import-of-waiting-module_FIXTURE | ||
// wasn't waiting on top-level await its top-level promise would already be resolved. | ||
import("./dynamic-import-of-waiting-module-2_FIXTURE.js").then(() => { | ||
continueExecution(); | ||
}, $DONE); | ||
|
||
let secondPromiseResolved = false; | ||
return Promise.all([ | ||
promiseForNamespace.then(() => { | ||
console.log("Resolving first..."); | ||
assert(!secondPromiseResolved, "The second import should not resolve before the first one"); | ||
}), | ||
promiseForNamespace2.then(() => { | ||
console.log("Resolving second..."); | ||
secondPromiseResolved = true; | ||
}) | ||
]); | ||
}).then($DONE, $DONE); |
8 changes: 8 additions & 0 deletions
8
test/language/module-code/top-level-await/dynamic-import-of-waiting-module_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,8 @@ | ||
// Copyright (C) 2025 Igalia. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
globalThis.executionStarted(); | ||
|
||
export let x = 1; | ||
|
||
await globalThis.promise; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not super nice but I don't know how else to give
promiseForNamespace2
a chance to resolve before callingcontinueExecution
. The expected behavior is thatpromiseForNamespace2
will not resolve before that call, so I cannot simply movecontinueExecution()
into a.then
handler on it.