ladybird/Libraries/LibWeb/HTML/StorageEvent.cpp
Andreas Kling a6dfc74e93 LibWeb: Only set prototype once for object with IDL interface
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.
2025-04-20 18:43:11 +02:00

70 lines
2.2 KiB
C++

/*
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/StorageEventPrototype.h>
#include <LibWeb/HTML/Storage.h>
#include <LibWeb/HTML/StorageEvent.h>
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(StorageEvent);
GC::Ref<StorageEvent> StorageEvent::create(JS::Realm& realm, FlyString const& event_name, StorageEventInit const& event_init)
{
auto event = realm.create<StorageEvent>(realm, event_name, event_init);
event->set_is_trusted(true);
return event;
}
GC::Ref<StorageEvent> StorageEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, StorageEventInit const& event_init)
{
return realm.create<StorageEvent>(realm, event_name, event_init);
}
StorageEvent::~StorageEvent() = default;
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storageevent-initstorageevent
void StorageEvent::init_storage_event(String const& type, bool bubbles, bool cancelable,
Optional<String> const& key, Optional<String> const& old_value, Optional<String> const& new_value,
String const& url, GC::Ptr<Storage> storage_area)
{
// The initStorageEvent(type, bubbles, cancelable, key, oldValue, newValue, url, storageArea) method must initialize
// the event in a manner analogous to the similarly-named initEvent() method. [DOM]
if (dispatched())
return;
initialize_event(type, bubbles, cancelable);
m_key = key;
m_old_value = old_value;
m_new_value = new_value;
m_url = url;
m_storage_area = storage_area;
}
StorageEvent::StorageEvent(JS::Realm& realm, FlyString const& event_name, StorageEventInit const& event_init)
: DOM::Event(realm, event_name, event_init)
, m_key(event_init.key)
, m_old_value(event_init.old_value)
, m_new_value(event_init.new_value)
, m_url(event_init.url)
, m_storage_area(event_init.storage_area)
{
}
void StorageEvent::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(StorageEvent);
Base::initialize(realm);
}
void StorageEvent::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_storage_area);
}
}