mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
LibWeb: Make WorkerNavigator GC-allocated
This commit is contained in:
parent
9da72cdaba
commit
2fe97fa8db
8 changed files with 51 additions and 14 deletions
|
@ -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).
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
25
Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp
Normal file
25
Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp
Normal file
|
@ -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;
|
||||
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue