1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:37:44 +00:00

LibJS: Add Float{32,64}Array

This commit is contained in:
Linus Groh 2020-12-05 22:28:10 +00:00 committed by Andreas Kling
parent 4dcd23c2be
commit a70aacd7c3
6 changed files with 48 additions and 15 deletions

View file

@ -1,5 +1,14 @@
// Update when more typed arrays get added
const TYPED_ARRAYS = [Uint8Array, Uint16Array, Uint32Array, Int8Array, Int16Array, Int32Array];
const TYPED_ARRAYS = [
Uint8Array,
Uint16Array,
Uint32Array,
Int8Array,
Int16Array,
Int32Array,
Float32Array,
Float64Array,
];
test("basic functionality", () => {
expect(ArrayBuffer.isView).toHaveLength(1);

View file

@ -5,4 +5,6 @@ test("basic functionality", () => {
expect(Int8Array.BYTES_PER_ELEMENT).toBe(1);
expect(Int16Array.BYTES_PER_ELEMENT).toBe(2);
expect(Int32Array.BYTES_PER_ELEMENT).toBe(4);
expect(Float32Array.BYTES_PER_ELEMENT).toBe(4);
expect(Float64Array.BYTES_PER_ELEMENT).toBe(8);
});

View file

@ -1,5 +1,14 @@
// Update when more typed arrays get added
const TYPED_ARRAYS = [Uint8Array, Uint16Array, Uint32Array, Int8Array, Int16Array, Int32Array];
const TYPED_ARRAYS = [
Uint8Array,
Uint16Array,
Uint32Array,
Int8Array,
Int16Array,
Int32Array,
Float32Array,
Float64Array,
];
const getTypedArrayConstructor = () => Object.getPrototypeOf(TYPED_ARRAYS[0]);
@ -65,9 +74,9 @@ test("typed array from ArrayBuffer with custom length and offset", () => {
const uint8ArrayAll = new Uint8Array(arrayBuffer);
const uint16ArrayPartial = new Uint16Array(arrayBuffer, 2, 4);
// Affects two bytes of the buffer, beginning at offset
uint16ArrayPartial[0] = 52651
uint16ArrayPartial[0] = 52651;
// Out of relative bounds, doesn't affect buffer
uint16ArrayPartial[4] = 123
uint16ArrayPartial[4] = 123;
expect(uint8ArrayAll[0]).toBe(0);
expect(uint8ArrayAll[1]).toBe(0);
expect(uint8ArrayAll[2]).toBe(0xab);

View file

@ -1,5 +1,14 @@
// Update when more typed arrays get added
const TYPED_ARRAYS = [Uint8Array, Uint16Array, Uint32Array, Int8Array, Int16Array, Int32Array];
const TYPED_ARRAYS = [
Uint8Array,
Uint16Array,
Uint32Array,
Int8Array,
Int16Array,
Int32Array,
Float32Array,
Float64Array,
];
test("basic functionality", () => {
TYPED_ARRAYS.forEach(T => {