1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:47:44 +00:00

Ladybird: Update for LibJS realm changes

This commit is contained in:
Luke Wilde 2022-08-23 17:25:10 +01:00 committed by Andrew Kaster
parent a14b00e046
commit c9e6967d7b
4 changed files with 17 additions and 12 deletions

View file

@ -26,16 +26,17 @@ ConsoleClient::ConsoleClient(JS::Console& console, WeakPtr<JS::Interpreter> inte
JS::DeferGC defer_gc(m_interpreter->heap()); JS::DeferGC defer_gc(m_interpreter->heap());
auto& vm = m_interpreter->vm(); auto& vm = m_interpreter->vm();
auto& global_object = m_interpreter->global_object(); auto& realm = m_interpreter->realm();
auto& window = static_cast<Web::Bindings::WindowObject&>(realm.global_object());
auto console_global_object = m_interpreter->heap().allocate_without_global_object<ConsoleGlobalObject>(*global_object.associated_realm(), static_cast<Web::Bindings::WindowObject&>(global_object)); auto console_global_object = m_interpreter->heap().allocate_without_realm<ConsoleGlobalObject>(realm, window);
// NOTE: We need to push an execution context here for NativeFunction::create() to succeed during global object initialization. // NOTE: We need to push an execution context here for NativeFunction::create() to succeed during global object initialization.
// It gets removed immediately after creating the interpreter in Document::interpreter(). // It gets removed immediately after creating the interpreter in Document::interpreter().
auto& eso = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_interpreter->realm().host_defined()); auto& eso = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_interpreter->realm().host_defined());
vm.push_execution_context(eso.realm_execution_context()); vm.push_execution_context(eso.realm_execution_context());
console_global_object->set_associated_realm(m_interpreter->realm()); console_global_object->set_associated_realm(m_interpreter->realm());
console_global_object->initialize_global_object(); console_global_object->initialize_global_object(realm);
vm.pop_execution_context(); vm.pop_execution_context();
m_console_global_object = JS::make_handle(console_global_object); m_console_global_object = JS::make_handle(console_global_object);

View file

@ -21,12 +21,12 @@ ConsoleGlobalObject::ConsoleGlobalObject(JS::Realm& realm, Web::Bindings::Window
{ {
} }
void ConsoleGlobalObject::initialize_global_object() void ConsoleGlobalObject::initialize_global_object(JS::Realm& realm)
{ {
Base::initialize_global_object(); Base::initialize_global_object(realm);
// $0 magic variable // $0 magic variable
define_native_accessor("$0", inspected_node_getter, nullptr, 0); define_native_accessor(realm, "$0", inspected_node_getter, nullptr, 0);
} }
void ConsoleGlobalObject::visit_edges(Visitor& visitor) void ConsoleGlobalObject::visit_edges(Visitor& visitor)
@ -98,10 +98,11 @@ JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> ConsoleGlobalObject::internal
JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter) JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter)
{ {
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); auto& realm = *vm.current_realm();
auto* this_object = TRY(vm.this_value().to_object(vm));
if (!is<ConsoleGlobalObject>(this_object)) if (!is<ConsoleGlobalObject>(this_object))
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "ConsoleGlobalObject"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "ConsoleGlobalObject");
auto console_global_object = static_cast<ConsoleGlobalObject*>(this_object); auto console_global_object = static_cast<ConsoleGlobalObject*>(this_object);
auto& window = console_global_object->m_window_object->impl(); auto& window = console_global_object->m_window_object->impl();
@ -109,7 +110,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter)
if (!inspected_node) if (!inspected_node)
return JS::js_undefined(); return JS::js_undefined();
return Web::Bindings::wrap(global_object, *inspected_node); return Web::Bindings::wrap(realm, *inspected_node);
} }
} }

View file

@ -38,7 +38,7 @@ public:
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const& name) override; virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const& name) override;
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override; virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;
virtual void initialize_global_object() override; virtual void initialize_global_object(JS::Realm&) override;
private: private:
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;

View file

@ -186,8 +186,11 @@ public:
return; return;
m_interpreter = interpreter; m_interpreter = interpreter;
m_console_client = make<Ladybird::ConsoleClient>(interpreter->global_object().console(), interpreter, m_view);
interpreter->global_object().console().set_client(*m_console_client.ptr()); auto& realm = interpreter->realm();
auto& global_object = realm.global_object();
m_console_client = make<Ladybird::ConsoleClient>(global_object.console(), interpreter, m_view);
global_object.console().set_client(*m_console_client.ptr());
} }
virtual void page_did_change_selection() override virtual void page_did_change_selection() override