summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Map/groupBy/invalid-iterable.js
blob: 5e0b9c8a353b817a2d1715259b2b448927106e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) 2023 Ecma International.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-map.groupby
description: Map.groupBy with a nullish Symbol.iterator throws
info: |
  Map.groupBy ( items, callbackfn )

  ...
  GroupBy ( items, callbackfn, coercion )

  4. Let iteratorRecord be ? GetIterator(items).

  ...
features: [array-grouping, Map]
---*/

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 () {
  Map.groupBy(makeIterable({}, undefined), throws);
}, 'undefined Symbol.iterator');

assert.throws(TypeError, function () {
  Map.groupBy(makeIterable({}, null), throws);
}, 'null Symbol.iterator');

reportCompare(0, 0);