diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index f5496e0d9ba3..6df7efed7667 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -2643,6 +2643,12 @@ void ScriptLoader::CalculateBytecodeCacheFlag(ScriptLoadRequest* aRequest) { return; } + if (aRequest->IsModuleRequest() && + aRequest->AsModuleRequest()->mModuleType != JS::ModuleType::JavaScript) { + aRequest->MarkSkippedBytecodeEncoding(); + return; + } + // We need the nsICacheInfoChannel to exist to be able to open the alternate // data output stream. This pointer would only be non-null if the bytecode was // activated at the time the channel got created in StartLoad. diff --git a/dom/tests/browser/browser.toml b/dom/tests/browser/browser.toml index 54a00f67c813..c8d65aafd6ed 100644 --- a/dom/tests/browser/browser.toml +++ b/dom/tests/browser/browser.toml @@ -60,6 +60,12 @@ support-files = [ "page_bytecode_cache_asm_js.js", ] +["browser_bytecode_json_module.js"] +support-files = [ + "page_bytecode_cache_json_module.html", + "page_bytecode_cache_json_module.json", +] + ["browser_cancel_keydown_keypress_event.js"] support-files = ["prevent_return_key.html"] diff --git a/dom/tests/browser/browser_bytecode_json_module.js b/dom/tests/browser/browser_bytecode_json_module.js new file mode 100644 index 000000000000..9826b96afeb3 --- /dev/null +++ b/dom/tests/browser/browser_bytecode_json_module.js @@ -0,0 +1,36 @@ +"use strict"; + +const PAGE_URL = + "https://example.com/browser/dom/tests/browser/page_bytecode_cache_json_module.html"; + +async function waitForIdle() { + for (let i = 0; i < 10; i++) { + await new Promise(resolve => Services.tm.idleDispatchToMainThread(resolve)); + } +} + +add_task(async function () { + // Eagerly generate bytecode cache. + await SpecialPowers.pushPrefEnv({ + set: [ + ["dom.script_loader.bytecode_cache.enabled", true], + ["dom.script_loader.bytecode_cache.strategy", -1], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: PAGE_URL, + waitForLoad: true, + }, + async () => { + // TODO: Once the bytecode-encoding events are refactored, + // listen to the events (bug 1902951). + await waitForIdle(); + ok(true, "No crash should happen"); + } + ); + + await SpecialPowers.popPrefEnv(); +}); diff --git a/dom/tests/browser/page_bytecode_cache_json_module.html b/dom/tests/browser/page_bytecode_cache_json_module.html new file mode 100644 index 000000000000..a0350c0dd100 --- /dev/null +++ b/dom/tests/browser/page_bytecode_cache_json_module.html @@ -0,0 +1,11 @@ + + + + JSON module test + + +

JSON module test

+ + diff --git a/dom/tests/browser/page_bytecode_cache_json_module.json b/dom/tests/browser/page_bytecode_cache_json_module.json new file mode 100644 index 000000000000..5944d8eefd55 --- /dev/null +++ b/dom/tests/browser/page_bytecode_cache_json_module.json @@ -0,0 +1,35 @@ +{ + "dummy": [ + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache", + "dummy text to exceed the minimal source length for bytecode cache" + ] +} diff --git a/eslint-ignores.config.mjs b/eslint-ignores.config.mjs index 20e7b9458c19..c5d18754ac5f 100644 --- a/eslint-ignores.config.mjs +++ b/eslint-ignores.config.mjs @@ -310,4 +310,5 @@ export default [ // Support for Import attributes is only available in ESLint v9.19 // https://bugzilla.mozilla.org/show_bug.cgi?id=1944290 "netwerk/test/mochitests/test_import_json_module.mjs", + "dom/tests/browser/page_bytecode_cache_json_module.html", ];