Просмотр исходного кода

LibWeb: Make WorkerLocation GC-allocated

Andreas Kling 2 лет назад
Родитель
Сommit
9da72cdaba

+ 0 - 1
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/WorkerLocationWrapper.h>
 #include <LibWeb/Bindings/WorkerNavigatorWrapper.h>
 #include <LibWeb/DOM/Element.h>
 #include <LibWeb/DOM/Event.h>

+ 0 - 1
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;

+ 7 - 1
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;

+ 5 - 3
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;

+ 11 - 1
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);
 }
 
 }

+ 11 - 12
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)

+ 1 - 1
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)