Skip to content

armgit / moli

Public Imported from GitHub
0

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

refactor: centralize cookie domain parsing and simplify control flow

ldm0dab1b0ed5100
diff --git a/moli-cookie-store/src/cookie_domain.rs b/moli-cookie-store/src/cookie_domain.rs
index e94f5273a..912369e74 100644
--- a/moli-cookie-store/src/cookie_domain.rs
+++ b/moli-cookie-store/src/cookie_domain.rs
@@ -137,6 +137,14 @@ impl CookieDomain {
impl TryFrom<&str> for CookieDomain {
type Error = crate::Error;
fn try_from(value: &str) -> Result<CookieDomain, Self::Error> {
+ value.parse()
+ }
+}
+
+impl std::str::FromStr for CookieDomain {
+ type Err = crate::Error;
+
+ fn from_str(value: &str) -> Result<Self, Self::Err> {
idna::domain_to_ascii(value.trim())
.map_err(super::IdnaErrors::from)
.map_err(Into::into)
diff --git a/moli-layout/src/pass.rs b/moli-layout/src/pass.rs
index fbf2d088f..4a7ad15e3 100644
--- a/moli-layout/src/pass.rs
+++ b/moli-layout/src/pass.rs
@@ -239,8 +239,7 @@ where
let numeric_layout_elapsed = phase_started.elapsed();
let phase_started = Instant::now();
let mut embedded_frames = HashMap::new();
- for index in 0..world.boxes.len() {
- let layout_box = &world.boxes[index];
+ for (index, layout_box) in world.boxes.iter().enumerate() {
if !layout_box
.element_semantics()
.is_some_and(|semantics| semantics.replaced == Some(crate::LayoutReplacedKind::Frame))
diff --git a/moli-module-syntax/src/dynamic_import.rs b/moli-module-syntax/src/dynamic_import.rs
index 855ec595e..8312f47d9 100644
--- a/moli-module-syntax/src/dynamic_import.rs
+++ b/moli-module-syntax/src/dynamic_import.rs
@@ -318,6 +318,7 @@ fn dynamic_import_site_from_oxc(
None => None,
};
let (replace_start, replace_end) = shifted_span(replace_span, offset)?;
+ source.get(replace_span.start as usize..replace_span.end as usize)?;
Some(DynamicImportRewriteSite {
specifier,
resolve_import_meta_first,
@@ -326,11 +327,6 @@ fn dynamic_import_site_from_oxc(
replace_end,
kind,
})
- .filter(|_| {
- source
- .get(replace_span.start as usize..replace_span.end as usize)
- .is_some()
- })
}
fn dynamic_import_specifier_from_expression(expression: &Expression<'_>) -> Option<(String, bool)> {
diff --git a/moli-renderer-v8/src/context_bootstrap/navigation_window.rs b/moli-renderer-v8/src/context_bootstrap/navigation_window.rs
index 92adaf820..51bc7b5c5 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigation_window.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigation_window.rs
@@ -261,10 +261,7 @@ fn navigation_document_is_live<'s>(
return false;
};
let host = unsafe { &*host_ptr };
- if !host.child_browsing_context_is_live(handle) {
- return false;
- }
- true
+ host.child_browsing_context_is_live(handle)
}
pub(in crate::context_bootstrap) fn dom_handle_from_marker_value(
diff --git a/moli-renderer-v8/src/document_script_scheduler/owner_work.rs b/moli-renderer-v8/src/document_script_scheduler/owner_work.rs
index bcf5348d9..eacc77c2b 100644
--- a/moli-renderer-v8/src/document_script_scheduler/owner_work.rs
+++ b/moli-renderer-v8/src/document_script_scheduler/owner_work.rs
@@ -123,12 +123,8 @@ impl PageOwnedDocumentScriptWork {
runtime_script_claim.as_ref().map(|claim| claim.owner()),
),
};
- if load_delay_owner.is_some_and(|binding_owner| binding_owner != owner)
- || runtime_script_owner.is_some_and(|claim_owner| claim_owner != owner)
- {
- return false;
- }
- true
+ !(load_delay_owner.is_some_and(|binding_owner| binding_owner != owner)
+ || runtime_script_owner.is_some_and(|claim_owner| claim_owner != owner))
}
pub(crate) fn script(lane: DocumentScriptExecutionLane, script: PreparedScript) -> Self {
diff --git a/moli-renderer-v8/src/document_script_scheduler/runner.rs b/moli-renderer-v8/src/document_script_scheduler/runner.rs
index 93d69533d..7b64c002c 100644
--- a/moli-renderer-v8/src/document_script_scheduler/runner.rs
+++ b/moli-renderer-v8/src/document_script_scheduler/runner.rs
@@ -181,10 +181,6 @@ impl<
let Self {
async_parse_time_queue,
async_fallback_queue,
- ready_work: _,
- parse_visible_async_lane_state: _,
- parse_visible_async_reevaluation_credit: _,
- owner_wake: _,
..
} = self;
let mut async_tasks = async_fallback_queue.into_async_phase_tasks();
diff --git a/moli-renderer-v8/src/native_bridge/element/styles/declaration/values/computed_properties.rs b/moli-renderer-v8/src/native_bridge/element/styles/declaration/values/computed_properties.rs
index 876d35ee0..f4f386df9 100644
--- a/moli-renderer-v8/src/native_bridge/element/styles/declaration/values/computed_properties.rs
+++ b/moli-renderer-v8/src/native_bridge/element/styles/declaration/values/computed_properties.rs
@@ -2255,7 +2255,6 @@ fn shared_css_wide_keyword_for_longhands<const N: usize>(
) -> Option<String> {
let keyword = longhands
.first()?
- .as_slice()
.first()
.and_then(|value| css_wide_keyword(value))?;
longhands
diff --git a/moli-renderer-v8/src/native_bridge/element/styles/declaration/values/computed_values.rs b/moli-renderer-v8/src/native_bridge/element/styles/declaration/values/computed_values.rs
index ed7bc8989..22fa2b287 100644
--- a/moli-renderer-v8/src/native_bridge/element/styles/declaration/values/computed_values.rs
+++ b/moli-renderer-v8/src/native_bridge/element/styles/declaration/values/computed_values.rs
@@ -653,13 +653,12 @@ fn resolve_computed_font_relative_length(
.and_then(|document_element| computed_font_size_px(runtime, document_element))
.unwrap_or(16.0),
)
- } else if let Some(number) = value.strip_suffix("em") {
+ } else {
+ let number = value.strip_suffix("em")?;
(
number,
computed_font_size_px(runtime, handle).unwrap_or(16.0),
)
- } else {
- return None;
};
let multiplier = moli_css_parse::parse_number(raw_number)?;
Some(format_css_px(multiplier * font_size))
diff --git a/moli-renderer-v8/src/native_bridge/element/stylesheets/sheet.rs b/moli-renderer-v8/src/native_bridge/element/stylesheets/sheet.rs
index dc2446403..512e6b762 100644
--- a/moli-renderer-v8/src/native_bridge/element/stylesheets/sheet.rs
+++ b/moli-renderer-v8/src/native_bridge/element/stylesheets/sheet.rs
@@ -168,7 +168,8 @@ pub(crate) fn style_sheet_for_element<'s>(
&& let Ok(existing) = v8::Local::<v8::Object>::try_from(existing)
{
if is_style {
- if let Some(stylesheet) = owner_live_stylesheet.as_ref() {
+ {
+ let stylesheet = owner_live_stylesheet.as_ref()?;
if css_style_sheet_id(scope, existing) == Some(stylesheet.id()) {
set_css_style_sheet_owner_node(scope, existing, receiver);
set_css_style_sheet_origin_clean(scope, existing, true);
@@ -177,8 +178,6 @@ pub(crate) fn style_sheet_for_element<'s>(
crate::context_bootstrap::clear_css_style_sheet_owner_node(scope, existing);
let undefined = v8::undefined(scope);
set_private_value(scope, receiver, STYLE_SHEET_CACHE_SLOT, undefined.into());
- } else {
- return None;
}
} else if let Some(source) = linked_source.as_ref() {
if !sync_sheet_from_linked_source(scope, existing, runtime, source) {
@@ -200,10 +199,9 @@ pub(crate) fn style_sheet_for_element<'s>(
let sheet = new_css_style_sheet_object(scope);
set_css_style_sheet_owner_node(scope, sheet, receiver);
if is_style {
- if let Some(stylesheet) = owner_live_stylesheet {
+ {
+ let stylesheet = owner_live_stylesheet?;
bind_css_style_sheet_to_live_stylesheet(scope, sheet, stylesheet);
- } else {
- return None;
}
set_css_style_sheet_origin_clean(scope, sheet, true);
} else if let Some(source) = linked_source.as_ref() {
diff --git a/moli-renderer-v8/src/native_bridge/node/mutation/core.rs b/moli-renderer-v8/src/native_bridge/node/mutation/core.rs
index a92ed6b4a..f284fc717 100644
--- a/moli-renderer-v8/src/native_bridge/node/mutation/core.rs
+++ b/moli-renderer-v8/src/native_bridge/node/mutation/core.rs
@@ -108,15 +108,12 @@ pub(in crate::native_bridge) fn node_append_child_callback<'s>(
inserted_handles_for_post_insert_events(unsafe { &*runtime_ptr }, child);
let inserted =
custom_elements::with_custom_element_reaction_scope(scope, runtime_ptr, |scope| {
- if !unsafe { &mut *runtime_ptr }.append_child_appending_to_current_reaction_queue(
+ unsafe { &mut *runtime_ptr }.append_child_appending_to_current_reaction_queue(
scope,
runtime_ptr,
parent,
child,
- ) {
- return false;
- }
- true
+ )
});
if !inserted {
throw_dom_exception(scope, "HierarchyRequestError", 3, "Hierarchy Error");
@@ -212,16 +209,13 @@ pub(in crate::native_bridge) fn node_insert_before_callback<'s>(
inserted_handles_for_post_insert_events(unsafe { &*runtime_ptr }, child);
let inserted =
custom_elements::with_custom_element_reaction_scope(scope, runtime_ptr, |scope| {
- if !unsafe { &mut *runtime_ptr }.insert_before_appending_to_current_reaction_queue(
+ unsafe { &mut *runtime_ptr }.insert_before_appending_to_current_reaction_queue(
scope,
runtime_ptr,
parent,
child,
reference_child,
- ) {
- return false;
- }
- true
+ )
});
if !inserted {
throw_dom_exception(scope, "HierarchyRequestError", 3, "Hierarchy Error");
@@ -453,7 +447,7 @@ fn node_move_before_after_argument_validation(
}
let moved = custom_elements::with_custom_element_reaction_scope(scope, runtime_ptr, |scope| {
- if !unsafe { &mut *runtime_ptr }
+ unsafe { &mut *runtime_ptr }
.move_before_preserving_state_appending_to_current_reaction_queue(
scope,
runtime_ptr,
@@ -461,10 +455,6 @@ fn node_move_before_after_argument_validation(
child,
reference_child,
)
- {
- return false;
- }
- true
});
if !moved {
throw_dom_exception(scope, "HierarchyRequestError", 3, "Hierarchy Error");
@@ -563,15 +553,12 @@ pub(in crate::native_bridge) fn node_remove_child_callback<'s>(
}
let removed =
custom_elements::with_custom_element_reaction_scope(scope, runtime_ptr, |scope| {
- if !unsafe { &mut *runtime_ptr }.remove_child_appending_to_current_reaction_queue(
+ unsafe { &mut *runtime_ptr }.remove_child_appending_to_current_reaction_queue(
scope,
runtime_ptr,
parent,
child,
- ) {
- return false;
- }
- true
+ )
});
if !removed {
throw_dom_exception(
@@ -670,16 +657,13 @@ pub(in crate::native_bridge) fn node_replace_child_callback<'s>(
inserted_handles_for_post_insert_events(unsafe { &*runtime_ptr }, new_child);
let replaced =
custom_elements::with_custom_element_reaction_scope(scope, runtime_ptr, |scope| {
- if !unsafe { &mut *runtime_ptr }.replace_child_appending_to_current_reaction_queue(
+ unsafe { &mut *runtime_ptr }.replace_child_appending_to_current_reaction_queue(
scope,
runtime_ptr,
parent,
new_child,
old_child,
- ) {
- return false;
- }
- true
+ )
});
if !replaced {
throw_dom_exception(scope, "HierarchyRequestError", 3, "Hierarchy Error");
diff --git a/moli-renderer-v8/src/style_engine/source_owner_text.rs b/moli-renderer-v8/src/style_engine/source_owner_text.rs
index 480df5e7f..743e39ada 100644
--- a/moli-renderer-v8/src/style_engine/source_owner_text.rs
+++ b/moli-renderer-v8/src/style_engine/source_owner_text.rs
@@ -141,10 +141,7 @@ impl OwnerStyleSheetSources {
let Some(installed) = self.sources_by_owner.get_mut(&owner) else {
return false;
};
- if !installed.refresh_live_stylesheet(stylesheet_id) {
- return false;
- }
- true
+ installed.refresh_live_stylesheet(stylesheet_id)
}
pub(super) fn live_stylesheet(
diff --git a/moli-renderer-v8/src/worker/thread/dispatch.rs b/moli-renderer-v8/src/worker/thread/dispatch.rs
index 297ae7929..c72cdf3c3 100644
--- a/moli-renderer-v8/src/worker/thread/dispatch.rs
+++ b/moli-renderer-v8/src/worker/thread/dispatch.rs
@@ -3497,10 +3497,7 @@ fn service_worker_navigation_preload_finish_matches_pending_event(
else {
return false;
};
- if preload.owner != finished.owner || preload.body_source_id != Some(finished.body_source_id) {
- return false;
- }
- true
+ !(preload.owner != finished.owner || preload.body_source_id != Some(finished.body_source_id))
}
pub(super) fn fail_service_worker_navigation_preload_response(
diff --git a/moli-selector/src/stylo/query/pseudo.rs b/moli-selector/src/stylo/query/pseudo.rs
index cb7f5ab00..2a02db1ff 100644
--- a/moli-selector/src/stylo/query/pseudo.rs
+++ b/moli-selector/src/stylo/query/pseudo.rs
@@ -188,15 +188,11 @@ impl<'a> QueryElement<'a> {
}
return self.element().input_value().is_empty();
}
- if self.element().local_name() == "input"
+ self.element().local_name() == "input"
&& self.input_type() == InputType::Number
&& !self.element().input_value().is_empty()
&& parse_input_numeric_value(InputType::Number, &self.element().input_value())
.is_none()
- {
- return true;
- }
- false
}
_ => false,
}
diff --git a/moli-web-mime/src/response_policy.rs b/moli-web-mime/src/response_policy.rs
index 2d176b5d3..15f47bc0d 100644
--- a/moli-web-mime/src/response_policy.rs
+++ b/moli-web-mime/src/response_policy.rs
@@ -116,13 +116,8 @@ pub fn should_opaque_response_be_blocked_by_orb_with_body(
return true;
};
let essence = mime.essence();
- if is_json_mime_essence(&essence)
- && response_body_looks_like_orb_allowed_javascript(&mime.to_string(), body)
- {
- return false;
- }
-
- true
+ !(is_json_mime_essence(&essence)
+ && response_body_looks_like_orb_allowed_javascript(&mime.to_string(), body))
}
pub fn computed_response_mime_type(