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

LibJS: Allow CallExpressions as lhs of assignments in most cases

Although not quite like the spec says the web reality is that a lhs
target of CallExpression should not give a SyntaxError but only a
ReferenceError once executed.
This commit is contained in:
davidot 2022-11-30 01:47:25 +01:00 committed by Andreas Kling
parent 8319d7ac06
commit d218a68296
2 changed files with 41 additions and 16 deletions

View file

@ -6,7 +6,7 @@ test("assignment to function call", () => {
});
test("assignment to function call in strict mode", () => {
expect("'use strict'; foo() = 'foo'").not.toEval();
expect("'use strict'; foo() = 'foo'").toEval();
});
test("assignment to inline function call", () => {
@ -29,4 +29,27 @@ test("assignment to invalid LHS is syntax error", () => {
expect("1 >>= 1").not.toEval();
expect("1 >>>= 1").not.toEval();
expect("1 = 1").not.toEval();
expect("1 &&= 1").not.toEval();
expect("1 ||= 1").not.toEval();
expect("1 ??= 1").not.toEval();
});
test("assignment to call LHS is only syntax error for new operators", () => {
expect("f() += 1").toEval();
expect("f() -= 1").toEval();
expect("f() *= 1").toEval();
expect("f() /= 1").toEval();
expect("f() %= 1").toEval();
expect("f() **= 1").toEval();
expect("f() &= 1").toEval();
expect("f() |= 1").toEval();
expect("f() ^= 1").toEval();
expect("f() <<= 1").toEval();
expect("f() >>= 1").toEval();
expect("f() >>>= 1").toEval();
expect("f() = 1").toEval();
expect("f() &&= 1").not.toEval();
expect("f() ||= 1").not.toEval();
expect("f() ??= 1").not.toEval();
});