forked from mirrors/gecko-dev
Bug 1614899 - Support WASM + SAB in AudioWorkletNode processOptions, r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D62598 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
2e7b630474
commit
acbbf5b903
5 changed files with 101 additions and 2 deletions
|
|
@ -302,8 +302,12 @@ bool AudioWorkletGlobalScope::ConstructProcessor(
|
|||
* 5. Let deserializedOptions be the result of
|
||||
* StructuredDeserialize(serializedOptions, the current Realm).
|
||||
*/
|
||||
JS::CloneDataPolicy cloneDataPolicy;
|
||||
cloneDataPolicy.allowIntraClusterClonableSharedObjects();
|
||||
cloneDataPolicy.allowSharedMemoryObjects();
|
||||
|
||||
JS::Rooted<JS::Value> deserializedOptions(cx);
|
||||
aSerializedOptions->Read(this, cx, &deserializedOptions, rv);
|
||||
aSerializedOptions->Read(this, cx, &deserializedOptions, cloneDataPolicy, rv);
|
||||
if (rv.MaybeSetPendingException(cx)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -508,10 +508,18 @@ already_AddRefed<AudioWorkletNode> AudioWorkletNode::Constructor(
|
|||
aRv.NoteJSContextException(cx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 9. Let serializedOptions be the result of
|
||||
* StructuredSerialize(optionsObject).
|
||||
*/
|
||||
|
||||
// This context and the worklet are part of the same agent cluster and they
|
||||
// can share memory.
|
||||
JS::CloneDataPolicy cloneDataPolicy;
|
||||
cloneDataPolicy.allowIntraClusterClonableSharedObjects();
|
||||
cloneDataPolicy.allowSharedMemoryObjects();
|
||||
|
||||
// StructuredCloneHolder does not have a move constructor. Instead allocate
|
||||
// memory so that the pointer can be passed to the rendering thread.
|
||||
UniquePtr<StructuredCloneHolder> serializedOptions =
|
||||
|
|
@ -519,7 +527,8 @@ already_AddRefed<AudioWorkletNode> AudioWorkletNode::Constructor(
|
|||
StructuredCloneHolder::CloningSupported,
|
||||
StructuredCloneHolder::TransferringNotSupported,
|
||||
JS::StructuredCloneScope::SameProcess);
|
||||
serializedOptions->Write(cx, optionsVal, aRv);
|
||||
serializedOptions->Write(cx, optionsVal, JS::UndefinedHandleValue,
|
||||
cloneDataPolicy, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,5 +25,7 @@ scheme = http
|
|||
support-files=worklet_paintWorklet.js
|
||||
[test_audioWorklet_WASM.html]
|
||||
support-files=worklet_audioWorklet_WASM.js
|
||||
[test_audioWorklet_options.html]
|
||||
support-files=worklet_audioWorklet_options.js
|
||||
[test_promise.html]
|
||||
support-files=worklet_promise.js
|
||||
|
|
|
|||
72
dom/worklet/tests/test_audioWorklet_options.html
Normal file
72
dom/worklet/tests/test_audioWorklet_options.html
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for AudioWorklet + Options + WASM</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript" src="common.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script type="application/javascript">
|
||||
|
||||
function configureTest() {
|
||||
return SpecialPowers.pushPrefEnv(
|
||||
{"set": [["dom.audioworklet.enabled", true],
|
||||
["dom.worklet.enabled", true],
|
||||
["dom.postMessage.sharedArrayBuffer.bypassCOOP_COEP.insecure.enabled", true],
|
||||
["browser.tabs.remote.useCrossOriginOpenerPolicy", true],
|
||||
["browser.tabs.remote.useCrossOriginEmbedderPolicy", true],
|
||||
["dom.postMessage.sharedArrayBuffer.withCOOP_COEP", true],
|
||||
["javascript.options.shared_memory", true],
|
||||
]});
|
||||
}
|
||||
|
||||
function create_wasmModule() {
|
||||
return new Promise(resolve => {
|
||||
info("Checking if we can play with WebAssembly...");
|
||||
|
||||
if (!SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
|
||||
ok(WebAssembly, "WebAssembly object should exist");
|
||||
ok(WebAssembly.compile, "WebAssembly.compile function should exist");
|
||||
|
||||
const wasmTextToBinary = SpecialPowers.unwrap(SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary);
|
||||
const fooModuleCode = wasmTextToBinary(`(module
|
||||
(func $foo (result i32) (i32.const 42))
|
||||
(export "foo" $foo)
|
||||
)`);
|
||||
|
||||
WebAssembly.compile(fooModuleCode).then(m => {
|
||||
ok(m instanceof WebAssembly.Module, "The WasmModule has been compiled.");
|
||||
resolve(m);
|
||||
}, () => {
|
||||
ok(false, "The compilation of the wasmModule failed.");
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function runTestInIframe() {
|
||||
let audioContext = new AudioContext();
|
||||
audioContext.audioWorklet.addModule("worklet_audioWorklet_options.js")
|
||||
.then(() => create_wasmModule())
|
||||
.then(wasmModule => {
|
||||
const node = new AudioWorkletNode(audioContext, 'options', { processorOptions: {
|
||||
wasmModule, sab: new SharedArrayBuffer(1024),
|
||||
}});
|
||||
node.port.onmessage = e => {
|
||||
ok(e.data.wasmModule instanceof WebAssembly.Module, "WasmModule received");
|
||||
ok(e.data.sab instanceof SharedArrayBuffer, "SAB received");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
node.connect(audioContext.destination);
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
12
dom/worklet/tests/worklet_audioWorklet_options.js
Normal file
12
dom/worklet/tests/worklet_audioWorklet_options.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
class OptionsProcessWorkletProcessor extends AudioWorkletProcessor {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.port.postMessage(args[0].processorOptions);
|
||||
}
|
||||
|
||||
process(inputs, outputs, parameters) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
registerProcessor("options", OptionsProcessWorkletProcessor);
|
||||
Loading…
Reference in a new issue