Files
sousa-gecko/dom/base/test/jsmodules/test_fetchedModuleHasErrorToRethrow_dynamic.html
T
Yoshi Cheng-Hao Huang 308e3ec2f1 Bug 2009280 : Relax !IsDynamicImport() assertion for error to rethrow. r=jonco
Per spec, [[ErrorToRethrow]] is only set for static imports and
top-level modules [1].  Accordingly, an assertion was added to require
non-dynamic imports when hasRethrow is true.

However, during a dynamic import, if the module script has already been
fetched, the cached module is returned (See HTML “fetch a single module
script”, step 6) [2]. In that case, a previously fetched module may already
carry [[ErrorToRethrow]], and this value is propagated to the dynamic
import.

This causes the assertion to fire for valid dynamic-import behavior. The
assertion is therefore incorrect and must be removed.

[1]: https://html.spec.whatwg.org/#fetch-the-descendants-of-and-link-a-module-script
[2]: https://html.spec.whatwg.org/#fetch-a-single-module-script

Differential Revision: https://phabricator.services.mozilla.com/D278670
2026-01-14 00:01:38 +00:00

39 lines
1.4 KiB
HTML

<!DOCTYPE html>
<meta charset=utf-8>
<title>Test an imported module has an error to rethrow when import()</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="module" src="./import_parse_error.mjs"></script>
<script>
SimpleTest.waitForExplicitFinish();
let hasErrorToRethrow = false;
let cachedError;
window.onerror = (_1, _2, _3, _4, error) => {
hasErrorToRethrow = true;
cachedError = error;
};
function testLoaded() {
// The top-level script "import_parse.error.mjs" has an error to rethrow.
is(hasErrorToRethrow, true, "hasErrorToRethrow should be set to true");
// Dynamic import the same module with an error to rethrow.
import("./import_parse_error.mjs").then(() => {
ok(false, "Should have thrown SyntaxError");
}).catch((e) => {
ok(e instanceof SyntaxError , "Should throw a SyntaxError");
ok(e === cachedError, "The same error object should be thrown");
});
// Dynamic import a module which has an error to rethrow.
import("./import_parse_error_3.mjs").then(() => {
ok(false, "Should have thrown SyntaxError");
}).catch((e) => {
ok(e instanceof SyntaxError , "Should throw a SyntaxError");
ok(e === cachedError, "The same error object should be thrown");
SimpleTest.finish();
});
}
</script>
<body onload='testLoaded()'></body>