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

HTML: use Wasm to get a SharedArrayBuffer instance #22385

Merged
merged 1 commit into from Mar 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,18 +1,29 @@
// META: global=window,worker

test(() => {
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
assert_equals(globalThis.SharedArrayBuffer, undefined);
assert_false("SharedArrayBuffer" in globalThis);
}, "SharedArrayBuffer constructor does not exist without COOP+COEP");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syg @domenic any other angles to test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah that should do it.


test(() => {
const sab = new SharedArrayBuffer();
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const sab = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
const channel = new MessageChannel();
assert_throws_dom("DataCloneError", () => channel.port1.postMessage(sab));
}, "SharedArrayBuffer over MessageChannel without COOP+COEP");

test(() => {
const sab = new SharedArrayBuffer();
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const sab = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
const channel = new BroadcastChannel("Is mir egal");
assert_throws_dom("DataCloneError", () => channel.postMessage(sab));
}, "SharedArrayBuffer over BroadcastChannel without COOP+COEP");

if (self.GLOBAL.isWindow()) {
test(() => {
const sab = new SharedArrayBuffer();
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const sab = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
assert_throws_dom("DataCloneError", () => self.postMessage(sab));
}, "SharedArrayBuffer over postMessage() without COOP+COEP");
}
Expand Down
Expand Up @@ -7,9 +7,11 @@ async_test(t => {
openReq.onupgradeneeded = e => {
const db = e.target.result;
const store = db.createObjectStore("store", { keyPath: "key" });
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const sab = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;

assert_throws_dom("DataCloneError", () => {
store.put({ key: 1, property: new SharedArrayBuffer() });
store.put({ key: 1, property: sab });
});
t.done();
};
Expand All @@ -21,14 +23,16 @@ async_test(t => {
openReq.onupgradeneeded = e => {
const db = e.target.result;
const store = db.createObjectStore("store", { keyPath: "key" });
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const sab = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;

let getter1Called = false;
let getter2Called = false;

assert_throws_dom("DataCloneError", () => {
store.put({ key: 1, property: [
{ get x() { getter1Called = true; return 5; } },
new SharedArrayBuffer(),
sab,
{ get x() { getter2Called = true; return 5; } }
]});
});
Expand Down
Expand Up @@ -2,18 +2,23 @@

test(() => {
assert_throws_dom("DataCloneError", () => {
new Notification("Bob: Hi", { data: new SharedArrayBuffer() });
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const sab = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
new Notification("Bob: Hi", { data: sab });
})
}, "SharedArrayBuffer cloning via the Notifications API's data member: basic case");

test(() => {
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const sab = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;

let getter1Called = false;
let getter2Called = false;

assert_throws_dom("DataCloneError", () => {
new Notification("Bob: Hi", { data: [
{ get x() { getter1Called = true; return 5; } },
new SharedArrayBuffer(),
sab,
{ get x() { getter2Called = true; return 5; } }
]});
});
Expand Down
@@ -1,7 +1,8 @@
// META: global=!default,window,serviceworker

test(() => {
const sab = new SharedArrayBuffer(16);
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const sab = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
const ta = new Int32Array(sab);

assert_throws_js(TypeError, () => {
Expand Down
@@ -1,7 +1,8 @@
// META: global=!default,dedicatedworker,sharedworker

test(() => {
const sab = new SharedArrayBuffer(16);
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const sab = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
const ta = new Int32Array(sab);

assert_equals(Atomics.wait(ta, 0, 0, 10), "timed-out");
Expand Down