1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 22:38:12 +00:00

Ladybird: Fix build after LibWeb+LibJS GC changes

This commit is contained in:
Andreas Kling 2022-09-06 00:42:16 +02:00 committed by Andrew Kaster
parent 9789d8b769
commit dcab11f5e9
5 changed files with 27 additions and 28 deletions

View file

@ -12,28 +12,27 @@
#include "WebView.h" #include "WebView.h"
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibJS/MarkupGenerator.h> #include <LibJS/MarkupGenerator.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h> #include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/HTML/Scripting/Environments.h> #include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
namespace Ladybird { namespace Ladybird {
ConsoleClient::ConsoleClient(JS::Console& console, WeakPtr<JS::Interpreter> interpreter, WebView& view) ConsoleClient::ConsoleClient(JS::Console& console, JS::Realm& realm, WebView& view)
: JS::ConsoleClient(console) : JS::ConsoleClient(console)
, m_view(view) , m_view(view)
, m_interpreter(interpreter) , m_realm(realm)
{ {
JS::DeferGC defer_gc(m_interpreter->heap()); JS::DeferGC defer_gc(realm.heap());
auto& vm = m_interpreter->vm(); auto& vm = realm.vm();
auto& realm = m_interpreter->realm(); auto& window = static_cast<Web::HTML::Window&>(realm.global_object());
auto& window = static_cast<Web::Bindings::WindowObject&>(realm.global_object());
auto console_global_object = m_interpreter->heap().allocate_without_realm<ConsoleGlobalObject>(realm, window); auto console_global_object = realm.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>(*realm.host_defined());
vm.push_execution_context(eso.realm_execution_context()); vm.push_execution_context(eso.realm_execution_context());
console_global_object->initialize(realm); console_global_object->initialize(realm);
vm.pop_execution_context(); vm.pop_execution_context();
@ -43,7 +42,10 @@ ConsoleClient::ConsoleClient(JS::Console& console, WeakPtr<JS::Interpreter> inte
void ConsoleClient::handle_input(String const& js_source) void ConsoleClient::handle_input(String const& js_source)
{ {
auto& settings = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_interpreter->realm().host_defined()); if (!m_realm)
return;
auto& settings = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_realm->host_defined());
auto script = Web::HTML::ClassicScript::create("(console)", js_source, settings, settings.api_base_url()); auto script = Web::HTML::ClassicScript::create("(console)", js_source, settings, settings.api_base_url());
// FIXME: Add parse error printouts back once ClassicScript can report parse errors. // FIXME: Add parse error printouts back once ClassicScript can report parse errors.

View file

@ -23,7 +23,7 @@ namespace Ladybird {
class ConsoleClient final : public JS::ConsoleClient { class ConsoleClient final : public JS::ConsoleClient {
public: public:
ConsoleClient(JS::Console&, WeakPtr<JS::Interpreter>, WebView&); ConsoleClient(JS::Console&, JS::Realm&, WebView&);
void handle_input(String const& js_source); void handle_input(String const& js_source);
void send_messages(i32 start_index); void send_messages(i32 start_index);
@ -54,6 +54,8 @@ private:
String data; String data;
}; };
Vector<ConsoleOutput> m_message_log; Vector<ConsoleOutput> m_message_log;
WeakPtr<JS::Realm> m_realm;
}; };
} }

View file

@ -7,15 +7,12 @@
#include "ConsoleGlobalObject.h" #include "ConsoleGlobalObject.h"
#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Completion.h>
#include <LibWeb/Bindings/NodeWrapper.h>
#include <LibWeb/Bindings/NodeWrapperFactory.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/Window.h>
namespace Ladybird { namespace Ladybird {
ConsoleGlobalObject::ConsoleGlobalObject(JS::Realm& realm, Web::Bindings::WindowObject& parent_object) ConsoleGlobalObject::ConsoleGlobalObject(JS::Realm& realm, Web::HTML::Window& parent_object)
: JS::GlobalObject(realm) : JS::GlobalObject(realm)
, m_window_object(&parent_object) , m_window_object(&parent_object)
{ {
@ -98,7 +95,6 @@ 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& realm = *vm.current_realm();
auto* this_object = TRY(vm.this_value().to_object(vm)); auto* this_object = TRY(vm.this_value().to_object(vm));
if (!is<ConsoleGlobalObject>(this_object)) if (!is<ConsoleGlobalObject>(this_object))
@ -110,7 +106,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(realm, *inspected_node); return &*inspected_node;
} }
} }

View file

@ -13,8 +13,8 @@
#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
namespace Web::Bindings { namespace Web::HTML {
class WindowObject; class Window;
} }
namespace Ladybird { namespace Ladybird {
@ -23,7 +23,7 @@ class ConsoleGlobalObject final : public JS::GlobalObject {
JS_OBJECT(ConsoleGlobalObject, JS::GlobalObject); JS_OBJECT(ConsoleGlobalObject, JS::GlobalObject);
public: public:
ConsoleGlobalObject(JS::Realm&, Web::Bindings::WindowObject&); ConsoleGlobalObject(JS::Realm&, Web::HTML::Window&);
virtual void initialize(JS::Realm&) override; virtual void initialize(JS::Realm&) override;
virtual ~ConsoleGlobalObject() override = default; virtual ~ConsoleGlobalObject() override = default;
@ -45,7 +45,7 @@ private:
// Because $0 is not a nice C++ function name // Because $0 is not a nice C++ function name
JS_DECLARE_NATIVE_FUNCTION(inspected_node_getter); JS_DECLARE_NATIVE_FUNCTION(inspected_node_getter);
Web::Bindings::WindowObject* m_window_object; Web::HTML::Window* m_window_object;
}; };
} }

View file

@ -31,7 +31,6 @@
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
#include <LibGfx/PNGWriter.h> #include <LibGfx/PNGWriter.h>
#include <LibGfx/Rect.h> #include <LibGfx/Rect.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/ConsoleObject.h> #include <LibJS/Runtime/ConsoleObject.h>
#include <LibMain/Main.h> #include <LibMain/Main.h>
#include <LibWeb/Bindings/MainThreadVM.h> #include <LibWeb/Bindings/MainThreadVM.h>
@ -182,14 +181,14 @@ public:
void initialize_js_console() void initialize_js_console()
{ {
auto* document = page().top_level_browsing_context().active_document(); auto* document = page().top_level_browsing_context().active_document();
auto interpreter = document->interpreter().make_weak_ptr(); auto realm = document->realm().make_weak_ptr();
if (m_interpreter.ptr() == interpreter.ptr()) if (m_realm && m_realm.ptr() == realm.ptr())
return; return;
m_interpreter = interpreter; m_realm = realm;
auto& console_object = *interpreter->realm().intrinsics().console_object(); auto& console_object = *document->realm().intrinsics().console_object();
m_console_client = make<Ladybird::ConsoleClient>(console_object.console(), interpreter, m_view); m_console_client = make<Ladybird::ConsoleClient>(console_object.console(), *realm, m_view);
console_object.console().set_client(*m_console_client.ptr()); console_object.console().set_client(*m_console_client.ptr());
} }
@ -336,7 +335,7 @@ public:
Browser::CookieJar m_cookie_jar; Browser::CookieJar m_cookie_jar;
OwnPtr<Ladybird::ConsoleClient> m_console_client; OwnPtr<Ladybird::ConsoleClient> m_console_client;
WeakPtr<JS::Interpreter> m_interpreter; WeakPtr<JS::Realm> m_realm;
RefPtr<Gfx::PaletteImpl> m_palette_impl; RefPtr<Gfx::PaletteImpl> m_palette_impl;
Gfx::IntRect m_viewport_rect { 0, 0, 800, 600 }; Gfx::IntRect m_viewport_rect { 0, 0, 800, 600 };
Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto }; Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto };