mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
LibJS: Avoid double construction in Array.fromAsync
This is a normative change in the array from async proposal, see:
49cfde2
It fixes a double construction when Array.fromAsync is given an array
like object.
This commit is contained in:
parent
ae3958f640
commit
9b884a9605
2 changed files with 43 additions and 21 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue