From 0cdf333aaa3704fe77e0af0d2913e8289a5eeb11 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 25 Oct 2012 17:01:08 +0200 Subject: [PATCH] Bug 797821 - Replace usage of XPCWrappedNativeScope::FindInJSObjectScope(ccx, obj) with GetObjectScope(obj). r=mrbkap --- dom/bindings/Codegen.py | 3 +-- js/xpconnect/src/XPCComponents.cpp | 10 +++------- js/xpconnect/src/XPCConvert.cpp | 3 +-- js/xpconnect/src/XPCWrappedJSClass.cpp | 4 ++-- js/xpconnect/src/XPCWrappedNative.cpp | 12 +++--------- js/xpconnect/src/XPCWrappedNativeScope.cpp | 6 ++---- js/xpconnect/src/nsXPConnect.cpp | 20 ++++++-------------- js/xpconnect/src/xpcprivate.h | 5 +++++ 8 files changed, 23 insertions(+), 40 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index d3b983346e5a..bf8c9e18ef4e 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -1424,8 +1424,7 @@ def CheckPref(descriptor, globalName, varName, retval, wrapperCache = None): " return %s;") % (varName, retval) return """ { - XPCWrappedNativeScope* scope = - XPCWrappedNativeScope::FindInJSObjectScope(aCx, %s); + XPCWrappedNativeScope* scope = xpc::ObjectScope(%s); if (!scope) { %s } diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index bd7d0f7ac639..18379a5e685e 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -2471,8 +2471,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper, nsXPConnect* xpc = ccx.GetXPConnect(); XPCContext* xpcc = ccx.GetXPCContext(); - XPCWrappedNativeScope* scope = - XPCWrappedNativeScope::FindInJSObjectScope(ccx, obj); + XPCWrappedNativeScope* scope = ObjectScope(obj); nsXPCComponents* comp; if (!xpc || !xpcc || !scope || !(comp = scope->GetComponents())) @@ -3310,7 +3309,7 @@ xpc_CreateSandboxObject(JSContext *cx, jsval *vp, nsISupports *prinOrSop, Sandbo { JSAutoCompartment ac(ccx, sandbox); if (options.wantComponents && - !nsXPCComponents::AttachComponentsObject(ccx, XPCWrappedNativeScope::FindInJSObjectScope(ccx, sandbox))) + !nsXPCComponents::AttachComponentsObject(ccx, ObjectScope(sandbox))) return NS_ERROR_XPC_UNEXPECTED; if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, sandbox)) @@ -4303,10 +4302,7 @@ nsXPCComponents_Utils::GetComponentsForScope(const jsval &vscope, JSContext *cx, if (!vscope.isObject()) return NS_ERROR_INVALID_ARG; JSObject *scopeObj = js::UnwrapObject(&vscope.toObject()); - XPCWrappedNativeScope *scope = - XPCWrappedNativeScope::FindInJSObjectScope(cx, scopeObj); - if (!scope) - return NS_ERROR_FAILURE; + XPCWrappedNativeScope *scope = ObjectScope(scopeObj); XPCCallContext ccx(NATIVE_CALLER, cx); JSObject *components = scope->GetComponentsJSObject(ccx); if (!components) diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index 2bcb35576121..8e0afe6a191c 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -812,8 +812,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx, "bad scope for new JSObjects"); JSObject *jsscope = lccx.GetScopeForNewJSObjects(); - XPCWrappedNativeScope* xpcscope = - XPCWrappedNativeScope::FindInJSObjectScope(cx, jsscope); + XPCWrappedNativeScope* xpcscope = ObjectScope(jsscope); if (!xpcscope) return false; diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index aad7a69a6d4a..54386a8d64ab 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -17,6 +17,7 @@ #include "jsapi.h" +using namespace xpc; NS_IMPL_THREADSAFE_ISUPPORTS1(nsXPCWrappedJSClass, nsIXPCWrappedJSClass) // the value of this variable is never used - we use its address as a sentinel @@ -506,8 +507,7 @@ GetContextFromObject(JSObject *obj) return nullptr; JSAutoCompartment ac(ccx, obj); - XPCWrappedNativeScope* scope = - XPCWrappedNativeScope::FindInJSObjectScope(ccx, obj); + XPCWrappedNativeScope* scope = ObjectScope(obj); XPCContext *xpcc = scope->GetContext(); if (xpcc) { diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index e9d103d97631..32d6905f43e6 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -525,8 +525,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx, ac.construct(ccx, parent); if (parent != plannedParent) { - XPCWrappedNativeScope* betterScope = - XPCWrappedNativeScope::FindInJSObjectScope(ccx, parent); + XPCWrappedNativeScope* betterScope = ObjectScope(parent); if (betterScope != Scope) return GetNewOrUsed(ccx, helper, betterScope, Interface, resultWrapper); @@ -1788,11 +1787,7 @@ XPCWrappedNative::RescueOrphans(XPCCallContext& ccx) JSObject *parentGhost = js::GetObjectParent(mFlatJSObject); JSObject *realParent = js::UnwrapObject(parentGhost); nsRefPtr ignored; - return ReparentWrapperIfFound(ccx, - XPCWrappedNativeScope:: - FindInJSObjectScope(ccx, parentGhost), - XPCWrappedNativeScope:: - FindInJSObjectScope(ccx, realParent), + return ReparentWrapperIfFound(ccx, ObjectScope(parentGhost), ObjectScope(realParent), realParent, mIdentity, getter_AddRefs(ignored)); } @@ -3816,8 +3811,7 @@ ConstructSlimWrapper(XPCCallContext &ccx, JSAutoCompartment ac(ccx, parent); if (parent != plannedParent) { - XPCWrappedNativeScope *newXpcScope = - XPCWrappedNativeScope::FindInJSObjectScope(ccx, parent); + XPCWrappedNativeScope *newXpcScope = ObjectScope(parent); if (newXpcScope != xpcScope) { SLIM_LOG_NOT_CREATED(ccx, identityObj, "crossing origins"); diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index 43521f410f0e..9d934569b929 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -84,12 +84,10 @@ XPCWrappedNativeScope* XPCWrappedNativeScope::gDyingScopes = nullptr; XPCWrappedNativeScope* XPCWrappedNativeScope::GetNewOrUsed(JSContext *cx, JSObject* aGlobal) { - - XPCWrappedNativeScope* scope = FindInJSObjectScope(cx, aGlobal, true); + XPCWrappedNativeScope* scope = ObjectScope(aGlobal); if (!scope) { scope = new XPCWrappedNativeScope(cx, aGlobal); - } - else { + } else { // We need to call SetGlobal in order to clear mPrototypeNoHelper (so we // get a new new one if requested in the new scope) in the case where // the global object is being reused (JS_SetAllNonReservedSlotsToUndefined diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 1d8c08e6b936..22604f740e67 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -1451,8 +1451,7 @@ nsXPConnect::GetWrappedNativeOfNativeObject(JSContext * aJSContext, if (!ccx.IsValid()) return UnexpectedFailure(NS_ERROR_FAILURE); - XPCWrappedNativeScope* scope = - XPCWrappedNativeScope::FindInJSObjectScope(ccx, aScope); + XPCWrappedNativeScope* scope = ObjectScope(aScope); if (!scope) return UnexpectedFailure(NS_ERROR_FAILURE); @@ -1483,14 +1482,9 @@ nsXPConnect::ReparentWrappedNativeIfFound(JSContext * aJSContext, if (!ccx.IsValid()) return UnexpectedFailure(NS_ERROR_FAILURE); - XPCWrappedNativeScope* scope = - XPCWrappedNativeScope::FindInJSObjectScope(ccx, aScope); - if (!scope) - return UnexpectedFailure(NS_ERROR_FAILURE); - - XPCWrappedNativeScope* scope2 = - XPCWrappedNativeScope::FindInJSObjectScope(ccx, aNewParent); - if (!scope2) + XPCWrappedNativeScope* scope = ObjectScope(aScope); + XPCWrappedNativeScope* scope2 = ObjectScope(aNewParent); + if (!scope || !scope2) return UnexpectedFailure(NS_ERROR_FAILURE); return XPCWrappedNative:: @@ -1521,8 +1515,7 @@ nsXPConnect::RescueOrphansInScope(JSContext *aJSContext, JSObject *aScope) if (!ccx.IsValid()) return UnexpectedFailure(NS_ERROR_FAILURE); - XPCWrappedNativeScope *scope = - XPCWrappedNativeScope::FindInJSObjectScope(ccx, aScope); + XPCWrappedNativeScope *scope = ObjectScope(aScope); if (!scope) return UnexpectedFailure(NS_ERROR_FAILURE); @@ -1774,8 +1767,7 @@ nsXPConnect::GetWrappedNativePrototype(JSContext * aJSContext, JSAutoCompartment ac(aJSContext, aScope); - XPCWrappedNativeScope* scope = - XPCWrappedNativeScope::FindInJSObjectScope(ccx, aScope); + XPCWrappedNativeScope* scope = ObjectScope(aScope); if (!scope) return UnexpectedFailure(NS_ERROR_FAILURE); diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index b6213e6a161f..744142d9252c 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -4418,6 +4418,11 @@ inline bool EnableUniversalXPConnect(JSContext *cx) js::AllCompartments()); } +inline XPCWrappedNativeScope* +ObjectScope(JSObject *obj) +{ + return EnsureCompartmentPrivate(obj)->scope; +} } /***************************************************************************/