mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-20 15:27:32 +09:00
Refactor ConsoleAPIStorage event handling and add tests for ring buffer behavior
This commit is contained in:
parent
be7e2afbcf
commit
810e55b503
6 changed files with 137 additions and 14 deletions
|
|
@ -81,9 +81,10 @@ function MapGroupBy(items, callbackfn) {
|
|||
var key = callContentFunction(callbackfn, undefined, value, k);
|
||||
|
||||
// Steps 6.c-d.
|
||||
var elements;
|
||||
if (callFunction(std_Map_has, groups, key)) {
|
||||
elements = callFunction(std_Map_get, groups, key);
|
||||
// Group values are always arrays, so undefined also tells us whether
|
||||
// this is a new key without a second hash-table lookup.
|
||||
var elements = callFunction(std_Map_get, groups, key);
|
||||
if (elements !== undefined) {
|
||||
callFunction(std_Array_push, elements, value);
|
||||
} else {
|
||||
elements = [value];
|
||||
|
|
|
|||
47
js/src/jit-test/tests/collections/Map-groupBy-lookup.js
Normal file
47
js/src/jit-test/tests/collections/Map-groupBy-lookup.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// Repeated keys must reuse their group, including SameValueZero keys.
|
||||
var objectKey = {};
|
||||
var symbolKey = Symbol();
|
||||
var keys = [undefined, null, false, 0, -0, NaN, "key", objectKey, symbolKey];
|
||||
for (var iteration = 0; iteration < 100; iteration++) {
|
||||
var input = [];
|
||||
for (var repeat = 0; repeat < 4; repeat++) {
|
||||
for (var key of keys)
|
||||
input.push(key);
|
||||
}
|
||||
var calls = 0;
|
||||
var groups = Map.groupBy(input, function(value, index) {
|
||||
assertEq(index, calls++);
|
||||
return value;
|
||||
});
|
||||
assertEq(calls, input.length);
|
||||
assertEq(groups.size, 8);
|
||||
for (var key of keys)
|
||||
assertEq(groups.get(key).length, key === 0 ? 8 : 4);
|
||||
assertEq(groups.get(objectKey)[0], objectKey);
|
||||
assertEq(groups.get(symbolKey)[0], symbolKey);
|
||||
assertEq(groups.get(undefined)[0], undefined);
|
||||
var order = Array.from(groups.keys());
|
||||
assertEq(order[0], undefined);
|
||||
assertEq(order[3], 0);
|
||||
assertEq(order[4], NaN);
|
||||
assertEq(order[7], symbolKey);
|
||||
}
|
||||
|
||||
// A throwing callback must still close the input iterator.
|
||||
var closed = false;
|
||||
function* values() {
|
||||
try {
|
||||
yield 1;
|
||||
yield 2;
|
||||
} finally {
|
||||
closed = true;
|
||||
}
|
||||
}
|
||||
var sentinel = {};
|
||||
try {
|
||||
Map.groupBy(values(), function() { throw sentinel; });
|
||||
throw new Error("callback did not throw");
|
||||
} catch (error) {
|
||||
assertEq(error, sentinel);
|
||||
}
|
||||
assertEq(closed, true);
|
||||
Loading…
Add table
Add a link
Reference in a new issue