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/cacheir/binaryarith-null-undef-bool.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 'js/src/jit-test/tests/cacheir/binaryarith-null-undef-bool.js')
-rw-r--r-- | js/src/jit-test/tests/cacheir/binaryarith-null-undef-bool.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/cacheir/binaryarith-null-undef-bool.js b/js/src/jit-test/tests/cacheir/binaryarith-null-undef-bool.js new file mode 100644 index 0000000000..140db26572 --- /dev/null +++ b/js/src/jit-test/tests/cacheir/binaryarith-null-undef-bool.js @@ -0,0 +1,75 @@ +// Pass |null| as argument to be more robust against code folding. +function testNullWithInt32OrBool(nullVal) { + var vals = [0, 1, true, false, null]; + for (var v of vals) { + assertEq(v + nullVal, Number(v)); + assertEq(v - nullVal, Number(v)); + assertEq(v * nullVal, 0); + var res = v / nullVal; + assertEq(isNaN(res) || res === Infinity, true); + assertEq(v % nullVal, NaN); + assertEq(v ** nullVal, 1); + + assertEq(nullVal + v, Number(v)); + assertEq(nullVal - v, 0 - Number(v)); + assertEq(nullVal * v, 0); + res = nullVal / v; + assertEq(isNaN(res) || res === 0, true); + res = nullVal % v; + assertEq(isNaN(res) || res === 0, true); + res = nullVal ** v; + assertEq(res === 0 || res === 1, true); + } +} +for (var i = 0; i < 15; i++) { + testNullWithInt32OrBool(null); +} + +function testUndefinedWithOther(undefinedVal) { + var vals = [1.1, NaN, true, false, null, undefined]; + for (var v of vals) { + assertEq(v + undefinedVal, NaN); + assertEq(v - undefinedVal, NaN); + assertEq(v * undefinedVal, NaN); + assertEq(v / undefinedVal, NaN); + assertEq(v % undefinedVal, NaN); + assertEq(v ** undefinedVal, NaN); + + assertEq(undefinedVal + v, NaN); + assertEq(undefinedVal - v, NaN); + assertEq(undefinedVal * v, NaN); + assertEq(undefinedVal / v, NaN); + assertEq(undefinedVal % v, NaN); + var res = undefinedVal ** v; + if (v === false || v === null) { + assertEq(res, 1); + } else { + assertEq(res, NaN); + } + } +} +for (var i = 0; i < 15; i++) { + testUndefinedWithOther(undefined); +} + +function testBooleanWithDouble(trueVal, falseVal) { + var vals = [1.1, 2.2, 5, 6, 3.14]; + for (var v of vals) { + assertEq(v + falseVal, v); + assertEq(v - falseVal, v); + assertEq(v * falseVal, 0); + assertEq(v / falseVal, Infinity); + assertEq(v % falseVal, NaN); + assertEq(v ** falseVal, 1); + + assertEq(trueVal + v, v + 1); + assertEq(trueVal - v, 1 - v); + assertEq(trueVal * v, v); + assertEq(trueVal / v, 1 / v); + assertEq(trueVal % v, 1); + assertEq(trueVal ** v, 1); + } +} +for (var i = 0; i < 15; i++) { + testBooleanWithDouble(true, false); +} |