mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 20:15:07 +00:00
LibJS/Bytecode: Move environment coordinate caches to Executable
Moving them out of the respective instructions allows the bytecode stream to be immutable.
This commit is contained in:
parent
5c7e5cc738
commit
2e23f00a2f
7 changed files with 31 additions and 20 deletions
|
@ -812,23 +812,24 @@ ThrowCompletionOr<void> GetVariable::execute_impl(Bytecode::Interpreter& interpr
|
|||
{
|
||||
auto& vm = interpreter.vm();
|
||||
|
||||
if (m_cached_environment_coordinate.has_value()) {
|
||||
auto& cached_environment_coordinate = interpreter.current_executable().environment_variable_caches[m_cache_index];
|
||||
if (cached_environment_coordinate.has_value()) {
|
||||
auto environment = vm.running_execution_context().lexical_environment;
|
||||
for (size_t i = 0; i < m_cached_environment_coordinate->hops; ++i)
|
||||
for (size_t i = 0; i < cached_environment_coordinate->hops; ++i)
|
||||
environment = environment->outer_environment();
|
||||
VERIFY(environment);
|
||||
VERIFY(environment->is_declarative_environment());
|
||||
if (!environment->is_permanently_screwed_by_eval()) {
|
||||
interpreter.accumulator() = TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, m_cached_environment_coordinate.value().index, vm.in_strict_mode()));
|
||||
interpreter.accumulator() = TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, cached_environment_coordinate.value().index, vm.in_strict_mode()));
|
||||
return {};
|
||||
}
|
||||
m_cached_environment_coordinate = {};
|
||||
cached_environment_coordinate = {};
|
||||
}
|
||||
|
||||
auto const& string = interpreter.current_executable().get_identifier(m_identifier);
|
||||
auto reference = TRY(vm.resolve_binding(string));
|
||||
if (reference.environment_coordinate().has_value())
|
||||
m_cached_environment_coordinate = reference.environment_coordinate();
|
||||
cached_environment_coordinate = reference.environment_coordinate();
|
||||
interpreter.accumulator() = TRY(reference.get_value(vm));
|
||||
return {};
|
||||
}
|
||||
|
@ -837,27 +838,28 @@ ThrowCompletionOr<void> GetCalleeAndThisFromEnvironment::execute_impl(Bytecode::
|
|||
{
|
||||
auto& vm = interpreter.vm();
|
||||
|
||||
if (m_cached_environment_coordinate.has_value()) {
|
||||
auto& cached_environment_coordinate = interpreter.current_executable().environment_variable_caches[m_cache_index];
|
||||
if (cached_environment_coordinate.has_value()) {
|
||||
auto environment = vm.running_execution_context().lexical_environment;
|
||||
for (size_t i = 0; i < m_cached_environment_coordinate->hops; ++i)
|
||||
for (size_t i = 0; i < cached_environment_coordinate->hops; ++i)
|
||||
environment = environment->outer_environment();
|
||||
VERIFY(environment);
|
||||
VERIFY(environment->is_declarative_environment());
|
||||
if (!environment->is_permanently_screwed_by_eval()) {
|
||||
interpreter.reg(m_callee_reg) = TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, m_cached_environment_coordinate.value().index, vm.in_strict_mode()));
|
||||
interpreter.reg(m_callee_reg) = TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, cached_environment_coordinate.value().index, vm.in_strict_mode()));
|
||||
Value this_value = js_undefined();
|
||||
if (auto base_object = environment->with_base_object())
|
||||
this_value = base_object;
|
||||
interpreter.reg(m_this_reg) = this_value;
|
||||
return {};
|
||||
}
|
||||
m_cached_environment_coordinate = {};
|
||||
cached_environment_coordinate = {};
|
||||
}
|
||||
|
||||
auto const& string = interpreter.current_executable().get_identifier(m_identifier);
|
||||
auto reference = TRY(vm.resolve_binding(string));
|
||||
if (reference.environment_coordinate().has_value())
|
||||
m_cached_environment_coordinate = reference.environment_coordinate();
|
||||
cached_environment_coordinate = reference.environment_coordinate();
|
||||
|
||||
interpreter.reg(m_callee_reg) = TRY(reference.get_value(vm));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue