LibWeb: Add closing flag to WorkerGlobalScope

Also implement close a worker AO.
This commit is contained in:
Andrew Kaster 2024-07-09 03:02:22 -06:00 committed by Andreas Kling
parent 27ef9ffa8f
commit f99c7ad85d
Notes: sideshowbarker 2024-07-17 07:11:12 +09:00
2 changed files with 19 additions and 0 deletions

View file

@ -70,6 +70,18 @@ void WorkerGlobalScope::set_internal_port(JS::NonnullGCPtr<MessagePort> port)
m_internal_port->set_worker_event_target(*this);
}
// https://html.spec.whatwg.org/multipage/workers.html#close-a-worker
void WorkerGlobalScope::close()
{
// 1. Discard any tasks that have been added to workerGlobal's relevant agent's event loop's task queues.
relevant_settings_object(*this).responsible_event_loop().task_queue().remove_tasks_matching([](HTML::Task const&) {
return true;
});
// 2. Set workerGlobal's closing flag to true. (This prevents any further tasks from being queued.)
m_closing = true;
}
// https://html.spec.whatwg.org/multipage/workers.html#importing-scripts-and-libraries
WebIDL::ExceptionOr<void> WorkerGlobalScope::import_scripts(Vector<String> const& urls, PerformTheFetchHook perform_fetch)
{

View file

@ -97,6 +97,10 @@ public:
PolicyContainer policy_container() const { return m_policy_container; }
bool is_closing() const { return m_closing; }
void close();
protected:
explicit WorkerGlobalScope(JS::Realm&, JS::NonnullGCPtr<Web::Page>);
@ -144,6 +148,9 @@ private:
// https://html.spec.whatwg.org/multipage/workers.html#concept-workerglobalscope-cross-origin-isolated-capability
bool m_cross_origin_isolated_capability { false };
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-closing
bool m_closing { false };
// https://drafts.csswg.org/css-font-loading/#font-source
JS::GCPtr<CSS::FontFaceSet> m_fonts;
};