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): treat boxed primitives as getAll options

ldm0b1fcb496489e
diff --git a/moli-indexeddb/src/options.rs b/moli-indexeddb/src/options.rs
index 7db1d3376..75fd7d083 100644
--- a/moli-indexeddb/src/options.rs
+++ b/moli-indexeddb/src/options.rs
@@ -63,8 +63,6 @@ pub fn validate_index_options(
pub struct GetAllOptionsCandidate {
pub is_object: bool,
pub is_key_range: bool,
- pub is_string_object: bool,
- pub is_number_object: bool,
pub is_date: bool,
pub is_array: bool,
pub is_buffer_source: bool,
@@ -73,8 +71,6 @@ pub struct GetAllOptionsCandidate {
pub fn should_parse_get_all_options(candidate: GetAllOptionsCandidate) -> bool {
candidate.is_object
&& !candidate.is_key_range
- && !candidate.is_string_object
- && !candidate.is_number_object
&& !candidate.is_date
&& !candidate.is_array
&& !candidate.is_buffer_source
@@ -153,8 +149,6 @@ mod tests {
assert!(should_parse_get_all_options(GetAllOptionsCandidate {
is_object: true,
is_key_range: false,
- is_string_object: false,
- is_number_object: false,
is_date: false,
is_array: false,
is_buffer_source: false,
@@ -164,8 +158,6 @@ mod tests {
GetAllOptionsCandidate {
is_object: false,
is_key_range: false,
- is_string_object: false,
- is_number_object: false,
is_date: false,
is_array: false,
is_buffer_source: false,
@@ -173,8 +165,6 @@ mod tests {
GetAllOptionsCandidate {
is_object: true,
is_key_range: true,
- is_string_object: false,
- is_number_object: false,
is_date: false,
is_array: false,
is_buffer_source: false,
@@ -182,26 +172,6 @@ mod tests {
GetAllOptionsCandidate {
is_object: true,
is_key_range: false,
- is_string_object: true,
- is_number_object: false,
- is_date: false,
- is_array: false,
- is_buffer_source: false,
- },
- GetAllOptionsCandidate {
- is_object: true,
- is_key_range: false,
- is_string_object: false,
- is_number_object: true,
- is_date: false,
- is_array: false,
- is_buffer_source: false,
- },
- GetAllOptionsCandidate {
- is_object: true,
- is_key_range: false,
- is_string_object: false,
- is_number_object: false,
is_date: true,
is_array: false,
is_buffer_source: false,
@@ -209,8 +179,6 @@ mod tests {
GetAllOptionsCandidate {
is_object: true,
is_key_range: false,
- is_string_object: false,
- is_number_object: false,
is_date: false,
is_array: true,
is_buffer_source: false,
@@ -218,8 +186,6 @@ mod tests {
GetAllOptionsCandidate {
is_object: true,
is_key_range: false,
- is_string_object: false,
- is_number_object: false,
is_date: false,
is_array: false,
is_buffer_source: true,
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 20da52549..63ff3748a 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
@@ -44,8 +44,6 @@ fn should_parse_get_all_options_value<'s>(
should_parse_get_all_options(GetAllOptionsCandidate {
is_object: value.is_object(),
is_key_range: parse_key_range_from_value(scope, value).is_some(),
- is_string_object: value.is_string_object(),
- is_number_object: value.is_number_object(),
is_date: value.is_date(),
is_array: v8::Local::<v8::Array>::try_from(value).is_ok(),
is_buffer_source: value_has_array_buffer_view_tag(value)
@@ -122,3 +120,44 @@ fn parse_get_all_options<'s>(
.unwrap_or_else(CursorDirection::default_next);
Ok((query, count, direction))
}
+
+#[cfg(test)]
+mod tests {
+ use std::pin::pin;
+
+ use super::{parse_get_all_options, should_parse_get_all_options_value};
+
+ #[test]
+ fn boxed_primitives_use_dictionary_members_for_get_all_options() {
+ crate::ensure_v8_for_test();
+ let mut isolate = v8::Isolate::new(v8::CreateParams::default());
+ let scope = pin!(v8::HandleScope::new(&mut isolate));
+ let scope = &mut scope.init();
+ let context = v8::Context::new(scope, Default::default());
+ let scope = &mut v8::ContextScope::new(scope, context);
+ for expression in [
+ "Object.assign(new Number(1), {count: 2, direction: 'prev'})",
+ "Object.assign(new String('key'), {count: 2, direction: 'prev'})",
+ ] {
+ let source = v8::String::new(scope, expression).unwrap();
+ let script = v8::Script::compile(scope, source, None).unwrap();
+ let value = crate::script_execution::execute_compiled_script(scope, script).unwrap();
+ assert!(should_parse_get_all_options_value(scope, value));
+ let Ok((query, count, direction)) = parse_get_all_options(scope, value) else {
+ panic!("boxed primitives must be converted as dictionaries");
+ };
+ assert!(query.is_undefined());
+ assert_eq!(count, Some(2));
+ assert_eq!(direction, moli_indexeddb::CursorDirection::Prev);
+ }
+ for expression in ["1", "'key'", "new Date(0)", "[1]", "new Uint8Array(1)"] {
+ let source = v8::String::new(scope, expression).unwrap();
+ let script = v8::Script::compile(scope, source, None).unwrap();
+ let value = crate::script_execution::execute_compiled_script(scope, script).unwrap();
+ assert!(
+ !should_parse_get_all_options_value(scope, value),
+ "{expression}"
+ );
+ }
+ }
+}
diff --git a/moli-renderer-v8/src/script_vm/tests/indexed_db.rs b/moli-renderer-v8/src/script_vm/tests/indexed_db.rs
index c5bbe70ec..6608d73e1 100644
--- a/moli-renderer-v8/src/script_vm/tests/indexed_db.rs
+++ b/moli-renderer-v8/src/script_vm/tests/indexed_db.rs
@@ -3854,7 +3854,7 @@ fn indexed_db_object_store_range_count_zero_and_open_bounds_work() {
}
#[test]
-fn indexed_db_get_all_object_wrapped_query_values_stay_queries() {
+fn indexed_db_get_all_boxed_primitives_are_options_and_dates_are_keys() {
let mut vm =
new_storage_page_task_executor_test_vm("https://indexeddb-getall-wrapper-query.test/");
@@ -3870,12 +3870,14 @@ fn indexed_db_get_all_object_wrapped_query_values_stay_queries() {
const store = writeTx.objectStore("kv");
store.put("five", 5);
store.put("string", "x");
- store.put("date", 1000);
+ store.put("date", new Date(1000));
writeTx.oncomplete = () => {
const readStore = db.transaction("kv").objectStore("kv");
- const numberReq = readStore.getAll(new Number(5));
+ const numberOptions = Object.assign(new Number(5), {query: "x"});
+ const numberReq = readStore.getAll(numberOptions);
numberReq.onsuccess = () => {
- const stringReq = readStore.getAllKeys(new String("x"));
+ const stringOptions = Object.assign(new String("x"), {query: 5});
+ const stringReq = readStore.getAllKeys(stringOptions);
stringReq.onsuccess = () => {
const dateReq = readStore.getAll(new Date(1000));
dateReq.onsuccess = () => {
@@ -3899,7 +3901,7 @@ fn indexed_db_get_all_object_wrapped_query_values_stay_queries() {
.eval_after_selected_page_tasks("String(globalThis.__indexedDbGetAllWrapperQueryResult)")
.expect("indexeddb wrapper query result should be readable");
- assert_eq!(result, "five|x|date");
+ assert_eq!(result, "string|5|date");
}
#[tokio::test]