mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibWeb: Make WorkerLocation GC-allocated
This commit is contained in:
parent
25daa14a05
commit
9da72cdaba
Notes:
sideshowbarker
2024-07-17 07:24:46 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9da72cdaba Pull-request: https://github.com/SerenityOS/serenity/pull/14816 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg ✅
7 changed files with 36 additions and 21 deletions
|
@ -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>
|
||||
|
|
|
@ -453,7 +453,6 @@ class LocationObject;
|
|||
class OptionConstructor;
|
||||
class RangePrototype;
|
||||
class WindowProxy;
|
||||
class WorkerLocationWrapper;
|
||||
class WorkerNavigatorWrapper;
|
||||
class Wrappable;
|
||||
class Wrapper;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
public:
|
||||
using WrapperType = Bindings::WorkerLocationWrapper;
|
||||
class WorkerLocation : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(WorkerLocation, Bindings::PlatformObject);
|
||||
|
||||
static NonnullRefPtr<WorkerLocation> create(WorkerGlobalScope& global_scope)
|
||||
{
|
||||
return adopt_ref(*new WorkerLocation(global_scope));
|
||||
}
|
||||
public:
|
||||
static JS::NonnullGCPtr<WorkerLocation> create(WorkerGlobalScope&);
|
||||
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue