script: Make root_from_handle_value a safe function by accepting SafeJSContext (#39193)

Change from unsafe pointer of root_from_handle_value  to SafeJSContext. 

#39131

---------

Signed-off-by: JasonHonKL <j2004nol@gmail.com>
Signed-off-by: Jason <jason@198-61-252-113-on-nets.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Jason <jason@198-61-252-113-on-nets.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
JasonHonKL 2025-09-09 12:26:02 -07:00 committed by GitHub
parent 721fc01c30
commit 839878c743
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 48 additions and 51 deletions

View file

@ -342,7 +342,7 @@ impl TrustedTypePolicyFactory {
cx: JSContext,
value: HandleValue,
) -> Result<DomRoot<TrustedScript>, ()> {
unsafe { root_from_handlevalue::<TrustedScript>(value, *cx) }
root_from_handlevalue::<TrustedScript>(value, cx)
}
}
@ -359,7 +359,7 @@ impl TrustedTypePolicyFactoryMethods<crate::DomTypeHolder> for TrustedTypePolicy
/// <https://www.w3.org/TR/trusted-types/#dom-trustedtypepolicyfactory-ishtml>
#[allow(unsafe_code)]
fn IsHTML(&self, cx: JSContext, value: HandleValue) -> bool {
unsafe { root_from_handlevalue::<TrustedHTML>(value, *cx).is_ok() }
root_from_handlevalue::<TrustedHTML>(value, cx).is_ok()
}
/// <https://www.w3.org/TR/trusted-types/#dom-trustedtypepolicyfactory-isscript>
#[allow(unsafe_code)]
@ -369,7 +369,7 @@ impl TrustedTypePolicyFactoryMethods<crate::DomTypeHolder> for TrustedTypePolicy
/// <https://www.w3.org/TR/trusted-types/#dom-trustedtypepolicyfactory-isscripturl>
#[allow(unsafe_code)]
fn IsScriptURL(&self, cx: JSContext, value: HandleValue) -> bool {
unsafe { root_from_handlevalue::<TrustedScriptURL>(value, *cx).is_ok() }
root_from_handlevalue::<TrustedScriptURL>(value, cx).is_ok()
}
/// <https://www.w3.org/TR/trusted-types/#dom-trustedtypepolicyfactory-emptyhtml>
fn EmptyHTML(&self, can_gc: CanGc) -> DomRoot<TrustedHTML> {