From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/tests/non262/TypedArray/slice-memcpy.js | 84 ++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 js/src/tests/non262/TypedArray/slice-memcpy.js (limited to 'js/src/tests/non262/TypedArray/slice-memcpy.js') diff --git a/js/src/tests/non262/TypedArray/slice-memcpy.js b/js/src/tests/non262/TypedArray/slice-memcpy.js new file mode 100644 index 0000000000..a20010ed16 --- /dev/null +++ b/js/src/tests/non262/TypedArray/slice-memcpy.js @@ -0,0 +1,84 @@ +const otherGlobal = newGlobal(); + +// Create with new ArrayBuffer and offset. +for (var constructor of typedArrayConstructors) { + const elementSize = constructor.BYTES_PER_ELEMENT; + let ab = new constructor(10).map((v, i) => i).buffer; + let ta = new constructor(ab, 2 * elementSize, 6); + ta.constructor = { + [Symbol.species]: function(len) { + return new constructor(new ArrayBuffer((len + 4) * elementSize), 4 * elementSize); + } + }; + let tb = ta.slice(0); + + assertEqArray(ta, [2, 3, 4, 5, 6, 7]); + assertEqArray(tb, [2, 3, 4, 5, 6, 7]); +} + +// Source and target arrays use the same ArrayBuffer, target range before source range. +for (var constructor of typedArrayConstructors) { + const elementSize = constructor.BYTES_PER_ELEMENT; + let ab = new constructor(10).map((v, i) => i).buffer; + let ta = new constructor(ab, 2 * elementSize, 6); + ta.constructor = { + [Symbol.species]: function(len) { + return new constructor(ab, 0, len); + } + }; + let tb = ta.slice(0); + + assertEqArray(ta, [4, 5, 6, 7, 6, 7]); + assertEqArray(tb, [2, 3, 4, 5, 6, 7]); + assertEqArray(new constructor(ab), [2, 3, 4, 5, 6, 7, 6, 7, 8, 9]); +} + +// Source and target arrays use the same ArrayBuffer, target range after source range. +for (var constructor of typedArrayConstructors) { + const elementSize = constructor.BYTES_PER_ELEMENT; + let ab = new constructor(10).map((v, i) => i + 1).buffer; + let ta = new constructor(ab, 0, 6); + ta.constructor = { + [Symbol.species]: function(len) { + return new constructor(ab, 2 * elementSize, len); + } + }; + let tb = ta.slice(0); + + assertEqArray(ta, [1, 2, 1, 2, 1, 2]); + assertEqArray(tb, [1, 2, 1, 2, 1, 2]); + assertEqArray(new constructor(ab), [1, 2, 1, 2, 1, 2, 1, 2, 9, 10]); +} + +// Tricky: Same as above, but with SharedArrayBuffer and different compartments. +if (this.setSharedObject && this.SharedArrayBuffer) { + for (var constructor of typedArrayConstructors) { + const elementSize = constructor.BYTES_PER_ELEMENT; + let ts = new constructor(new SharedArrayBuffer(10 * elementSize)); + for (let i = 0; i < ts.length; i++) { + ts[i] = i + 1; + } + let ab = ts.buffer; + let ta = new constructor(ab, 0, 6); + ta.constructor = { + [Symbol.species]: function(len) { + setSharedObject(ab); + try { + return otherGlobal.eval(` + new ${constructor.name}(getSharedObject(), ${2 * elementSize}, ${len}); + `); + } finally { + setSharedObject(null); + } + } + }; + let tb = ta.slice(0); + + assertEqArray(ta, [1, 2, 1, 2, 1, 2]); + assertEqArray(tb, [1, 2, 1, 2, 1, 2]); + assertEqArray(new constructor(ab), [1, 2, 1, 2, 1, 2, 1, 2, 9, 10]); + } +} + +if (typeof reportCompare === "function") + reportCompare(true, true); -- cgit v1.2.3