Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 66b4fab

Browse files
authored
Web Audio: SharedArrayBuffer and COOP/COEP
Stop making SharedArrayBuffer usage conditional as it should always be enabled. postMessage() can fail however and only works if the appropriate headers are set, so add those to the worklet test. (I'm assuming here that worklets will inherit COEP without having to declare it.)
1 parent e8eda6f commit 66b4fab

File tree

3 files changed

+73
-84
lines changed

3 files changed

+73
-84
lines changed

webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel.html

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,20 @@
149149
buffer.copyFromChannel(x, 3);
150150
}, '7: buffer.copyFromChannel(x, 3)').throw(DOMException, 'IndexSizeError');
151151

152-
if (window.SharedArrayBuffer) {
153-
let shared_buffer = new Float32Array(new SharedArrayBuffer(32));
154-
should(
155-
() => {
156-
buffer.copyFromChannel(shared_buffer, 0);
157-
},
158-
'8: buffer.copyFromChannel(SharedArrayBuffer view, 0)')
159-
.throw(TypeError);
160-
161-
should(
162-
() => {
163-
buffer.copyFromChannel(shared_buffer, 0, 0);
164-
},
165-
'9: buffer.copyFromChannel(SharedArrayBuffer view, 0, 0)')
166-
.throw(TypeError);
167-
}
152+
let shared_buffer = new Float32Array(new SharedArrayBuffer(32));
153+
should(
154+
() => {
155+
buffer.copyFromChannel(shared_buffer, 0);
156+
},
157+
'8: buffer.copyFromChannel(SharedArrayBuffer view, 0)')
158+
.throw(TypeError);
159+
160+
should(
161+
() => {
162+
buffer.copyFromChannel(shared_buffer, 0, 0);
163+
},
164+
'9: buffer.copyFromChannel(SharedArrayBuffer view, 0, 0)')
165+
.throw(TypeError);
168166

169167
task.done();
170168
});
@@ -204,22 +202,20 @@
204202
buffer.copyToChannel(x, 3);
205203
}, '6: buffer.copyToChannel(x, 3)').throw(DOMException, 'IndexSizeError');
206204

207-
if (window.SharedArrayBuffer) {
208-
let shared_buffer = new Float32Array(new SharedArrayBuffer(32));
209-
should(
210-
() => {
211-
buffer.copyToChannel(shared_buffer, 0);
212-
},
213-
'7: buffer.copyToChannel(SharedArrayBuffer view, 0)')
214-
.throw(TypeError);
215-
216-
should(
217-
() => {
218-
buffer.copyToChannel(shared_buffer, 0, 0);
219-
},
220-
'8: buffer.copyToChannel(SharedArrayBuffer view, 0, 0)')
221-
.throw(TypeError);
222-
}
205+
let shared_buffer = new Float32Array(new SharedArrayBuffer(32));
206+
should(
207+
() => {
208+
buffer.copyToChannel(shared_buffer, 0);
209+
},
210+
'7: buffer.copyToChannel(SharedArrayBuffer view, 0)')
211+
.throw(TypeError);
212+
213+
should(
214+
() => {
215+
buffer.copyToChannel(shared_buffer, 0, 0);
216+
},
217+
'8: buffer.copyToChannel(SharedArrayBuffer view, 0, 0)')
218+
.throw(TypeError);
223219

224220
task.done();
225221
});

webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-sharedarraybuffer.https.html

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,65 +16,56 @@
1616

1717
let filePath = 'processors/sharedarraybuffer-processor.js';
1818

19-
if (window.SharedArrayBuffer) {
20-
audit.define(
21-
'Test postMessage from AudioWorkletProcessor to AudioWorkletNode',
22-
(task, should) => {
23-
let workletNode =
24-
new AudioWorkletNode(context, 'sharedarraybuffer-processor');
19+
audit.define(
20+
'Test postMessage from AudioWorkletProcessor to AudioWorkletNode',
21+
(task, should) => {
22+
let workletNode =
23+
new AudioWorkletNode(context, 'sharedarraybuffer-processor');
2524

26-
// After it is created, the worklet will send a new
27-
// SharedArrayBuffer to the main thread.
28-
//
29-
// The worklet will then wait to receive a message from the main
30-
// thread.
31-
//
32-
// When it receives the message, it will check whether it is a
33-
// SharedArrayBuffer, and send this information back to the main
34-
// thread.
25+
// After it is created, the worklet will send a new
26+
// SharedArrayBuffer to the main thread.
27+
//
28+
// The worklet will then wait to receive a message from the main
29+
// thread.
30+
//
31+
// When it receives the message, it will check whether it is a
32+
// SharedArrayBuffer, and send this information back to the main
33+
// thread.
3534

36-
workletNode.port.onmessage = (event) => {
37-
let data = event.data;
38-
switch (data.state) {
39-
case 'created':
40-
should(
41-
data.sab instanceof SharedArrayBuffer,
42-
'event.data.sab from worklet is an instance of SharedArrayBuffer')
43-
.beTrue();
35+
workletNode.port.onmessage = (event) => {
36+
let data = event.data;
37+
switch (data.state) {
38+
case 'created':
39+
should(
40+
data.sab instanceof SharedArrayBuffer,
41+
'event.data.sab from worklet is an instance of SharedArrayBuffer')
42+
.beTrue();
4443

45-
// Send a SharedArrayBuffer back to the worklet.
46-
let sab = new SharedArrayBuffer(8);
47-
workletNode.port.postMessage(sab);
48-
break;
44+
// Send a SharedArrayBuffer back to the worklet.
45+
let sab = new SharedArrayBuffer(8);
46+
workletNode.port.postMessage(sab);
47+
break;
4948

50-
case 'received message':
51-
should(data.isSab, 'event.data from main thread is an instance of SharedArrayBuffer')
52-
.beTrue();
53-
task.done();
54-
break;
49+
case 'received message':
50+
should(data.isSab, 'event.data from main thread is an instance of SharedArrayBuffer')
51+
.beTrue();
52+
task.done();
53+
break;
5554

56-
default:
57-
should(false,
58-
`Got unexpected message from worklet: ${data.state}`)
59-
.beTrue();
60-
task.done();
61-
break;
62-
}
63-
};
55+
default:
56+
should(false,
57+
`Got unexpected message from worklet: ${data.state}`)
58+
.beTrue();
59+
task.done();
60+
break;
61+
}
62+
};
6463

65-
workletNode.port.onmessageerror = (event) => {
66-
should(false, 'Got messageerror from worklet').beTrue();
67-
task.done();
68-
};
69-
});
70-
} else {
71-
// NOTE(binji): SharedArrayBuffer is only enabled where we have site
72-
// isolation.
73-
audit.define('Skipping test because SharedArrayBuffer is not defined',
74-
(task, should) => {
75-
task.done();
64+
workletNode.port.onmessageerror = (event) => {
65+
should(false, 'Got messageerror from worklet').beTrue();
66+
task.done();
67+
};
7668
});
77-
}
7869

7970
context.audioWorklet.addModule(filePath).then(() => {
8071
audit.run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cross-Origin-Opener-Policy: same-origin
2+
Cross-Origin-Embedder-Policy: require-corp

0 commit comments

Comments
 (0)