mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated PlatformObjects. Their C++ wrapper classes are removed, and the LibJS garbage collector is now responsible for their lifetimes. There's a fair amount of hacks and band-aids in this patch, and we'll have a lot of cleanup to do after this.
This commit is contained in:
parent
bb547ce1c4
commit
6f433c8656
445 changed files with 4797 additions and 4268 deletions
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/PromiseRejectionEvent.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
|
@ -67,7 +66,7 @@ EventLoop& EnvironmentSettingsObject::responsible_event_loop()
|
|||
RunScriptDecision EnvironmentSettingsObject::can_run_script()
|
||||
{
|
||||
// 1. If the global object specified by settings is a Window object whose Document object is not fully active, then return "do not run".
|
||||
if (is<Bindings::WindowObject>(global_object()) && !verify_cast<Bindings::WindowObject>(global_object()).impl().associated_document().is_fully_active())
|
||||
if (is<HTML::Window>(global_object()) && !verify_cast<HTML::Window>(global_object()).associated_document().is_fully_active())
|
||||
return RunScriptDecision::DoNotRun;
|
||||
|
||||
// 2. If scripting is disabled for settings, then return "do not run".
|
||||
|
@ -218,11 +217,11 @@ void EnvironmentSettingsObject::notify_about_rejected_promises(Badge<EventLoop>)
|
|||
/* .reason = */ promise.result(),
|
||||
};
|
||||
// FIXME: This currently assumes that global is a WindowObject.
|
||||
auto& window = verify_cast<Bindings::WindowObject>(*global.cell());
|
||||
auto& window = verify_cast<HTML::Window>(*global.cell());
|
||||
|
||||
auto promise_rejection_event = PromiseRejectionEvent::create(window, HTML::EventNames::unhandledrejection, event_init);
|
||||
|
||||
bool not_handled = window.impl().dispatch_event(*promise_rejection_event);
|
||||
bool not_handled = window.dispatch_event(*promise_rejection_event);
|
||||
|
||||
// 3. If notHandled is false, then the promise rejection is handled. Otherwise, the promise rejection is not handled.
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ struct EnvironmentSettingsObject
|
|||
// FIXME: A module map https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-module-map
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#responsible-document
|
||||
virtual RefPtr<DOM::Document> responsible_document() = 0;
|
||||
virtual JS::GCPtr<DOM::Document> responsible_document() = 0;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#api-url-character-encoding
|
||||
virtual String api_url_character_encoding() = 0;
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
WindowEnvironmentSettingsObject::WindowEnvironmentSettingsObject(Window& window, NonnullOwnPtr<JS::ExecutionContext> execution_context)
|
||||
: EnvironmentSettingsObject(move(execution_context))
|
||||
, m_window(window)
|
||||
, m_window(JS::make_handle(window))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ void WindowEnvironmentSettingsObject::setup(AK::URL const& creation_url, Nonnull
|
|||
|
||||
// 2. Let window be realm's global object.
|
||||
// NOTE: We want to store the Window impl rather than the WindowObject.
|
||||
auto& window = verify_cast<Bindings::WindowObject>(realm->global_object()).impl();
|
||||
auto& window = verify_cast<HTML::Window>(realm->global_object()).impl();
|
||||
|
||||
// 3. Let settings object be a new environment settings object whose algorithms are defined as follows:
|
||||
// NOTE: See the functions defined for this class.
|
||||
|
@ -61,7 +61,7 @@ void WindowEnvironmentSettingsObject::setup(AK::URL const& creation_url, Nonnull
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:responsible-document
|
||||
RefPtr<DOM::Document> WindowEnvironmentSettingsObject::responsible_document()
|
||||
JS::GCPtr<DOM::Document> WindowEnvironmentSettingsObject::responsible_document()
|
||||
{
|
||||
// Return window's associated Document.
|
||||
return m_window->associated_document();
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
virtual ~WindowEnvironmentSettingsObject() override = default;
|
||||
|
||||
virtual RefPtr<DOM::Document> responsible_document() override;
|
||||
virtual JS::GCPtr<DOM::Document> responsible_document() override;
|
||||
virtual String api_url_character_encoding() override;
|
||||
virtual AK::URL api_base_url() override;
|
||||
virtual Origin origin() override;
|
||||
|
@ -26,7 +26,7 @@ public:
|
|||
private:
|
||||
WindowEnvironmentSettingsObject(Window&, NonnullOwnPtr<JS::ExecutionContext>);
|
||||
|
||||
NonnullRefPtr<Window> m_window;
|
||||
JS::Handle<Window> m_window;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class WorkerEnvironmentSettingsObject final
|
|||
public:
|
||||
WorkerEnvironmentSettingsObject(DOM::Document& document, NonnullOwnPtr<JS::ExecutionContext> execution_context)
|
||||
: EnvironmentSettingsObject(move(execution_context))
|
||||
, m_document(document)
|
||||
, m_document(JS::make_handle(document))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -37,14 +37,14 @@ public:
|
|||
|
||||
virtual ~WorkerEnvironmentSettingsObject() override = default;
|
||||
|
||||
RefPtr<DOM::Document> responsible_document() override { return m_document; }
|
||||
JS::GCPtr<DOM::Document> responsible_document() override { return m_document.ptr(); }
|
||||
String api_url_character_encoding() override { return m_document->encoding_or_default(); }
|
||||
AK::URL api_base_url() override { return m_document->url(); }
|
||||
Origin origin() override { return m_document->origin(); }
|
||||
CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability() override { TODO(); }
|
||||
|
||||
private:
|
||||
NonnullRefPtr<DOM::Document> m_document;
|
||||
JS::Handle<DOM::Document> m_document;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue