mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:28:11 +00:00
LibJS+LibWeb: Implement resizable ArrayBuffer support for DataView
This is (part of) a normative change in the ECMA-262 spec. See:
a9ae96e
This commit is contained in:
parent
29ac6e3689
commit
c7fec9424c
12 changed files with 377 additions and 94 deletions
|
@ -1,7 +1,36 @@
|
|||
test("basic functionality", () => {
|
||||
const buffer = new ArrayBuffer(124);
|
||||
expect(new DataView(buffer).byteLength).toBe(124);
|
||||
expect(new DataView(buffer, 0, 1).byteLength).toBe(1);
|
||||
expect(new DataView(buffer, 0, 64).byteLength).toBe(64);
|
||||
expect(new DataView(buffer, 0, 123).byteLength).toBe(123);
|
||||
describe("errors", () => {
|
||||
test("called on non-DataView object", () => {
|
||||
expect(() => {
|
||||
DataView.prototype.byteLength;
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type DataView");
|
||||
});
|
||||
|
||||
test("detached buffer", () => {
|
||||
let buffer = new ArrayBuffer(5, { maxByteLength: 10 });
|
||||
let view = new DataView(buffer);
|
||||
detachArrayBuffer(buffer);
|
||||
|
||||
expect(() => {
|
||||
view.byteLength;
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"DataView contains a property which references a value at an index not contained within its buffer's bounds"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
let buffer = new ArrayBuffer(124);
|
||||
expect(new DataView(buffer).byteLength).toBe(124);
|
||||
expect(new DataView(buffer, 0, 1).byteLength).toBe(1);
|
||||
expect(new DataView(buffer, 0, 64).byteLength).toBe(64);
|
||||
expect(new DataView(buffer, 0, 123).byteLength).toBe(123);
|
||||
|
||||
buffer = new ArrayBuffer(5, { maxByteLength: 10 });
|
||||
expect(new DataView(buffer).byteLength).toBe(5);
|
||||
expect(new DataView(buffer, 0).byteLength).toBe(5);
|
||||
expect(new DataView(buffer, 3).byteLength).toBe(2);
|
||||
expect(new DataView(buffer, 5).byteLength).toBe(0);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,30 @@
|
|||
test("basic functionality", () => {
|
||||
const buffer = new ArrayBuffer(124);
|
||||
expect(new DataView(buffer).byteOffset).toBe(0);
|
||||
expect(new DataView(buffer, 1).byteOffset).toBe(1);
|
||||
expect(new DataView(buffer, 64).byteOffset).toBe(64);
|
||||
expect(new DataView(buffer, 123).byteOffset).toBe(123);
|
||||
describe("errors", () => {
|
||||
test("called on non-DataView object", () => {
|
||||
expect(() => {
|
||||
DataView.prototype.byteOffset;
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type DataView");
|
||||
});
|
||||
|
||||
test("detached buffer", () => {
|
||||
let buffer = new ArrayBuffer(5, { maxByteLength: 10 });
|
||||
let view = new DataView(buffer);
|
||||
detachArrayBuffer(buffer);
|
||||
|
||||
expect(() => {
|
||||
view.byteOffset;
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"DataView contains a property which references a value at an index not contained within its buffer's bounds"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const buffer = new ArrayBuffer(124);
|
||||
expect(new DataView(buffer).byteOffset).toBe(0);
|
||||
expect(new DataView(buffer, 1).byteOffset).toBe(1);
|
||||
expect(new DataView(buffer, 64).byteOffset).toBe(64);
|
||||
expect(new DataView(buffer, 123).byteOffset).toBe(123);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue