[gjs/wip/ptomato/mozjs45prep: 26/26] fixme stuff



commit 7248f0d14ebd90fbff804d050725d112ecd1ce56
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Mar 27 19:48:13 2017 +0100

    fixme stuff

 gjs/jsapi-util.cpp  |   24 +++++++++++++++++++-----
 modules/console.cpp |   38 +++++++++++++++++++++++++-------------
 2 files changed, 44 insertions(+), 18 deletions(-)
---
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index bb6fc9c..0cc2927 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -24,13 +24,14 @@
 
 #include <config.h>
 
+#include "jsapi-wrapper.h"
+#include <js/CharacterEncoding.h>
+
 #include <util/log.h>
 #include <util/glib.h>
 #include <util/misc.h>
 #include <util/error.h>
-
 #include "jsapi-util.h"
-#include "jsapi-wrapper.h"
 #include "context-private.h"
 #include "jsapi-private.h"
 #include <gi/boxed.h>
@@ -931,12 +932,25 @@ gjs_eval_with_scope(JSContext             *context,
         eval_obj = JS_NewPlainObject(context);
 
     JS::CompileOptions options(context);
-    options.setUTF8(true)
-           .setFileAndLine(filename, start_line_number)
+    options.setFileAndLine(filename, start_line_number)
            .setSourceIsLazy(true);
 
-    if (!JS::Evaluate(context, eval_obj, options, script, real_len, retval))
+    JS::AutoObjectVector scope_chain(context);
+    scope_chain.append(eval_obj);
+
+    /* FIXME can we really do this? UTF8CharsToNewTwoByteCharsZ is not marked
+     * as public API, maybe that's a mistake, but requires a distro patch */
+    char16_t *uscript =
+        JS::UTF8CharsToNewTwoByteCharsZ(context, JS::UTF8Chars(script, real_len),
+                                        &real_len).get();
+    if (!uscript)
+        return false;
+
+    if (!JS::Evaluate(context, scope_chain, options, uscript, real_len, retval)) {
+        free(uscript);
         return false;
+    }
+    free(uscript);
 
     gjs_schedule_gc_if_needed(context);
 
diff --git a/modules/console.cpp b/modules/console.cpp
index 50c6212..eba911a 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -40,6 +40,7 @@
 
 #include "config.h"
 
+#include <iostream>
 #include <stdlib.h>
 #include <string.h>
 
@@ -52,10 +53,12 @@
 #include <glib.h>
 #include <glib/gprintf.h>
 
+#include "gjs/jsapi-wrapper.h"
+#include <js/CharacterEncoding.h>
+
 #include "console.h"
 #include "gjs/context.h"
 #include "gjs/jsapi-private.h"
-#include "gjs/jsapi-wrapper.h"
 
 static void
 gjs_console_error_reporter(JSContext *cx, const char *message, JSErrorReport *report)
@@ -99,21 +102,20 @@ gjs_console_error_reporter(JSContext *cx, const char *message, JSErrorReport *re
         fputs(prefix, stderr);
     fputs(message, stderr);
 
-    if (!report->linebuf) {
+    if (!report->linebuf()) {
         fputc('\n', stderr);
         goto out;
     }
 
+    // FIXME THIS
     /* report->linebuf usually ends with a newline. */
-    n = strlen(report->linebuf);
-    fprintf(stderr, ":\n%s%s%s%s",
-            prefix,
-            report->linebuf,
-            (n > 0 && report->linebuf[n-1] == '\n') ? "" : "\n",
-            prefix);
-    n = ((char*)report->tokenptr) - ((char*) report->linebuf);
+    n = std::char_traits<char16_t>::length(report->linebuf());
+    std::cerr << ":\n" << prefix << report->linebuf()
+        << ((n > 0 && report->linebuf()[n-1] == '\n') ? "" : "\n")
+        << prefix;
+    n = report->tokenOffset();
     for (i = j = 0; i < n; i++) {
-        if (report->linebuf[i] == '\t') {
+        if (report->linebuf()[i] == '\t') {
             for (k = (j + 8) & ~7; j < k; j++) {
                 fputc('.', stderr);
             }
@@ -194,10 +196,19 @@ gjs_console_interact(JSContext *context,
         } while (!JS_BufferIsCompilableUnit(context, object, buffer->str, buffer->len));
 
         JS::CompileOptions options(context);
-        options.setUTF8(true)
-               .setFileAndLine("typein", startline);
-        if (!JS::Evaluate(context, object, options, buffer->str, buffer->len,
+        options.setFileAndLine("typein", startline);
+
+        JS::AutoObjectVector scope_chain(context);
+        scope_chain.append(object);
+
+        size_t script_len;
+        /* FIXME can we really do this? UTF8CharsToNewTwoByteCharsZ is not marked
+         * as public API, maybe that's a mistake, but requires a distro patch */
+        char16_t *uscript = JS::UTF8CharsToNewTwoByteCharsZ(context,
+            JS::UTF8Chars(buffer->str, buffer->len), &script_len).get();
+        if (!JS::Evaluate(context, scope_chain, options, uscript, script_len,
                           &result)) {
+            free(uscript);
             /* If this was an uncatchable exception, throw another uncatchable
              * exception on up to the surrounding JS::Evaluate() in main(). This
              * happens when you run gjs-console and type imports.system.exit(0);
@@ -208,6 +219,7 @@ gjs_console_interact(JSContext *context,
                 return false;
             }
         }
+        free(uscript);
 
         gjs_schedule_gc_if_needed(context);
 


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