Files
sousa-gecko/testing/web-platform/tests/wasm/webapi/esm-integration/source-phase-preload.tentative.html
T
Luis Pardo c7300d3696 Bug 1966168 [wpt PR 52498] - [source-phase-imports] Support Wasm Source Phase Imports,
Automatic update from web-platform-tests
[source-phase-imports] Support Wasm Source Phase Imports

Adds ModuleRecord::ResolveSourceCallback to be called when instantiating
source phase children of the module graph.

Implement HostImportModuleWithPhaseDynamically and register it in the V8
isolate, this is called when executing `import.source`.

Add error handling for wasm imports in evaluation phase and non-wasm
imports in source phase.

Move module instantiation behind the ModuleScript interface to properly
throw evaluation phase errors.

Bug: 42204365
Change-Id: Ia3e855180f1f740023864b3499dc451278b53d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6351556
Reviewed-by: Dominic Farolino <dom@chromium.org>
Commit-Queue: Luis Pardo <lpardosixtos@microsoft.com>
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1459475}

--

wpt-commits: 8e1b3aaae7ebbb333ae0ccb1b67a01b5b2d774bf
wpt-pr: 52498

Differential Revision: https://phabricator.services.mozilla.com/D250146
2025-05-20 12:01:08 +00:00

65 lines
2.4 KiB
HTML

<!doctype html>
<title>Preload source phase modules</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
function verifyNumberOfDownloads(url, number, allowTransferSizeOfZero = false) {
var numDownloads = 0;
let absoluteURL = new URL(url, location.href).href;
performance.getEntriesByName(absoluteURL).forEach(entry => {
if (entry.transferSize > 0 || allowTransferSizeOfZero) {
numDownloads++;
}
});
assert_equals(numDownloads, number, url);
}
function attachAndWaitForLoad(element) {
return new Promise((resolve, reject) => {
element.onload = resolve;
element.onerror = reject;
document.body.appendChild(element);
});
}
promise_test(function(t) {
var link = document.createElement('link');
link.rel = 'modulepreload';
link.href = 'resources/exported-names.wasm';
return attachAndWaitForLoad(link).then(() => {
verifyNumberOfDownloads('resources/exported-names.wasm', 1);
let promise = new Promise((resolve) => {window.resolveStatic = resolve});
// Verify that <script> doesn't fetch the module again.
var script = document.createElement('script');
script.type = 'module';
script.text = "import source exportedNamesSource from './resources/exported-names.wasm'; window.resolveStatic()";
document.body.appendChild(script);
return promise;
}).then(() => {
verifyNumberOfDownloads('resources/exported-names.wasm', 1);
})
}, 'Static source phase import.');
promise_test(function(t) {
var link = document.createElement('link');
link.rel = 'modulepreload';
link.href = 'resources/execute-start.wasm';
return attachAndWaitForLoad(link).then(() => {
verifyNumberOfDownloads('resources/execute-start.wasm', 1);
let promise = new Promise((resolve) => {window.resolveDynamic = resolve});
// Verify that <script> doesn't fetch the module again.
var script = document.createElement('script');
script.type = 'module';
script.text = "await import.source('./resources/execute-start.wasm'); window.resolveDynamic();";
document.body.appendChild(script);
return promise;
}).then(() => {
verifyNumberOfDownloads('resources/execute-start.wasm', 1);
})
}, 'Dynamic source phase import.');
</script>
</body>