mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 17:37:33 +02:00
The scope collector stored identifier_groups and variables in HashMaps and then sorted them alphabetically before assigning local register indices. The sorts existed only because HashMap iteration order is non-deterministic; alphabetical was a stable choice for comparing bytecode against the now-removed C++ port. Switch both maps to indexmap::IndexMap so iteration follows the order of first reference (= source order), and drop the alphabetical sorts. Local indices now reflect declaration order, which matches what shows up in bytecode dumps and is easier to read alongside the source. Add a focused bytecode test using zebra/yak/aardvark to pin the new allocation order; existing tests using let/var declarations have their local indices renumbered to match.
13 lines
366 B
JavaScript
13 lines
366 B
JavaScript
// Local variables should be allocated indices in source order, not in
|
|
// alphabetical order. With names that sort in reverse alphabetical
|
|
// order, the difference is visible in the bytecode dump (~0 first, etc).
|
|
|
|
function source_order_locals() {
|
|
let zebra = 1;
|
|
let yak = 2;
|
|
let aardvark = 3;
|
|
return zebra + yak + aardvark;
|
|
}
|
|
|
|
source_order_locals();
|