Add new Window globals as debuggees

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
Delan Azabani 2025-07-18 21:51:13 +08:00
parent 4d7a514923
commit bae25bb596
3 changed files with 49 additions and 0 deletions

View file

@ -16,8 +16,10 @@ use js::rust::Runtime;
use js::rust::wrappers::JS_DefineDebuggerObject;
use net_traits::ResourceThreads;
use profile_traits::{mem, time};
use script_bindings::conversions::SafeToJSValConvertible;
use script_bindings::realms::InRealm;
use script_bindings::reflector::DomObject;
use script_bindings::utils::set_dictionary_property;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use crate::dom::bindings::codegen::Bindings::DebuggerGlobalScopeBinding;
@ -116,4 +118,31 @@ impl DebuggerGlobalScope {
warn!("Failed to execute debugger request");
}
}
#[allow(unsafe_code)]
pub(crate) fn execute_with_global(&self, can_gc: CanGc, global: &GlobalScope) {
let cx = Self::get_cx();
rooted!(in(*cx) let mut property_value = UndefinedValue());
let _realm = enter_realm(self);
// Convert the debuggee globals reflector to a Value, wrapping it from its originating realm (debuggee realm)
// into the active realm (debugger realm) so that it can be passed across compartments.
global
.reflector()
.safe_to_jsval(cx, property_value.handle_mut());
// TODO: what invariants do we need to uphold for the unsafe call?
if let Err(()) = unsafe {
set_dictionary_property(
*cx,
self.global_scope.reflector().get_jsobject(),
"debuggee",
property_value.handle(),
)
} {
warn!("Failed to set debuggee");
return;
}
self.execute(can_gc);
}
}

View file

@ -3430,6 +3430,8 @@ impl ScriptThread {
incomplete.load_data.inherited_secure_context,
incomplete.theme,
);
self.debugger_global
.execute_with_global(can_gc, window.upcast());
let _realm = enter_realm(&*window);