diff --git a/components/script/dom/bindings/buffer_source.rs b/components/script/dom/bindings/buffer_source.rs index 6af96e0281a..a271cad5643 100644 --- a/components/script/dom/bindings/buffer_source.rs +++ b/components/script/dom/bindings/buffer_source.rs @@ -604,7 +604,7 @@ unsafe impl crate::dom::bindings::trace::JSTraceable for HeapBufferSource unsafe fn trace(&self, tracer: *mut js::jsapi::JSTracer) { match &self.buffer_source { BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer) => { - buffer.trace(tracer); + unsafe { buffer.trace(tracer) }; }, } } @@ -879,7 +879,7 @@ impl DataBlock { // the exact same line to fix it. Doing the cast is tricky because of the use of // a generic type in this parameter. #[allow(clippy::from_raw_with_void_ptr)] - drop(Arc::from_raw(free_user_data as *const _)); + drop(unsafe { Arc::from_raw(free_user_data as *const _) }); } let raw: *mut Box<[u8]> = Arc::into_raw(Arc::clone(&self.data)) as _; rooted!(in(*cx) let object = unsafe { diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index 805ab28224f..ce050b482a9 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -49,9 +49,11 @@ impl DomRefCell { #[allow(unsafe_code)] pub(crate) unsafe fn borrow_for_layout(&self) -> &T { assert_in_layout(); - self.value - .try_borrow_unguarded() - .expect("cell is mutably borrowed") + unsafe { + self.value + .try_borrow_unguarded() + .expect("cell is mutably borrowed") + } } /// Borrow the contents for the purpose of script deallocation. @@ -68,7 +70,7 @@ impl DomRefCell { #[allow(unsafe_code, clippy::mut_from_ref)] pub(crate) unsafe fn borrow_for_script_deallocation(&self) -> &mut T { assert_in_script(); - &mut *self.value.as_ptr() + unsafe { &mut *self.value.as_ptr() } } /// Mutably borrow a cell for layout. Ideally this would use @@ -86,7 +88,7 @@ impl DomRefCell { #[allow(unsafe_code, clippy::mut_from_ref)] pub(crate) unsafe fn borrow_mut_for_layout(&self) -> &mut T { assert_in_layout(); - &mut *self.value.as_ptr() + unsafe { &mut *self.value.as_ptr() } } } diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index f01357fda55..51a150f5808 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -84,16 +84,18 @@ pub(crate) unsafe fn get_property_jsval( Err(_) => return Ok(()), }; let mut found = false; - if JS_HasProperty(cx, object, cname.as_ptr(), &mut found) && found { - JS_GetProperty(cx, object, cname.as_ptr(), rval); - if JS_IsExceptionPending(cx) { - return Err(Error::JSFailed); + unsafe { + if JS_HasProperty(cx, object, cname.as_ptr(), &mut found) && found { + JS_GetProperty(cx, object, cname.as_ptr(), rval); + if JS_IsExceptionPending(cx) { + return Err(Error::JSFailed); + } + Ok(()) + } else if JS_IsExceptionPending(cx) { + Err(Error::JSFailed) + } else { + Ok(()) } - Ok(()) - } else if JS_IsExceptionPending(cx) { - Err(Error::JSFailed) - } else { - Ok(()) } } @@ -109,13 +111,14 @@ where { debug!("Getting property {}.", name); rooted!(in(cx) let mut result = UndefinedValue()); - get_property_jsval(cx, object, name, result.handle_mut())?; + unsafe { get_property_jsval(cx, object, name, result.handle_mut())? }; if result.is_undefined() { debug!("No property {}.", name); return Ok(None); } debug!("Converting property {}.", name); - match T::from_jsval(cx, result.handle(), option) { + let value = unsafe { T::from_jsval(cx, result.handle(), option) }; + match value { Ok(ConversionResult::Success(value)) => Ok(Some(value)), Ok(ConversionResult::Failure(_)) => Ok(None), Err(()) => Err(Error::JSFailed), diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index e280c347000..0e7601817a9 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -179,11 +179,7 @@ impl ErrorInfo { } fn from_dom_exception(object: HandleObject, cx: SafeJSContext) -> Option { - let exception = match unsafe { root_from_object::(object.get(), *cx) } { - Ok(exception) => exception, - Err(_) => return None, - }; - + let exception = unsafe { root_from_object::(object.get(), *cx).ok()? }; Some(ErrorInfo { filename: "".to_string(), message: exception.stringifier().into(), diff --git a/components/script/dom/bindings/principals.rs b/components/script/dom/bindings/principals.rs index 0594b77022c..bc9132f1bb3 100644 --- a/components/script/dom/bindings/principals.rs +++ b/components/script/dom/bindings/principals.rs @@ -16,8 +16,10 @@ use crate::DomTypeHolder; #[allow(unused)] pub(crate) unsafe extern "C" fn destroy_servo_jsprincipal(principals: *mut JSPrincipals) { - Box::from_raw(GetRustJSPrincipalsPrivate(principals) as *mut MutableOrigin); - DestroyRustJSPrincipals(principals); + unsafe { + Box::from_raw(GetRustJSPrincipalsPrivate(principals) as *mut MutableOrigin); + DestroyRustJSPrincipals(principals); + } } pub(crate) unsafe extern "C" fn write_jsprincipal( @@ -28,7 +30,7 @@ pub(crate) unsafe extern "C" fn write_jsprincipal( let Some(principal) = NonNull::new(principal) else { return false; }; - let obj = ServoJSPrincipalsRef::from_raw_nonnull(principal); + let obj = unsafe { ServoJSPrincipalsRef::from_raw_nonnull(principal) }; let origin = obj.origin(); let Ok(bytes_of_origin) = bincode::serialize(&origin) else { return false; @@ -36,12 +38,16 @@ pub(crate) unsafe extern "C" fn write_jsprincipal( let Ok(len) = bytes_of_origin.len().try_into() else { return false; }; - if !js::jsapi::JS_WriteUint32Pair(writer, StructuredCloneTags::Principals as u32, len) { - return false; - } - if !js::jsapi::JS_WriteBytes(writer, bytes_of_origin.as_ptr() as _, len as usize) { - return false; + + unsafe { + if !js::jsapi::JS_WriteUint32Pair(writer, StructuredCloneTags::Principals as u32, len) { + return false; + } + if !js::jsapi::JS_WriteBytes(writer, bytes_of_origin.as_ptr() as _, len as usize) { + return false; + } } + true } @@ -52,21 +58,29 @@ pub(crate) unsafe extern "C" fn read_jsprincipal( ) -> bool { let mut tag: u32 = 0; let mut len: u32 = 0; - if !JS_ReadUint32Pair(reader, &mut tag as *mut u32, &mut len as *mut u32) { - return false; + + unsafe { + if !JS_ReadUint32Pair(reader, &mut tag as *mut u32, &mut len as *mut u32) { + return false; + } } + if tag != StructuredCloneTags::Principals as u32 { return false; } let mut bytes = vec![0u8; len as usize]; - if !js::jsapi::JS_ReadBytes(reader, bytes.as_mut_ptr() as _, len as usize) { - return false; + + unsafe { + if !js::jsapi::JS_ReadBytes(reader, bytes.as_mut_ptr() as _, len as usize) { + return false; + } } + let Ok(origin) = bincode::deserialize(&bytes[..]) else { return false; }; let principal = ServoJSPrincipals::new::(&origin); - *principals = principal.as_raw(); + unsafe { *principals = principal.as_raw() }; // we transferred ownership of principal to the caller std::mem::forget(principal); true @@ -85,8 +99,8 @@ unsafe extern "C" fn principals_is_system_or_addon_principal(_: *mut JSPrincipal pub(crate) unsafe extern "C" fn subsumes(obj: *mut JSPrincipals, other: *mut JSPrincipals) -> bool { match (NonNull::new(obj), NonNull::new(other)) { (Some(obj), Some(other)) => { - let obj = ServoJSPrincipalsRef::from_raw_nonnull(obj); - let other = ServoJSPrincipalsRef::from_raw_nonnull(other); + let obj = unsafe { ServoJSPrincipalsRef::from_raw_nonnull(obj) }; + let other = unsafe { ServoJSPrincipalsRef::from_raw_nonnull(other) }; let obj_origin = obj.origin(); let other_origin = other.origin(); obj_origin.same_origin_domain(&other_origin) diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index 2e203a81fa9..ef420729f22 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -18,13 +18,14 @@ pub(crate) unsafe fn is_platform_object_same_origin( cx: SafeJSContext, obj: RawHandleObject, ) -> bool { - let subject_realm = get_context_realm(*cx); - let obj_realm = GetObjectRealmOrNull(*obj); + let subject_realm = unsafe { get_context_realm(*cx) }; + let obj_realm = unsafe { GetObjectRealmOrNull(*obj) }; assert!(!obj_realm.is_null()); let subject_principals = - ServoJSPrincipalsRef::from_raw_unchecked(GetRealmPrincipals(subject_realm)); - let obj_principals = ServoJSPrincipalsRef::from_raw_unchecked(GetRealmPrincipals(obj_realm)); + unsafe { ServoJSPrincipalsRef::from_raw_unchecked(GetRealmPrincipals(subject_realm)) }; + let obj_principals = + unsafe { ServoJSPrincipalsRef::from_raw_unchecked(GetRealmPrincipals(obj_realm)) }; let subject_origin = subject_principals.origin(); let obj_origin = obj_principals.origin(); diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index eccf32cdd77..096950c2f1f 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -270,13 +270,13 @@ impl LiveDOMReferences { Occupied(mut entry) => match entry.get().upgrade() { Some(refcount) => refcount, None => { - let refcount = Arc::new(TrustedReference::new(ptr)); + let refcount = Arc::new(unsafe { TrustedReference::new(ptr) }); entry.insert(Arc::downgrade(&refcount)); refcount }, }, Vacant(entry) => { - let refcount = Arc::new(TrustedReference::new(ptr)); + let refcount = Arc::new(unsafe { TrustedReference::new(ptr) }); entry.insert(Arc::downgrade(&refcount)); refcount }, @@ -307,15 +307,18 @@ pub(crate) unsafe fn trace_refcounted_objects(tracer: *mut JSTracer) { let mut table = live_references.reflectable_table.borrow_mut(); remove_nulls(&mut table); for obj in table.keys() { - let reflectable = &*(*obj as *const Reflector); - trace_reflector(tracer, "refcounted", reflectable); + unsafe { + trace_reflector(tracer, "refcounted", &*(*obj as *const Reflector)); + } } } { let table = live_references.promise_table.borrow_mut(); for promise in table.keys() { - trace_reflector(tracer, "refcounted", (**promise).reflector()); + unsafe { + trace_reflector(tracer, "refcounted", (**promise).reflector()); + } } } }); diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index 24d291f79bf..599254a5ad5 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -71,7 +71,7 @@ impl ToLayout for Dom { unsafe fn to_layout(&self) -> LayoutDom { assert_in_layout(); LayoutDom { - value: self.as_ptr().as_ref().unwrap(), + value: unsafe { self.as_ptr().as_ref().unwrap() }, } } } @@ -162,7 +162,7 @@ impl LayoutDom<'_, Node> { assert_in_layout(); let TrustedNodeAddress(addr) = inner; LayoutDom { - value: &*(addr as *const Node), + value: unsafe { &*(addr as *const Node) }, } } } @@ -268,7 +268,7 @@ impl MutNullableDom { #[cfg_attr(crown, allow(crown::unrooted_must_root))] pub(crate) unsafe fn get_inner_as_layout(&self) -> Option> { assert_in_layout(); - (*self.ptr.get()).as_ref().map(|js| js.to_layout()) + unsafe { (*self.ptr.get()).as_ref().map(|js| js.to_layout()) } } /// Get a rooted value out of this object @@ -385,7 +385,7 @@ impl MallocSizeOf for DomOnceCell { unsafe impl JSTraceable for DomOnceCell { unsafe fn trace(&self, trc: *mut JSTracer) { if let Some(ptr) = self.ptr.get() { - ptr.trace(trc); + unsafe { ptr.trace(trc) }; } } } @@ -407,7 +407,7 @@ where // This doesn't compile if Dom and LayoutDom don't have the same // representation. let _ = mem::transmute::, LayoutDom>; - &*(slice as *const [Dom] as *const [LayoutDom]) + unsafe { &*(slice as *const [Dom] as *const [LayoutDom]) } } } diff --git a/components/script/dom/bindings/settings_stack.rs b/components/script/dom/bindings/settings_stack.rs index 8e00d03a953..9a8a210cca8 100644 --- a/components/script/dom/bindings/settings_stack.rs +++ b/components/script/dom/bindings/settings_stack.rs @@ -20,7 +20,7 @@ thread_local!(pub(super) static STACK: RefCell( ) -> *mut JSObject { let mut name_space: u32 = 0; let mut index: u32 = 0; - assert!(JS_ReadUint32Pair( - r, - &mut name_space as *mut u32, - &mut index as *mut u32 - )); + unsafe { + assert!(JS_ReadUint32Pair( + r, + &mut name_space as *mut u32, + &mut index as *mut u32 + )); + } let storage_key = StorageKey { index, name_space }; // 1. Re-build the key for the storage location @@ -171,16 +173,18 @@ unsafe fn write_object( objects.insert(new_id, serialized); let storage_key = StorageKey::new(new_id); - assert!(JS_WriteUint32Pair( - w, - StructuredCloneTags::from(interface) as u32, - 0 - )); - assert!(JS_WriteUint32Pair( - w, - storage_key.name_space, - storage_key.index - )); + unsafe { + assert!(JS_WriteUint32Pair( + w, + StructuredCloneTags::from(interface) as u32, + 0 + )); + assert!(JS_WriteUint32Pair( + w, + storage_key.name_space, + storage_key.index + )); + } return true; } warn!("Writing structured data failed in {:?}.", owner.get_url()); @@ -204,13 +208,15 @@ unsafe extern "C" fn read_callback( "tag should be higher than StructuredCloneTags::Min" ); - let sc_reader = &mut *(closure as *mut StructuredDataReader<'_>); - let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx)); - let global = GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)); - for serializable in SerializableInterface::iter() { - if tag == StructuredCloneTags::from(serializable) as u32 { - let reader = reader_for_type(serializable); - return reader(&global, r, sc_reader, CanGc::note()); + unsafe { + let sc_reader = &mut *(closure as *mut StructuredDataReader<'_>); + let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx)); + let global = GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)); + for serializable in SerializableInterface::iter() { + if tag == StructuredCloneTags::from(serializable) as u32 { + let reader = reader_for_type(serializable); + return reader(&global, r, sc_reader, CanGc::note()); + } } } @@ -225,13 +231,14 @@ enum OperationError { unsafe fn try_serialize( val: SerializableInterface, cx: *mut JSContext, - obj: RawHandleObject, + object: RawHandleObject, global: &GlobalScope, w: *mut JSStructuredCloneWriter, writer: &mut StructuredDataWriter, ) -> Result { - if let Ok(obj) = root_from_object::(*obj, cx) { - return Ok(write_object(val, global, &*obj, w, writer)); + let object = unsafe { root_from_object::(*object, cx) }; + if let Ok(obj) = object { + return unsafe { Ok(write_object(val, global, &*obj, w, writer)) }; } Err(OperationError::InterfaceDoesNotMatch) } @@ -262,13 +269,15 @@ unsafe extern "C" fn write_callback( _same_process_scope_required: *mut bool, closure: *mut raw::c_void, ) -> bool { - let sc_writer = &mut *(closure as *mut StructuredDataWriter); - let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx)); - let global = GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)); - for serializable in SerializableInterface::iter() { - let serializer = serialize_for_type(serializable); - if let Ok(result) = serializer(serializable, cx, obj, &global, w, sc_writer) { - return result; + unsafe { + let sc_writer = &mut *(closure as *mut StructuredDataWriter); + let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx)); + let global = GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)); + for serializable in SerializableInterface::iter() { + let serializer = serialize_for_type(serializable); + if let Ok(result) = serializer(serializable, cx, obj, &global, w, sc_writer) { + return result; + } } } false @@ -344,9 +353,9 @@ unsafe extern "C" fn read_transfer_callback( closure: *mut raw::c_void, return_object: RawMutableHandleObject, ) -> bool { - let sc_reader = &mut *(closure as *mut StructuredDataReader<'_>); - let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx)); - let owner = GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)); + let sc_reader = unsafe { &mut *(closure as *mut StructuredDataReader<'_>) }; + let in_realm_proof = unsafe { AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx)) }; + let owner = unsafe { GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)) }; for transferrable in TransferrableInterface::iter() { if tag == StructuredCloneTags::from(transferrable) as u32 { @@ -368,12 +377,13 @@ unsafe fn try_transfer( ownership: *mut TransferableOwnership, extra_data: *mut u64, ) -> Result<(), OperationError> { - let Ok(object) = root_from_object::(*obj, cx) else { + let object = unsafe { root_from_object::(*obj, cx) }; + let Ok(object) = object else { return Err(OperationError::InterfaceDoesNotMatch); }; - *tag = StructuredCloneTags::from(interface) as u32; - *ownership = TransferableOwnership::SCTAG_TMO_CUSTOM; + unsafe { *tag = StructuredCloneTags::from(interface) as u32 }; + unsafe { *ownership = TransferableOwnership::SCTAG_TMO_CUSTOM }; let (id, object) = object.transfer().map_err(OperationError::Exception)?; @@ -393,7 +403,7 @@ unsafe fn try_transfer( right.copy_from_slice(&index); // 3. Return a u64 representation of the key where the object is stored. - *extra_data = u64::from_ne_bytes(big); + unsafe { *extra_data = u64::from_ne_bytes(big) }; Ok(()) } @@ -428,11 +438,13 @@ unsafe extern "C" fn write_transfer_callback( _content: *mut *mut raw::c_void, extra_data: *mut u64, ) -> bool { - let sc_writer = &mut *(closure as *mut StructuredDataWriter); + let sc_writer = unsafe { &mut *(closure as *mut StructuredDataWriter) }; for transferable in TransferrableInterface::iter() { let try_transfer = transfer_for_type(transferable); - match try_transfer(transferable, obj, cx, sc_writer, tag, ownership, extra_data) { + let transfer_result = + unsafe { try_transfer(transferable, obj, cx, sc_writer, tag, ownership, extra_data) }; + match transfer_result { Err(error) => match error { OperationError::InterfaceDoesNotMatch => {}, OperationError::Exception(error) => { @@ -465,15 +477,18 @@ unsafe fn can_transfer_for_type( obj: RawHandleObject, cx: *mut JSContext, ) -> Result { - root_from_object::(*obj, cx).map(|o| Transferable::can_transfer(&*o)) + unsafe { root_from_object::(*obj, cx).map(|o| Transferable::can_transfer(&*o)) } } - match transferable { - TransferrableInterface::ImageBitmap => can_transfer::(obj, cx), - TransferrableInterface::MessagePort => can_transfer::(obj, cx), - TransferrableInterface::OffscreenCanvas => can_transfer::(obj, cx), - TransferrableInterface::ReadableStream => can_transfer::(obj, cx), - TransferrableInterface::WritableStream => can_transfer::(obj, cx), - TransferrableInterface::TransformStream => can_transfer::(obj, cx), + + unsafe { + match transferable { + TransferrableInterface::ImageBitmap => can_transfer::(obj, cx), + TransferrableInterface::MessagePort => can_transfer::(obj, cx), + TransferrableInterface::OffscreenCanvas => can_transfer::(obj, cx), + TransferrableInterface::ReadableStream => can_transfer::(obj, cx), + TransferrableInterface::WritableStream => can_transfer::(obj, cx), + TransferrableInterface::TransformStream => can_transfer::(obj, cx), + } } } @@ -484,7 +499,8 @@ unsafe extern "C" fn can_transfer_callback( _closure: *mut raw::c_void, ) -> bool { for transferable in TransferrableInterface::iter() { - if let Ok(can_transfer) = can_transfer_for_type(transferable, obj, cx) { + let can_transfer = unsafe { can_transfer_for_type(transferable, obj, cx) }; + if let Ok(can_transfer) = can_transfer { return can_transfer; } } @@ -500,7 +516,7 @@ unsafe extern "C" fn report_error_callback( let msg_result = unsafe { CStr::from_ptr(error_message).to_str().map(str::to_string) }; if let Ok(msg) = msg_result { - let error = &mut *(closure as *mut Option); + let error = unsafe { &mut *(closure as *mut Option) }; if error.is_none() { *error = Some(Error::DataClone(Some(msg))); diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 5d48e4c4e0f..0eedf13e214 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -54,7 +54,7 @@ use crate::task::TaskBox; unsafe impl CustomTraceable for DomRefCell { unsafe fn trace(&self, trc: *mut JSTracer) { - (*self).borrow().trace(trc) + unsafe { (*self).borrow().trace(trc) } } } @@ -193,7 +193,7 @@ unsafe impl JSTraceable for HashMapTracedValues { #[inline] unsafe fn trace(&self, trc: *mut ::js::jsapi::JSTracer) { for v in self.0.values() { - v.trace(trc); + unsafe { v.trace(trc) }; } } } @@ -247,7 +247,7 @@ pub(crate) fn trace_string(tracer: *mut JSTracer, description: &str, s: &Heap<*m unsafe impl JSTraceable for DomRefCell { unsafe fn trace(&self, trc: *mut JSTracer) { - (*self).borrow().trace(trc) + unsafe { (*self).borrow().trace(trc) }; } } diff --git a/components/script/dom/bindings/weakref.rs b/components/script/dom/bindings/weakref.rs index c1cb012b7c2..bf22a4158b7 100644 --- a/components/script/dom/bindings/weakref.rs +++ b/components/script/dom/bindings/weakref.rs @@ -54,12 +54,9 @@ impl MallocSizeOf for MutableWeakRef { unsafe impl JSTraceable for MutableWeakRef { unsafe fn trace(&self, _: *mut JSTracer) { let ptr = self.cell.get(); - let should_drop = match *ptr { - Some(ref value) => !value.is_alive(), - None => false, - }; - if should_drop { - mem::drop((*ptr).take().unwrap()); + let value = unsafe { &mut *ptr }; + if value.as_ref().is_some_and(|value| !value.is_alive()) { + mem::drop(value.take().unwrap()); } } } diff --git a/components/script/dom/customelementregistry.rs b/components/script/dom/customelementregistry.rs index 18d5a59f954..6bd9db4ae08 100644 --- a/components/script/dom/customelementregistry.rs +++ b/components/script/dom/customelementregistry.rs @@ -428,7 +428,8 @@ impl CustomElementRegistryMethods for CustomElementRegistr rooted!(in(*cx) let proto_object = prototype.to_object()); let mut callbacks = { let _ac = JSAutoRealm::new(*cx, proto_object.get()); - match unsafe { self.get_callbacks(proto_object.handle()) } { + let callbacks = unsafe { self.get_callbacks(proto_object.handle()) }; + match callbacks { Ok(callbacks) => callbacks, Err(error) => { self.element_definition_is_running.set(false);