1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

LibJS: Bring ForIn body evaluation closer to the specification

This fixes 2 bugs in our current implementation:
 * Properties deleted during iteration were still being iterated
 * Properties with the same name in both the object and it's prototype
   were iterated twice
This commit is contained in:
Idan Horowitz 2022-03-29 00:18:39 +03:00
parent 9cfbbfd8d8
commit 02e97b3313
2 changed files with 40 additions and 20 deletions

View file

@ -99,3 +99,24 @@ describe("special left hand sides", () => {
}).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
});
});
test("remove properties while iterating", () => {
const from = [1, 2, 3];
const to = [];
for (const prop in from) {
to.push(prop);
from.pop();
}
expect(to).toEqual(["0", "1"]);
});
test("duplicated properties in prototype", () => {
const object = { a: 1 };
const proto = { a: 2 };
Object.setPrototypeOf(object, proto);
const a = [];
for (const prop in object) {
a.push(prop);
}
expect(a).toEqual(["a"]);
});