mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 13:45:06 +00:00
LibJS: Evaluate AssignmentExpression LHS before RHS according to the spec
Fixes #3689.
This commit is contained in:
parent
7fd4646acb
commit
2d4cd5b49b
2 changed files with 63 additions and 39 deletions
|
@ -53,3 +53,38 @@ test("basic functionality", () => {
|
|||
expect((x >>>= 2)).toBe(2);
|
||||
expect(x).toBe(2);
|
||||
});
|
||||
|
||||
test("evaluation order", () => {
|
||||
for (const op of [
|
||||
"=",
|
||||
"+=",
|
||||
"-=",
|
||||
"*=",
|
||||
"/=",
|
||||
"%=",
|
||||
"**=",
|
||||
"&=",
|
||||
"|=",
|
||||
"^=",
|
||||
"<<=",
|
||||
">>=",
|
||||
">>>=",
|
||||
]) {
|
||||
var a = [];
|
||||
function b() {
|
||||
b.hasBeenCalled = true;
|
||||
throw Error();
|
||||
}
|
||||
function c() {
|
||||
c.hasBeenCalled = true;
|
||||
throw Error();
|
||||
}
|
||||
b.hasBeenCalled = false;
|
||||
c.hasBeenCalled = false;
|
||||
expect(() => {
|
||||
new Function(`a[b()] ${op} c()`)();
|
||||
}).toThrow(Error);
|
||||
expect(b.hasBeenCalled).toBeTrue();
|
||||
expect(c.hasBeenCalled).toBeFalse();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue