1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:47:35 +00:00

LibWeb: Remove unecessary dependence on Window from DOM and WebIDL

These classes only needed Window to get at its realm. Pass a realm
directly to construct DOM and WebIDL classes.

This change importantly removes the guarantee that a Document will
always have a non-null Window object. Only Documents created by a
BrowsingContext will have a non-null Window object. Documents created by
for example, DocumentFragment, will not have a Window (soon).

This incremental commit leaves some workarounds in place to keep other
parts of the code building.
This commit is contained in:
Andrew Kaster 2022-09-25 16:15:49 -06:00 committed by Linus Groh
parent 8407bf60c5
commit 8de7e49a56
56 changed files with 364 additions and 326 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/AbortSignal.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/EventDispatcher.h>
@ -11,15 +12,20 @@
namespace Web::DOM {
JS::NonnullGCPtr<AbortSignal> AbortSignal::create_with_global_object(HTML::Window& window)
JS::NonnullGCPtr<AbortSignal> AbortSignal::construct_impl(JS::Realm& realm)
{
return *window.heap().allocate<AbortSignal>(window.realm(), window);
return *realm.heap().allocate<AbortSignal>(realm, realm);
}
AbortSignal::AbortSignal(JS::Realm& realm)
: EventTarget(realm)
{
set_prototype(&Bindings::cached_web_prototype(realm, "AbortSignal"));
}
AbortSignal::AbortSignal(HTML::Window& window)
: EventTarget(window.realm())
: AbortSignal(window.realm())
{
set_prototype(&window.cached_web_prototype("AbortSignal"));
}
// https://dom.spec.whatwg.org/#abortsignal-add
@ -44,7 +50,7 @@ void AbortSignal::signal_abort(JS::Value reason)
if (!reason.is_undefined())
m_abort_reason = reason;
else
m_abort_reason = WebIDL::AbortError::create(global_object(), "Aborted without reason").ptr();
m_abort_reason = WebIDL::AbortError::create(realm(), "Aborted without reason").ptr();
// 3. For each algorithm in signals abort algorithms: run algorithm.
for (auto& algorithm : m_abort_algorithms)
@ -54,7 +60,7 @@ void AbortSignal::signal_abort(JS::Value reason)
m_abort_algorithms.clear();
// 5. Fire an event named abort at signal.
dispatch_event(*Event::create(global_object(), HTML::EventNames::abort));
dispatch_event(*Event::create(realm(), HTML::EventNames::abort));
}
void AbortSignal::set_onabort(WebIDL::CallbackType* event_handler)