[gjs] Adapt to JS_GetStringChars removal in xulrunner 2



commit 4633da894ae6525425b6157eecec7503c6ffad22
Author: Sardem FF7 <sardemff7 pub gmail com>
Date:   Wed Jan 5 10:57:33 2011 +0100

    Adapt to JS_GetStringChars removal in xulrunner 2
    
    https://bugzilla.gnome.org/show_bug.cgi?id=638731

 configure.ac            |    1 +
 gjs/byteArray.c         |    8 +++++++-
 gjs/jsapi-util-string.c |   26 +++++++++++++++++++++-----
 3 files changed, 29 insertions(+), 6 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a6f978e..04fa332 100644
--- a/configure.ac
+++ b/configure.ac
@@ -148,6 +148,7 @@ fi
 
 AC_CHECK_LIB([mozjs], [JS_GetStringBytes], AC_DEFINE([HAVE_JS_GETSTRINGBYTES], [1], [Define if we still have JS_GetStringBytes]),, [$JS_LIBS])
 AC_CHECK_LIB([mozjs], [JS_GetFunctionName], AC_DEFINE([HAVE_JS_GETFUNCTIONNAME], [1], [Define if we still have JS_GetFunctionName]),, [$JS_LIBS])
+AC_CHECK_LIB([mozjs], [JS_GetStringCharsAndLength], AC_DEFINE([HAVE_JS_GETSTRINGCHARSANDLENGTH], [1], [Define if we have JS_GetStringCharsAndLength]),, [$JS_LIBS])
 
 AC_MSG_CHECKING([for mozilla-js >= 2 ])
 if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 2`; then
diff --git a/gjs/byteArray.c b/gjs/byteArray.c
index ea09cc4..d88c029 100644
--- a/gjs/byteArray.c
+++ b/gjs/byteArray.c
@@ -675,11 +675,17 @@ from_string_func(JSContext *context,
         char *encoded;
         gsize bytes_written;
         GError *error;
-        jschar *u16_chars;
+        const jschar *u16_chars;
         gsize u16_len;
 
+#ifdef HAVE_JS_GETSTRINGCHARSANDLENGTH
+        u16_chars = JS_GetStringCharsAndLength(context, JSVAL_TO_STRING(argv[0]), &u16_len);
+        if (u16_chars == NULL)
+            goto out;
+#else
         u16_chars = JS_GetStringChars(JSVAL_TO_STRING(argv[0]));
         u16_len = JS_GetStringLength(JSVAL_TO_STRING(argv[0]));
+#endif
 
         error = NULL;
         encoded = g_convert((char*) u16_chars,
diff --git a/gjs/jsapi-util-string.c b/gjs/jsapi-util-string.c
index c1af3bc..0266baa 100644
--- a/gjs/jsapi-util-string.c
+++ b/gjs/jsapi-util-string.c
@@ -34,7 +34,7 @@ gjs_try_string_to_utf8 (JSContext  *context,
                         char      **utf8_string_p,
                         GError    **error)
 {
-    jschar *s;
+    const jschar *s;
     size_t s_length;
     char *utf8_string;
     long read_items;
@@ -50,8 +50,16 @@ gjs_try_string_to_utf8 (JSContext  *context,
         return FALSE;
     }
 
+#ifdef HAVE_JS_GETSTRINGCHARSANDLENGTH
+    s = JS_GetStringCharsAndLength(context, JSVAL_TO_STRING(string_val), &s_length);
+    if (s == NULL) {
+        JS_EndRequest(context);
+        return FALSE;
+    }
+#else
     s = JS_GetStringChars(JSVAL_TO_STRING(string_val));
     s_length = JS_GetStringLength(JSVAL_TO_STRING(string_val));
+#endif
 
     utf8_string = g_utf16_to_utf8(s,
                                   (glong)s_length,
@@ -410,23 +418,31 @@ gjs_string_get_uint16_data(JSContext       *context,
                            guint16        **data_p,
                            gsize           *len_p)
 {
-    jschar *js_data;
+    const jschar *js_data;
+    JSBool retval = JS_FALSE;
 
     JS_BeginRequest(context);
 
     if (!JSVAL_IS_STRING(value)) {
         gjs_throw(context,
                   "Value is not a string, can't return binary data from it");
-        JS_EndRequest(context);
-        return JS_FALSE;
+        goto out;
     }
 
+#ifdef HAVE_JS_GETSTRINGCHARSANDLENGTH
+    js_data = JS_GetStringCharsAndLength(context, JSVAL_TO_STRING(value), len_p);
+    if (js_data == NULL)
+        goto out;
+#else
     js_data = JS_GetStringChars(JSVAL_TO_STRING(value));
     *len_p = JS_GetStringLength(JSVAL_TO_STRING(value));
+#endif
     *data_p = g_memdup(js_data, sizeof(*js_data)*(*len_p));
 
+    retval = JS_TRUE;
+out:
     JS_EndRequest(context);
-    return JS_TRUE;
+    return retval;
 }
 
 /**



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