[gjs] arg: Throw an explicit error if we don't know how to make an array
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] arg: Throw an explicit error if we don't know how to make an array
- Date: Fri, 30 Nov 2012 21:53:14 +0000 (UTC)
commit 2312df25dbf0cb5ec8da553086fb8d2e0cacfce6
Author: Colin Walters <walters verbum org>
Date: Fri Nov 30 08:02:30 2012 -0500
arg: Throw an explicit error if we don't know how to make an array
Previously, we were just passing a 0 length array if you gave say {}
as the argument for a uint8 array...kind of lame.
https://bugzilla.gnome.org/show_bug.cgi?id=689343
gi/arg.c | 10 ++++++++++
test/js/testGIMarshalling.js | 3 +++
2 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/gi/arg.c b/gi/arg.c
index 5ffdb3f..1e313c9 100644
--- a/gi/arg.c
+++ b/gi/arg.c
@@ -1087,6 +1087,16 @@ gjs_array_to_explicit_array_internal(JSContext *context,
*length_p = length;
}
+ } else {
+ gchar *display_name = get_argument_display_name(arg_name, arg_type);
+ gjs_throw(context, "Expected type %s for %s but got type '%s' %p",
+ g_type_tag_to_string(g_type_info_get_tag(param_info)),
+ display_name,
+ JS_GetTypeName(context,
+ JS_TypeOfValue(context, value)),
+ JSVAL_IS_OBJECT(value) ? JSVAL_TO_OBJECT(value) : NULL);
+ g_free(display_name);
+ goto out;
}
ret = JS_TRUE;
diff --git a/test/js/testGIMarshalling.js b/test/js/testGIMarshalling.js
index e127c20..d91b9d2 100644
--- a/test/js/testGIMarshalling.js
+++ b/test/js/testGIMarshalling.js
@@ -206,6 +206,9 @@ function testGBytes() {
bytes = GLib.Bytes.new([97, 98, 99, 100])
GIMarshallingTests.array_uint8_in(bytes.toArray());
+ assertRaises(function() {
+ GIMarshallingTests.array_uint8_in(bytes);
+ });
}
function testPtrArray() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]