ladybird/Libraries/LibWeb/HTML/SharedWorkerGlobalScope.cpp
Andreas Kling 164ed80244 Meta: Enable exit-time destructor warnings for libraries
Enable -Wexit-time-destructors for all in-tree library targets and
update process-lifetime library statics so they no longer register
exit-time destructors. Long-lived caches, lookup tables, singleton
registries, and generated constants now use NeverDestroyed or leaked
references where the data is intended to live until process exit.

Update LibWeb, LibLine, and the binding generators so regenerated
sources follow the same rule instead of reintroducing destructed
statics.
2026-06-04 19:20:49 +02:00

68 lines
2.3 KiB
C++

/*
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/NeverDestroyed.h>
#include <LibWeb/Bindings/SharedWorkerExposedInterfaces.h>
#include <LibWeb/HTML/SharedWorkerGlobalScope.h>
#include <LibWeb/Page/Page.h>
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(SharedWorkerGlobalScope);
HashTable<GC::RawRef<SharedWorkerGlobalScope>>& all_shared_worker_global_scopes()
{
static NeverDestroyed<HashTable<GC::RawRef<SharedWorkerGlobalScope>>> set;
return *set;
}
SharedWorkerGlobalScope::SharedWorkerGlobalScope(JS::Realm& realm, GC::Ref<Web::Page> page)
: WorkerGlobalScope(realm, page)
{
all_shared_worker_global_scopes().set(*this);
}
SharedWorkerGlobalScope::~SharedWorkerGlobalScope() = default;
void SharedWorkerGlobalScope::initialize_web_interfaces_impl()
{
auto& realm = this->realm();
Bindings::add_shared_worker_exposed_interfaces(*this);
SharedWorkerGlobalScopeGlobalMixin::initialize(realm, *this);
Base::initialize_web_interfaces_impl();
}
void SharedWorkerGlobalScope::finalize()
{
Base::finalize();
WindowOrWorkerGlobalScopeMixin::finalize();
all_shared_worker_global_scopes().remove(*this);
}
// https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworkerglobalscope-close
void SharedWorkerGlobalScope::close()
{
// The close() method steps are to close a worker given this.
close_a_worker();
}
#define __ENUMERATE(attribute_name, event_name) \
void SharedWorkerGlobalScope::set_##attribute_name(WebIDL::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, move(value)); \
} \
\
WebIDL::CallbackType* SharedWorkerGlobalScope::attribute_name() \
{ \
return event_handler_attribute(event_name); \
}
ENUMERATE_SHARED_WORKER_GLOBAL_SCOPE_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE
}