nsresult rv = CreateSyntheticDocument(); if (NS_FAILED(rv)) { return;
if (!mRootContent) {  nsresult rv = CreateSyntheticDocument(); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic document");  if (mImageResizingEnabled) { target = do_QueryInterface(mImageContent); target->AddEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE); }
nsImageDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject){  if (!aScriptGlobalObject) {    if (mImageResizingEnabled) {      nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mImageContent);      target->RemoveEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE);      target = do_QueryInterface(mScriptGlobalObject);      target->RemoveEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);      target->RemoveEventListener(NS_LITERAL_STRING("keypress"), this,                                  PR_FALSE);    }    // Break reference cycle with mImageContent, if we have one    nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);    if (imageLoader) {      imageLoader->RemoveObserver(this);    }        mImageContent = nsnull;  }  // Set the script global object on the superclass before doing  // anything that might require it....  nsHTMLDocument::SetScriptGlobalObject(aScriptGlobalObject);  if (aScriptGlobalObject) {    // Create synthetic document    nsresult rv = CreateSyntheticDocument();    if (NS_FAILED(rv)) {      return;    }    if (mImageResizingEnabled) {      nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mImageContent);      target->AddEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE);      target = do_QueryInterface(aScriptGlobalObject);      target->AddEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);      target->AddEventListener(NS_LITERAL_STRING("keypress"), this, PR_FALSE);    }  }}