diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index b40b211c294..49f6a66b61b 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -467,38 +467,46 @@ unsafe fn clone_an_object( // Step 2. Append value to `seen`. seen.insert(hashable.clone()); - let return_val = if is_array_like::(cx, val) || - is_arguments_object(cx, val) - { + let return_val = if unsafe { + is_array_like::(cx, val) || is_arguments_object(cx, val) + } { let mut result: Vec = Vec::new(); - let length = - match get_property::(cx, object_handle, "length", ConversionBehavior::Default) { - Ok(length) => match length { - Some(length) => length, - _ => return Err(WebDriverJSError::UnknownType), - }, - Err(error) => { - throw_dom_exception( - SafeJSContext::from_ptr(cx), - global_scope, - error, - CanGc::note(), - ); - return Err(WebDriverJSError::JSError); - }, - }; + let get_property_result = unsafe { + get_property::(cx, object_handle, "length", ConversionBehavior::Default) + }; + let length = match get_property_result { + Ok(length) => match length { + Some(length) => length, + _ => return Err(WebDriverJSError::UnknownType), + }, + Err(error) => { + throw_dom_exception( + unsafe { SafeJSContext::from_ptr(cx) }, + global_scope, + error, + CanGc::note(), + ); + return Err(WebDriverJSError::JSError); + }, + }; // Step 4. For each enumerable property in value, run the following substeps: for i in 0..length { rooted!(in(cx) let mut item = UndefinedValue()); - match get_property_jsval(cx, object_handle, &i.to_string(), item.handle_mut()) { - Ok(_) => match jsval_to_webdriver_inner(cx, global_scope, item.handle(), seen) { - Ok(converted_item) => result.push(converted_item), - err @ Err(_) => return err, + let get_property_result = + unsafe { get_property_jsval(cx, object_handle, &i.to_string(), item.handle_mut()) }; + match get_property_result { + Ok(_) => { + let conversion_result = + unsafe { jsval_to_webdriver_inner(cx, global_scope, item.handle(), seen) }; + match conversion_result { + Ok(converted_item) => result.push(converted_item), + err @ Err(_) => return err, + } }, Err(error) => { throw_dom_exception( - SafeJSContext::from_ptr(cx), + unsafe { SafeJSContext::from_ptr(cx) }, global_scope, error, CanGc::note(), @@ -511,13 +519,16 @@ unsafe fn clone_an_object( } else { let mut result = HashMap::new(); - let mut ids = IdVector::new(cx); - if !GetPropertyKeys( - cx, - object_handle.into(), - jsapi::JSITER_OWNONLY, - ids.handle_mut(), - ) { + let mut ids = unsafe { IdVector::new(cx) }; + let succeeded = unsafe { + GetPropertyKeys( + cx, + object_handle.into(), + jsapi::JSITER_OWNONLY, + ids.handle_mut(), + ) + }; + if !succeeded { return Err(WebDriverJSError::JSError); } for id in ids.iter() { @@ -525,32 +536,40 @@ unsafe fn clone_an_object( rooted!(in(cx) let mut desc = PropertyDescriptor::default()); let mut is_none = false; - if !JS_GetOwnPropertyDescriptorById( - cx, - object_handle.into(), - id.handle().into(), - desc.handle_mut().into(), - &mut is_none, - ) { + let succeeded = unsafe { + JS_GetOwnPropertyDescriptorById( + cx, + object_handle.into(), + id.handle().into(), + desc.handle_mut().into(), + &mut is_none, + ) + }; + if !succeeded { return Err(WebDriverJSError::JSError); } rooted!(in(cx) let mut property = UndefinedValue()); - if !JS_GetPropertyById( - cx, - object_handle.into(), - id.handle().into(), - property.handle_mut().into(), - ) { + let succeeded = unsafe { + JS_GetPropertyById( + cx, + object_handle.into(), + id.handle().into(), + property.handle_mut().into(), + ) + }; + if !succeeded { return Err(WebDriverJSError::JSError); } + if !property.is_undefined() { - let Some(name) = jsid_to_string(cx, id.handle()) else { + let name = unsafe { jsid_to_string(cx, id.handle()) }; + let Some(name) = name else { return Err(WebDriverJSError::JSError); }; if let Ok(value) = - jsval_to_webdriver_inner(cx, global_scope, property.handle(), seen) + unsafe { jsval_to_webdriver_inner(cx, global_scope, property.handle(), seen) } { result.insert(name.into(), value); } else { diff --git a/components/script/window_named_properties.rs b/components/script/window_named_properties.rs index 5cdb8bd6c2c..0cc52ed5538 100644 --- a/components/script/window_named_properties.rs +++ b/components/script/window_named_properties.rs @@ -89,11 +89,13 @@ unsafe extern "C" fn get_own_property_descriptor( let cx = unsafe { SafeJSContext::from_ptr(cx) }; if id.is_symbol() { - if id.get().asBits_ == SymbolId(GetWellKnownSymbol(*cx, SymbolCode::toStringTag)).asBits_ { + if id.get().asBits_ == + SymbolId(unsafe { GetWellKnownSymbol(*cx, SymbolCode::toStringTag) }).asBits_ + { rooted!(in(*cx) let mut rval = UndefinedValue()); - "WindowProperties".to_jsval(*cx, rval.handle_mut()); + unsafe { "WindowProperties".to_jsval(*cx, rval.handle_mut()) }; set_property_descriptor( - RustMutableHandle::from_raw(desc), + unsafe { RustMutableHandle::from_raw(desc) }, rval.handle(), JSPROP_READONLY.into(), unsafe { &mut *is_none }, @@ -103,12 +105,15 @@ unsafe extern "C" fn get_own_property_descriptor( } let mut found = false; - if !has_property_on_prototype( - *cx, - RustHandle::from_raw(proxy), - RustHandle::from_raw(id), - &mut found, - ) { + let lookup_succeeded = unsafe { + has_property_on_prototype( + *cx, + RustHandle::from_raw(proxy), + RustHandle::from_raw(id), + &mut found, + ) + }; + if !lookup_succeeded { return false; } if found { @@ -136,7 +141,9 @@ unsafe extern "C" fn get_own_property_descriptor( .expect("global is not a window"); if let Some(obj) = window.NamedGetter(s.into()) { rooted!(in(*cx) let mut rval = UndefinedValue()); - obj.to_jsval(*cx, rval.handle_mut()); + unsafe { + obj.to_jsval(*cx, rval.handle_mut()); + } set_property_descriptor( unsafe { RustMutableHandle::from_raw(desc) }, rval.handle(), diff --git a/components/script_bindings/utils.rs b/components/script_bindings/utils.rs index 0b924e0e43b..57dde90b23a 100644 --- a/components/script_bindings/utils.rs +++ b/components/script_bindings/utils.rs @@ -312,7 +312,11 @@ pub unsafe fn set_dictionary_property( Ok(()) } -/// Returns whether `proxy` has a property `id` on its prototype. +/// Computes whether `proxy` has a property `id` on its prototype and stores +/// the result in `found`. +/// +/// Returns a boolean indicating whether the check succeeded. +/// If `false` is returned then the value of `found` is unspecified. /// /// # Safety /// `cx` must point to a valid, non-null JSContext.