mirror of
https://github.com/lexmount/moli.git
synced 2026-10-30 16:07:24 +00:00
refactor(events): use shared WebIDL conversion for native event dictionaries
This commit is contained in:
@@ -317,7 +317,7 @@ pub(super) use base::{
|
||||
event_target_getter_function, event_type_getter_function, set_event_dispatch_fields,
|
||||
set_event_initialized,
|
||||
};
|
||||
pub(in crate::context_bootstrap) use init::EventInit;
|
||||
pub(in crate::context_bootstrap) use init::{EventInit, parse_event_dictionary};
|
||||
pub(super) use kind::EventSubclassKind;
|
||||
pub(super) use methods::{
|
||||
event_cancel_bubble_getter_function, event_cancel_bubble_setter_function,
|
||||
|
||||
@@ -14,6 +14,25 @@ pub(in crate::context_bootstrap) struct EventInit {
|
||||
pub(in crate::context_bootstrap) composed: bool,
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap) fn parse_event_dictionary<'s, T: webidl::WebIdlDictionary<'s>>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
args: &v8::FunctionCallbackArguments<'s>,
|
||||
constructor: &'static str,
|
||||
) -> Option<T> {
|
||||
let parsed = webidl::convert::<webidl::Dictionary<T>>(
|
||||
scope,
|
||||
args.get(1),
|
||||
webidl::Context::argument(constructor, 2),
|
||||
);
|
||||
match parsed {
|
||||
Ok(init) => Some(init.0),
|
||||
Err(error) => {
|
||||
webidl::throw_error(scope, &error);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn init_bool_property<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
init: Option<v8::Local<'s, v8::Object>>,
|
||||
|
||||
@@ -50,25 +50,7 @@ pub(super) fn parse_message_event_init<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
args: &v8::FunctionCallbackArguments<'s>,
|
||||
) -> Option<MessageEventInit<'s>> {
|
||||
let parsed = webidl::dictionary_arg(args, 1, webidl::Context::argument("MessageEvent", 2))
|
||||
.and_then(|object| match object {
|
||||
Some(object) => webidl::parse_dictionary_object(scope, object),
|
||||
None => Ok(MessageEventInit {
|
||||
base: EventInit::default(),
|
||||
data: None,
|
||||
last_event_id: webidl::DomString16(Vec::new()),
|
||||
origin: String::new(),
|
||||
ports: Vec::new(),
|
||||
source: None,
|
||||
}),
|
||||
});
|
||||
match parsed {
|
||||
Ok(init) => Some(init),
|
||||
Err(error) => {
|
||||
webidl::throw_error(scope, &error);
|
||||
None
|
||||
}
|
||||
}
|
||||
crate::context_bootstrap::events::parse_event_dictionary(scope, args, "MessageEvent")
|
||||
}
|
||||
|
||||
#[derive(webidl::WebIdlArgs)]
|
||||
|
||||
@@ -290,18 +290,7 @@ pub(super) fn parse_storage_event_init<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
args: &v8::FunctionCallbackArguments<'s>,
|
||||
) -> Option<StorageEventInitMembers<'s>> {
|
||||
let parsed = webidl::dictionary_arg(args, 1, webidl::Context::argument("StorageEvent", 2))
|
||||
.and_then(|object| match object {
|
||||
Some(object) => webidl::parse_dictionary_object(scope, object),
|
||||
None => Ok(StorageEventInitMembers::default()),
|
||||
});
|
||||
match parsed {
|
||||
Ok(init) => Some(init),
|
||||
Err(error) => {
|
||||
webidl::throw_error(scope, &error);
|
||||
None
|
||||
}
|
||||
}
|
||||
crate::context_bootstrap::events::parse_event_dictionary(scope, args, "StorageEvent")
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap::events::subclasses) fn initialize_drag_event<'s>(
|
||||
|
||||
@@ -22,35 +22,11 @@ pub(super) struct ErrorEventInit<'s> {
|
||||
message: webidl::DomString16,
|
||||
}
|
||||
|
||||
impl Default for ErrorEventInit<'_> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
base: EventInit::default(),
|
||||
colno: 0,
|
||||
error: None,
|
||||
filename: String::new(),
|
||||
lineno: 0,
|
||||
message: webidl::DomString16(Vec::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn parse_error_event_init<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
args: &v8::FunctionCallbackArguments<'s>,
|
||||
) -> Option<ErrorEventInit<'s>> {
|
||||
let parsed = webidl::dictionary_arg(args, 1, webidl::Context::argument("ErrorEvent", 2))
|
||||
.and_then(|object| match object {
|
||||
Some(object) => webidl::parse_dictionary_object(scope, object),
|
||||
None => Ok(ErrorEventInit::default()),
|
||||
});
|
||||
match parsed {
|
||||
Ok(init) => Some(init),
|
||||
Err(error) => {
|
||||
webidl::throw_error(scope, &error);
|
||||
None
|
||||
}
|
||||
}
|
||||
crate::context_bootstrap::events::parse_event_dictionary(scope, args, "ErrorEvent")
|
||||
}
|
||||
|
||||
impl<'s> ErrorEventInit<'s> {
|
||||
|
||||
Reference in New Issue
Block a user