1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 11:17:43 +00:00
serenity/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js
Linus Groh 283ee678f7 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.
2020-10-05 09:25:04 +02:00

28 lines
915 B
JavaScript

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