[gjs/wip/gobj-kitchen-sink: 12/21] GParamSpec: set an exception when invoking the constructor with wrong arguments
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/gobj-kitchen-sink: 12/21] GParamSpec: set an exception when invoking the constructor with wrong arguments
- Date: Fri, 27 Jan 2012 20:07:30 +0000 (UTC)
commit 74c413a6f766d22d9ef5a5c9c82217357e48fa51
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Fri Dec 9 19:12:23 2011 +0100
GParamSpec: set an exception when invoking the constructor with wrong arguments
Returning FALSE without an exception will confuse the JS API. Instead,
we should report the wrong arguments to the user.
gi/param.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/gi/param.c b/gi/param.c
index fd61665..36aa3b6 100644
--- a/gi/param.c
+++ b/gi/param.c
@@ -186,15 +186,21 @@ param_new_internal(JSContext *cx,
gchar *blurb;
GParamFlags flags;
- if (argc < 5)
+ if (argc < 5) {
+ gjs_throw(cx, "Wrong number of arguments to GObject.ParamSpec._new_internal (expected 5)");
return JS_FALSE;
+ }
if (!JSVAL_IS_STRING(argv[0]) ||
!JSVAL_IS_OBJECT(argv[1]) ||
!JSVAL_IS_STRING(argv[2]) ||
!JSVAL_IS_STRING(argv[3]) ||
- !JSVAL_IS_INT(argv[4]))
+ !JSVAL_IS_INT(argv[4])) {
+ gjs_throw(cx, "Wrong type of arguments to GObject.ParamSpec._new_internal (expected string, GType object, string, string, number), "
+ "were %s, %s, %s, %s, %s", JS_GetTypeName(cx, JS_TypeOfValue(cx, argv[0])), JS_GetTypeName(cx, JS_TypeOfValue(cx, argv[1])),
+ JS_GetTypeName(cx, JS_TypeOfValue(cx, argv[2])), JS_GetTypeName(cx, JS_TypeOfValue(cx, argv[3])), JS_GetTypeName(cx, JS_TypeOfValue(cx, argv[4])));
return JS_FALSE;
+ }
prop_name = gjs_string_get_ascii(cx, argv[0]);
prop_gtype = gjs_gtype_get_actual_gtype(cx, JSVAL_TO_OBJECT(argv[1]));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]