summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/mathImul.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/basic/mathImul.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/basic/mathImul.js')
-rw-r--r--js/src/jit-test/tests/basic/mathImul.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/mathImul.js b/js/src/jit-test/tests/basic/mathImul.js
new file mode 100644
index 0000000000..aa1861e5a7
--- /dev/null
+++ b/js/src/jit-test/tests/basic/mathImul.js
@@ -0,0 +1,71 @@
+
+var table = [
+ [NaN, 0, 0],
+ [Infinity, Infinity, 0],
+ [NaN, 1000, 0],
+
+ [-1, -2, 2],
+ [1, 2, 2],
+ [-1, 2, -2],
+ [1, -2, -2],
+ [-0, 0, 0],
+ [0, -0, 0],
+ [-1, -0, 0],
+ [1, -0, 0],
+
+ [0xffffffff, 1, -1],
+
+ [0xffffffff, 0xffffffff, 1],
+ [0xffffffff, -0xffffffff, -1],
+ [0xffffffff, 0xfffffffe, 2],
+ [0xffffffff, -0xfffffffe, -2],
+ [0x10000, 0x10000, 0],
+
+ [{}, {}, 0],
+ [[], [], 0],
+ [{}, [], 0],
+ [[], {}, 0],
+
+ [{valueOf: function() { return -1; }}, 0x100000, -1048576],
+ ["3", "-4", -12],
+ [3.4, 6, 18]
+];
+
+try {
+ Math.imul({ valueOf: function() { throw "ha ha ha"; } });
+ assertEq(true, false, "no error thrown");
+} catch (e) {
+ assertEq(e, "ha ha ha");
+}
+
+var order = [];
+assertEq(Math.imul({ valueOf: function() { order.push("first"); return 0; } },
+ { valueOf: function() { order.push("second"); return 0; } }),
+ 0);
+assertEq(order[0], "first");
+assertEq(order[1], "second");
+
+var seen = [];
+try
+{
+ Math.imul({ valueOf: function() { seen.push("one"); return 17; } },
+ { valueOf: function() { throw "abort!"; } });
+ assertEq(true, false, "no error thrown");
+}
+catch (e)
+{
+ assertEq(e, "abort!", "should have thrown partway through, instead threw " + e);
+}
+assertEq(seen.length, 1);
+assertEq(seen[0], "one");
+
+assertEq(Math.imul(), 0);
+assertEq(Math.imul(100), 0);
+assertEq(Math.imul(NaN, 100), 0);
+assertEq(Math.imul(NaN, NaN), 0);
+assertEq(Math.imul(5, Infinity), 0);
+
+for (var i = 0; i < table.length; i++) {
+ assertEq(Math.imul(table[i][0], table[i][1]), table[i][2]);
+ assertEq(Math.imul(table[i][1], table[i][0]), table[i][2]);
+}