nsCOMPtr<nsIPrincipal> principal; nsresult rv = GetDocumentPrincipal(getter_AddRefs(principal)); if (NS_FAILED(rv)) return rv;
nsIPrincipal *principal = GetDocumentPrincipal(); if (!principal) return NS_ERROR_FAILURE;
nsXULPrototypeDocument::NewXULPDGlobalObject(nsIScriptGlobalObject** aResult){    nsCOMPtr<nsIPrincipal> principal;    nsresult rv = GetDocumentPrincipal(getter_AddRefs(principal));    if (NS_FAILED(rv))        return rv;    // Now that GetDocumentPrincipal has succeeded, we can safely compare its    // result to gSystemPrincipal, in order to create gSystemGlobal if the two    // pointers are equal.  Thus, gSystemGlobal implies gSystemPrincipal.    nsCOMPtr<nsIScriptGlobalObject> global;    if (principal == gSystemPrincipal) {        if (!gSystemGlobal) {            gSystemGlobal = new nsXULPDGlobalObject();            if (! gSystemGlobal)                return NS_ERROR_OUT_OF_MEMORY;            NS_ADDREF(gSystemGlobal);        }        global = gSystemGlobal;    } else {        global = new nsXULPDGlobalObject();        if (! global)            return NS_ERROR_OUT_OF_MEMORY;        global->SetGlobalObjectOwner(this); // does not refcount    }    *aResult = global;    NS_ADDREF(*aResult);    return NS_OK;}