mirror of
https://github.com/lexmount/moli.git
synced 2026-11-17 08:08:43 +00:00
fix(indexeddb): validate pending cursor iteration
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
globalThis.navigationChecks = [];
|
||||
async function cursorNavigationProbe(name = 'cursor-navigation-' + Math.random()) {
|
||||
const checks = globalThis.navigationChecks;
|
||||
const check = (label, pass, actual = '') => { checks.push({label, pass: !!pass, actual: String(actual)}); return !!pass; };
|
||||
const equal = (label, actual, expected) => check(label, actual === expected, actual);
|
||||
const throws = (label, call, expected, realm = globalThis) => {
|
||||
try { call(); return check(label, false, 'accepted'); }
|
||||
catch (error) { return check(label, error.name === expected && error instanceof (expected === 'TypeError' ? realm.TypeError : realm.DOMException), error.name); }
|
||||
};
|
||||
const request = r => new Promise((resolve, reject) => { r.onsuccess = () => resolve(r.result); r.onerror = event => { event.preventDefault(); reject(r.error); }; });
|
||||
const done = tx => new Promise(resolve => { tx.oncomplete = () => resolve('complete'); tx.onabort = () => resolve('abort'); });
|
||||
const methods = Object.fromEntries(['advance', 'continue', 'continuePrimaryKey', 'update', 'delete'].map(key => [key, IDBCursor.prototype[key]]));
|
||||
const sourceOf = (store, kind) => kind === 'store' ? store : store.index('i');
|
||||
const seed = db => {
|
||||
const store = db.createObjectStore('s'); store.createIndex('i', 'index');
|
||||
for (let n = 1; n <= 3; n++) store.put({id: n, index: [n]}, [n]);
|
||||
return store;
|
||||
};
|
||||
const opening = indexedDB.open(name, 1); opening.onupgradeneeded = () => seed(opening.result);
|
||||
const db = await request(opening);
|
||||
let argumentReads = 0;
|
||||
const key = Object.defineProperty([], 0, {get() { argumentReads++; return 2; }});
|
||||
const value = {get id() { argumentReads++; return 2; }};
|
||||
const inactive = (label, cursor, realm = globalThis) => {
|
||||
const p = realm.IDBCursor.prototype;
|
||||
argumentReads = 0;
|
||||
throws(label + ' zero before inactive', () => p.advance.call(cursor, 0), 'TypeError', realm);
|
||||
throws(label + ' required count before inactive', () => p.advance.call(cursor), 'TypeError', realm);
|
||||
throws(label + ' required tuple before inactive', () => p.continuePrimaryKey.call(cursor), 'TypeError', realm);
|
||||
throws(label + ' advance inactive', () => p.advance.call(cursor, 1), 'TransactionInactiveError', realm);
|
||||
throws(label + ' continue inactive', () => p.continue.call(cursor, key), 'TransactionInactiveError', realm);
|
||||
throws(label + ' tuple inactive', () => p.continuePrimaryKey.call(cursor, key, key), 'TransactionInactiveError', realm);
|
||||
throws(label + ' update inactive', () => p.update.call(cursor, value), 'TransactionInactiveError', realm);
|
||||
throws(label + ' delete inactive', () => p.delete.call(cursor), 'TransactionInactiveError', realm);
|
||||
equal(label + ' inactive arguments untouched', argumentReads, 0);
|
||||
};
|
||||
let completedCursor;
|
||||
try {
|
||||
for (const mode of ['readonly', 'readwrite']) for (const kind of ['store', 'index']) for (const direction of ['next', 'prev', 'nextunique', 'prevunique']) for (const open of ['openCursor', 'openKeyCursor']) {
|
||||
const tupleAllowed = kind === 'index' && !direction.endsWith('unique');
|
||||
for (const first of tupleAllowed ? ['advance', 'continue', 'continuePrimaryKey'] : ['advance', 'continue']) {
|
||||
const label = [mode, kind, direction, open, first].join(' ');
|
||||
const tx = db.transaction('s', mode), complete = done(tx), r = sourceOf(tx.objectStore('s'), kind)[open](null, direction);
|
||||
const cursor = await request(r), oldKey = cursor.key, oldValue = cursor.value;
|
||||
throws(label + ' rejected zero preserves state', () => methods.advance.call(cursor, 0), 'TypeError');
|
||||
throws(label + ' rejected key preserves state', () => methods.continue.call(cursor, cursor.key), 'DataError');
|
||||
const marker = {};
|
||||
const throwingKey = Object.defineProperty([], 0, {get() { throw marker; }});
|
||||
try { methods.continue.call(cursor, throwingKey); check(label + ' key getter exception', false); }
|
||||
catch (error) { check(label + ' key getter exception', error === marker); }
|
||||
if (!tupleAllowed) {
|
||||
argumentReads = 0;
|
||||
throws(label + ' source or direction before key', () => methods.continuePrimaryKey.call(cursor, key, key), 'InvalidAccessError');
|
||||
equal(label + ' invalid tuple arguments untouched', argumentReads, 0);
|
||||
}
|
||||
methods[first].apply(cursor, first === 'advance' ? [1] : first === 'continue' ? [] : [[2], [2]]);
|
||||
equal(label + ' pending request', r.readyState, 'pending');
|
||||
check(label + ' pending getters retain values', cursor.key === oldKey && cursor.value === oldValue);
|
||||
let valid = throws(label + ' zero before pending', () => methods.advance.call(cursor, 0), 'TypeError');
|
||||
argumentReads = 0;
|
||||
valid = throws(label + ' count conversion before pending', () => methods.advance.call(cursor, {valueOf() { argumentReads++; return 1; }}), 'InvalidStateError') && valid;
|
||||
equal(label + ' count converted', argumentReads, 1);
|
||||
argumentReads = 0;
|
||||
valid = throws(label + ' continue pending', () => methods.continue.call(cursor, key), 'InvalidStateError') && valid;
|
||||
valid = throws(label + ' tuple pending', () => methods.continuePrimaryKey.call(cursor, key, key), tupleAllowed ? 'InvalidStateError' : 'InvalidAccessError') && valid;
|
||||
valid = throws(label + ' update pending', () => methods.update.call(cursor, value), mode === 'readonly' ? 'ReadOnlyError' : 'InvalidStateError') && valid;
|
||||
valid = throws(label + ' delete pending', () => methods.delete.call(cursor), mode === 'readonly' ? 'ReadOnlyError' : 'InvalidStateError') && valid;
|
||||
equal(label + ' pending keys and value untouched', argumentReads, 0);
|
||||
// A broken baseline may have queued extra requests. Abort that variant
|
||||
// so it cannot mutate the database or corrupt later checks.
|
||||
if (!valid) { tx.abort(); await complete; continue; }
|
||||
check(label + ' next result reuses cursor', await request(r) === cursor);
|
||||
equal(label + ' next position', cursor.key[0], 2);
|
||||
equal(label + ' ready after success', r.readyState, 'done');
|
||||
methods.advance.call(cursor, 100);
|
||||
equal(label + ' exhausted result', await request(r), null);
|
||||
throws(label + ' zero before exhausted', () => methods.advance.call(cursor, 0), 'TypeError');
|
||||
throws(label + ' advance exhausted', () => methods.advance.call(cursor, 1), 'InvalidStateError');
|
||||
argumentReads = 0;
|
||||
throws(label + ' continue exhausted', () => methods.continue.call(cursor, key), 'InvalidStateError');
|
||||
throws(label + ' tuple exhausted', () => methods.continuePrimaryKey.call(cursor, key, key), tupleAllowed ? 'InvalidStateError' : 'InvalidAccessError');
|
||||
equal(label + ' exhausted keys untouched', argumentReads, 0);
|
||||
equal(label + ' completion', await complete, 'complete');
|
||||
inactive(label, cursor);
|
||||
completedCursor = cursor;
|
||||
}
|
||||
}
|
||||
// Count conversion can change the cursor's state. Validate only after it.
|
||||
for (const transition of ['continue', 'abort']) {
|
||||
const tx = db.transaction('s'), complete = done(tx), r = tx.objectStore('s').openCursor(), cursor = await request(r);
|
||||
throws('count conversion triggers ' + transition, () => cursor.advance({valueOf() { if (transition === 'abort') tx.abort(); else cursor.continue(); return 1; }}), transition === 'abort' ? 'TransactionInactiveError' : 'InvalidStateError');
|
||||
await complete;
|
||||
inactive('after ' + transition, cursor);
|
||||
}
|
||||
if (typeof document !== 'undefined' && completedCursor) {
|
||||
const frame = document.createElement('iframe'); document.body.appendChild(frame);
|
||||
try { inactive('foreign callee', completedCursor, frame.contentWindow); }
|
||||
finally { frame.remove(); }
|
||||
}
|
||||
} finally { db.close(); }
|
||||
await request(indexedDB.deleteDatabase(name));
|
||||
|
||||
// Recreating a deleted source under the same name must not revive a cursor.
|
||||
for (const removed of ['store', 'index', 'index-store']) for (const direction of ['next', 'nextunique']) for (const phase of ['ready', 'exhausted']) {
|
||||
const label = ['deleted', removed, direction, phase].join(' '), databaseName = name + label;
|
||||
const r = indexedDB.open(databaseName, 1);
|
||||
let probe;
|
||||
r.onupgradeneeded = () => {
|
||||
const database = r.result, tx = r.transaction, complete = done(tx), store = seed(database);
|
||||
probe = (async () => {
|
||||
const source = removed === 'store' ? store : store.index('i'), cr = source.openCursor(null, direction), cursor = await request(cr);
|
||||
if (phase === 'exhausted') { cursor.advance(100); await request(cr); }
|
||||
if (removed === 'index') { store.deleteIndex('i'); store.createIndex('i', 'index'); }
|
||||
else { database.deleteObjectStore('s'); seed(database); }
|
||||
argumentReads = 0;
|
||||
let valid = throws(label + ' zero before deleted', () => cursor.advance(0), 'TypeError');
|
||||
valid = throws(label + ' advance deleted', () => cursor.advance(1), 'InvalidStateError') && valid;
|
||||
valid = throws(label + ' continue deleted', () => cursor.continue(key), 'InvalidStateError') && valid;
|
||||
valid = throws(label + ' tuple deleted', () => cursor.continuePrimaryKey(key, key), 'InvalidStateError') && valid;
|
||||
valid = throws(label + ' update deleted', () => cursor.update(value), 'InvalidStateError') && valid;
|
||||
valid = throws(label + ' delete deleted', () => cursor.delete(), 'InvalidStateError') && valid;
|
||||
equal(label + ' deleted arguments untouched', argumentReads, 0);
|
||||
if (!valid) tx.abort();
|
||||
await complete;
|
||||
inactive(label + ' inactive', cursor);
|
||||
})();
|
||||
};
|
||||
const opened = await request(r).catch(() => null);
|
||||
await probe;
|
||||
if (opened) opened.close();
|
||||
await request(indexedDB.deleteDatabase(databaseName));
|
||||
}
|
||||
return {state: checks.every(item => item.pass) ? 'pass' : 'fail', checks};
|
||||
}
|
||||
@@ -1,5 +1,26 @@
|
||||
use super::pipe_disturbed::run_probe;
|
||||
use super::*;
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn indexed_db_cursor_navigation_validates_state_in_spec_order() -> Result<()> {
|
||||
let server = FixtureServer::spawn().await?;
|
||||
let browser = Browser::new(AppConfig::default())?;
|
||||
let fixture = include_str!("fixtures/indexeddb-cursor-navigation.js");
|
||||
for target in ["window", "child", "worker"] {
|
||||
let source = format!(
|
||||
"{fixture}\ncursorNavigationProbe('cursor-navigation-{target}').then(finish, error => finish({{state: 'error', error: String(error), checks: navigationChecks}}));"
|
||||
);
|
||||
let result = run_probe(&browser, &server, target, &source).await?;
|
||||
assert_eq!(result["state"], "pass", "{target}: {result}");
|
||||
assert_eq!(
|
||||
result["checks"].as_array().unwrap().len(),
|
||||
if target == "worker" { 2612 } else { 2621 },
|
||||
"{target}: {result}"
|
||||
);
|
||||
}
|
||||
server.shutdown().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn indexed_db_cursors_protect_native_state_and_cache_values_in_getter_realms() -> Result<()> {
|
||||
let server = FixtureServer::spawn().await?;
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
use super::{
|
||||
CursorDirection, INDEXED_DB_INDEX_MARKER_SLOT, INDEXED_DB_PENDING_CURSOR_POSITION_SLOT,
|
||||
INDEXED_DB_PENDING_CURSOR_SLOT, INDEXED_DB_REQUEST_READY_STATE_SLOT,
|
||||
INDEXED_DB_REQUEST_SOURCE_SLOT, INDEXED_DB_TRANSACTION_ACTIVE_SLOT, Key, TransactionHandle,
|
||||
TransactionMode, create_request_object, cursor_direction_from_cursor, cursor_request,
|
||||
cursor_source, dom_exception_value, extract_index_keys_from_value, indexed_db_cursor_state,
|
||||
indexed_db_index_is_deleted, indexed_db_index_object_store, indexed_db_object_store_is_deleted,
|
||||
INDEXED_DB_PENDING_CURSOR_SLOT, INDEXED_DB_TRANSACTION_ACTIVE_SLOT, Key, TransactionHandle,
|
||||
TransactionMode, begin_indexed_db_cursor_iteration, create_request_object,
|
||||
cursor_direction_from_cursor, cursor_request, cursor_source, dom_exception_value,
|
||||
extract_index_keys_from_value, indexed_db_cursor_state, indexed_db_index_is_deleted,
|
||||
indexed_db_index_object_store, indexed_db_object_store_is_deleted,
|
||||
indexed_db_object_store_metadata, indexed_db_object_store_name,
|
||||
indexed_db_request_transaction_object, indexed_db_transaction_mode, key_to_js_value,
|
||||
object_bool_property, object_hidden_value, object_string_property, parse_idb_key,
|
||||
prepare_cursor_request, queue_transaction_request, request_error_object, require_idb_key,
|
||||
serialize_js_value, set_indexed_db_slot_value, storage_bucket_quota_check_for_object_store,
|
||||
store_request_error, store_request_success, throw_type_error, transaction_handle_from_value,
|
||||
with_indexed_db_manager,
|
||||
object_bool_property, parse_idb_key, prepare_cursor_request, queue_transaction_request,
|
||||
request_error_object, require_idb_key, serialize_js_value, set_indexed_db_slot_value,
|
||||
storage_bucket_quota_check_for_object_store, store_request_error, store_request_success,
|
||||
throw_type_error, transaction_handle_from_value, with_indexed_db_manager,
|
||||
};
|
||||
use crate::webidl;
|
||||
|
||||
|
||||
@@ -24,9 +24,12 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_cursor_continue_callback<'s>
|
||||
return;
|
||||
};
|
||||
let cursor = args.this();
|
||||
let Some(current) = cursor_current_position(scope, cursor) else {
|
||||
let error = dom_exception_value(scope, "The cursor is exhausted.", "InvalidStateError");
|
||||
scope.throw_exception(error);
|
||||
if cursor_active_transaction(scope, cursor).is_none()
|
||||
|| cursor_effective_object_store(scope, cursor).is_none()
|
||||
{
|
||||
return;
|
||||
}
|
||||
let Some(current) = cursor_iteration_position(scope, cursor) else {
|
||||
return;
|
||||
};
|
||||
let key = parsed.key.unwrap_or_else(|| v8::undefined(scope).into());
|
||||
@@ -65,11 +68,6 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_cursor_advance_callback<'s>(
|
||||
return;
|
||||
};
|
||||
let cursor = args.this();
|
||||
let Some(current) = cursor_current_position(scope, cursor) else {
|
||||
let error = dom_exception_value(scope, "The cursor is exhausted.", "InvalidStateError");
|
||||
scope.throw_exception(error);
|
||||
return;
|
||||
};
|
||||
let count = parsed.count;
|
||||
if count == 0 {
|
||||
throw_type_error(
|
||||
@@ -78,6 +76,14 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_cursor_advance_callback<'s>(
|
||||
);
|
||||
return;
|
||||
}
|
||||
if cursor_active_transaction(scope, cursor).is_none()
|
||||
|| cursor_effective_object_store(scope, cursor).is_none()
|
||||
{
|
||||
return;
|
||||
}
|
||||
let Some(current) = cursor_iteration_position(scope, cursor) else {
|
||||
return;
|
||||
};
|
||||
let next = current + count as usize;
|
||||
let next = (next < cursor_entries_len(scope, cursor)).then_some(next);
|
||||
let _ = result::enqueue_cursor_result(scope, cursor, next);
|
||||
|
||||
+16
-13
@@ -21,24 +21,16 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_cursor_continue_primary_key_
|
||||
return;
|
||||
};
|
||||
let cursor = args.this();
|
||||
if cursor_active_transaction(scope, cursor).is_none()
|
||||
|| cursor_effective_object_store(scope, cursor).is_none()
|
||||
{
|
||||
return;
|
||||
}
|
||||
if !cursor_source_is_index(scope, cursor) {
|
||||
let error = dom_exception_value(scope, "The source is not an index.", "InvalidAccessError");
|
||||
scope.throw_exception(error);
|
||||
return;
|
||||
}
|
||||
let Some(current) = cursor_current_position(scope, cursor) else {
|
||||
let error = dom_exception_value(scope, "The cursor is exhausted.", "InvalidStateError");
|
||||
scope.throw_exception(error);
|
||||
return;
|
||||
};
|
||||
let key = match require_idb_key(scope, parsed.key) {
|
||||
Some(key) => key,
|
||||
None => return,
|
||||
};
|
||||
let primary_key = match require_idb_key(scope, parsed.primary_key) {
|
||||
Some(key) => key,
|
||||
None => return,
|
||||
};
|
||||
let direction = cursor_direction_from_cursor(scope, cursor);
|
||||
if direction.is_unique() {
|
||||
let error = dom_exception_value(
|
||||
@@ -49,6 +41,17 @@ pub(in crate::context_bootstrap::indexed_db) fn idb_cursor_continue_primary_key_
|
||||
scope.throw_exception(error);
|
||||
return;
|
||||
}
|
||||
let Some(current) = cursor_iteration_position(scope, cursor) else {
|
||||
return;
|
||||
};
|
||||
let key = match require_idb_key(scope, parsed.key) {
|
||||
Some(key) => key,
|
||||
None => return,
|
||||
};
|
||||
let primary_key = match require_idb_key(scope, parsed.primary_key) {
|
||||
Some(key) => key,
|
||||
None => return,
|
||||
};
|
||||
if !target_is_after_current_cursor(scope, cursor, current, direction, &key, &primary_key) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,17 +6,8 @@ pub(super) fn enqueue_cursor_result<'s>(
|
||||
next_position: Option<usize>,
|
||||
) -> Option<()> {
|
||||
let (request, transaction) = cursor_request_and_transaction(scope, cursor)?;
|
||||
if !object_bool_property(scope, transaction, INDEXED_DB_TRANSACTION_ACTIVE_SLOT)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
let error = dom_exception_value(
|
||||
scope,
|
||||
"The transaction is not active.",
|
||||
"TransactionInactiveError",
|
||||
);
|
||||
scope.throw_exception(error);
|
||||
return None;
|
||||
}
|
||||
cursor_active_transaction(scope, cursor)?;
|
||||
begin_indexed_db_cursor_iteration(scope, cursor)?;
|
||||
queue_transaction_request(scope, transaction, request);
|
||||
prepare_cursor_request(scope, request);
|
||||
set_indexed_db_slot_value(
|
||||
|
||||
@@ -44,18 +44,28 @@ pub(in crate::context_bootstrap::indexed_db) fn cursor_primary_key_at(
|
||||
)
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap::indexed_db) fn cursor_current_position(
|
||||
pub(in crate::context_bootstrap::indexed_db) fn cursor_iteration_position(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
cursor: v8::Local<'_, v8::Object>,
|
||||
) -> Option<usize> {
|
||||
indexed_db_cursor_state(scope, cursor)?.position
|
||||
let state = indexed_db_cursor_state(scope, cursor)?;
|
||||
if state.got_value {
|
||||
return state.position;
|
||||
}
|
||||
let error = dom_exception_value(
|
||||
scope,
|
||||
"The cursor is being iterated or has iterated past its end.",
|
||||
"InvalidStateError",
|
||||
);
|
||||
scope.throw_exception(error);
|
||||
None
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap::indexed_db) fn cursor_mutation_state<'s>(
|
||||
pub(in crate::context_bootstrap::indexed_db) fn cursor_active_transaction<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
cursor: v8::Local<'s, v8::Object>,
|
||||
) -> Option<(v8::Local<'s, v8::Object>, v8::Local<'s, v8::Object>, Key)> {
|
||||
let (request, transaction) = cursor_request_and_transaction(scope, cursor)?;
|
||||
) -> Option<v8::Local<'s, v8::Object>> {
|
||||
let (_, transaction) = cursor_request_and_transaction(scope, cursor)?;
|
||||
if !object_bool_property(scope, transaction, INDEXED_DB_TRANSACTION_ACTIVE_SLOT)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
@@ -67,33 +77,50 @@ pub(in crate::context_bootstrap::indexed_db) fn cursor_mutation_state<'s>(
|
||||
scope.throw_exception(error);
|
||||
return None;
|
||||
}
|
||||
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 None;
|
||||
}
|
||||
let source = object_hidden_value(scope, request, INDEXED_DB_REQUEST_SOURCE_SLOT)
|
||||
.and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())?;
|
||||
Some(transaction)
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap::indexed_db) fn cursor_effective_object_store<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
cursor: v8::Local<'s, v8::Object>,
|
||||
) -> Option<v8::Local<'s, v8::Object>> {
|
||||
let source = cursor_source(scope, cursor)?;
|
||||
let store = indexed_db_index_object_store(scope, source).unwrap_or(source);
|
||||
if indexed_db_object_store_is_deleted(scope, store)
|
||||
|| (source != store && indexed_db_index_is_deleted(scope, source))
|
||||
|| object_string_property(scope, request, INDEXED_DB_REQUEST_READY_STATE_SLOT).as_deref()
|
||||
!= Some("done")
|
||||
|| indexed_db_cursor_state(scope, cursor).is_some_and(|state| state.key_only)
|
||||
{
|
||||
let error = dom_exception_value(
|
||||
scope,
|
||||
"The cursor cannot modify a record in its current state.",
|
||||
"The cursor's source or effective object store has been deleted.",
|
||||
"InvalidStateError",
|
||||
);
|
||||
scope.throw_exception(error);
|
||||
return None;
|
||||
}
|
||||
let Some(position) = cursor_current_position(scope, cursor) else {
|
||||
let error = dom_exception_value(scope, "The cursor is exhausted.", "InvalidStateError");
|
||||
Some(store)
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap::indexed_db) fn cursor_mutation_state<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
cursor: v8::Local<'s, v8::Object>,
|
||||
) -> Option<(v8::Local<'s, v8::Object>, v8::Local<'s, v8::Object>, Key)> {
|
||||
let transaction = cursor_active_transaction(scope, cursor)?;
|
||||
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 None;
|
||||
};
|
||||
}
|
||||
let store = cursor_effective_object_store(scope, cursor)?;
|
||||
let position = cursor_iteration_position(scope, cursor)?;
|
||||
if indexed_db_cursor_state(scope, cursor)?.key_only {
|
||||
let error = dom_exception_value(
|
||||
scope,
|
||||
"A key-only cursor cannot modify records.",
|
||||
"InvalidStateError",
|
||||
);
|
||||
scope.throw_exception(error);
|
||||
return None;
|
||||
}
|
||||
Some((
|
||||
store,
|
||||
transaction,
|
||||
|
||||
@@ -494,6 +494,7 @@ impl IndexedDbDatabaseLifecycleState {
|
||||
pub(super) struct IndexedDbCursorLifecycleState {
|
||||
pub(super) entries: Rc<[CursorSnapshotEntry]>,
|
||||
pub(super) position: Option<usize>,
|
||||
pub(super) got_value: bool,
|
||||
pub(super) direction: CursorDirection,
|
||||
pub(super) key_only: bool,
|
||||
}
|
||||
@@ -955,6 +956,7 @@ pub(super) fn register_indexed_db_cursor_lifecycle(
|
||||
let state = IndexedDbCursorLifecycleState {
|
||||
entries: entries.into(),
|
||||
position,
|
||||
got_value: position.is_some(),
|
||||
direction,
|
||||
key_only,
|
||||
};
|
||||
@@ -984,6 +986,18 @@ pub(super) fn set_indexed_db_cursor_position(
|
||||
state.entries.get(position)?;
|
||||
}
|
||||
state.position = position;
|
||||
state.got_value = position.is_some();
|
||||
Some(())
|
||||
}
|
||||
|
||||
pub(super) fn begin_indexed_db_cursor_iteration(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
cursor: v8::Local<'_, v8::Object>,
|
||||
) -> Option<()> {
|
||||
let state = cursor_native_state(scope, cursor)?;
|
||||
// Keep the position and exposed values until the asynchronous iteration
|
||||
// settles, but reject further navigation and mutation immediately.
|
||||
state.borrow_mut().got_value = false;
|
||||
Some(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user