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/toString.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/toString.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/toString.js b/js/src/tests/non262/TypedArray/toString.js new file mode 100644 index 0000000000..0879b8b31d --- /dev/null +++ b/js/src/tests/non262/TypedArray/toString.js @@ -0,0 +1,69 @@ +const TypedArrayPrototype = Object.getPrototypeOf(Int8Array.prototype); + +// %TypedArrayPrototype% has an own "toString" property. +assertEq(TypedArrayPrototype.hasOwnProperty("toString"), true); + +// The initial value of %TypedArrayPrototype%.toString is Array.prototype.toString. +assertEq(TypedArrayPrototype.toString, Array.prototype.toString); + +// The concrete TypedArray prototypes do not have an own "toString" property. +assertEq(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("toString")), true); + +assertDeepEq(Object.getOwnPropertyDescriptor(TypedArrayPrototype, "toString"), { + value: TypedArrayPrototype.toString, + writable: true, + enumerable: false, + configurable: true, +}); + +for (let constructor of anyTypedArrayConstructors) { + assertEq(new constructor([]).toString(), ""); + assertEq(new constructor([1]).toString(), "1"); + assertEq(new constructor([1, 2]).toString(), "1,2"); +} + +const testCases = { + [Int8Array.name]: { + array: [-1, 2, -3, 4, NaN], + expected: "-1,2,-3,4,0", + }, + [Int16Array.name]: { + array: [-1, 2, -3, 4, NaN], + expected: "-1,2,-3,4,0", + }, + [Int32Array.name]: { + array: [-1, 2, -3, 4, NaN], + expected: "-1,2,-3,4,0", + }, + [Uint8Array.name]: { + array: [255, 2, 3, 4, NaN], + expected: "255,2,3,4,0", + }, + [Uint16Array.name]: { + array: [-1, 2, 3, 4, NaN], + expected: "65535,2,3,4,0", + }, + [Uint32Array.name]: { + array: [-1, 2, 3, 4, NaN], + expected: "4294967295,2,3,4,0", + }, + [Uint8ClampedArray.name]: { + array: [255, 256, 2, 3, 4, NaN], + expected: "255,255,2,3,4,0", + }, + [Float32Array.name]: { + array: [-0, 0, 0.5, -0.5, NaN, Infinity, -Infinity], + expected: "0,0,0.5,-0.5,NaN,Infinity,-Infinity", + }, + [Float64Array.name]: { + array: [-0, 0, 0.5, -0.5, NaN, Infinity, -Infinity], + expected: "0,0,0.5,-0.5,NaN,Infinity,-Infinity", + }, +}; +for (let constructor of anyTypedArrayConstructors) { + let {array, expected} = testCases[constructor.name]; + assertEq(new constructor(array).toString(), expected); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |