mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 12:07:14 +02:00
LibWeb/IDB: Implement clone_in_realm
This commit is contained in:
Notes:
github-actions[bot]
2025-04-23 18:38:55 +00:00
Author: https://github.com/stelar7 Commit: https://github.com/LadybirdBrowser/ladybird/commit/499548c3d0f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4317 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/kennethmyhra ✅
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user