From 6b41db971f88225aa734ec40612788670c1781ed Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Wed, 17 Apr 2013 16:38:44 +0100 Subject: [PATCH] Bug 863289 - GC: Continue the rooting of XPConnect r=bholley --- js/xpconnect/src/XPCConvert.cpp | 70 ++++++++++--------- js/xpconnect/src/XPCQuickStubs.cpp | 35 ++++++---- js/xpconnect/src/XPCVariant.cpp | 31 ++++---- js/xpconnect/src/XPCWrappedJSClass.cpp | 4 +- js/xpconnect/src/XPCWrappedNative.cpp | 6 +- js/xpconnect/src/nsXPConnect.cpp | 8 +-- js/xpconnect/src/xpcprivate.h | 6 +- js/xpconnect/wrappers/AccessCheck.cpp | 21 ++++-- js/xpconnect/wrappers/ChromeObjectWrapper.cpp | 60 ++++++++-------- js/xpconnect/wrappers/WrapperFactory.cpp | 6 +- 10 files changed, 132 insertions(+), 115 deletions(-) diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index a201d126a3ec..3eddb6e1a029 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -29,6 +29,7 @@ using namespace xpc; using namespace mozilla; using namespace mozilla::dom; +using namespace JS; //#define STRICT_CHECK_OF_UNICODE #ifdef STRICT_CHECK_OF_UNICODE @@ -169,7 +170,7 @@ XPCConvert::NativeData2JS(XPCLazyCallContext& lccx, jsval* d, const void* s, nsID* iid2 = *((nsID**)s); if (!iid2) break; - JS::RootedObject scope(cx, lccx.GetScopeForNewJSObjects()); + RootedObject scope(cx, lccx.GetScopeForNewJSObjects()); JSObject* obj; if (!(obj = xpc_NewIDObject(cx, scope, *iid2))) return false; @@ -369,7 +370,7 @@ bool ConvertToPrimitive(JSContext *cx, const JS::Value& v, T *retval) // static JSBool -XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s, +XPCConvert::JSData2Native(JSContext* cx, void* d, HandleValue s, const nsXPTType& type, JSBool useAllocator, const nsID* iid, nsresult* pErr) @@ -754,8 +755,8 @@ XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s, return false; } - return JSObject2NativeInterface(cx, (void**)d, &s.toObject(), iid, - nullptr, pErr); + RootedObject src(cx, &s.toObject()); + return JSObject2NativeInterface(cx, (void**)d, src, iid, nullptr, pErr); } default: NS_ERROR("bad type"); @@ -765,7 +766,7 @@ XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s, } inline JSBool -CreateHolderIfNeeded(XPCCallContext& ccx, JSObject* obj, jsval* d, +CreateHolderIfNeeded(XPCCallContext& ccx, HandleObject obj, jsval* d, nsIXPConnectJSObjectHolder** dest) { if (dest) { @@ -830,7 +831,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx, nsWrapperCache *cache = aHelper.GetWrapperCache(); bool tryConstructSlimWrapper = false; - JS::RootedObject flat(cx); + RootedObject flat(cx); if (cache) { flat = cache->GetWrapper(); if (cache->IsDOMBinding()) { @@ -874,7 +875,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx, if (!ccx.IsValid()) return false; - jsval slim; + RootedValue slim(cx); if (ConstructSlimWrapper(ccx, aHelper, xpcscope, &slim)) { *d = slim; return true; @@ -975,7 +976,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx, // The call to wrap here handles both cross-compartment and same-compartment // security wrappers. - JSObject *original = flat; + RootedObject original(cx, flat); if (!JS_WrapObject(ccx, flat.address())) return false; @@ -1006,7 +1007,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx, // static JSBool XPCConvert::JSObject2NativeInterface(JSContext* cx, - void** dest, JSObject* src, + void** dest, HandleObject src, const nsID* iid, nsISupports* aOuter, nsresult* pErr) @@ -1153,23 +1154,24 @@ public: private: JSContext * const mContext; - JS::AutoValueRooter tvr; + AutoValueRooter tvr; }; // static nsresult XPCConvert::JSValToXPCException(XPCCallContext& ccx, - jsval s, + jsval sArg, const char* ifaceName, const char* methodName, nsIException** exceptn) { JSContext* cx = ccx.GetJSContext(); + RootedValue s(cx, sArg); AutoExceptionRestorer aer(cx, s); if (!JSVAL_IS_PRIMITIVE(s)) { // we have a JSObject - JSObject* obj = JSVAL_TO_OBJECT(s); + RootedObject obj(cx, JSVAL_TO_OBJECT(s)); if (!obj) { NS_ERROR("when is an object not an object?"); @@ -1255,14 +1257,14 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx, return ConstructException(NS_ERROR_XPC_JS_THREW_JS_OBJECT, strBytes.ptr(), ifaceName, methodName, - nullptr, exceptn, cx, &s); + nullptr, exceptn, cx, s.address()); } } if (JSVAL_IS_VOID(s) || JSVAL_IS_NULL(s)) { return ConstructException(NS_ERROR_XPC_JS_THREW_NULL, nullptr, ifaceName, methodName, nullptr, - exceptn, cx, &s); + exceptn, cx, s.address()); } if (JSVAL_IS_NUMBER(s)) { @@ -1293,7 +1295,7 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx, if (isResult) return ConstructException(rv, nullptr, ifaceName, methodName, - nullptr, exceptn, cx, &s); + nullptr, exceptn, cx, s.address()); else { // XXX all this nsISupportsDouble code seems a little redundant // now that we're storing the jsval in the exception... @@ -1307,7 +1309,7 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx, return NS_ERROR_FAILURE; data->SetData(number); rv = ConstructException(NS_ERROR_XPC_JS_THREW_NUMBER, nullptr, - ifaceName, methodName, data, exceptn, cx, &s); + ifaceName, methodName, data, exceptn, cx, s.address()); NS_RELEASE(data); return rv; } @@ -1322,7 +1324,7 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx, if (!!strBytes) { return ConstructException(NS_ERROR_XPC_JS_THREW_STRING, strBytes.ptr(), ifaceName, methodName, - nullptr, exceptn, cx, &s); + nullptr, exceptn, cx, s.address()); } } return NS_ERROR_FAILURE; @@ -1660,7 +1662,7 @@ XPCConvert::JSArray2Native(JSContext* cx, void** d, JS::Value s, return false; } - JSObject* jsarray = &s.toObject(); + RootedObject jsarray(cx, &s.toObject()); // If this is a typed array, then try a fast conversion with memcpy. if (JS_IsTypedArrayObject(jsarray)) { @@ -1683,22 +1685,22 @@ XPCConvert::JSArray2Native(JSContext* cx, void** d, JS::Value s, if (pErr) *pErr = NS_ERROR_XPC_BAD_CONVERT_JS; -#define POPULATE(_mode, _t) \ - PR_BEGIN_MACRO \ - cleanupMode = _mode; \ - size_t max = UINT32_MAX / sizeof(_t); \ - if (count > max || \ +#define POPULATE(_mode, _t) \ + PR_BEGIN_MACRO \ + cleanupMode = _mode; \ + size_t max = UINT32_MAX / sizeof(_t); \ + if (count > max || \ nullptr == (array = nsMemory::Alloc(count * sizeof(_t)))) { \ - if (pErr) \ - *pErr = NS_ERROR_OUT_OF_MEMORY; \ - goto failure; \ - } \ - for (initedCount = 0; initedCount < count; initedCount++) { \ - if (!JS_GetElement(cx, jsarray, initedCount, ¤t) || \ - !JSData2Native(cx, ((_t*)array)+initedCount, current, type, \ - true, iid, pErr)) \ - goto failure; \ - } \ + if (pErr) \ + *pErr = NS_ERROR_OUT_OF_MEMORY; \ + goto failure; \ + } \ + for (initedCount = 0; initedCount < count; initedCount++) { \ + if (!JS_GetElement(cx, jsarray, initedCount, current.address()) || \ + !JSData2Native(cx, ((_t*)array)+initedCount, current, type, \ + true, iid, pErr)) \ + goto failure; \ + } \ PR_END_MACRO // No Action, FRee memory, RElease object @@ -1708,7 +1710,7 @@ XPCConvert::JSArray2Native(JSContext* cx, void** d, JS::Value s, void *array = nullptr; uint32_t initedCount; - jsval current; + RootedValue current(cx); // XXX check IsPtr - esp. to handle array of nsID (as opposed to nsID*) // XXX make extra space at end of char* and wchar* and null termintate diff --git a/js/xpconnect/src/XPCQuickStubs.cpp b/js/xpconnect/src/XPCQuickStubs.cpp index 8432193d51e2..7d5d5320e8a4 100644 --- a/js/xpconnect/src/XPCQuickStubs.cpp +++ b/js/xpconnect/src/XPCQuickStubs.cpp @@ -14,6 +14,7 @@ #include "mozilla/dom/BindingUtils.h" using namespace mozilla; +using namespace JS; extern const char* xpc_qsStringTable; @@ -99,7 +100,7 @@ PointerHolderClass = { }; JSBool -xpc_qsDefineQuickStubs(JSContext *cx, JSObject *proto, unsigned flags, +xpc_qsDefineQuickStubs(JSContext *cx, JSObject *protoArg, unsigned flags, uint32_t ifacec, const nsIID **interfaces, uint32_t tableSize, const xpc_qsHashEntry *table, const xpc_qsPropertySpec *propspecs, @@ -114,6 +115,7 @@ xpc_qsDefineQuickStubs(JSContext *cx, JSObject *proto, unsigned flags, * searching the interfaces forward. Here, definitions toward the * front of 'interfaces' overwrite those toward the back. */ + RootedObject proto(cx, protoArg); for (uint32_t i = ifacec; i-- != 0;) { const nsID &iid = *interfaces[i]; const xpc_qsHashEntry *entry = @@ -222,7 +224,7 @@ GetMethodInfo(JSContext *cx, jsval *vp, const char **ifaceNamep, jsid *memberIdp static bool ThrowCallFailed(JSContext *cx, nsresult rv, - const char *ifaceName, jsid memberId, const char *memberName) + const char *ifaceName, HandleId memberId, const char *memberName) { /* Only one of memberId or memberName should be given. */ MOZ_ASSERT(JSID_IS_VOID(memberId) != !memberName); @@ -273,17 +275,19 @@ ThrowCallFailed(JSContext *cx, nsresult rv, JSBool xpc_qsThrowGetterSetterFailed(JSContext *cx, nsresult rv, JSObject *obj, - jsid memberId) + jsid memberIdArg) { + RootedId memberId(cx, memberIdArg); const char *ifaceName; GetMemberInfo(obj, memberId, &ifaceName); return ThrowCallFailed(cx, rv, ifaceName, memberId, NULL); } JSBool -xpc_qsThrowGetterSetterFailed(JSContext *cx, nsresult rv, JSObject *obj, +xpc_qsThrowGetterSetterFailed(JSContext *cx, nsresult rv, JSObject *objArg, const char* memberName) { + RootedObject obj(cx, objArg); JSString *str = JS_InternString(cx, memberName); if (!str) { return false; @@ -304,8 +308,8 @@ JSBool xpc_qsThrowMethodFailed(JSContext *cx, nsresult rv, jsval *vp) { const char *ifaceName; - jsid memberId; - GetMethodInfo(cx, vp, &ifaceName, &memberId); + RootedId memberId(cx); + GetMethodInfo(cx, vp, &ifaceName, memberId.address()); return ThrowCallFailed(cx, rv, ifaceName, memberId, NULL); } @@ -321,7 +325,7 @@ xpc_qsThrowMethodFailedWithDetails(JSContext *cx, nsresult rv, const char *ifaceName, const char *memberName) { - return ThrowCallFailed(cx, rv, ifaceName, JSID_VOID, memberName); + return ThrowCallFailed(cx, rv, ifaceName, JSID_VOIDHANDLE, memberName); } static void @@ -386,8 +390,9 @@ xpc_qsThrowBadSetterValue(JSContext *cx, nsresult rv, void xpc_qsThrowBadSetterValue(JSContext *cx, nsresult rv, - JSObject *obj, const char* propName) + JSObject *objArg, const char* propName) { + RootedObject obj(cx, objArg); JSString *str = JS_InternString(cx, propName); if (!str) { return; @@ -494,7 +499,7 @@ xpc_qsAUTF8String::xpc_qsAUTF8String(JSContext *cx, jsval v, jsval *pval) static nsresult getNative(nsISupports *idobj, QITableEntry* entries, - JSObject *obj, + HandleObject obj, const nsIID &iid, void **ppThis, nsISupports **pThisRef, @@ -527,8 +532,9 @@ getNativeFromWrapper(JSContext *cx, nsISupports **pThisRef, jsval *vp) { + RootedObject obj(cx, wrapper->GetFlatJSObject()); return getNative(wrapper->GetIdentityObject(), wrapper->GetOffsets(), - wrapper->GetFlatJSObject(), iid, ppThis, pThisRef, vp); + obj, iid, ppThis, pThisRef, vp); } @@ -595,7 +601,7 @@ getWrapper(JSContext *cx, nsresult castNative(JSContext *cx, XPCWrappedNative *wrapper, - JSObject *cur, + JSObject *curArg, XPCWrappedNativeTearOff *tearoff, const nsIID &iid, void **ppThis, @@ -603,6 +609,7 @@ castNative(JSContext *cx, jsval *vp, XPCLazyCallContext *lccx) { + RootedObject cur(cx, curArg); if (wrapper) { nsresult rv = getNativeFromWrapper(cx,wrapper, iid, ppThis, pThisRef, vp); @@ -653,9 +660,9 @@ xpc_qsUnwrapThisFromCcxImpl(XPCCallContext &ccx, if (!native) return xpc_qsThrow(ccx.GetJSContext(), NS_ERROR_XPC_HAS_BEEN_SHUTDOWN); + RootedObject obj(ccx, ccx.GetFlattenedJSObject()); nsresult rv = getNative(native, GetOffsets(native, ccx.GetProto()), - ccx.GetFlattenedJSObject(), iid, ppThis, pThisRef, - vp); + obj, iid, ppThis, pThisRef, vp); if (NS_FAILED(rv)) return xpc_qsThrow(ccx.GetJSContext(), rv); return true; @@ -670,7 +677,7 @@ xpc_qsUnwrapArgImpl(JSContext *cx, jsval *vp) { nsresult rv; - JSObject *src = xpc_qsUnwrapObj(v, ppArgRef, &rv); + RootedObject src(cx, xpc_qsUnwrapObj(v, ppArgRef, &rv)); if (!src) { *ppArg = nullptr; diff --git a/js/xpconnect/src/XPCVariant.cpp b/js/xpconnect/src/XPCVariant.cpp index 8d6d4525b484..6a03bffadf5c 100644 --- a/js/xpconnect/src/XPCVariant.cpp +++ b/js/xpconnect/src/XPCVariant.cpp @@ -11,6 +11,8 @@ #include "jsfriendapi.h" +using namespace JS; + NS_IMPL_CLASSINFO(XPCVariant, NULL, 0, XPCVARIANT_CID) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XPCVariant) NS_INTERFACE_MAP_ENTRY(XPCVariant) @@ -149,7 +151,7 @@ private: static const Type StateTable[tTypeCount][tTypeCount-1]; public: - static JSBool GetTypeForArray(JSContext* cx, JSObject* array, + static JSBool GetTypeForArray(JSContext* cx, HandleObject array, uint32_t length, nsXPTType* resultType, nsID* resultID); }; @@ -174,16 +176,17 @@ XPCArrayHomogenizer::StateTable[tTypeCount][tTypeCount-1] = { // static JSBool -XPCArrayHomogenizer::GetTypeForArray(JSContext* cx, JSObject* array, +XPCArrayHomogenizer::GetTypeForArray(JSContext* cx, HandleObject array, uint32_t length, nsXPTType* resultType, nsID* resultID) { Type state = tUnk; Type type; + RootedValue val(cx); + RootedObject jsobj(cx); for (uint32_t i = 0; i < length; i++) { - JS::Value val; - if (!JS_GetElement(cx, array, i, &val)) + if (!JS_GetElement(cx, array, i, val.address())) return false; if (val.isInt32()) { @@ -192,7 +195,7 @@ XPCArrayHomogenizer::GetTypeForArray(JSContext* cx, JSObject* array, type = tDbl; } else if (val.isBoolean()) { type = tBool; - } else if (val.isUndefined()) { + } else if (val.isUndefined()) { state = tVar; break; } else if (val.isNull()) { @@ -201,7 +204,7 @@ XPCArrayHomogenizer::GetTypeForArray(JSContext* cx, JSObject* array, type = tStr; } else { NS_ASSERTION(val.isObject(), "invalid type of jsval!"); - JSObject* jsobj = &val.toObject(); + jsobj = &val.toObject(); if (JS_IsArrayObject(cx, jsobj)) type = tArr; else if (xpc_JSObjectIsID(cx, jsobj)) @@ -267,7 +270,7 @@ JSBool XPCVariant::InitializeData(JSContext* cx) { JS_CHECK_RECURSION(cx, return false); - JS::Value val = GetJSVal(); + RootedValue val(cx, GetJSVal()); if (val.isInt32()) return NS_SUCCEEDED(nsVariant::SetFromInt32(&mData, val.toInt32())); @@ -309,7 +312,7 @@ JSBool XPCVariant::InitializeData(JSContext* cx) // leaving only JSObject... NS_ASSERTION(val.isObject(), "invalid type of jsval!"); - JSObject* jsobj = &val.toObject(); + RootedObject jsobj(cx, &val.toObject()); // Let's see if it is a xpcJSID. @@ -378,16 +381,16 @@ XPCVariant::VariantDataToJS(XPCLazyCallContext& lccx, if (NS_FAILED(variant->GetDataType(&type))) return false; - jsval realVal; - nsresult rv = variant->GetAsJSVal(&realVal); + JSContext *cx = lccx.GetJSContext(); + RootedValue realVal(cx); + nsresult rv = variant->GetAsJSVal(realVal.address()); if (NS_SUCCEEDED(rv) && (JSVAL_IS_PRIMITIVE(realVal) || type == nsIDataType::VTYPE_ARRAY || type == nsIDataType::VTYPE_EMPTY_ARRAY || type == nsIDataType::VTYPE_ID)) { - JSContext *cx = lccx.GetJSContext(); - if (!JS_WrapValue(cx, &realVal)) + if (!JS_WrapValue(cx, realVal.address())) return false; *pJSVal = realVal; return true; @@ -399,8 +402,7 @@ XPCVariant::VariantDataToJS(XPCLazyCallContext& lccx, type == nsIDataType::VTYPE_INTERFACE_IS, "Weird variant"); - JSContext *cx = lccx.GetJSContext(); - if (!JS_WrapValue(cx, &realVal)) + if (!JS_WrapValue(cx, realVal.address())) return false; *pJSVal = realVal; return true; @@ -425,7 +427,6 @@ XPCVariant::VariantDataToJS(XPCLazyCallContext& lccx, xpctvar.flags = 0; JSBool success; - JSContext* cx = lccx.GetJSContext(); NS_ABORT_IF_FALSE(js::IsObjectInContextCompartment(lccx.GetScopeForNewJSObjects(), cx), "bad scope for new JSObjects"); diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index d4a47e6cbe5f..fc250a3a527c 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -406,8 +406,8 @@ nsXPCWrappedJSClass::BuildPropertyEnumerator(XPCCallContext& ccx, return NS_ERROR_FAILURE; } - jsval jsvalName; - if (!JS_IdToValue(cx, idName, &jsvalName)) + RootedValue jsvalName(cx); + if (!JS_IdToValue(cx, idName, jsvalName.address())) return NS_ERROR_FAILURE; JSString* name = JS_ValueToString(cx, jsvalName); diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index 4af1041add6e..a18e95c8d47e 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -3616,7 +3616,7 @@ static uint32_t sSlimWrappers; JSBool ConstructSlimWrapper(XPCCallContext &ccx, xpcObjectHelper &aHelper, - XPCWrappedNativeScope* xpcScope, jsval *rval) + XPCWrappedNativeScope* xpcScope, MutableHandleValue rval) { nsISupports *identityObj = aHelper.GetCanonical(); nsXPCClassInfo *classInfoHelper = aHelper.GetXPCClassInfo(); @@ -3672,7 +3672,7 @@ ConstructSlimWrapper(XPCCallContext &ccx, nsWrapperCache *cache = aHelper.GetWrapperCache(); JSObject* wrapper = cache->GetWrapper(); if (wrapper) { - *rval = OBJECT_TO_JSVAL(wrapper); + rval.setObject(*wrapper); return true; } @@ -3709,7 +3709,7 @@ ConstructSlimWrapper(XPCCallContext &ccx, SLIM_LOG(("+++++ %i created slim wrapper (%p, %p, %p)\n", ++sSlimWrappers, wrapper, p, xpcScope)); - *rval = OBJECT_TO_JSVAL(wrapper); + rval.setObject(*wrapper); return true; } diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index e8e9ee71e9b3..605ff2496601 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -2421,13 +2421,13 @@ const uint8_t HAS_ORIGIN_PRINCIPALS_FLAG = 2; static nsresult WriteScriptOrFunction(nsIObjectOutputStream *stream, JSContext *cx, - JSScript *script, HandleObject functionObj) + JSScript *scriptArg, HandleObject functionObj) { // Exactly one of script or functionObj must be given - MOZ_ASSERT(!script != !functionObj); + MOZ_ASSERT(!scriptArg != !functionObj); - if (!script) - script = JS_GetFunctionScript(cx, JS_GetObjectFunction(functionObj)); + RootedScript script(cx, scriptArg ? scriptArg : + JS_GetFunctionScript(cx, JS_GetObjectFunction(functionObj))); nsIPrincipal *principal = nsJSPrincipals::get(JS_GetScriptPrincipals(script)); diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 0f10da0881c7..7318234df4a1 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -2516,7 +2516,7 @@ class xpcObjectHelper; extern JSBool ConstructSlimWrapper(XPCCallContext &ccx, xpcObjectHelper &aHelper, XPCWrappedNativeScope* xpcScope, - jsval *rval); + JS::MutableHandleValue rval); extern JSBool MorphSlimWrapper(JSContext *cx, JS::HandleObject obj); /***********************************************/ @@ -3301,7 +3301,7 @@ public: const void* s, const nsXPTType& type, const nsID* iid, nsresult* pErr); - static JSBool JSData2Native(JSContext* cx, void* d, jsval s, + static JSBool JSData2Native(JSContext* cx, void* d, JS::HandleValue s, const nsXPTType& type, JSBool useAllocator, const nsID* iid, nsresult* pErr); @@ -3349,7 +3349,7 @@ public: const nsID* iid, nsresult* pErr); static JSBool JSObject2NativeInterface(JSContext* cx, - void** dest, JSObject* src, + void** dest, JS::HandleObject src, const nsID* iid, nsISupports* aOuter, nsresult* pErr); diff --git a/js/xpconnect/wrappers/AccessCheck.cpp b/js/xpconnect/wrappers/AccessCheck.cpp index 985e473c70b7..65bb08032036 100644 --- a/js/xpconnect/wrappers/AccessCheck.cpp +++ b/js/xpconnect/wrappers/AccessCheck.cpp @@ -166,8 +166,11 @@ IsPermitted(const char *name, JSFlatString *prop, bool set) #undef W static bool -IsFrameId(JSContext *cx, JSObject *obj, jsid id) +IsFrameId(JSContext *cx, JSObject *objArg, jsid idArg) { + RootedObject obj(cx, objArg); + RootedId id(cx, idArg); + obj = JS_ObjectToInnerObject(cx, obj); MOZ_ASSERT(!js::IsWrapper(obj)); XPCWrappedNative *wn = IS_WN_WRAPPER(obj) ? XPCWrappedNative::Get(obj) @@ -279,14 +282,16 @@ EnterAndThrow(JSContext *cx, JSObject *wrapper, const char *msg) } bool -ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper::Action act) +ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapperArg, jsid idArg, Wrapper::Action act) { - JSObject *wrappedObject = Wrapper::wrappedObject(wrapper); + RootedObject wrapper(cx, wrapperArg); + RootedId id(cx, idArg); + RootedObject wrappedObject(cx, Wrapper::wrappedObject(wrapper)); if (act == Wrapper::CALL) return true; - jsid exposedPropsId = GetRTIdByIndex(cx, XPCJSRuntime::IDX_EXPOSEDPROPS); + RootedId exposedPropsId(cx, GetRTIdByIndex(cx, XPCJSRuntime::IDX_EXPOSEDPROPS)); // We need to enter the wrappee's compartment to look at __exposedProps__, // but we want to be in the wrapper's compartment if we call Deny(). @@ -314,8 +319,8 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper: if (id == JSID_VOID) return true; - JS::Value exposedProps; - if (!JS_LookupPropertyById(cx, wrappedObject, exposedPropsId, &exposedProps)) + RootedValue exposedProps(cx); + if (!JS_LookupPropertyById(cx, wrappedObject, exposedPropsId, exposedProps.address())) return false; if (exposedProps.isNullOrUndefined()) @@ -398,8 +403,10 @@ ExposedPropertiesOnly::allowNativeCall(JSContext *cx, JS::IsAcceptableThis test, } bool -ComponentsObjectPolicy::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper::Action act) +ComponentsObjectPolicy::check(JSContext *cx, JSObject *wrapperArg, jsid idArg, Wrapper::Action act) { + RootedObject wrapper(cx, wrapperArg); + RootedId id(cx, idArg); JSAutoCompartment ac(cx, wrapper); if (JSID_IS_STRING(id) && act == Wrapper::GET) { diff --git a/js/xpconnect/wrappers/ChromeObjectWrapper.cpp b/js/xpconnect/wrappers/ChromeObjectWrapper.cpp index 5afec574f7ee..58b592323927 100644 --- a/js/xpconnect/wrappers/ChromeObjectWrapper.cpp +++ b/js/xpconnect/wrappers/ChromeObjectWrapper.cpp @@ -1,5 +1,7 @@ #include "ChromeObjectWrapper.h" +using namespace JS; + namespace xpc { // When creating wrappers for chrome objects in content, we detect if the @@ -17,7 +19,7 @@ ChromeObjectWrapper ChromeObjectWrapper::singleton; using js::assertEnteredPolicy; static bool -AllowedByBase(JSContext *cx, JS::Handle wrapper, JS::Handle id, +AllowedByBase(JSContext *cx, HandleObject wrapper, HandleId id, js::Wrapper::Action act) { MOZ_ASSERT(js::Wrapper::wrapperHandler(wrapper) == @@ -31,7 +33,7 @@ static bool PropIsFromStandardPrototype(JSContext *cx, JSPropertyDescriptor *desc) { MOZ_ASSERT(desc->obj); - JSObject *unwrapped = js::UncheckedUnwrap(desc->obj); + RootedObject unwrapped(cx, js::UncheckedUnwrap(desc->obj)); JSAutoCompartment ac(cx, unwrapped); return JS_IdentifyClassPrototype(cx, unwrapped) != JSProto_Null; } @@ -41,26 +43,26 @@ PropIsFromStandardPrototype(JSContext *cx, JSPropertyDescriptor *desc) // This lets us determine whether the property we would have found (given a // transparent wrapper) would have come off a standard prototype. static bool -PropIsFromStandardPrototype(JSContext *cx, JS::Handle wrapper, - JS::Handle id) +PropIsFromStandardPrototype(JSContext *cx, HandleObject wrapper, + HandleId id) { MOZ_ASSERT(js::Wrapper::wrapperHandler(wrapper) == &ChromeObjectWrapper::singleton); - JSPropertyDescriptor desc; + Rooted desc(cx); ChromeObjectWrapper *handler = &ChromeObjectWrapper::singleton; if (!handler->ChromeObjectWrapperBase::getPropertyDescriptor(cx, wrapper, id, - &desc, 0) || - !desc.obj) + desc.address(), 0) || + !desc.object()) { return false; } - return PropIsFromStandardPrototype(cx, &desc); + return PropIsFromStandardPrototype(cx, desc.address()); } bool ChromeObjectWrapper::getPropertyDescriptor(JSContext *cx, - JS::Handle wrapper, - JS::Handle id, + HandleObject wrapper, + HandleId id, js::PropertyDescriptor *desc, unsigned flags) { @@ -80,8 +82,8 @@ ChromeObjectWrapper::getPropertyDescriptor(JSContext *cx, desc->obj = NULL; // If we found something or have no proto, we're done. - JSObject *wrapperProto; - if (!JS_GetPrototype(cx, wrapper, &wrapperProto)) + RootedObject wrapperProto(cx); + if (!JS_GetPrototype(cx, wrapper, wrapperProto.address())) return false; if (desc->obj || !wrapperProto) return true; @@ -92,8 +94,8 @@ ChromeObjectWrapper::getPropertyDescriptor(JSContext *cx, } bool -ChromeObjectWrapper::has(JSContext *cx, JS::Handle wrapper, - JS::Handle id, bool *bp) +ChromeObjectWrapper::has(JSContext *cx, HandleObject wrapper, + HandleId id, bool *bp) { assertEnteredPolicy(cx, wrapper, id); // Try the lookup on the base wrapper if permitted. @@ -104,25 +106,25 @@ ChromeObjectWrapper::has(JSContext *cx, JS::Handle wrapper, } // If we found something or have no prototype, we're done. - JSObject *wrapperProto; - if (!JS_GetPrototype(cx, wrapper, &wrapperProto)) + RootedObject wrapperProto(cx); + if (!JS_GetPrototype(cx, wrapper, wrapperProto.address())) return false; if (*bp || !wrapperProto) return true; // Try the prototype if that failed. MOZ_ASSERT(js::IsObjectInContextCompartment(wrapper, cx)); - JSPropertyDescriptor desc; - if (!JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, &desc)) + Rooted desc(cx); + if (!JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, desc.address())) return false; - *bp = !!desc.obj; + *bp = !!desc.object(); return true; } bool -ChromeObjectWrapper::get(JSContext *cx, JS::Handle wrapper, - JS::Handle receiver, JS::Handle id, - JS::MutableHandle vp) +ChromeObjectWrapper::get(JSContext *cx, HandleObject wrapper, + HandleObject receiver, HandleId id, + MutableHandleValue vp) { assertEnteredPolicy(cx, wrapper, id); vp.setUndefined(); @@ -142,8 +144,8 @@ ChromeObjectWrapper::get(JSContext *cx, JS::Handle wrapper, } // If we have no proto, we're done. - JSObject *wrapperProto; - if (!JS_GetPrototype(cx, wrapper, &wrapperProto)) + RootedObject wrapperProto(cx); + if (!JS_GetPrototype(cx, wrapper, wrapperProto.address())) return false; if (!wrapperProto) return true; @@ -157,7 +159,7 @@ ChromeObjectWrapper::get(JSContext *cx, JS::Handle wrapper, // contacts API depends on Array.isArray returning true for COW-implemented // contacts. This isn't really ideal, but make it work for now. bool -ChromeObjectWrapper::objectClassIs(JS::Handle obj, js::ESClassValue classValue, +ChromeObjectWrapper::objectClassIs(HandleObject obj, js::ESClassValue classValue, JSContext *cx) { return CrossCompartmentWrapper::objectClassIs(obj, classValue, cx); @@ -168,8 +170,8 @@ ChromeObjectWrapper::objectClassIs(JS::Handle obj, js::ESClassValue c // enforcement or COWs isn't cheap. But it results in the cleanest code, and this // whole proto remapping thing for COWs is going to be phased out anyway. bool -ChromeObjectWrapper::enter(JSContext *cx, JS::Handle wrapper, - JS::Handle id, js::Wrapper::Action act, bool *bp) +ChromeObjectWrapper::enter(JSContext *cx, HandleObject wrapper, + HandleId id, js::Wrapper::Action act, bool *bp) { if (AllowedByBase(cx, wrapper, id, act)) return true; @@ -181,9 +183,7 @@ ChromeObjectWrapper::enter(JSContext *cx, JS::Handle wrapper, // Note that PropIsFromStandardPrototype needs to invoke getPropertyDescriptor // before we've fully entered the policy. Waive our policy. - JS::RootedObject rootedWrapper(cx, wrapper); - JS::RootedId rootedId(cx, id); - js::AutoWaivePolicy policy(cx, rootedWrapper, rootedId); + js::AutoWaivePolicy policy(cx, wrapper, id); return PropIsFromStandardPrototype(cx, wrapper, id); } diff --git a/js/xpconnect/wrappers/WrapperFactory.cpp b/js/xpconnect/wrappers/WrapperFactory.cpp index 381f296d6341..02ea384a9844 100644 --- a/js/xpconnect/wrappers/WrapperFactory.cpp +++ b/js/xpconnect/wrappers/WrapperFactory.cpp @@ -69,15 +69,15 @@ WrapperFactory::CreateXrayWaiver(JSContext *cx, HandleObject obj) XPCWrappedNativeScope *scope = GetObjectScope(obj); // Get a waiver for the proto. - JSObject *proto; - if (!js::GetObjectProto(cx, obj, &proto)) + RootedObject proto(cx); + if (!js::GetObjectProto(cx, obj, proto.address())) return nullptr; if (proto && !(proto = WaiveXray(cx, proto))) return nullptr; // Create the waiver. JSAutoCompartment ac(cx, obj); - if (!JS_WrapObject(cx, &proto)) + if (!JS_WrapObject(cx, proto.address())) return nullptr; JSObject *waiver = Wrapper::New(cx, obj, proto, JS_GetGlobalForObject(cx, obj),