nsCOMPtr<nsIScriptGlobalObject> global; doc->GetScriptGlobalObject(getter_AddRefs(global));
nsIScriptGlobalObject *global = doc->GetScriptGlobalObject();
nsBindingManager::GetBindingImplementation(nsIContent* aContent, void* aScriptObject, REFNSIID aIID, void** aResult){  *aResult = nsnull;  nsCOMPtr<nsIXBLBinding> binding;  GetBinding(aContent, getter_AddRefs(binding));  if (binding) {    PRBool supportsInterface;    binding->ImplementsInterface(aIID, &supportsInterface);    if (supportsInterface) {      nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS;      GetWrappedJS(aContent, getter_AddRefs(wrappedJS));      if (wrappedJS)        return wrappedJS->AggregatedQueryInterface(aIID, aResult);      // We have never made a wrapper for this implementation.      // Create an XPC wrapper for the script object and hand it back.      JSObject* jsobj = (JSObject*)aScriptObject;      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;      nsISupports* nativeThis = (nsISupports*)JS_GetPrivate(jscontext, jsobj);      nsresult rv = xpConnect->WrapJSAggregatedToNative(nativeThis, 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;}