summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-11-11 15:24:57 +0100
committerAndreas Kling <kling@serenityos.org>2022-11-11 15:25:52 +0100
commit2d33b2996f5737f82c07c73fba675a29d5521f4f (patch)
tree6cbe872b88771b70ed6622f9046cdb1375539f96
parentcf046dbfdb766d0ceb6df530171af92cd407f1e7 (diff)
downloadserenity-2d33b2996f5737f82c07c73fba675a29d5521f4f.zip
LibJS: Teach GetVariable bytecode op to deal with global variable cache
This mirrors the behavior of Identifer::to_reference() in the AST interpreter.
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index 6d8c00a930..f8e69a7910 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -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 };
}