LibWeb: Ensure global objects are an event target

All global objects current need to be event targets so that they
can have events dispatched to them. This allows for removing of
verify_cast for these global objects.
This commit is contained in:
Shannon Booth 2024-12-03 02:37:33 +13:00 committed by Andreas Kling
parent 6a85677f70
commit 05b4676917
Notes: github-actions[bot] 2024-12-02 23:20:48 +00:00
6 changed files with 11 additions and 12 deletions

View file

@ -26,8 +26,8 @@ public:
static GC::Ref<ShadowRealmGlobalScope> create(JS::Realm&);
virtual Bindings::PlatformObject& this_impl() override { return *this; }
virtual Bindings::PlatformObject const& this_impl() const override { return *this; }
virtual DOM::EventTarget& this_impl() override { return *this; }
virtual DOM::EventTarget const& this_impl() const override { return *this; }
// https://whatpr.org/html/9893/webappapis.html#dom-shadowrealmglobalscope-self
GC::Ref<ShadowRealmGlobalScope> self()

View file

@ -198,8 +198,7 @@ void UniversalGlobalScopeMixin::notify_about_rejected_promises(Badge<EventLoop>)
m_about_to_be_notified_rejected_promises_list.clear();
// 4. Let global be settings object's global object.
// We need this as an event target for the unhandledrejection event below
auto& global = verify_cast<DOM::EventTarget>(this_impl());
auto& global = this_impl();
// 5. Queue a global task on the DOM manipulation task source given global to run the following substep:
queue_global_task(Task::Source::DOMManipulation, global, GC::create_function(realm.heap(), [this, &global, list = move(list)] {

View file

@ -21,8 +21,8 @@ class UniversalGlobalScopeMixin {
public:
virtual ~UniversalGlobalScopeMixin();
virtual Bindings::PlatformObject& this_impl() = 0;
virtual Bindings::PlatformObject const& this_impl() const = 0;
virtual DOM::EventTarget& this_impl() = 0;
virtual DOM::EventTarget const& this_impl() const = 0;
WebIDL::ExceptionOr<String> btoa(String const& data) const;
WebIDL::ExceptionOr<String> atob(String const& data) const;

View file

@ -76,8 +76,8 @@ public:
virtual bool dispatch_event(DOM::Event&) override;
// ^WindowOrWorkerGlobalScopeMixin
virtual Bindings::PlatformObject& this_impl() override { return *this; }
virtual Bindings::PlatformObject const& this_impl() const override { return *this; }
virtual DOM::EventTarget& this_impl() override { return *this; }
virtual DOM::EventTarget const& this_impl() const override { return *this; }
// ^JS::Object
virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(JS::Object* prototype) override;

View file

@ -29,8 +29,8 @@ class WindowOrWorkerGlobalScopeMixin {
public:
virtual ~WindowOrWorkerGlobalScopeMixin();
virtual Bindings::PlatformObject& this_impl() = 0;
virtual Bindings::PlatformObject const& this_impl() const = 0;
virtual DOM::EventTarget& this_impl() = 0;
virtual DOM::EventTarget const& this_impl() const = 0;
// JS API functions
String origin() const;

View file

@ -43,8 +43,8 @@ public:
virtual ~WorkerGlobalScope() override;
// ^WindowOrWorkerGlobalScopeMixin
virtual Bindings::PlatformObject& this_impl() override { return *this; }
virtual Bindings::PlatformObject const& this_impl() const override { return *this; }
virtual DOM::EventTarget& this_impl() override { return *this; }
virtual DOM::EventTarget const& this_impl() const override { return *this; }
using UniversalGlobalScopeMixin::atob;
using UniversalGlobalScopeMixin::btoa;