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/tests/non262/TypedArray/slice-memcpy.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/TypedArray/slice-memcpy.js | 84 |
1 files changed, 84 insertions, 0 deletions
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); |