1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 02:13:56 +09:00

LibWeb/IDB: Implement clone_in_realm

This commit is contained in:
stelar7 2025-04-11 10:38:55 +02:00 committed by Andrew Kaster
parent eea81738cd
commit 499548c3d0
Notes: github-actions[bot] 2025-04-23 18:38:55 +00:00
2 changed files with 26 additions and 0 deletions

View file

@ -15,6 +15,7 @@
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/StructuredSerialize.h>
#include <LibWeb/IndexedDB/IDBDatabase.h>
#include <LibWeb/IndexedDB/IDBRequest.h>
#include <LibWeb/IndexedDB/IDBTransaction.h>
@ -790,4 +791,28 @@ void commit_a_transaction(JS::Realm& realm, GC::Ref<IDBTransaction> transaction)
}));
}
// https://w3c.github.io/IndexedDB/#clone
WebIDL::ExceptionOr<JS::Value> clone_in_realm(JS::Realm& target_realm, JS::Value value, GC::Ref<IDBTransaction> transaction)
{
auto& vm = target_realm.vm();
// 1. Assert: transactions state is active.
VERIFY(transaction->state() == IDBTransaction::TransactionState::Active);
// 2. Set transactions state to inactive.
transaction->set_state(IDBTransaction::TransactionState::Inactive);
// 3. Let serialized be ? StructuredSerializeForStorage(value).
auto serialized = TRY(HTML::structured_serialize_for_storage(vm, value));
// 4. Let clone be ? StructuredDeserialize(serialized, targetRealm).
auto clone = TRY(HTML::structured_deserialize(vm, serialized, target_realm));
// 5. Set transactions state to active.
transaction->set_state(IDBTransaction::TransactionState::Active);
// 6. Return clone.
return clone;
}
}

View file

@ -28,5 +28,6 @@ JS::Value convert_a_key_to_a_value(JS::Realm&, GC::Ref<Key>);
bool is_valid_key_path(KeyPath const&);
GC::Ref<HTML::DOMStringList> create_a_sorted_name_list(JS::Realm&, Vector<String>);
void commit_a_transaction(JS::Realm&, GC::Ref<IDBTransaction>);
WebIDL::ExceptionOr<JS::Value> clone_in_realm(JS::Realm&, JS::Value, GC::Ref<IDBTransaction>);
}