Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2025 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-moduleevaluation
description: >
Simultaneous imports of a module with top-level await should all wait for evaluation to complete
info: |
Module Evaluation
1. If module.[[TopLevelCapability]] is not empty, then
a. Return module.[[TopLevelCapability]].[[Promise]].

When multiple modules simultaneously import the same module with top-level await,
all import promises should wait for the module's top-level capability to resolve.

flags: [module, async]
features: [top-level-await, dynamic-import]
---*/

let continueExecution;
globalThis.promise = new Promise((resolve) => continueExecution = resolve);

const executionStartPromise = new Promise((resolve) => globalThis.executionStarted = resolve);

const importPromises = [];

for (let i = 0; i < 3; i++) {
importPromises.push(import("./simultaneous-imports-race-condition_FIXTURE.js"));
}

await executionStartPromise;

continueExecution();

const results = await Promise.all(importPromises);

const firstResult = results[0];
for (let i = 1; i < results.length; i++) {
assert.sameValue(results[i], firstResult,
`Import ${i} should return the same module namespace`);
}

assert.sameValue(firstResult.exportedValue, "success", "Exported value should be correct");
assert.sameValue(firstResult.importCount, 3, "Module should have been imported 3 times");

$DONE();
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2025 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

globalThis.executionStarted();

let importCount = 0;
importCount++;

await globalThis.promise;

export const exportedValue = "success";
export { importCount };