diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp index a0436f16ca..1e5dd48b9f 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp @@ -308,26 +308,25 @@ ThrowCompletionOr put_by_value(VM& vm, Value base, Value property_key_valu return {}; } -ThrowCompletionOr get_variable(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& name, u32 cache_index) +ThrowCompletionOr get_variable(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& name, EnvironmentVariableCache& cache) { auto& vm = interpreter.vm(); - auto& cached_environment_coordinate = interpreter.current_executable().environment_variable_caches[cache_index]; - if (cached_environment_coordinate.has_value()) { + if (cache.has_value()) { auto environment = vm.running_execution_context().lexical_environment; - for (size_t i = 0; i < cached_environment_coordinate->hops; ++i) + for (size_t i = 0; i < cache->hops; ++i) environment = environment->outer_environment(); VERIFY(environment); VERIFY(environment->is_declarative_environment()); if (!environment->is_permanently_screwed_by_eval()) { - return TRY(verify_cast(*environment).get_binding_value_direct(vm, cached_environment_coordinate.value().index, vm.in_strict_mode())); + return TRY(verify_cast(*environment).get_binding_value_direct(vm, cache.value().index, vm.in_strict_mode())); } - cached_environment_coordinate = {}; + cache = {}; } auto reference = TRY(vm.resolve_binding(name)); if (reference.environment_coordinate().has_value()) - cached_environment_coordinate = reference.environment_coordinate(); + cache = reference.environment_coordinate(); return TRY(reference.get_value(vm)); } diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index 8939c51f3c..e818e4e899 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -23,7 +23,7 @@ ThrowCompletionOr typeof_variable(VM&, DeprecatedFlyString const&); ThrowCompletionOr set_variable(VM&, DeprecatedFlyString const&, Value, Op::EnvironmentMode, Op::SetVariable::InitializationMode); Value new_function(VM&, FunctionExpression const&, Optional const& lhs_name, Optional const& home_object); ThrowCompletionOr put_by_value(VM&, Value base, Value property_key_value, Value value, Op::PropertyKind); -ThrowCompletionOr get_variable(Bytecode::Interpreter&, DeprecatedFlyString const& name, u32 cache_index); +ThrowCompletionOr get_variable(Bytecode::Interpreter&, DeprecatedFlyString const& name, EnvironmentVariableCache&); struct CalleeAndThis { Value callee; diff --git a/Userland/Libraries/LibJS/Bytecode/Executable.h b/Userland/Libraries/LibJS/Bytecode/Executable.h index 831af875ad..34959336d2 100644 --- a/Userland/Libraries/LibJS/Bytecode/Executable.h +++ b/Userland/Libraries/LibJS/Bytecode/Executable.h @@ -33,6 +33,8 @@ struct GlobalVariableCache : public PropertyLookupCache { u64 environment_serial_number { 0 }; }; +using EnvironmentVariableCache = Optional; + struct SourceRecord { u32 source_start_offset {}; u32 source_end_offset {}; @@ -57,7 +59,7 @@ public: DeprecatedFlyString name; Vector property_lookup_caches; Vector global_variable_caches; - Vector> environment_variable_caches; + Vector environment_variable_caches; Vector> basic_blocks; NonnullOwnPtr string_table; NonnullOwnPtr identifier_table; diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 713496d0c5..72ff4e3be1 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -683,7 +683,10 @@ ThrowCompletionOr ConcatString::execute_impl(Bytecode::Interpreter& interp ThrowCompletionOr GetVariable::execute_impl(Bytecode::Interpreter& interpreter) const { - interpreter.accumulator() = TRY(get_variable(interpreter, interpreter.current_executable().get_identifier(m_identifier), m_cache_index)); + interpreter.accumulator() = TRY(get_variable( + interpreter, + interpreter.current_executable().get_identifier(m_identifier), + interpreter.current_executable().environment_variable_caches[m_cache_index])); return {}; } diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 5d36b9d638..8e4799d4d1 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -970,9 +970,9 @@ void Compiler::compile_get_global(Bytecode::Op::GetGlobal const& op) check_exception(); } -static Value cxx_get_variable(VM& vm, DeprecatedFlyString const& name, u32 cache_index) +static Value cxx_get_variable(VM& vm, DeprecatedFlyString const& name, Bytecode::EnvironmentVariableCache& cache) { - return TRY_OR_SET_EXCEPTION(Bytecode::get_variable(vm.bytecode_interpreter(), name, cache_index)); + return TRY_OR_SET_EXCEPTION(Bytecode::get_variable(vm.bytecode_interpreter(), name, cache)); } void Compiler::compile_get_variable(Bytecode::Op::GetVariable const& op) @@ -982,7 +982,7 @@ void Compiler::compile_get_variable(Bytecode::Op::GetVariable const& op) Assembler::Operand::Imm(bit_cast(&m_bytecode_executable.get_identifier(op.identifier())))); m_assembler.mov( Assembler::Operand::Register(ARG2), - Assembler::Operand::Imm(op.cache_index())); + Assembler::Operand::Imm(bit_cast(&m_bytecode_executable.environment_variable_caches[op.cache_index()]))); native_call((void*)cxx_get_variable); store_accumulator(RET); check_exception();