Skip to content

Commit 150183a

Browse files
committed
Fix build after LibWeb+LibJS GC changes (ladybird:f19c400c5c01cd1d3c13ef63fd6fb3856b5fe553)
1 parent b83e98a commit 150183a

5 files changed

+27
-28
lines changed

ConsoleClient.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,27 @@
1212
#include "WebView.h"
1313
#include <LibJS/Interpreter.h>
1414
#include <LibJS/MarkupGenerator.h>
15-
#include <LibWeb/Bindings/WindowObject.h>
1615
#include <LibWeb/HTML/Scripting/ClassicScript.h>
1716
#include <LibWeb/HTML/Scripting/Environments.h>
17+
#include <LibWeb/HTML/Window.h>
1818

1919
namespace Coccinellidae {
2020

21-
ConsoleClient::ConsoleClient(JS::Console& console, WeakPtr<JS::Interpreter> interpreter, WebView& view)
21+
ConsoleClient::ConsoleClient(JS::Console& console, JS::Realm& realm, WebView& view)
2222
: JS::ConsoleClient(console)
2323
, m_view(view)
24-
, m_interpreter(interpreter)
24+
, m_realm(realm)
2525
{
26-
JS::DeferGC defer_gc(m_interpreter->heap());
26+
JS::DeferGC defer_gc(realm.heap());
2727

28-
auto& vm = m_interpreter->vm();
29-
auto& realm = m_interpreter->realm();
30-
auto& window = static_cast<Web::Bindings::WindowObject&>(realm.global_object());
28+
auto& vm = realm.vm();
29+
auto& window = static_cast<Web::HTML::Window&>(realm.global_object());
3130

32-
auto console_global_object = m_interpreter->heap().allocate_without_realm<ConsoleGlobalObject>(realm, window);
31+
auto console_global_object = realm.heap().allocate_without_realm<ConsoleGlobalObject>(realm, window);
3332

3433
// NOTE: We need to push an execution context here for NativeFunction::create() to succeed during global object initialization.
3534
// It gets removed immediately after creating the interpreter in Document::interpreter().
36-
auto& eso = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_interpreter->realm().host_defined());
35+
auto& eso = verify_cast<Web::HTML::EnvironmentSettingsObject>(*realm.host_defined());
3736
vm.push_execution_context(eso.realm_execution_context());
3837
console_global_object->initialize(realm);
3938
vm.pop_execution_context();
@@ -43,7 +42,10 @@ ConsoleClient::ConsoleClient(JS::Console& console, WeakPtr<JS::Interpreter> inte
4342

4443
void ConsoleClient::handle_input(String const& js_source)
4544
{
46-
auto& settings = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_interpreter->realm().host_defined());
45+
if (!m_realm)
46+
return;
47+
48+
auto& settings = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_realm->host_defined());
4749
auto script = Web::HTML::ClassicScript::create("(console)", js_source, settings, settings.api_base_url());
4850

4951
// FIXME: Add parse error printouts back once ClassicScript can report parse errors.

ConsoleClient.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Coccinellidae {
2323

2424
class ConsoleClient final : public JS::ConsoleClient {
2525
public:
26-
ConsoleClient(JS::Console&, WeakPtr<JS::Interpreter>, WebView&);
26+
ConsoleClient(JS::Console&, JS::Realm&, WebView&);
2727

2828
void handle_input(String const& js_source);
2929
void send_messages(i32 start_index);
@@ -54,6 +54,8 @@ class ConsoleClient final : public JS::ConsoleClient {
5454
String data;
5555
};
5656
Vector<ConsoleOutput> m_message_log;
57+
58+
WeakPtr<JS::Realm> m_realm;
5759
};
5860

5961
}

ConsoleGlobalObject.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77

88
#include "ConsoleGlobalObject.h"
99
#include <LibJS/Runtime/Completion.h>
10-
#include <LibWeb/Bindings/NodeWrapper.h>
11-
#include <LibWeb/Bindings/NodeWrapperFactory.h>
12-
#include <LibWeb/Bindings/WindowObject.h>
1310
#include <LibWeb/DOM/Document.h>
1411
#include <LibWeb/HTML/Window.h>
1512

1613
namespace Coccinellidae {
1714

18-
ConsoleGlobalObject::ConsoleGlobalObject(JS::Realm& realm, Web::Bindings::WindowObject& parent_object)
15+
ConsoleGlobalObject::ConsoleGlobalObject(JS::Realm& realm, Web::HTML::Window& parent_object)
1916
: JS::GlobalObject(realm)
2017
, m_window_object(&parent_object)
2118
{
@@ -98,7 +95,6 @@ JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> ConsoleGlobalObject::internal
9895

9996
JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter)
10097
{
101-
auto& realm = *vm.current_realm();
10298
auto* this_object = TRY(vm.this_value().to_object(vm));
10399

104100
if (!is<ConsoleGlobalObject>(this_object))
@@ -110,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter)
110106
if (!inspected_node)
111107
return JS::js_undefined();
112108

113-
return Web::Bindings::wrap(realm, *inspected_node);
109+
return &*inspected_node;
114110
}
115111

116112
}

ConsoleGlobalObject.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <LibJS/Runtime/Completion.h>
1414
#include <LibJS/Runtime/GlobalObject.h>
1515

16-
namespace Web::Bindings {
17-
class WindowObject;
16+
namespace Web::HTML {
17+
class Window;
1818
}
1919

2020
namespace Coccinellidae {
@@ -23,7 +23,7 @@ class ConsoleGlobalObject final : public JS::GlobalObject {
2323
JS_OBJECT(ConsoleGlobalObject, JS::GlobalObject);
2424

2525
public:
26-
ConsoleGlobalObject(JS::Realm&, Web::Bindings::WindowObject&);
26+
ConsoleGlobalObject(JS::Realm&, Web::HTML::Window&);
2727
virtual void initialize(JS::Realm&) override;
2828
virtual ~ConsoleGlobalObject() override = default;
2929

@@ -45,7 +45,7 @@ class ConsoleGlobalObject final : public JS::GlobalObject {
4545
// Because $0 is not a nice C++ function name
4646
JS_DECLARE_NATIVE_FUNCTION(inspected_node_getter);
4747

48-
Web::Bindings::WindowObject* m_window_object;
48+
Web::HTML::Window* m_window_object;
4949
};
5050

5151
}

WebView.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <LibGfx/ImageDecoder.h>
3232
#include <LibGfx/PNGWriter.h>
3333
#include <LibGfx/Rect.h>
34-
#include <LibJS/Interpreter.h>
3534
#include <LibJS/Runtime/ConsoleObject.h>
3635
#include <LibMain/Main.h>
3736
#include <LibWeb/Bindings/MainThreadVM.h>
@@ -183,14 +182,14 @@ class HeadlessBrowserPageClient final : public Web::PageClient {
183182
void initialize_js_console()
184183
{
185184
auto* document = page().top_level_browsing_context().active_document();
186-
auto interpreter = document->interpreter().make_weak_ptr();
187-
if (m_interpreter.ptr() == interpreter.ptr())
185+
auto realm = document->realm().make_weak_ptr();
186+
if (m_realm && m_realm.ptr() == realm.ptr())
188187
return;
189188

190-
m_interpreter = interpreter;
189+
m_realm = realm;
191190

192-
auto& console_object = *interpreter->realm().intrinsics().console_object();
193-
m_console_client = make<Coccinellidae::ConsoleClient>(console_object.console(), interpreter, m_view);
191+
auto& console_object = *document->realm().intrinsics().console_object();
192+
m_console_client = make<Coccinellidae::ConsoleClient>(console_object.console(), *realm, m_view);
194193
console_object.console().set_client(*m_console_client.ptr());
195194
}
196195

@@ -338,7 +337,7 @@ class HeadlessBrowserPageClient final : public Web::PageClient {
338337
Browser::CookieJar m_cookie_jar;
339338

340339
OwnPtr<Coccinellidae::ConsoleClient> m_console_client;
341-
WeakPtr<JS::Interpreter> m_interpreter;
340+
WeakPtr<JS::Realm> m_realm;
342341

343342
RefPtr<Gfx::PaletteImpl> m_palette_impl;
344343
Gfx::IntRect m_viewport_rect { 0, 0, 800, 600 };

0 commit comments

Comments
 (0)