summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-04 14:37:49 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-06 00:27:09 +0200
commit2fe97fa8db663c802a6080805e6fec64cca9d084 (patch)
treef28c6586584002e37f49656fadadeed9c4596fb2
parent9da72cdaba7cd426b0d9f2c445c95df27d145530 (diff)
downloadserenity-2fe97fa8db663c802a6080805e6fec64cca9d084.zip
LibWeb: Make WorkerNavigator GC-allocated
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp1
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp10
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h6
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp25
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerNavigator.h19
-rw-r--r--Userland/Libraries/LibWeb/idl_files.cmake2
8 files changed, 51 insertions, 14 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
index 1295198537..cc9daf4352 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
@@ -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>
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 9931d02f08..700ae2a68c 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -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
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 2b94dd4d7d..35dbb89550 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -453,7 +453,6 @@ class LocationObject;
class OptionConstructor;
class RangePrototype;
class WindowProxy;
-class WorkerNavigatorWrapper;
class Wrappable;
class Wrapper;
class XMLHttpRequestPrototype;
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
index f360e57e40..74280f5647 100644
--- a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
@@ -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).
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h
index 592c792e3d..fa58ddbaea 100644
--- a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h
+++ b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h
@@ -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
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp b/Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp
new file mode 100644
index 0000000000..09898a3805
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp
@@ -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;
+
+}
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerNavigator.h b/Userland/Libraries/LibWeb/HTML/WorkerNavigator.h
index 6d992e1305..1d67e5a7bd 100644
--- a/Userland/Libraries/LibWeb/HTML/WorkerNavigator.h
+++ b/Userland/Libraries/LibWeb/HTML/WorkerNavigator.h
@@ -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)
diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake
index 92833ff7ce..b7c01b01dc 100644
--- a/Userland/Libraries/LibWeb/idl_files.cmake
+++ b/Userland/Libraries/LibWeb/idl_files.cmake
@@ -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)