mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Move common indexeddb methods out of dom implementations (#38101)
A lot of shared functions were scattered around the dom files; I moved them into `indexed_db.rs` for clarity. Fixes: Nothing to my knowledge, just a cleanup Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
This commit is contained in:
parent
e10466b4c4
commit
f70a4eb4ff
8 changed files with 314 additions and 299 deletions
|
@ -3,21 +3,18 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::iter::repeat;
|
||||
|
||||
use constellation_traits::StructuredSerializedData;
|
||||
use dom_struct::dom_struct;
|
||||
use ipc_channel::router::ROUTER;
|
||||
use js::gc::MutableHandle;
|
||||
use js::jsapi::Heap;
|
||||
use js::jsval::{DoubleValue, JSVal, UndefinedValue};
|
||||
use js::rust::{HandleValue, MutableHandleValue};
|
||||
use js::jsval::{JSVal, UndefinedValue};
|
||||
use js::rust::HandleValue;
|
||||
use net_traits::IpcSend;
|
||||
use net_traits::indexeddb_thread::{
|
||||
AsyncOperation, IdbResult, IndexedDBKeyType, IndexedDBThreadMsg, IndexedDBTxnMode,
|
||||
AsyncOperation, IdbResult, IndexedDBThreadMsg, IndexedDBTxnMode,
|
||||
};
|
||||
use profile_traits::ipc;
|
||||
use script_bindings::conversions::SafeToJSValConvertible;
|
||||
use stylo_atoms::Atom;
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::IDBRequestBinding::{
|
||||
|
@ -36,6 +33,7 @@ use crate::dom::eventtarget::EventTarget;
|
|||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::idbobjectstore::IDBObjectStore;
|
||||
use crate::dom::idbtransaction::IDBTransaction;
|
||||
use crate::indexed_db::key_type_to_jsval;
|
||||
use crate::realms::enter_realm;
|
||||
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
|
||||
|
||||
|
@ -44,30 +42,6 @@ struct RequestListener {
|
|||
request: Trusted<IDBRequest>,
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn key_type_to_jsval(cx: SafeJSContext, key: &IndexedDBKeyType, mut result: MutableHandleValue) {
|
||||
match key {
|
||||
IndexedDBKeyType::Number(n) => result.set(DoubleValue(*n)),
|
||||
IndexedDBKeyType::String(s) => s.safe_to_jsval(cx, result),
|
||||
IndexedDBKeyType::Binary(b) => b.safe_to_jsval(cx, result),
|
||||
IndexedDBKeyType::Date(_d) => {
|
||||
// TODO: implement this when Date's representation is finalized.
|
||||
result.set(UndefinedValue());
|
||||
},
|
||||
IndexedDBKeyType::Array(a) => {
|
||||
rooted_vec!(let mut values <- repeat(UndefinedValue()).take(a.len()));
|
||||
for (key, value) in a.iter().zip(unsafe {
|
||||
values
|
||||
.iter_mut()
|
||||
.map(|v| MutableHandle::from_marked_location(v))
|
||||
}) {
|
||||
key_type_to_jsval(cx, key, value);
|
||||
}
|
||||
values.safe_to_jsval(cx, result);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
impl RequestListener {
|
||||
fn handle_async_request_finished(&self, result: Result<Option<IdbResult>, ()>) {
|
||||
let request = self.request.root();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue