ladybird/Libraries/LibWeb/ServiceWorker/ServiceWorker.cpp
Luke Wilde babfd70ca7 LibGC: Enforce that a Cell type must declare the allocator to use
This ensures that we are explicitly declaring the allocator to use when
allocating a cell(-inheriting) type, instead of silently falling back
to size-based allocation.

Since this is done in allocate_cell, this will only be detected for
types that are actively being allocated. However, since that means
they're _not_ being allocated, that means it's safe to not declare
an allocator to use for those. For example, the base TypedArray<T>,
which is never directly allocated and only the defined specializations
are ever allocated.
2026-01-20 12:00:11 +01:00

58 lines
1.8 KiB
C++

/*
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGC/Heap.h>
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/ServiceWorker/ServiceWorker.h>
namespace Web::ServiceWorker {
GC_DEFINE_ALLOCATOR(ServiceWorker);
ServiceWorker::ServiceWorker(JS::Realm& realm, ServiceWorkerRecord* service_worker_record)
: DOM::EventTarget(realm)
, m_service_worker_record(service_worker_record)
{
}
ServiceWorker::~ServiceWorker() = default;
GC::Ref<ServiceWorker> ServiceWorker::create(JS::Realm& realm, ServiceWorkerRecord* service_worker_record)
{
return realm.create<ServiceWorker>(realm, service_worker_record);
}
void ServiceWorker::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(ServiceWorker);
Base::initialize(realm);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworker-scripturl
String ServiceWorker::script_url() const
{
if (!m_service_worker_record)
return {};
return m_service_worker_record->script_url.serialize();
}
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
void ServiceWorker::set_##attribute_name(WebIDL::CallbackType* value) \
{ \
set_event_handler_attribute(event_name, value); \
} \
WebIDL::CallbackType* ServiceWorker::attribute_name() \
{ \
return event_handler_attribute(event_name); \
}
ENUMERATE_SERVICE_WORKER_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE
}