Bug 899812 - Error reporters should consistently report errors to stderr (r=bholley)

This commit is contained in:
Bill McCloskey 2013-07-31 17:04:49 -07:00
parent 49ce084f1b
commit ca26060518
8 changed files with 83 additions and 75 deletions

View File

@ -2116,6 +2116,11 @@ public:
const nsAString& aFeature,
const nsAString& aVersion);
/**
* Return true if the browser.dom.window.dump.enabled pref is set.
*/
static bool DOMWindowDumpEnabled();
private:
static bool InitializeEventTable();
@ -2225,6 +2230,10 @@ private:
static nsString* sOSText;
static nsString* sAltText;
static nsString* sModifierSeparator;
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
static bool sDOMWindowDumpEnabled;
#endif
};
typedef nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>

View File

@ -242,6 +242,10 @@ nsIParser* nsContentUtils::sXMLFragmentParser = nullptr;
nsIFragmentContentSink* nsContentUtils::sXMLFragmentSink = nullptr;
bool nsContentUtils::sFragmentParsingActive = false;
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
bool nsContentUtils::sDOMWindowDumpEnabled;
#endif
namespace {
static const char kJSStackContractID[] = "@mozilla.org/js/xpc/ContextStack;1";
@ -434,6 +438,11 @@ nsContentUtils::Init()
"dom.event.handling-user-input-time-limit",
1000);
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
Preferences::AddBoolVarCache(&sDOMWindowDumpEnabled,
"browser.dom.window.dump.enabled");
#endif
Element::InitCCCallbacks();
sInitialized = true;
@ -6423,3 +6432,16 @@ nsContentUtils::InternalIsSupported(nsISupports* aObject,
// Otherwise, we claim to support everything
return true;
}
bool
nsContentUtils::DOMWindowDumpEnabled()
{
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
// In optimized builds we check a pref that controls if we should
// enable output from dump() or not, in debug builds it's always
// enabled.
return nsContentUtils::sDOMWindowDumpEnabled;
#else
return true;
#endif
}

View File

@ -283,10 +283,6 @@ static TimeStamp gLastRecordedRecentTimeouts;
int32_t gTimeoutCnt = 0;
#endif
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
static bool gDOMWindowDumpEnabled = false;
#endif
#if defined(DEBUG_bryner) || defined(DEBUG_chb)
#define DEBUG_PAGE_CACHE
#endif
@ -1085,10 +1081,6 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
gRefCnt++;
if (gRefCnt == 1) {
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
Preferences::AddBoolVarCache(&gDOMWindowDumpEnabled,
"browser.dom.window.dump.enabled");
#endif
Preferences::AddIntVarCache(&gMinTimeoutValue,
"dom.min_timeout_value",
DEFAULT_MIN_TIMEOUT_VALUE);
@ -5160,23 +5152,10 @@ nsGlobalWindow::GetFullScreen(bool* aFullScreen)
return NS_OK;
}
bool
nsGlobalWindow::DOMWindowDumpEnabled()
{
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
// In optimized builds we check a pref that controls if we should
// enable output from dump() or not, in debug builds it's always
// enabled.
return gDOMWindowDumpEnabled;
#else
return true;
#endif
}
NS_IMETHODIMP
nsGlobalWindow::Dump(const nsAString& aStr)
{
if (!DOMWindowDumpEnabled()) {
if (!nsContentUtils::DOMWindowDumpEnabled()) {
return NS_OK;
}

View File

@ -631,8 +631,6 @@ public:
virtual nsresult SetArguments(nsIArray *aArguments);
static bool DOMWindowDumpEnabled();
void MaybeForgiveSpamCount();
bool IsClosedOrClosing() {
return (mIsClosed ||

View File

@ -555,31 +555,31 @@ NS_ScriptErrorReporter(JSContext *cx,
}
}
#ifdef DEBUG
// Print it to stderr as well, for the benefit of those invoking
// mozilla with -console.
nsAutoCString error;
error.Assign("JavaScript ");
if (JSREPORT_IS_STRICT(report->flags))
error.Append("strict ");
if (JSREPORT_IS_WARNING(report->flags))
error.Append("warning: ");
else
error.Append("error: ");
error.Append(report->filename);
error.Append(", line ");
error.AppendInt(report->lineno, 10);
error.Append(": ");
if (report->ucmessage) {
AppendUTF16toUTF8(reinterpret_cast<const PRUnichar*>(report->ucmessage),
error);
} else {
error.Append(message);
}
if (nsContentUtils::DOMWindowDumpEnabled()) {
// Print it to stderr as well, for the benefit of those invoking
// mozilla with -console.
nsAutoCString error;
error.Assign("JavaScript ");
if (JSREPORT_IS_STRICT(report->flags))
error.Append("strict ");
if (JSREPORT_IS_WARNING(report->flags))
error.Append("warning: ");
else
error.Append("error: ");
error.Append(report->filename);
error.Append(", line ");
error.AppendInt(report->lineno, 10);
error.Append(": ");
if (report->ucmessage) {
AppendUTF16toUTF8(reinterpret_cast<const PRUnichar*>(report->ucmessage),
error);
} else {
error.Append(message);
}
fprintf(stderr, "%s\n", error.get());
fflush(stderr);
#endif
fprintf(stderr, "%s\n", error.get());
fflush(stderr);
}
#ifdef PR_LOGGING
if (!gJSDiagnostics)

View File

@ -1126,7 +1126,7 @@ public:
}
}
if (!logged) {
if (!logged || nsContentUtils::DOMWindowDumpEnabled()) {
NS_ConvertUTF16toUTF8 msg(aMessage);
#ifdef ANDROID
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", msg.get());

View File

@ -9,6 +9,7 @@
#include "xpcprivate.h"
#include "nsArrayEnumerator.h"
#include "nsContentUtils.h"
#include "nsWrapperCache.h"
#include "XPCWrapper.h"
#include "AccessCheck.h"
@ -1032,25 +1033,25 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
}
if (reportable) {
#ifdef DEBUG
static const char line[] =
"************************************************************\n";
static const char preamble[] =
"* Call to xpconnect wrapped JSObject produced this error: *\n";
static const char cant_get_text[] =
"FAILED TO GET TEXT FROM EXCEPTION\n";
if (nsContentUtils::DOMWindowDumpEnabled()) {
static const char line[] =
"************************************************************\n";
static const char preamble[] =
"* Call to xpconnect wrapped JSObject produced this error: *\n";
static const char cant_get_text[] =
"FAILED TO GET TEXT FROM EXCEPTION\n";
fputs(line, stdout);
fputs(preamble, stdout);
char* text;
if (NS_SUCCEEDED(xpc_exception->ToString(&text)) && text) {
fputs(text, stdout);
fputs("\n", stdout);
nsMemory::Free(text);
} else
fputs(cant_get_text, stdout);
fputs(line, stdout);
#endif
fputs(line, stdout);
fputs(preamble, stdout);
char* text;
if (NS_SUCCEEDED(xpc_exception->ToString(&text)) && text) {
fputs(text, stdout);
fputs("\n", stdout);
nsMemory::Free(text);
} else
fputs(cant_get_text, stdout);
fputs(line, stdout);
}
// Log the exception to the JS Console, so that users can do
// something with it.

View File

@ -269,14 +269,13 @@ xpc::SystemErrorReporter(JSContext *cx, const char *message, JSErrorReport *rep)
consoleService->LogMessage(errorObject);
}
/* Log to stderr in debug builds. */
#ifdef DEBUG
fprintf(stderr, "System JS : %s %s:%d\n"
" %s\n",
JSREPORT_IS_WARNING(rep->flags) ? "WARNING" : "ERROR",
rep->filename, rep->lineno,
message ? message : "<no message>");
#endif
if (nsContentUtils::DOMWindowDumpEnabled()) {
fprintf(stderr, "System JS : %s %s:%d\n"
" %s\n",
JSREPORT_IS_WARNING(rep->flags) ? "WARNING" : "ERROR",
rep->filename, rep->lineno,
message ? message : "<no message>");
}
}