+describe("arrayBufferSlice", () => {
+ it("[[Call]] slices an `ArrayBuffer`", () => {
+ const baseBuffer = Uint8Array.from([2, 3, 1, 9, 8, 5]).buffer;
+ assertEquals(
+ new Uint8Array(arrayBufferSlice(baseBuffer, 1, 4)),
+ Uint8Array.from([3, 1, 9]),
+ );
+ });
+
+ it("[[Call]] slices an `SharedArrayBuffer`", () => {
+ const baseBuffer = new SharedArrayBuffer(6);
+ new Uint8Array(baseBuffer).set([2, 3, 1, 9, 8, 5], 0);
+ assertEquals(
+ new Uint8Array(arrayBufferSlice(baseBuffer, 1, 4)),
+ Uint8Array.from([3, 1, 9]),
+ );
+ });
+
+ it("[[Call]] throws for others", () => {
+ [
+ undefined,
+ null,
+ true,
+ Symbol(),
+ 27,
+ 98n,
+ {},
+ [],
+ () => {},
+ new Proxy({}, {}),
+ "string",
+ new DataView(new ArrayBuffer()),
+ new Uint8Array(),
+ ].forEach((value) =>
+ assertThrows(() => arrayBufferSlice(value, 0, 0))
+ );
+ });
+});
+