[gjs] console: Print exception even when not from SpiderMonkey



commit 29ff8b88c2e7d74cd6e04a7a0a6c5c8fd3bed09c
Author: Philip Chimento <philip endlessm com>
Date:   Fri Aug 11 16:56:54 2017 -0700

    console: Print exception even when not from SpiderMonkey
    
    This was a recent regression; the console shell would abort if an
    exception couldn't be converted into an error report. However, only
    exceptions created within SpiderMonkey have error reports associated with
    them. Our exceptions created from GErrors do not, so if there is no error
    report available simply convert the exception to a string.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786183

 modules/console.cpp |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/modules/console.cpp b/modules/console.cpp
index 794ee1e..eb1fb6b 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -156,12 +156,18 @@ public:
 
         JS::RootedObject exn(m_cx, &v_exn.toObject());
         JSErrorReport *report = JS_ErrorFromException(m_cx, exn);
-        if (!report)
-            g_error("Out of memory initializing ErrorReport");
-
-        g_assert(!JSREPORT_IS_WARNING(report->flags));
-
-        gjs_console_print_error(report);
+        if (report) {
+            g_assert(!JSREPORT_IS_WARNING(report->flags));
+            gjs_console_print_error(report);
+        } else {
+            JS::RootedString message(m_cx, JS::ToString(m_cx, v_exn));
+            if (!message) {
+                g_printerr("(could not convert thrown exception to string)\n");
+            } else {
+                GjsAutoJSChar message_utf8(m_cx, JS_EncodeStringToUTF8(m_cx, message));
+                g_printerr("%s\n", message_utf8.get());
+            }
+        }
 
         JS::RootedObject stack(m_cx, ExceptionStackOrNull(exn));
         if (stack) {


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