mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-04 09:22:53 +00:00
LibJS/Bytecode: Don't generate ResolveThisBinding if not needed
Functions that don't have a FunctionEnvironment will get their `this` value from the ExecutionContext. This patch stops generating ResolveThisBinding instructions at all for functions like that, and instead pre-populates the `this` register when entering a new bytecode executable.
This commit is contained in:
parent
9d22db2802
commit
e6b1e54c44
Notes:
sideshowbarker
2024-07-17 06:33:00 +09:00
Author: https://github.com/awesomekling
Commit: e6b1e54c44
Pull-request: https://github.com/SerenityOS/serenity/pull/24504
2 changed files with 8 additions and 0 deletions
|
@ -1087,6 +1087,13 @@ ScopedOperand Generator::get_this(Optional<ScopedOperand> preferred_dst)
|
||||||
m_current_basic_block->set_has_resolved_this();
|
m_current_basic_block->set_has_resolved_this();
|
||||||
return this_value();
|
return this_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OPTIMIZATION: If we're compiling a function that doesn't allocate a FunctionEnvironment,
|
||||||
|
// it will always have the same `this` value as the outer function,
|
||||||
|
// and so the `this` value is already in the `this` register!
|
||||||
|
if (m_function && !m_function->allocates_function_environment())
|
||||||
|
return this_value();
|
||||||
|
|
||||||
auto dst = preferred_dst.has_value() ? preferred_dst.value() : allocate_register();
|
auto dst = preferred_dst.has_value() ? preferred_dst.value() : allocate_register();
|
||||||
emit<Bytecode::Op::ResolveThisBinding>();
|
emit<Bytecode::Op::ResolveThisBinding>();
|
||||||
m_current_basic_block->set_has_resolved_this();
|
m_current_basic_block->set_has_resolved_this();
|
||||||
|
|
|
@ -718,6 +718,7 @@ Interpreter::ResultAndReturnRegister Interpreter::run_executable(Executable& exe
|
||||||
|
|
||||||
reg(Register::accumulator()) = initial_accumulator_value;
|
reg(Register::accumulator()) = initial_accumulator_value;
|
||||||
reg(Register::return_value()) = {};
|
reg(Register::return_value()) = {};
|
||||||
|
reg(Register::this_value()) = running_execution_context.this_value;
|
||||||
|
|
||||||
running_execution_context.executable = &executable;
|
running_execution_context.executable = &executable;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue