Bug 889714 - Use SystemErrorReporter instead of ScriptErrorReporter. r=mrbkap
☠☠ backed out by 659b0d61fbc6 ☠ ☠
authorBobby Holley <bobbyholley@gmail.com>
Thu, 25 Jul 2013 11:29:21 -0700
changeset 148052 0645c69167ba3298d741dac359dd0309b7756e6b
parent 148051 6462b9338a4925d77cadd80fc5e44c1ccf466139
child 148053 142c7afd4ec5d193bb62da5679f46db99b78c4c1
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs889714
milestone24.0a2
Bug 889714 - Use SystemErrorReporter instead of ScriptErrorReporter. r=mrbkap SystemErrorReporter is the new unified error reporter for everything non-dom. In particular, it's used by the SafeJSContext, which we'll be switching to here shortly.
ipc/testshell/XPCShellEnvironment.cpp
--- a/ipc/testshell/XPCShellEnvironment.cpp
+++ b/ipc/testshell/XPCShellEnvironment.cpp
@@ -81,114 +81,27 @@ Environment(JSObject* global)
     if (!JS_GetProperty(cx, global, "__XPCShellEnvironment", v.address()) ||
         !v.get().isDouble())
     {
         return nullptr;
     }
     return static_cast<XPCShellEnvironment*>(v.get().toPrivate());
 }
 
-static void
-ScriptErrorReporter(JSContext *cx,
-                    const char *message,
-                    JSErrorReport *report)
-{
-    int i, j, k, n;
-    char *prefix = NULL, *tmp;
-    const char *ctmp;
-    nsCOMPtr<nsIXPConnect> xpc;
-
-    // Don't report an exception from inner JS frames as the callers may intend
-    // to handle it.
-    if (JS_DescribeScriptedCaller(cx, nullptr, nullptr)) {
-        return;
-    }
-
-    // In some cases cx->fp is null here so use XPConnect to tell us about inner
-    // frames.
-    if ((xpc = do_GetService(nsIXPConnect::GetCID()))) {
-        nsAXPCNativeCallContext *cc = nullptr;
-        xpc->GetCurrentNativeCallContext(&cc);
-        if (cc) {
-            nsAXPCNativeCallContext *prev = cc;
-            while (NS_SUCCEEDED(prev->GetPreviousCallContext(&prev)) && prev) {
-                uint16_t lang;
-                if (NS_SUCCEEDED(prev->GetLanguage(&lang)) &&
-                    lang == nsAXPCNativeCallContext::LANG_JS) {
-                    return;
-                }
-            }
-        }
-    }
-
-    if (!report) {
-        fprintf(stderr, "%s\n", message);
-        return;
-    }
-
-    if (report->filename)
-        prefix = JS_smprintf("%s:", report->filename);
-    if (report->lineno) {
-        tmp = prefix;
-        prefix = JS_smprintf("%s%u: ", tmp ? tmp : "", report->lineno);
-        JS_free(cx, tmp);
-    }
-    if (JSREPORT_IS_WARNING(report->flags)) {
-        tmp = prefix;
-        prefix = JS_smprintf("%s%swarning: ",
-                             tmp ? tmp : "",
-                             JSREPORT_IS_STRICT(report->flags) ? "strict " : "");
-        JS_free(cx, tmp);
-    }
-
-    /* embedded newlines -- argh! */
-    while ((ctmp = strchr(message, '\n')) != 0) {
-        ctmp++;
-        if (prefix) fputs(prefix, stderr);
-        fwrite(message, 1, ctmp - message, stderr);
-        message = ctmp;
-    }
-    /* If there were no filename or lineno, the prefix might be empty */
-    if (prefix)
-        fputs(prefix, stderr);
-    fputs(message, stderr);
-
-    if (!report->linebuf) {
-        fputc('\n', stderr);
-        goto out;
-    }
-
-    fprintf(stderr, ":\n%s%s\n%s", prefix, report->linebuf, prefix);
-    n = report->tokenptr - report->linebuf;
-    for (i = j = 0; i < n; i++) {
-        if (report->linebuf[i] == '\t') {
-            for (k = (j + 8) & ~7; j < k; j++) {
-                fputc('.', stderr);
-            }
-            continue;
-        }
-        fputc('.', stderr);
-        j++;
-    }
-    fputs("^\n", stderr);
- out:
-    JS_free(cx, prefix);
-}
-
 JSContextCallback gOldContextCallback = NULL;
 
 static JSBool
 ContextCallback(JSContext *cx,
                 unsigned contextOp)
 {
     if (gOldContextCallback && !gOldContextCallback(cx, contextOp))
         return JS_FALSE;
 
     if (contextOp == JSCONTEXT_NEW) {
-        JS_SetErrorReporter(cx, ScriptErrorReporter);
+        JS_SetErrorReporter(cx, xpc::SystemErrorReporter);
     }
     return JS_TRUE;
 }
 
 static JSBool
 Print(JSContext *cx,
       unsigned argc,
       JS::Value *vp)