mirror of
https://github.com/servo/servo.git
synced 2025-09-23 05:10:09 +01:00
indexeddb: Serialize all cloned values when storing data. (#39081)
We were performing a structured clone but throwing away any serializable DOM interfaces included in the result. We need to instead serialize the full structured clone result so we can deserialize the DOM interfaces when getting the data out of the object store. Testing: Existing WPT coverage is sufficient. Fixes: #38818 Fixed: #38842 Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
6b208124dc
commit
433a461044
6 changed files with 16 additions and 27 deletions
|
@ -257,7 +257,10 @@ impl IDBObjectStore {
|
|||
}
|
||||
|
||||
// Step 10. Let clone be a clone of value in targetRealm during transaction. Rethrow any exceptions.
|
||||
let serialized_value = structuredclone::write(cx, value, None)?;
|
||||
let cloned_value = structuredclone::write(cx, value, None)?;
|
||||
let Ok(serialized_value) = bincode::serialize(&cloned_value) else {
|
||||
return Err(Error::InvalidState);
|
||||
};
|
||||
|
||||
let (sender, receiver) = indexed_db::create_channel(self.global());
|
||||
|
||||
|
@ -268,7 +271,7 @@ impl IDBObjectStore {
|
|||
AsyncOperation::ReadWrite(AsyncReadWriteOperation::PutItem {
|
||||
sender,
|
||||
key: serialized_key,
|
||||
value: serialized_value.serialized,
|
||||
value: serialized_value,
|
||||
should_overwrite: overwrite,
|
||||
}),
|
||||
receiver,
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
use std::cell::Cell;
|
||||
|
||||
use constellation_traits::StructuredSerializedData;
|
||||
use dom_struct::dom_struct;
|
||||
use ipc_channel::router::ROUTER;
|
||||
use js::jsapi::Heap;
|
||||
|
@ -117,14 +116,14 @@ impl RequestListener {
|
|||
key_type_to_jsval(GlobalScope::get_cx(), &key, answer.handle_mut())
|
||||
},
|
||||
IdbResult::Data(serialized_data) => {
|
||||
let data = StructuredSerializedData {
|
||||
serialized: serialized_data,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if structuredclone::read(&global, data, answer.handle_mut()).is_err() {
|
||||
let result = bincode::deserialize(&serialized_data)
|
||||
.map_err(|_| Error::Data)
|
||||
.and_then(|data| structuredclone::read(&global, data, answer.handle_mut()));
|
||||
if let Err(e) = result {
|
||||
warn!("Error reading structuredclone data");
|
||||
}
|
||||
Self::handle_async_request_error(&global, cx, request, e);
|
||||
return;
|
||||
};
|
||||
},
|
||||
IdbResult::Count(count) => {
|
||||
answer.handle_mut().set(DoubleValue(count as f64));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue