mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00

Before this change, we were going through the chain of base classes for each IDL interface object and having them set the prototype to their prototype. Instead of doing that, reorder things so that we set the right prototype immediately in Foo::initialize(), and then don't bother in all the base class overrides. This knocks off a ~1% profile item on Speedometer 3.
56 lines
1.8 KiB
C++
56 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 {
|
|
|
|
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
|
|
|
|
}
|