mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-24 00:24:38 +00:00
LibJS/Bytecode: Only emit ResolveThisBinding once per basic block
Once executed, this instruction will always produce the same result in subsequent executions, so it's okay to cache it. Unfortunately it may throw, so we can't just hoist it to the top of every executable, since that would break observable execution order.
This commit is contained in:
@@ -798,4 +798,14 @@ void Generator::set_local_initialized(u32 local_index)
|
||||
m_initialized_locals.set(local_index);
|
||||
}
|
||||
|
||||
Operand Generator::get_this(Optional<Operand> preferred_dst)
|
||||
{
|
||||
if (m_current_basic_block->this_().has_value())
|
||||
return m_current_basic_block->this_().value();
|
||||
auto dst = preferred_dst.has_value() ? preferred_dst.value() : Operand(allocate_register());
|
||||
emit<Bytecode::Op::ResolveThisBinding>(dst);
|
||||
m_current_basic_block->set_this(dst);
|
||||
return dst;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user