1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:27:44 +00:00

LibWeb: Make WorkerLocation GC-allocated

This commit is contained in:
Andreas Kling 2022-09-04 14:30:38 +02:00
parent 25daa14a05
commit 9da72cdaba
7 changed files with 36 additions and 21 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/WorkerLocationWrapper.h>
#include <LibWeb/Bindings/WorkerNavigatorWrapper.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>

View file

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

View file

@ -28,6 +28,12 @@ WorkerGlobalScope::WorkerGlobalScope(JS::Realm& realm)
WorkerGlobalScope::~WorkerGlobalScope() = default; 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 // https://html.spec.whatwg.org/multipage/workers.html#importing-scripts-and-libraries
DOM::ExceptionOr<void> WorkerGlobalScope::import_scripts(Vector<String> urls) 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 // 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. // The location attribute must return the WorkerLocation object whose associated WorkerGlobalScope object is the WorkerGlobalScope object.
return *m_location; return *m_location;

View file

@ -41,7 +41,7 @@ public:
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-self // https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-self
JS::NonnullGCPtr<WorkerGlobalScope> self() const { return *this; } JS::NonnullGCPtr<WorkerGlobalScope> self() const { return *this; }
NonnullRefPtr<WorkerLocation const> location() const; JS::NonnullGCPtr<WorkerLocation> location() const;
NonnullRefPtr<WorkerNavigator const> navigator() const; NonnullRefPtr<WorkerNavigator const> navigator() const;
DOM::ExceptionOr<void> import_scripts(Vector<String> urls); 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, // Spec note: While the WorkerLocation object is created after the WorkerGlobalScope object,
// this is not problematic as it cannot be observed from script. // 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: protected:
explicit WorkerGlobalScope(JS::Realm&); explicit WorkerGlobalScope(JS::Realm&);
private: private:
RefPtr<WorkerLocation> m_location; virtual void visit_edges(Cell::Visitor&) override;
JS::GCPtr<WorkerLocation> m_location;
// FIXME: Implement WorkerNavigator according to the spec // FIXME: Implement WorkerNavigator according to the spec
NonnullRefPtr<WorkerNavigator> m_navigator; NonnullRefPtr<WorkerNavigator> m_navigator;

View file

@ -117,8 +117,18 @@ String WorkerLocation::hash() const
} }
WorkerLocation::WorkerLocation(WorkerGlobalScope& global_scope) 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);
} }
} }

View file

@ -6,23 +6,18 @@
#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 {
// https://html.spec.whatwg.org/multipage/workers.html#worker-locations // https://html.spec.whatwg.org/multipage/workers.html#worker-locations
class WorkerLocation class WorkerLocation : public Bindings::PlatformObject {
: public RefCounted<WorkerLocation> WEB_PLATFORM_OBJECT(WorkerLocation, Bindings::PlatformObject);
, public Bindings::Wrappable {
public:
using WrapperType = Bindings::WorkerLocationWrapper;
static NonnullRefPtr<WorkerLocation> create(WorkerGlobalScope& global_scope) public:
{ static JS::NonnullGCPtr<WorkerLocation> create(WorkerGlobalScope&);
return adopt_ref(*new WorkerLocation(global_scope));
} virtual ~WorkerLocation() override;
String href() const; String href() const;
String origin() const; String origin() const;
@ -35,9 +30,13 @@ public:
String hash() const; String hash() const;
private: private:
WorkerLocation(WorkerGlobalScope&); explicit WorkerLocation(WorkerGlobalScope&);
virtual void visit_edges(Cell::Visitor&) override;
WorkerGlobalScope& m_global_scope; WorkerGlobalScope& m_global_scope;
}; };
} }
WRAPPER_HACK(WorkerLocation, Web::HTML)

View file

@ -152,7 +152,7 @@ libweb_js_wrapper(HTML/SubmitEvent NO_INSTANCE)
libweb_js_wrapper(HTML/TextMetrics NO_INSTANCE) 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) libweb_js_wrapper(HTML/WorkerLocation NO_INSTANCE)
libweb_js_wrapper(HTML/WorkerNavigator) libweb_js_wrapper(HTML/WorkerNavigator)
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)