gjs r99 - in trunk: gi gjs test/js
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: gjs r99 - in trunk: gi gjs test/js
- Date: Wed, 12 Nov 2008 21:20:24 +0000 (UTC)
Author: johan
Date: Wed Nov 12 21:20:23 2008
New Revision: 99
URL: http://svn.gnome.org/viewvc/gjs?rev=99&view=rev
Log:
Add support for GI_TYPE_TAG_FILENAME, convert the the string daa using g_filename_to/from_utf8.
Modified:
trunk/gi/arg.c
trunk/gjs/jsapi-util-string.c
trunk/gjs/jsapi-util.h
trunk/test/js/testEverythingBasic.js
Modified: trunk/gi/arg.c
==============================================================================
--- trunk/gi/arg.c (original)
+++ trunk/gi/arg.c Wed Nov 12 21:20:23 2008
@@ -371,6 +371,18 @@
wrong = TRUE;
break;
+ case GI_TYPE_TAG_FILENAME:
+ nullable_type = TRUE;
+ if (JSVAL_IS_NULL(value)) {
+ arg->v_pointer = NULL;
+ } else if (JSVAL_IS_STRING(value)) {
+ if (!gjs_string_to_filename(context, value, (char **)&arg->v_pointer))
+ wrong = TRUE;
+ } else {
+ wrong = TRUE;
+ report_type_mismatch = TRUE;
+ }
+ break;
case GI_TYPE_TAG_UTF8:
nullable_type = TRUE;
if (JSVAL_IS_NULL(value)) {
@@ -785,6 +797,15 @@
case GI_TYPE_TAG_DOUBLE:
return JS_NewDoubleValue(context, arg->v_double, value_p);
+ case GI_TYPE_TAG_FILENAME:
+ if (arg->v_pointer)
+ return gjs_string_from_filename(context, arg->v_pointer, -1, value_p);
+ else {
+ /* For NULL we'll return JSVAL_NULL, which is already set
+ * in *value_p
+ */
+ return JS_TRUE;
+ }
case GI_TYPE_TAG_UTF8:
if (arg->v_pointer)
return gjs_string_from_utf8(context, arg->v_pointer, -1, value_p);
@@ -941,6 +962,7 @@
case GI_TYPE_TAG_SIZE:
break;
+ case GI_TYPE_TAG_FILENAME:
case GI_TYPE_TAG_UTF8:
g_free(arg->v_pointer);
break;
@@ -1023,7 +1045,8 @@
param_info = g_type_info_get_param_type(type_info, 0);
- if (g_type_info_get_tag (param_info) == GI_TYPE_TAG_UTF8)
+ if (g_type_info_get_tag (param_info) == GI_TYPE_TAG_UTF8 ||
+ g_type_info_get_tag (param_info) == GI_TYPE_TAG_FILENAME)
g_strfreev (arg->v_pointer);
else
g_assert_not_reached ();
@@ -1116,6 +1139,7 @@
switch (type_tag) {
case GI_TYPE_TAG_UTF8:
+ case GI_TYPE_TAG_FILENAME:
case GI_TYPE_TAG_ARRAY:
return gjs_g_arg_release_internal(context, GI_TRANSFER_EVERYTHING,
type_info, type_tag, arg);
Modified: trunk/gjs/jsapi-util-string.c
==============================================================================
--- trunk/gjs/jsapi-util-string.c (original)
+++ trunk/gjs/jsapi-util-string.c Wed Nov 12 21:20:23 2008
@@ -61,14 +61,13 @@
*utf8_string_p = utf8_string;
return JS_TRUE;
-
}
JSBool
-gjs_string_from_utf8(JSContext *context,
+gjs_string_from_utf8(JSContext *context,
const char *utf8_string,
- gsize n_bytes,
- jsval *value_p)
+ gsize n_bytes,
+ jsval *value_p)
{
jschar *u16_string;
glong u16_string_length;
@@ -107,6 +106,71 @@
return JS_TRUE;
}
+JSBool
+gjs_string_to_filename(JSContext *context,
+ const jsval filename_val,
+ char **filename_string_p)
+{
+ GError *error;
+ gchar *tmp, *filename_string;
+
+ /* gjs_string_to_filename verifies that filename_val is a string */
+
+ if (!gjs_string_to_utf8(context, filename_val, &tmp)) {
+ /* exception already set */
+ return JS_FALSE;
+ }
+
+ error = NULL;
+ filename_string = g_filename_to_utf8(tmp, -1, NULL, NULL, &error);
+ if (error) {
+ gjs_throw(context,
+ "Could not convert filename '%s' to UTF8: '%s'",
+ tmp,
+ error->message);
+ g_error_free(error);
+ g_free(tmp);
+ return JS_FALSE;
+ }
+
+ *filename_string_p = filename_string;
+
+ g_free(tmp);
+ return JS_TRUE;
+}
+
+JSBool
+gjs_string_from_filename(JSContext *context,
+ const char *filename_string,
+ gsize n_bytes,
+ jsval *value_p)
+{
+ gssize written;
+ GError *error;
+ gchar *utf8_string;
+
+ error = NULL;
+ utf8_string = g_filename_from_utf8(filename_string, n_bytes, NULL,
+ &written, &error);
+ if (error) {
+ gjs_throw(context,
+ "Could not convert UTF-8 string '%s' to a filename: '%s'",
+ filename_string,
+ error->message);
+ g_error_free(error);
+ g_free(utf8_string);
+ return JS_FALSE;
+ }
+
+ if (!gjs_string_from_utf8(context, utf8_string, written, value_p))
+ return JS_FALSE;
+
+ g_free(utf8_string);
+
+ return JS_TRUE;
+}
+
+
/**
* gjs_string_get_ascii:
* @value: a jsval
Modified: trunk/gjs/jsapi-util.h
==============================================================================
--- trunk/gjs/jsapi-util.h (original)
+++ trunk/gjs/jsapi-util.h Wed Nov 12 21:20:23 2008
@@ -197,6 +197,13 @@
const char *utf8_string,
gsize n_bytes,
jsval *value_p);
+JSBool gjs_string_to_filename (JSContext *context,
+ const jsval string_val,
+ char **filename_string_p);
+JSBool gjs_string_from_filename (JSContext *context,
+ const char *filename_string,
+ gsize n_bytes,
+ jsval *value_p);
const char* gjs_string_get_ascii (jsval value);
const char* gjs_string_get_ascii_checked (JSContext *context,
jsval value);
Modified: trunk/test/js/testEverythingBasic.js
==============================================================================
--- trunk/test/js/testEverythingBasic.js (original)
+++ trunk/test/js/testEverythingBasic.js Wed Nov 12 21:20:23 2008
@@ -86,4 +86,18 @@
assertRaises(function() { Everything.test_strv_in(['1', 2, 3]); });
}
+function testFilenameReturn() {
+ var filenames = Everything.test_filename_return();
+ assertEquals(2, filenames.length);
+ assertEquals('\u00e5\u00e4\u00f6', filenames[0]);
+ assertEquals('/etc/fstab', filenames[1]);
+}
+
+function testFilename() {
+ var filenames = Everything.test_filename_return();
+ assertEquals(2, filenames.length);
+ assertEquals('\u00e5\u00e4\u00f6', filenames[0]);
+ assertEquals('/etc/fstab', filenames[1]);
+}
+
gjstestRun();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]