summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-04 14:30:38 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-06 00:27:09 +0200
commit9da72cdaba7cd426b0d9f2c445c95df27d145530 (patch)
tree3c47185f3f93f898a7b0d0cfb4032a0ea6904fc2 /Userland/Libraries/LibWeb
parent25daa14a054a1866afbe881fe4d055c07e1d70c4 (diff)
downloadserenity-9da72cdaba7cd426b0d9f2c445c95df27d145530.zip
LibWeb: Make WorkerLocation GC-allocated
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp8
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h8
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerLocation.cpp12
-rw-r--r--Userland/Libraries/LibWeb/HTML/WorkerLocation.h23
-rw-r--r--Userland/Libraries/LibWeb/idl_files.cmake2
6 files changed, 35 insertions, 19 deletions
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index bc711fdb32..2b94dd4d7d 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 WorkerLocationWrapper;
class WorkerNavigatorWrapper;
class Wrappable;
class Wrapper;
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
index 350e4ec11d..f360e57e40 100644
--- a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
@@ -28,6 +28,12 @@ WorkerGlobalScope::WorkerGlobalScope(JS::Realm& realm)
WorkerGlobalScope::~WorkerGlobalScope() = default;
+void WorkerGlobalScope::visit_edges(Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_location);
+}
+
// https://html.spec.whatwg.org/multipage/workers.html#importing-scripts-and-libraries
DOM::ExceptionOr<void> WorkerGlobalScope::import_scripts(Vector<String> urls)
{
@@ -56,7 +62,7 @@ DOM::ExceptionOr<void> WorkerGlobalScope::import_scripts(Vector<String> urls)
}
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-location
-NonnullRefPtr<WorkerLocation const> WorkerGlobalScope::location() const
+JS::NonnullGCPtr<WorkerLocation> WorkerGlobalScope::location() const
{
// The location attribute must return the WorkerLocation object whose associated WorkerGlobalScope object is the WorkerGlobalScope object.
return *m_location;
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h
index 269b9f1ab9..592c792e3d 100644
--- a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h
+++ b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.h
@@ -41,7 +41,7 @@ public:
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-self
JS::NonnullGCPtr<WorkerGlobalScope> self() const { return *this; }
- NonnullRefPtr<WorkerLocation const> location() const;
+ JS::NonnullGCPtr<WorkerLocation> location() const;
NonnullRefPtr<WorkerNavigator const> navigator() const;
DOM::ExceptionOr<void> import_scripts(Vector<String> urls);
@@ -68,13 +68,15 @@ public:
// Spec note: While the WorkerLocation object is created after the WorkerGlobalScope object,
// this is not problematic as it cannot be observed from script.
- void set_location(NonnullRefPtr<WorkerLocation> loc) { m_location = move(loc); }
+ void set_location(JS::NonnullGCPtr<WorkerLocation> loc) { m_location = move(loc); }
protected:
explicit WorkerGlobalScope(JS::Realm&);
private:
- RefPtr<WorkerLocation> m_location;
+ virtual void visit_edges(Cell::Visitor&) override;
+
+ JS::GCPtr<WorkerLocation> m_location;
// FIXME: Implement WorkerNavigator according to the spec
NonnullRefPtr<WorkerNavigator> m_navigator;
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerLocation.cpp b/Userland/Libraries/LibWeb/HTML/WorkerLocation.cpp
index 4499aa0aa3..fac203d735 100644
--- a/Userland/Libraries/LibWeb/HTML/WorkerLocation.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WorkerLocation.cpp
@@ -117,8 +117,18 @@ String WorkerLocation::hash() const
}
WorkerLocation::WorkerLocation(WorkerGlobalScope& global_scope)
- : m_global_scope(global_scope)
+ : PlatformObject(global_scope.realm())
+ , m_global_scope(global_scope)
{
+ // FIXME: Set prototype once we can get to worker scope prototypes.
+}
+
+WorkerLocation::~WorkerLocation() = default;
+
+void WorkerLocation::visit_edges(Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_global_scope);
}
}
diff --git a/Userland/Libraries/LibWeb/HTML/WorkerLocation.h b/Userland/Libraries/LibWeb/HTML/WorkerLocation.h
index 384b74bfc7..49bcc0463a 100644
--- a/Userland/Libraries/LibWeb/HTML/WorkerLocation.h
+++ b/Userland/Libraries/LibWeb/HTML/WorkerLocation.h
@@ -6,23 +6,18 @@
#pragma once
-#include <AK/RefCounted.h>
-#include <LibWeb/Bindings/Wrappable.h>
-#include <LibWeb/Forward.h>
+#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/workers.html#worker-locations
-class WorkerLocation
- : public RefCounted<WorkerLocation>
- , public Bindings::Wrappable {
+class WorkerLocation : public Bindings::PlatformObject {
+ WEB_PLATFORM_OBJECT(WorkerLocation, Bindings::PlatformObject);
+
public:
- using WrapperType = Bindings::WorkerLocationWrapper;
+ static JS::NonnullGCPtr<WorkerLocation> create(WorkerGlobalScope&);
- static NonnullRefPtr<WorkerLocation> create(WorkerGlobalScope& global_scope)
- {
- return adopt_ref(*new WorkerLocation(global_scope));
- }
+ virtual ~WorkerLocation() override;
String href() const;
String origin() const;
@@ -35,9 +30,13 @@ public:
String hash() const;
private:
- WorkerLocation(WorkerGlobalScope&);
+ explicit WorkerLocation(WorkerGlobalScope&);
+
+ virtual void visit_edges(Cell::Visitor&) override;
WorkerGlobalScope& m_global_scope;
};
}
+
+WRAPPER_HACK(WorkerLocation, Web::HTML)
diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake
index 20db0f4104..92833ff7ce 100644
--- a/Userland/Libraries/LibWeb/idl_files.cmake
+++ b/Userland/Libraries/LibWeb/idl_files.cmake
@@ -152,7 +152,7 @@ libweb_js_wrapper(HTML/SubmitEvent NO_INSTANCE)
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)
+libweb_js_wrapper(HTML/WorkerLocation NO_INSTANCE)
libweb_js_wrapper(HTML/WorkerNavigator)
libweb_js_wrapper(HighResolutionTime/Performance NO_INSTANCE)
libweb_js_wrapper(IntersectionObserver/IntersectionObserver NO_INSTANCE)