1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00

LibJS: Allow CallExpression as left hand side of for-of/for-in loops

Although this will fail with a ReferenceError it should pass the parser
and only fail if actually assigned to.
This commit is contained in:
davidot 2022-02-17 01:23:10 +01:00 committed by Linus Groh
parent ce057115fc
commit 65bebb5241
4 changed files with 63 additions and 10 deletions

View file

@ -67,8 +67,35 @@ test("allow binding patterns", () => {
expect(counter).toBe(3);
});
test("allow member expression as variable", () => {
const f = {};
for (f.a in "abc");
expect(f.a).toBe("2");
describe("special left hand sides", () => {
test("allow member expression as variable", () => {
const f = {};
for (f.a in "abc");
expect(f.a).toBe("2");
});
test("allow member expression of function call", () => {
const b = {};
function f() {
return b;
}
for (f().a in "abc");
expect(f().a).toBe("2");
expect(b.a).toBe("2");
});
test("call function is allowed in parsing but fails in runtime", () => {
function f() {
expect().fail();
}
// Does not fail since it does not iterate
expect("for (f() in []);").toEvalTo(undefined);
expect(() => {
eval("for (f() in [0]) { expect().fail() }");
}).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
});
});