diff --git a/components/script/dom/idbdatabase.rs b/components/script/dom/idbdatabase.rs index 29df4d9384f..d1877e88350 100644 --- a/components/script/dom/idbdatabase.rs +++ b/components/script/dom/idbdatabase.rs @@ -244,8 +244,8 @@ impl IDBDatabaseMethods for IDBDatabase { name.clone(), Some(options), CanGc::note(), + &upgrade_transaction, ); - object_store.set_transaction(&upgrade_transaction); let (sender, receiver) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap(); diff --git a/components/script/dom/idbobjectstore.rs b/components/script/dom/idbobjectstore.rs index c11ddd23c48..6961a0e10f0 100644 --- a/components/script/dom/idbobjectstore.rs +++ b/components/script/dom/idbobjectstore.rs @@ -19,7 +19,7 @@ use crate::dom::bindings::codegen::Bindings::IDBTransactionBinding::IDBTransacti use crate::dom::bindings::codegen::UnionTypes::StringOrStringSequence as StrOrStringSequence; use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object}; -use crate::dom::bindings::root::{DomRoot, MutNullableDom}; +use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::DOMString; use crate::dom::bindings::structuredclone; use crate::dom::domstringlist::DOMStringList; @@ -42,7 +42,7 @@ pub struct IDBObjectStore { name: DomRefCell, key_path: Option, index_names: DomRoot, - transaction: MutNullableDom, + transaction: Dom, auto_increment: bool, // We store the db name in the object store to be able to find the correct @@ -57,6 +57,7 @@ impl IDBObjectStore { name: DOMString, options: Option<&IDBObjectStoreParameters>, can_gc: CanGc, + transaction: &IDBTransaction, ) -> IDBObjectStore { let key_path: Option = match options { Some(options) => options.keyPath.as_ref().map(|path| match path { @@ -74,7 +75,7 @@ impl IDBObjectStore { key_path, index_names: DOMStringList::new(global, Vec::new(), can_gc), - transaction: Default::default(), + transaction: Dom::from_ref(transaction), // FIXME:(arihant2math) auto_increment: false, @@ -88,10 +89,16 @@ impl IDBObjectStore { name: DOMString, options: Option<&IDBObjectStoreParameters>, can_gc: CanGc, + transaction: &IDBTransaction, ) -> DomRoot { reflect_dom_object( Box::new(IDBObjectStore::new_inherited( - global, db_name, name, options, can_gc, + global, + db_name, + name, + options, + can_gc, + transaction, )), global, can_gc, @@ -102,12 +109,8 @@ impl IDBObjectStore { self.name.borrow().clone() } - pub fn set_transaction(&self, transaction: &IDBTransaction) { - self.transaction.set(Some(transaction)); - } - - pub fn transaction(&self) -> Option> { - self.transaction.get() + pub fn transaction(&self) -> DomRoot { + self.transaction.as_rooted() } fn has_key_generator(&self) -> bool { @@ -171,7 +174,7 @@ impl IDBObjectStore { /// Checks if the transation is active, throwing a "TransactionInactiveError" DOMException if not. fn check_transaction_active(&self) -> Fallible<()> { // Let transaction be this object store handle's transaction. - let transaction = self.transaction.get().ok_or(Error::TransactionInactive)?; + let transaction = &self.transaction; // If transaction is not active, throw a "TransactionInactiveError" DOMException. if !transaction.is_active() { @@ -185,7 +188,7 @@ impl IDBObjectStore { /// it then checks if the transaction is a read-only transaction, throwing a "ReadOnlyError" DOMException if so. fn check_readwrite_transaction_active(&self) -> Fallible<()> { // Let transaction be this object store handle's transaction. - let transaction = self.transaction.get().ok_or(Error::TransactionInactive)?; + let transaction = &self.transaction; // If transaction is not active, throw a "TransactionInactiveError" DOMException. if !transaction.is_active() { @@ -449,7 +452,7 @@ impl IDBObjectStoreMethods for IDBObjectStore { // } // https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-transaction - fn GetTransaction(&self) -> Option> { + fn Transaction(&self) -> DomRoot { self.transaction() } diff --git a/components/script/dom/idbrequest.rs b/components/script/dom/idbrequest.rs index 5471b62413c..649ae9eed93 100644 --- a/components/script/dom/idbrequest.rs +++ b/components/script/dom/idbrequest.rs @@ -254,7 +254,7 @@ impl IDBRequest { T: Into + for<'a> Deserialize<'a> + Serialize + Send + Sync + 'static, { // Step 1: Let transaction be the transaction associated with source. - let transaction = source.transaction().expect("Store has no transaction"); + let transaction = source.transaction(); let global = transaction.global(); // Step 2: Assert: transaction is active. diff --git a/components/script/dom/idbtransaction.rs b/components/script/dom/idbtransaction.rs index 1c16b08c2f6..a386cc23bf7 100644 --- a/components/script/dom/idbtransaction.rs +++ b/components/script/dom/idbtransaction.rs @@ -236,8 +236,8 @@ impl IDBTransactionMethods for IDBTransaction { name, None, CanGc::note(), + self, ); - store.set_transaction(self); Dom::from_ref(&*store) }); diff --git a/components/script_bindings/webidls/IDBObjectStore.webidl b/components/script_bindings/webidls/IDBObjectStore.webidl index 1151b3ffbd8..ce29c506e61 100644 --- a/components/script_bindings/webidls/IDBObjectStore.webidl +++ b/components/script_bindings/webidls/IDBObjectStore.webidl @@ -13,7 +13,7 @@ interface IDBObjectStore { attribute DOMString name; // readonly attribute any keyPath; // readonly attribute DOMStringList indexNames; - [SameObject] readonly attribute IDBTransaction? transaction; + [SameObject] readonly attribute IDBTransaction transaction; readonly attribute boolean autoIncrement; [NewObject, Throws] IDBRequest put(any value, optional any key);