4 <title>Test for AudioWorklet + WASM
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
7 <script type=
"application/javascript" src=
"common.js"></script>
11 <script type=
"application/javascript">
13 function configureTest() {
14 return SpecialPowers.pushPrefEnv(
16 [
"dom.postMessage.sharedArrayBuffer.bypassCOOP_COEP.insecure.enabled", true],
17 [
"browser.tabs.remote.useCrossOriginOpenerPolicy", true],
18 [
"browser.tabs.remote.useCrossOriginEmbedderPolicy", true],
19 [
"javascript.options.shared_memory", true],
23 function create_wasmModule() {
24 return new Promise(resolve =
> {
25 info(
"Checking if we can play with WebAssembly...");
27 if (!SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()) {
32 ok(WebAssembly,
"WebAssembly object should exist");
33 ok(WebAssembly.compile,
"WebAssembly.compile function should exist");
35 const wasmTextToBinary = SpecialPowers.unwrap(SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary);
38 t = wasmTextToBinary(`
40 (func $foo (result i32) (i32.const
42))
41 (export
"foo" (func $foo))
47 // eslint-disable-next-line
48 const fooModuleCode = new Uint8Array([
0,
97,
115,
109,
1,
0,
0,
0,
1,
5,
1,
96,
0,
1,
127,
3,
2,
1,
0,
7,
7,
1,
3,
102,
111,
111,
0,
0,
10,
6,
1,
4,
0,
65,
42,
11,
0,
13,
4,
110,
97,
109,
101,
1,
6,
1,
0,
3,
102,
111,
111]);
50 WebAssembly.compile(fooModuleCode).then(m =
> {
51 ok(m instanceof WebAssembly.Module,
"The WasmModule has been compiled.");
54 ok(false,
"The compilation of the wasmModule failed.");
60 function runTestInIframe() {
61 let audioContext = new AudioContext();
62 audioContext.audioWorklet.addModule(
"worklet_audioWorklet_WASM.js")
63 .then(() =
> create_wasmModule())
65 const node = new AudioWorkletNode(audioContext, 'wasm');
67 node.port.onmessage = e =
> {
69 ok(e.data.wasmModule instanceof WebAssembly.Module,
"WasmModule received");
71 ok(e.data.sab instanceof SharedArrayBuffer,
"SAB received");
76 node.port.postMessage({wasmModule});
77 node.port.postMessage({sab: new SharedArrayBuffer(
1024)});
78 node.connect(audioContext.destination);