summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/Set
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/Set
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 '')
-rw-r--r--js/src/jit-test/tests/Set/NaN-as-key.js40
-rw-r--r--js/src/jit-test/tests/Set/bug1729269.js19
-rw-r--r--js/src/jit-test/tests/Set/forEach-selfhosted-behavior.js36
-rw-r--r--js/src/jit-test/tests/Set/getter-name.js3
-rw-r--r--js/src/jit-test/tests/Set/iterator-thisv-error.js19
-rw-r--r--js/src/jit-test/tests/Set/non-iterable-error.js7
-rw-r--r--js/src/jit-test/tests/Set/symbols.js26
7 files changed, 150 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/Set/NaN-as-key.js b/js/src/jit-test/tests/Set/NaN-as-key.js
new file mode 100644
index 0000000000..1a24010a83
--- /dev/null
+++ b/js/src/jit-test/tests/Set/NaN-as-key.js
@@ -0,0 +1,40 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+// All NaNs must be treated as identical keys for Set.
+
+// Avoid constant-folding that would happen were |undefined| to be used.
+var key = -/a/g.missingProperty;
+
+var s = new Set();
+s.add(key, 17);
+assertEq(s.has(key), true);
+assertEq(s.has(-key), true);
+assertEq(s.has(NaN), true);
+
+s.delete(-key);
+assertEq(s.has(key), false);
+assertEq(s.has(-key), false);
+assertEq(s.has(NaN), false);
+
+s.add(-key, 17);
+assertEq(s.has(key), true);
+assertEq(s.has(-key), true);
+assertEq(s.has(NaN), true);
+
+s.delete(NaN);
+assertEq(s.has(key), false);
+assertEq(s.has(-key), false);
+assertEq(s.has(NaN), false);
+
+s.add(NaN, 17);
+assertEq(s.has(key), true);
+assertEq(s.has(-key), true);
+assertEq(s.has(NaN), true);
+
+s.delete(key);
+assertEq(s.has(key), false);
+assertEq(s.has(-key), false);
+assertEq(s.has(NaN), false);
diff --git a/js/src/jit-test/tests/Set/bug1729269.js b/js/src/jit-test/tests/Set/bug1729269.js
new file mode 100644
index 0000000000..e97f6d2a12
--- /dev/null
+++ b/js/src/jit-test/tests/Set/bug1729269.js
@@ -0,0 +1,19 @@
+// |jit-test| skip-if: !('oomTest' in this)
+
+var patchSet = new Set();
+
+function checkSet(str) {
+ patchSet.has(str);
+}
+
+for (var i = 0; i < 20; i++) {
+ checkSet("s");
+}
+
+let re = /x(.*)x/;
+let count = 0;
+oomTest(() => {
+ // Create a string that needs to be atomized.
+ let result = re.exec("xa" + count++ + "ax")[1];
+ checkSet(result);
+})
diff --git a/js/src/jit-test/tests/Set/forEach-selfhosted-behavior.js b/js/src/jit-test/tests/Set/forEach-selfhosted-behavior.js
new file mode 100644
index 0000000000..ca6363be5c
--- /dev/null
+++ b/js/src/jit-test/tests/Set/forEach-selfhosted-behavior.js
@@ -0,0 +1,36 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+// Don't use .call(...) in the self-hosted Set.prototype.forEach
+
+var functionCall = Function.prototype.call;
+
+function throwSyntaxError()
+{
+ throw new SyntaxError("Function.prototype.call incorrectly called");
+}
+
+function lalala() {}
+
+Function.prototype.call = throwSyntaxError;
+
+new Set().forEach(throwSyntaxError);
+new Set([1]).forEach(lalala);
+new Set([{}, 4]).forEach(lalala);
+
+Function.prototype.call = function() { this.add(3.141592654); };
+
+new Set().forEach(throwSyntaxError);
+new Set(["foo"]).forEach(lalala);
+new Set([undefined, NaN]).forEach(lalala);
+
+var callCount = 0;
+Function.prototype.call = function() { callCount++; };
+
+new Set().forEach(throwSyntaxError);
+new Set([new Number]).forEach(lalala);
+new Set([true, new Boolean(false)]).forEach(lalala);
+
+assertEq(callCount, 0);
diff --git a/js/src/jit-test/tests/Set/getter-name.js b/js/src/jit-test/tests/Set/getter-name.js
new file mode 100644
index 0000000000..fe049d32a9
--- /dev/null
+++ b/js/src/jit-test/tests/Set/getter-name.js
@@ -0,0 +1,3 @@
+// Set getters should have get prefix
+assertEq(Object.getOwnPropertyDescriptor(Set, Symbol.species).get.name, "get [Symbol.species]");
+assertEq(Object.getOwnPropertyDescriptor(Set.prototype, "size").get.name, "get size");
diff --git a/js/src/jit-test/tests/Set/iterator-thisv-error.js b/js/src/jit-test/tests/Set/iterator-thisv-error.js
new file mode 100644
index 0000000000..b8a4e65196
--- /dev/null
+++ b/js/src/jit-test/tests/Set/iterator-thisv-error.js
@@ -0,0 +1,19 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+
+function test(fn, thisv) {
+ var message;
+ try {
+ fn.call(thisv);
+ } catch (e) {
+ message = e.message;
+ }
+
+ assertEq(/^values method called on incompatible.+/.test(message), true);
+}
+
+for (var thisv of [null, undefined, false, true, 0, ""]) {
+ test(Set.prototype.values, thisv);
+ test(Set.prototype.keys, thisv);
+ test(Set.prototype[Symbol.iterator], thisv);
+}
diff --git a/js/src/jit-test/tests/Set/non-iterable-error.js b/js/src/jit-test/tests/Set/non-iterable-error.js
new file mode 100644
index 0000000000..e2702abb49
--- /dev/null
+++ b/js/src/jit-test/tests/Set/non-iterable-error.js
@@ -0,0 +1,7 @@
+// Self-hosted JS code shouldn't be used for error message.
+
+try {
+ new Set(...[1]);
+} catch (e) {
+ assertEq(e.message, "1 is not iterable");
+}
diff --git a/js/src/jit-test/tests/Set/symbols.js b/js/src/jit-test/tests/Set/symbols.js
new file mode 100644
index 0000000000..f272102800
--- /dev/null
+++ b/js/src/jit-test/tests/Set/symbols.js
@@ -0,0 +1,26 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+
+load(libdir + "asserts.js");
+
+var s = new Set;
+
+// Symbols can be stored in Sets.
+var sym = Symbol();
+s.add(sym);
+assertEq(s.has(sym), true);
+assertEq(s.has(Symbol()), false);
+assertEq([...s][0], sym);
+s.add(sym);
+assertEq(s.has(sym), true);
+assertEq(s.size, 1);
+s.delete(sym);
+assertEq(s.has(sym), false);
+assertEq(s.size, 0);
+
+// Symbols returned by Symbol.for() can be in Sets.
+var str = "how much wood would a woodchuck chuck if a woodchuck could chuck wood";
+var s2 = "how much wood would a woodchuck chuck if could";
+var arr = str.split(" ").map(Symbol.for);
+s = new Set(arr);
+assertDeepEq([...s], s2.split(" ").map(Symbol.for));