mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
LibJS/Bytecode: Always evaluate LHS first in assignment expressions
This fixes an issue where expressions like `a[i] = a[++i]` could evaluate `++i` before `a[i]`.
This commit is contained in:
parent
1986693edc
commit
0f8c6dc9ad
3 changed files with 27 additions and 2 deletions
|
@ -0,0 +1,21 @@
|
|||
test("Assignment should always evaluate LHS first", () => {
|
||||
function go(a) {
|
||||
let i = 0;
|
||||
a[i] = a[++i];
|
||||
}
|
||||
|
||||
let a = [1, 2, 3];
|
||||
go(a);
|
||||
expect(a).toEqual([2, 2, 3]);
|
||||
});
|
||||
|
||||
test("Binary assignment should always evaluate LHS first", () => {
|
||||
function go(a) {
|
||||
let i = 0;
|
||||
a[i] |= a[++i];
|
||||
}
|
||||
|
||||
let a = [1, 2];
|
||||
go(a);
|
||||
expect(a).toEqual([3, 2]);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue