[gjs/halfline/debug-metrics: 1/4] Revert "js: Convert scripts to UTF-16 before evaluating"




commit 942674f07b5e761b4f4e42758938c1675fe3587d
Author: Kalev Lember <klember redhat com>
Date:   Tue May 15 21:14:16 2018 +0200

    Revert "js: Convert scripts to UTF-16 before evaluating"
    
    RHEL 7 libstdc++ 4.8 doesn't have <codecvt> header that gjs needs. In
    order to work this around, this commit reverts the patch that introduced
    the requirement.
    
    This reverts commit bc36f39ff09629e1b4c5c54f334028d2b2f8c545.

 gjs/jsapi-util.cpp | 14 ++++++--------
 gjs/module.cpp     | 15 ++++++---------
 2 files changed, 12 insertions(+), 17 deletions(-)
---
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index ed3e6492..8b686048 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -24,8 +24,6 @@
 
 #include <config.h>
 
-#include <codecvt>
-#include <locale>
 #include "jsapi-wrapper.h"
 #include <js/GCAPI.h>
 
@@ -853,19 +851,19 @@ gjs_eval_with_scope(JSContext             *context,
         eval_obj = JS_NewPlainObject(context);
 
     JS::CompileOptions options(context);
-    options.setFileAndLine(filename, start_line_number)
+    options.setUTF8(true)
+           .setFileAndLine(filename, start_line_number)
            .setSourceIsLazy(true);
 
-    std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
-    std::u16string utf16_string = convert.from_bytes(script);
-    JS::SourceBufferHolder buf(utf16_string.c_str(), utf16_string.size(),
-                               JS::SourceBufferHolder::NoOwnership);
+    JS::RootedScript compiled_script(context);
+    if (!JS::Compile(context, options, script, real_len, &compiled_script))
+        return false;
 
     JS::AutoObjectVector scope_chain(context);
     if (!scope_chain.append(eval_obj))
         g_error("Unable to append to vector");
 
-    if (!JS::Evaluate(context, scope_chain, options, buf, retval))
+    if (!JS_ExecuteScript(context, scope_chain, compiled_script, retval))
         return false;
 
     gjs_schedule_gc_if_needed(context);
diff --git a/gjs/module.cpp b/gjs/module.cpp
index cc6657a7..4b8bd40c 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -21,9 +21,6 @@
  * IN THE SOFTWARE.
  */
 
-#include <codecvt>
-#include <locale>
-
 #include <gio/gio.h>
 
 #include "jsapi-util.h"
@@ -89,20 +86,20 @@ class GjsModule {
                     int              line_number)
     {
         JS::CompileOptions options(cx);
-        options.setFileAndLine(filename, line_number)
+        options.setUTF8(true)
+               .setFileAndLine(filename, line_number)
                .setSourceIsLazy(true);
 
-        std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
-        std::u16string utf16_string = convert.from_bytes(script);
-        JS::SourceBufferHolder buf(utf16_string.c_str(), utf16_string.size(),
-                                   JS::SourceBufferHolder::NoOwnership);
+        JS::RootedScript compiled_script(cx);
+        if (!JS::Compile(cx, options, script, script_len, &compiled_script))
+            return false;
 
         JS::AutoObjectVector scope_chain(cx);
         if (!scope_chain.append(module))
             g_error("Unable to append to vector");
 
         JS::RootedValue ignored_retval(cx);
-        if (!JS::Evaluate(cx, scope_chain, options, buf, &ignored_retval))
+        if (!JS_ExecuteScript(cx, scope_chain, compiled_script, &ignored_retval))
             return false;
 
         gjs_schedule_gc_if_needed(cx);


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