mirror of
https://github.com/lexmount/moli.git
synced 2026-10-25 08:01:49 +00:00
refactor(webapi): derive common options dictionaries
Remove options-to-dictionary adapter hooks for TextDecoder, custom elements, QuotaExceededError, Worklet, Geolocation and ProgressEvent. Use dictionary member defaults, including the Geolocation timeout, and normalize conversion error contexts to the declaring API. Validation on the combined tree: cargo fmt --all; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo nextest run --no-fail-fast (19639 passed, 16 skipped; CARGO_BUILD_JOBS=1).
This commit is contained in:
@@ -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>,
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user