NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(CreateScriptEnvironment(), NS_ERROR_FAILURE);
nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr){   NS_ENSURE_ARG_POINTER(aInstancePtr);   nsresult rv = NS_OK;   *aInstancePtr = nsnull;   if(aIID.Equals(NS_GET_IID(nsILinkHandler)))      {      // Note: If we ever allow for registering other link handlers,      // we need to make sure that link handler implementations take      // the necessary precautions to prevent the security compromise      // that is blocked by nsWebSell::OnLinkClickSync().      *aInstancePtr = NS_STATIC_CAST(nsILinkHandler*, this);      NS_ADDREF((nsISupports*)*aInstancePtr);      return NS_OK;      }   else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObjectOwner)))      {      *aInstancePtr = NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this);      NS_ADDREF((nsISupports*)*aInstancePtr);      return NS_OK;      }   else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)))      {      NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);      *aInstancePtr = mScriptGlobal;      NS_ADDREF((nsISupports*)*aInstancePtr);      return NS_OK;      }   else if(aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) ||           aIID.Equals(NS_GET_IID(nsIDOMWindow)))      {      NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);      NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(aIID, aInstancePtr),                        NS_ERROR_FAILURE);      return NS_OK;      }   else if(aIID.Equals(NS_GET_IID(nsICommandManager)))      {      NS_ENSURE_SUCCESS(EnsureCommandHandler(), NS_ERROR_FAILURE);      NS_ENSURE_SUCCESS(mCommandManager->QueryInterface(NS_GET_IID(nsICommandManager),         aInstancePtr), NS_ERROR_FAILURE);      return NS_OK;      }   if (!*aInstancePtr || NS_FAILED(rv))     return nsDocShell::GetInterface(aIID,aInstancePtr);   else     return rv;}