summaryrefslogtreecommitdiff
path: root/libseed/seed-types.c
diff options
context:
space:
mode:
Diffstat (limited to 'libseed/seed-types.c')
-rw-r--r--libseed/seed-types.c472
1 files changed, 365 insertions, 107 deletions
diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index a42d4db..5f17d9b 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -163,6 +163,27 @@ seed_release_arg (GITransfer transfer,
g_base_info_unref ((GIBaseInfo *) param_type);
}
break;
+ case GI_TYPE_TAG_GHASH:
+ {
+ GITypeInfo *val_param_info;
+ GHashTableIter iter;
+ GArgument value;
+
+ val_param_info = g_type_info_get_param_type (type_info, 1);
+ g_assert(val_param_info != NULL);
+
+ /* release the hashtable's values */
+ g_hash_table_iter_init (&iter, arg->v_pointer);
+ while (g_hash_table_iter_next (&iter, NULL, &value.v_pointer))
+ {
+ seed_release_arg (GI_TRANSFER_EVERYTHING, val_param_info,
+ g_type_info_get_tag (val_param_info), &value);
+ }
+
+ /* release the hashtable's keys and the hashtable itself */
+ g_hash_table_destroy (arg->v_pointer);
+ break;
+ }
case GI_TYPE_TAG_INTERFACE:
{
if (arg->v_pointer)
@@ -253,6 +274,7 @@ seed_gi_release_in_arg (GITransfer transfer,
case GI_TYPE_TAG_UTF8:
case GI_TYPE_TAG_FILENAME:
case GI_TYPE_TAG_ARRAY:
+ case GI_TYPE_TAG_GHASH:
return seed_release_arg (GI_TRANSFER_EVERYTHING,
type_info, type_tag, arg);
default:
@@ -638,7 +660,8 @@ seed_value_to_gi_argument (JSContextRef ctx,
else if (interface_type == GI_INFO_TYPE_ENUM ||
interface_type == GI_INFO_TYPE_FLAGS)
{
- arg->v_long = seed_value_to_long (ctx, value, exception);
+ // this might need fixing...
+ arg->v_long = seed_value_to_long (ctx, value, exception);
if (!(interface_type == GI_INFO_TYPE_FLAGS)
&& !seed_validate_enum ((GIEnumInfo *) interface,
arg->v_long))
@@ -808,6 +831,82 @@ seed_value_to_gi_argument (JSContextRef ctx,
break;
}
}
+ case GI_TYPE_TAG_GHASH:
+ {
+ GITypeInfo *key_param_info, *val_param_info;
+ GHashTable *hash_table;
+
+ JSPropertyNameArrayRef jsprops = 0;
+ JSStringRef jsprop_name;
+ JSValueRef jsprop_value;
+ int i, nparams = 0;
+
+ if (!JSValueIsObject (ctx, value))
+ {
+ return FALSE;
+ }
+
+ if (JSValueIsNull (ctx, value))
+ {
+ arg->v_pointer = NULL;
+ break;
+ }
+
+ key_param_info = g_type_info_get_param_type (type_info, 0);
+ g_assert(key_param_info != NULL);
+ if (g_type_info_get_tag (key_param_info) != GI_TYPE_TAG_UTF8)
+ {
+ /* Functions requesting a hash table with non-string keys are
+ * not supported */
+ return FALSE;
+ }
+
+ val_param_info = g_type_info_get_param_type (type_info, 1);
+ g_assert(val_param_info != NULL);
+
+ jsprops = JSObjectCopyPropertyNames (ctx, (JSObjectRef) value);
+ nparams = JSPropertyNameArrayGetCount (jsprops);
+
+ /* keys are strings and the destructor is g_free
+ * values will be freed in seed_release_arg
+ */
+ hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ for (i = 0; i < nparams; i++)
+ {
+ char *prop_name;
+ int length;
+ GArgument hash_arg;
+
+ jsprop_name = JSPropertyNameArrayGetNameAtIndex (jsprops, i);
+
+ length = JSStringGetMaximumUTF8CStringSize (jsprop_name);
+ prop_name = g_malloc (length * sizeof (gchar));
+ JSStringGetUTF8CString (jsprop_name, prop_name, length);
+
+ jsprop_value = JSObjectGetProperty (ctx,
+ (JSObjectRef) value,
+ jsprop_name, NULL);
+
+ if (!seed_value_to_gi_argument (ctx, jsprop_value,
+ val_param_info,
+ &hash_arg,
+ exception))
+ {
+ g_hash_table_destroy (hash_table);
+ g_base_info_unref ((GIBaseInfo *) val_param_info);
+ return FALSE;
+ }
+
+ g_hash_table_insert (hash_table,
+ prop_name,
+ hash_arg.v_pointer);
+ }
+
+ arg->v_pointer = hash_table;
+
+ break;
+ }
default:
return FALSE;
@@ -818,10 +917,36 @@ seed_value_to_gi_argument (JSContextRef ctx,
JSValueRef
seed_value_from_gi_argument (JSContextRef ctx,
- GArgument * arg, GITypeInfo * type_info,
+ GArgument * arg,
+ GITypeInfo * type_info,
JSValueRef * exception)
{
- GITypeTag gi_tag = g_type_info_get_tag (type_info);
+
+ return seed_value_from_gi_argument_full (
+ ctx,
+ arg,
+ type_info,
+ exception,
+ 0,
+ g_type_info_get_tag (type_info) );
+}
+
+JSValueRef
+seed_value_from_gi_argument_full (JSContextRef ctx,
+ GArgument * arg,
+ GITypeInfo * type_info,
+ JSValueRef * exception,
+ guint64 array_len,
+ GITypeTag gi_tag
+ )
+{
+
+ //seed_value_from_gi_argument_with_length : g_type_tag_to_string(gi_tag)
+ SEED_NOTE (INVOCATION,
+ "seed_value_from_gi_argument_full: arg_type = %s ",
+ g_type_tag_to_string(gi_tag)
+ );
+
switch (gi_tag)
{
@@ -873,8 +998,9 @@ seed_value_from_gi_argument (JSContextRef ctx,
return seed_value_from_int (ctx, arg->v_int, exception);
case GI_TYPE_TAG_ARRAY:
{
- GITypeInfo *param_type;
+
GIArrayType array_type;
+ GITypeInfo *array_type_info;
JSValueRef ret;
if (arg->v_pointer == NULL)
@@ -882,20 +1008,19 @@ seed_value_from_gi_argument (JSContextRef ctx,
array_type = g_type_info_get_array_type (type_info);
+ array_type_info = g_type_info_get_param_type (type_info, 0);
+
+
+
if (array_type == GI_ARRAY_TYPE_PTR_ARRAY)
{
JSObjectRef ret_ptr_array;
- GITypeInfo *array_type_info;
GPtrArray *ptr = arg->v_pointer;
GArgument larg;
int length = 0;
int i;
- if (!ptr)
- break;
-
length = ptr->len;
- array_type_info = g_type_info_get_param_type (type_info, 0);
ret_ptr_array = JSObjectMakeArray (ctx, 0, NULL, exception);
for (i = 0; i < length; ++i)
@@ -910,18 +1035,49 @@ seed_value_from_gi_argument (JSContextRef ctx,
JSObjectSetPropertyAtIndex (ctx, ret_ptr_array, i, ival, NULL);
}
- return ret_ptr_array;
+
+ g_base_info_unref ((GIBaseInfo *) array_type_info);
+
+ return ret_ptr_array;
}
+
+ // technically gir has arrays of bytes, eg.
+ // <array length="2" zero-terminated="0" c:type="gchar**"><type name="guint8"/>
+ // example : g_file_get_contents..
+ // we can treat this as a string.. - it's a bit flakey, we should really use
+ // Uint8Array - need to check the webkit API for this..
+
+ if (
+ !g_type_info_is_zero_terminated (type_info)
+ && array_type == GI_ARRAY_TYPE_C
+ && GI_TYPE_TAG_UINT8 == g_type_info_get_tag (array_type_info)
+ && array_len > 0
+ )
+ {
+ // got a stringy array..
+ // we should check g_type_info_get_array_fixed_size
+ // we are assuming that this is the array_len from the call..
+ g_base_info_unref ((GIBaseInfo *) array_type_info);
+
+ ret = seed_value_from_binary_string (ctx, arg->v_pointer, array_len, exception);
+ // always free arg... what about when we do not own it...?
+ //g_free(arg->v_pointer);
+
+ return ret;
+
+ }
+
if (!g_type_info_is_zero_terminated (type_info))
- break;
-
- param_type = g_type_info_get_param_type (type_info, 0);
-
- ret = seed_gi_make_jsarray (ctx, arg->v_pointer, param_type,
+ {
+ g_base_info_unref ((GIBaseInfo *) array_type_info);
+ break;
+ }
+
+ ret = seed_gi_make_jsarray (ctx, arg->v_pointer, array_type_info,
exception);
- g_base_info_unref ((GIBaseInfo *) param_type);
+ g_base_info_unref ((GIBaseInfo *) array_type_info);
return ret;
}
@@ -944,9 +1100,26 @@ seed_value_from_gi_argument (JSContextRef ctx,
g_base_info_unref (interface);
return seed_value_from_object (ctx, arg->v_pointer, exception);
}
- else if (interface_type == GI_INFO_TYPE_ENUM
- || interface_type == GI_INFO_TYPE_FLAGS)
+ else if (interface_type == GI_INFO_TYPE_ENUM)
{
+ JSValueRef ret;
+ GITypeTag etype = g_enum_info_get_storage_type (interface);
+
+ // needs GITypeInfo - we are sending it GIBaseInfo
+
+ ret = seed_value_from_gi_argument_full (
+ ctx,
+ arg,
+ type_info,
+ exception,
+ 0,
+ etype);
+ g_base_info_unref (interface);
+ return ret;
+ }
+ else if ( interface_type == GI_INFO_TYPE_FLAGS)
+ {
+
g_base_info_unref (interface);
return seed_value_from_long (ctx, arg->v_long, exception);
}
@@ -1022,6 +1195,53 @@ seed_value_from_gi_argument (JSContextRef ctx,
}
return ret;
}
+ case GI_TYPE_TAG_GHASH:
+ {
+ GITypeInfo *key_type;
+ GITypeTag key_type_tag;
+ GITypeInfo *value_type;
+ JSObjectRef ret;
+ GHashTable *hash_table;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ key_type = g_type_info_get_param_type (type_info, 0);
+ key_type_tag = g_type_info_get_tag (key_type);
+
+ if ((key_type_tag != GI_TYPE_TAG_UTF8) &&
+ (key_type_tag != GI_TYPE_TAG_FILENAME))
+ {
+ char *error_message = g_strdup_printf ("Unable to make object from hash table indexed with values of type %s", g_type_tag_to_string (key_type_tag));
+ seed_make_exception (ctx, exception, "ArgumentError",
+ error_message);
+ g_free (error_message);
+ return JSValueMakeNull (ctx);
+ }
+
+ value_type = g_type_info_get_param_type (type_info, 1);
+
+ ret = JSObjectMake (ctx, NULL, NULL);
+
+ hash_table = arg->v_pointer;
+ g_hash_table_iter_init (&iter, hash_table);
+
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ JSStringRef js_key;
+ GArgument value_arg;
+ JSValueRef value_jsval;
+
+ js_key = JSStringCreateWithUTF8CString ((const char*) key);
+
+ value_arg.v_string = value;
+ value_jsval = seed_value_from_gi_argument_full (ctx, &value_arg,
+ value_type, exception, 0, key_type_tag);
+
+ JSObjectSetProperty (ctx, ret, js_key, value_jsval, 0, NULL);
+ }
+
+ return ret;
+ }
case GI_TYPE_TAG_ERROR:
{
JSValueRef ret;
@@ -1037,8 +1257,9 @@ seed_value_from_gi_argument (JSContextRef ctx,
}
JSValueRef
-seed_value_from_gvalue (JSContextRef ctx,
- GValue * gval, JSValueRef * exception)
+seed_value_from_gvalue_for_signal (JSContextRef ctx, GValue * gval,
+ JSValueRef * exception,
+ GSignalQuery *signal_query, gint arg_n)
{
if (!G_IS_VALUE (gval))
{
@@ -1075,7 +1296,44 @@ seed_value_from_gvalue (JSContextRef ctx,
return seed_value_from_string (ctx, (gchar *)
g_value_get_string (gval), exception);
case G_TYPE_POINTER:
- return seed_make_pointer (ctx, g_value_get_pointer (gval));
+ if (signal_query)
+ {
+ JSValueRef res;
+ GArgument arg;
+ GIBaseInfo *obj;
+ GISignalInfo *signal_info;
+ GIArgInfo *arg_info;
+ GITypeInfo type_info;
+
+ obj = g_irepository_find_by_gtype(NULL, signal_query->itype);
+ if (!obj)
+ return NULL;
+
+ signal_info = g_object_info_find_signal((GIObjectInfo *) obj,
+ signal_query->signal_name);
+
+ if (!signal_info) {
+ g_base_info_unref((GIBaseInfo *) obj);
+ return NULL;
+ }
+
+ arg_info = g_callable_info_get_arg(signal_info, arg_n - 1);
+ g_arg_info_load_type(arg_info, &type_info);
+
+ arg.v_pointer = g_value_get_pointer(gval);
+
+ res = seed_value_from_gi_argument (ctx, &arg, &type_info, exception);
+
+ g_base_info_unref((GIBaseInfo*)arg_info);
+ g_base_info_unref((GIBaseInfo*)signal_info);
+ g_base_info_unref((GIBaseInfo*)obj);
+
+ return res;
+ }
+ else
+ {
+ return seed_make_pointer (ctx, g_value_get_pointer (gval));
+ }
case G_TYPE_PARAM:
// Might need to dup and make a boxed.
return seed_make_pointer (ctx, g_value_get_param (gval));
@@ -1125,6 +1383,13 @@ seed_value_from_gvalue (JSContextRef ctx,
return NULL;
}
+JSValueRef
+seed_value_from_gvalue (JSContextRef ctx,
+ GValue * gval, JSValueRef * exception)
+{
+ return seed_value_from_gvalue_for_signal(ctx, gval, exception, NULL, 0);
+}
+
gboolean
seed_value_to_gvalue (JSContextRef ctx,
JSValueRef val,
@@ -1314,9 +1579,17 @@ seed_value_to_gvalue (JSContextRef ctx,
// TODO: FIXME: This whole undefined type area
// needs some heaaavy improvement.
+ if (type == 0 && seed_value_is_gobject(ctx, val))
+ {
+ GObject *o = seed_value_to_object (ctx, val, exception);
+
+ g_value_init (ret, G_OBJECT_TYPE(o));
+ g_value_set_object (ret, o);
+ return TRUE;
+ }
// Support [GObject.TYPE_INT, 3]
// TODO: FIXME: Might crash.
- if (type == 0 && JSValueIsObject (ctx, val))
+ else if (type == 0 && JSValueIsObject (ctx, val))
{
// TODO: FIXME: Better array test like the cool one on reddit.
guint length = seed_value_to_int (ctx,
@@ -1389,7 +1662,7 @@ seed_value_to_gvalue (JSContextRef ctx,
* @object: A #SeedObject
* @name: The property to get, should be a valid JavaScript identifier
*
- * Returns: The value of the property or %NULL
+ * Returns: The value of the property or the undefined value
*/
JSValueRef
seed_object_get_property (JSContextRef ctx,
@@ -1446,8 +1719,7 @@ seed_object_set_property (JSContextRef ctx, JSObjectRef object,
* Converts the given #SeedValue into a #gboolean. Keep in mind that this will
* not convert a JavaScript number type, only a boolean.
*
- * Return value: The #gboolean represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gboolean represented by @val.
*
*/
gboolean
@@ -1478,8 +1750,7 @@ seed_value_to_boolean (JSContextRef ctx,
*
* Converts the given #gboolean into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1498,8 +1769,7 @@ seed_value_from_boolean (JSContextRef ctx,
*
* Converts the given #SeedValue into a #guint.
*
- * Return value: The #guint represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #guint represented by @val.
*
*/
guint
@@ -1528,8 +1798,7 @@ seed_value_to_uint (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #guint into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1547,8 +1816,7 @@ seed_value_from_uint (JSContextRef ctx, guint val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gint.
*
- * Return value: The #gint represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gint represented by @val.
*
*/
gint
@@ -1574,8 +1842,7 @@ seed_value_to_int (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #gint into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1593,8 +1860,7 @@ seed_value_from_int (JSContextRef ctx, gint val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gchar.
*
- * Return value: The #gchar represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gchar represented by @val.
*
*/
gchar
@@ -1631,8 +1897,7 @@ seed_value_to_char (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #gchar into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1650,8 +1915,7 @@ seed_value_from_char (JSContextRef ctx, gchar val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #guchar.
*
- * Return value: The #guchar represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #guchar represented by @val.
*
*/
guchar
@@ -1688,8 +1952,7 @@ seed_value_to_uchar (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #guchar into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1707,8 +1970,7 @@ seed_value_from_uchar (JSContextRef ctx, guchar val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gshort.
*
- * Return value: The #gshort represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gshort represented by @val.
*
*/
gshort
@@ -1734,8 +1996,7 @@ seed_value_to_short (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #gshort into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1753,8 +2014,7 @@ seed_value_from_short (JSContextRef ctx, gshort val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gushort.
*
- * Return value: The #gushort represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gushort represented by @val.
*
*/
gushort
@@ -1781,8 +2041,7 @@ seed_value_to_ushort (JSContextRef ctx, JSValueRef val,
*
* Converts the given #gushort into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1800,8 +2059,7 @@ seed_value_from_ushort (JSContextRef ctx, gushort val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #glong.
*
- * Return value: The #glong represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #glong represented by @val.
*
*/
glong
@@ -1827,8 +2085,7 @@ seed_value_to_long (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #glong into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1846,8 +2103,7 @@ seed_value_from_long (JSContextRef ctx, glong val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gulong.
*
- * Return value: The #gulong represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gulong represented by @val.
*
*/
gulong
@@ -1874,8 +2130,7 @@ seed_value_to_ulong (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #gulong into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1893,8 +2148,7 @@ seed_value_from_ulong (JSContextRef ctx, gulong val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gint64.
*
- * Return value: The #gint64 represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gint64 represented by @val.
*
*/
gint64
@@ -1921,8 +2175,7 @@ seed_value_to_int64 (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #gint64 into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1940,8 +2193,7 @@ seed_value_from_int64 (JSContextRef ctx, gint64 val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #guint64.
*
- * Return value: The #guint64 represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #guint64 represented by @val.
*
*/
guint64
@@ -1970,8 +2222,7 @@ seed_value_to_uint64 (JSContextRef ctx,
*
* Converts the given #guint64 into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -1989,8 +2240,7 @@ seed_value_from_uint64 (JSContextRef ctx, guint64 val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gfloat.
*
- * Return value: The #gfloat represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gfloat represented by @val.
*
*/
gfloat
@@ -2016,8 +2266,7 @@ seed_value_to_float (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #gfloat into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -2035,8 +2284,7 @@ seed_value_from_float (JSContextRef ctx, gfloat val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gdouble.
*
- * Return value: The #gdouble represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gdouble represented by @val.
*
*/
gdouble
@@ -2063,8 +2311,7 @@ seed_value_to_double (JSContextRef ctx,
*
* Converts the given #gdouble into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -2082,8 +2329,7 @@ seed_value_from_double (JSContextRef ctx, gdouble val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gsize.
*
- * Return value: The #gsize represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gsize represented by @val.
*
*/
gsize
@@ -2109,8 +2355,7 @@ seed_value_to_size (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #gsize into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -2128,8 +2373,7 @@ seed_value_from_size (JSContextRef ctx, gsize val, JSValueRef * exception)
*
* Converts the given #SeedValue into a #gssize.
*
- * Return value: The #gssize represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gssize represented by @val.
*
*/
gssize
@@ -2155,8 +2399,7 @@ seed_value_to_ssize (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
* Converts the given #gssize into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -2185,8 +2428,7 @@ seed_value_from_ssize (JSContextRef ctx, gssize val, JSValueRef * exception)
* If the #SeedValue is an object, the string returned is that obtained by
* calling .toString() on said object.
*
- * Return value: The #gchar* represented by @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: The #gchar* represented by @val.
*
*/
gchar *
@@ -2194,7 +2436,7 @@ seed_value_to_string (JSContextRef ctx,
JSValueRef val, JSValueRef * exception)
{
JSStringRef jsstr = NULL;
- JSValueRef func, str;
+ JSValueRef func;
gchar *buf = NULL;
gint length;
@@ -2219,10 +2461,11 @@ seed_value_to_string (JSContextRef ctx,
{
func =
seed_object_get_property (ctx, (JSObjectRef) val, "toString");
+
if (!JSValueIsNull (ctx, func) &&
JSValueIsObject (ctx, func) &&
JSObjectIsFunction (ctx, (JSObjectRef) func))
- str =
+ //str = ... we dump the return value!?!
JSObjectCallAsFunction (ctx, (JSObjectRef) func,
(JSObjectRef) val, 0, NULL, NULL);
}
@@ -2250,8 +2493,7 @@ seed_value_to_string (JSContextRef ctx,
*
* Converts the given #gchar* string into a #SeedValue.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -2281,8 +2523,9 @@ seed_value_from_string (JSContextRef ctx,
* Converts a string representation of the given binary string
* into a #SeedValue.
*
- * Return value: A #SeedValue which represents @bytes as a string, or %NULL
- * if an exception is raised during the conversion.
+ * FIXME - should use BinaryArray really
+ *
+ * Return value: A #SeedValue which represents @bytes as a string.
*
*/
JSValueRef
@@ -2290,15 +2533,33 @@ seed_value_from_binary_string (JSContextRef ctx,
const gchar * bytes,
gint n_bytes, JSValueRef * exception)
{
- JSValueRef ret;
-
- gchar *nstr = g_alloca ((n_bytes + 1) * sizeof (gchar));
- g_strlcpy (nstr, bytes, n_bytes);
- nstr[n_bytes] = '\0';
-
- ret = seed_value_from_string (ctx, nstr, exception);
-
- return ret;
+ JSStringRef jsstr;
+ JSValueRef valstr;
+ JSChar* jchar;
+ gint i;
+
+ SEED_NOTE (INVOCATION, "Creating binary string of length %d ",
+ n_bytes);
+
+ if (bytes == NULL)
+ {
+ return JSValueMakeNull (ctx);
+ }
+
+ jchar = g_new0(JSChar, n_bytes);
+ for(i =0;i < n_bytes; i++)
+ {
+ jchar[i] = bytes[i];
+ }
+ // this may leak...
+
+ jsstr = JSStringCreateWithCharacters((const JSChar*)jchar, n_bytes);
+ valstr = JSValueMakeString (ctx, jsstr);
+ g_free(jchar);
+ JSStringRelease (jsstr);
+
+ return valstr;
+
}
/**
@@ -2345,8 +2606,7 @@ seed_value_to_filename (JSContextRef ctx,
* Converts the given #gchar* filename into a #SeedValue, respecting the
* character set used for filenames on the local machine.
*
- * Return value: A #SeedValue which represents @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
@@ -2429,8 +2689,7 @@ seed_value_to_object (JSContextRef ctx,
*
* Wraps @val in a #SeedValue.
*
- * Return value: A #SeedValue which wraps @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which wraps @val.
*
*/
JSValueRef
@@ -2519,8 +2778,7 @@ out:
*
* Wraps @val in a #SeedValue.
*
- * Return value: A #SeedValue which wraps @val, or %NULL if an exception
- * is raised during the conversion.
+ * Return value: A #SeedValue which wraps @val.
*
*/
JSValueRef
@@ -2530,7 +2788,7 @@ seed_value_from_strv (JSContextRef ctx,
GArray *js_string_array = g_array_new (FALSE, FALSE, sizeof(gpointer));
for (; *val != NULL; val++)
{
- JSStringRef js_string = JSStringCreateWithUTF8CString((char*)*val);
+ JSStringRef js_string = seed_value_from_string (ctx, *val, exception);
js_string_array = g_array_append_val(js_string_array, js_string);
}
JSValueRef res = JSObjectMakeArray (ctx,