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

LibJS: Validate all assignment expressions, not just "="

The check for invalid lhs and assignment to eval/arguments in strict
mode should happen for all kinds of assignment expressions, not just
AssignmentOp::Assignment.
This commit is contained in:
Linus Groh 2020-10-04 23:58:57 +01:00 committed by Andreas Kling
parent e80217a746
commit 283ee678f7
3 changed files with 56 additions and 39 deletions

View file

@ -10,3 +10,19 @@ test("assignment to inline function call", () => {
(function () {})() = "foo";
}).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
});
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();
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();
expect("1 = 1").not.toEval();
});