Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(navigation): allocate activation in the owning realm

ldm0b55824eba4ee
diff --git a/moli-renderer-v8/src/context_bootstrap/navigation_activation.rs b/moli-renderer-v8/src/context_bootstrap/navigation_activation.rs
index 116ec0886..afd3a13aa 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigation_activation.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigation_activation.rs
@@ -154,12 +154,14 @@ pub(super) fn bind_navigation_entry_runtime_owner<'s>(
pub(super) fn create_navigation_activation_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
+ context: v8::Local<'s, v8::Context>,
current_entry: v8::Local<'s, v8::Object>,
activation: Option<&NavigationActivationSeed>,
) -> v8::Local<'s, v8::Value> {
let Some(activation) = activation else {
return v8::null(scope).into();
};
+ let scope = &mut v8::ContextScope::new(scope, context);
let entry = navigation_activation_entry_object(scope, current_entry, activation);
let from = activation
.from
@@ -173,7 +175,6 @@ pub(super) fn create_navigation_activation_object<'s>(
.and_then(|value| v8_string(scope, value))
.map(v8::Local::<v8::Value>::from)
.unwrap_or_else(|| v8::null(scope).into());
- let context = scope.get_current_context();
let entry = super::history_runtime::native::entry_in_realm(scope, entry, context);
let from = if let Ok(from) = v8::Local::<v8::Object>::try_from(from) {
super::history_runtime::native::entry_in_realm(scope, from, context).into()
@@ -192,7 +193,11 @@ pub(super) fn install_navigation_activation_runtime_state<'s>(
current_entry: v8::Local<'s, v8::Object>,
activation: Option<&NavigationActivationSeed>,
) {
- let activation_value = create_navigation_activation_object(scope, current_entry, activation);
+ let context = navigation
+ .get_creation_context(scope)
+ .unwrap_or_else(|| scope.get_current_context());
+ let activation_value =
+ create_navigation_activation_object(scope, context, current_entry, activation);
set_navigation_activation_value(scope, navigation, activation_value);
if super::shared_event_targets::shared_target_owner(scope, navigation)
.strict_equals(navigation.into())
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs
index fc499d015..9c04311aa 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs
@@ -13356,6 +13356,50 @@ const initialDocument = frame.contentDocument;
}
}
+#[test]
+fn initial_about_blank_navigation_activation_uses_child_realm() {
+ let mut vm = new_storage_test_vm("https://activation-realm.test/");
+ assert_eq!(
+ vm.eval(
+ r#"
+const frame = document.createElement('iframe');
+(document.body || document.documentElement || document).appendChild(frame);
+String(frame.contentWindow.navigation.activation === null)
+"#,
+ )
+ .expect("initial child should have no activation"),
+ "true"
+ );
+ vm.exec(
+ "frame.contentWindow.navigation.navigate('about:blank?next');",
+ None,
+ )
+ .expect("parent should navigate the initial child");
+ vm.drain_pending_child_frame_work_for_test();
+
+ assert_eq!(
+ vm.eval(
+ r#"
+(() => {
+ const child = frame.contentWindow;
+ const activation = child.navigation.activation;
+ return JSON.stringify([
+ activation.entry === child.navigation.currentEntry,
+ Object.getPrototypeOf(activation) === child.NavigationActivation.prototype,
+ Object.getPrototypeOf(activation.entry) === child.NavigationHistoryEntry.prototype,
+ Object.getPrototypeOf(activation.from) === child.NavigationHistoryEntry.prototype,
+ activation.from.url,
+ activation.from.index,
+ activation.navigationType
+ ]);
+})()
+"#,
+ )
+ .expect("activation and its entries should belong to the child realm"),
+ r#"[true,true,true,true,"about:blank",-1,"replace"]"#
+ );
+}
+
#[test]
fn non_initial_about_blank_iframe_assign_appends_history_after_replace() {
for initial_srcdoc in [false, true] {