1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 13:17:36 +00:00

LibWeb: Make WorkerNavigator GC-allocated

This commit is contained in:
Andreas Kling 2022-09-04 14:37:49 +02:00
parent 9da72cdaba
commit 2fe97fa8db
8 changed files with 51 additions and 14 deletions

View file

@ -3275,7 +3275,6 @@ void generate_prototype_implementation(IDL::Interface const& interface)
#endif #endif
#include <LibWeb/Bindings/ExceptionOrUtils.h> #include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/LocationObject.h> #include <LibWeb/Bindings/LocationObject.h>
#include <LibWeb/Bindings/WorkerNavigatorWrapper.h>
#include <LibWeb/DOM/Element.h> #include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/IDLEventListener.h> #include <LibWeb/DOM/IDLEventListener.h>

View file

@ -266,6 +266,7 @@ set(SOURCES
HTML/WorkerDebugConsoleClient.cpp HTML/WorkerDebugConsoleClient.cpp
HTML/WorkerGlobalScope.cpp HTML/WorkerGlobalScope.cpp
HTML/WorkerLocation.cpp HTML/WorkerLocation.cpp
HTML/WorkerNavigator.cpp
HighResolutionTime/Performance.cpp HighResolutionTime/Performance.cpp
ImageDecoding.cpp ImageDecoding.cpp
Infra/ByteSequences.cpp Infra/ByteSequences.cpp

View file

@ -453,7 +453,6 @@ class LocationObject;
class OptionConstructor; class OptionConstructor;
class RangePrototype; class RangePrototype;
class WindowProxy; class WindowProxy;
class WorkerNavigatorWrapper;
class Wrappable; class Wrappable;
class Wrapper; class Wrapper;
class XMLHttpRequestPrototype; class XMLHttpRequestPrototype;

View file

@ -22,12 +22,18 @@ namespace Web::HTML {
WorkerGlobalScope::WorkerGlobalScope(JS::Realm& realm) WorkerGlobalScope::WorkerGlobalScope(JS::Realm& realm)
: DOM::EventTarget(realm) : DOM::EventTarget(realm)
, m_navigator(make_ref_counted<WorkerNavigator>())
{ {
} }
WorkerGlobalScope::~WorkerGlobalScope() = default; WorkerGlobalScope::~WorkerGlobalScope() = default;
void WorkerGlobalScope::initialize(JS::Realm& realm)
{
Base::initialize(realm);
m_navigator = WorkerNavigator::create(*this);
}
void WorkerGlobalScope::visit_edges(Cell::Visitor& visitor) void WorkerGlobalScope::visit_edges(Cell::Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
@ -69,7 +75,7 @@ JS::NonnullGCPtr<WorkerLocation> WorkerGlobalScope::location() const
} }
// https://html.spec.whatwg.org/multipage/workers.html#dom-worker-navigator // https://html.spec.whatwg.org/multipage/workers.html#dom-worker-navigator
NonnullRefPtr<WorkerNavigator const> WorkerGlobalScope::navigator() const JS::NonnullGCPtr<WorkerNavigator> WorkerGlobalScope::navigator() const
{ {
// The navigator attribute of the WorkerGlobalScope interface must return an instance of the WorkerNavigator interface, // The navigator attribute of the WorkerGlobalScope interface must return an instance of the WorkerNavigator interface,
// which represents the identity and state of the user agent (the client). // which represents the identity and state of the user agent (the client).

View file

@ -42,7 +42,7 @@ public:
JS::NonnullGCPtr<WorkerGlobalScope> self() const { return *this; } JS::NonnullGCPtr<WorkerGlobalScope> self() const { return *this; }
JS::NonnullGCPtr<WorkerLocation> location() const; JS::NonnullGCPtr<WorkerLocation> location() const;
NonnullRefPtr<WorkerNavigator const> navigator() const; JS::NonnullGCPtr<WorkerNavigator> navigator() const;
DOM::ExceptionOr<void> import_scripts(Vector<String> urls); DOM::ExceptionOr<void> import_scripts(Vector<String> urls);
#undef __ENUMERATE #undef __ENUMERATE
@ -74,12 +74,14 @@ protected:
explicit WorkerGlobalScope(JS::Realm&); explicit WorkerGlobalScope(JS::Realm&);
private: private:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;
JS::GCPtr<WorkerLocation> m_location; JS::GCPtr<WorkerLocation> m_location;
// FIXME: Implement WorkerNavigator according to the spec // FIXME: Implement WorkerNavigator according to the spec
NonnullRefPtr<WorkerNavigator> m_navigator; JS::GCPtr<WorkerNavigator> m_navigator;
// FIXME: Add all these internal slots // FIXME: Add all these internal slots

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/HTML/WorkerGlobalScope.h>
#include <LibWeb/HTML/WorkerNavigator.h>
namespace Web::HTML {
JS::NonnullGCPtr<WorkerNavigator> WorkerNavigator::create(WorkerGlobalScope& global_scope)
{
return *global_scope.heap().allocate<WorkerNavigator>(global_scope.realm(), global_scope);
}
WorkerNavigator::WorkerNavigator(WorkerGlobalScope& global_scope)
: PlatformObject(global_scope.realm())
{
// FIXME: Set prototype once we can get to worker scope prototypes.
}
WorkerNavigator::~WorkerNavigator() = default;
}

View file

@ -6,18 +6,23 @@
#pragma once #pragma once
#include <AK/RefCounted.h> #include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Forward.h>
namespace Web::HTML { namespace Web::HTML {
// FIXME: Add Mixin APIs from https://html.spec.whatwg.org/multipage/workers.html#the-workernavigator-object // FIXME: Add Mixin APIs from https://html.spec.whatwg.org/multipage/workers.html#the-workernavigator-object
class WorkerNavigator class WorkerNavigator : public Bindings::PlatformObject {
: public RefCounted<WorkerNavigator> WEB_PLATFORM_OBJECT(WorkerNavigator, Bindings::PlatformObject);
, public Bindings::Wrappable {
public: public:
using WrapperType = Bindings::WorkerNavigatorWrapper; static JS::NonnullGCPtr<WorkerNavigator> create(WorkerGlobalScope&);
virtual ~WorkerNavigator() override;
private:
explicit WorkerNavigator(WorkerGlobalScope&);
}; };
} }
WRAPPER_HACK(WorkerNavigator, Web::HTML)

View file

@ -153,7 +153,7 @@ libweb_js_wrapper(HTML/TextMetrics NO_INSTANCE)
libweb_js_wrapper(HTML/Worker NO_INSTANCE) libweb_js_wrapper(HTML/Worker NO_INSTANCE)
libweb_js_wrapper(HTML/WorkerGlobalScope NO_INSTANCE) libweb_js_wrapper(HTML/WorkerGlobalScope NO_INSTANCE)
libweb_js_wrapper(HTML/WorkerLocation NO_INSTANCE) libweb_js_wrapper(HTML/WorkerLocation NO_INSTANCE)
libweb_js_wrapper(HTML/WorkerNavigator) libweb_js_wrapper(HTML/WorkerNavigator NO_INSTANCE)
libweb_js_wrapper(HighResolutionTime/Performance NO_INSTANCE) libweb_js_wrapper(HighResolutionTime/Performance NO_INSTANCE)
libweb_js_wrapper(IntersectionObserver/IntersectionObserver NO_INSTANCE) libweb_js_wrapper(IntersectionObserver/IntersectionObserver NO_INSTANCE)
libweb_js_wrapper(NavigationTiming/PerformanceTiming NO_INSTANCE) libweb_js_wrapper(NavigationTiming/PerformanceTiming NO_INSTANCE)