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/symbol | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/symbol')
-rw-r--r-- | js/src/jit-test/tests/symbol/bug-1033856.js | 6 | ||||
-rw-r--r-- | js/src/jit-test/tests/symbol/not.js | 13 | ||||
-rw-r--r-- | js/src/jit-test/tests/symbol/toNumber-2.js | 14 | ||||
-rw-r--r-- | js/src/jit-test/tests/symbol/toNumber.js | 53 | ||||
-rw-r--r-- | js/src/jit-test/tests/symbol/toString.js | 11 | ||||
-rw-r--r-- | js/src/jit-test/tests/symbol/truthiness.js | 13 | ||||
-rw-r--r-- | js/src/jit-test/tests/symbol/typed-arrays.js | 29 | ||||
-rw-r--r-- | js/src/jit-test/tests/symbol/typeof.js | 9 |
8 files changed, 148 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/symbol/bug-1033856.js b/js/src/jit-test/tests/symbol/bug-1033856.js new file mode 100644 index 0000000000..18f80ac202 --- /dev/null +++ b/js/src/jit-test/tests/symbol/bug-1033856.js @@ -0,0 +1,6 @@ +function f(x, y) { + return x == y; +} +f(1.1, 2.2); +for (var i=0; i<5; i++) + f(1, Symbol()); diff --git a/js/src/jit-test/tests/symbol/not.js b/js/src/jit-test/tests/symbol/not.js new file mode 100644 index 0000000000..7237b0b36c --- /dev/null +++ b/js/src/jit-test/tests/symbol/not.js @@ -0,0 +1,13 @@ +for (var i = 0; i < 9; i++) + assertEq(!Symbol(), false, "symbols are truthy"); + +var a = [0, 0, 0, 0, 0, Symbol(), Symbol()]; +var b = []; +function f(i, v) { + b[i] = !v; +} +for (var i = 0; i < a.length; i++) + f(i, a[i]); +assertEq(b[b.length - 3], true); +assertEq(b[b.length - 2], false); +assertEq(b[b.length - 1], false); diff --git a/js/src/jit-test/tests/symbol/toNumber-2.js b/js/src/jit-test/tests/symbol/toNumber-2.js new file mode 100644 index 0000000000..05a3224e96 --- /dev/null +++ b/js/src/jit-test/tests/symbol/toNumber-2.js @@ -0,0 +1,14 @@ +// |jit-test| error: ReferenceError +function eq(e, a) { + passed = (a == e); +} +function f(e, a) { + fail(); + eq(e, a); +} +try { + f(); +} catch (exc1) {} +eq(.1, .1); +var sym = Symbol("method"); +evaluate("f(test, sym, 0)", {isRunOnce:true}); diff --git a/js/src/jit-test/tests/symbol/toNumber.js b/js/src/jit-test/tests/symbol/toNumber.js new file mode 100644 index 0000000000..4677acbeb4 --- /dev/null +++ b/js/src/jit-test/tests/symbol/toNumber.js @@ -0,0 +1,53 @@ +load(libdir + "asserts.js"); + +var sym = Symbol(); + +function add2(x) { + return x + 2; +} +for (var i = 0; i < 9; i++) + assertThrowsInstanceOf(() => add2(sym), TypeError); + +function sqr(x) { + return x * x; +} +for (var i = 0; i < 9; i++) + assertThrowsInstanceOf(() => sqr(sym), TypeError); + +function bit_or(x) { + return x | x; +} +for (var i = 0; i < 9; i++) + assertThrowsInstanceOf(() => bit_or(sym), TypeError); + +function bit_not(x) { + return ~x; +} +for (var i = 0; i < 9; i++) + assertThrowsInstanceOf(() => bit_not(sym), TypeError); + +function plus(x) { + return +x; +} +for (var i = 0; i < 9; i++) + assertThrowsInstanceOf(() => plus(sym), TypeError); + +function f(a, b) { + return a + b; +} + +function testPoly() { + assertEq(f(20, 30), 50); + assertEq(f("one", "two"), "onetwo"); + assertThrowsInstanceOf(() => f(Symbol("one"), Symbol("two")), TypeError); + assertThrowsInstanceOf(() => f(Symbol("14"), 14), TypeError); + assertThrowsInstanceOf(() => f(Symbol("14"), 13.719), TypeError); + assertThrowsInstanceOf(() => f(14, Symbol("14")), TypeError); + assertThrowsInstanceOf(() => f(13.719, Symbol("14")), TypeError); +} + +for (var i = 0; i < 9; i++) + testPoly(); + +for (var i = 0; i < 9; i++) + assertThrowsInstanceOf(() => assertEq(f(Symbol("14"), "40"), NaN), TypeError); diff --git a/js/src/jit-test/tests/symbol/toString.js b/js/src/jit-test/tests/symbol/toString.js new file mode 100644 index 0000000000..764ea7aab4 --- /dev/null +++ b/js/src/jit-test/tests/symbol/toString.js @@ -0,0 +1,11 @@ +// ToString(symbol) throws a TypeError. + +var N = 10, obj, hits = 0; +for (var i = 0; i < N; i++) { + try { + obj = new String(Symbol()); + } catch (exc) { + hits++; + } +} +assertEq(hits, N); diff --git a/js/src/jit-test/tests/symbol/truthiness.js b/js/src/jit-test/tests/symbol/truthiness.js new file mode 100644 index 0000000000..a672158d60 --- /dev/null +++ b/js/src/jit-test/tests/symbol/truthiness.js @@ -0,0 +1,13 @@ +for (var i = 0; i < 9; i++) + assertEq(Symbol() ? 1 : 0, 1, "symbols are truthy"); + +var a = [0, 0, 0, 0, 0, Symbol(), Symbol()]; +var b = []; +function f(i, v) { + b[i] = v ? "yes" : "no"; +} +for (var i = 0; i < a.length; i++) + f(i, a[i]); +assertEq(b[b.length - 3], "no"); +assertEq(b[b.length - 2], "yes"); +assertEq(b[b.length - 1], "yes"); diff --git a/js/src/jit-test/tests/symbol/typed-arrays.js b/js/src/jit-test/tests/symbol/typed-arrays.js new file mode 100644 index 0000000000..005eec09af --- /dev/null +++ b/js/src/jit-test/tests/symbol/typed-arrays.js @@ -0,0 +1,29 @@ +load(libdir + "asserts.js"); + +var LENGTH = 1024, SYMBOL_INDEX = 999; + +var big = []; +for (var i = 0; i < LENGTH; i++) + big[i] = (i === SYMBOL_INDEX ? Symbol.for("comet") : i); + +var progress; +function copy(arr, big) { + for (var i = 0; i < LENGTH; i++) { + arr[i] = big[i]; + progress = i; + } +} + +for (var T of [Uint8Array, Uint8ClampedArray, Int16Array, Float32Array]) { + // Typed array constructors convert symbols using ToNumber, which throws. + assertThrowsInstanceOf(() => new T(big), TypeError); + + // Element assignment does the same. + var arr = new T(big.length); + for (var k = 0; k < 3; k++) { + progress = -1; + assertThrowsInstanceOf(() => copy(arr, big), TypeError); + assertEq(progress, SYMBOL_INDEX - 1); + assertEq(arr[SYMBOL_INDEX], 0); + } +} diff --git a/js/src/jit-test/tests/symbol/typeof.js b/js/src/jit-test/tests/symbol/typeof.js new file mode 100644 index 0000000000..d2c7d51cfd --- /dev/null +++ b/js/src/jit-test/tests/symbol/typeof.js @@ -0,0 +1,9 @@ +var a = [0, 0, 0, 0, 0, Symbol(), Symbol()]; +var b = []; +function f(i, v) { + b[i] = typeof v; +} +for (var i = 0; i < a.length; i++) + f(i, a[i]); +assertEq(b[b.length - 2], "symbol"); +assertEq(b[b.length - 1], "symbol"); |