summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Set
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/non262/Set')
-rw-r--r--js/src/tests/non262/Set/browser.js0
-rw-r--r--js/src/tests/non262/Set/difference.js63
-rw-r--r--js/src/tests/non262/Set/intersection.js63
-rw-r--r--js/src/tests/non262/Set/is-disjoint-from.js63
-rw-r--r--js/src/tests/non262/Set/is-subset-of.js69
-rw-r--r--js/src/tests/non262/Set/is-superset-of.js63
-rw-r--r--js/src/tests/non262/Set/shell.js45
-rw-r--r--js/src/tests/non262/Set/symmetric-difference.js63
-rw-r--r--js/src/tests/non262/Set/union.js65
9 files changed, 494 insertions, 0 deletions
diff --git a/js/src/tests/non262/Set/browser.js b/js/src/tests/non262/Set/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/non262/Set/browser.js
diff --git a/js/src/tests/non262/Set/difference.js b/js/src/tests/non262/Set/difference.js
new file mode 100644
index 0000000000..edcaec7608
--- /dev/null
+++ b/js/src/tests/non262/Set/difference.js
@@ -0,0 +1,63 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+if (typeof getBuildConfiguration === "undefined") {
+ var getBuildConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getBuildConfiguration;
+}
+
+if (typeof getRealmConfiguration === "undefined") {
+ var getRealmConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getRealmConfiguration;
+}
+
+if (getBuildConfiguration()['new-set-methods'] && getRealmConfiguration().enableNewSetMethods) {
+
+ assertEq(typeof Set.prototype.difference, 'function');
+ assertEq(Set.prototype.difference.length, 1);
+ assertEq(Set.prototype.difference.name, 'difference');
+
+ assertSetContainsExactOrderedItems(new Set([1, true, null]).difference(new Set()), [1, true, null]);
+ assertSetContainsExactOrderedItems(new Set([1, true, null]).difference([1, true, null]), []);
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).difference([2, 3, 4]), [1]);
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).difference([4]), [1, 2, 3]);
+ // Works when the argument is a custom iterable which follows the Symbol.iterator protocol
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).difference(makeArrayIterator([3, 4])), [1, 2]);
+ assertSetContainsExactOrderedItems(new Set(['a','d']).difference('abc'), ['d']);
+
+ // Works when the `this` is a custom iterable which follows the Symbol.iterator protocol
+ assertSetContainsExactOrderedItems(Set.prototype.difference.call(makeArrayIterator([1, 2, 3, 3, 2]), [4, 5, 6]), [1, 2, 3]);
+
+ // Does not modify the original set object
+ const set = new Set([1]);
+ assertEq(set.difference([1]) !== set, true);
+
+ // Argument must be iterable
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.difference();
+ }, TypeError);
+ for (const arg of [null, {}, true, 1, undefined, NaN, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.difference(arg);
+ }, TypeError);
+ }
+
+ // `this` must be an Object
+ for (const arg of [null, undefined, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ Set.prototype.difference.call(arg, []);
+ }, TypeError);
+ }
+
+ // `this` must be iterable
+ assertThrowsInstanceOf(function () {
+ Set.prototype.difference.call({}, []);
+ }, TypeError);
+} else {
+ assertEq(typeof Set.prototype.difference, 'undefined');
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Set/intersection.js b/js/src/tests/non262/Set/intersection.js
new file mode 100644
index 0000000000..806edebc9b
--- /dev/null
+++ b/js/src/tests/non262/Set/intersection.js
@@ -0,0 +1,63 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+if (typeof getBuildConfiguration === "undefined") {
+ var getBuildConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getBuildConfiguration;
+}
+
+if (typeof getRealmConfiguration === "undefined") {
+ var getRealmConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getRealmConfiguration;
+}
+
+if (getBuildConfiguration()['new-set-methods'] && getRealmConfiguration().enableNewSetMethods) {
+
+ assertEq(typeof Set.prototype.intersection, 'function');
+ assertEq(Set.prototype.intersection.length, 1);
+ assertEq(Set.prototype.intersection.name, 'intersection');
+
+ assertSetContainsExactOrderedItems(new Set([1, true, null]).intersection(new Set()), []);
+ assertSetContainsExactOrderedItems(new Set([1, true, null]).intersection([1, true, null]), [1, true, null]);
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).intersection([2, 3, 4]), [2, 3]);
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).intersection([4]), []);
+ // Works when the argument is a custom iterable which follows the Symbol.iterator protocol
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).intersection(makeArrayIteratorWithHasMethod([3, 4])), [3]);
+ assertSetContainsExactOrderedItems(new Set(['a']).intersection('abc'), ['a']);
+
+ // Works when the `this` is a custom iterable which follows the Symbol.iterator protocol and has a `has` method
+ assertSetContainsExactOrderedItems(Set.prototype.intersection.call(makeArrayIteratorWithHasMethod([1, 2, 3, 3, 2]), [3, 4, 5, 6]), [3]);
+
+ // Does not modify the original set object
+ const set = new Set([1]);
+ assertEq(set.intersection([2]) !== set, true);
+
+ // Argument must be iterable
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.intersection();
+ }, TypeError);
+ for (const arg of [null, {}, true, 1, undefined, NaN, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.intersection(arg);
+ }, TypeError);
+ }
+
+ // `this` must be an Object
+ for (const arg of [null, undefined, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ Set.prototype.intersection.call(arg, []);
+ }, TypeError);
+ }
+
+ // `this` must be iterable
+ assertThrowsInstanceOf(function () {
+ Set.prototype.intersection.call({}, []);
+ }, TypeError);
+} else {
+ assertEq(typeof Set.prototype.intersection, 'undefined');
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Set/is-disjoint-from.js b/js/src/tests/non262/Set/is-disjoint-from.js
new file mode 100644
index 0000000000..0209f637fc
--- /dev/null
+++ b/js/src/tests/non262/Set/is-disjoint-from.js
@@ -0,0 +1,63 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+if (typeof getBuildConfiguration === "undefined") {
+ var getBuildConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getBuildConfiguration;
+}
+
+if (typeof getRealmConfiguration === "undefined") {
+ var getRealmConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getRealmConfiguration;
+}
+
+if (getBuildConfiguration()['new-set-methods'] && getRealmConfiguration().enableNewSetMethods) {
+
+ assertEq(typeof Set.prototype.isDisjointFrom, 'function');
+ assertEq(Set.prototype.isDisjointFrom.length, 1);
+ assertEq(Set.prototype.isDisjointFrom.name, 'isDisjointFrom');
+
+ assertEq(new Set([1, true, null]).isDisjointFrom(new Set()), true);
+ assertEq(new Set([1, true, null]).isDisjointFrom([1, true, null]), false);
+ assertEq(new Set([1, 2, 3]).isDisjointFrom([2, 3, 4]), false);
+ assertEq(new Set([1, 2, 3]).isDisjointFrom([4]), true);
+ // Works when the argument is a custom iterable which follows the Symbol.iterator protocol
+ assertEq(new Set([1, 2, 3]).isDisjointFrom(makeArrayIteratorWithHasMethod([3, 4])), false);
+ assertEq(new Set(['a']).isDisjointFrom('abc'), false);
+
+ // Works when the `this` is a custom iterable which follows the Symbol.iterator protocol
+ assertEq(Set.prototype.isDisjointFrom.call(makeArrayIteratorWithHasMethod([1, 2, 3, 3, 2]), [4, 5, 6]), true);
+
+ // Does not modify the original set object
+ const set = new Set([1]);
+ assertEq(set.isDisjointFrom([2]) !== set, true);
+
+ // Argument must be iterable
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.isDisjointFrom();
+ }, TypeError);
+ for (const arg of [null, {}, true, 1, undefined, NaN, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.isDisjointFrom(arg);
+ }, TypeError);
+ }
+
+ // `this` must be an Object
+ for (const arg of [null, undefined, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ Set.prototype.isDisjointFrom.call(arg, []);
+ }, TypeError);
+ }
+
+ // `this` must be iterable
+ assertThrowsInstanceOf(function () {
+ Set.prototype.isDisjointFrom.call({}, []);
+ }, TypeError);
+} else {
+ assertEq(typeof Set.prototype.isDisjointFrom, 'undefined');
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Set/is-subset-of.js b/js/src/tests/non262/Set/is-subset-of.js
new file mode 100644
index 0000000000..b6c74126b6
--- /dev/null
+++ b/js/src/tests/non262/Set/is-subset-of.js
@@ -0,0 +1,69 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+if (typeof getBuildConfiguration === "undefined") {
+ var getBuildConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getBuildConfiguration;
+}
+
+if (typeof getRealmConfiguration === "undefined") {
+ var getRealmConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getRealmConfiguration;
+}
+
+if (getBuildConfiguration()['new-set-methods'] && getRealmConfiguration().enableNewSetMethods) {
+
+ assertEq(typeof Set.prototype.isSubsetOf, 'function');
+ assertEq(Set.prototype.isSubsetOf.length, 1);
+ assertEq(Set.prototype.isSubsetOf.name, 'isSubsetOf');
+
+ assertEq(new Set([1, true, null]).isSubsetOf(new Set()), false);
+
+ assertEq(new Set([1, true, null]).isSubsetOf([1, true, null]), true);
+ assertEq(new Set([1, 2, 3]).isSubsetOf([2, 3, 4]), false);
+ assertEq(new Set([1, 2, 3]).isSubsetOf([1, 2, 3, 4]), true);
+ // Works when the argument is a custom iterable which follows the Symbol.iterator protocol
+ assertEq(new Set([1, 2, 3]).isSubsetOf(makeArrayIteratorWithHasMethod([3, 4])), false);
+
+ // Works when the `this` is a custom iterable which follows the Symbol.iterator protocol
+ assertEq(
+ Set.prototype.isSubsetOf.call(
+ makeArrayIteratorWithHasMethod([1, 2, 3, 3, 2]),
+ makeArrayIteratorWithHasMethod([4, 5, 6])
+ ),
+ false
+ );
+
+ // Does not modify the original set object
+ const set = new Set([1]);
+ assertEq(set.isSubsetOf(new Set([2])) !== set, true);
+
+ // Argument must be iterable and an object
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.isSubsetOf();
+ }, TypeError);
+ for (const arg of [null, {}, true, 1, undefined, NaN, Symbol(), ""]) {
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.isSubsetOf(arg);
+ }, TypeError);
+ }
+
+ // `this` must be an Object
+ for (const arg of [null, undefined, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ Set.prototype.isSubsetOf.call(arg, []);
+ }, TypeError);
+ }
+
+ // `this` must be iterable
+ assertThrowsInstanceOf(function () {
+ Set.prototype.isSubsetOf.call({}, []);
+ }, TypeError);
+} else {
+ assertEq(typeof Set.prototype.isSubsetOf, 'undefined');
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Set/is-superset-of.js b/js/src/tests/non262/Set/is-superset-of.js
new file mode 100644
index 0000000000..d814f061f9
--- /dev/null
+++ b/js/src/tests/non262/Set/is-superset-of.js
@@ -0,0 +1,63 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+if (typeof getBuildConfiguration === "undefined") {
+ var getBuildConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getBuildConfiguration;
+}
+
+if (typeof getRealmConfiguration === "undefined") {
+ var getRealmConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getRealmConfiguration;
+}
+
+if (getBuildConfiguration()['new-set-methods'] && getRealmConfiguration().enableNewSetMethods) {
+
+ assertEq(typeof Set.prototype.isSupersetOf, 'function');
+ assertEq(Set.prototype.isSupersetOf.length, 1);
+ assertEq(Set.prototype.isSupersetOf.name, 'isSupersetOf');
+
+ assertEq(new Set([1, true, null]).isSupersetOf(new Set()), true);
+ assertEq(new Set([1, true, null]).isSupersetOf([1, true, null]), true);
+ assertEq(new Set([1, 2, 3]).isSupersetOf([2, 3, 4]), false);
+ assertEq(new Set([1, 2, 3]).isSupersetOf([3]), true);
+ // Works when the argument is a custom iterable which follows the Symbol.iterator protocol
+ assertEq(new Set([1, 2, 3]).isSupersetOf(makeArrayIteratorWithHasMethod([2, 3])), true);
+ assertEq(new Set(['a']).isSupersetOf('abc'), false);
+
+ // Works when the `this` is a custom iterable which follows the Symbol.iterator protocol
+ assertEq(Set.prototype.isSupersetOf.call(makeArrayIteratorWithHasMethod([1, 2, 3, 3, 2]), [4, 5, 6]), false);
+
+ // Does not modify the original set object
+ const set = new Set([1]);
+ assertEq(set.isSupersetOf([2]) !== set, true);
+
+ // Argument must be iterable
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.isSupersetOf();
+ }, TypeError);
+ for (const arg of [null, {}, true, 1, undefined, NaN, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.isSupersetOf(arg);
+ }, TypeError);
+ }
+
+ // `this` must be an Object
+ for (const arg of [null, undefined, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ Set.prototype.isSupersetOf.call(arg, []);
+ }, TypeError);
+ }
+
+ // `this` must be iterable
+ assertThrowsInstanceOf(function () {
+ Set.prototype.isSupersetOf.call({}, []);
+ }, TypeError);
+} else {
+ assertEq(typeof Set.prototype.isSupersetOf, 'undefined');
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Set/shell.js b/js/src/tests/non262/Set/shell.js
new file mode 100644
index 0000000000..8c61eee059
--- /dev/null
+++ b/js/src/tests/non262/Set/shell.js
@@ -0,0 +1,45 @@
+function makeArrayIterator(array) {
+ let i = 0;
+ return {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ if (i >= array.length) {
+ return { done: true };
+ } else {
+ return { value: array[i++] };
+ }
+ }
+ };
+ }
+ }
+}
+
+function makeArrayIteratorWithHasMethod(array) {
+ let i = 0;
+ return {
+ has(item) {
+ return array.includes(item);
+ },
+ [Symbol.iterator]() {
+ return {
+ next() {
+ if (i >= array.length) {
+ return { done: true };
+ } else {
+ return { value: array[i++] };
+ }
+ }
+ };
+ }
+ };
+}
+
+function assertSetContainsExactOrderedItems(actual, expected) {
+ assertEq(actual.size, expected.length);
+ let index = 0;
+ for (const item of actual) {
+ assertEq(item, expected[index]);
+ index++;
+ }
+}
diff --git a/js/src/tests/non262/Set/symmetric-difference.js b/js/src/tests/non262/Set/symmetric-difference.js
new file mode 100644
index 0000000000..37e29902b8
--- /dev/null
+++ b/js/src/tests/non262/Set/symmetric-difference.js
@@ -0,0 +1,63 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+if (typeof getBuildConfiguration === "undefined") {
+ var getBuildConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getBuildConfiguration;
+}
+
+if (typeof getRealmConfiguration === "undefined") {
+ var getRealmConfiguration = SpecialPowers.Cu.getJSTestingFunctions().getRealmConfiguration;
+}
+
+if (getBuildConfiguration()['new-set-methods'] && getRealmConfiguration().enableNewSetMethods) {
+
+ assertEq(typeof Set.prototype.symmetricDifference, 'function');
+ assertEq(Set.prototype.symmetricDifference.length, 1);
+ assertEq(Set.prototype.symmetricDifference.name, 'symmetricDifference');
+
+ assertSetContainsExactOrderedItems(new Set([1, true, null]).symmetricDifference(new Set()), [1, true, null]);
+ assertSetContainsExactOrderedItems(new Set([1, true, null]).symmetricDifference([1, true, null]), []);
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).symmetricDifference([2, 3, 4]), [1, 4]);
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).symmetricDifference([4]), [1, 2, 3, 4]);
+ // Works when the argument is a custom iterable which follows the Symbol.iterator protocol
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).symmetricDifference(makeArrayIterator([3, 4])), [1, 2, 4]);
+ assertSetContainsExactOrderedItems(new Set(['a']).symmetricDifference('abc'), ['b', 'c']);
+
+ // Works when the `this` is a custom iterable which follows the Symbol.iterator protocol
+ assertSetContainsExactOrderedItems(Set.prototype.symmetricDifference.call(makeArrayIterator([1, 2, 3, 3, 2]), [4, 5, 6]), [1, 2, 3, 4, 5, 6]);
+
+ // Does not modify the original set object
+ const set = new Set([1]);
+ assertEq(set.symmetricDifference([2]) !== set, true);
+
+ // Argument must be iterable
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.symmetricDifference();
+ }, TypeError);
+ for (const arg of [null, {}, true, 1, undefined, NaN, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.symmetricDifference(arg);
+ }, TypeError);
+ }
+
+ // `this` must be an Object
+ for (const arg of [null, undefined, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ Set.prototype.symmetricDifference.call(arg, []);
+ }, TypeError);
+ }
+
+ // `this` must be iterable
+ assertThrowsInstanceOf(function () {
+ Set.prototype.symmetricDifference.call({}, []);
+ }, TypeError);
+} else {
+ assertEq(typeof Set.prototype.symmetricDifference, 'undefined');
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Set/union.js b/js/src/tests/non262/Set/union.js
new file mode 100644
index 0000000000..c7cf8026e5
--- /dev/null
+++ b/js/src/tests/non262/Set/union.js
@@ -0,0 +1,65 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+if (typeof getBuildConfiguration === "undefined") {
+ var getBuildConfiguration =
+ SpecialPowers.Cu.getJSTestingFunctions().getBuildConfiguration;
+}
+
+if (typeof getRealmConfiguration === "undefined") {
+ var getRealmConfiguration =
+ SpecialPowers.Cu.getJSTestingFunctions().getRealmConfiguration;
+}
+
+if (getBuildConfiguration()['new-set-methods'] && getRealmConfiguration().enableNewSetMethods) {
+
+ assertEq(typeof Set.prototype.union, 'function');
+ assertEq(Set.prototype.union.length, 1);
+ assertEq(Set.prototype.union.name, 'union');
+
+ assertSetContainsExactOrderedItems(new Set([1, true, null]).union(new Set()), [1, true, null]);
+ assertSetContainsExactOrderedItems(new Set([1, true, null]).union([1, true, null]), [1, true, null]);
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).union([2, 3, 4]), [1, 2, 3, 4]);
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).union([4]), [1, 2, 3, 4]);
+ // Works when the argument is a custom iterable which follows the Symbol.iterator protocol
+ assertSetContainsExactOrderedItems(new Set([1, 2, 3]).union(makeArrayIterator([3, 4])), [1, 2, 3, 4]);
+ assertSetContainsExactOrderedItems(new Set(['a']).union('abc'), ['a', 'b', 'c']);
+
+ // Works when the `this` is a custom iterable which follows the Symbol.iterator protocol
+ assertSetContainsExactOrderedItems(Set.prototype.union.call(makeArrayIterator([1, 2, 3, 3, 2]), [4, 5, 6]), [1, 2, 3, 4, 5, 6]);
+
+ // Does not modify the original set object
+ const set = new Set([1]);
+ assertEq(set.union([2]) !== set, true);
+
+ // Argument must be iterable
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.union();
+ }, TypeError);
+ for (const arg of [null, {}, true, 1, undefined, NaN, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ const set = new Set();
+ set.union(arg);
+ }, TypeError);
+ }
+
+ // `this` must be an Object
+ for (const arg of [null, undefined, Symbol()]) {
+ assertThrowsInstanceOf(function () {
+ Set.prototype.union.call(arg, []);
+ }, TypeError);
+ }
+
+ // `this` must be iterable
+ assertThrowsInstanceOf(function () {
+ Set.prototype.union.call({}, []);
+ }, TypeError);
+} else {
+ assertEq(typeof Set.prototype.union, 'undefined');
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);