Skip to content

armgit / moli

Public Imported from GitHub
0

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

refactor(webapi): derive common options dictionaries

ldm0aecb1e9c2fa6
diff --git a/moli-renderer-v8/src/context_bootstrap/constructors/custom_elements_registry.rs b/moli-renderer-v8/src/context_bootstrap/constructors/custom_elements_registry.rs
index cabbb6088..b9a174b2c 100644
--- a/moli-renderer-v8/src/context_bootstrap/constructors/custom_elements_registry.rs
+++ b/moli-renderer-v8/src/context_bootstrap/constructors/custom_elements_registry.rs
@@ -1,7 +1,6 @@
use super::*;
use crate::web_api_interfaces;
use crate::webidl;
-use anyhow::Result;
use moli_webapi_declare::WebApiFunctionTemplate;
#[derive(WebApiFunctionTemplate)]
@@ -49,7 +48,7 @@ struct CustomElementsDefineArgs<'s> {
missing_message = "customElements.define(name, constructor) requires a constructor function"
)]
constructor: v8::Local<'s, v8::Function>,
- #[webidl(with = parse_element_definition_options_arg)]
+ #[webidl(dictionary)]
options: ElementDefinitionOptions,
}
@@ -225,18 +224,6 @@ pub(in crate::context_bootstrap) fn custom_elements_define_callback<'s>(
}
}
-fn parse_element_definition_options_arg<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: &v8::FunctionCallbackArguments<'s>,
- index: i32,
-) -> Result<ElementDefinitionOptions, webidl::WebIdlError> {
- let context = webidl::Context::argument("CustomElementRegistry.define", (index + 1) as usize);
- webidl::dictionary_arg(args, index, context)?
- .map(|object| webidl::parse_dictionary_object::<ElementDefinitionOptions>(scope, object))
- .transpose()
- .map(|options| options.unwrap_or_default())
-}
-
pub(in crate::context_bootstrap) fn custom_elements_get_callback<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
diff --git a/moli-renderer-v8/src/context_bootstrap/constructors/dom_exception.rs b/moli-renderer-v8/src/context_bootstrap/constructors/dom_exception.rs
index fe481fec7..e594c9b9e 100644
--- a/moli-renderer-v8/src/context_bootstrap/constructors/dom_exception.rs
+++ b/moli-renderer-v8/src/context_bootstrap/constructors/dom_exception.rs
@@ -46,7 +46,7 @@ struct QuotaExceededErrorOptions {
struct QuotaExceededErrorConstructorArgs {
#[webidl(default = "")]
message: String,
- #[webidl(default = QuotaExceededErrorOptions::default(), with = quota_exceeded_error_options_arg)]
+ #[webidl(dictionary)]
options: QuotaExceededErrorOptions,
}
@@ -636,20 +636,6 @@ pub(crate) fn new_dom_error_value<'s>(
.into()
}
-fn quota_exceeded_error_options_arg<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: &v8::FunctionCallbackArguments<'s>,
- index: i32,
-) -> Result<QuotaExceededErrorOptions, webidl::WebIdlError> {
- let context = webidl::Context::argument("QuotaExceededError", (index + 1) as usize);
- if args.length() <= index {
- return Ok(QuotaExceededErrorOptions::default());
- }
- let value = args.get(index);
- webidl::parse_dictionary::<QuotaExceededErrorOptions>(scope, value, context)
- .map(|value| value.unwrap_or_default())
-}
-
pub(crate) fn quota_exceeded_error_constructor_callback<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
diff --git a/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs b/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs
index ad9fa402a..8a51dceed 100644
--- a/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs
+++ b/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs
@@ -109,7 +109,7 @@ struct TextEncoderEncodeIntoArgs<'s> {
struct TextDecoderConstructorArgs {
#[webidl(default = "utf-8")]
label: String,
- #[webidl(index = 1, with = parse_text_decoder_options_arg)]
+ #[webidl(index = 1, dictionary)]
options: TextDecoderOptions,
}
@@ -127,7 +127,7 @@ struct TextDecoderOptions {
struct TextDecoderDecodeArgs {
#[webidl(converter = "buffer_source")]
input: Option<webidl::BufferSource>,
- #[webidl(index = 1, with = parse_text_decode_options_arg)]
+ #[webidl(index = 1, dictionary)]
options: TextDecodeOptions,
}
@@ -338,30 +338,6 @@ pub(in crate::context_bootstrap) fn text_decoder_constructor_callback<'s>(
rv.set(args.this().into());
}
-fn parse_text_decoder_options_arg<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: &v8::FunctionCallbackArguments<'s>,
- index: i32,
-) -> Result<TextDecoderOptions, webidl::WebIdlError> {
- let context = webidl::Context::argument("TextDecoder", (index + 1) as usize);
- webidl::dictionary_arg(args, index, context)?
- .map(|object| webidl::parse_dictionary_object(scope, object))
- .transpose()
- .map(|options| options.unwrap_or_default())
-}
-
-fn parse_text_decode_options_arg<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: &v8::FunctionCallbackArguments<'s>,
- index: i32,
-) -> Result<TextDecodeOptions, webidl::WebIdlError> {
- let context = webidl::Context::argument("TextDecoder.decode", (index + 1) as usize);
- webidl::dictionary_arg(args, index, context)?
- .map(|object| webidl::parse_dictionary_object(scope, object))
- .transpose()
- .map(|options| options.unwrap_or_default())
-}
-
fn text_decoder_decode_callback<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs
index 8fdc662a4..3db26ffe7 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs
@@ -88,7 +88,7 @@ struct GetCurrentPositionArgs {
#[webidl(nullable, converter = "callback_function")]
error_callback: Option<webidl::WebIdlCallbackFunction>,
- #[webidl(with = position_options_arg)]
+ #[webidl(dictionary)]
options: PositionOptions,
}
@@ -101,7 +101,7 @@ struct WatchPositionArgs {
#[webidl(nullable, converter = "callback_function")]
error_callback: Option<webidl::WebIdlCallbackFunction>,
- #[webidl(with = position_options_arg)]
+ #[webidl(dictionary)]
options: PositionOptions,
}
@@ -248,30 +248,6 @@ fn geolocation_clear_watch_callback<'s>(
rv.set_undefined();
}
-fn position_options_arg<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: &v8::FunctionCallbackArguments<'s>,
- index: i32,
-) -> std::result::Result<PositionOptions, webidl::WebIdlError> {
- if args.length() <= index || args.get(index).is_undefined() {
- return Ok(PositionOptions {
- timeout: u32::MAX,
- ..PositionOptions::default()
- });
- }
- webidl::parse_dictionary::<PositionOptions>(
- scope,
- args.get(index),
- webidl::Context::argument("Geolocation", (index + 1) as usize),
- )
- .map(|options| {
- options.unwrap_or(PositionOptions {
- timeout: u32::MAX,
- ..PositionOptions::default()
- })
- })
-}
-
fn clamped_unsigned_long_position_option<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
diff --git a/moli-renderer-v8/src/context_bootstrap/web_audio_runtime.rs b/moli-renderer-v8/src/context_bootstrap/web_audio_runtime.rs
index 234df22f2..0175beedc 100644
--- a/moli-renderer-v8/src/context_bootstrap/web_audio_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/web_audio_runtime.rs
@@ -685,23 +685,10 @@ struct WorkletOptions {
struct WorkletAddModuleArgs {
#[webidl(required, converter = "usv_string")]
module_url: String,
- #[webidl(with = worklet_options_arg)]
+ #[webidl(dictionary)]
options: WorkletOptions,
}
-fn worklet_options_arg<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: &v8::FunctionCallbackArguments<'s>,
- index: i32,
-) -> Result<WorkletOptions, webidl::WebIdlError> {
- webidl::parse_dictionary(
- scope,
- args.get(index),
- webidl::Context::argument("Worklet.addModule", 2),
- )
- .map(Option::unwrap_or_default)
-}
-
fn audio_worklet_add_module_callback<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
diff --git a/moli-renderer-v8/src/network_host/xhr/bindings/progress_event.rs b/moli-renderer-v8/src/network_host/xhr/bindings/progress_event.rs
index 0b7ff0267..d5f2ed7cc 100644
--- a/moli-renderer-v8/src/network_host/xhr/bindings/progress_event.rs
+++ b/moli-renderer-v8/src/network_host/xhr/bindings/progress_event.rs
@@ -41,24 +41,10 @@ struct ProgressEventConstructorArgs {
missing_message = "Failed to construct 'ProgressEvent': 1 argument required, but only 0 present."
)]
event_type: String,
- #[webidl(default = ProgressEventInitArgs::default(), with = progress_event_init_arg)]
+ #[webidl(dictionary)]
init: ProgressEventInitArgs,
}
-fn progress_event_init_arg<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: &v8::FunctionCallbackArguments<'s>,
- index: i32,
-) -> Result<ProgressEventInitArgs, webidl::WebIdlError> {
- let context = webidl::Context::argument("ProgressEvent", (index + 1) as usize);
- if args.length() <= index {
- return Ok(ProgressEventInitArgs::default());
- }
- let value = args.get(index);
- webidl::parse_dictionary::<ProgressEventInitArgs>(scope, value, context)
- .map(|value| value.unwrap_or_default())
-}
-
pub(crate) fn progress_event_constructor_callback<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,