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/toLocaleString.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/toLocaleString.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/toLocaleString.js b/js/src/tests/non262/TypedArray/toLocaleString.js new file mode 100644 index 0000000000..78049ec225 --- /dev/null +++ b/js/src/tests/non262/TypedArray/toLocaleString.js @@ -0,0 +1,80 @@ +const TypedArrayPrototype = Object.getPrototypeOf(Int8Array.prototype); + +// %TypedArrayPrototype% has an own "toLocaleString" function property. +assertEq(TypedArrayPrototype.hasOwnProperty("toLocaleString"), true); +assertEq(typeof TypedArrayPrototype.toLocaleString, "function"); + +// The initial value of %TypedArrayPrototype%.toLocaleString is not Array.prototype.toLocaleString. +assertEq(TypedArrayPrototype.toLocaleString === Array.prototype.toLocaleString, false); + +// The concrete TypedArray prototypes do not have an own "toLocaleString" property. +assertEq(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("toLocaleString")), true); + +assertDeepEq(Object.getOwnPropertyDescriptor(TypedArrayPrototype, "toLocaleString"), { + value: TypedArrayPrototype.toLocaleString, + writable: true, + enumerable: false, + configurable: true, +}); + +assertEq(TypedArrayPrototype.toLocaleString.name, "toLocaleString"); +assertEq(TypedArrayPrototype.toLocaleString.length, 0); + +// It's not a generic method. +assertThrowsInstanceOf(() => TypedArrayPrototype.toLocaleString.call(), TypeError); +for (let invalid of [void 0, null, {}, [], function(){}, true, 0, "", Symbol()]) { + assertThrowsInstanceOf(() => TypedArrayPrototype.toLocaleString.call(invalid), TypeError); +} + +const localeOne = 1..toLocaleString(), + localeTwo = 2..toLocaleString(), + localeSep = [,,].toLocaleString(); + +for (let constructor of anyTypedArrayConstructors) { + assertEq(new constructor([]).toLocaleString(), ""); + assertEq(new constructor([1]).toLocaleString(), localeOne); + assertEq(new constructor([1, 2]).toLocaleString(), localeOne + localeSep + localeTwo); +} + +const originalNumberToLocaleString = Number.prototype.toLocaleString; + +// Calls Number.prototype.toLocaleString on each element. +for (let constructor of anyTypedArrayConstructors) { + Number.prototype.toLocaleString = function() { + "use strict"; + + // Ensure this-value is not boxed. + assertEq(typeof this, "number"); + + // Test ToString is applied. + return { + valueOf: () => { + throw new Error("valueOf called"); + }, + toString: () => { + return this + 10; + } + }; + }; + let typedArray = new constructor([1, 2]); + assertEq(typedArray.toLocaleString(), "11" + localeSep + "12"); +} +Number.prototype.toLocaleString = originalNumberToLocaleString; + +// Calls Number.prototype.toLocaleString from the current Realm. +const otherGlobal = newGlobal(); +for (let constructor of anyTypedArrayConstructors) { + Number.prototype.toLocaleString = function() { + "use strict"; + called = true; + return this; + }; + let typedArray = new otherGlobal[constructor.name]([1]); + let called = false; + assertEq(TypedArrayPrototype.toLocaleString.call(typedArray), "1"); + assertEq(called, true); +} +Number.prototype.toLocaleString = originalNumberToLocaleString; + +if (typeof reportCompare === "function") + reportCompare(true, true); |