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

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.
This commit is contained in:
Linus Groh 2020-05-12 21:19:48 +01:00 committed by Andreas Kling
parent 063228c02e
commit d69ed91790
3 changed files with 11 additions and 9 deletions

View file

@ -1,22 +1,17 @@
load("test-common.js");
try {
function foo() { }
assertThrowsError(() => {
512 = 256;
foo() = "foo";
}, {
error: ReferenceError,
message: "Invalid left-hand side in assignment"
});
assertThrowsError(() => {
512 = 256;
}, {
error: ReferenceError,
message: "Invalid left-hand side in assignment"
});
assertThrowsError(() => {
"hello world" = "another thing?";
(function () { })() = "foo";
}, {
error: ReferenceError,
message: "Invalid left-hand side in assignment"