mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Mark get_property_on_prototype and has_property_on_prototype as unsafe
This commit is contained in:
parent
8b84566097
commit
fbc8938bee
1 changed files with 29 additions and 30 deletions
|
@ -127,32 +127,29 @@ pub type ProtoOrIfaceArray = [*mut JSObject; PROTO_OR_IFACE_LENGTH];
|
|||
/// set to true and `*vp` to the value, otherwise `*found` is set to false.
|
||||
///
|
||||
/// Returns false on JSAPI failure.
|
||||
pub fn get_property_on_prototype(cx: *mut JSContext,
|
||||
proxy: HandleObject,
|
||||
id: HandleId,
|
||||
found: *mut bool,
|
||||
vp: MutableHandleValue)
|
||||
-> bool {
|
||||
unsafe {
|
||||
// let proto = GetObjectProto(proxy);
|
||||
rooted!(in(cx) let mut proto = ptr::null_mut());
|
||||
if !JS_GetPrototype(cx, proxy, proto.handle_mut()) || proto.is_null() {
|
||||
*found = false;
|
||||
return true;
|
||||
}
|
||||
let mut has_property = false;
|
||||
if !JS_HasPropertyById(cx, proto.handle(), id, &mut has_property) {
|
||||
return false;
|
||||
}
|
||||
*found = has_property;
|
||||
let no_output = vp.ptr.is_null();
|
||||
if !has_property || no_output {
|
||||
return true;
|
||||
}
|
||||
|
||||
rooted!(in(cx) let receiver = ObjectValue(&*proxy.get()));
|
||||
JS_ForwardGetPropertyTo(cx, proto.handle(), id, receiver.handle(), vp)
|
||||
pub unsafe fn get_property_on_prototype(cx: *mut JSContext,
|
||||
proxy: HandleObject,
|
||||
id: HandleId,
|
||||
found: *mut bool,
|
||||
vp: MutableHandleValue)
|
||||
-> bool {
|
||||
rooted!(in(cx) let mut proto = ptr::null_mut());
|
||||
if !JS_GetPrototype(cx, proxy, proto.handle_mut()) || proto.is_null() {
|
||||
*found = false;
|
||||
return true;
|
||||
}
|
||||
let mut has_property = false;
|
||||
if !JS_HasPropertyById(cx, proto.handle(), id, &mut has_property) {
|
||||
return false;
|
||||
}
|
||||
*found = has_property;
|
||||
let no_output = vp.ptr.is_null();
|
||||
if !has_property || no_output {
|
||||
return true;
|
||||
}
|
||||
|
||||
rooted!(in(cx) let receiver = ObjectValue(&*proxy.get()));
|
||||
JS_ForwardGetPropertyTo(cx, proto.handle(), id, receiver.handle(), vp)
|
||||
}
|
||||
|
||||
/// Get an array index from the given `jsid`. Returns `None` if the given
|
||||
|
@ -285,12 +282,14 @@ pub fn set_dictionary_property(cx: *mut JSContext,
|
|||
}
|
||||
|
||||
/// Returns whether `proxy` has a property `id` on its prototype.
|
||||
pub fn has_property_on_prototype(cx: *mut JSContext, proxy: HandleObject, id: HandleId) -> bool {
|
||||
// MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
|
||||
pub unsafe fn has_property_on_prototype(cx: *mut JSContext,
|
||||
proxy: HandleObject,
|
||||
id: HandleId)
|
||||
-> bool {
|
||||
let mut found = false;
|
||||
!get_property_on_prototype(cx, proxy, id, &mut found, unsafe {
|
||||
MutableHandleValue::from_marked_location(ptr::null_mut())
|
||||
}) || found
|
||||
!get_property_on_prototype(
|
||||
cx, proxy, id, &mut found,
|
||||
MutableHandleValue::from_marked_location(ptr::null_mut())) || found
|
||||
}
|
||||
|
||||
/// Drop the resources held by reserved slots of a global object
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue