Debian Codegraph @

js/src/tests/test262/built-ins/Object/groupBy/callback-arg.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 calls function with correct arguments
7 info: |
8 Object.groupBy ( items, callbackfn )
9
10 ...
11 GroupBy ( items, callbackfn, coercion )
12
13 6. Repeat,
14
15 e. Let key be Completion(Call(callbackfn, undefined, « value, 𝔽(k) »)).
16 ...
17 features: [array-grouping]
18 ---*/
19
20
21 const arr = [-0, 0, 1, 2, 3];
22
23 let calls = 0;
24
25 Object.groupBy(arr, function (n, i) {
26 calls++;
27 assert.sameValue(n, arr[i], "selected element aligns with index");
28 assert.sameValue(arguments.length, 2, "only two arguments are passed");
29 return null;
30 });
31
32 assert.sameValue(calls, 5, 'called for all 5 elements');
33
34 reportCompare(0, 0);