[gjs] Remove all calls to g_utf8_to_utf16



commit 27389b79f2853c07c26f68fd50847684d7e6c3c3
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Fri Dec 28 00:09:38 2012 +0100

    Remove all calls to g_utf8_to_utf16
    
    Lets have just one place where we do unicode conversion, and make that
    the one in Spidermonkey.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680730

 gjs/context.c     |   26 ++++++++-------------
 gjs/importer.c    |   62 +++++++++++++++++-----------------------------------
 modules/console.c |   21 +----------------
 3 files changed, 32 insertions(+), 77 deletions(-)
---
diff --git a/gjs/context.c b/gjs/context.c
index afe1470..5f568ce 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -979,8 +979,6 @@ gjs_context_eval(GjsContext *js_context,
     int line_number;
     jsval retval;
     gboolean success;
-    gunichar2 *u16_script;
-    glong u16_script_len;
 
     g_object_ref(G_OBJECT(js_context));
 
@@ -1006,13 +1004,8 @@ gjs_context_eval(GjsContext *js_context,
         }
     }
 
-    if ((u16_script = g_utf8_to_utf16 (script, script_len, NULL, &u16_script_len, error)) == NULL)
-        return FALSE;
-    g_assert (u16_script_len < G_MAXUINT);
-
     /* log and clear exception if it's set (should not be, normally...) */
-    if (gjs_log_exception(js_context->context,
-                             NULL)) {
+    if (gjs_log_exception(js_context->context, NULL)) {
         gjs_debug(GJS_DEBUG_CONTEXT,
                   "Exception was set prior to JS_EvaluateScript()");
     }
@@ -1024,13 +1017,15 @@ gjs_context_eval(GjsContext *js_context,
     JS_BeginRequest(js_context->context);
 
     retval = JSVAL_VOID;
-    if (!JS_EvaluateUCScript(js_context->context,
-                             js_context->global,
-                             (const jschar*)u16_script,
-                             (guint) u16_script_len,
-                             filename,
-                             line_number,
-                             &retval)) {
+    if (script_len < 0)
+        script_len = strlen(script);
+    if (!JS_EvaluateScript(js_context->context,
+                           js_context->global,
+                           script,
+                           script_len,
+                           filename,
+                           line_number,
+                           &retval)) {
         char *message;
 
         gjs_debug(GJS_DEBUG_CONTEXT,
@@ -1057,7 +1052,6 @@ gjs_context_eval(GjsContext *js_context,
 
         success = FALSE;
     }
-    g_free (u16_script);
 
     gjs_debug(GJS_DEBUG_CONTEXT,
               "Script evaluation succeeded");
diff --git a/gjs/importer.c b/gjs/importer.c
index a4c242f..f3d42b8 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -275,35 +275,13 @@ import_native_file(JSContext  *context,
     return retval;
 }
 
-static jschar *
-file_get_utf16_contents (const char  *filename,
-                         glong       *length,
-                         GError     **error)
-{
-    jschar *result;
-    gchar *contents;
-    gsize utf8_length;
-
-    if (!g_file_get_contents (filename, &contents,
-                              &utf8_length, error))
-        return NULL;
-
-    /* No cast here, so we get a warning in the
-       (impossible?) case that gunichar2 is different
-       from jschar */
-    result = g_utf8_to_utf16 (contents, utf8_length,
-                              NULL, length, error);
-
-    g_free (contents);
-    return result;
-}
 static JSObject *
 load_module_init(JSContext  *context,
                  JSObject   *in_object,
                  const char *full_path)
 {
-    jschar *script;
-    glong script_len;
+    char *script;
+    gsize script_len;
     jsval script_retval;
     JSObject *module_obj;
     GError *error;
@@ -340,7 +318,7 @@ load_module_init(JSContext  *context,
     script_len = 0;
     error = NULL;
 
-    if (!(script = file_get_utf16_contents(full_path, &script_len, &error))) {
+    if (!g_file_get_contents(full_path, &script, &script_len, &error)) {
         if (!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_ISDIR) &&
             !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR) &&
             !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
@@ -355,13 +333,13 @@ load_module_init(JSContext  *context,
 
     gjs_debug(GJS_DEBUG_IMPORTER, "Importing %s", full_path);
 
-    if (!JS_EvaluateUCScript(context,
-                             module_obj,
-                             script,
-                             script_len,
-                             full_path,
-                             1, /* line number */
-                             &script_retval)) {
+    if (!JS_EvaluateScript(context,
+                           module_obj,
+                           script,
+                           script_len,
+                           full_path,
+                           1, /* line number */
+                           &script_retval)) {
         g_free(script);
 
         /* If JSOPTION_DONT_REPORT_UNCAUGHT is set then the exception
@@ -431,8 +409,8 @@ import_file(JSContext  *context,
             const char *name,
             const char *full_path)
 {
-    jschar *script;
-    glong script_len;
+    char *script;
+    gsize script_len;
     JSObject *module_obj;
     GError *error;
     jsval script_retval;
@@ -455,7 +433,7 @@ import_file(JSContext  *context,
     script_len = 0;
     error = NULL;
 
-    if (!(script = file_get_utf16_contents(full_path, &script_len, &error))) {
+    if (!(g_file_get_contents(full_path, &script, &script_len, &error))) {
         if (!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_ISDIR) &&
             !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR) &&
             !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
@@ -468,13 +446,13 @@ import_file(JSContext  *context,
 
     g_assert(script != NULL);
 
-    if (!JS_EvaluateUCScript(context,
-                             module_obj,
-                             script,
-                             script_len,
-                             full_path,
-                             1, /* line number */
-                             &script_retval)) {
+    if (!JS_EvaluateScript(context,
+                           module_obj,
+                           script,
+                           script_len,
+                           full_path,
+                           1, /* line number */
+                           &script_retval)) {
         g_free(script);
 
         /* If JSOPTION_DONT_REPORT_UNCAUGHT is set then the exception
diff --git a/modules/console.c b/modules/console.c
index a66077f..71a95b4 100644
--- a/modules/console.c
+++ b/modules/console.c
@@ -160,16 +160,12 @@ gjs_console_interact(JSContext *context,
 {
     JSObject *object = JS_THIS_OBJECT(context, vp);
     gboolean eof = FALSE;
-    JSObject *script = NULL;
     jsval result;
     JSString *str;
     GString *buffer = NULL;
     char *temp_buf = NULL;
-    gunichar2 *u16_buffer;
-    glong u16_buffer_len;
     int lineno;
     int startline;
-    GError *error = NULL;
     FILE *file = stdin;
 
     JS_SetErrorReporter(context, gjs_console_error_reporter);
@@ -194,23 +190,10 @@ gjs_console_interact(JSContext *context,
             g_string_append(buffer, temp_buf);
             g_free(temp_buf);
             lineno++;
-        /* Note in this case, we are trying to parse the buffer as
-         * ISO-8859-1 which is broken for non-ASCII.
-         */
         } while (!JS_BufferIsCompilableUnit(context, object, buffer->str, buffer->len));
 
-        if ((u16_buffer = g_utf8_to_utf16 (buffer->str, buffer->len, NULL, &u16_buffer_len, &error)) == NULL) {
-            g_printerr ("%s\n", error->message);
-            g_clear_error (&error);
-            continue;
-        }
-
-        script = JS_CompileUCScript(context, object, u16_buffer, u16_buffer_len, "typein",
-                                    startline);
-        g_free (u16_buffer);
-
-        if (script)
-            JS_ExecuteScript(context, object, script, &result);
+        JS_EvaluateScript(context, object, buffer->str, buffer->len, "typein",
+                          startline, &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]