toPropertyKey.js (871B)
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 coerces return value with ToPropertyKey 7 info: | 8 Object.groupBy ( items, callbackfn ) 9 10 ... 11 12 GroupBy ( items, callbackfn, coercion ) 13 14 6. Repeat, 15 g. If coercion is property, then 16 i. Set key to Completion(ToPropertyKey(key)). 17 ii. IfAbruptCloseIterator(key, iteratorRecord). 18 19 ... 20 includes: [compareArray.js] 21 features: [array-grouping] 22 ---*/ 23 24 let calls = 0; 25 const stringable = { 26 toString: function toString() { 27 return 1; 28 } 29 } 30 31 const array = [1, '1', stringable]; 32 33 const obj = Object.groupBy(array, function (v) { return v; }); 34 35 assert.compareArray(Object.keys(obj), ['1']); 36 assert.compareArray(obj['1'], [1, '1', stringable]); 37 38 reportCompare(0, 0);