LibJS/JIT: Resolve the GetGlobal identifier at JIT time

This commit is contained in:
Andreas Kling 2023-11-05 14:19:42 +01:00
parent c92954db36
commit 234ed2d466
4 changed files with 12 additions and 13 deletions

View file

@ -94,7 +94,7 @@ ThrowCompletionOr<Value> get_by_value(Bytecode::Interpreter& interpreter, Value
return TRY(object->internal_get(property_key, base_value));
}
ThrowCompletionOr<Value> get_global(Bytecode::Interpreter& interpreter, IdentifierTableIndex identifier, u32 cache_index)
ThrowCompletionOr<Value> get_global(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& identifier, u32 cache_index)
{
auto& vm = interpreter.vm();
auto& realm = *vm.current_realm();
@ -114,25 +114,24 @@ ThrowCompletionOr<Value> get_global(Bytecode::Interpreter& interpreter, Identifi
cache.environment_serial_number = declarative_record.environment_serial_number();
auto const& name = interpreter.current_executable().get_identifier(identifier);
if (vm.running_execution_context().script_or_module.has<NonnullGCPtr<Module>>()) {
// NOTE: GetGlobal is used to access variables stored in the module environment and global environment.
// The module environment is checked first since it precedes the global environment in the environment chain.
auto& module_environment = *vm.running_execution_context().script_or_module.get<NonnullGCPtr<Module>>()->environment();
if (TRY(module_environment.has_binding(name))) {
if (TRY(module_environment.has_binding(identifier))) {
// TODO: Cache offset of binding value
return TRY(module_environment.get_binding_value(vm, name, vm.in_strict_mode()));
return TRY(module_environment.get_binding_value(vm, identifier, vm.in_strict_mode()));
}
}
if (TRY(declarative_record.has_binding(name))) {
if (TRY(declarative_record.has_binding(identifier))) {
// TODO: Cache offset of binding value
return TRY(declarative_record.get_binding_value(vm, name, vm.in_strict_mode()));
return TRY(declarative_record.get_binding_value(vm, identifier, vm.in_strict_mode()));
}
if (TRY(binding_object.has_property(name))) {
if (TRY(binding_object.has_property(identifier))) {
CacheablePropertyMetadata cacheable_metadata;
auto value = TRY(binding_object.internal_get(name, js_undefined(), &cacheable_metadata));
auto value = TRY(binding_object.internal_get(identifier, js_undefined(), &cacheable_metadata));
if (cacheable_metadata.type == CacheablePropertyMetadata::Type::OwnProperty) {
cache.shape = shape;
cache.property_offset = cacheable_metadata.property_offset.value();
@ -141,7 +140,7 @@ ThrowCompletionOr<Value> get_global(Bytecode::Interpreter& interpreter, Identifi
return value;
}
return vm.throw_completion<ReferenceError>(ErrorType::UnknownIdentifier, name);
return vm.throw_completion<ReferenceError>(ErrorType::UnknownIdentifier, identifier);
}
ThrowCompletionOr<void> put_by_property_key(VM& vm, Value base, Value this_value, Value value, PropertyKey name, Op::PropertyKind kind)

View file

@ -15,7 +15,7 @@ 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<Value> get_global(Bytecode::Interpreter&, IdentifierTableIndex, u32 cache_index);
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);
ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter&, Value callee, Op::CallType, Optional<StringTableIndex> const& expression_string);

View file

@ -697,7 +697,7 @@ ThrowCompletionOr<void> GetCalleeAndThisFromEnvironment::execute_impl(Bytecode::
ThrowCompletionOr<void> GetGlobal::execute_impl(Bytecode::Interpreter& interpreter) const
{
interpreter.accumulator() = TRY(get_global(interpreter, m_identifier, m_cache_index));
interpreter.accumulator() = TRY(get_global(interpreter, interpreter.current_executable().get_identifier(m_identifier), m_cache_index));
return {};
}

View file

@ -952,7 +952,7 @@ void Compiler::compile_get_by_value(Bytecode::Op::GetByValue const& op)
check_exception();
}
static Value cxx_get_global(VM& vm, Bytecode::IdentifierTableIndex identifier, u32 cache_index)
static Value cxx_get_global(VM& vm, DeprecatedFlyString const& identifier, u32 cache_index)
{
return TRY_OR_SET_EXCEPTION(Bytecode::get_global(vm.bytecode_interpreter(), identifier, cache_index));
}
@ -961,7 +961,7 @@ void Compiler::compile_get_global(Bytecode::Op::GetGlobal const& op)
{
m_assembler.mov(
Assembler::Operand::Register(ARG1),
Assembler::Operand::Imm(op.identifier().value()));
Assembler::Operand::Imm(bit_cast<u64>(&m_bytecode_executable.get_identifier(op.identifier()))));
m_assembler.mov(
Assembler::Operand::Register(ARG2),
Assembler::Operand::Imm(op.cache_index()));