mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 07:07:34 +00:00
LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated PlatformObjects. Their C++ wrapper classes are removed, and the LibJS garbage collector is now responsible for their lifetimes. There's a fair amount of hacks and band-aids in this patch, and we'll have a lot of cleanup to do after this.
This commit is contained in:
parent
bb547ce1c4
commit
6f433c8656
445 changed files with 4797 additions and 4268 deletions
|
@ -32,19 +32,12 @@ struct WorkerOptions {
|
|||
};
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#dedicated-workers-and-the-worker-interface
|
||||
class Worker
|
||||
: public RefCounted<Worker>
|
||||
, public Weakable<Worker>
|
||||
, public DOM::EventTarget
|
||||
, public Bindings::Wrappable {
|
||||
class Worker : public DOM::EventTarget {
|
||||
WEB_PLATFORM_OBJECT(Worker, DOM::EventTarget);
|
||||
|
||||
public:
|
||||
using WrapperType = Bindings::WorkerWrapper;
|
||||
|
||||
using RefCounted::ref;
|
||||
using RefCounted::unref;
|
||||
|
||||
static DOM::ExceptionOr<NonnullRefPtr<Worker>> create(FlyString const& script_url, WorkerOptions const options, DOM::Document& document);
|
||||
static DOM::ExceptionOr<NonnullRefPtr<Worker>> create_with_global_object(Bindings::WindowObject& window, FlyString const& script_url, WorkerOptions const options)
|
||||
static DOM::ExceptionOr<JS::NonnullGCPtr<Worker>> create(FlyString const& script_url, WorkerOptions const options, DOM::Document& document);
|
||||
static DOM::ExceptionOr<JS::NonnullGCPtr<Worker>> create_with_global_object(HTML::Window& window, FlyString const& script_url, WorkerOptions const options)
|
||||
{
|
||||
return Worker::create(script_url, options, window.impl().associated_document());
|
||||
}
|
||||
|
@ -55,13 +48,8 @@ public:
|
|||
|
||||
virtual ~Worker() = default;
|
||||
|
||||
// ^EventTarget
|
||||
virtual void ref_event_target() override { ref(); }
|
||||
virtual void unref_event_target() override { unref(); }
|
||||
virtual JS::Object* create_wrapper(JS::Realm&) override;
|
||||
|
||||
MessagePort* implicit_message_port() { return m_implicit_port; }
|
||||
RefPtr<MessagePort> outside_message_port() { return m_outside_port; }
|
||||
MessagePort* implicit_message_port() { return m_implicit_port.ptr(); }
|
||||
JS::GCPtr<MessagePort> outside_message_port() { return m_outside_port; }
|
||||
|
||||
#undef __ENUMERATE
|
||||
#define __ENUMERATE(attribute_name, event_name) \
|
||||
|
@ -79,29 +67,29 @@ private:
|
|||
return static_cast<Bindings::WebEngineCustomData*>(target_vm.custom_data())->event_loop;
|
||||
}
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
FlyString m_script_url;
|
||||
WorkerOptions m_options;
|
||||
WeakPtr<DOM::Document> m_document;
|
||||
|
||||
JS::GCPtr<DOM::Document> m_document;
|
||||
|
||||
Bindings::WebEngineCustomData m_custom_data;
|
||||
|
||||
NonnullRefPtr<JS::VM> m_worker_vm;
|
||||
NonnullOwnPtr<JS::Interpreter> m_interpreter;
|
||||
WeakPtr<WorkerEnvironmentSettingsObject> m_inner_settings;
|
||||
JS::VM::InterpreterExecutionScope m_interpreter_scope;
|
||||
WeakPtr<JS::Realm> m_worker_realm;
|
||||
JS::GCPtr<JS::Realm> m_worker_realm;
|
||||
RefPtr<WorkerDebugConsoleClient> m_console;
|
||||
JS::GlobalObject* m_worker_scope;
|
||||
JS::GCPtr<JS::Object> m_worker_scope;
|
||||
|
||||
NonnullRefPtr<MessagePort> m_implicit_port;
|
||||
RefPtr<MessagePort> m_outside_port;
|
||||
JS::NonnullGCPtr<MessagePort> m_implicit_port;
|
||||
JS::GCPtr<MessagePort> m_outside_port;
|
||||
|
||||
void run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_settings, MessagePort& outside_port, WorkerOptions const options);
|
||||
};
|
||||
|
||||
} // namespace Web::HTML
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
WorkerWrapper* wrap(JS::Realm&, HTML::Worker&);
|
||||
|
||||
}
|
||||
|
||||
WRAPPER_HACK(Worker, Web::HTML)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue