[gjs/wip/ptomato/mozjs52: 18/38] modules/console: Update to js::PrintError from upstream



commit b9a32c962615cd8bc9e61d529a83bb9944fe55d5
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Apr 29 18:25:44 2017 -0700

    modules/console: Update to js::PrintError from upstream
    
    The existing code doesn't compile with SpiderMonkey 45, so we copy the
    corresponding code from SpiderMonkey 45's js::PrintError() function.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784196

 modules/console.cpp |   34 +++++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/modules/console.cpp b/modules/console.cpp
index 932d9f8..f3d1ac0 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -100,20 +100,28 @@ gjs_console_print_error(const char *message, JSErrorReport *report)
         fputs(prefix, stderr);
     fputs(message, stderr);
 
-    if (report->linebuf) {
-        /* report->linebuf usually ends with a newline. */
-        int n = strlen(report->linebuf);
-        fprintf(stderr, ":\n%s%s%s%s",
-                prefix,
-                report->linebuf,
-                (n > 0 && report->linebuf[n-1] == '\n') ? "" : "\n",
-                prefix);
-        n = report->tokenptr - report->linebuf;
-        for (int i = 0, j = 0; i < n; i++) {
-            if (report->linebuf[i] == '\t') {
-                for (int k = (j + 8) & ~7; j < k; j++) {
+    if (const char16_t* linebuf = report->linebuf()) {
+        size_t n = report->linebufLength();
+
+        fputs(":\n", stderr);
+        if (prefix)
+            fputs(prefix, stderr);
+
+        for (size_t i = 0; i < n; i++)
+            fputc(static_cast<char>(linebuf[i]), stderr);
+
+        // linebuf usually ends with a newline. If not, add one here.
+        if (n == 0 || linebuf[n - 1] != '\n')
+            fputc('\n', stderr);
+
+        if (prefix)
+            fputs(prefix, stderr);
+
+        n = report->tokenOffset();
+        for (size_t i = 0, j = 0; i < n; i++) {
+            if (linebuf[i] == '\t') {
+                for (size_t k = (j + 8) & ~7; j < k; j++)
                     fputc('.', stderr);
-                }
                 continue;
             }
             fputc('.', stderr);


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