diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Object/groupBy | |
parent | Initial commit. (diff) | |
download | firefox-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 'js/src/tests/test262/built-ins/Object/groupBy')
15 files changed, 400 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Object/groupBy/browser.js b/js/src/tests/test262/built-ins/Object/groupBy/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/browser.js diff --git a/js/src/tests/test262/built-ins/Object/groupBy/callback-arg.js b/js/src/tests/test262/built-ins/Object/groupBy/callback-arg.js new file mode 100644 index 0000000000..945639607b --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/callback-arg.js @@ -0,0 +1,34 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy calls function with correct arguments +info: | + Object.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + + e. Let key be Completion(Call(callbackfn, undefined, « value, 𝔽(k) »)). + ... +features: [array-grouping] +---*/ + + +const arr = [-0, 0, 1, 2, 3]; + +let calls = 0; + +Object.groupBy(arr, function (n, i) { + calls++; + assert.sameValue(n, arr[i], "selected element aligns with index"); + assert.sameValue(arguments.length, 2, "only two arguments are passed"); + return null; +}); + +assert.sameValue(calls, 5, 'called for all 5 elements'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/callback-throws.js b/js/src/tests/test262/built-ins/Object/groupBy/callback-throws.js new file mode 100644 index 0000000000..3aa4030f17 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/callback-throws.js @@ -0,0 +1,27 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy throws when callback throws +info: | + Object.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + e. Let key be Completion(Call(callbackfn, undefined, « value, 𝔽(k) »)). + f. IfAbruptCloseIterator(key, iteratorRecord). + ... +features: [array-grouping] +---*/ + +assert.throws(Test262Error, function() { + const array = [1]; + Object.groupBy(array, function() { + throw new Test262Error('throw in callback'); + }) +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/emptyList.js b/js/src/tests/test262/built-ins/Object/groupBy/emptyList.js new file mode 100644 index 0000000000..74f2f2d18c --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/emptyList.js @@ -0,0 +1,29 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Callback is not called and object is not populated if the iterable is empty +info: | + Object.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + c. If next is false, then + i. Return groups. + ... +features: [array-grouping] +---*/ + +const original = []; + +const obj = Object.groupBy(original, function () { + throw new Test262Error('callback function should not be called') +}); + +assert.notSameValue(original, obj, 'Object.groupBy returns an object'); +assert.sameValue(Object.keys(obj).length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/evenOdd.js b/js/src/tests/test262/built-ins/Object/groupBy/evenOdd.js new file mode 100644 index 0000000000..b28522b1cb --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/evenOdd.js @@ -0,0 +1,24 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy populates object with correct keys and values +info: | + Object.groupBy ( items, callbackfn ) + ... +includes: [compareArray.js] +features: [array-grouping] +---*/ + +const array = [1, 2, 3]; + +const obj = Object.groupBy(array, function (i) { + return i % 2 === 0 ? 'even' : 'odd'; +}); + +assert.compareArray(Object.keys(obj), ['odd', 'even']); +assert.compareArray(obj['even'], [2]); +assert.compareArray(obj['odd'], [1, 3]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/groupLength.js b/js/src/tests/test262/built-ins/Object/groupBy/groupLength.js new file mode 100644 index 0000000000..2ab88b9a0d --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/groupLength.js @@ -0,0 +1,29 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Callback can return numbers that are converted to property keys +info: | + Object.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + c. If next is false, then + i. Return groups. + ... +includes: [compareArray.js] +features: [array-grouping] +---*/ + +const arr = ['hello', 'test', 'world']; + +const obj = Object.groupBy(arr, function (i) { return i.length; }); + +assert.compareArray(Object.keys(obj), ['4', '5']); +assert.compareArray(obj['5'], ['hello', 'world']); +assert.compareArray(obj['4'], ['test']); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/invalid-callback.js b/js/src/tests/test262/built-ins/Object/groupBy/invalid-callback.js new file mode 100644 index 0000000000..a8b54d33bd --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/invalid-callback.js @@ -0,0 +1,31 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy called with non-callable throws TypeError +info: | + Object.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 2. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +features: [array-grouping] +---*/ + + +assert.throws(TypeError, function() { + Object.groupBy([], null) +}, "null callback throws TypeError"); + +assert.throws(TypeError, function() { + Object.groupBy([], undefined) +}, "undefined callback throws TypeError"); + +assert.throws(TypeError, function() { + Object.groupBy([], {}) +}, "object callback throws TypeError"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/invalid-iterable.js b/js/src/tests/test262/built-ins/Object/groupBy/invalid-iterable.js new file mode 100644 index 0000000000..b5839b7f92 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/invalid-iterable.js @@ -0,0 +1,36 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy with a nullish Symbol.iterator throws +info: | + Object.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 4. Let iteratorRecord be ? GetIterator(items). + + ... +features: [array-grouping] +---*/ + +const throws = function () { + throw new Test262Error('callback function should not be called') +}; + +function makeIterable(obj, iteratorFn) { + obj[Symbol.iterator] = iteratorFn; + return obj; +} + +assert.throws(TypeError, function () { + Object.groupBy(makeIterable({}, undefined), throws); +}, 'undefined Symbol.iterator'); + +assert.throws(TypeError, function () { + Object.groupBy(makeIterable({}, null), throws); +}, 'null Symbol.iterator'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/invalid-property-key.js b/js/src/tests/test262/built-ins/Object/groupBy/invalid-property-key.js new file mode 100644 index 0000000000..badc3b9137 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/invalid-property-key.js @@ -0,0 +1,33 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy errors when callback return value cannot be converted to a property key. +info: | + Object.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + g. If coercion is property, then + i. Set key to Completion(ToPropertyKey(key)). + ii. IfAbruptCloseIterator(key, iteratorRecord). + + ... +features: [array-grouping] +---*/ + +assert.throws(Test262Error, function () { + const array = [1]; + Object.groupBy(array, function () { + return { + toString() { + throw new Test262Error('not a property key'); + } + }; + }) +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/iterator-next-throws.js b/js/src/tests/test262/built-ins/Object/groupBy/iterator-next-throws.js new file mode 100644 index 0000000000..01d981a0ab --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/iterator-next-throws.js @@ -0,0 +1,36 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy throws when iterator next throws +info: | + Object.groupBy ( items, callbackfn ) + + ... + + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + b. Let next be ? IteratorStep(iteratorRecord). + + ... +features: [array-grouping, Symbol.iterator] +---*/ + +const throwingIterator = { + [Symbol.iterator]: function () { + return this; + }, + next: function next() { + throw new Test262Error('next() method was called'); + } +}; + +assert.throws(Test262Error, function () { + Object.groupBy(throwingIterator, function () { + return 'key'; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/length.js b/js/src/tests/test262/built-ins/Object/groupBy/length.js new file mode 100644 index 0000000000..311ba7d028 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/length.js @@ -0,0 +1,27 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy property length descriptor +info: | + Object.groupBy ( items, callbackfn ) + + ... + + 17 ECMAScript Standard Built-in Objects + + ... + +includes: [propertyHelper.js] +features: [array-grouping] +---*/ + +verifyProperty(Object.groupBy, "length", { + value: 2, + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/name.js b/js/src/tests/test262/built-ins/Object/groupBy/name.js new file mode 100644 index 0000000000..6ccfac61d1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/name.js @@ -0,0 +1,27 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy property name descriptor +info: | + Object.groupBy ( items, callbackfn ) + + ... + + 17 ECMAScript Standard Built-in Objects + + ... + +includes: [propertyHelper.js] +features: [array-grouping] +---*/ + +verifyProperty(Object.groupBy, "name", { + value: "groupBy", + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/null-prototype.js b/js/src/tests/test262/built-ins/Object/groupBy/null-prototype.js new file mode 100644 index 0000000000..d524ef734a --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/null-prototype.js @@ -0,0 +1,29 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy returns a null prototype object +info: | + Object.groupBy ( items, callbackfn ) + + ... + + 2. Let obj be OrdinaryObjectCreate(null). + ... + 4. Return obj. + + ... +features: [array-grouping] +---*/ + +const array = [1, 2, 3]; + +const obj = Object.groupBy(array, function (i) { + return i % 2 === 0 ? 'even' : 'odd'; +}); + +assert.sameValue(Object.getPrototypeOf(obj), null); +assert.sameValue(obj.hasOwnProperty, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/groupBy/shell.js b/js/src/tests/test262/built-ins/Object/groupBy/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/shell.js diff --git a/js/src/tests/test262/built-ins/Object/groupBy/toPropertyKey.js b/js/src/tests/test262/built-ins/Object/groupBy/toPropertyKey.js new file mode 100644 index 0000000000..e24e36b98a --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/groupBy/toPropertyKey.js @@ -0,0 +1,38 @@ +// Copyright (c) 2023 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.groupby +description: Object.groupBy coerces return value with ToPropertyKey +info: | + Object.groupBy ( items, callbackfn ) + + ... + + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + g. If coercion is property, then + i. Set key to Completion(ToPropertyKey(key)). + ii. IfAbruptCloseIterator(key, iteratorRecord). + + ... +includes: [compareArray.js] +features: [array-grouping] +---*/ + +let calls = 0; +const stringable = { + toString: function toString() { + return 1; + } +} + +const array = [1, '1', stringable]; + +const obj = Object.groupBy(array, function (v) { return v; }); + +assert.compareArray(Object.keys(obj), ['1']); +assert.compareArray(obj['1'], [1, '1', stringable]); + +reportCompare(0, 0); |