From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/tests/non262/Set/browser.js | 0 js/src/tests/non262/Set/difference.js | 63 ++++++++++++++++++++++ js/src/tests/non262/Set/intersection.js | 63 ++++++++++++++++++++++ js/src/tests/non262/Set/is-disjoint-from.js | 63 ++++++++++++++++++++++ js/src/tests/non262/Set/is-subset-of.js | 69 +++++++++++++++++++++++++ js/src/tests/non262/Set/is-superset-of.js | 63 ++++++++++++++++++++++ js/src/tests/non262/Set/shell.js | 45 ++++++++++++++++ js/src/tests/non262/Set/symmetric-difference.js | 63 ++++++++++++++++++++++ js/src/tests/non262/Set/union.js | 65 +++++++++++++++++++++++ 9 files changed, 494 insertions(+) create mode 100644 js/src/tests/non262/Set/browser.js create mode 100644 js/src/tests/non262/Set/difference.js create mode 100644 js/src/tests/non262/Set/intersection.js create mode 100644 js/src/tests/non262/Set/is-disjoint-from.js create mode 100644 js/src/tests/non262/Set/is-subset-of.js create mode 100644 js/src/tests/non262/Set/is-superset-of.js create mode 100644 js/src/tests/non262/Set/shell.js create mode 100644 js/src/tests/non262/Set/symmetric-difference.js create mode 100644 js/src/tests/non262/Set/union.js (limited to 'js/src/tests/non262/Set') 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 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); -- cgit v1.2.3