[gjs] GI: throw if connecting to an invalid signal
- From: Johan Bilien <jobi src gnome org>
- To: svn-commits-list gnome org
- Subject: [gjs] GI: throw if connecting to an invalid signal
- Date: Tue, 24 Mar 2009 13:01:05 -0400 (EDT)
commit bc6acbfdbc32898212a0c57743c00b15aec362e3
Author: Johan Bilien <jobi litl com>
Date: Tue Mar 24 12:36:29 2009 +0000
GI: throw if connecting to an invalid signal
instead of triggering a GLib warning.
Add test for this.
---
gi/object.c | 10 ++++++++++
test/js/testEverythingBasic.js | 9 +++++++++
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/gi/object.c b/gi/object.c
index 794f7d1..07bfca3 100644
--- a/gi/object.c
+++ b/gi/object.c
@@ -887,6 +887,7 @@ real_connect_func(JSContext *context,
ObjectInstance *priv;
GClosure *closure;
gulong id;
+ guint signal_id;
const char *signal_name;
*retval = INT_TO_JSVAL(0);
@@ -926,6 +927,15 @@ real_connect_func(JSContext *context,
return JS_FALSE;
}
+ signal_id = g_signal_lookup(signal_name, G_TYPE_FROM_INSTANCE(priv->gobj));
+ if (signal_id == 0) {
+ gjs_throw(context, "No signal %s on object of type %s",
+ signal_name,
+ g_base_info_get_name((GIBaseInfo*) priv->info));
+ g_closure_sink(closure);
+ return JS_FALSE;
+ }
+
id = g_signal_connect_closure(priv->gobj,
signal_name,
closure,
diff --git a/test/js/testEverythingBasic.js b/test/js/testEverythingBasic.js
index ab16906..901c589 100644
--- a/test/js/testEverythingBasic.js
+++ b/test/js/testEverythingBasic.js
@@ -183,6 +183,15 @@ function testSignal() {
assertEquals('disconnected handler not called', 1, handlerCounter);
}
+function testInvalidSignal() {
+ let o = new Everything.TestObj();
+
+ assertRaises('connect to invalid signal',
+ function() { o.connect('invalid-signal', function(o) {}); });
+ assertRaises('emit invalid signal',
+ function() { o.emit('invalid-signal'); });
+}
+
function testSignalWithStaticScopeArg() {
let o = new Everything.TestObj();
let b = new Everything.TestSimpleBoxedA({ some_int: 42,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]