[seed] https://bugzilla.gnome.org/show_bug.cgi?id=657647



commit bc3c00ee0b18d6fd13ee8d9766d53e443e57bf6c
Author: Alexandre Mazari <amazari igalia com>
Date:   Wed Aug 31 16:51:57 2011 +0800

    https://bugzilla.gnome.org/show_bug.cgi?id=657647

 libseed/seed-types.c |   38 ++++++++++++++++++++++++++++++++++++++
 libseed/seed-types.h |    3 ++-
 2 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index 96e62d1..a42d4db 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -1081,6 +1081,12 @@ seed_value_from_gvalue (JSContextRef ctx,
       return seed_make_pointer (ctx, g_value_get_param (gval));
     }
 
+  if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_STRV))
+    {
+      return seed_value_from_strv(ctx, g_value_get_boxed (gval), exception);
+    }
+
+
   if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_ENUM) ||
       g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_FLAGS))
     return seed_value_from_long (ctx, gval->data[0].v_long, exception);
@@ -2503,3 +2509,35 @@ out:
 		       "Unable to convert JavaScript value to time_t");
   return 0;
 }
+
+/**
+ * seed_value_from_strv:
+ * @ctx: A #SeedContext.
+ * @val: The #GStrv to wrap.
+ * @exception: A reference to a #SeedValue in which to store any exceptions.
+ *             Pass %NULL to ignore exceptions.
+ *
+ * Wraps @val in a #SeedValue.
+ *
+ * Return value: A #SeedValue which wraps @val, or %NULL if an exception
+ *               is raised during the conversion.
+ *
+ */
+JSValueRef
+seed_value_from_strv (JSContextRef ctx,
+		      GStrv * val, JSValueRef * exception)
+{
+      GArray *js_string_array = g_array_new (FALSE, FALSE, sizeof(gpointer));
+      for (; *val != NULL; val++)
+	{
+	  JSStringRef js_string = JSStringCreateWithUTF8CString((char*)*val);
+	  js_string_array = g_array_append_val(js_string_array, js_string);
+	}
+      JSValueRef res = JSObjectMakeArray (ctx,
+					  js_string_array->len,
+					  (JSValueRef*)js_string_array->data,
+					  exception);
+      g_array_free (js_string_array, FALSE);
+
+      return res;
+}
diff --git a/libseed/seed-types.h b/libseed/seed-types.h
index e66eed6..322a10a 100644
--- a/libseed/seed-types.h
+++ b/libseed/seed-types.h
@@ -143,7 +143,8 @@ GObject *seed_value_to_object (JSContextRef ctx,
 			       JSValueRef val, JSValueRef * exception);
 JSValueRef seed_value_from_object (JSContextRef ctx,
 				   GObject * val, JSValueRef * exception);
-
+JSValueRef seed_value_from_strv (JSContextRef ctx,
+				 GStrv * val, JSValueRef * exception);
 void seed_toggle_ref (gpointer data, GObject * object, gboolean is_last_ref);
 
 gboolean seed_validate_enum (GIEnumInfo * info, long val);



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