[gjs/wip/js24: 26/29] Port to JS::Evaluate, this is required to enable UTF-8



commit 9abd918846a08055d36b06684acb70fb359f2324
Author: Tim Lunn <tim feathertop org>
Date:   Tue Oct 1 17:52:43 2013 +1000

    Port to JS::Evaluate, this is required to enable UTF-8

 gjs/byteArray.cpp   |   10 +++++++---
 gjs/context.cpp     |   19 ++++++++++++-------
 gjs/importer.cpp    |   21 ++++++++++++++-------
 modules/console.cpp |    8 +++++---
 4 files changed, 38 insertions(+), 20 deletions(-)
---
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index 57d27a5..4c5113b 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -771,9 +771,13 @@ byte_array_ensure_initialized (JSContext *context)
 
     if (g_once_init_enter (&initialized)) {
         jsval rval;
-        JS_EvaluateScript(context, JS_GetGlobalObject(context),
-                          "imports.byteArray.ByteArray;", 27,
-                          "<internal>", 1, &rval);
+        JS::CompileOptions options(context);
+        options.setUTF8(true)
+               .setFileAndLine("<internal>", 1);
+        js::RootedObject rootedObj(context, JS_GetGlobalObject(context));
+        JS::Evaluate(context, rootedObj, options,
+                     "imports.byteArray.ByteArray;", 27,
+                     &rval);
         g_once_init_leave (&initialized, 1);
     }
 }
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 08b5083..c971289 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -1009,13 +1009,18 @@ gjs_context_eval(GjsContext *js_context,
     if (script_len < 0)
         script_len = strlen(script);
     JSAutoCompartment ac(js_context->context, js_context->global);
-    if (!JS_EvaluateScript(js_context->context,
-                           js_context->global,
-                           script,
-                           script_len,
-                           filename,
-                           line_number,
-                           &retval)) {
+    JS::CompileOptions options(js_context->context);
+    options.setUTF8(true)
+           .setFileAndLine(filename, line_number)
+           .setPrincipals(NULL);
+    js::RootedObject rootedObj(js_context->context, js_context->global);
+
+    if (!JS::Evaluate(js_context->context,
+                      rootedObj,
+                      options,
+                      script,
+                      script_len,
+                      &retval)) {
         gjs_debug(GJS_DEBUG_CONTEXT,
                   "Script evaluation failed");
 
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 3941d18..2e7c11d 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -269,6 +269,9 @@ import_file(JSContext  *context,
     jsval script_retval;
     GError *error = NULL;
 
+    JS::CompileOptions options(context);
+    js::RootedObject rootedObj(context, module_obj);
+
     if (!(g_file_load_contents(file, NULL, &script, &script_len, NULL, &error))) {
         if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY) &&
             !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY) &&
@@ -284,13 +287,17 @@ import_file(JSContext  *context,
 
     full_path = g_file_get_parse_name (file);
 
-    if (!JS_EvaluateScript(context,
-                           module_obj,
-                           script,
-                           script_len,
-                           full_path,
-                           1, /* line number */
-                           &script_retval)) {
+    
+    options.setUTF8(true)
+           .setFileAndLine(full_path, 1);
+    
+    if (!JS::Evaluate(context,
+                      rootedObj,
+                      options,
+                      script,
+                      script_len,
+                      &script_retval)) {
+        g_free(script);
 
         /* If JSOPTION_DONT_REPORT_UNCAUGHT is set then the exception
          * would be left set after the evaluate and not go to the error
diff --git a/modules/console.cpp b/modules/console.cpp
index 549c492..fcbe1f0 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -191,9 +191,11 @@ gjs_console_interact(JSContext *context,
             g_free(temp_buf);
             lineno++;
         } while (!JS_BufferIsCompilableUnit(context, object, buffer->str, buffer->len));
-
-        JS_EvaluateScript(context, object, buffer->str, buffer->len, "typein",
-                          startline, &result);
+        JS::CompileOptions options(context);
+        options.setUTF8(true)
+               .setFileAndLine("typein", startline);
+        js::RootedObject rootedObj(context, object);
+        JS::Evaluate(context, rootedObj, options, buffer->str, buffer->len,  &result);
 
         if (JS_GetPendingException(context, &result)) {
             str = JS_ValueToString(context, result);


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