Files
ladybird/Tests/LibJS/Bytecode/expected/switch-scoping.txt
Andreas Kling 6b0003b057 LibJS: Pre-create SharedFunctionInstanceData in NewFunction
Replace the FunctionNode const& stored on the NewFunction bytecode
instruction with an index into a table of pre-created
SharedFunctionInstanceData objects on the Executable.

During bytecode compilation, we now eagerly create
SharedFunctionInstanceData for each function that will be
instantiated by NewFunction, and store it on both the FunctionNode
(for caching) and the Executable (for GC tracing).

At runtime, NewFunction simply looks up the SharedFunctionInstanceData
by index and calls create_from_function_data() directly, bypassing
the AST entirely. This removes one of the main reasons the AST had
to stay alive after compilation.

The instantiate_ordinary_function_expression() helper in
Interpreter.cpp is removed as its non-trivial code path (creating a
scope for named function expressions) was dead code -- it was only
called when !has_name(), so the has_own_name branch never executed.
2026-02-11 23:57:41 +01:00

48 lines
2.3 KiB
Plaintext

JS bytecode executable ""
[ 0] 0: GetLexicalEnvironment dst:reg4
[ 8] GetGlobal dst:reg6, identifier:console
[ 18] GetById dst:reg7, base:reg6, property:log, base_identifier:console
[ 30] GetGlobal dst:reg9, identifier:switchWithBlockDecl
[ 40] Call dst:reg8, callee:reg9, this_value:Undefined, switchWithBlockDecl, arguments:[Int32(1)]
[ 68] Call dst:reg5, callee:reg7, this_value:reg6, console.log, arguments:[reg8]
[ 90] GetGlobal dst:reg6, identifier:console
[ a0] GetById dst:reg8, base:reg6, property:log, base_identifier:console
[ b8] GetGlobal dst:reg10, identifier:switchWithBlockDecl
[ c8] Call dst:reg9, callee:reg10, this_value:Undefined, switchWithBlockDecl, arguments:[Int32(2)]
[ f0] Call dst:reg7, callee:reg8, this_value:reg6, console.log, arguments:[reg9]
[ 118] End value:reg7
JS bytecode executable "switchWithBlockDecl"
[ 0] 0: GetLexicalEnvironment dst:reg4
[ 8] Mov dst:result~0, src:Undefined
[ 18] CreateLexicalEnvironment dst:reg5, parent:reg4, capacity:0
[ 28] CreateMutableBinding environment:reg5, identifier:a, can_be_deleted:false
[ 38] CreateMutableBinding environment:reg5, identifier:b, can_be_deleted:false
[ 48] 1: JumpStrictlyEquals lhs:Int32(1), rhs:arg0, true_target:@80, false_target:@60
[ 60] 2: JumpStrictlyEquals lhs:Int32(2), rhs:arg0, true_target:@c8, false_target:@78
[ 78] 3: Jump target:@108
[ 80] 4: InitializeLexicalBinding identifier:a, src:String("one")
[ 98] NewFunction dst:reg6, shared_function_data_index:0, lhs_name:result
[ b0] Mov dst:result~0, src:reg6
[ c0] Jump target:@108
[ c8] 5: InitializeLexicalBinding identifier:b, src:String("two")
[ e0] NewFunction dst:reg6, shared_function_data_index:1, lhs_name:result
[ f8] Mov dst:result~0, src:reg6
[ 108] 6: SetLexicalEnvironment environment:reg4
[ 110] Mov dst:reg6, src:result~0
[ 120] Call dst:reg5, callee:reg6, this_value:Undefined, result
[ 140] Return value:reg5
JS bytecode executable "result"
[ 0] 0: GetLexicalEnvironment dst:reg4
[ 8] GetBinding dst:reg5, identifier:a
[ 20] Return value:reg5
JS bytecode executable "result"
[ 0] 0: GetLexicalEnvironment dst:reg4
[ 8] GetBinding dst:reg5, identifier:b
[ 20] Return value:reg5
"one"
"two"