mirror of
https://github.com/servo/servo.git
synced 2025-08-29 17:18:23 +01:00
script: Move operations in window_named_properties::get_own_property_descriptor
& webdriver_handlers::clone_an_object
into unsafe blocks (#38951)
Testing: Covered by existing tests Part of https://github.com/servo/servo/issues/35955 Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
87fe202ded
commit
de6feb469a
3 changed files with 87 additions and 57 deletions
|
@ -467,20 +467,22 @@ unsafe fn clone_an_object(
|
|||
// Step 2. Append value to `seen`.
|
||||
seen.insert(hashable.clone());
|
||||
|
||||
let return_val = if is_array_like::<crate::DomTypeHolder>(cx, val) ||
|
||||
is_arguments_object(cx, val)
|
||||
{
|
||||
let return_val = if unsafe {
|
||||
is_array_like::<crate::DomTypeHolder>(cx, val) || is_arguments_object(cx, val)
|
||||
} {
|
||||
let mut result: Vec<JSValue> = Vec::new();
|
||||
|
||||
let length =
|
||||
match get_property::<u32>(cx, object_handle, "length", ConversionBehavior::Default) {
|
||||
let get_property_result = unsafe {
|
||||
get_property::<u32>(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(
|
||||
SafeJSContext::from_ptr(cx),
|
||||
unsafe { SafeJSContext::from_ptr(cx) },
|
||||
global_scope,
|
||||
error,
|
||||
CanGc::note(),
|
||||
|
@ -491,14 +493,20 @@ unsafe fn clone_an_object(
|
|||
// 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) {
|
||||
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(
|
||||
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(
|
||||
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(
|
||||
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 {
|
||||
|
|
|
@ -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(
|
||||
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());
|
||||
unsafe {
|
||||
obj.to_jsval(*cx, rval.handle_mut());
|
||||
}
|
||||
set_property_descriptor(
|
||||
unsafe { RustMutableHandle::from_raw(desc) },
|
||||
rval.handle(),
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue