Debian Codegraph @

js/src/tests/test262/built-ins/Object/groupBy/invalid-iterable.js

raw
1 // Copyright (c) 2023 Ecma International. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-object.groupby
6 description: Object.groupBy with a nullish Symbol.iterator throws
7 info: |
8 Object.groupBy ( items, callbackfn )
9
10 ...
11 GroupBy ( items, callbackfn, coercion )
12
13 4. Let iteratorRecord be ? GetIterator(items).
14
15 ...
16 features: [array-grouping]
17 ---*/
18
19 const throws = function () {
20 throw new Test262Error('callback function should not be called')
21 };
22
23 function makeIterable(obj, iteratorFn) {
24 obj[Symbol.iterator] = iteratorFn;
25 return obj;
26 }
27
28 assert.throws(TypeError, function () {
29 Object.groupBy(makeIterable({}, undefined), throws);
30 }, 'undefined Symbol.iterator');
31
32 assert.throws(TypeError, function () {
33 Object.groupBy(makeIterable({}, null), throws);
34 }, 'null Symbol.iterator');
35
36 reportCompare(0, 0);