Bug 648801 (new DOM list bindings) - Fix GetNativeOfWrapper/GetJSObjectOfWrapper/xpc_OkToHandOutWrapper/quickstubs to deal with the new DOM bindings. r=bz/jst/mrbkap.

--HG--
extra : rebase_source : 1b9afcc9d588ece15753fb36b249bc3a288e98c0
This commit is contained in:
Peter Van der Beken 2011-08-02 15:16:05 +02:00
parent 2980e5d4d8
commit bfe49c1981
6 changed files with 74 additions and 26 deletions

View File

@ -503,6 +503,7 @@
#include "nsIDOMCustomEvent.h"
#include "nsWrapperCacheInlines.h"
#include "dombindings.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -8425,14 +8426,20 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
if (!JSVAL_IS_PRIMITIVE(collection)) {
// We already have a node list in our reserved slot, use it.
nsISupports *native =
sXPConnect->GetNativeOfWrapper(cx, JSVAL_TO_OBJECT(collection));
if (native) {
NS_ADDREF(*nodeList = nsContentList::FromSupports(native));
JSObject *obj = JSVAL_TO_OBJECT(collection);
if (xpc::dom::NodeList<nsIHTMLCollection>::objIsNodeList(obj)) {
nsIHTMLCollection *native =
xpc::dom::NodeList<nsIHTMLCollection>::getNodeList(obj);
NS_ADDREF(*nodeList = static_cast<nsContentList*>(native));
}
else {
rv = NS_ERROR_FAILURE;
nsISupports *native = sXPConnect->GetNativeOfWrapper(cx, obj);
if (native) {
NS_ADDREF(*nodeList = nsContentList::FromSupports(native));
}
else {
rv = NS_ERROR_FAILURE;
}
}
} else {
// No node list for this document.all yet, create one...

View File

@ -1019,5 +1019,9 @@ NodeList<T>::finalize(JSContext *cx, JSObject *proxy)
NS_RELEASE(nodeList);
}
template
nsIHTMLCollection*
NodeList<nsIHTMLCollection>::getNodeList(JSObject *obj);
}
}

View File

@ -118,8 +118,6 @@ class NodeList : public NodeListBase {
static bool instanceIsNodeListObject(JSContext *cx, JSObject *obj, JSObject *callee);
static JSObject *getPrototype(JSContext *cx, XPCWrappedNativeScope *scope, bool *enabled);
static T *getNodeList(JSObject *obj);
static JSObject *ensureExpandoObject(JSContext *cx, JSObject *obj);
static uint32 getProtoShape(JSObject *obj);
@ -178,6 +176,7 @@ class NodeList : public NodeListBase {
{
return js::GetObjectClass(prototype) == &sInterfaceClass;
}
static T *getNodeList(JSObject *obj);
};
}

View File

@ -1539,9 +1539,22 @@ nsXPConnect::GetNativeOfWrapper(JSContext * aJSContext,
nsIXPConnectWrappedNative* wrapper =
XPCWrappedNative::GetWrappedNativeOfJSObject(aJSContext, aJSObj, nsnull,
&obj2);
if(wrapper)
return wrapper->Native();
return wrapper ? wrapper->Native() :
(obj2 ? (nsISupports*)xpc_GetJSPrivate(obj2) : nsnull);
if(obj2)
return (nsISupports*)xpc_GetJSPrivate(obj2);
if(xpc::dom::instanceIsProxy(aJSObj)) {
// FIXME: Provide a fast non-refcounting way to get the canonical
// nsISupports from the proxy.
nsISupports *supports =
static_cast<nsISupports*>(js::GetProxyPrivate(aJSObj).toPrivate());
nsCOMPtr<nsISupports> canonical = do_QueryInterface(supports);
return canonical.get();
}
return nsnull;
}
/* JSObjectPtr getJSObjectOfWrapper (in JSContextPtr aJSContext, in JSObjectPtr aJSObj); */
@ -1572,6 +1585,11 @@ nsXPConnect::GetJSObjectOfWrapper(JSContext * aJSContext,
*_retval = obj2;
return NS_OK;
}
if(xpc::dom::instanceIsProxy(aJSObj))
{
*_retval = aJSObj;
return NS_OK;
}
// else...
*_retval = nsnull;
return NS_ERROR_FAILURE;

View File

@ -875,13 +875,31 @@ castNative(JSContext *cx,
}
else if(cur)
{
NS_ABORT_IF_FALSE(IS_SLIM_WRAPPER(cur), "should be a slim wrapper");
nsISupports *native = static_cast<nsISupports*>(xpc_GetJSPrivate(cur));
if(NS_SUCCEEDED(getNative(native, GetOffsetsFromSlimWrapper(cur),
cur, iid, ppThis, pThisRef, vp)))
nsISupports *native;
QITableEntry *entries;
if(IS_SLIM_WRAPPER(cur))
{
native = static_cast<nsISupports*>(xpc_GetJSPrivate(cur));
entries = GetOffsetsFromSlimWrapper(cur);
}
else
{
NS_ABORT_IF_FALSE(xpc::dom::instanceIsProxy(cur),
"what kind of wrapper is this?");
native = static_cast<nsISupports*>(js::GetProxyPrivate(cur).toPrivate());
entries = nsnull;
}
if(NS_SUCCEEDED(getNative(native, entries, cur, iid, ppThis, pThisRef, vp)))
{
if(lccx)
{
// This only matters for unwrapping of this objects, so we
// shouldn't end up here for the new DOM bindings.
NS_ABORT_IF_FALSE(IS_SLIM_WRAPPER(cur),
"what kind of wrapper is this?");
lccx->SetWrapper(cur);
}
return NS_OK;
}
@ -953,8 +971,16 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
XPCWrappedNative *wrapper;
XPCWrappedNativeTearOff *tearoff;
JSObject *obj2;
rv = getWrapper(cx, src, nsnull, &wrapper, &obj2, &tearoff);
NS_ENSURE_SUCCESS(rv, rv);
if(xpc::dom::instanceIsProxy(src))
{
wrapper = nsnull;
obj2 = src;
}
else
{
rv = getWrapper(cx, src, nsnull, &wrapper, &obj2, &tearoff);
NS_ENSURE_SUCCESS(rv, rv);
}
if(wrapper || obj2)
{

View File

@ -60,16 +60,10 @@ xpc_OkToHandOutWrapper(nsWrapperCache *cache)
NS_ABORT_IF_FALSE(cache->GetWrapper(), "Must have wrapper");
NS_ABORT_IF_FALSE(cache->IsProxy() || IS_WN_WRAPPER(cache->GetWrapper()),
"Must have proxy or XPCWrappedNative wrapper");
NS_ABORT_IF_FALSE(cache->IsProxy() == js::IsProxy(cache->GetWrapper()),
"There's serious confusion about whether this is a "
"proxy");
return
(cache->IsProxy() &&
js::GetProxyHandler(cache->GetWrapper())->family() ==
xpc::dom::ProxyFamily()) ||
(!cache->IsProxy() &&
!static_cast<XPCWrappedNative*>(xpc_GetJSPrivate(cache->GetWrapper()))->
NeedsSOW());
return cache->IsProxy() ?
xpc::dom::instanceIsProxy(cache->GetWrapper()) :
!static_cast<XPCWrappedNative*>(xpc_GetJSPrivate(cache->GetWrapper()))->
NeedsSOW();
}
/***************************************************************************/