-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce51121
commit 9592077
Showing
28 changed files
with
628 additions
and
239 deletions.
There are no files selected for viewing
35 changes: 0 additions & 35 deletions
35
test/built-ins/Array/prototype/groupByToMap/callback-arg.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
test/built-ins/Array/prototype/groupByToMap/groupByLength.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
test/built-ins/Array/prototype/groupByToMap/negativeZero.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2021 Ecma International. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-array.prototype.groupToMap | ||
description: Array.prototype.groupToMap iterates array-like up to length | ||
info: | | ||
22.1.3.15 Array.prototype.groupToMap ( callbackfn [ , thisArg ] ) | ||
... | ||
2. Let len be ? LengthOfArrayLike(O). | ||
... | ||
4. Let k be 0. | ||
... | ||
6. Repeat, while k < len | ||
... | ||
includes: [compareArray.js] | ||
features: [array-grouping] | ||
---*/ | ||
|
||
const arrayLike = {0: 1, 1: 2, 2: 3, 3: 4, length: 3 }; | ||
|
||
let calls = 0; | ||
|
||
const map = Array.prototype.groupToMap.call(arrayLike, i => { | ||
calls++; | ||
return i % 2 === 0 ? 'even' : 'odd'; | ||
}); | ||
|
||
assert.sameValue(calls, 3, 'only calls length times'); | ||
assert.compareArray(Array.from(map.keys()), ['odd', 'even']); | ||
assert.compareArray(map.get('even'), [2]); | ||
assert.compareArray(map.get('odd'), [1, 3]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2021 Ecma International. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-array.prototype.groupToMap | ||
description: Array.prototype.groupToMap calls function with correct arguments | ||
info: | | ||
22.1.3.15 Array.prototype.groupToMap ( callbackfn [ , thisArg ] ) | ||
... | ||
6. Repeat, while k < len | ||
a. Let Pk be ! ToString(𝔽(k)). | ||
b. Let kValue be ? Get(O, Pk). | ||
c. Let key be ? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »). | ||
e. Perform ! AddValueToKeyedGroup(groups, key, kValue). | ||
... | ||
features: [array-grouping] | ||
---*/ | ||
|
||
|
||
const arr = [-0, 0, 1, 2, 3]; | ||
|
||
let calls = 0; | ||
|
||
arr.groupToMap((n, i, testArr) => { | ||
calls++; | ||
assert.sameValue(n, arr[i], "selected element aligns with index"); | ||
assert.sameValue(testArr, arr, "original array is passed as final argument"); | ||
return null; | ||
}); | ||
|
||
assert.sameValue(calls, 5, 'called for all 5 elements'); |
24 changes: 24 additions & 0 deletions
24
test/built-ins/Array/prototype/groupToMap/callback-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2021 Ecma International. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-array.prototype.groupToMap | ||
description: Array.prototype.groupToMap errors when return value cannot be converted to a property key. | ||
info: | | ||
22.1.3.15 Array.prototype.groupToMap ( callbackfn [ , thisArg ] ) | ||
... | ||
6. Repeat, while k < len | ||
c. Let propertyKey be ? ToPropertyKey(? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »)). | ||
... | ||
features: [array-grouping] | ||
---*/ | ||
|
||
assert.throws(Test262Error, function() { | ||
const array = [1]; | ||
array.groupToMap(function() { | ||
throw new Test262Error('throw in callback'); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2021 Ecma International. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-array.prototype.groupToMap | ||
description: Callback is not called and object is not populated if the array is empty | ||
info: | | ||
22.1.3.15 Array.prototype.groupToMap ( callbackfn [ , thisArg ] ) | ||
... | ||
8. For each Record { [[Key]], [[Elements]] } g of groups, do | ||
a. Let elements be ! CreateArrayFromList(g.[[Elements]]). | ||
b. Perform ! CreateDataPropertyOrThrow(map, g.[[Key]], elements). | ||
... | ||
features: [array-grouping] | ||
---*/ | ||
|
||
const original = []; | ||
|
||
const map = original.groupToMap(() => { | ||
throw new Test262Error('callback function should not be called') | ||
}); | ||
|
||
assert.notSameValue(original, map, 'groupToMap returns a map'); | ||
assert.sameValue(map.size, 0); |
Oops, something went wrong.