mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-24 13:52:37 +00:00
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:
parent
507098fb13
commit
06960e57dc
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -1412,8 +1412,7 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot()
|
||||
|
||||
jsval v;
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> 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);
|
||||
|
||||
|
@ -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<nsIXPConnectJSObjectHolder> 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<nsIXPConnectJSObjectHolder> 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<nsIXPConnectJSObjectHolder> 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<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));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to wrap native!");
|
||||
|
||||
@ -8833,7 +8836,7 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv |= nsDOMClassInfo::WrapNative(cx, obj, static_cast<nsINodeList*>(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<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = nsDOMClassInfo::WrapNative(cx, obj,
|
||||
static_cast<nsINodeList*>(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<nsGenericHTMLFormElement*>(form->GetElementAt(n));
|
||||
nsresult rv = WrapNative(cx, obj, element, element, PR_TRUE, vp);
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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); */
|
||||
|
Loading…
x
Reference in New Issue
Block a user