[gjs/wip/ptomato/mozjs45prep: 18/18] js: stuff FIXME



commit 035559a37de08b32363b367815f5fd8723241c0c
Author: Philip Chimento <philip endlessm com>
Date:   Sun Mar 19 08:02:58 2017 +0000

    js: stuff FIXME

 gjs/jsapi-util.cpp  |   15 ++++++++++++++-
 modules/console.cpp |   21 +++++++++++----------
 2 files changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 42f12fe..a8743e7 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -931,7 +931,20 @@ gjs_eval_with_scope(JSContext             *context,
            .setFileAndLine(filename, start_line_number)
            .setSourceIsLazy(true);
 
-    if (!JS::Evaluate(context, eval_obj, options, script, script_len, retval))
+    JS::AutoObjectVector scope_chain(context);
+    scope_chain.append(eval_obj);
+
+    // FIXME don't do this!!
+    GError *error = NULL;
+    gunichar2 *uscript = g_utf8_to_utf16(script, script_len, nullptr, nullptr, &error);
+    if (!uscript) {
+        gjs_throw(context, "Failed to convert script to UTF-16 for evaluation: %s",
+                  error->message);
+        return false;
+    }
+
+    if (!JS::Evaluate(context, scope_chain, options,
+                      reinterpret_cast<char16_t *>(uscript), script_len, retval))
         return false;
 
     gjs_schedule_gc_if_needed(context);
diff --git a/modules/console.cpp b/modules/console.cpp
index 60f095b..9bc81a2 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -40,6 +40,7 @@
 
 #include "config.h"
 
+#include <iostream>
 #include <stdlib.h>
 #include <string.h>
 
@@ -99,21 +100,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);
             }
@@ -196,7 +196,8 @@ gjs_console_interact(JSContext *context,
         JS::CompileOptions options(context);
         options.setUTF8(true)
                .setFileAndLine("typein", startline);
-        if (!JS::Evaluate(context, object, options, buffer->str, buffer->len,
+        // FIXME put object back in the scope chain and switch to char16_t buffer
+        if (!JS::Evaluate(context, options, buffer->str, buffer->len,
                           &result)) {
             /* If this was an uncatchable exception, throw another uncatchable
              * exception on up to the surrounding JS::Evaluate() in main(). This


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