ladybird/Tests/LibWeb/Text/input/wpt-import/common/sab.js
Andreas Kling 969ee0f3e0 LibJS: Make DataView::byte_offset() return u32
This fixes structured serialization of DataView. It was expected
to be uniform with TypedArray, which returns u32 for byte_offset().

This was covered by a number of WPT infrastructure tests, which this
commit also imports.
2024-11-04 00:22:40 +01:00

21 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");
}
}
})();