diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/structured-clone/array-buffers.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/structured-clone/array-buffers.js')
-rw-r--r-- | js/src/jit-test/tests/structured-clone/array-buffers.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/structured-clone/array-buffers.js b/js/src/jit-test/tests/structured-clone/array-buffers.js new file mode 100644 index 0000000000..fcb61f6eca --- /dev/null +++ b/js/src/jit-test/tests/structured-clone/array-buffers.js @@ -0,0 +1,80 @@ +// Tests for ArrayBuffer, TypedArray, and DataView encoding/decoding. + +var clonebuffer = serialize("dummy"); + +// ========= V2 ========= + +function testV2Int32Array() { + var buf = new Uint8Array([3,0,0,0,0,0,241,255,3,0,0,0,16,0,255,255,4,0,0,0,0,0,0,0,12,0,0,0,9,0,255,255,1,0,0,0,177,127,57,5,133,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0]); + clonebuffer.clonebuffer = buf.buffer; + var ta = deserialize(clonebuffer); + assertEq(ta instanceof Int32Array, true); + assertEq(ta.toString(), "1,87654321,-123"); +} +testV2Int32Array(); + +function testV2Float64Array() { + var buf = new Uint8Array([3,0,0,0,0,0,241,255,4,0,0,0,16,0,255,255,7,0,0,0,0,0,0,0,32,0,0,0,9,0,255,255,0,0,0,0,0,0,248,127,31,133,235,81,184,30,9,64,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); + clonebuffer.clonebuffer = buf.buffer; + var ta = deserialize(clonebuffer); + assertEq(ta instanceof Float64Array, true); + assertEq(ta.toString(), "NaN,3.14,0,0"); +} +testV2Float64Array(); + +function testV2DataView() { + var buf = new Uint8Array([3,0,0,0,0,0,241,255,3,0,0,0,21,0,255,255,3,0,0,0,9,0,255,255,5,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0]); + clonebuffer.clonebuffer = buf.buffer; + var dv = deserialize(clonebuffer); + assertEq(dv instanceof DataView, true); + assertEq(new Uint8Array(dv.buffer).toString(), "5,0,255"); +} +testV2DataView(); + +function testV2ArrayBuffer() { + var buf = new Uint8Array([3,0,0,0,0,0,241,255,4,0,0,0,9,0,255,255,33,44,55,66,0,0,0,0]); + clonebuffer.clonebuffer = buf.buffer; + var ab = deserialize(clonebuffer); + assertEq(ab instanceof ArrayBuffer, true); + assertEq(new Uint8Array(ab).toString(), "33,44,55,66"); +} +testV2ArrayBuffer(); + +// ========= Current ========= + +function testInt32Array() { + var ta1 = new Int32Array([1, 87654321, -123]); + var clonebuf = serialize(ta1, undefined, {scope: "DifferentProcessForIndexedDB"}); + var ta2 = deserialize(clonebuf); + assertEq(ta2 instanceof Int32Array, true); + assertEq(ta2.toString(), "1,87654321,-123"); +} +testInt32Array(); + +function testFloat64Array() { + var ta1 = new Float64Array([NaN, 3.14, 0, 0]); + var clonebuf = serialize(ta1, undefined, {scope: "DifferentProcessForIndexedDB"}); + var ta2 = deserialize(clonebuf); + assertEq(ta2 instanceof Float64Array, true); + assertEq(ta2.toString(), "NaN,3.14,0,0"); +} +testFloat64Array(); + +function testDataView() { + var ta = new Uint8Array([5, 0, 255]); + var dv1 = new DataView(ta.buffer); + var clonebuf = serialize(dv1, undefined, {scope: "DifferentProcessForIndexedDB"}); + var dv2 = deserialize(clonebuf); + assertEq(dv2 instanceof DataView, true); + assertEq(new Uint8Array(dv2.buffer).toString(), "5,0,255"); +} +testDataView(); + +function testArrayBuffer() { + var ta = new Uint8Array([33, 44, 55, 66]); + var clonebuf = serialize(ta.buffer, undefined, {scope: "DifferentProcessForIndexedDB"}); + var ab = deserialize(clonebuf); + assertEq(ab instanceof ArrayBuffer, true); + assertEq(new Uint8Array(ab).toString(), "33,44,55,66"); +} +testArrayBuffer(); |