mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 09:35:09 +00:00
Ladybird: Fix build after LibWeb+LibJS GC changes
This commit is contained in:
parent
9789d8b769
commit
dcab11f5e9
5 changed files with 27 additions and 28 deletions
|
@ -12,28 +12,27 @@
|
|||
#include "WebView.h"
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/MarkupGenerator.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
||||
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)
|
||||
, 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& realm = m_interpreter->realm();
|
||||
auto& window = static_cast<Web::Bindings::WindowObject&>(realm.global_object());
|
||||
auto& vm = realm.vm();
|
||||
auto& window = static_cast<Web::HTML::Window&>(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.
|
||||
// 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());
|
||||
console_global_object->initialize(realm);
|
||||
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)
|
||||
{
|
||||
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());
|
||||
|
||||
// FIXME: Add parse error printouts back once ClassicScript can report parse errors.
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Ladybird {
|
|||
|
||||
class ConsoleClient final : public JS::ConsoleClient {
|
||||
public:
|
||||
ConsoleClient(JS::Console&, WeakPtr<JS::Interpreter>, WebView&);
|
||||
ConsoleClient(JS::Console&, JS::Realm&, WebView&);
|
||||
|
||||
void handle_input(String const& js_source);
|
||||
void send_messages(i32 start_index);
|
||||
|
@ -54,6 +54,8 @@ private:
|
|||
String data;
|
||||
};
|
||||
Vector<ConsoleOutput> m_message_log;
|
||||
|
||||
WeakPtr<JS::Realm> m_realm;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -7,15 +7,12 @@
|
|||
|
||||
#include "ConsoleGlobalObject.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/HTML/Window.h>
|
||||
|
||||
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)
|
||||
, 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)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
if (!is<ConsoleGlobalObject>(this_object))
|
||||
|
@ -110,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter)
|
|||
if (!inspected_node)
|
||||
return JS::js_undefined();
|
||||
|
||||
return Web::Bindings::wrap(realm, *inspected_node);
|
||||
return &*inspected_node;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
class WindowObject;
|
||||
namespace Web::HTML {
|
||||
class Window;
|
||||
}
|
||||
|
||||
namespace Ladybird {
|
||||
|
@ -23,7 +23,7 @@ class ConsoleGlobalObject final : public JS::GlobalObject {
|
|||
JS_OBJECT(ConsoleGlobalObject, JS::GlobalObject);
|
||||
|
||||
public:
|
||||
ConsoleGlobalObject(JS::Realm&, Web::Bindings::WindowObject&);
|
||||
ConsoleGlobalObject(JS::Realm&, Web::HTML::Window&);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~ConsoleGlobalObject() override = default;
|
||||
|
||||
|
@ -45,7 +45,7 @@ private:
|
|||
// Because $0 is not a nice C++ function name
|
||||
JS_DECLARE_NATIVE_FUNCTION(inspected_node_getter);
|
||||
|
||||
Web::Bindings::WindowObject* m_window_object;
|
||||
Web::HTML::Window* m_window_object;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include <LibGfx/ImageDecoder.h>
|
||||
#include <LibGfx/PNGWriter.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/ConsoleObject.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
|
@ -182,14 +181,14 @@ public:
|
|||
void initialize_js_console()
|
||||
{
|
||||
auto* document = page().top_level_browsing_context().active_document();
|
||||
auto interpreter = document->interpreter().make_weak_ptr();
|
||||
if (m_interpreter.ptr() == interpreter.ptr())
|
||||
auto realm = document->realm().make_weak_ptr();
|
||||
if (m_realm && m_realm.ptr() == realm.ptr())
|
||||
return;
|
||||
|
||||
m_interpreter = interpreter;
|
||||
m_realm = realm;
|
||||
|
||||
auto& console_object = *interpreter->realm().intrinsics().console_object();
|
||||
m_console_client = make<Ladybird::ConsoleClient>(console_object.console(), interpreter, m_view);
|
||||
auto& console_object = *document->realm().intrinsics().console_object();
|
||||
m_console_client = make<Ladybird::ConsoleClient>(console_object.console(), *realm, m_view);
|
||||
console_object.console().set_client(*m_console_client.ptr());
|
||||
}
|
||||
|
||||
|
@ -336,7 +335,7 @@ public:
|
|||
Browser::CookieJar m_cookie_jar;
|
||||
|
||||
OwnPtr<Ladybird::ConsoleClient> m_console_client;
|
||||
WeakPtr<JS::Interpreter> m_interpreter;
|
||||
WeakPtr<JS::Realm> m_realm;
|
||||
RefPtr<Gfx::PaletteImpl> m_palette_impl;
|
||||
Gfx::IntRect m_viewport_rect { 0, 0, 800, 600 };
|
||||
Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue