summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/boolean-call.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit-test/tests/cacheir/boolean-call.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/cacheir/boolean-call.js')
-rw-r--r--js/src/jit-test/tests/cacheir/boolean-call.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/cacheir/boolean-call.js b/js/src/jit-test/tests/cacheir/boolean-call.js
new file mode 100644
index 0000000000..7c6d94f3d4
--- /dev/null
+++ b/js/src/jit-test/tests/cacheir/boolean-call.js
@@ -0,0 +1,67 @@
+function wrapper(values) {
+ function test(values) {
+ var expected = values.map(v => !!v);
+
+ for (var i = 0; i < 100; ++i) {
+ var ix = i % values.length;
+ var val = values[ix];
+ var actual = Boolean(val);
+ assertEq(actual, expected[ix]);
+ }
+ }
+
+ for (var i = 0; i < 2; ++i) {
+ test(values);
+ }
+}
+
+function makeTest() {
+ // Create a copy to avoid type pollution.
+ return Function(`return ${wrapper}`)();
+}
+
+// Use a new compartment to create a wrapper.
+var g = newGlobal({newCompartment: true});
+
+var testValues = {
+ boolean: [true, false],
+ int32: [-2147483648, -1, 0, 1, 2147483647],
+ double: [-Infinity, -1.5, -1, -0.5, -0, +0, +0.5, +1, +1.5, Infinity, NaN],
+ string: ["", "true", "false", "0", "1", "hello"],
+ symbol: [Symbol(), Symbol("desc"), Symbol.iterator],
+ bigint: [
+ -(2n ** 1000n),
+ -18446744073709551616n, // -(2n**64n)
+ -9223372036854775808n, // -(2n**63n)
+ -4294967296n, // -(2**32)
+ -2147483648n, // -(2**31)
+ -1n, 0n, 1n,
+ 2147483648n, // 2**31
+ 4294967296n, // 2**32
+ 9223372036854775808n, // 2n**63n
+ 18446744073709551616n, // 2n**64n
+ 2n ** 1000n,
+ ],
+ object: [{}, [], function(){}, new Proxy({}, {}), createIsHTMLDDA(), g.eval("createIsHTMLDDA()")],
+ null: [null],
+ undefined: [undefined],
+};
+
+for (var values of Object.values(testValues)) {
+ makeTest()(values);
+}
+
+// boolean and int32
+makeTest()([].concat(testValues.boolean, testValues.int32));
+
+// int32 and double
+makeTest()([].concat(testValues.int32, testValues.double));
+
+// null and undefined
+makeTest()([].concat(testValues.null, testValues.undefined));
+
+// null, undefined, and object
+makeTest()([].concat(testValues.null, testValues.undefined, testValues.object));
+
+// all values
+makeTest()(Object.values(testValues).flat());