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:
parent
eea81738cd
commit
499548c3d0
Notes:
github-actions[bot]
2025-04-23 18:38:55 +00:00
Author: https://github.com/stelar7
Commit: 499548c3d0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4317
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/kennethmyhra ✅
2 changed files with 26 additions and 0 deletions
|
@ -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: transaction’s state is active.
|
||||
VERIFY(transaction->state() == IDBTransaction::TransactionState::Active);
|
||||
|
||||
// 2. Set transaction’s 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 transaction’s state to active.
|
||||
transaction->set_state(IDBTransaction::TransactionState::Active);
|
||||
|
||||
// 6. Return clone.
|
||||
return clone;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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>);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue