Files
tubestation/testing/web-platform/tests/common/sab.js
Shu-yu Guo 94c233b8d1 Bug 1804575 [wpt PR 37393] - [rab/gsab] Add WPT tests for resizable ArrayBuffer, a=testonly
Automatic update from web-platform-tests
[rab/gsab] Add WPT tests for resizable ArrayBuffer

Bug: v8:11111
Change-Id: I531f10cae15dd09e7934ad698acf9dcae225ca4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4082152
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1086557}

--

wpt-commits: 5656a2f4653b5894c500b724778009ca9a26e48c
wpt-pr: 37393
2023-01-05 09:08:24 +00:00

22 lines
768 B
JavaScript

const createBuffer = (() => {
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
let sabConstructor;
try {
sabConstructor = new WebAssembly.Memory({ shared:true, initial:0, maximum:0 }).buffer.constructor;
} catch(e) {
sabConstructor = null;
}
return (type, length, opts) => {
if (type === "ArrayBuffer") {
return new ArrayBuffer(length, opts);
} else if (type === "SharedArrayBuffer") {
if (sabConstructor && sabConstructor.name !== "SharedArrayBuffer") {
throw new Error("WebAssembly.Memory does not support shared:true");
}
return new sabConstructor(length, opts);
} else {
throw new Error("type has to be ArrayBuffer or SharedArrayBuffer");
}
}
})();