aContent->GetDocument(*getter_AddRefs(doc));
aContent->GetDocument(getter_AddRefs(doc));
nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,                                           void** aResult){  *aResult = nsnull;  nsCOMPtr<nsIXBLBinding> binding;  GetBinding(aContent, getter_AddRefs(binding));  if (binding) {    PRBool supportsInterface;    // The binding should not be asked for nsISupports    NS_ASSERTION(!aIID.Equals(NS_GET_IID(nsISupports)), "Asking a binding for nsISupports");    binding->ImplementsInterface(aIID, &supportsInterface);    if (supportsInterface) {      nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS;      GetWrappedJS(aContent, getter_AddRefs(wrappedJS));      if (wrappedJS) {        // Protect from recurring in QI calls through XPConnect.         // This can happen when a second binding is being resolved.        // At that point a wrappedJS exists, but it doesn't yet know about        // the iid we are asking for. So, without this protection,         // AggregatedQueryInterface would end up recurring back into itself        // through this code.         //        // With this protection, when we detect the recursion we return         // NS_NOINTERFACE in the inner call. The outer call will then fall         // through (see below) and build a new chained wrappedJS for the iid.        //        // We're careful to not assume that only one direct nesting can occur        // because there is a call into JS in the middle and we can't assume         // that this code won't be reached by some more complex nesting path.        //        // NOTE: We *assume* this is single threaded, so we can use a        // static linked list to do the check.        static AntiRecursionData* list = nsnull;        for (AntiRecursionData* p = list; p; p = p->next) {          if (p->element == aContent && p->iid.Equals(aIID)) {            *aResult = nsnull;            return NS_NOINTERFACE;          }        }        AntiRecursionData item(aContent, aIID, list);        list = &item;        nsresult rv = wrappedJS->AggregatedQueryInterface(aIID, aResult);                list = item.next;                if (*aResult)          return rv;                // No result was found, so this must be another XBL interface.        // Fall through to create a new wrapper.      }      // We have never made a wrapper for this implementation.      // Create an XPC wrapper for the script object and hand it back.      nsCOMPtr<nsIDocument> doc;      aContent->GetDocument(*getter_AddRefs(doc));      if (!doc)        return NS_NOINTERFACE;      nsCOMPtr<nsIScriptGlobalObject> global;      doc->GetScriptGlobalObject(getter_AddRefs(global));      if (!global)        return NS_NOINTERFACE;      nsCOMPtr<nsIScriptContext> context;      global->GetContext(getter_AddRefs(context));      if (!context)        return NS_NOINTERFACE;      JSContext* jscontext = (JSContext*)context->GetNativeContext();      if (!jscontext)        return NS_NOINTERFACE;      nsCOMPtr<nsIXPConnect> xpConnect = do_GetService("@mozilla.org/js/xpc/XPConnect;1");      if (!xpConnect)        return NS_NOINTERFACE;      nsCOMPtr<nsIXPConnectWrappedNative> wrapper;      xpConnect->GetWrappedNativeOfNativeObject(jscontext,                                                JS_GetGlobalObject(jscontext),                                                aContent,                                                NS_GET_IID(nsISupports),                                                getter_AddRefs(wrapper));      NS_ENSURE_TRUE(wrapper, NS_NOINTERFACE);      JSObject* jsobj = nsnull;      wrapper->GetJSObject(&jsobj);      NS_ENSURE_TRUE(jsobj, NS_NOINTERFACE);      nsresult rv = xpConnect->WrapJSAggregatedToNative(aContent, jscontext,                                                        jsobj, aIID, aResult);      if (NS_FAILED(rv))        return rv;      // We successfully created a wrapper.  We will own this wrapper for as long as the binding remains      // alive.  At the time the binding is cleared out of the bindingManager, we will remove the wrapper      // from the bindingManager as well.      nsISupports* supp = NS_STATIC_CAST(nsISupports*, *aResult);      wrappedJS = do_QueryInterface(supp);      SetWrappedJS(aContent, wrappedJS);      return rv;    }  }    *aResult = nsnull;  return NS_NOINTERFACE;}