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
This commit is contained in:
Peter Van der Beken 2010-05-10 20:53:05 +02:00
parent 507098fb13
commit 06960e57dc
7 changed files with 70 additions and 28 deletions

View File

@ -1573,17 +1573,33 @@ public:
// If non-null aHolder will keep the jsval alive // If non-null aHolder will keep the jsval alive
// while there's a ref to it // while there's a ref to it
nsIXPConnectJSObjectHolder** aHolder = nsnull, 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. // Same as the WrapNative above, but use this one if aIID is nsISupports' IID.
static nsresult WrapNative(JSContext *cx, JSObject *scope, static nsresult WrapNative(JSContext *cx, JSObject *scope,
nsISupports *native, jsval *vp, nsISupports *native, jsval *vp,
// If non-null aHolder will keep the jsval alive // If non-null aHolder will keep the jsval alive
// while there's a ref to it // while there's a ref to it
nsIXPConnectJSObjectHolder** aHolder = nsnull, nsIXPConnectJSObjectHolder** aHolder = nsnull,
PRBool aAllowWrapping = PR_FALSE) 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); static void StripNullChars(const nsAString& aInStr, nsAString& aOutStr);
@ -1674,6 +1690,12 @@ private:
static PRBool CanCallerAccess(nsIPrincipal* aSubjectPrincipal, static PRBool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
nsIPrincipal* aPrincipal); 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 nsIDOMScriptObjectFactory *sDOMScriptObjectFactory;
static nsIXPConnect *sXPConnect; static nsIXPConnect *sXPConnect;

View File

@ -5353,7 +5353,7 @@ nsContentUtils::DispatchXULCommand(nsIContent* aTarget,
// static // static
nsresult nsresult
nsContentUtils::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, nsContentUtils::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
const nsIID* aIID, jsval *vp, nsWrapperCache *cache, const nsIID* aIID, jsval *vp,
nsIXPConnectJSObjectHolder **aHolder, nsIXPConnectJSObjectHolder **aHolder,
PRBool aAllowWrapping) PRBool aAllowWrapping)
{ {
@ -5390,7 +5390,7 @@ nsContentUtils::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
rv = sThreadJSContextStack->Push(cx); rv = sThreadJSContextStack->Push(cx);
} }
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = sXPConnect->WrapNativeToJSVal(cx, scope, native, aIID, rv = sXPConnect->WrapNativeToJSVal(cx, scope, native, cache, aIID,
aAllowWrapping, vp, aHolder); aAllowWrapping, vp, aHolder);
if (push) { if (push) {
sThreadJSContextStack->Pop(nsnull); sThreadJSContextStack->Pop(nsnull);

View File

@ -1412,8 +1412,7 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot()
jsval v; jsval v;
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper; nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
rv = nsContentUtils::WrapNative(jscontext, scope, mRoot, rv = nsContentUtils::WrapNative(jscontext, scope, mRoot, mRoot, &v,
&NS_GET_IID(nsIDOMElement), &v,
getter_AddRefs(wrapper)); getter_AddRefs(wrapper));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

View File

@ -2058,7 +2058,8 @@ nsDOMClassInfo::WrapNativeParent(JSContext *cx, JSObject *scope,
if (obj) { if (obj) {
#ifdef DEBUG #ifdef DEBUG
jsval debugVal; 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, NS_ASSERTION(NS_SUCCEEDED(rv) && JSVAL_TO_OBJECT(debugVal) == obj,
"Unexpected object in nsWrapperCache"); "Unexpected object in nsWrapperCache");
#endif #endif
@ -2067,7 +2068,7 @@ nsDOMClassInfo::WrapNativeParent(JSContext *cx, JSObject *scope,
} }
jsval v; 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); NS_ENSURE_SUCCESS(rv, rv);
*parentObj = JSVAL_TO_OBJECT(v); *parentObj = JSVAL_TO_OBJECT(v);
return NS_OK; return NS_OK;
@ -4987,7 +4988,7 @@ nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
if (result) { if (result) {
jsval v; jsval v;
nsCOMPtr<nsIXPConnectJSObjectHolder> holder; nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = WrapNative(cx, obj, result, PR_TRUE, &v, nsresult rv = WrapNative(cx, obj, result, cache, PR_TRUE, &v,
getter_AddRefs(holder)); getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, JS_FALSE); NS_ENSURE_SUCCESS(rv, JS_FALSE);
@ -6958,6 +6959,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
rv = win->GetDocument(getter_AddRefs(document)); rv = win->GetDocument(getter_AddRefs(document));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// FIXME Ideally we'd have an nsIDocument here and get nsWrapperCache
// from it.
jsval v; jsval v;
nsCOMPtr<nsIXPConnectJSObjectHolder> holder; nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = WrapNative(cx, obj, document, &NS_GET_IID(nsIDOMDocument), PR_FALSE, 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) { if (scope) {
jsval v; jsval v;
nsCOMPtr<nsIXPConnectJSObjectHolder> holder; nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = WrapNative(cx, globalObj, scope, nsnull, PR_FALSE, &v, nsresult rv = WrapNative(cx, globalObj, scope, PR_FALSE, &v,
getter_AddRefs(holder)); getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -8234,7 +8237,7 @@ nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (array_item) { 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); NS_ENSURE_SUCCESS(rv, rv);
rv = NS_SUCCESS_I_DID_SOMETHING; rv = NS_SUCCESS_I_DID_SOMETHING;
@ -8354,7 +8357,7 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (item) { if (item) {
rv = WrapNative(cx, obj, item, PR_TRUE, vp); rv = WrapNative(cx, obj, item, cache, PR_TRUE, vp);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = NS_SUCCESS_I_DID_SOMETHING; rv = NS_SUCCESS_I_DID_SOMETHING;
@ -8753,7 +8756,7 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc,
} }
nsCOMPtr<nsIXPConnectJSObjectHolder> holder; nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = WrapNative(cx, obj, retval, &NS_GET_IID(nsIDOMDocument), PR_FALSE, rval, rv = WrapNative(cx, obj, retval, PR_FALSE, rval,
getter_AddRefs(holder)); getter_AddRefs(holder));
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to wrap native!"); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to wrap native!");
@ -8833,7 +8836,7 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
nsCOMPtr<nsIXPConnectJSObjectHolder> holder; nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv |= nsDOMClassInfo::WrapNative(cx, obj, static_cast<nsINodeList*>(list), rv |= nsDOMClassInfo::WrapNative(cx, obj, static_cast<nsINodeList*>(list),
PR_FALSE, &collection, list, PR_FALSE, &collection,
getter_AddRefs(holder)); getter_AddRefs(holder));
list.forget(nodeList); list.forget(nodeList);
@ -8935,7 +8938,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSObject *obj,
} }
if (result) { if (result) {
rv = WrapNative(cx, obj, result, PR_TRUE, vp); rv = WrapNative(cx, obj, result, cache, PR_TRUE, vp);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
nsDOMClassInfo::ThrowJSException(cx, rv); nsDOMClassInfo::ThrowJSException(cx, rv);
@ -9201,7 +9204,7 @@ nsHTMLDocumentSH::DocumentAllTagsNewResolve(JSContext *cx, JSObject *obj,
nsCOMPtr<nsIXPConnectJSObjectHolder> holder; nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = nsDOMClassInfo::WrapNative(cx, obj, nsresult rv = nsDOMClassInfo::WrapNative(cx, obj,
static_cast<nsINodeList*>(tags), static_cast<nsINodeList*>(tags),
PR_TRUE, &v, tags, PR_TRUE, &v,
getter_AddRefs(holder)); getter_AddRefs(holder));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
nsDOMClassInfo::ThrowJSException(cx, rv); nsDOMClassInfo::ThrowJSException(cx, rv);
@ -9362,7 +9365,7 @@ nsHTMLDocumentSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (result) { if (result) {
rv = WrapNative(cx, obj, result, PR_TRUE, vp); rv = WrapNative(cx, obj, result, cache, PR_TRUE, vp);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = NS_SUCCESS_I_DID_SOMETHING; rv = NS_SUCCESS_I_DID_SOMETHING;
} }
@ -9454,7 +9457,7 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
if (result) { if (result) {
// Wrap result, result can be either an element or a list of // Wrap result, result can be either an element or a list of
// elements // 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; return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
} }
} }
@ -9465,7 +9468,9 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
nsIFormControl* control = form->GetElementAt(n); nsIFormControl* control = form->GetElementAt(n);
if (control) { if (control) {
nsresult rv = WrapNative(cx, obj, control, PR_TRUE, vp); Element *element =
static_cast<nsGenericHTMLFormElement*>(form->GetElementAt(n));
nsresult rv = WrapNative(cx, obj, element, element, PR_TRUE, vp);
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING; return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
} }
} }

View File

@ -153,7 +153,7 @@ public:
nsWrapperCache *nativeWrapperCache, nsWrapperCache *nativeWrapperCache,
JSObject **parentObj); 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, static nsresult WrapNative(JSContext *cx, JSObject *scope,
nsISupports *native, PRBool aAllowWrapping, nsISupports *native, PRBool aAllowWrapping,
jsval *vp, jsval *vp,
@ -161,7 +161,18 @@ public:
// while there's a ref to it // while there's a ref to it
nsIXPConnectJSObjectHolder** aHolder = nsnull) 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); static nsresult ThrowJSException(JSContext *cx, nsresult aResult);

View File

@ -55,6 +55,7 @@
#include "jspubtd.h" #include "jspubtd.h"
#include "xptinfo.h" #include "xptinfo.h"
#include "nsAXPCNativeCallContext.h" #include "nsAXPCNativeCallContext.h"
#include "nsWrapperCache.h"
%} %}
/***************************************************************************/ /***************************************************************************/
@ -72,6 +73,7 @@
[ptr] native nsScriptObjectTracerPtr(nsScriptObjectTracer); [ptr] native nsScriptObjectTracerPtr(nsScriptObjectTracer);
[ref] native nsCCTraversalCallbackRef(nsCycleCollectionTraversalCallback); [ref] native nsCCTraversalCallbackRef(nsCycleCollectionTraversalCallback);
[ptr] native nsAXPCNativeCallContextPtr(nsAXPCNativeCallContext); [ptr] native nsAXPCNativeCallContextPtr(nsAXPCNativeCallContext);
[ptr] native nsWrapperCachePtr(nsWrapperCache);
/***************************************************************************/ /***************************************************************************/
@ -397,7 +399,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
%} %}
[uuid(c53c54ac-afc1-458a-98f5-cadb52574e40)] [uuid(7a30abb6-349c-4bb5-b395-78f8a860d6e3)]
interface nsIXPConnect : nsISupports interface nsIXPConnect : nsISupports
{ {
%{ C++ %{ C++
@ -498,6 +500,7 @@ interface nsIXPConnect : nsISupports
wrapNativeToJSVal(in JSContextPtr aJSContext, wrapNativeToJSVal(in JSContextPtr aJSContext,
in JSObjectPtr aScope, in JSObjectPtr aScope,
in nsISupports aCOMObj, in nsISupports aCOMObj,
in nsWrapperCachePtr aCache,
in nsIIDPtr aIID, in nsIIDPtr aIID,
in boolean aAllowWrapper, in boolean aAllowWrapper,
out jsval aVal, out jsval aVal,

View File

@ -1271,6 +1271,7 @@ static nsresult
NativeInterface2JSObject(XPCLazyCallContext & lccx, NativeInterface2JSObject(XPCLazyCallContext & lccx,
JSObject * aScope, JSObject * aScope,
nsISupports *aCOMObj, nsISupports *aCOMObj,
nsWrapperCache *aCache,
const nsIID * aIID, const nsIID * aIID,
PRBool aAllowWrapping, PRBool aAllowWrapping,
jsval *aVal, jsval *aVal,
@ -1278,7 +1279,7 @@ NativeInterface2JSObject(XPCLazyCallContext & lccx,
{ {
nsresult rv; nsresult rv;
if(!XPCConvert::NativeInterface2JSObject(lccx, aVal, aHolder, aCOMObj, aIID, if(!XPCConvert::NativeInterface2JSObject(lccx, aVal, aHolder, aCOMObj, aIID,
nsnull, nsnull, aScope, nsnull, aCache, aScope,
aAllowWrapping, OBJ_IS_NOT_GLOBAL, aAllowWrapping, OBJ_IS_NOT_GLOBAL,
&rv)) &rv))
return rv; return rv;
@ -1310,8 +1311,8 @@ nsXPConnect::WrapNative(JSContext * aJSContext,
XPCLazyCallContext lccx(ccx); XPCLazyCallContext lccx(ccx);
jsval v; jsval v;
return NativeInterface2JSObject(lccx, aScope, aCOMObj, &aIID, PR_FALSE, &v, return NativeInterface2JSObject(lccx, aScope, aCOMObj, nsnull, &aIID,
aHolder); PR_FALSE, &v, aHolder);
} }
/* void wrapNativeToJSVal (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDPtr aIID, out jsval aVal, out nsIXPConnectJSObjectHolder 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, nsXPConnect::WrapNativeToJSVal(JSContext * aJSContext,
JSObject * aScope, JSObject * aScope,
nsISupports *aCOMObj, nsISupports *aCOMObj,
nsWrapperCache *aCache,
const nsIID * aIID, const nsIID * aIID,
PRBool aAllowWrapping, PRBool aAllowWrapping,
jsval *aVal, jsval *aVal,
@ -1333,8 +1335,8 @@ nsXPConnect::WrapNativeToJSVal(JSContext * aJSContext,
XPCLazyCallContext lccx(NATIVE_CALLER, aJSContext); XPCLazyCallContext lccx(NATIVE_CALLER, aJSContext);
return NativeInterface2JSObject(lccx, aScope, aCOMObj, aIID, aAllowWrapping, return NativeInterface2JSObject(lccx, aScope, aCOMObj, aCache, aIID,
aVal, aHolder); aAllowWrapping, aVal, aHolder);
} }
/* void wrapJS (in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */ /* void wrapJS (in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */