-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compilation of named variables in loop headers
We must open new scopes for loop headers. Otherwise we might try to reuse a named variable created in the loop header in its body, which is invalid. See the added tests for examples. Change-Id: Ib2df5df6b28ba28432706c69630eef22452fb858 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/7934191 Reviewed-by: Carl Smith <[email protected]> Commit-Queue: Carl Smith <[email protected]> Auto-Submit: Samuel Groß <[email protected]>
- Loading branch information
Samuel Groß
authored and
V8-internal LUCI CQ
committed
Jan 7, 2025
1 parent
78e6dc7
commit 50d2fcc
Showing
3 changed files
with
46 additions
and
15 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
38 changes: 38 additions & 0 deletions
38
Tests/FuzzilliTests/CompilerTests/named_variables_scoping.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,38 @@ | ||
if (typeof output === 'undefined') output = console.log; | ||
|
||
// Test to ensure that multiple uses of the same named variable compile correctly. | ||
|
||
{ | ||
// This named variable will go out of scope, so subsequent uses require creating a new one (with the same name). | ||
global = { start: 0, end: 3, step: 1, value: 42 }; | ||
} | ||
|
||
{ | ||
if (global.value) { | ||
output("inside if with global value", global.value); | ||
} else { | ||
output("inside else with global value", global.value); | ||
} | ||
} | ||
|
||
{ | ||
for (let i = global.start; i < global.end; i += global.step) { | ||
output("inside for loop body with global value", global.value); | ||
} | ||
} | ||
|
||
{ | ||
let i = 0; | ||
while (i < global.end) { | ||
i += global.step; | ||
output("inside while loop body with global value", global.value); | ||
} | ||
} | ||
|
||
{ | ||
let i = 0; | ||
do { | ||
i += global.step; | ||
output("inside do-while loop body with global value", global.value); | ||
} while (i < global.end); | ||
} |