From a9b173567826e62591410560abbef047b534f01d Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 24 Mar 2020 14:17:24 +0100 Subject: [PATCH] Audio/Orientation/Portals: use Wasm to get a SharedArrayBuffer instance For https://github.com/web-platform-tests/wpt/issues/22358. --- orientation-sensor/orientation-sensor-tests.js | 4 +++- portals/portal-activate-data.html | 3 ++- .../audiobuffer-copy-channel.html | 8 ++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/orientation-sensor/orientation-sensor-tests.js b/orientation-sensor/orientation-sensor-tests.js index 5d35f3b9afcc52..9d44d63870526a 100644 --- a/orientation-sensor/orientation-sensor-tests.js +++ b/orientation-sensor/orientation-sensor-tests.js @@ -42,7 +42,9 @@ async function checkPopulateMatrix(t, sensorProvider, sensorType) { // Throws if passed SharedArrayBuffer view. assert_throws_js(TypeError, - () => sensor.populateMatrix(new Float32Array(new SharedArrayBuffer(16)))); + // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()` + // WebAssembly.Memory's size is in multiples of 64 KiB + () => sensor.populateMatrix(new Float32Array(new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer))); sensor.start(); diff --git a/portals/portal-activate-data.html b/portals/portal-activate-data.html index 004fa97e55c050..260bb00ff0686c 100644 --- a/portals/portal-activate-data.html +++ b/portals/portal-activate-data.html @@ -74,7 +74,8 @@ const w = await openBlankPortalHost(); await promise_rejects_dom( t, 'DataCloneError', w.DOMException, - openPortalAndActivate('', {data: new SharedArrayBuffer}, w)); + // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()` + openPortalAndActivate('', {data: new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer}, w)); }, "A SharedArrayBuffer cannot be passed through activate data."); promise_test(async t => { diff --git a/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel.html b/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel.html index 20780d94b730ac..c0cd49d32520fd 100644 --- a/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel.html +++ b/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel.html @@ -149,7 +149,9 @@ buffer.copyFromChannel(x, 3); }, '7: buffer.copyFromChannel(x, 3)').throw(DOMException, 'IndexSizeError'); - let shared_buffer = new Float32Array(new SharedArrayBuffer(32)); + // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()` + // WebAssembly.Memory's size is in multiples of 64 KiB + const shared_buffer = new Float32Array(new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer); should( () => { buffer.copyFromChannel(shared_buffer, 0); @@ -202,7 +204,9 @@ buffer.copyToChannel(x, 3); }, '6: buffer.copyToChannel(x, 3)').throw(DOMException, 'IndexSizeError'); - let shared_buffer = new Float32Array(new SharedArrayBuffer(32)); + // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()` + // WebAssembly.Memory's size is in multiples of 64 KiB + const shared_buffer = new Float32Array(new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer); should( () => { buffer.copyToChannel(shared_buffer, 0);