From b3b912f85950c88ca0b33257438859b7c6f422bf Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Thu, 7 Sep 2023 15:30:57 +0000 Subject: [PATCH] Bug 1851468 - wasm: Set ContextOptions defaults to help consumers that don't read preferences. r=yury WorkletThread does not read from preferences to initialize JS::ContextOptions and relies on the default values it has. This lead to a regression from bug 1832378 where certain wasm features had their field's default change. This didn't affect other globals because we read preferences from those and so the default value is ignored. This commit fixes the default value for wasm features in JS::ContextOptions as a temporary fix, and adds a quick test in worklets. Ideally worklets will read from preferences for consistency and to allow us to force enable/disable features. But that's a bigger change. Differential Revision: https://phabricator.services.mozilla.com/D187583 --- dom/worklet/tests/mochitest.ini | 2 + .../test_audioWorklet_WASM_Features.html | 28 ++++++++++++ .../worklet_audioWorklet_WASM_features.js | 44 +++++++++++++++++++ js/public/WasmFeatures.h | 2 +- js/src/jit-test/tests/wasm/features.js | 2 + 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 dom/worklet/tests/test_audioWorklet_WASM_Features.html create mode 100644 dom/worklet/tests/worklet_audioWorklet_WASM_features.js diff --git a/dom/worklet/tests/mochitest.ini b/dom/worklet/tests/mochitest.ini index 53d94622affb..6963451f336b 100644 --- a/dom/worklet/tests/mochitest.ini +++ b/dom/worklet/tests/mochitest.ini @@ -10,6 +10,8 @@ support-files=worklet_test_audioWorkletGlobalScopeRegisterProcessor.js [test_audioWorklet_WASM.html] skip-if = release_or_beta # requires dom.postMessage.sharedArrayBuffer.bypassCOOP_COEP.insecure.enabled support-files=worklet_audioWorklet_WASM.js +[test_audioWorklet_WASM_Features.html] +support-files=worklet_audioWorklet_WASM_features.js [test_audioWorklet_insecureContext.html] scheme = http skip-if = diff --git a/dom/worklet/tests/test_audioWorklet_WASM_Features.html b/dom/worklet/tests/test_audioWorklet_WASM_Features.html new file mode 100644 index 000000000000..944983a5d338 --- /dev/null +++ b/dom/worklet/tests/test_audioWorklet_WASM_Features.html @@ -0,0 +1,28 @@ + + + + Test for AudioWorklet + WASM features + + + + + + + + + + diff --git a/dom/worklet/tests/worklet_audioWorklet_WASM_features.js b/dom/worklet/tests/worklet_audioWorklet_WASM_features.js new file mode 100644 index 000000000000..e9e4586f91cc --- /dev/null +++ b/dom/worklet/tests/worklet_audioWorklet_WASM_features.js @@ -0,0 +1,44 @@ +class WasmProcessWorkletProcessor extends AudioWorkletProcessor { + constructor(...args) { + super(...args); + this.port.postMessage(testModules()); + } + + process(inputs, outputs, parameters) { + // Do nothing, output silence + return true; + } +} + +function testModule(binary) { + try { + let wasmModule = new WebAssembly.Module(binary); + } catch (error) { + if (error instanceof WebAssembly.CompileError) { + return error.message; + } + return "unknown error"; + } + return true; +} + +// TODO: test more features +function testModules() { + /* + js -e ' + t = wasmTextToBinary(` + (module + (tag) + ) + `); + print(t) + ' + */ + // eslint-disable-next-line + const exceptionHandlingCode = new Uint8Array([ + 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 13, 3, 1, 0, 0, + ]); + return testModule(exceptionHandlingCode); +} + +registerProcessor("wasm", WasmProcessWorkletProcessor); diff --git a/js/public/WasmFeatures.h b/js/public/WasmFeatures.h index 77d58f8ff265..93fc6420e346 100644 --- a/js/public/WasmFeatures.h +++ b/js/public/WasmFeatures.h @@ -123,7 +123,7 @@ enum class WasmFeatureStage { FEATURE( \ /* capitalized name */ Exceptions, \ /* lower case name */ exceptions, \ - /* stage */ WasmFeatureStage::Tentative, \ + /* stage */ WasmFeatureStage::Default, \ /* compile predicate */ true, \ /* compiler predicate */ AnyCompilerAvailable(cx), \ /* flag predicate */ true, \ diff --git a/js/src/jit-test/tests/wasm/features.js b/js/src/jit-test/tests/wasm/features.js index 3520ecef5d35..78fe5c2c09e5 100644 --- a/js/src/jit-test/tests/wasm/features.js +++ b/js/src/jit-test/tests/wasm/features.js @@ -19,6 +19,8 @@ // feature to work correctly. All features should have a 'disabled.js' // test to verify this. Basic testing for this is included with each // feature in this test for sanity. +// NOTE2: Keep this file in sync with: +// `dom/worklet/tests/worklet_audioWorklet_WASM_features.js`. let { release_or_beta } = getBuildConfiguration(); let nightly = !release_or_beta;