ladybird/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js
Linus Groh d69ed91790 LibJS: Check AssignmentExpression LHS in parser
There are many cases which shouldn't even parse, like

null = ...
true = ...
false = ...
123 = ...
"foo" = ...

However this *is* valid syntax:

foo() = ...

So we still have to keep the current code doing a runtime check if the
LHS value is a resolvable reference. I believe this was declared valid
syntax to *in theory* allow functions returning references - though in
practice that isn't a thing.

Fixes #2204.
2020-05-13 01:15:29 +02:00

23 lines
457 B
JavaScript

load("test-common.js");
try {
function foo() { }
assertThrowsError(() => {
foo() = "foo";
}, {
error: ReferenceError,
message: "Invalid left-hand side in assignment"
});
assertThrowsError(() => {
(function () { })() = "foo";
}, {
error: ReferenceError,
message: "Invalid left-hand side in assignment"
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}