forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]`.
- Loading branch information
1 parent
1986693
commit 0f8c6dc
Showing
3 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Userland/Libraries/LibJS/Tests/assignment-evaluation-order.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]); | ||
}); |