mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 11:37:16 +02:00
LibJS: Avoid double construction in Array.fromAsync
This is a normative change in the array from async proposal, see: https://github.com/tc39/proposal-array-from-async/commit/49cfde2 It fixes a double construction when Array.fromAsync is given an array like object.
This commit is contained in:
Notes:
sideshowbarker
2024-07-16 23:03:06 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/9b884a9605 Pull-request: https://github.com/SerenityOS/serenity/pull/20819 Reviewed-by: https://github.com/trflynn89
@@ -3,13 +3,13 @@ test("length is 1", () => {
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
function checkResult(promise) {
|
||||
function checkResult(promise, type = Array) {
|
||||
expect(promise).toBeInstanceOf(Promise);
|
||||
let error = null;
|
||||
let passed = false;
|
||||
promise
|
||||
.then(value => {
|
||||
expect(value instanceof Array).toBeTrue();
|
||||
expect(value instanceof type).toBeTrue();
|
||||
expect(value[0]).toBe(0);
|
||||
expect(value[1]).toBe(2);
|
||||
expect(value[2]).toBe(4);
|
||||
@@ -57,4 +57,24 @@ describe("normal behavior", () => {
|
||||
);
|
||||
checkResult(promise);
|
||||
});
|
||||
|
||||
test("does not double construct from array like object", () => {
|
||||
let callCount = 0;
|
||||
|
||||
class TestArray {
|
||||
constructor() {
|
||||
callCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let promise = Array.fromAsync.call(TestArray, {
|
||||
length: 3,
|
||||
0: Promise.resolve(0),
|
||||
1: Promise.resolve(2),
|
||||
2: Promise.resolve(4),
|
||||
});
|
||||
|
||||
checkResult(promise, TestArray);
|
||||
expect(callCount).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user