mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 17:37:33 +02:00
ECMAScript hoisting keeps the LAST function declaration with a given name. The Rust scope_collector and script GDI extraction implemented this with a single reverse scan that pushed first-seen entries, which left the resulting list in REVERSE source order. The C++ side then iterated `m_functions_to_initialize.in_reverse()` to undo that. Switch the Rust side to a two-pass forward scan that records the last position per name and emits entries in source order, and drop the matching `.in_reverse()` calls in Script.cpp and AbstractOperations.cpp. Same hoisting semantics; NewFunction emission and global property iteration order now follow the source. The HashMap that tracks last positions is keyed on `SharedUtf16String`, so each insert is a refcount bump on the AST's existing Rc instead of a deep `Vec<u16>` clone. Add bytecode tests at script and nested-function scope that exercise multiple declarations and a duplicate name to pin the new ordering.
16 lines
536 B
JavaScript
16 lines
536 B
JavaScript
// Same source-order check, but for FunctionDeclarations nested inside a
|
|
// function body. The scope_collector builds functions_to_initialize for
|
|
// these and previously emitted them in reverse source order.
|
|
|
|
function outer() {
|
|
function alpha() { return 1; }
|
|
function beta() { return 2; }
|
|
function dup() { return "first"; }
|
|
function gamma() { return 3; }
|
|
function dup() { return "second"; }
|
|
function delta() { return 4; }
|
|
return [alpha(), beta(), gamma(), delta(), dup()];
|
|
}
|
|
|
|
console.log(outer().join(","));
|