Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web Audio: SharedArrayBuffer and COOP/COEP #17719

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,20 @@
buffer.copyFromChannel(x, 3);
}, '7: buffer.copyFromChannel(x, 3)').throw(DOMException, 'IndexSizeError');

if (window.SharedArrayBuffer) {
let shared_buffer = new Float32Array(new SharedArrayBuffer(32));
should(
() => {
buffer.copyFromChannel(shared_buffer, 0);
},
'8: buffer.copyFromChannel(SharedArrayBuffer view, 0)')
.throw(TypeError);

should(
() => {
buffer.copyFromChannel(shared_buffer, 0, 0);
},
'9: buffer.copyFromChannel(SharedArrayBuffer view, 0, 0)')
.throw(TypeError);
}
let shared_buffer = new Float32Array(new SharedArrayBuffer(32));
should(
() => {
buffer.copyFromChannel(shared_buffer, 0);
},
'8: buffer.copyFromChannel(SharedArrayBuffer view, 0)')
.throw(TypeError);

should(
() => {
buffer.copyFromChannel(shared_buffer, 0, 0);
},
'9: buffer.copyFromChannel(SharedArrayBuffer view, 0, 0)')
.throw(TypeError);

task.done();
});
Expand Down Expand Up @@ -204,22 +202,20 @@
buffer.copyToChannel(x, 3);
}, '6: buffer.copyToChannel(x, 3)').throw(DOMException, 'IndexSizeError');

if (window.SharedArrayBuffer) {
let shared_buffer = new Float32Array(new SharedArrayBuffer(32));
should(
() => {
buffer.copyToChannel(shared_buffer, 0);
},
'7: buffer.copyToChannel(SharedArrayBuffer view, 0)')
.throw(TypeError);

should(
() => {
buffer.copyToChannel(shared_buffer, 0, 0);
},
'8: buffer.copyToChannel(SharedArrayBuffer view, 0, 0)')
.throw(TypeError);
}
let shared_buffer = new Float32Array(new SharedArrayBuffer(32));
should(
() => {
buffer.copyToChannel(shared_buffer, 0);
},
'7: buffer.copyToChannel(SharedArrayBuffer view, 0)')
.throw(TypeError);

should(
() => {
buffer.copyToChannel(shared_buffer, 0, 0);
},
'8: buffer.copyToChannel(SharedArrayBuffer view, 0, 0)')
.throw(TypeError);

task.done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,56 @@

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

if (window.SharedArrayBuffer) {
audit.define(
'Test postMessage from AudioWorkletProcessor to AudioWorkletNode',
(task, should) => {
let workletNode =
new AudioWorkletNode(context, 'sharedarraybuffer-processor');
audit.define(
'Test postMessage from AudioWorkletProcessor to AudioWorkletNode',
(task, should) => {
let workletNode =
new AudioWorkletNode(context, 'sharedarraybuffer-processor');

// After it is created, the worklet will send a new
// SharedArrayBuffer to the main thread.
//
// The worklet will then wait to receive a message from the main
// thread.
//
// When it receives the message, it will check whether it is a
// SharedArrayBuffer, and send this information back to the main
// thread.
// After it is created, the worklet will send a new
// SharedArrayBuffer to the main thread.
//
// The worklet will then wait to receive a message from the main
// thread.
//
// When it receives the message, it will check whether it is a
// SharedArrayBuffer, and send this information back to the main
// thread.

workletNode.port.onmessage = (event) => {
let data = event.data;
switch (data.state) {
case 'created':
should(
data.sab instanceof SharedArrayBuffer,
'event.data.sab from worklet is an instance of SharedArrayBuffer')
.beTrue();
workletNode.port.onmessage = (event) => {
let data = event.data;
switch (data.state) {
case 'created':
should(
data.sab instanceof SharedArrayBuffer,
'event.data.sab from worklet is an instance of SharedArrayBuffer')
.beTrue();

// Send a SharedArrayBuffer back to the worklet.
let sab = new SharedArrayBuffer(8);
workletNode.port.postMessage(sab);
break;
// Send a SharedArrayBuffer back to the worklet.
let sab = new SharedArrayBuffer(8);
workletNode.port.postMessage(sab);
break;

case 'received message':
should(data.isSab, 'event.data from main thread is an instance of SharedArrayBuffer')
.beTrue();
task.done();
break;
case 'received message':
should(data.isSab, 'event.data from main thread is an instance of SharedArrayBuffer')
.beTrue();
task.done();
break;

default:
should(false,
`Got unexpected message from worklet: ${data.state}`)
.beTrue();
task.done();
break;
}
};
default:
should(false,
`Got unexpected message from worklet: ${data.state}`)
.beTrue();
task.done();
break;
}
};

workletNode.port.onmessageerror = (event) => {
should(false, 'Got messageerror from worklet').beTrue();
task.done();
};
});
} else {
// NOTE(binji): SharedArrayBuffer is only enabled where we have site
// isolation.
audit.define('Skipping test because SharedArrayBuffer is not defined',
(task, should) => {
task.done();
workletNode.port.onmessageerror = (event) => {
should(false, 'Got messageerror from worklet').beTrue();
task.done();
};
});
}

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