if (context) context->RemoveReference((void*) &mScriptObject, mScriptObject); } }  if (aNewDocument) { nsCOMPtr<nsIScriptGlobalObject> global; aNewDocument->GetScriptGlobalObject(getter_AddRefs(global)); if (global) { nsCOMPtr<nsIScriptContext> context; global->GetContext(getter_AddRefs(context)); if (context) context->AddNamedReference((void*) &mScriptObject, mScriptObject, "nsXBLBinding::mScriptObject");
if (context) { JSObject* scriptObject; nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(mBoundElement)); owner->GetScriptObject(context, (void**)&scriptObject); if (scriptObject) {     JSContext* jscontext = (JSContext*)context->GetNativeContext(); JSObject* ourProto = ::JS_GetPrototype(jscontext, scriptObject); JSObject* grandProto = ::JS_GetPrototype(jscontext, ourProto); ::JS_SetPrototype(jscontext, scriptObject, grandProto); } }
nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument){  if (aOldDocument != aNewDocument) {    if (mNextBinding)      mNextBinding->ChangeDocument(aOldDocument, aNewDocument);    if (mScriptObject) {      if (aOldDocument) {        nsCOMPtr<nsIScriptGlobalObject> global;        aOldDocument->GetScriptGlobalObject(getter_AddRefs(global));        if (global) {          nsCOMPtr<nsIScriptContext> context;          global->GetContext(getter_AddRefs(context));          if (context)            context->RemoveReference((void*) &mScriptObject, mScriptObject);        }      }      if (aNewDocument) {        nsCOMPtr<nsIScriptGlobalObject> global;        aNewDocument->GetScriptGlobalObject(getter_AddRefs(global));        if (global) {          nsCOMPtr<nsIScriptContext> context;          global->GetContext(getter_AddRefs(context));          if (context)            context->AddNamedReference((void*) &mScriptObject, mScriptObject, "nsXBLBinding::mScriptObject");        }      }    }    nsCOMPtr<nsIContent> anonymous;    GetAnonymousContent(getter_AddRefs(anonymous));    if (anonymous)      anonymous->SetDocument(aNewDocument, PR_TRUE);  }  return NS_OK;}