From 06960e57dcad3da5704d9d7e6650b84f9c8b981f Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Mon, 10 May 2010 20:53:05 +0200 Subject: [PATCH] Part 6 of fix for bug 564266 (DOMCI GetItemAt/GetNamedItem should return nsWrapperCache) - pass the wrapper cache to WrapNative. r=jst. --HG-- extra : rebase_source : 06db2c01b59630cd47c6d9d4f2302bf952233897 --- content/base/public/nsContentUtils.h | 28 +++++++++++++++-- content/base/src/nsContentUtils.cpp | 4 +-- .../templates/src/nsXULTemplateBuilder.cpp | 3 +- dom/base/nsDOMClassInfo.cpp | 31 +++++++++++-------- dom/base/nsDOMClassInfo.h | 15 +++++++-- js/src/xpconnect/idl/nsIXPConnect.idl | 5 ++- js/src/xpconnect/src/nsXPConnect.cpp | 12 ++++--- 7 files changed, 70 insertions(+), 28 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 7d640ebcb5a1..444dcc426b9d 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -1573,17 +1573,33 @@ public: // If non-null aHolder will keep the jsval alive // while there's a ref to it nsIXPConnectJSObjectHolder** aHolder = nsnull, - PRBool aAllowWrapping = PR_FALSE); + PRBool aAllowWrapping = PR_FALSE) + { + return WrapNative(cx, scope, native, nsnull, aIID, vp, aHolder, + aAllowWrapping); + } // Same as the WrapNative above, but use this one if aIID is nsISupports' IID. static nsresult WrapNative(JSContext *cx, JSObject *scope, - nsISupports *native, jsval *vp, + nsISupports *native, jsval *vp, // If non-null aHolder will keep the jsval alive // while there's a ref to it nsIXPConnectJSObjectHolder** aHolder = nsnull, PRBool aAllowWrapping = PR_FALSE) { - return WrapNative(cx, scope, native, nsnull, vp, aHolder, aAllowWrapping); + return WrapNative(cx, scope, native, nsnull, nsnull, vp, aHolder, + aAllowWrapping); + } + static nsresult WrapNative(JSContext *cx, JSObject *scope, + nsISupports *native, nsWrapperCache *cache, + jsval *vp, + // If non-null aHolder will keep the jsval alive + // while there's a ref to it + nsIXPConnectJSObjectHolder** aHolder = nsnull, + PRBool aAllowWrapping = PR_FALSE) + { + return WrapNative(cx, scope, native, cache, nsnull, vp, aHolder, + aAllowWrapping); } static void StripNullChars(const nsAString& aInStr, nsAString& aOutStr); @@ -1674,6 +1690,12 @@ private: static PRBool CanCallerAccess(nsIPrincipal* aSubjectPrincipal, nsIPrincipal* aPrincipal); + static nsresult WrapNative(JSContext *cx, JSObject *scope, + nsISupports *native, nsWrapperCache *cache, + const nsIID* aIID, jsval *vp, + nsIXPConnectJSObjectHolder** aHolder, + PRBool aAllowWrapping); + static nsIDOMScriptObjectFactory *sDOMScriptObjectFactory; static nsIXPConnect *sXPConnect; diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 6945a94425e2..22cdac304225 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -5353,7 +5353,7 @@ nsContentUtils::DispatchXULCommand(nsIContent* aTarget, // static nsresult nsContentUtils::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, - const nsIID* aIID, jsval *vp, + nsWrapperCache *cache, const nsIID* aIID, jsval *vp, nsIXPConnectJSObjectHolder **aHolder, PRBool aAllowWrapping) { @@ -5390,7 +5390,7 @@ nsContentUtils::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, rv = sThreadJSContextStack->Push(cx); } if (NS_SUCCEEDED(rv)) { - rv = sXPConnect->WrapNativeToJSVal(cx, scope, native, aIID, + rv = sXPConnect->WrapNativeToJSVal(cx, scope, native, cache, aIID, aAllowWrapping, vp, aHolder); if (push) { sThreadJSContextStack->Pop(nsnull); diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index de916d88d24e..c5ee9e002bdb 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -1412,8 +1412,7 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot() jsval v; nsCOMPtr wrapper; - rv = nsContentUtils::WrapNative(jscontext, scope, mRoot, - &NS_GET_IID(nsIDOMElement), &v, + rv = nsContentUtils::WrapNative(jscontext, scope, mRoot, mRoot, &v, getter_AddRefs(wrapper)); NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 28c952dc0b1c..d508e251833c 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -2058,7 +2058,8 @@ nsDOMClassInfo::WrapNativeParent(JSContext *cx, JSObject *scope, if (obj) { #ifdef DEBUG jsval debugVal; - nsresult rv = WrapNative(cx, scope, native, PR_FALSE, &debugVal); + nsresult rv = WrapNative(cx, scope, native, nativeWrapperCache, PR_FALSE, + &debugVal); NS_ASSERTION(NS_SUCCEEDED(rv) && JSVAL_TO_OBJECT(debugVal) == obj, "Unexpected object in nsWrapperCache"); #endif @@ -2067,7 +2068,7 @@ nsDOMClassInfo::WrapNativeParent(JSContext *cx, JSObject *scope, } jsval v; - nsresult rv = WrapNative(cx, scope, native, PR_FALSE, &v); + nsresult rv = WrapNative(cx, scope, native, nativeWrapperCache, PR_FALSE, &v); NS_ENSURE_SUCCESS(rv, rv); *parentObj = JSVAL_TO_OBJECT(v); return NS_OK; @@ -4987,7 +4988,7 @@ nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj, if (result) { jsval v; nsCOMPtr holder; - nsresult rv = WrapNative(cx, obj, result, PR_TRUE, &v, + nsresult rv = WrapNative(cx, obj, result, cache, PR_TRUE, &v, getter_AddRefs(holder)); NS_ENSURE_SUCCESS(rv, JS_FALSE); @@ -6958,6 +6959,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, rv = win->GetDocument(getter_AddRefs(document)); NS_ENSURE_SUCCESS(rv, rv); + // FIXME Ideally we'd have an nsIDocument here and get nsWrapperCache + // from it. jsval v; nsCOMPtr holder; rv = WrapNative(cx, obj, document, &NS_GET_IID(nsIDOMDocument), PR_FALSE, @@ -7546,7 +7549,7 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, if (scope) { jsval v; nsCOMPtr holder; - nsresult rv = WrapNative(cx, globalObj, scope, nsnull, PR_FALSE, &v, + nsresult rv = WrapNative(cx, globalObj, scope, PR_FALSE, &v, getter_AddRefs(holder)); NS_ENSURE_SUCCESS(rv, rv); @@ -8234,7 +8237,7 @@ nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, NS_ENSURE_SUCCESS(rv, rv); if (array_item) { - rv = WrapNative(cx, obj, array_item, PR_TRUE, vp); + rv = WrapNative(cx, obj, array_item, cache, PR_TRUE, vp); NS_ENSURE_SUCCESS(rv, rv); rv = NS_SUCCESS_I_DID_SOMETHING; @@ -8354,7 +8357,7 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, NS_ENSURE_SUCCESS(rv, rv); if (item) { - rv = WrapNative(cx, obj, item, PR_TRUE, vp); + rv = WrapNative(cx, obj, item, cache, PR_TRUE, vp); NS_ENSURE_SUCCESS(rv, rv); rv = NS_SUCCESS_I_DID_SOMETHING; @@ -8753,7 +8756,7 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc, } nsCOMPtr holder; - rv = WrapNative(cx, obj, retval, &NS_GET_IID(nsIDOMDocument), PR_FALSE, rval, + rv = WrapNative(cx, obj, retval, PR_FALSE, rval, getter_AddRefs(holder)); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to wrap native!"); @@ -8833,7 +8836,7 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx, JSObject *obj, nsCOMPtr holder; rv |= nsDOMClassInfo::WrapNative(cx, obj, static_cast(list), - PR_FALSE, &collection, + list, PR_FALSE, &collection, getter_AddRefs(holder)); list.forget(nodeList); @@ -8935,7 +8938,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSObject *obj, } if (result) { - rv = WrapNative(cx, obj, result, PR_TRUE, vp); + rv = WrapNative(cx, obj, result, cache, PR_TRUE, vp); if (NS_FAILED(rv)) { nsDOMClassInfo::ThrowJSException(cx, rv); @@ -9201,7 +9204,7 @@ nsHTMLDocumentSH::DocumentAllTagsNewResolve(JSContext *cx, JSObject *obj, nsCOMPtr holder; nsresult rv = nsDOMClassInfo::WrapNative(cx, obj, static_cast(tags), - PR_TRUE, &v, + tags, PR_TRUE, &v, getter_AddRefs(holder)); if (NS_FAILED(rv)) { nsDOMClassInfo::ThrowJSException(cx, rv); @@ -9362,7 +9365,7 @@ nsHTMLDocumentSH::GetProperty(nsIXPConnectWrappedNative *wrapper, NS_ENSURE_SUCCESS(rv, rv); if (result) { - rv = WrapNative(cx, obj, result, PR_TRUE, vp); + rv = WrapNative(cx, obj, result, cache, PR_TRUE, vp); if (NS_SUCCEEDED(rv)) { rv = NS_SUCCESS_I_DID_SOMETHING; } @@ -9454,7 +9457,7 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper, if (result) { // Wrap result, result can be either an element or a list of // elements - nsresult rv = WrapNative(cx, obj, result, PR_TRUE, vp); + nsresult rv = WrapNative(cx, obj, result, cache, PR_TRUE, vp); return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING; } } @@ -9465,7 +9468,9 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper, nsIFormControl* control = form->GetElementAt(n); if (control) { - nsresult rv = WrapNative(cx, obj, control, PR_TRUE, vp); + Element *element = + static_cast(form->GetElementAt(n)); + nsresult rv = WrapNative(cx, obj, element, element, PR_TRUE, vp); return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING; } } diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index b92540f5e49b..bf824021697b 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -153,7 +153,7 @@ public: nsWrapperCache *nativeWrapperCache, JSObject **parentObj); - // Same as the WrapNative above, but use this one if aIID is nsISupports' IID. + // Same as the WrapNative above, but use these if aIID is nsISupports' IID. static nsresult WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, PRBool aAllowWrapping, jsval *vp, @@ -161,7 +161,18 @@ public: // while there's a ref to it nsIXPConnectJSObjectHolder** aHolder = nsnull) { - return WrapNative(cx, scope, native, nsnull, aAllowWrapping, vp, aHolder); + return nsContentUtils::WrapNative(cx, scope, native, vp, aHolder, + aAllowWrapping); + } + static nsresult WrapNative(JSContext *cx, JSObject *scope, + nsISupports *native, nsWrapperCache *cache, + PRBool aAllowWrapping, jsval *vp, + // If non-null aHolder will keep the jsval alive + // while there's a ref to it + nsIXPConnectJSObjectHolder** aHolder = nsnull) + { + return nsContentUtils::WrapNative(cx, scope, native, cache, vp, aHolder, + aAllowWrapping); } static nsresult ThrowJSException(JSContext *cx, nsresult aResult); diff --git a/js/src/xpconnect/idl/nsIXPConnect.idl b/js/src/xpconnect/idl/nsIXPConnect.idl index dc248d64860d..0ed0f15505d2 100644 --- a/js/src/xpconnect/idl/nsIXPConnect.idl +++ b/js/src/xpconnect/idl/nsIXPConnect.idl @@ -55,6 +55,7 @@ #include "jspubtd.h" #include "xptinfo.h" #include "nsAXPCNativeCallContext.h" +#include "nsWrapperCache.h" %} /***************************************************************************/ @@ -72,6 +73,7 @@ [ptr] native nsScriptObjectTracerPtr(nsScriptObjectTracer); [ref] native nsCCTraversalCallbackRef(nsCycleCollectionTraversalCallback); [ptr] native nsAXPCNativeCallContextPtr(nsAXPCNativeCallContext); +[ptr] native nsWrapperCachePtr(nsWrapperCache); /***************************************************************************/ @@ -397,7 +399,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } %} -[uuid(c53c54ac-afc1-458a-98f5-cadb52574e40)] +[uuid(7a30abb6-349c-4bb5-b395-78f8a860d6e3)] interface nsIXPConnect : nsISupports { %{ C++ @@ -498,6 +500,7 @@ interface nsIXPConnect : nsISupports wrapNativeToJSVal(in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, + in nsWrapperCachePtr aCache, in nsIIDPtr aIID, in boolean aAllowWrapper, out jsval aVal, diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp index b3c1fa80ad70..69b8ddaa32ba 100644 --- a/js/src/xpconnect/src/nsXPConnect.cpp +++ b/js/src/xpconnect/src/nsXPConnect.cpp @@ -1271,6 +1271,7 @@ static nsresult NativeInterface2JSObject(XPCLazyCallContext & lccx, JSObject * aScope, nsISupports *aCOMObj, + nsWrapperCache *aCache, const nsIID * aIID, PRBool aAllowWrapping, jsval *aVal, @@ -1278,7 +1279,7 @@ NativeInterface2JSObject(XPCLazyCallContext & lccx, { nsresult rv; if(!XPCConvert::NativeInterface2JSObject(lccx, aVal, aHolder, aCOMObj, aIID, - nsnull, nsnull, aScope, + nsnull, aCache, aScope, aAllowWrapping, OBJ_IS_NOT_GLOBAL, &rv)) return rv; @@ -1310,8 +1311,8 @@ nsXPConnect::WrapNative(JSContext * aJSContext, XPCLazyCallContext lccx(ccx); jsval v; - return NativeInterface2JSObject(lccx, aScope, aCOMObj, &aIID, PR_FALSE, &v, - aHolder); + return NativeInterface2JSObject(lccx, aScope, aCOMObj, nsnull, &aIID, + PR_FALSE, &v, aHolder); } /* void wrapNativeToJSVal (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDPtr aIID, out jsval aVal, out nsIXPConnectJSObjectHolder aHolder); */ @@ -1319,6 +1320,7 @@ NS_IMETHODIMP nsXPConnect::WrapNativeToJSVal(JSContext * aJSContext, JSObject * aScope, nsISupports *aCOMObj, + nsWrapperCache *aCache, const nsIID * aIID, PRBool aAllowWrapping, jsval *aVal, @@ -1333,8 +1335,8 @@ nsXPConnect::WrapNativeToJSVal(JSContext * aJSContext, XPCLazyCallContext lccx(NATIVE_CALLER, aJSContext); - return NativeInterface2JSObject(lccx, aScope, aCOMObj, aIID, aAllowWrapping, - aVal, aHolder); + return NativeInterface2JSObject(lccx, aScope, aCOMObj, aCache, aIID, + aAllowWrapping, aVal, aHolder); } /* void wrapJS (in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */