mirror of
https://github.com/servo/servo.git
synced 2025-08-10 16:05:43 +01:00
script: Wrap unsafe code in components/script/bindings
in unsafe {}
(#38544)
Clippy now checks to see if unsafe code is wrapped in unsafe blocks. We have this lint disabled for `script` and `script_bindings` because of a lot of legacy code that doesn't do this. The lint is useful though as it makes it more obvious what code is unsafe. This is an incremental step toward being able to turn this lint on for `script`. This has the benefit of silencing warnings that show up in some IDEs that use rust-analyzer. Testing: This should not change behavior at all and is thus covered by existing tests. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
fef104cff7
commit
931025c16e
13 changed files with 147 additions and 114 deletions
|
@ -604,7 +604,7 @@ unsafe impl<T> crate::dom::bindings::trace::JSTraceable for HeapBufferSource<T>
|
|||
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 {
|
||||
|
|
|
@ -49,9 +49,11 @@ impl<T> DomRefCell<T> {
|
|||
#[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<T> DomRefCell<T> {
|
|||
#[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<T> DomRefCell<T> {
|
|||
#[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() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -179,11 +179,7 @@ impl ErrorInfo {
|
|||
}
|
||||
|
||||
fn from_dom_exception(object: HandleObject, cx: SafeJSContext) -> Option<ErrorInfo> {
|
||||
let exception = match unsafe { root_from_object::<DOMException>(object.get(), *cx) } {
|
||||
Ok(exception) => exception,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let exception = unsafe { root_from_object::<DOMException>(object.get(), *cx).ok()? };
|
||||
Some(ErrorInfo {
|
||||
filename: "".to_string(),
|
||||
message: exception.stringifier().into(),
|
||||
|
|
|
@ -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::<DomTypeHolder>(&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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -71,7 +71,7 @@ impl<T: DomObject> ToLayout<T> for Dom<T> {
|
|||
unsafe fn to_layout(&self) -> LayoutDom<T> {
|
||||
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<T: DomObject> MutNullableDom<T> {
|
|||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
pub(crate) unsafe fn get_inner_as_layout(&self) -> Option<LayoutDom<T>> {
|
||||
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<T: DomObject> MallocSizeOf for DomOnceCell<T> {
|
|||
unsafe impl<T: DomObject> JSTraceable for DomOnceCell<T> {
|
||||
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::<Dom<T>, LayoutDom<T>>;
|
||||
&*(slice as *const [Dom<T>] as *const [LayoutDom<T>])
|
||||
unsafe { &*(slice as *const [Dom<T>] as *const [LayoutDom<T>]) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ thread_local!(pub(super) static STACK: RefCell<Vec<StackEntry<crate::DomTypeHold
|
|||
/// Traces the script settings stack.
|
||||
pub(crate) unsafe fn trace(tracer: *mut JSTracer) {
|
||||
STACK.with(|stack| {
|
||||
stack.borrow().trace(tracer);
|
||||
unsafe { stack.borrow().trace(tracer) };
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -126,11 +126,13 @@ unsafe fn read_object<T: Serializable>(
|
|||
) -> *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<T: Serializable>(
|
|||
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<T: Serializable + IDLInterface>(
|
||||
val: SerializableInterface,
|
||||
cx: *mut JSContext,
|
||||
obj: RawHandleObject,
|
||||
object: RawHandleObject,
|
||||
global: &GlobalScope,
|
||||
w: *mut JSStructuredCloneWriter,
|
||||
writer: &mut StructuredDataWriter,
|
||||
) -> Result<bool, OperationError> {
|
||||
if let Ok(obj) = root_from_object::<T>(*obj, cx) {
|
||||
return Ok(write_object(val, global, &*obj, w, writer));
|
||||
let object = unsafe { root_from_object::<T>(*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<T: Transferable + IDLInterface>(
|
|||
ownership: *mut TransferableOwnership,
|
||||
extra_data: *mut u64,
|
||||
) -> Result<(), OperationError> {
|
||||
let Ok(object) = root_from_object::<T>(*obj, cx) else {
|
||||
let object = unsafe { root_from_object::<T>(*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<T: Transferable + IDLInterface>(
|
|||
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<bool, ()> {
|
||||
root_from_object::<T>(*obj, cx).map(|o| Transferable::can_transfer(&*o))
|
||||
unsafe { root_from_object::<T>(*obj, cx).map(|o| Transferable::can_transfer(&*o)) }
|
||||
}
|
||||
match transferable {
|
||||
TransferrableInterface::ImageBitmap => can_transfer::<ImageBitmap>(obj, cx),
|
||||
TransferrableInterface::MessagePort => can_transfer::<MessagePort>(obj, cx),
|
||||
TransferrableInterface::OffscreenCanvas => can_transfer::<OffscreenCanvas>(obj, cx),
|
||||
TransferrableInterface::ReadableStream => can_transfer::<ReadableStream>(obj, cx),
|
||||
TransferrableInterface::WritableStream => can_transfer::<WritableStream>(obj, cx),
|
||||
TransferrableInterface::TransformStream => can_transfer::<TransformStream>(obj, cx),
|
||||
|
||||
unsafe {
|
||||
match transferable {
|
||||
TransferrableInterface::ImageBitmap => can_transfer::<ImageBitmap>(obj, cx),
|
||||
TransferrableInterface::MessagePort => can_transfer::<MessagePort>(obj, cx),
|
||||
TransferrableInterface::OffscreenCanvas => can_transfer::<OffscreenCanvas>(obj, cx),
|
||||
TransferrableInterface::ReadableStream => can_transfer::<ReadableStream>(obj, cx),
|
||||
TransferrableInterface::WritableStream => can_transfer::<WritableStream>(obj, cx),
|
||||
TransferrableInterface::TransformStream => can_transfer::<TransformStream>(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<Error>);
|
||||
let error = unsafe { &mut *(closure as *mut Option<Error>) };
|
||||
|
||||
if error.is_none() {
|
||||
*error = Some(Error::DataClone(Some(msg)));
|
||||
|
|
|
@ -54,7 +54,7 @@ use crate::task::TaskBox;
|
|||
|
||||
unsafe impl<T: CustomTraceable> CustomTraceable for DomRefCell<T> {
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
(*self).borrow().trace(trc)
|
||||
unsafe { (*self).borrow().trace(trc) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ unsafe impl<K, V: JSTraceable, S> JSTraceable for HashMapTracedValues<K, V, S> {
|
|||
#[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<T: JSTraceable> JSTraceable for DomRefCell<T> {
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
(*self).borrow().trace(trc)
|
||||
unsafe { (*self).borrow().trace(trc) };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,12 +54,9 @@ impl<T: WeakReferenceable> MallocSizeOf for MutableWeakRef<T> {
|
|||
unsafe impl<T: WeakReferenceable> JSTraceable for MutableWeakRef<T> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -428,7 +428,8 @@ impl CustomElementRegistryMethods<crate::DomTypeHolder> 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue