diff options
author | Auguste Baum <52001167+augustebaum@users.noreply.github.com> | 2025-02-23 01:34:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-23 00:34:51 +0000 |
commit | b0b0289014b707505a6921152b9ecba75afa207f (patch) | |
tree | f2ffba650cf28da83904b14e94ba3913967951f2 /components/script/dom/bindings | |
parent | 02199520f2b611c9b5ab7b34a2372689cb4c22cd (diff) | |
download | servo-b0b0289014b707505a6921152b9ecba75afa207f.tar.gz servo-b0b0289014b707505a6921152b9ecba75afa207f.zip |
refactor: propagate CanGc arguments through callers (#35591)
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/constructor.rs | 18 | ||||
-rw-r--r-- | components/script/dom/bindings/error.rs | 11 | ||||
-rw-r--r-- | components/script/dom/bindings/proxyhandler.rs | 4 | ||||
-rw-r--r-- | components/script/dom/bindings/utils.rs | 2 |
4 files changed, 24 insertions, 11 deletions
diff --git a/components/script/dom/bindings/constructor.rs b/components/script/dom/bindings/constructor.rs index 93c8c9514b1..0fd6e0427bd 100644 --- a/components/script/dom/bindings/constructor.rs +++ b/components/script/dom/bindings/constructor.rs @@ -77,7 +77,12 @@ unsafe fn html_constructor( // so we can do the spec's object-identity checks. rooted!(in(*cx) let new_target_unwrapped = UnwrapObjectDynamic(call_args.new_target().to_object(), *cx, true)); if new_target_unwrapped.is_null() { - throw_dom_exception(cx, global, Error::Type("new.target is null".to_owned())); + throw_dom_exception( + cx, + global, + Error::Type("new.target is null".to_owned()), + can_gc, + ); return Err(()); } if call_args.callee() == new_target_unwrapped.get() { @@ -85,6 +90,7 @@ unsafe fn html_constructor( cx, global, Error::Type("new.target must not be the active function object".to_owned()), + can_gc, ); return Err(()); } @@ -98,6 +104,7 @@ unsafe fn html_constructor( cx, global, Error::Type("No custom element definition found for new.target".to_owned()), + can_gc, ); return Err(()); }, @@ -105,7 +112,7 @@ unsafe fn html_constructor( rooted!(in(*cx) let callee = UnwrapObjectStatic(call_args.callee())); if callee.is_null() { - throw_dom_exception(cx, global, Error::Security); + throw_dom_exception(cx, global, Error::Security, can_gc); return Err(()); } @@ -139,6 +146,7 @@ unsafe fn html_constructor( cx, global, Error::Type("Custom element does not extend the proper interface".to_owned()), + can_gc, ); return Err(()); } @@ -178,7 +186,7 @@ unsafe fn html_constructor( // Step 8.5 if !check_type(&element) { - throw_dom_exception(cx, global, Error::InvalidState); + throw_dom_exception(cx, global, Error::InvalidState, can_gc); return Err(()); } else { element @@ -195,7 +203,7 @@ unsafe fn html_constructor( // Step 13 if !check_type(&element) { - throw_dom_exception(cx, global, Error::InvalidState); + throw_dom_exception(cx, global, Error::InvalidState, can_gc); return Err(()); } else { element @@ -206,7 +214,7 @@ unsafe fn html_constructor( let s = "Top of construction stack marked AlreadyConstructed due to \ a custom element constructor constructing itself after super()" .to_string(); - throw_dom_exception(cx, global, Error::Type(s)); + throw_dom_exception(cx, global, Error::Type(s), can_gc); return Err(()); }, }; diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index abf394b6ed9..779cc04c28b 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -105,7 +105,12 @@ pub(crate) type Fallible<T> = Result<T, Error>; pub(crate) type ErrorResult = Fallible<()>; /// Set a pending exception for the given `result` on `cx`. -pub(crate) fn throw_dom_exception(cx: SafeJSContext, global: &GlobalScope, result: Error) { +pub(crate) fn throw_dom_exception( + cx: SafeJSContext, + global: &GlobalScope, + result: Error, + can_gc: CanGc, +) { #[cfg(feature = "js_backtrace")] unsafe { capture_stack!(in(*cx) let stack); @@ -159,7 +164,7 @@ pub(crate) fn throw_dom_exception(cx: SafeJSContext, global: &GlobalScope, resul unsafe { assert!(!JS_IsExceptionPending(*cx)); - let exception = DOMException::new(global, code, CanGc::note()); + let exception = DOMException::new(global, code, can_gc); rooted!(in(*cx) let mut thrown = UndefinedValue()); exception.to_jsval(*cx, thrown.handle_mut()); JS_SetPendingException(*cx, thrown.handle(), ExceptionStackBehavior::Capture); @@ -349,7 +354,7 @@ impl Error { Error::JSFailed => (), _ => unsafe { assert!(!JS_IsExceptionPending(*cx)) }, } - throw_dom_exception(cx, global, self); + throw_dom_exception(cx, global, self, CanGc::note()); unsafe { assert!(JS_IsExceptionPending(*cx)); assert!(JS_GetPendingException(*cx, rval)); diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index 1258ee2220a..581171b20b5 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -44,7 +44,7 @@ use crate::dom::bindings::str::DOMString; use crate::dom::bindings::utils::delete_property_by_id; use crate::dom::globalscope::{GlobalScope, GlobalScopeHelpers}; use crate::realms::{AlreadyInRealm, InRealm}; -use crate::script_runtime::JSContext as SafeJSContext; +use crate::script_runtime::{CanGc, JSContext as SafeJSContext}; /// Determine if this id shadows any existing properties for this proxy. pub(crate) unsafe extern "C" fn shadow_check_callback( @@ -253,7 +253,7 @@ pub(crate) unsafe fn report_cross_origin_denial( if !JS_IsExceptionPending(*cx) { let global = GlobalScope::from_context(*cx, InRealm::Already(&in_realm_proof)); // TODO: include `id` and `access` in the exception message - throw_dom_exception(cx, &global, Error::Security); + throw_dom_exception(cx, &global, Error::Security, CanGc::note()); } false } diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index b3f3219cf1a..2fc47b09403 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -689,7 +689,7 @@ impl DomHelpers<crate::DomTypeHolder> for crate::DomTypeHolder { global: &<crate::DomTypeHolder as DomTypes>::GlobalScope, result: Error, ) { - throw_dom_exception(cx, global, result) + throw_dom_exception(cx, global, result, CanGc::note()) } unsafe fn call_html_constructor< |