script: further use of safe to jsval (#38099)

Remove size bound from safe to jsval trait, apply to script/dom, with
the exception of windowproxy.

Second part of https://github.com/servo/servo/issues/37951

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>

*Describe the changes that this pull request makes here. This will be
the commit message.*

Testing: *Describe how this pull request is tested or why it doesn't
require tests*
Fixes: *Link to an issue this pull requests fixes or remove this line if
there is no issue*
This commit is contained in:
Gregory Terzian 2025-07-16 21:46:10 +07:00 committed by GitHub
parent 72a9f36c43
commit b821377771
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 114 additions and 128 deletions

View file

@ -16,13 +16,12 @@ use js::jsval::UndefinedValue;
use js::rust::wrappers::{JS_ErrorFromException, JS_GetPendingException, JS_SetPendingException};
use js::rust::{HandleObject, HandleValue, MutableHandleValue};
use libc::c_uint;
use script_bindings::conversions::SafeToJSValConvertible;
pub(crate) use script_bindings::error::*;
#[cfg(feature = "js_backtrace")]
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::conversions::{
ConversionResult, FromJSValConvertible, ToJSValConvertible, root_from_object,
};
use crate::dom::bindings::conversions::{ConversionResult, FromJSValConvertible, root_from_object};
use crate::dom::bindings::str::USVString;
use crate::dom::domexception::{DOMErrorName, DOMException};
use crate::dom::globalscope::GlobalScope;
@ -80,7 +79,7 @@ pub(crate) fn throw_dom_exception(
can_gc,
);
rooted!(in(*cx) let mut thrown = UndefinedValue());
exception.to_jsval(*cx, thrown.handle_mut());
exception.safe_to_jsval(cx, thrown.handle_mut());
JS_SetPendingException(*cx, thrown.handle(), ExceptionStackBehavior::Capture);
return;
},
@ -119,7 +118,7 @@ pub(crate) fn throw_dom_exception(
assert!(!JS_IsExceptionPending(*cx));
let exception = DOMException::new(global, code, can_gc);
rooted!(in(*cx) let mut thrown = UndefinedValue());
exception.to_jsval(*cx, thrown.handle_mut());
exception.safe_to_jsval(cx, thrown.handle_mut());
JS_SetPendingException(*cx, thrown.handle(), ExceptionStackBehavior::Capture);
}
}

View file

@ -32,10 +32,10 @@ use js::jsapi::{
use js::jsval::UndefinedValue;
use js::rust::wrappers::{JS_ReadStructuredClone, JS_WriteStructuredClone};
use js::rust::{CustomAutoRooterGuard, HandleValue, MutableHandleValue};
use script_bindings::conversions::IDLInterface;
use script_bindings::conversions::{IDLInterface, SafeToJSValConvertible};
use strum::IntoEnumIterator;
use crate::dom::bindings::conversions::{ToJSValConvertible, root_from_object};
use crate::dom::bindings::conversions::root_from_object;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::serializable::{Serializable, StorageKey};
@ -594,7 +594,7 @@ pub(crate) fn write(
unsafe {
rooted!(in(*cx) let mut val = UndefinedValue());
if let Some(transfer) = transfer {
transfer.to_jsval(*cx, val.handle_mut());
transfer.safe_to_jsval(cx, val.handle_mut());
}
let mut sc_writer = StructuredDataWriter::default();
let sc_writer_ptr = &mut sc_writer as *mut _;

View file

@ -13,6 +13,7 @@ use js::jsapi::{
CallArgs, DOMCallbacks, HandleObject as RawHandleObject, JS_FreezeObject, JSContext, JSObject,
};
use js::rust::{HandleObject, MutableHandleValue, get_object_class, is_dom_class};
use script_bindings::conversions::SafeToJSValConvertible;
use script_bindings::interfaces::{DomHelpers, Interface};
use script_bindings::settings_stack::StackEntry;
@ -59,7 +60,7 @@ pub(crate) fn to_frozen_array<T: ToJSValConvertible>(
mut rval: MutableHandleValue,
_can_gc: CanGc,
) {
unsafe { convertibles.to_jsval(*cx, rval.reborrow()) };
convertibles.safe_to_jsval(cx, rval.reborrow());
rooted!(in(*cx) let obj = rval.to_object());
unsafe { JS_FreezeObject(*cx, RawHandleObject::from(obj.handle())) };