NS_IMETHODIMP nsXPCWrappedJS::QueryInterface(REFNSIID aIID, void** aInstancePtr) { if (nsnull == aInstancePtr) { NS_PRECONDITION(0, "null pointer"); return NS_ERROR_NULL_POINTER; } if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) { *aInstancePtr = & NS_CYCLE_COLLECTION_NAME(nsXPCWrappedJS); return NS_OK; } if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports))) { *aInstancePtr = NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Upcast(this); return NS_OK; } if (!IsValid()) return NS_ERROR_UNEXPECTED; // Always check for this first so that our 'outer' can get this interface // from us without recurring into a call to the outer's QI! if (aIID.Equals(NS_GET_IID(nsIXPConnectWrappedJS))) { NS_ADDREF(this); *aInstancePtr = (void*) static_cast<nsIXPConnectWrappedJS*>(this); return NS_OK; } nsISupports* outer = GetAggregatedNativeObject(); if (outer) return outer->QueryInterface(aIID, aInstancePtr); // else... return mClass->DelegatedQueryInterface(this, aIID, aInstancePtr); }
/* Class that wraps JS objects to appear as XPCOM objects. */ #include "xpcprivate.h" #include "nsAtomicRefcnt.h" #include "nsProxyRelease.h" #include "nsThreadUtils.h" #include "nsTextFormatter.h" // NOTE: much of the fancy footwork is done in xpcstubs.cpp NS_IMPL_CYCLE_COLLECTION_CLASS(nsXPCWrappedJS) NS_IMETHODIMP NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::TraverseImpl (NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS) *that, void *p, nsCycleCollectionTraversalCallback &cb) { nsISupports *s = static_cast<nsISupports*>(p); NS_ASSERTION(CheckForRightISupports(s), "not the nsISupports pointer we expect"); nsXPCWrappedJS *tmp = Downcast(s); nsrefcnt refcnt = tmp->mRefCnt.get(); if (cb.WantDebugInfo()) { char name[72]; if (tmp->GetClass()) JS_snprintf(name, sizeof(name), "nsXPCWrappedJS (%s)", tmp->GetClass()->GetInterfaceName()); else JS_snprintf(name, sizeof(name), "nsXPCWrappedJS");