Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(indexeddb): snapshot queued queries and support range deletion (#767)

Donough Liufe28a946e47b
diff --git a/moli-core/tests/web_apis.rs b/moli-core/tests/web_apis.rs
index f67629c7d..bee25241a 100644
--- a/moli-core/tests/web_apis.rs
+++ b/moli-core/tests/web_apis.rs
@@ -1,3 +1,6 @@
+#[path = "web_apis/indexed_db_transaction.rs"]
+mod indexed_db_transaction;
+
#[path = "web_apis/pipe_disturbed.rs"]
mod pipe_disturbed;
diff --git a/moli-core/tests/web_apis/fixtures/indexeddb-query-snapshots.js b/moli-core/tests/web_apis/fixtures/indexeddb-query-snapshots.js
new file mode 100644
index 000000000..6cbb9948f
--- /dev/null
+++ b/moli-core/tests/web_apis/fixtures/indexeddb-query-snapshots.js
@@ -0,0 +1,179 @@
+globalThis.queryChecks = [];
+async function querySnapshotProbe(name = 'query-snapshots-' + Math.random()) {
+ const checks = globalThis.queryChecks;
+ const check = (name, pass, detail) => checks.push({name, pass: !!pass, detail});
+ const request = req => new Promise(resolve => {
+ req.onsuccess = () => resolve({value: req.result});
+ req.onerror = event => { event.preventDefault(); resolve({error: req.error}); };
+ });
+ const done = tx => new Promise(resolve => {
+ tx.oncomplete = () => resolve(true);
+ tx.onabort = () => resolve(false);
+ });
+ const open = indexedDB.open(name, 1);
+ const seeds = [
+ ['array', [1]], ['nested', [[1]]], ['date', new Date(1)]
+ ];
+ open.onupgradeneeded = () => {
+ const store = open.result.createObjectStore('keys');
+ store.createIndex('byKey', 'key');
+ for (const [label, key] of seeds) store.put({label, key}, key);
+ const deletes = open.result.createObjectStore('deletes');
+ deletes.createIndex('byId', 'id');
+ };
+ const db = (await request(open)).value;
+ const variants = [
+ ['array', () => { const key = [1]; return {key, mutate: () => key[0] = 99}; }],
+ ['nested', () => { const key = [[1]]; return {key, mutate: () => key[0][0] = 99}; }],
+ ['date', () => { const key = new Date(1); return {key, mutate: () => key.setTime(99)}; }],
+ ['array', () => {
+ let reads = 0;
+ const key = Object.defineProperty([], 0, {get() {
+ if (++reads > 1) throw new Error('key converted again');
+ return 1;
+ }});
+ return {key, mutate() {}, reads: () => reads};
+ }]
+ ];
+ const block = storeName => {
+ const tx = db.transaction(storeName,'readwrite');
+ const completion = done(tx);
+ tx.objectStore(storeName).get('barrier');
+ return completion;
+ };
+ try {
+ for (const mode of ['pending', 'started']) {
+ for (const sourceName of ['store', 'index']) {
+ for (const method of ['get', 'getKey', 'getAll', 'getAllKeys', 'count', 'openCursor', 'openKeyCursor']) {
+ for (const [i, [label, create]] of variants.entries()) {
+ const unblocked = mode === 'pending' ? block('keys') : Promise.resolve(true);
+ const tx = db.transaction('keys', mode === 'pending' ? 'readwrite' : 'readonly');
+ const completion = done(tx), store = tx.objectStore('keys');
+ if (mode === 'started') await request(store.get('barrier'));
+ const source = sourceName === 'store' ? store : store.index('byKey');
+ const input = create();
+ const result = request(source[method](input.key));
+ input.mutate();
+ const actual = await result;
+ const expected = seeds.find(entry => entry[0] === label)[1];
+ let matches = false;
+ if (!actual.error) {
+ const value = actual.value;
+ if (method === 'get') matches = value && value.label === label;
+ else if (method === 'getKey') matches = value !== undefined && indexedDB.cmp(value,expected) === 0;
+ else if (method === 'getAll') matches = value.length === 1 && value[0].label === label;
+ else if (method === 'getAllKeys') matches = value.length === 1 && indexedDB.cmp(value[0],expected) === 0;
+ else if (method === 'count') matches = value === 1;
+ else matches = value && indexedDB.cmp(value.key,expected) === 0 && indexedDB.cmp(value.primaryKey,expected) === 0;
+ }
+ check(`${mode} ${sourceName}.${method} input ${i}`, matches && (!input.reads || input.reads() === 1), String(actual.error || ''));
+ check(`${mode} ${sourceName}.${method} input ${i} completes`, await completion && await unblocked);
+ }
+ }
+ }
+ }
+ for (const sourceName of ['store','index']) {
+ for (const method of ['getAll','getAllKeys']) {
+ const unblocked = block('keys');
+ const tx = db.transaction('keys','readwrite'), completion = done(tx), store = tx.objectStore('keys');
+ const source = sourceName === 'store' ? store : store.index('byKey');
+ const key = [1];
+ const reads = {query:0,count:0,direction:0};
+ const options = {
+ get query() { reads.query++; return key; },
+ get count() { reads.count++; return 1; },
+ get direction() { reads.direction++; return 'prev'; }
+ };
+ const pending = request(source[method](options));
+ key[0] = 99;
+ const result = await pending;
+ check(`${sourceName}.${method} options query snapshot`, !result.error && result.value.length === 1);
+ check(`${sourceName}.${method} options read once`, Object.values(reads).every(count => count === 1));
+ check(`${sourceName}.${method} options completes`, await completion && await unblocked);
+ }
+ }
+ // Capture the query at call time, but read records after preceding writes.
+ {
+ const writer = db.transaction('keys','readwrite'), written = done(writer);
+ writer.objectStore('keys').put({label:'new value',key:[1]},[1]);
+ const reader = db.transaction('keys','readwrite'), read = done(reader), key = [1];
+ const pending = request(reader.objectStore('keys').get(key));
+ key[0] = 99;
+ const result = await pending;
+ check('waiting read sees preceding committed write using original key', !result.error && result.value && result.value.label === 'new value');
+ check('waiting read and preceding writer complete', await written && await read);
+ }
+ const seedDeletes = async keys => {
+ const tx = db.transaction('deletes','readwrite'), completion = done(tx), store = tx.objectStore('deletes');
+ store.clear();
+ keys.forEach((key,i) => store.put({id:i+1},key));
+ if (!await completion) throw new Error('delete setup aborted');
+ };
+ for (const mode of ['pending','started']) {
+ for (const [i, [label, create]] of variants.entries()) {
+ const expected = seeds.find(entry => entry[0] === label)[1];
+ await seedDeletes([expected]);
+ const unblocked = mode === 'pending' ? block('deletes') : Promise.resolve(true);
+ const tx = db.transaction('deletes','readwrite'), completion = done(tx), store = tx.objectStore('deletes');
+ if (mode === 'started') await request(store.get('barrier'));
+ const input = create(), pending = request(store.delete(input.key));
+ input.mutate();
+ const result = await pending;
+ const count = await request(store.count());
+ check(`${mode} delete input ${i}`, !result.error && result.value === undefined && count.value === 0 && (!input.reads || input.reads() === 1));
+ check(`${mode} delete input ${i} completes`, await completion && await unblocked);
+ }
+ }
+ const ranges = [
+ [() => IDBKeyRange.bound(2,4), [1,5]],
+ [() => IDBKeyRange.bound(2,4,true), [1,2,5]],
+ [() => IDBKeyRange.bound(2,4,false,true), [1,4,5]],
+ [() => IDBKeyRange.bound(2,4,true,true), [1,2,4,5]],
+ [() => IDBKeyRange.lowerBound(3), [1,2]],
+ [() => IDBKeyRange.upperBound(3,true), [3,4,5]],
+ [() => IDBKeyRange.only(3), [1,2,4,5]],
+ [() => IDBKeyRange.bound(10,20), [1,2,3,4,5]]
+ ];
+ for (const mode of ['pending','started']) {
+ for (const [i,[range,expected]] of ranges.entries()) {
+ await seedDeletes([1,2,3,4,5]);
+ const unblocked = mode === 'pending' ? block('deletes') : Promise.resolve(true);
+ const tx = db.transaction('deletes','readwrite'), completion = done(tx), store = tx.objectStore('deletes');
+ if (mode === 'started') await request(store.get('barrier'));
+ let result;
+ try { result = await request(store.delete(range())); }
+ catch (error) { result = {error}; }
+ const keys = await request(store.getAllKeys());
+ const indexKeys = await request(store.index('byId').getAllKeys());
+ check(`${mode} delete range ${i}`, !result.error && result.value === undefined && JSON.stringify(keys.value) === JSON.stringify(expected));
+ check(`${mode} delete range ${i} index agrees`, JSON.stringify(indexKeys.value) === JSON.stringify(expected));
+ check(`${mode} delete range ${i} completes`, await completion && await unblocked);
+ }
+ }
+ {
+ const tx = db.transaction('deletes'), completion = done(tx), store = tx.objectStore('deletes');
+ let reads = 0, error;
+ const key = Object.defineProperty([],0,{get(){reads++;throw new Error('conversion');}});
+ try { store.delete(key); } catch (caught) { error = caught; }
+ check('readonly delete rejects before key conversion', error && error.name === 'ReadOnlyError' && reads === 0);
+ check('readonly rejection leaves transaction usable', (await request(store.count())).value === 5);
+ check('readonly transaction completes', await completion);
+ }
+ {
+ await seedDeletes([1,2,3,4,5]);
+ const tx = db.transaction('deletes','readwrite'), completion = done(tx), store = tx.objectStore('deletes');
+ let deleted;
+ try { deleted = request(store.delete(IDBKeyRange.bound(2,4))); }
+ catch (error) { deleted = Promise.resolve({error}); }
+ tx.abort();
+ await deleted;
+ check('range delete transaction aborts', !await completion);
+ const reader = db.transaction('deletes'), read = done(reader);
+ const result = await request(reader.objectStore('deletes').getAllKeys());
+ check('range deletion rolls back', JSON.stringify(result.value) === '[1,2,3,4,5]');
+ check('rollback verification completes', await read);
+ }
+ } finally { db.close(); }
+ await request(indexedDB.deleteDatabase(name));
+ return {state:checks.every(check => check.pass)?'pass':'fail',checks};
+}
diff --git a/moli-core/tests/web_apis/indexed_db_transaction.rs b/moli-core/tests/web_apis/indexed_db_transaction.rs
new file mode 100644
index 000000000..fcca85afa
--- /dev/null
+++ b/moli-core/tests/web_apis/indexed_db_transaction.rs
@@ -0,0 +1,27 @@
+use super::pipe_disturbed::run_probe;
+use super::*;
+
+#[tokio::test(flavor = "multi_thread")]
+async fn indexed_db_queries_snapshot_arguments_and_delete_key_ranges() -> Result<()> {
+ let server = FixtureServer::spawn().await?;
+ let browser = Browser::new(AppConfig::default())?;
+ let fixture = include_str!("fixtures/indexeddb-query-snapshots.js");
+ for target in ["window", "child", "worker"] {
+ let source = format!(
+ "{fixture}\nquerySnapshotProbe('query-snapshots-{target}').then(finish, error => finish({{state: 'error', error: String(error), checks: queryChecks}}));"
+ );
+ let result = tokio::time::timeout(
+ Duration::from_secs(30),
+ run_probe(&browser, &server, target, &source),
+ )
+ .await??;
+ assert_eq!(result["state"], "pass", "{target}: {result}");
+ assert_eq!(
+ result["checks"].as_array().unwrap().len(),
+ 308,
+ "{target}: {result}"
+ );
+ }
+ server.shutdown().await;
+ Ok(())
+}
diff --git a/moli-core/tests/web_apis/pipe_disturbed.rs b/moli-core/tests/web_apis/pipe_disturbed.rs
index 93f4e51fc..4f08b9779 100644
--- a/moli-core/tests/web_apis/pipe_disturbed.rs
+++ b/moli-core/tests/web_apis/pipe_disturbed.rs
@@ -40,7 +40,7 @@ fn markup_url(server: &FixtureServer, markup: &str) -> String {
url.into()
}
-async fn run_probe(
+pub(super) async fn run_probe(
browser: &Browser,
server: &FixtureServer,
target: &str,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors.rs
index f721bb201..bb41ae933 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors.rs
@@ -7,8 +7,8 @@ mod surface;
pub(in crate::context_bootstrap::indexed_db) use self::direction::{
apply_cursor_direction, apply_index_collection_direction,
- apply_object_store_collection_direction, cursor_direction_from_cursor,
- cursor_direction_to_value, parse_cursor_direction, parse_cursor_direction_with_context,
+ apply_object_store_collection_direction, cursor_direction_from_cursor, parse_cursor_direction,
+ parse_cursor_direction_with_context,
};
use self::entries::cursor_entries_to_js_array;
pub(in crate::context_bootstrap::indexed_db) use self::entries::cursor_entry_object;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors/direction.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors/direction.rs
index f5754de4e..90f4a70f1 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors/direction.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors/direction.rs
@@ -21,13 +21,6 @@ impl From<CursorDirectionWebIdl> for CursorDirection {
}
}
-pub(in crate::context_bootstrap::indexed_db) fn cursor_direction_to_value<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- direction: CursorDirection,
-) -> v8::Local<'s, v8::Value> {
- v8str(scope, direction.as_str()).into()
-}
-
pub(in crate::context_bootstrap::indexed_db) fn parse_cursor_direction<'s>(
scope: &mut v8::PinScope<'s, '_>,
value: v8::Local<'s, v8::Value>,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/keys/value.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/keys/value.rs
index edd508300..b5eb3b03c 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/keys/value.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/keys/value.rs
@@ -124,15 +124,6 @@ pub(in crate::context_bootstrap::indexed_db) fn key_to_js_value<'s>(
}
}
-pub(in crate::context_bootstrap::indexed_db) fn optional_count_to_value<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- count: Option<usize>,
-) -> v8::Local<'s, v8::Value> {
- count
- .map(|count| v8::Number::new(scope, count as f64).into())
- .unwrap_or_else(|| v8::undefined(scope).into())
-}
-
pub(in crate::context_bootstrap::indexed_db) fn parse_optional_count<'s>(
scope: &mut v8::PinScope<'s, '_>,
value: v8::Local<'s, v8::Value>,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/objects/creation/transaction.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/objects/creation/transaction.rs
index adcdd584b..b3d756707 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/objects/creation/transaction.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/objects/creation/transaction.rs
@@ -34,10 +34,10 @@ pub(in crate::context_bootstrap::indexed_db) fn create_transaction_object<'s>(
store_names: &[String],
) -> Option<v8::Local<'s, v8::Object>> {
let handle_raw = handle.map(|handle| handle.into_raw() as f64);
- let mode: &'static str = mode.into();
+ let mode_label: &'static str = mode.into();
let db_key = object_string_property(scope, db, INDEXED_DB_DATABASE_KEY_SLOT);
let object_store_names = new_idb_dom_string_list(scope, store_names);
- let tx = IdbTransactionObjectDeclaration::new(db, mode, object_store_names)
+ let tx = IdbTransactionObjectDeclaration::new(db, mode_label, object_store_names)
.bind(scope)
.ok()?;
let storage_scope = indexed_db_typed_storage_scope(scope, db);
@@ -50,6 +50,13 @@ pub(in crate::context_bootstrap::indexed_db) fn create_transaction_object<'s>(
owner,
storage_scope,
);
- register_indexed_db_transaction_lifecycle(scope, tx, handle, handle_raw.is_some(), db_key);
+ register_indexed_db_transaction_lifecycle(
+ scope,
+ tx,
+ handle,
+ mode,
+ handle_raw.is_some(),
+ db_key,
+ );
Some(tx)
}
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/operation_state.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/operation_state.rs
index 554c24eba..a223dee4a 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/operation_state.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/operation_state.rs
@@ -42,172 +42,72 @@ impl IndexedDbCursorOpenOperation {
}
}
-pub(super) enum IndexedDbTransactionOperationInput<'s> {
+pub(super) enum IndexedDbTransactionOperation {
ObjectStoreGet {
- query: v8::Local<'s, v8::Value>,
+ query: IdbKeyRangeQuery,
},
ObjectStoreGetAll {
- query: v8::Local<'s, v8::Value>,
- count: v8::Local<'s, v8::Value>,
- direction: v8::Local<'s, v8::Value>,
+ query: Option<IdbKeyRangeQuery>,
+ count: Option<usize>,
+ direction: CursorDirection,
},
ObjectStoreGetKey {
- query: v8::Local<'s, v8::Value>,
+ query: IdbKeyRangeQuery,
},
ObjectStoreGetAllKeys {
- query: v8::Local<'s, v8::Value>,
- count: v8::Local<'s, v8::Value>,
- direction: v8::Local<'s, v8::Value>,
+ query: Option<IdbKeyRangeQuery>,
+ count: Option<usize>,
+ direction: CursorDirection,
},
ObjectStoreCount {
- query: v8::Local<'s, v8::Value>,
+ query: Option<IdbKeyRangeQuery>,
},
OpenCursor(IndexedDbCursorOpenOperation),
ObjectStoreWrite {
- value: v8::Local<'s, v8::Value>,
- key: v8::Local<'s, v8::Value>,
+ value: v8::Global<v8::Value>,
+ key: v8::Global<v8::Value>,
add_only: bool,
},
ObjectStoreDelete {
- key: v8::Local<'s, v8::Value>,
+ query: IdbKeyRangeQuery,
},
ObjectStoreClear,
IndexGet {
- query: v8::Local<'s, v8::Value>,
+ query: IdbKeyRangeQuery,
},
IndexGetKey {
- query: v8::Local<'s, v8::Value>,
+ query: IdbKeyRangeQuery,
},
IndexGetAll {
- query: v8::Local<'s, v8::Value>,
- count: v8::Local<'s, v8::Value>,
- direction: v8::Local<'s, v8::Value>,
+ query: Option<IdbKeyRangeQuery>,
+ count: Option<usize>,
+ direction: CursorDirection,
},
IndexGetAllKeys {
- query: v8::Local<'s, v8::Value>,
- count: v8::Local<'s, v8::Value>,
- direction: v8::Local<'s, v8::Value>,
+ query: Option<IdbKeyRangeQuery>,
+ count: Option<usize>,
+ direction: CursorDirection,
},
IndexCount {
- query: v8::Local<'s, v8::Value>,
+ query: Option<IdbKeyRangeQuery>,
},
}
+// Query arguments are converted at the API boundary and retained as native snapshots.
+// Write requests retain their existing deferred value/key conversion behavior.
pub(super) struct IndexedDbPendingTransactionOperation {
owner: OwnerDispatchScope,
source: v8::Global<v8::Object>,
request: v8::Global<v8::Object>,
store_name: String,
- kind: IndexedDbPendingTransactionOperationKind,
-}
-
-enum IndexedDbPendingTransactionOperationKind {
- ObjectStoreGet {
- query: v8::Global<v8::Value>,
- },
- ObjectStoreGetAll {
- query: v8::Global<v8::Value>,
- count: v8::Global<v8::Value>,
- direction: v8::Global<v8::Value>,
- },
- ObjectStoreGetKey {
- query: v8::Global<v8::Value>,
- },
- ObjectStoreGetAllKeys {
- query: v8::Global<v8::Value>,
- count: v8::Global<v8::Value>,
- direction: v8::Global<v8::Value>,
- },
- ObjectStoreCount {
- query: v8::Global<v8::Value>,
- },
- OpenCursor(IndexedDbCursorOpenOperation),
- ObjectStoreWrite {
- value: v8::Global<v8::Value>,
- key: v8::Global<v8::Value>,
- add_only: bool,
- },
- ObjectStoreDelete {
- key: v8::Global<v8::Value>,
- },
- ObjectStoreClear,
- IndexGet {
- query: v8::Global<v8::Value>,
- },
- IndexGetKey {
- query: v8::Global<v8::Value>,
- },
- IndexGetAll {
- query: v8::Global<v8::Value>,
- count: v8::Global<v8::Value>,
- direction: v8::Global<v8::Value>,
- },
- IndexGetAllKeys {
- query: v8::Global<v8::Value>,
- count: v8::Global<v8::Value>,
- direction: v8::Global<v8::Value>,
- },
- IndexCount {
- query: v8::Global<v8::Value>,
- },
+ kind: IndexedDbTransactionOperation,
}
pub(super) struct IndexedDbTransactionOperationLocals<'s> {
pub(super) source: v8::Local<'s, v8::Object>,
pub(super) request: v8::Local<'s, v8::Object>,
pub(super) store_name: String,
- pub(super) kind: IndexedDbTransactionOperationKindLocals<'s>,
-}
-
-pub(super) enum IndexedDbTransactionOperationKindLocals<'s> {
- ObjectStoreGet {
- query: v8::Local<'s, v8::Value>,
- },
- ObjectStoreGetAll {
- query: v8::Local<'s, v8::Value>,
- count: v8::Local<'s, v8::Value>,
- direction: v8::Local<'s, v8::Value>,
- },
- ObjectStoreGetKey {
- query: v8::Local<'s, v8::Value>,
- },
- ObjectStoreGetAllKeys {
- query: v8::Local<'s, v8::Value>,
- count: v8::Local<'s, v8::Value>,
- direction: v8::Local<'s, v8::Value>,
- },
- ObjectStoreCount {
- query: v8::Local<'s, v8::Value>,
- },
- OpenCursor(IndexedDbCursorOpenOperation),
- ObjectStoreWrite {
- value: v8::Local<'s, v8::Value>,
- key: v8::Local<'s, v8::Value>,
- add_only: bool,
- },
- ObjectStoreDelete {
- key: v8::Local<'s, v8::Value>,
- },
- ObjectStoreClear,
- IndexGet {
- query: v8::Local<'s, v8::Value>,
- },
- IndexGetKey {
- query: v8::Local<'s, v8::Value>,
- },
- IndexGetAll {
- query: v8::Local<'s, v8::Value>,
- count: v8::Local<'s, v8::Value>,
- direction: v8::Local<'s, v8::Value>,
- },
- IndexGetAllKeys {
- query: v8::Local<'s, v8::Value>,
- count: v8::Local<'s, v8::Value>,
- direction: v8::Local<'s, v8::Value>,
- },
- IndexCount {
- query: v8::Local<'s, v8::Value>,
- },
+ pub(super) kind: IndexedDbTransactionOperation,
}
impl IndexedDbPendingTransactionOperation {
@@ -217,81 +117,8 @@ impl IndexedDbPendingTransactionOperation {
source: v8::Local<'s, v8::Object>,
request: v8::Local<'s, v8::Object>,
store_name: impl Into<String>,
- input: IndexedDbTransactionOperationInput<'s>,
+ kind: IndexedDbTransactionOperation,
) -> Self {
- use IndexedDbPendingTransactionOperationKind as Pending;
- use IndexedDbTransactionOperationInput as Input;
-
- let kind = match input {
- Input::ObjectStoreGet { query } => Pending::ObjectStoreGet {
- query: v8::Global::new(scope, query),
- },
- Input::ObjectStoreGetAll {
- query,
- count,
- direction,
- } => Pending::ObjectStoreGetAll {
- query: v8::Global::new(scope, query),
- count: v8::Global::new(scope, count),
- direction: v8::Global::new(scope, direction),
- },
- Input::ObjectStoreGetKey { query } => Pending::ObjectStoreGetKey {
- query: v8::Global::new(scope, query),
- },
- Input::ObjectStoreGetAllKeys {
- query,
- count,
- direction,
- } => Pending::ObjectStoreGetAllKeys {
- query: v8::Global::new(scope, query),
- count: v8::Global::new(scope, count),
- direction: v8::Global::new(scope, direction),
- },
- Input::ObjectStoreCount { query } => Pending::ObjectStoreCount {
- query: v8::Global::new(scope, query),
- },
- Input::OpenCursor(operation) => Pending::OpenCursor(operation),
- Input::ObjectStoreWrite {
- value,
- key,
- add_only,
- } => Pending::ObjectStoreWrite {
- value: v8::Global::new(scope, value),
- key: v8::Global::new(scope, key),
- add_only,
- },
- Input::ObjectStoreDelete { key } => Pending::ObjectStoreDelete {
- key: v8::Global::new(scope, key),
- },
- Input::ObjectStoreClear => Pending::ObjectStoreClear,
- Input::IndexGet { query } => Pending::IndexGet {
- query: v8::Global::new(scope, query),
- },
- Input::IndexGetKey { query } => Pending::IndexGetKey {
- query: v8::Global::new(scope, query),
- },
- Input::IndexGetAll {
- query,
- count,
- direction,
- } => Pending::IndexGetAll {
- query: v8::Global::new(scope, query),
- count: v8::Global::new(scope, count),
- direction: v8::Global::new(scope, direction),
- },
- Input::IndexGetAllKeys {
- query,
- count,
- direction,
- } => Pending::IndexGetAllKeys {
- query: v8::Global::new(scope, query),
- count: v8::Global::new(scope, count),
- direction: v8::Global::new(scope, direction),
- },
- Input::IndexCount { query } => Pending::IndexCount {
- query: v8::Global::new(scope, query),
- },
- };
Self {
owner,
source: v8::Global::new(scope, source),
@@ -316,84 +143,11 @@ impl IndexedDbPendingTransactionOperation {
self,
scope: &mut v8::PinScope<'s, '_>,
) -> IndexedDbTransactionOperationLocals<'s> {
- use IndexedDbPendingTransactionOperationKind as Pending;
- use IndexedDbTransactionOperationKindLocals as Locals;
-
- let kind = match self.kind {
- Pending::ObjectStoreGet { query } => Locals::ObjectStoreGet {
- query: v8::Local::new(scope, &query),
- },
- Pending::ObjectStoreGetAll {
- query,
- count,
- direction,
- } => Locals::ObjectStoreGetAll {
- query: v8::Local::new(scope, &query),
- count: v8::Local::new(scope, &count),
- direction: v8::Local::new(scope, &direction),
- },
- Pending::ObjectStoreGetKey { query } => Locals::ObjectStoreGetKey {
- query: v8::Local::new(scope, &query),
- },
- Pending::ObjectStoreGetAllKeys {
- query,
- count,
- direction,
- } => Locals::ObjectStoreGetAllKeys {
- query: v8::Local::new(scope, &query),
- count: v8::Local::new(scope, &count),
- direction: v8::Local::new(scope, &direction),
- },
- Pending::ObjectStoreCount { query } => Locals::ObjectStoreCount {
- query: v8::Local::new(scope, &query),
- },
- Pending::OpenCursor(operation) => Locals::OpenCursor(operation),
- Pending::ObjectStoreWrite {
- value,
- key,
- add_only,
- } => Locals::ObjectStoreWrite {
- value: v8::Local::new(scope, &value),
- key: v8::Local::new(scope, &key),
- add_only,
- },
- Pending::ObjectStoreDelete { key } => Locals::ObjectStoreDelete {
- key: v8::Local::new(scope, &key),
- },
- Pending::ObjectStoreClear => Locals::ObjectStoreClear,
- Pending::IndexGet { query } => Locals::IndexGet {
- query: v8::Local::new(scope, &query),
- },
- Pending::IndexGetKey { query } => Locals::IndexGetKey {
- query: v8::Local::new(scope, &query),
- },
- Pending::IndexGetAll {
- query,
- count,
- direction,
- } => Locals::IndexGetAll {
- query: v8::Local::new(scope, &query),
- count: v8::Local::new(scope, &count),
- direction: v8::Local::new(scope, &direction),
- },
- Pending::IndexGetAllKeys {
- query,
- count,
- direction,
- } => Locals::IndexGetAllKeys {
- query: v8::Local::new(scope, &query),
- count: v8::Local::new(scope, &count),
- direction: v8::Local::new(scope, &direction),
- },
- Pending::IndexCount { query } => Locals::IndexCount {
- query: v8::Local::new(scope, &query),
- },
- };
IndexedDbTransactionOperationLocals {
source: v8::Local::new(scope, &self.source),
request: v8::Local::new(scope, &self.request),
store_name: self.store_name,
- kind,
+ kind: self.kind,
}
}
}
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores.rs
index 2c0906e5d..65498d34e 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores.rs
@@ -1,21 +1,20 @@
use super::{
CursorDirection, CursorSnapshotEntry, INDEXED_DB_TRANSACTION_ACTIVE_SLOT,
INDEXED_DB_TRANSACTION_STARTED_SLOT, IdbKeyRangeQuery, IndexInfo, IndexOptions,
- IndexedDbCursorOpenOperation, IndexedDbError, IndexedDbTransactionOperationInput, KeyPath,
+ IndexedDbCursorOpenOperation, IndexedDbError, IndexedDbTransactionOperation, KeyPath,
PreparedObjectStoreWriteError, TransactionHandle, apply_cursor_direction,
apply_index_collection_direction, apply_object_store_collection_direction, compare_idb_keys,
- create_index_object, create_key_range_object, create_request_object, cursor_direction_to_value,
- deserialize_js_value, dom_exception_value, enforce_object_store_unique_constraints,
- enqueue_transaction_operation, execute_object_store_clear_request,
- execute_object_store_delete_request, index_info_from_store_metadata,
- indexed_db_database_store_metadata, indexed_db_index_info, indexed_db_index_object_store,
- indexed_db_object_store_database, indexed_db_object_store_name,
+ create_index_object, create_key_range_object, create_request_object, deserialize_js_value,
+ dom_exception_value, enforce_object_store_unique_constraints, enqueue_transaction_operation,
+ execute_object_store_clear_request, execute_object_store_delete_request,
+ index_info_from_store_metadata, indexed_db_database_store_metadata, indexed_db_index_info,
+ indexed_db_index_object_store, indexed_db_object_store_database, indexed_db_object_store_name,
indexed_db_object_store_transaction, key_in_range, key_to_js_value, object_bool_property,
- object_string_property, optional_count_to_value, parse_cursor_direction,
- parse_cursor_direction_with_context, parse_idb_key, parse_idb_key_path, parse_key_or_range,
- parse_key_range_from_value, parse_optional_count, prepare_object_store_write,
- queue_transaction_request, remove_database_index_metadata, request_error_object,
- scan_index_entries, scan_object_store_entries, serialize_js_value, set_database_index_metadata,
+ object_string_property, parse_cursor_direction, parse_cursor_direction_with_context,
+ parse_idb_key, parse_idb_key_path, parse_key_or_range, parse_key_range_from_value,
+ parse_optional_count, prepare_object_store_write, queue_transaction_request,
+ remove_database_index_metadata, request_error_object, scan_index_entries,
+ scan_object_store_entries, serialize_js_value, set_database_index_metadata,
storage_bucket_quota_check_for_object_store, store_request_error, store_request_success,
submit_cursor_open_operation, sync_store_surface_from_metadata, throw_type_error,
transaction_handle_from_value, with_indexed_db_manager,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/collection_args.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/collection_args.rs
index f6d7d4cbb..20da52549 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/collection_args.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/collection_args.rs
@@ -2,8 +2,7 @@ use super::*;
use crate::webidl;
use moli_indexeddb::{GetAllOptionsCandidate, should_parse_get_all_options};
-pub(in crate::context_bootstrap::indexed_db::stores) struct CollectionRequestArgs<'s> {
- pub(in crate::context_bootstrap::indexed_db::stores) query_value: v8::Local<'s, v8::Value>,
+pub(in crate::context_bootstrap::indexed_db::stores) struct CollectionRequestArgs {
pub(in crate::context_bootstrap::indexed_db::stores) query: Option<IdbKeyRangeQuery>,
pub(in crate::context_bootstrap::indexed_db::stores) count: Option<usize>,
pub(in crate::context_bootstrap::indexed_db::stores) direction: CursorDirection,
@@ -18,7 +17,7 @@ pub(in crate::context_bootstrap::indexed_db::stores) fn parse_collection_request
scope: &mut v8::PinScope<'s, '_>,
args: &v8::FunctionCallbackArguments<'s>,
operation_name: &'static str,
-) -> Result<CollectionRequestArgs<'s>, CollectionRequestArgsError> {
+) -> Result<CollectionRequestArgs, CollectionRequestArgsError> {
let positional_query = args.get(0);
let parsed =
if args.length() == 1 && should_parse_get_all_options_value(scope, positional_query) {
@@ -32,7 +31,6 @@ pub(in crate::context_bootstrap::indexed_db::stores) fn parse_collection_request
let query = parse_key_or_range(scope, query_value)
.map_err(|_| CollectionRequestArgsError::InvalidQuery)?;
Ok(CollectionRequestArgs {
- query_value,
query,
count,
direction,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/collection/get_all.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/collection/get_all.rs
index f08ec963c..64fecf05b 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/collection/get_all.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/collection/get_all.rs
@@ -36,18 +36,16 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_index_get_all_callback<'s>(
if !object_bool_property(scope, transaction, INDEXED_DB_TRANSACTION_STARTED_SLOT)
.unwrap_or(false)
{
- let count_value = optional_count_to_value(scope, parsed.count);
- let direction_value = cursor_direction_to_value(scope, parsed.direction);
enqueue_transaction_operation(
scope,
transaction,
index,
request,
&store_name,
- IndexedDbTransactionOperationInput::IndexGetAll {
- query: parsed.query_value,
- count: count_value,
- direction: direction_value,
+ IndexedDbTransactionOperation::IndexGetAll {
+ query: parsed.query,
+ count: parsed.count,
+ direction: parsed.direction,
},
);
rv.set(request.into());
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/collection/get_all_keys.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/collection/get_all_keys.rs
index 639497c0e..c10cd3340 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/collection/get_all_keys.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/collection/get_all_keys.rs
@@ -36,18 +36,16 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_index_get_all_keys_callback<
if !object_bool_property(scope, transaction, INDEXED_DB_TRANSACTION_STARTED_SLOT)
.unwrap_or(false)
{
- let count_value = optional_count_to_value(scope, parsed.count);
- let direction_value = cursor_direction_to_value(scope, parsed.direction);
enqueue_transaction_operation(
scope,
transaction,
index,
request,
&store_name,
- IndexedDbTransactionOperationInput::IndexGetAllKeys {
- query: parsed.query_value,
- count: count_value,
- direction: direction_value,
+ IndexedDbTransactionOperation::IndexGetAllKeys {
+ query: parsed.query,
+ count: parsed.count,
+ direction: parsed.direction,
},
);
rv.set(request.into());
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/count.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/count.rs
index b0487960c..003dd879b 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/count.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/count.rs
@@ -49,7 +49,7 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_index_count_callback<'s>(
index,
request,
&store_name,
- IndexedDbTransactionOperationInput::IndexCount { query: query_value },
+ IndexedDbTransactionOperation::IndexCount { query },
);
rv.set(request.into());
return;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/single/get.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/single/get.rs
index 1d84b952f..46528e766 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/single/get.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/single/get.rs
@@ -47,9 +47,7 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_index_get_callback<'s>(
index,
request,
&store_name,
- IndexedDbTransactionOperationInput::IndexGet {
- query: parsed.query,
- },
+ IndexedDbTransactionOperation::IndexGet { query },
);
rv.set(request.into());
return;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/single/get_key.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/single/get_key.rs
index dd560b3db..5e337f395 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/single/get_key.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/index/read/single/get_key.rs
@@ -47,9 +47,7 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_index_get_key_callback<'s>(
index,
request,
&store_name,
- IndexedDbTransactionOperationInput::IndexGetKey {
- query: parsed.query,
- },
+ IndexedDbTransactionOperation::IndexGetKey { query },
);
rv.set(request.into());
return;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/collection/get_all.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/collection/get_all.rs
index d72656ad2..9ccb2eef9 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/collection/get_all.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/collection/get_all.rs
@@ -36,18 +36,16 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_get_all_callbac
if !object_bool_property(scope, transaction, INDEXED_DB_TRANSACTION_STARTED_SLOT)
.unwrap_or(false)
{
- let count_value = optional_count_to_value(scope, parsed.count);
- let direction_value = cursor_direction_to_value(scope, parsed.direction);
enqueue_transaction_operation(
scope,
transaction,
store,
request,
&store_name,
- IndexedDbTransactionOperationInput::ObjectStoreGetAll {
- query: parsed.query_value,
- count: count_value,
- direction: direction_value,
+ IndexedDbTransactionOperation::ObjectStoreGetAll {
+ query: parsed.query,
+ count: parsed.count,
+ direction: parsed.direction,
},
);
rv.set(request.into());
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/collection/get_all_keys.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/collection/get_all_keys.rs
index 1e0fcb5bd..2001e20ba 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/collection/get_all_keys.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/collection/get_all_keys.rs
@@ -36,18 +36,16 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_get_all_keys_ca
if !object_bool_property(scope, transaction, INDEXED_DB_TRANSACTION_STARTED_SLOT)
.unwrap_or(false)
{
- let count_value = optional_count_to_value(scope, parsed.count);
- let direction_value = cursor_direction_to_value(scope, parsed.direction);
enqueue_transaction_operation(
scope,
transaction,
store,
request,
&store_name,
- IndexedDbTransactionOperationInput::ObjectStoreGetAllKeys {
- query: parsed.query_value,
- count: count_value,
- direction: direction_value,
+ IndexedDbTransactionOperation::ObjectStoreGetAllKeys {
+ query: parsed.query,
+ count: parsed.count,
+ direction: parsed.direction,
},
);
rv.set(request.into());
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/count.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/count.rs
index 584651ed4..6a28f7209 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/count.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/count.rs
@@ -49,7 +49,7 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_count_callback<
store,
request,
&store_name,
- IndexedDbTransactionOperationInput::ObjectStoreCount { query: query_value },
+ IndexedDbTransactionOperation::ObjectStoreCount { query },
);
rv.set(request.into());
return;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/single/get.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/single/get.rs
index 42802ee89..2a0046d00 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/single/get.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/single/get.rs
@@ -47,9 +47,7 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_get_callback<'s
store,
request,
&store_name,
- IndexedDbTransactionOperationInput::ObjectStoreGet {
- query: parsed.query,
- },
+ IndexedDbTransactionOperation::ObjectStoreGet { query },
);
rv.set(request.into());
return;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/single/get_key.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/single/get_key.rs
index 7e8239a15..edac0560f 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/single/get_key.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/read/single/get_key.rs
@@ -47,9 +47,7 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_get_key_callbac
store,
request,
&store_name,
- IndexedDbTransactionOperationInput::ObjectStoreGetKey {
- query: parsed.query,
- },
+ IndexedDbTransactionOperation::ObjectStoreGetKey { query },
);
rv.set(request.into());
return;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/write/delete_clear.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/write/delete_clear.rs
index aca4f459e..cfd3fca97 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/write/delete_clear.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/write/delete_clear.rs
@@ -1,4 +1,6 @@
use super::*;
+use crate::context_bootstrap::indexed_db::indexed_db_transaction_mode;
+use moli_indexeddb::TransactionMode;
#[derive(webidl::WebIdlArgs)]
#[webidl(prefix = "IDBObjectStore.delete")]
@@ -16,7 +18,12 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_delete_callback
return;
};
let store = args.this();
- let Some((request, transaction)) = create_store_request(scope, store) else {
+ let Some(transaction) =
+ indexed_db_object_store_transaction(scope, store).filter(|transaction| {
+ object_bool_property(scope, *transaction, INDEXED_DB_TRANSACTION_ACTIVE_SLOT)
+ .unwrap_or(false)
+ })
+ else {
let error = dom_exception_value(
scope,
"The transaction is not active.",
@@ -26,16 +33,34 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_delete_callback
return;
};
let Some(store_name) = indexed_db_object_store_name(scope, store) else {
- rv.set(request.into());
return;
};
- match parse_idb_key(scope, parsed.key) {
- Ok(Some(_)) => {}
- _ => {
- throw_type_error(scope, "Failed to execute 'delete': invalid key.");
+ if indexed_db_transaction_mode(scope, transaction) == Some(TransactionMode::ReadOnly) {
+ let error = dom_exception_value(scope, "The transaction is readonly.", "ReadOnlyError");
+ scope.throw_exception(error);
+ return;
+ }
+ let query = match parse_key_or_range(scope, parsed.key) {
+ Ok(Some(query)) => query,
+ Ok(None) => {
+ let error = dom_exception_value(
+ scope,
+ "The query is not a valid key or key range.",
+ "DataError",
+ );
+ scope.throw_exception(error);
return;
}
- }
+ Err(message) => {
+ let error = dom_exception_value(scope, message, "DataError");
+ scope.throw_exception(error);
+ return;
+ }
+ };
+ let Some(request) = create_request_object(scope, store.into(), transaction) else {
+ return;
+ };
+ queue_transaction_request(scope, transaction, request);
if !object_bool_property(scope, transaction, INDEXED_DB_TRANSACTION_STARTED_SLOT)
.unwrap_or(false)
{
@@ -45,7 +70,7 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_delete_callback
store,
request,
&store_name,
- IndexedDbTransactionOperationInput::ObjectStoreDelete { key: parsed.key },
+ IndexedDbTransactionOperation::ObjectStoreDelete { query },
);
rv.set(request.into());
return;
@@ -59,7 +84,7 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_delete_callback
scope.throw_exception(error);
return;
};
- execute_object_store_delete_request(scope, request, handle, &store_name, parsed.key);
+ execute_object_store_delete_request(scope, request, handle, &store_name, &query);
rv.set(request.into());
}
@@ -91,7 +116,7 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_object_store_clear_callback<
store,
request,
&store_name,
- IndexedDbTransactionOperationInput::ObjectStoreClear,
+ IndexedDbTransactionOperation::ObjectStoreClear,
);
rv.set(request.into());
return;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/write/put_add/operation/enqueue.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/write/put_add/operation/enqueue.rs
index 07ebd3ecf..e166450b9 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/write/put_add/operation/enqueue.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/stores/object_store/write/put_add/operation/enqueue.rs
@@ -10,13 +10,15 @@ pub(super) fn enqueue_deferred_object_store_write<'s>(
key: v8::Local<'s, v8::Value>,
add_only: bool,
) {
+ let value = v8::Global::new(scope, value);
+ let key = v8::Global::new(scope, key);
enqueue_transaction_operation(
scope,
transaction,
store,
request,
store_name,
- IndexedDbTransactionOperationInput::ObjectStoreWrite {
+ IndexedDbTransactionOperation::ObjectStoreWrite {
value,
key,
add_only,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks.rs
index 5ed6ce087..294d15835 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks.rs
@@ -8,10 +8,10 @@ use super::{
INDEXED_DB_TRANSACTION_ABORTED_SLOT, INDEXED_DB_TRANSACTION_ACTIVE_SLOT,
INDEXED_DB_TRANSACTION_COMMIT_SCHEDULED_SLOT, INDEXED_DB_TRANSACTION_FINISHED_SLOT,
INDEXED_DB_TRANSACTION_HANDLE_SLOT, INDEXED_DB_TRANSACTION_PENDING_SLOT,
- INDEXED_DB_TRANSACTION_START_SCHEDULED_SLOT, INDEXED_DB_TRANSACTION_STARTED_SLOT, IndexInfo,
- IndexedDbCursorOpenOperation, IndexedDbCursorSource, IndexedDbError,
- IndexedDbPendingTransactionOperation, IndexedDbRuntimeArray, IndexedDbStorageScope,
- IndexedDbTransactionOperationInput, IndexedDbTransactionOperationKindLocals, OpenOptions,
+ INDEXED_DB_TRANSACTION_START_SCHEDULED_SLOT, INDEXED_DB_TRANSACTION_STARTED_SLOT,
+ IdbKeyRangeQuery, IndexInfo, IndexedDbCursorOpenOperation, IndexedDbCursorSource,
+ IndexedDbError, IndexedDbPendingTransactionOperation, IndexedDbRuntimeArray,
+ IndexedDbStorageScope, IndexedDbTransactionOperation, OpenOptions,
PreparedObjectStoreWriteError, TransactionHandle, TransactionMode,
apply_index_collection_direction, apply_object_store_collection_direction,
close_indexed_db_database_connection, create_database_object, create_transaction_object,
@@ -26,11 +26,10 @@ use super::{
indexed_db_typed_execution_owner, indexed_db_typed_owner_scope,
indexed_db_typed_task_execution_context, indexed_db_typed_task_execution_owner,
indexed_db_typed_task_id, indexed_db_typed_task_kind, indexed_db_typed_task_owner_scope,
- indexed_db_typed_task_storage_scope, key_to_js_value,
+ indexed_db_typed_task_storage_scope, key_in_range, key_to_js_value,
materialize_cursor_result_in_request_realm, object_bool_property, object_hidden_value,
object_number_property, object_property_as_object, object_store_cursor_snapshot,
- object_string_property, parse_idb_key, parse_key_or_range, parse_optional_count,
- pop_first_indexed_db_task, prepare_object_store_write,
+ object_string_property, parse_idb_key, pop_first_indexed_db_task, prepare_object_store_write,
push_indexed_db_operation_waiting_for_start, push_object_to_indexed_db_runtime_array,
push_unique_object_to_indexed_db_runtime_array, readwrite_transaction_can_start,
refresh_cursor_surface, refresh_database_surface, register_blocked_database_context,
@@ -40,7 +39,7 @@ use super::{
storage_bucket_quota_check_for_object_store, storage_bucket_quota_check_for_transaction,
take_indexed_db_operations_waiting_for_start, take_indexed_db_task_by_id, transaction_db_key,
transaction_handle_from_value, unregister_blocked_database_context,
- unregister_readwrite_transaction, v8_string, v8str, validate_storage_bucket_scope,
+ unregister_readwrite_transaction, v8str, validate_storage_bucket_scope,
with_indexed_db_manager,
};
use crate::util::enqueue_host_microtask;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations.rs
index e11d1b46a..1b185dc4b 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations.rs
@@ -1,6 +1,5 @@
use super::*;
-mod collection_parse;
mod cursor;
mod flush;
mod index;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/collection_parse.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/collection_parse.rs
deleted file mode 100644
index b60b510bb..000000000
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/collection_parse.rs
+++ /dev/null
@@ -1,58 +0,0 @@
-use super::*;
-use crate::context_bootstrap::indexed_db::IdbKeyRangeQuery;
-
-pub(in crate::context_bootstrap::indexed_db::tasks::operations) fn parse_collection_query_and_count<
- 's,
->(
- scope: &mut v8::PinScope<'s, '_>,
- request: v8::Local<'s, v8::Object>,
- query_value: v8::Local<'s, v8::Value>,
- count_value: v8::Local<'s, v8::Value>,
- operation_name: &'static str,
-) -> Option<(Option<IdbKeyRangeQuery>, Option<usize>)> {
- let query = match parse_key_or_range(scope, query_value) {
- Ok(query) => query,
- Err(_) => {
- let error =
- dom_exception_value(scope, invalid_query_message(operation_name), "DataError");
- store_request_error(scope, request, error);
- return None;
- }
- };
- let count =
- match parse_optional_count(scope, count_value, operation_count_prefix(operation_name)) {
- Ok(count) => count,
- Err(error) => {
- let message = error_message_or_fallback(&error);
- let message = v8_string(scope, &message)?;
- let error = v8::Exception::type_error(scope, message);
- store_request_error(scope, request, error);
- return None;
- }
- };
- Some((query, count))
-}
-
-fn operation_count_prefix(operation_name: &str) -> &'static str {
- match operation_name {
- "getAllKeys" | "index.getAllKeys" => "IndexedDB.getAllKeys",
- _ => "IndexedDB.getAll",
- }
-}
-
-fn error_message_or_fallback(error: &crate::webidl::WebIdlError) -> String {
- if error.is_pending_exception() {
- "Failed to execute IndexedDB collection operation: invalid count.".to_owned()
- } else {
- error.to_string()
- }
-}
-
-fn invalid_query_message(operation_name: &str) -> &'static str {
- match operation_name {
- "getAllKeys" => {
- "Failed to execute 'getAllKeys': the query is not a valid key or key range."
- }
- _ => "Failed to execute 'getAll': the query is not a valid key or key range.",
- }
-}
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/cursor.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/cursor.rs
index 97c8cb711..f0251128e 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/cursor.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/cursor.rs
@@ -15,7 +15,7 @@ pub(in crate::context_bootstrap::indexed_db) fn submit_cursor_open_operation<'s>
source,
request,
store_name,
- IndexedDbTransactionOperationInput::OpenCursor(operation),
+ IndexedDbTransactionOperation::OpenCursor(operation),
);
return;
};
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/cursor.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/cursor.rs
index 79d1943d3..b3e0a0b31 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/cursor.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/cursor.rs
@@ -4,7 +4,7 @@ pub(super) fn try_dispatch_cursor_operation<'s>(
scope: &mut v8::PinScope<'s, '_>,
operation: &operation::QueuedTransactionOperation<'s>,
) -> bool {
- let IndexedDbTransactionOperationKindLocals::OpenCursor(cursor) = &operation.kind else {
+ let IndexedDbTransactionOperation::OpenCursor(cursor) = &operation.kind else {
return false;
};
execute_cursor_open_operation(
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/index/read.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/index/read.rs
index 57dbb0288..132543224 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/index/read.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/index/read.rs
@@ -5,68 +5,66 @@ pub(super) fn try_dispatch_index_read_operation<'s>(
operation: &operation::QueuedTransactionOperation<'s>,
) -> bool {
match &operation.kind {
- IndexedDbTransactionOperationKindLocals::IndexGet { query } => {
+ IndexedDbTransactionOperation::IndexGet { query } => {
execute_index_get_request(
scope,
operation.source,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query,
);
}
- IndexedDbTransactionOperationKindLocals::IndexGetKey { query } => {
+ IndexedDbTransactionOperation::IndexGetKey { query } => {
execute_index_get_key_request(
scope,
operation.source,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query,
);
}
- IndexedDbTransactionOperationKindLocals::IndexGetAll {
+ IndexedDbTransactionOperation::IndexGetAll {
query,
count,
direction,
} => {
- let direction = operation::collection_direction_from_value(scope, *direction);
execute_index_get_all_request(
scope,
operation.source,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query.as_ref(),
*count,
- direction,
+ *direction,
);
}
- IndexedDbTransactionOperationKindLocals::IndexGetAllKeys {
+ IndexedDbTransactionOperation::IndexGetAllKeys {
query,
count,
direction,
} => {
- let direction = operation::collection_direction_from_value(scope, *direction);
execute_index_get_all_keys_request(
scope,
operation.source,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query.as_ref(),
*count,
- direction,
+ *direction,
);
}
- IndexedDbTransactionOperationKindLocals::IndexCount { query } => {
+ IndexedDbTransactionOperation::IndexCount { query } => {
execute_index_count_request(
scope,
operation.source,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query.as_ref(),
);
}
_ => return false,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/object_store/read.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/object_store/read.rs
index 051a9092e..17b807b2e 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/object_store/read.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/object_store/read.rs
@@ -5,63 +5,61 @@ pub(super) fn try_dispatch_object_store_read_operation<'s>(
operation: &operation::QueuedTransactionOperation<'s>,
) -> bool {
match &operation.kind {
- IndexedDbTransactionOperationKindLocals::ObjectStoreGet { query } => {
+ IndexedDbTransactionOperation::ObjectStoreGet { query } => {
execute_object_store_get_request(
scope,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query,
);
}
- IndexedDbTransactionOperationKindLocals::ObjectStoreGetAll {
+ IndexedDbTransactionOperation::ObjectStoreGetAll {
query,
count,
direction,
} => {
- let direction = operation::collection_direction_from_value(scope, *direction);
execute_object_store_get_all_request(
scope,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query.as_ref(),
*count,
- direction,
+ *direction,
);
}
- IndexedDbTransactionOperationKindLocals::ObjectStoreGetKey { query } => {
+ IndexedDbTransactionOperation::ObjectStoreGetKey { query } => {
execute_object_store_get_key_request(
scope,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query,
);
}
- IndexedDbTransactionOperationKindLocals::ObjectStoreGetAllKeys {
+ IndexedDbTransactionOperation::ObjectStoreGetAllKeys {
query,
count,
direction,
} => {
- let direction = operation::collection_direction_from_value(scope, *direction);
execute_object_store_get_all_keys_request(
scope,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query.as_ref(),
*count,
- direction,
+ *direction,
);
}
- IndexedDbTransactionOperationKindLocals::ObjectStoreCount { query } => {
+ IndexedDbTransactionOperation::ObjectStoreCount { query } => {
execute_object_store_count_request(
scope,
operation.request,
operation.handle,
&operation.store_name,
- *query,
+ query.as_ref(),
);
}
_ => return false,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/object_store/write.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/object_store/write.rs
index a8cd6f044..85c8dfcad 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/object_store/write.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/object_store/write.rs
@@ -5,32 +5,34 @@ pub(super) fn try_dispatch_object_store_write_operation<'s>(
operation: &operation::QueuedTransactionOperation<'s>,
) -> bool {
match &operation.kind {
- IndexedDbTransactionOperationKindLocals::ObjectStoreWrite {
+ IndexedDbTransactionOperation::ObjectStoreWrite {
value,
key,
add_only,
} => {
+ let value = v8::Local::new(scope, value);
+ let key = v8::Local::new(scope, key);
execute_object_store_write_request(
scope,
operation.source,
operation.request,
operation.handle,
&operation.store_name,
- *value,
- *key,
+ value,
+ key,
*add_only,
);
}
- IndexedDbTransactionOperationKindLocals::ObjectStoreDelete { key } => {
+ IndexedDbTransactionOperation::ObjectStoreDelete { query } => {
execute_object_store_delete_request(
scope,
operation.request,
operation.handle,
&operation.store_name,
- *key,
+ query,
);
}
- IndexedDbTransactionOperationKindLocals::ObjectStoreClear => {
+ IndexedDbTransactionOperation::ObjectStoreClear => {
execute_object_store_clear_request(
scope,
operation.request,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/operation.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/operation.rs
index a96e87de6..f32b8d8ee 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/operation.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/flush/operation.rs
@@ -5,7 +5,7 @@ pub(super) struct QueuedTransactionOperation<'s> {
pub(super) request: v8::Local<'s, v8::Object>,
pub(super) handle: TransactionHandle,
pub(super) store_name: String,
- pub(super) kind: IndexedDbTransactionOperationKindLocals<'s>,
+ pub(super) kind: IndexedDbTransactionOperation,
}
impl<'s> QueuedTransactionOperation<'s> {
@@ -26,17 +26,6 @@ impl<'s> QueuedTransactionOperation<'s> {
}
}
-pub(super) fn collection_direction_from_value<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- direction: v8::Local<'s, v8::Value>,
-) -> CursorDirection {
- direction
- .to_string(scope)
- .map(|value| value.to_rust_string_lossy(scope))
- .and_then(|value| CursorDirection::parse(&value))
- .unwrap_or_else(CursorDirection::default_next)
-}
-
pub(super) fn flush_queued_transaction_operation<'s>(
scope: &mut v8::PinScope<'s, '_>,
transaction: v8::Local<'s, v8::Object>,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection.rs
index 853b5fb5e..c66e794df 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection.rs
@@ -1,5 +1,4 @@
use super::*;
-use crate::context_bootstrap::indexed_db::tasks::operations::collection_parse;
mod get_all;
mod get_all_keys;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection/get_all.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection/get_all.rs
index 26f63b389..2d5d9091e 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection/get_all.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection/get_all.rs
@@ -7,23 +7,14 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_index_get_all_request<'s
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
- count_value: v8::Local<'s, v8::Value>,
+ query: Option<&IdbKeyRangeQuery>,
+ count: Option<usize>,
direction: CursorDirection,
) {
- let Some((query, count)) = collection_parse::parse_collection_query_and_count(
- scope,
- request,
- query_value,
- count_value,
- "getAll",
- ) else {
- return;
- };
let Some(index_info) = parse::index_info_for_collection(scope, index, request) else {
return;
};
- match scan_index_entries(scope, handle, store_name, &index_info, query.as_ref()) {
+ match scan_index_entries(scope, handle, store_name, &index_info, query) {
Ok(entries) => {
let entries = apply_index_collection_direction(entries, direction);
let limit = count.unwrap_or(entries.len());
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection/get_all_keys.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection/get_all_keys.rs
index 44e5e726e..e1fb545ab 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection/get_all_keys.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/collection/get_all_keys.rs
@@ -7,23 +7,14 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_index_get_all_keys_reque
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
- count_value: v8::Local<'s, v8::Value>,
+ query: Option<&IdbKeyRangeQuery>,
+ count: Option<usize>,
direction: CursorDirection,
) {
- let Some((query, count)) = collection_parse::parse_collection_query_and_count(
- scope,
- request,
- query_value,
- count_value,
- "getAllKeys",
- ) else {
- return;
- };
let Some(index_info) = parse::index_info_for_collection(scope, index, request) else {
return;
};
- match scan_index_entries(scope, handle, store_name, &index_info, query.as_ref()) {
+ match scan_index_entries(scope, handle, store_name, &index_info, query) {
Ok(entries) => {
let entries = apply_index_collection_direction(entries, direction);
let limit = count.unwrap_or(entries.len());
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/count.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/count.rs
index 46f2aaed7..ad7c6fa2b 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/count.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/count.rs
@@ -6,27 +6,15 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_index_count_request<'s>(
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
+ query: Option<&IdbKeyRangeQuery>,
) {
- let query = match parse_key_or_range(scope, query_value) {
- Ok(query) => query,
- Err(_) => {
- let error = dom_exception_value(
- scope,
- "Failed to execute 'count': the query is not a valid key or key range.",
- "DataError",
- );
- store_request_error(scope, request, error);
- return;
- }
- };
let Some(index_info) = index_info_from_index_object(scope, index) else {
let error =
dom_exception_value(scope, "The requested index was not found.", "NotFoundError");
store_request_error(scope, request, error);
return;
};
- match scan_index_entries(scope, handle, store_name, &index_info, query.as_ref()) {
+ match scan_index_entries(scope, handle, store_name, &index_info, query) {
Ok(entries) => store_request_success(
scope,
request,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/single.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/single.rs
index 7dc4b9aa1..caf44a3b4 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/single.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/index/read/single.rs
@@ -6,27 +6,15 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_index_get_request<'s>(
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
+ query: &IdbKeyRangeQuery,
) {
- let query = match parse_key_or_range(scope, query_value) {
- Ok(Some(query)) => query,
- _ => {
- let error = dom_exception_value(
- scope,
- "Failed to execute 'get': the query is not a valid key or key range.",
- "DataError",
- );
- store_request_error(scope, request, error);
- return;
- }
- };
let Some(index_info) = index_info_from_index_object(scope, index) else {
let error =
dom_exception_value(scope, "The requested index was not found.", "NotFoundError");
store_request_error(scope, request, error);
return;
};
- match scan_index_entries(scope, handle, store_name, &index_info, Some(&query)) {
+ match scan_index_entries(scope, handle, store_name, &index_info, Some(query)) {
Ok(entries) => {
let result = entries
.first()
@@ -47,27 +35,15 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_index_get_key_request<'s
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
+ query: &IdbKeyRangeQuery,
) {
- let query = match parse_key_or_range(scope, query_value) {
- Ok(Some(query)) => query,
- _ => {
- let error = dom_exception_value(
- scope,
- "Failed to execute 'getKey': the query is not a valid key or key range.",
- "DataError",
- );
- store_request_error(scope, request, error);
- return;
- }
- };
let Some(index_info) = index_info_from_index_object(scope, index) else {
let error =
dom_exception_value(scope, "The requested index was not found.", "NotFoundError");
store_request_error(scope, request, error);
return;
};
- match scan_index_entries(scope, handle, store_name, &index_info, Some(&query)) {
+ match scan_index_entries(scope, handle, store_name, &index_info, Some(query)) {
Ok(entries) => {
let result = entries
.first()
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection.rs
index d03dc506e..35f962095 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection.rs
@@ -1,5 +1,4 @@
use super::*;
-use crate::context_bootstrap::indexed_db::tasks::operations::collection_parse;
mod get_all;
mod get_all_keys;
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection/get_all.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection/get_all.rs
index d80743cd9..e8834c9b3 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection/get_all.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection/get_all.rs
@@ -6,20 +6,11 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_object_store_get_all_req
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
- count_value: v8::Local<'s, v8::Value>,
+ query: Option<&IdbKeyRangeQuery>,
+ count: Option<usize>,
direction: CursorDirection,
) {
- let Some((query, count)) = collection_parse::parse_collection_query_and_count(
- scope,
- request,
- query_value,
- count_value,
- "getAll",
- ) else {
- return;
- };
- match scan_object_store_entries(scope, handle, store_name, query.as_ref()) {
+ match scan_object_store_entries(scope, handle, store_name, query) {
Ok(entries) => {
let entries = apply_object_store_collection_direction(entries, direction);
let limit = count.unwrap_or(entries.len());
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection/get_all_keys.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection/get_all_keys.rs
index 436bd94d5..bb63657e9 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection/get_all_keys.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/collection/get_all_keys.rs
@@ -6,20 +6,11 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_object_store_get_all_key
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
- count_value: v8::Local<'s, v8::Value>,
+ query: Option<&IdbKeyRangeQuery>,
+ count: Option<usize>,
direction: CursorDirection,
) {
- let Some((query, count)) = collection_parse::parse_collection_query_and_count(
- scope,
- request,
- query_value,
- count_value,
- "getAllKeys",
- ) else {
- return;
- };
- match scan_object_store_entries(scope, handle, store_name, query.as_ref()) {
+ match scan_object_store_entries(scope, handle, store_name, query) {
Ok(entries) => {
let entries = apply_object_store_collection_direction(entries, direction);
let limit = count.unwrap_or(entries.len());
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/count.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/count.rs
index d9c999db6..d6c9bb72d 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/count.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/count.rs
@@ -5,21 +5,9 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_object_store_count_reque
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
+ query: Option<&IdbKeyRangeQuery>,
) {
- let query = match parse_key_or_range(scope, query_value) {
- Ok(query) => query,
- Err(_) => {
- let error = dom_exception_value(
- scope,
- "Failed to execute 'count': the query is not a valid key or key range.",
- "DataError",
- );
- store_request_error(scope, request, error);
- return;
- }
- };
- match scan_object_store_entries(scope, handle, store_name, query.as_ref()) {
+ match scan_object_store_entries(scope, handle, store_name, query) {
Ok(entries) => store_request_success(
scope,
request,
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/single.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/single.rs
index aa94ca0da..53bcd1543 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/single.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/read/single.rs
@@ -5,21 +5,9 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_object_store_get_request
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
+ query: &IdbKeyRangeQuery,
) {
- let query = match parse_key_or_range(scope, query_value) {
- Ok(Some(query)) => query,
- _ => {
- let error = dom_exception_value(
- scope,
- "Failed to execute 'get': the query is not a valid key or key range.",
- "DataError",
- );
- store_request_error(scope, request, error);
- return;
- }
- };
- match scan_object_store_entries(scope, handle, store_name, Some(&query)) {
+ match scan_object_store_entries(scope, handle, store_name, Some(query)) {
Ok(entries) => {
let result = entries
.first()
@@ -39,21 +27,9 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_object_store_get_key_req
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- query_value: v8::Local<'s, v8::Value>,
+ query: &IdbKeyRangeQuery,
) {
- let query = match parse_key_or_range(scope, query_value) {
- Ok(Some(query)) => query,
- _ => {
- let error = dom_exception_value(
- scope,
- "Failed to execute 'getKey': the query is not a valid key or key range.",
- "DataError",
- );
- store_request_error(scope, request, error);
- return;
- }
- };
- match scan_object_store_entries(scope, handle, store_name, Some(&query)) {
+ match scan_object_store_entries(scope, handle, store_name, Some(query)) {
Ok(entries) => {
let result = entries
.first()
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/write/delete_clear.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/write/delete_clear.rs
index 626c0f46c..d351976ab 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/write/delete_clear.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/object_store/write/delete_clear.rs
@@ -5,21 +5,27 @@ pub(in crate::context_bootstrap::indexed_db) fn execute_object_store_delete_requ
request: v8::Local<'s, v8::Object>,
handle: TransactionHandle,
store_name: &str,
- key_value: v8::Local<'s, v8::Value>,
+ query: &IdbKeyRangeQuery,
) {
- let key = match parse_idb_key(scope, key_value) {
- Ok(Some(key)) => key,
- _ => {
- let error = dom_exception_value(
- scope,
- "Failed to execute 'delete': invalid key.",
- "TypeError",
- );
- store_request_error(scope, request, error);
- return;
+ let result = with_indexed_db_manager(scope, |manager| {
+ // Preserve the direct lookup for a single key. Ranges are evaluated
+ // when the operation executes, after earlier writes in the transaction.
+ if let Some(key) = &query.lower
+ && query.upper.as_ref() == Some(key)
+ && !query.lower_open
+ && !query.upper_open
+ {
+ return manager.delete(handle, store_name, key);
+ }
+ let entries = manager.entries(handle, store_name)?;
+ for (key, _) in entries {
+ if key_in_range(&key, query) {
+ manager.delete(handle, store_name, &key)?;
+ }
}
- };
- match with_indexed_db_manager(scope, |manager| manager.delete(handle, store_name, &key)) {
+ Ok(())
+ });
+ match result {
Ok(()) => store_request_success(scope, request, v8::undefined(scope).into()),
Err(error) => {
let error = request_error_object(scope, &error);
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/queue_state.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/queue_state.rs
index 00b60a137..7d3199e8c 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/queue_state.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/tasks/operations/queue_state.rs
@@ -28,7 +28,7 @@ pub(in crate::context_bootstrap::indexed_db) fn enqueue_transaction_operation<'s
source: v8::Local<'s, v8::Object>,
request: v8::Local<'s, v8::Object>,
store_name: &str,
- input: IndexedDbTransactionOperationInput<'s>,
+ input: IndexedDbTransactionOperation,
) {
let transaction_context = transaction
.get_creation_context(scope)
diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/typed_state.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/typed_state.rs
index c50655119..2a3db2941 100644
--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/typed_state.rs
+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/typed_state.rs
@@ -352,6 +352,7 @@ impl IndexedDbRequestLifecycleState {
}
struct IndexedDbTransactionLifecycleState {
+ mode: TransactionMode,
handle: Option<TransactionHandle>,
active: bool,
finished: bool,
@@ -367,8 +368,14 @@ struct IndexedDbTransactionLifecycleState {
}
impl IndexedDbTransactionLifecycleState {
- fn new(handle: Option<TransactionHandle>, started: bool, db_key: Option<String>) -> Self {
+ fn new(
+ handle: Option<TransactionHandle>,
+ mode: TransactionMode,
+ started: bool,
+ db_key: Option<String>,
+ ) -> Self {
Self {
+ mode,
handle,
active: true,
finished: false,
@@ -686,17 +693,27 @@ pub(super) fn register_indexed_db_transaction_lifecycle<'s>(
scope: &mut v8::PinScope<'s, '_>,
transaction: v8::Local<'s, v8::Object>,
handle: Option<TransactionHandle>,
+ mode: TransactionMode,
started: bool,
db_key: Option<String>,
) {
let Some(id) = indexed_db_typed_state_id(scope, transaction) else {
return;
};
- let state = IndexedDbTransactionLifecycleState::new(handle, started, db_key);
+ let state = IndexedDbTransactionLifecycleState::new(handle, mode, started, db_key);
let table = indexed_db_runtime_state_table_for_object(scope, transaction);
table.borrow_mut().transactions.insert(id, state);
}
+pub(super) fn indexed_db_transaction_mode<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ transaction: v8::Local<'s, v8::Object>,
+) -> Option<TransactionMode> {
+ let id = indexed_db_typed_state_id(scope, transaction)?;
+ let table = indexed_db_runtime_state_table_for_object(scope, transaction);
+ table.borrow().transactions.get(&id).map(|state| state.mode)
+}
+
pub(in crate::context_bootstrap::indexed_db) fn schedule_indexed_db_transaction_deactivation_after_microtask_checkpoint<
's,
>(
diff --git a/moli-wpt-compat/fixtures/wpt/ported/indexeddb/idb-query-boundary-conversion-basic.html b/moli-wpt-compat/fixtures/wpt/ported/indexeddb/idb-query-boundary-conversion-basic.html
index dddd54aae..8fd814125 100644
--- a/moli-wpt-compat/fixtures/wpt/ported/indexeddb/idb-query-boundary-conversion-basic.html
+++ b/moli-wpt-compat/fixtures/wpt/ported/indexeddb/idb-query-boundary-conversion-basic.html
@@ -117,7 +117,7 @@ promise_test(async () => {
"objectStore.delete key is required"
);
assert_throws_name(
- "TypeError",
+ "DataError",
() => writeStore.delete(undefined),
"objectStore.delete validates present undefined as a key"
);