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/typedarray | |
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 '')
16 files changed, 668 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/typedarray/bug1518764.js b/js/src/jit-test/tests/typedarray/bug1518764.js new file mode 100644 index 0000000000..3ea5bfb76b --- /dev/null +++ b/js/src/jit-test/tests/typedarray/bug1518764.js @@ -0,0 +1,8 @@ +// |jit-test| error:dead object + +var g = newGlobal({newCompartment: true}); +var ta = new g.Int32Array(1); +Int32Array.prototype.filter.call(ta, function() { + nukeAllCCWs(); + return true; +}); diff --git a/js/src/jit-test/tests/typedarray/bug1520536.js b/js/src/jit-test/tests/typedarray/bug1520536.js new file mode 100644 index 0000000000..af6c8472bd --- /dev/null +++ b/js/src/jit-test/tests/typedarray/bug1520536.js @@ -0,0 +1,3 @@ +let a = wrapWithProto(new Int16Array([300]), {}); +let b = new Uint8ClampedArray(a); +assertEq(b[0], 255); diff --git a/js/src/jit-test/tests/typedarray/bug1713567.js b/js/src/jit-test/tests/typedarray/bug1713567.js new file mode 100644 index 0000000000..36209f8a15 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/bug1713567.js @@ -0,0 +1,21 @@ +// |jit-test| --ion-gvn=off; --fast-warmup; --no-threads + +var heap = new ArrayBuffer(4); +var view32 = new Uint32Array(heap); + +function foo(i0) { + var t1 = i0 + 1; + var t2 = i0 >>> view32[0]; + var t3 = t1 - (t2 > 0); + return t3; +} + +with ({}) {} +view32[0] = 0x80000000; +for (var i = 0; i < 100; i++) { + foo(0); +} +view32[0] = 0; +for (var i = 0; i < 100; i++) { + foo(0x80000000); +} diff --git a/js/src/jit-test/tests/typedarray/construct-with-arraybuffer.js b/js/src/jit-test/tests/typedarray/construct-with-arraybuffer.js new file mode 100644 index 0000000000..5b819f1d57 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/construct-with-arraybuffer.js @@ -0,0 +1,59 @@ +// Test TypedArray constructor when called with ArrayBuffers. + +function testArrayBuffer() { + function test() { + var ab = new ArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(ab); + assertEq(ta.length, 4); + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testArrayBuffer(); + +function testArrayBufferAndByteOffset() { + function test() { + var ab = new ArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(ab, Int32Array.BYTES_PER_ELEMENT); + assertEq(ta.length, 3); + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testArrayBufferAndByteOffset(); + +function testArrayBufferAndByteOffsetAndLength() { + function test() { + var ab = new ArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(ab, Int32Array.BYTES_PER_ELEMENT, 2); + assertEq(ta.length, 2); + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testArrayBufferAndByteOffsetAndLength(); + +function testWrappedArrayBuffer() { + var g = newGlobal(); + + function test() { + var ab = new g.ArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(ab); + assertEq(ta.length, 4); + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testWrappedArrayBuffer(); diff --git a/js/src/jit-test/tests/typedarray/construct-with-arrays.js b/js/src/jit-test/tests/typedarray/construct-with-arrays.js new file mode 100644 index 0000000000..290a27b3ea --- /dev/null +++ b/js/src/jit-test/tests/typedarray/construct-with-arrays.js @@ -0,0 +1,165 @@ +// Test TypedArray constructor when called with iterables or typed arrays. + +function testPackedArray() { + function test() { + var array = [ + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + ]; + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(array); + assertEq(ta.length, array.length); + for (var j = 0; j < array.length; ++j) { + assertEq(ta[j], array[j]); + } + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testPackedArray(); + +function testHoleArray() { + function test() { + var array = [ + 1, /* hole */, 3, + 4, /* hole */, 6, + 7, /* hole */, 9, + ]; + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(array); + assertEq(ta.length, array.length); + for (var j = 0; j < array.length; ++j) { + assertEq(ta[j], array[j] || 0); + } + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testHoleArray(); + +function testTypedArraySameType() { + function test() { + var array = new Int32Array([ + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + ]); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(array); + assertEq(ta.length, array.length); + for (var j = 0; j < array.length; ++j) { + assertEq(ta[j], array[j]); + } + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testTypedArraySameType(); + +function testTypedArrayDifferentType() { + function test() { + var array = new Float32Array([ + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + ]); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(array); + assertEq(ta.length, array.length); + for (var j = 0; j < array.length; ++j) { + assertEq(ta[j], array[j]); + } + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testTypedArrayDifferentType(); + +function testIterable() { + function test() { + var array = [ + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + ]; + array = Object.defineProperties({ + [Symbol.iterator]() { + var index = 0; + return { + next() { + var done = index >= array.length; + var value = !done ? array[index++] : undefined; + return {done, value}; + } + }; + } + }, Object.getOwnPropertyDescriptors(array)); + + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(array); + assertEq(ta.length, array.length); + for (var j = 0; j < array.length; ++j) { + assertEq(ta[j], array[j]); + } + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testIterable(); + +function testWrappedArray() { + var g = newGlobal(); + + function test() { + var array = new g.Array( + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + ); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(array); + assertEq(ta.length, array.length); + for (var j = 0; j < array.length; ++j) { + assertEq(ta[j], array[j]); + } + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testWrappedArray(); + +function testWrappedTypedArray() { + var g = newGlobal(); + + function test() { + var array = new g.Int32Array([ + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + ]); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(array); + assertEq(ta.length, array.length); + for (var j = 0; j < array.length; ++j) { + assertEq(ta[j], array[j]); + } + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testWrappedTypedArray(); diff --git a/js/src/jit-test/tests/typedarray/construct-with-sharedarraybuffer.js b/js/src/jit-test/tests/typedarray/construct-with-sharedarraybuffer.js new file mode 100644 index 0000000000..8583901ce5 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/construct-with-sharedarraybuffer.js @@ -0,0 +1,61 @@ +// |jit-test| skip-if: !this.SharedArrayBuffer + +// Test TypedArray constructor when called with SharedArrayBuffers. + +function testSharedArrayBuffer() { + function test() { + var sab = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(sab); + assertEq(ta.length, 4); + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testSharedArrayBuffer(); + +function testSharedArrayBufferAndByteOffset() { + function test() { + var sab = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(sab, Int32Array.BYTES_PER_ELEMENT); + assertEq(ta.length, 3); + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testSharedArrayBufferAndByteOffset(); + +function testSharedArrayBufferAndByteOffsetAndLength() { + function test() { + var sab = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(sab, Int32Array.BYTES_PER_ELEMENT, 2); + assertEq(ta.length, 2); + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testSharedArrayBufferAndByteOffsetAndLength(); + +function testWrappedSharedArrayBuffer() { + var g = newGlobal(); + + function test() { + var sab = new g.SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT); + for (var i = 0; i < 1000; ++i) { + var ta = new Int32Array(sab); + assertEq(ta.length, 4); + } + } + for (var i = 0; i < 2; ++i) { + test(); + } +} +testWrappedSharedArrayBuffer(); diff --git a/js/src/jit-test/tests/typedarray/define-property-oob.js b/js/src/jit-test/tests/typedarray/define-property-oob.js new file mode 100644 index 0000000000..a4afac3a57 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/define-property-oob.js @@ -0,0 +1,24 @@ +const ta = new Int32Array(1); +const desc = {value: 0, writable: true, enumerable: true, configurable: true}; + +// Out-of-bounds with an int32 index. +for (let i = 0; i < 1000; ++i) { + let didThrow = false; + try { + Object.defineProperty(ta, 10, desc); + } catch { + didThrow = true; + } + assertEq(didThrow, true); +} + +// Out-of-bounds with a non-int32 index. +for (let i = 0; i < 1000; ++i) { + let didThrow = false; + try { + Object.defineProperty(ta, 12.3, desc); + } catch { + didThrow = true; + } + assertEq(didThrow, true); +} diff --git a/js/src/jit-test/tests/typedarray/dom-view.js b/js/src/jit-test/tests/typedarray/dom-view.js new file mode 100644 index 0000000000..cfc9ead74e --- /dev/null +++ b/js/src/jit-test/tests/typedarray/dom-view.js @@ -0,0 +1,13 @@ +// Bug 1731039 fuzzbug. Exercises one of the new ArrayBufferOrView classes. + +var error; +try { + encodeAsUtf8InBuffer("", ""); +} catch (e) { + error = e; +} + +assertEq(error.message.includes("must be a Uint8Array"), true); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/jit-test/tests/typedarray/error-messages.js b/js/src/jit-test/tests/typedarray/error-messages.js new file mode 100644 index 0000000000..f98e397dc7 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/error-messages.js @@ -0,0 +1,40 @@ +// |jit-test| skip-if: getBuildConfiguration()['wasi'] + +function assertThrowsMessage(f, regexp) { + var threw = true; + var error = null; + try { + f(); + threw = false; + } catch (e) { + error = e; + } + // Make sure f threw + assertEq(threw, true); + // Make sure the message is as we expected + assertEq(regexp.test(error.message), true); +} + +var shared = new SharedArrayBuffer(4096); +assertThrowsMessage(() => new Int32Array(shared, 7), /start offset of Int32Array should be a multiple of 4/); + +var shared = new SharedArrayBuffer(4096); +assertThrowsMessage(() => new Float64Array(shared, 3), /start offset of Float64Array should be a multiple of 8/); + +var shared = new SharedArrayBuffer(1025); +assertThrowsMessage(() => new Float32Array(shared, 8), /buffer length for Float32Array should be a multiple of 4/); + +var shared = new SharedArrayBuffer(513); +assertThrowsMessage(() => new Int16Array(shared, 8), /buffer length for Int16Array should be a multiple of 2/); + +var shared = new SharedArrayBuffer(32); +assertThrowsMessage(() => new Int16Array(shared, 36), /size of buffer is too small for Int16Array with byteOffset/); + +var shared = new SharedArrayBuffer(2048); +assertThrowsMessage(() => new BigInt64Array(shared, 4096), /size of buffer is too small for BigInt64Array with byteOffset/); + +var shared = new SharedArrayBuffer(4096); +assertThrowsMessage(() => new Int32Array(shared, 4096, 4), /attempting to construct out-of-bounds Int32Array on ArrayBuffer/); + +var shared = new SharedArrayBuffer(1024); +assertThrowsMessage(() => new Float32Array(shared, 800, 300), /attempting to construct out-of-bounds Float32Array on ArrayBuffer/);
\ No newline at end of file diff --git a/js/src/jit-test/tests/typedarray/indexed-integer-exotics-simple.js b/js/src/jit-test/tests/typedarray/indexed-integer-exotics-simple.js new file mode 100644 index 0000000000..4d9eb30875 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/indexed-integer-exotics-simple.js @@ -0,0 +1,35 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +var array = new Int32Array(10); +function check() { + for (var i = 0; i < 4; i++) { + assertEq(undefined, array["-1"]); + } +} +check(); +check(); diff --git a/js/src/jit-test/tests/typedarray/indexed-integer-exotics.js b/js/src/jit-test/tests/typedarray/indexed-integer-exotics.js new file mode 100644 index 0000000000..6331efd7c3 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/indexed-integer-exotics.js @@ -0,0 +1,97 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +function assertThrows(code) { + try { + eval(code); + } catch (e) { + return; + } + assertEq(true, false); +} + +Object.prototype["10"] = "unreachable"; +Object.prototype["7"] = "unreachable"; +Object.prototype["-1"] = "unreachable"; +Object.prototype["-0"] = "unreachable"; +Object.prototype["4294967295"] = "unreachable"; + +var array = new Int32Array(10); + +function check() { + for (var i = 0; i < 4; i++) { + assertEq(undefined, array["-1"]); + assertEq(undefined, array["-0"]); + assertEq(undefined, array["10"]); + assertEq(undefined, array["4294967295"]); + } + assertEq("unreachable", array.__proto__["-1"]); + assertEq("unreachable", array.__proto__["-0"]); + assertEq("unreachable", array.__proto__["10"]); + assertEq("unreachable", array.__proto__["4294967295"]); +} + +check(); + +array["-1"] = "unreachable"; +array["-0"] = "unreachable"; +array["10"] = "unreachable"; +array["4294967295"] = "unreachable"; + +check(); + +delete array["-0"]; +delete array["-1"]; +delete array["10"]; +delete array["4294967295"]; + +assertEq(undefined, Object.getOwnPropertyDescriptor(array, "-1")); +assertEq(undefined, Object.getOwnPropertyDescriptor(array, "-0")); +assertEq(undefined, Object.getOwnPropertyDescriptor(array, "10")); +assertEq(undefined, Object.getOwnPropertyDescriptor(array, "4294967295")); +assertEq(10, Object.keys(array).length); + +check(); + +function f() { return array["-1"]; } + +for (var i = 0; i < 3; i++) { + assertEq(undefined, f()); +} +setJitCompilerOption("baseline.warmup.trigger", 0); +setJitCompilerOption("ion.warmup.trigger", 0); +assertEq(undefined, f()); + +// These checks currently fail due to bug 1129202 not being implemented yet. +// We should uncomment them once that bug landed. +//assertThrows('Object.defineProperty(new Int32Array(100), -1, {value: 1})'); +// -0 gets converted to the string "0", so use "-0" instead. +//assertThrows('Object.defineProperty(new Int32Array(100), "-0", {value: 1})'); +//assertThrows('Object.defineProperty(new Int32Array(100), -10, {value: 1})'); +//assertThrows('Object.defineProperty(new Int32Array(), 4294967295, {value: 1})'); + +check(); diff --git a/js/src/jit-test/tests/typedarray/oom-allocating-arraybuffer-contents.js b/js/src/jit-test/tests/typedarray/oom-allocating-arraybuffer-contents.js new file mode 100644 index 0000000000..16d1bf976f --- /dev/null +++ b/js/src/jit-test/tests/typedarray/oom-allocating-arraybuffer-contents.js @@ -0,0 +1,15 @@ +// |jit-test| skip-if: !('oomTest' in this) + +// Resolve ArrayBuffer before OOM-testing, so OOM-testing runs less code and is +// less fragile. +var AB = ArrayBuffer; + +function f() +{ + return new AB(256); +} + +// Create |f|'s script before OOM-testing for the same reason. +f(); + +oomTest(f); diff --git a/js/src/jit-test/tests/typedarray/sort.js b/js/src/jit-test/tests/typedarray/sort.js new file mode 100644 index 0000000000..45d1b2ac23 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/sort.js @@ -0,0 +1,24 @@ +setJitCompilerOption("ion.warmup.trigger", 40); + +const constructors = [ + Int8Array, + Uint8Array, + Uint8ClampedArray, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array ]; + +// Ensure that when creating TypedArrays under JIT +// the sort() method works as expected (bug 1295034). +for (var ctor of constructors) { + for (var _ of Array(1024)) { + var testArray = new ctor(10); + testArray.sort(); + } +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js b/js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js new file mode 100644 index 0000000000..f339d4d94a --- /dev/null +++ b/js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js @@ -0,0 +1,43 @@ +// |jit-test| --enable-change-array-by-copy + +load(libdir + 'array-compare.js'); +load(libdir + "asserts.js"); + +let typedArray123 = new Uint8Array([1, 2, 3]); +let typedArray12345 = new Uint8Array([1, 2, 3, 4, 5]); +let typedArray = new Uint8Array([1, 2, 3]); +let typedArray2 = new Uint8Array([3, 2, 1]); + +let a_with = typedArray.with(1, 42); +assertEq(arraysEqual(typedArray, new Uint8Array([1, 2, 3])), true); +assertEq(arraysEqual(a_with, new Uint8Array([1, 42, 3])), true); + +let tarray1 = new Uint8Array([42, 2, 3]); +let tarray2 = new Uint8Array([1, 2, 42]); + +assertEq(arraysEqual(typedArray.with(-0, 42), tarray1), true); + +/* null => 0 */ +assertEq(arraysEqual(typedArray.with(null, 42), tarray1), true); +/* [] => 0 */ +assertEq(arraysEqual(typedArray.with([], 42), tarray1), true); + +assertEq(arraysEqual(typedArray.with("2", 42), tarray2), true); + +/* Non-numeric indices => 0 */ +assertEq(arraysEqual(typedArray.with("monkeys", 42), tarray1), true); +assertEq(arraysEqual(typedArray.with(undefined, 42), tarray1), true); +assertEq(arraysEqual(typedArray.with(function() {}, 42), tarray1), true); + +assertThrowsInstanceOf(() => typedArray.with(3, 42), RangeError); +assertThrowsInstanceOf(() => typedArray.with(5, 42), RangeError); +assertThrowsInstanceOf(() => typedArray.with(-10, 42), RangeError); +assertThrowsInstanceOf(() => typedArray.with(Infinity, 42), RangeError); + +let reversedIntArray = typedArray.toReversed(); +assertEq(arraysEqual(typedArray, typedArray123), true); +assertEq(arraysEqual(reversedIntArray, typedArray2), true); + +let sortedIntArray = typedArray2.toSorted(); +assertEq(arraysEqual(typedArray2, new Uint8Array([3, 2, 1])), true); +assertEq(arraysEqual(sortedIntArray, typedArray), true); diff --git a/js/src/jit-test/tests/typedarray/typed-array-inline-cache.js b/js/src/jit-test/tests/typedarray/typed-array-inline-cache.js new file mode 100644 index 0000000000..f7697875f9 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/typed-array-inline-cache.js @@ -0,0 +1,54 @@ +// ECMA262 9.4.5.2 [[HasProperty]] +function check_in(x, a) { + return (x in a); +} + +function check_has_own(x, a) { + return a.hasOwnProperty(x); +} + +//make sure baseline gets compiled +function warmup(a) { + for (var i = 0; i < 1001; i++) { + check_in(i, a); + check_has_own(i, a); + } +} + +function check_assertions(a) { + assertEq(check_in(1, a), true); + assertEq(check_in("-0",a), false); // -0 access + assertEq(check_in(-10,a), false); // Negative access + assertEq(check_in(1012,a), false); // OOB access + + + assertEq(check_has_own(1, a), true); + assertEq(check_has_own("-0",a), false); // -0 access + assertEq(check_has_own(-10,a), false); // Negative access + assertEq(check_has_own(1012,a), false); // OOB access +} + +function test_with_no_protochain(a) { + var a = new Int32Array(1000).fill(1); + warmup(a); + check_assertions(a); +} + +// Attempting to validate against this comment: +// https://bugzilla.mozilla.org/show_bug.cgi?id=1419372#c3 +// +// "Out of bounds "in" or "hasOwnProperty" should always +// return false, and not consider the prototype chain at all" +function test_with_protochain(a) { + var a = new Int32Array(1000).fill(1); + warmup(a); + // try to force the behaviour of 9.4.5.2 + Object.prototype["-0"] = "value"; + Object.prototype[-1] = "value"; + Object.prototype[-10] = "value"; + Object.prototype[1012] = "value"; + check_assertions(a); +} + +test_with_no_protochain(); +test_with_protochain(); diff --git a/js/src/jit-test/tests/typedarray/typedarrayobject-getelements.js b/js/src/jit-test/tests/typedarray/typedarrayobject-getelements.js new file mode 100644 index 0000000000..98296b1fe1 --- /dev/null +++ b/js/src/jit-test/tests/typedarray/typedarrayobject-getelements.js @@ -0,0 +1,6 @@ +function test() { + var view = new Uint8Array([72, 101, 108, 108, 111]); + let s = String.fromCharCode.apply(null, view); + assertEq("Hello", s); +} +test(); |