nsIScriptGlobalObject* globalObject = mDocument->GetScriptGlobalObject();  if (globalObject) { globalObject->SetNewDocument(nsnull, PR_TRUE, PR_TRUE); }
DocumentViewerImpl::Close(nsISHEntry *aSHEntry){  // All callers are supposed to call close to break circular  // references.  If we do this stuff in the destructor, the  // destructor might never be called (especially if we're being  // used from JS.  mSHEntry = aSHEntry;  // Close is also needed to disable scripts during paint suppression,  // since we transfer the existing global object to the new document  // that is loaded.  In the future, the global object may become a proxy  // for an object that can be switched in and out so that we don't need  // to disable scripts during paint suppression.  if (!mDocument)    return NS_OK;#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)  // Turn scripting back on  // after PrintPreview had turned it off  if (GetIsPrintPreview() && mPrintEngine) {    mPrintEngine->TurnScriptingOn(PR_TRUE);  }#endif  // Break global object circular reference on the document created  // in the DocViewer Init  nsIScriptGlobalObject* globalObject = mDocument->GetScriptGlobalObject();  if (globalObject) {    globalObject->SetNewDocument(nsnull, PR_TRUE, PR_TRUE);  }#ifdef NS_PRINTING  // A Close was called while we were printing  // so don't clear the ScriptGlobalObject  // or clear the mDocument below  // Also, do an extra addref to keep the viewer from going away.  if (mPrintEngine && !mClosingWhilePrinting) {    mClosingWhilePrinting = PR_TRUE;    NS_ADDREF_THIS();  } else#endif    {      // out of band cleanup of webshell      mDocument->SetScriptGlobalObject(nsnull);      if (!mSHEntry)        mDocument->Destroy();    }  if (mFocusListener) {    // get the DOM event receiver    nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));    NS_WARN_IF_FALSE(erP, "No event receiver in document!");    if (erP) {      erP->RemoveEventListenerByIID(mFocusListener,                                    NS_GET_IID(nsIDOMFocusListener));    }  }  return NS_OK;}