[gjs/wip/ptomato/mozjs52: 40/40] js: Replace error reporter callbacks



commit 6c8b27f88bea651cb0292e3487f504c652a6d236
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Jun 10 18:13:23 2017 -0700

    js: Replace error reporter callbacks
    
    JS_SetErrorReporter() goes away in SpiderMonkey 52, and is replaced by
    JS::SetWarningReporter(). Errors should now be reported manually after
    each call into JS code. (We don't actually have to change much, since we
    already used the DontReportUncaught option and reported uncaught
    exceptions manually already. This is now the only choice.)

 gjs/jsapi-private.cpp |   10 ++++++----
 gjs/jsapi-util.h      |    5 ++---
 gjs/runtime.cpp       |    2 +-
 modules/console.cpp   |   16 +++++++---------
 4 files changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/gjs/jsapi-private.cpp b/gjs/jsapi-private.cpp
index cf16f73..f6584ef 100644
--- a/gjs/jsapi-private.cpp
+++ b/gjs/jsapi-private.cpp
@@ -32,13 +32,14 @@
 #include "jsapi-wrapper.h"
 
 void
-gjs_error_reporter(JSContext     *context,
-                   const char    *message,
-                   JSErrorReport *report)
+gjs_warning_reporter(JSContext     *context,
+                     JSErrorReport *report)
 {
     const char *warning;
     GLogLevelFlags level;
 
+    g_assert(report);
+
     if (gjs_environment_variable_is_set("GJS_ABORT_ON_OOM") &&
         report->flags == JSREPORT_ERROR &&
         report->errorNumber == 137) {
@@ -66,5 +67,6 @@ gjs_error_reporter(JSContext     *context,
         level = G_LOG_LEVEL_WARNING;
     }
 
-    g_log(G_LOG_DOMAIN, level, "JS %s: [%s %d]: %s", warning, report->filename, report->lineno, message);
+    g_log(G_LOG_DOMAIN, level, "JS %s: [%s %d]: %s", warning, report->filename,
+          report->lineno, report->message().c_str());
 }
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index e05e12b..53480e3 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -178,9 +178,8 @@ bool gjs_call_function_value(JSContext                  *context,
                              const JS::HandleValueArray& args,
                              JS::MutableHandleValue      rval);
 
-void        gjs_error_reporter               (JSContext       *context,
-                                              const char      *message,
-                                              JSErrorReport   *report);
+void gjs_warning_reporter(JSContext     *cx,
+                          JSErrorReport *report);
 
 bool        gjs_string_to_utf8               (JSContext       *context,
                                               const JS::Value  string_val,
diff --git a/gjs/runtime.cpp b/gjs/runtime.cpp
index 83c272a..42d96e9 100644
--- a/gjs/runtime.cpp
+++ b/gjs/runtime.cpp
@@ -222,7 +222,7 @@ gjs_create_js_context(GjsContext *js_context)
     // JS_SetGCParameter(cx, JSGC_ALLOCATION_THRESHOLD, 30);
     // JS_SetGCParameter(cx, JSGC_DECOMMIT_THRESHOLD, 32);
     JS_SetLocaleCallbacks(cx, &gjs_locale_callbacks);
-    JS_SetErrorReporter(cx, gjs_error_reporter);
+    JS::SetWarningReporter(cx, gjs_warning_reporter);
 
     return cx;
 }
diff --git a/modules/console.cpp b/modules/console.cpp
index 224a635..6f0195b 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -58,15 +58,11 @@
 #include "gjs/jsapi-wrapper.h"
 
 static void
-gjs_console_print_error(const char *message, JSErrorReport *report)
+gjs_console_print_error(JSErrorReport *report)
 {
     /* Code modified from SpiderMonkey js/src/jscntxt.cpp, js::PrintError() */
 
-    if (!report) {
-        fprintf(stderr, "%s\n", message);
-        fflush(stderr);
-        return;
-    }
+    g_assert(report);
 
     char *prefix = nullptr;
     if (report->filename)
@@ -85,6 +81,8 @@ gjs_console_print_error(const char *message, JSErrorReport *report)
         g_free(tmp);
     }
 
+    const char *message = report->message().c_str();
+
     /* embedded newlines -- argh! */
     const char *ctmp;
     while ((ctmp = strchr(message, '\n')) != 0) {
@@ -135,9 +133,9 @@ gjs_console_print_error(const char *message, JSErrorReport *report)
 }
 
 static void
-gjs_console_error_reporter(JSContext *cx, const char *message, JSErrorReport *report)
+gjs_console_warning_reporter(JSContext *cx, JSErrorReport *report)
 {
-    gjs_console_print_error(message, report);
+    gjs_console_print_error(report);
 }
 
 /* Based on js::shell::AutoReportException from SpiderMonkey. Different from
@@ -266,7 +264,7 @@ gjs_console_interact(JSContext *context,
     int startline;
     FILE *file = stdin;
 
-    JS_SetErrorReporter(JS_GetRuntime(context), gjs_console_error_reporter);
+    JS::SetWarningReporter(context, gjs_console_warning_reporter);
 
         /* It's an interactive filehandle; drop into read-eval-print loop. */
     lineno = 1;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]