[gjs/wip/js24] Port to JS::Evaluate, although this doesnt fix the failing UTF-8 tests



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

    Port to JS::Evaluate, although this doesnt fix the failing UTF-8 tests

 gjs/byteArray.cpp   |   10 +++++++---
 gjs/context.cpp     |   19 ++++++++++++-------
 gjs/importer.cpp    |   39 +++++++++++++++++++++++++--------------
 modules/console.cpp |    8 +++++---
 4 files changed, 49 insertions(+), 27 deletions(-)
---
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index 01e598a..ee08e0f 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 55a6eba..61556d3 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 422d9a8..d25b734 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -334,13 +334,18 @@ load_module_init(JSContext  *context,
 
     gjs_debug(GJS_DEBUG_IMPORTER, "Importing %s", full_path);
 
-    if (!JS_EvaluateScript(context,
-                           module_obj,
-                           script,
-                           script_len,
-                           full_path,
-                           1, /* line number */
-                           &script_retval)) {
+    JS::CompileOptions options(context);
+    options.setUTF8(true)
+           .setFileAndLine(full_path, 1)
+           .setPrincipals(NULL);
+    js::RootedObject rootedObj(context, module_obj);
+
+    if (!JS::Evaluate(context,
+                      rootedObj,
+                      options,
+                      script,
+                      script_len,
+                      &script_retval)) {
         g_free(script);
 
         /* If JSOPTION_DONT_REPORT_UNCAUGHT is set then the exception
@@ -416,6 +421,7 @@ import_file(JSContext  *context,
     GError *error;
     jsval script_retval;
     JSBool retval = JS_FALSE;
+    JS::CompileOptions options(context);
 
     gjs_debug(GJS_DEBUG_IMPORTER,
               "Importing '%s'", full_path);
@@ -424,6 +430,7 @@ import_file(JSContext  *context,
     if (module_obj == NULL) {
         return JS_FALSE;
     }
+    js::RootedObject rootedObj(context, module_obj);
 
     if (!define_import(context, obj, module_obj, name))
         return JS_FALSE;
@@ -447,13 +454,17 @@ import_file(JSContext  *context,
 
     g_assert(script != NULL);
 
-    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
diff --git a/modules/console.cpp b/modules/console.cpp
index 35add3f..0e3ca43 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]