LibWeb: Make WorkerNavigator GC-allocated

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

View file

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

View file

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

View file

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

View file

@ -22,12 +22,18 @@ namespace Web::HTML {
WorkerGlobalScope::WorkerGlobalScope(JS::Realm& realm)
: DOM::EventTarget(realm)
, m_navigator(make_ref_counted<WorkerNavigator>())
{
}
WorkerGlobalScope::~WorkerGlobalScope() = default;
void WorkerGlobalScope::initialize(JS::Realm& realm)
{
Base::initialize(realm);
m_navigator = WorkerNavigator::create(*this);
}
void WorkerGlobalScope::visit_edges(Cell::Visitor& 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
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,
// 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<WorkerLocation> location() const;
NonnullRefPtr<WorkerNavigator const> navigator() const;
JS::NonnullGCPtr<WorkerNavigator> navigator() const;
DOM::ExceptionOr<void> import_scripts(Vector<String> urls);
#undef __ENUMERATE
@ -74,12 +74,14 @@ protected:
explicit WorkerGlobalScope(JS::Realm&);
private:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
JS::GCPtr<WorkerLocation> m_location;
// FIXME: Implement WorkerNavigator according to the spec
NonnullRefPtr<WorkerNavigator> m_navigator;
JS::GCPtr<WorkerNavigator> m_navigator;
// 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
#include <AK/RefCounted.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::HTML {
// FIXME: Add Mixin APIs from https://html.spec.whatwg.org/multipage/workers.html#the-workernavigator-object
class WorkerNavigator
: public RefCounted<WorkerNavigator>
, public Bindings::Wrappable {
class WorkerNavigator : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(WorkerNavigator, Bindings::PlatformObject);
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/WorkerGlobalScope 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(IntersectionObserver/IntersectionObserver NO_INSTANCE)
libweb_js_wrapper(NavigationTiming/PerformanceTiming NO_INSTANCE)