script: introduce safe wrappers for js val conversions (#38004)

Introduce a safe wrapper trait for the unsafe `ToJSValConvertible`, and
use it in `script/dom` where the default `T` implementation works.

Part of https://github.com/servo/servo/issues/37951

---------

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
Gregory Terzian 2025-07-15 08:57:15 +07:00 committed by GitHub
parent 9e2ee0029a
commit 027954dbad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 149 additions and 187 deletions

View file

@ -4,10 +4,10 @@
use dom_struct::dom_struct;
use euclid::RigidTransform3D;
use js::conversions::ToJSValConvertible;
use js::jsapi::Heap;
use js::jsval::{JSVal, UndefinedValue};
use js::rust::MutableHandleValue;
use script_bindings::conversions::SafeToJSValConvertible;
use webxr_api::{Viewer, ViewerPose, Views};
use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
@ -38,7 +38,6 @@ impl XRViewerPose {
}
}
#[allow(unsafe_code)]
pub(crate) fn new(
window: &Window,
session: &XRSession,
@ -183,11 +182,9 @@ impl XRViewerPose {
);
let cx = GlobalScope::get_cx();
unsafe {
rooted!(in(*cx) let mut jsval = UndefinedValue());
views.to_jsval(*cx, jsval.handle_mut());
pose.views.set(jsval.get());
}
rooted!(in(*cx) let mut jsval = UndefinedValue());
views.safe_to_jsval(cx, jsval.handle_mut());
pose.views.set(jsval.get());
pose
}