Skip to content

armgit / moli

Public Imported from GitHub
0

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

refactor(webauthn): use shared dictionary conversions

ldm01e3e2e1ba1f7
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/container.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/container.rs
index e61e3125a..c6ac16e96 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/container.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/container.rs
@@ -122,7 +122,7 @@ fn get<'s>(
let Some(parsed) = webidl::parse_args::<GetArgs>(scope, &args) else {
return;
};
- if !check_fully_active(scope) || check_aborted(scope, parsed.options.0.signal) {
+ if !check_fully_active(scope) || check_aborted(scope, parsed.options.signal) {
return;
}
backend_unavailable(scope);
@@ -139,7 +139,7 @@ fn create<'s>(
if !check_fully_active(scope) {
return;
}
- let options = parsed.options.0;
+ let options = parsed.options;
// Unlike get(), create() checks multiple credential types before abort.
let types = usize::from(options.password.is_some())
+ usize::from(options.federated.is_some())
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/container/options.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/container/options.rs
index f92cd43de..e339623c4 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/container/options.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/container/options.rs
@@ -9,8 +9,9 @@ use crate::{abort_signal_route::ResolvedAbortSignal, web_api_interfaces, webidl}
use super::super::{
schema::{Entity, Parameters, RelyingParty, Selection},
- value::{Dictionary, Text},
+ value::Text,
};
+use webidl::Dictionary;
#[derive(Clone, Copy, webidl::WebIdlEnum)]
#[webidl(name = "CredentialMediationRequirement")]
@@ -90,15 +91,15 @@ impl<'s> webidl::WebIdlConverter<'s> for PasswordInit {
#[derive(webidl::WebIdlArgs)]
#[webidl(prefix = "CredentialsContainer.get")]
pub(super) struct GetArgs<'s> {
- #[webidl(converter = "raw", default = Dictionary::empty(scope)?)]
- pub(super) options: Dictionary<Request<'s>>,
+ #[webidl(dictionary)]
+ pub(super) options: Request<'s>,
}
#[derive(webidl::WebIdlArgs)]
#[webidl(prefix = "CredentialsContainer.create")]
pub(super) struct CreateArgs<'s> {
- #[webidl(converter = "raw", default = Dictionary::empty(scope)?)]
- pub(super) options: Dictionary<Creation<'s>>,
+ #[webidl(dictionary)]
+ pub(super) options: Creation<'s>,
}
#[derive(webidl::WebIdlArgs)]
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/json_options.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/json_options.rs
index 7d8575e5e..14ed0ac39 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/json_options.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/json_options.rs
@@ -10,21 +10,20 @@ mod schema;
use crate::webidl;
use webidl::{SnapshotPrototype, WebIdlDictionarySerialize};
-use super::value::Dictionary;
use schema::{CreationJson, RequestJson};
#[derive(webidl::WebIdlArgs)]
#[webidl(prefix = "PublicKeyCredential.parseCreationOptionsFromJSON")]
struct CreationArgs {
- #[webidl(required, converter = "raw")]
- options: Dictionary<CreationJson>,
+ #[webidl(required, dictionary)]
+ options: CreationJson,
}
#[derive(webidl::WebIdlArgs)]
#[webidl(prefix = "PublicKeyCredential.parseRequestOptionsFromJSON")]
struct RequestArgs {
- #[webidl(required, converter = "raw")]
- options: Dictionary<RequestJson>,
+ #[webidl(required, dictionary)]
+ options: RequestJson,
}
pub(super) fn parse_creation<'s>(
@@ -37,7 +36,6 @@ pub(super) fn parse_creation<'s>(
};
if let Some(result) = parsed
.options
- .0
.to_js_snapshot(scope, SnapshotPrototype::Ordinary)
{
rv.set(result.into());
@@ -54,7 +52,6 @@ pub(super) fn parse_request<'s>(
};
if let Some(result) = parsed
.options
- .0
.to_js_snapshot(scope, SnapshotPrototype::Ordinary)
{
rv.set(result.into());
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/json_options/schema.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/json_options/schema.rs
index 57e5d94d8..8c1322189 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/json_options/schema.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/json_options/schema.rs
@@ -1,7 +1,8 @@
use crate::webidl;
pub(super) use super::super::schema::{Parameters, RelyingParty, Selection};
-use super::super::value::{Dictionary, Text};
+use super::super::value::Text;
+use webidl::Dictionary;
// The derive orders each dictionary's final member names lexicographically;
// inherited dictionaries such as RelyingParty declare their base explicitly.
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/value.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/value.rs
index b7211f8ce..f9d9c7827 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/value.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/credentials/value.rs
@@ -1,6 +1,6 @@
use moli_webapi_declare::WebApiValue;
-use crate::{util::new_null_prototype_object, webidl};
+use crate::webidl;
/// Preserve every DOMString code unit, including lone surrogates in labels and
/// PRF record keys and signal user details. Base64url values must still be ASCII
@@ -33,49 +33,6 @@ impl<'s> WebApiValue<'s> for Text {
}
}
-pub(super) struct Dictionary<T>(pub(super) T);
-
-impl<T> Dictionary<T> {
- pub(super) fn empty<'s>(scope: &mut v8::PinScope<'s, '_>) -> Result<Self, webidl::WebIdlError>
- where
- T: webidl::WebIdlDictionary<'s>,
- {
- let object = new_null_prototype_object(scope);
- T::parse_dictionary(scope, object).map(Self)
- }
-}
-
-impl<'s, T: webidl::WebIdlDictionary<'s>> webidl::WebIdlConverter<'s> for Dictionary<T> {
- type Options = ();
-
- fn convert(
- scope: &mut v8::PinScope<'s, '_>,
- value: v8::Local<'s, v8::Value>,
- context: webidl::Context,
- _options: &Self::Options,
- ) -> Result<Self, webidl::WebIdlError> {
- match webidl::dictionary_value(value, context)? {
- Some(object) => T::parse_dictionary(scope, object).map(Self),
- // null/undefined mean an empty dictionary, not an Object whose
- // prototype could contribute author-installed dictionary members.
- None => Self::empty(scope),
- }
- }
-}
-
impl webidl::WebIdlSnapshotValue for Text {
const SNAPSHOT_KIND: webidl::SnapshotKind = webidl::SnapshotKind::Scalar;
}
-
-impl<T: webidl::WebIdlDictionarySnapshot> webidl::WebIdlSnapshotValue for Dictionary<T> {
- const SNAPSHOT_KIND: webidl::SnapshotKind =
- webidl::SnapshotKind::Dictionary(&T::SNAPSHOT_SCHEMA);
-}
-
-impl<'s, T: webidl::WebIdlDictionarySerialize<'s>> WebApiValue<'s> for Dictionary<T> {
- fn to_v8_value(&self, scope: &mut v8::PinScope<'s, '_>) -> Option<v8::Local<'s, v8::Value>> {
- self.0
- .to_js_snapshot(scope, webidl::SnapshotPrototype::Ordinary)
- .map(Into::into)
- }
-}