summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/TypedArray/set-tointeger.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/TypedArray/set-tointeger.js
parentInitial commit. (diff)
downloadfirefox-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/set-tointeger.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/set-tointeger.js b/js/src/tests/non262/TypedArray/set-tointeger.js
new file mode 100644
index 0000000000..8c1e9c2418
--- /dev/null
+++ b/js/src/tests/non262/TypedArray/set-tointeger.js
@@ -0,0 +1,95 @@
+// Test ToInteger conversion in %TypedArray%.prototype.set(array|typedArray, offset).
+
+let ta = new Int32Array(4);
+
+// %TypedArray%.prototype.set has two different implementations for typed array
+// and non-typed array arguments. Test with both input types.
+let emptySources = [[], new Int32Array(0)];
+let nonEmptySource = [[0], new Int32Array(1)];
+let sources = [...emptySources, ...nonEmptySource];
+
+// Test when ToInteger(offset) is in (-1, 4).
+let validOffsets = [
+ // Values in [+0, 4).
+ 0,
+ 0.1,
+ 3,
+ 3.9,
+
+ // Values in (-1, -0].
+ -0,
+ -0.1,
+ -0.9,
+
+ NaN,
+
+ // Also include some non-number values.
+ undefined,
+ null,
+ true,
+ "",
+ "3",
+ " 1\t\n",
+ "some string",
+ {valueOf() { return 2; }},
+];
+
+for (let offset of validOffsets) {
+ for (let source of sources) {
+ ta.set(source, offset);
+ }
+}
+
+// Test when ToInteger(offset) isn't in (-1, 4).
+let invalidOffsets = [
+ // Values exceeding the typed array's length.
+ 5,
+ 2147483647,
+ 2147483648,
+ 2147483649,
+ 4294967295,
+ 4294967296,
+ 4294967297,
+ Infinity,
+
+ // Negative values.
+ -1,
+ -1.1,
+ -2147483647,
+ -2147483648,
+ -2147483649,
+ -4294967295,
+ -4294967296,
+ -4294967297,
+ -Infinity,
+
+ // Also include some non-number values.
+ "8",
+ "Infinity",
+ " Infinity ",
+ {valueOf() { return 10; }},
+];
+
+for (let offset of invalidOffsets) {
+ for (let source of sources) {
+ assertThrowsInstanceOf(() => ta.set(source, offset), RangeError);
+ }
+}
+
+// Test when ToInteger(offset) is in [4, 5).
+for (let source of emptySources) {
+ ta.set(source, 4);
+ ta.set(source, 4.9);
+}
+for (let source of nonEmptySource) {
+ assertThrowsInstanceOf(() => ta.set(source, 4), RangeError);
+ assertThrowsInstanceOf(() => ta.set(source, 4.9), RangeError);
+}
+
+// ToInteger(symbol value) throws a TypeError.
+for (let source of sources) {
+ assertThrowsInstanceOf(() => ta.set(source, Symbol()), TypeError);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);