mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-31 15:32:51 +00:00
LibWeb/HTML: Implement the StorageEvent interface
This commit is contained in:
parent
c5f9710492
commit
f3e92f2ae5
Notes:
github-actions[bot]
2024-12-25 10:58:07 +00:00
Author: https://github.com/shannonbooth
Commit: f3e92f2ae5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3017
13 changed files with 333 additions and 0 deletions
70
Libraries/LibWeb/HTML/StorageEvent.cpp
Normal file
70
Libraries/LibWeb/HTML/StorageEvent.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(StorageEvent);
|
||||
}
|
||||
|
||||
void StorageEvent::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_storage_area);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue