mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
LibJS: Teach GetVariable bytecode op to deal with global variable cache
This mirrors the behavior of Identifer::to_reference() in the AST interpreter.
This commit is contained in:
parent
cf046dbfdb
commit
2d33b2996f
1 changed files with 10 additions and 5 deletions
|
@ -358,11 +358,16 @@ ThrowCompletionOr<void> GetVariable::execute_impl(Bytecode::Interpreter& interpr
|
|||
auto get_reference = [&]() -> ThrowCompletionOr<Reference> {
|
||||
auto const& string = interpreter.current_executable().get_identifier(m_identifier);
|
||||
if (m_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)
|
||||
environment = environment->outer_environment();
|
||||
VERIFY(environment);
|
||||
VERIFY(environment->is_declarative_environment());
|
||||
Environment* environment = nullptr;
|
||||
if (m_cached_environment_coordinate->index == EnvironmentCoordinate::global_marker) {
|
||||
environment = &interpreter.vm().current_realm()->global_environment();
|
||||
} else {
|
||||
environment = vm.running_execution_context().lexical_environment;
|
||||
for (size_t i = 0; i < m_cached_environment_coordinate->hops; ++i)
|
||||
environment = environment->outer_environment();
|
||||
VERIFY(environment);
|
||||
VERIFY(environment->is_declarative_environment());
|
||||
}
|
||||
if (!environment->is_permanently_screwed_by_eval()) {
|
||||
return Reference { *environment, string, vm.in_strict_mode(), m_cached_environment_coordinate };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue