Switch to using the new rooted!/RootedGuard API for rooting.

This commit is contained in:
Eduard Burtescu 2016-07-04 20:59:01 +03:00
parent a77cc9950f
commit 0db1faf876
28 changed files with 238 additions and 237 deletions

View file

@ -29,8 +29,8 @@ use js::jsapi::{JS_ForwardGetPropertyTo, JS_GetClass, JS_GetLatin1StringCharsAnd
use js::jsapi::{JS_GetProperty, JS_GetPrototype, JS_GetReservedSlot, JS_HasProperty};
use js::jsapi::{JS_HasPropertyById, JS_IsExceptionPending, JS_IsGlobalObject, JS_NewGlobalObject};
use js::jsapi::{JS_ResolveStandardClass, JS_SetProperty, ToWindowProxyIfWindow};
use js::jsapi::{JS_SetReservedSlot, JS_StringHasLatin1Chars, MutableHandleValue, ObjectOpResult};
use js::jsapi::{OnNewGlobalHookOption, RootedObject, RootedValue};
use js::jsapi::{JS_SetReservedSlot, JS_StringHasLatin1Chars, MutableHandleValue};
use js::jsapi::{ObjectOpResult, OnNewGlobalHookOption};
use js::jsval::{JSVal, ObjectValue, PrivateValue, UndefinedValue};
use js::rust::{GCMethods, ToString};
use libc;
@ -135,8 +135,8 @@ pub fn get_property_on_prototype(cx: *mut JSContext,
-> bool {
unsafe {
// let proto = GetObjectProto(proxy);
let mut proto = RootedObject::new(cx, ptr::null_mut());
if !JS_GetPrototype(cx, proxy, proto.handle_mut()) || proto.ptr.is_null() {
rooted!(in(cx) let mut proto = ptr::null_mut());
if !JS_GetPrototype(cx, proxy, proto.handle_mut()) || proto.is_null() {
*found = false;
return true;
}
@ -150,7 +150,7 @@ pub fn get_property_on_prototype(cx: *mut JSContext,
return true;
}
let receiver = RootedValue::new(cx, ObjectValue(&**proxy.ptr));
rooted!(in(cx) let receiver = ObjectValue(&*proxy.get()));
JS_ForwardGetPropertyTo(cx, proto.handle(), id, receiver.handle(), vp)
}
}
@ -305,29 +305,28 @@ pub fn create_dom_global(cx: *mut JSContext,
options.creationOptions_.traceGlobal_ = trace;
options.creationOptions_.sharedMemoryAndAtomics_ = true;
let obj =
RootedObject::new(cx,
JS_NewGlobalObject(cx,
class,
ptr::null_mut(),
OnNewGlobalHookOption::DontFireOnNewGlobalHook,
&options));
if obj.ptr.is_null() {
rooted!(in(cx) let obj =
JS_NewGlobalObject(cx,
class,
ptr::null_mut(),
OnNewGlobalHookOption::DontFireOnNewGlobalHook,
&options));
if obj.is_null() {
return ptr::null_mut();
}
// Initialize the reserved slots before doing amything that can GC, to
// avoid getting trace hooks called on a partially initialized object.
JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT, PrivateValue(private));
JS_SetReservedSlot(obj.get(), DOM_OBJECT_SLOT, PrivateValue(private));
let proto_array: Box<ProtoOrIfaceArray> =
box [0 as *mut JSObject; PROTO_OR_IFACE_LENGTH];
JS_SetReservedSlot(obj.ptr,
JS_SetReservedSlot(obj.get(),
DOM_PROTOTYPE_SLOT,
PrivateValue(Box::into_raw(proto_array) as *const libc::c_void));
let _ac = JSAutoCompartment::new(cx, obj.ptr);
let _ac = JSAutoCompartment::new(cx, obj.get());
JS_FireOnNewGlobalObject(cx, obj.handle());
obj.ptr
obj.get()
}
}
@ -459,14 +458,14 @@ unsafe fn generic_call(cx: *mut JSContext,
} else {
GetGlobalForObjectCrossCompartment(JS_CALLEE(cx, vp).to_object_or_null())
};
let obj = RootedObject::new(cx, obj);
rooted!(in(cx) let obj = obj);
let info = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));
let proto_id = (*info).protoID;
let depth = (*info).depth;
let proto_check = |class: &'static DOMClass| {
class.interface_chain[depth as usize] as u16 == proto_id
};
let this = match private_from_proto_check(obj.ptr, proto_check) {
let this = match private_from_proto_check(obj.get(), proto_check) {
Ok(val) => val,
Err(()) => {
if is_lenient {