LibJS: Take VM instead of Interpreter in more common implementations

This commit is contained in:
Andreas Kling 2023-11-05 14:22:57 +01:00
parent 234ed2d466
commit 3b6b9b9f25
4 changed files with 15 additions and 18 deletions

View file

@ -18,9 +18,8 @@
namespace JS::Bytecode {
ThrowCompletionOr<NonnullGCPtr<Object>> base_object_for_get(Bytecode::Interpreter& interpreter, Value base_value)
ThrowCompletionOr<NonnullGCPtr<Object>> base_object_for_get(VM& vm, Value base_value)
{
auto& vm = interpreter.vm();
if (base_value.is_object())
return base_value.as_object();
@ -35,10 +34,9 @@ ThrowCompletionOr<NonnullGCPtr<Object>> base_object_for_get(Bytecode::Interprete
return base_value.to_object(vm);
}
ThrowCompletionOr<Value> get_by_id(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& property, Value base_value, Value this_value, u32 cache_index)
ThrowCompletionOr<Value> get_by_id(VM& vm, DeprecatedFlyString const& property, Value base_value, Value this_value, u32 cache_index)
{
auto& vm = interpreter.vm();
auto& cache = interpreter.current_executable().property_lookup_caches[cache_index];
auto& cache = vm.bytecode_interpreter().current_executable().property_lookup_caches[cache_index];
if (base_value.is_string()) {
auto string_value = TRY(base_value.as_string().get(vm, property));
@ -46,7 +44,7 @@ ThrowCompletionOr<Value> get_by_id(Bytecode::Interpreter& interpreter, Deprecate
return *string_value;
}
auto base_obj = TRY(base_object_for_get(interpreter, base_value));
auto base_obj = TRY(base_object_for_get(vm, base_value));
// OPTIMIZATION: If the shape of the object hasn't changed, we can use the cached property offset.
// NOTE: Unique shapes don't change identity, so we compare their serial numbers instead.
@ -68,10 +66,9 @@ ThrowCompletionOr<Value> get_by_id(Bytecode::Interpreter& interpreter, Deprecate
return value;
}
ThrowCompletionOr<Value> get_by_value(Bytecode::Interpreter& interpreter, Value base_value, Value property_key_value)
ThrowCompletionOr<Value> get_by_value(VM& vm, Value base_value, Value property_key_value)
{
auto& vm = interpreter.vm();
auto object = TRY(base_object_for_get(interpreter, base_value));
auto object = TRY(base_object_for_get(vm, base_value));
// OPTIMIZATION: Fast path for simple Int32 indexes in array-like objects.
if (property_key_value.is_int32()

View file

@ -12,9 +12,9 @@
namespace JS::Bytecode {
ThrowCompletionOr<NonnullGCPtr<Object>> base_object_for_get(Bytecode::Interpreter&, Value base_value);
ThrowCompletionOr<Value> get_by_id(Bytecode::Interpreter&, DeprecatedFlyString const& property, Value base_value, Value this_value, u32 cache_index);
ThrowCompletionOr<Value> get_by_value(Bytecode::Interpreter&, Value base_value, Value property_key_value);
ThrowCompletionOr<NonnullGCPtr<Object>> base_object_for_get(VM&, Value base_value);
ThrowCompletionOr<Value> get_by_id(VM&, DeprecatedFlyString const& property, Value base_value, Value this_value, u32 cache_index);
ThrowCompletionOr<Value> get_by_value(VM&, Value base_value, Value property_key_value);
ThrowCompletionOr<Value> get_global(Bytecode::Interpreter&, DeprecatedFlyString const& identifier, u32 cache_index);
ThrowCompletionOr<void> put_by_property_key(VM&, Value base, Value this_value, Value value, PropertyKey name, Op::PropertyKind kind);
ThrowCompletionOr<Value> perform_call(Interpreter&, Value this_value, Op::CallType, Value callee, MarkedVector<Value> argument_values);

View file

@ -760,7 +760,7 @@ ThrowCompletionOr<void> SetLocal::execute_impl(Bytecode::Interpreter&) const
ThrowCompletionOr<void> GetById::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto base_value = interpreter.accumulator();
interpreter.accumulator() = TRY(get_by_id(interpreter, interpreter.current_executable().get_identifier(m_property), base_value, base_value, m_cache_index));
interpreter.accumulator() = TRY(get_by_id(interpreter.vm(), interpreter.current_executable().get_identifier(m_property), base_value, base_value, m_cache_index));
return {};
}
@ -768,7 +768,7 @@ ThrowCompletionOr<void> GetByIdWithThis::execute_impl(Bytecode::Interpreter& int
{
auto base_value = interpreter.accumulator();
auto this_value = interpreter.reg(m_this_value);
interpreter.accumulator() = TRY(get_by_id(interpreter, interpreter.current_executable().get_identifier(m_property), base_value, this_value, m_cache_index));
interpreter.accumulator() = TRY(get_by_id(interpreter.vm(), interpreter.current_executable().get_identifier(m_property), base_value, this_value, m_cache_index));
return {};
}
@ -1071,7 +1071,7 @@ ThrowCompletionOr<void> Await::execute_impl(Bytecode::Interpreter& interpreter)
ThrowCompletionOr<void> GetByValue::execute_impl(Bytecode::Interpreter& interpreter) const
{
interpreter.accumulator() = TRY(get_by_value(interpreter, interpreter.reg(m_base), interpreter.accumulator()));
interpreter.accumulator() = TRY(get_by_value(interpreter.vm(), interpreter.reg(m_base), interpreter.accumulator()));
return {};
}

View file

@ -921,7 +921,7 @@ void Compiler::compile_new_class(Bytecode::Op::NewClass const& op)
static Value cxx_get_by_id(VM& vm, Value base, DeprecatedFlyString const& property, u32 cache_index)
{
return TRY_OR_SET_EXCEPTION(Bytecode::get_by_id(vm.bytecode_interpreter(), property, base, base, cache_index));
return TRY_OR_SET_EXCEPTION(Bytecode::get_by_id(vm, property, base, base, cache_index));
}
void Compiler::compile_get_by_id(Bytecode::Op::GetById const& op)
@ -940,7 +940,7 @@ void Compiler::compile_get_by_id(Bytecode::Op::GetById const& op)
static Value cxx_get_by_value(VM& vm, Value base, Value property)
{
return TRY_OR_SET_EXCEPTION(Bytecode::get_by_value(vm.bytecode_interpreter(), base, property));
return TRY_OR_SET_EXCEPTION(Bytecode::get_by_value(vm, base, property));
}
void Compiler::compile_get_by_value(Bytecode::Op::GetByValue const& op)
@ -1577,7 +1577,7 @@ void Compiler::compile_resolve_super_base(Bytecode::Op::ResolveSuperBase const&)
static Value cxx_get_by_id_with_this(VM& vm, DeprecatedFlyString const& property, Value base_value, Value this_value, u32 cache_index)
{
return TRY_OR_SET_EXCEPTION(get_by_id(vm.bytecode_interpreter(), property, base_value, this_value, cache_index));
return TRY_OR_SET_EXCEPTION(Bytecode::get_by_id(vm, property, base_value, this_value, cache_index));
}
void Compiler::compile_get_by_id_with_this(Bytecode::Op::GetByIdWithThis const& op)