[gjs] signals: addSignalMethods warns about overwriting
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] signals: addSignalMethods warns about overwriting
- Date: Tue, 3 Jan 2017 05:41:19 +0000 (UTC)
commit 03558adf2e79606f5e6ca08018a3959d29f50c63
Author: Joe Shaw <joeshaw litl com>
Date: Wed May 26 08:51:55 2010 -0400
signals: addSignalMethods warns about overwriting
Log a warning if addSignalMethods() replaces existing methods. Original
patch by Joe Shaw, test added by Philip Chimento.
https://bugzilla.gnome.org/show_bug.cgi?id=619710
Makefile-test.am | 5 ++++-
installed-tests/scripts/testWarnings.sh | 25 +++++++++++++++++++++++++
modules/signals.js | 17 +++++++++++++----
3 files changed, 42 insertions(+), 5 deletions(-)
---
diff --git a/Makefile-test.am b/Makefile-test.am
index b9ac608..bcf6592 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -276,7 +276,10 @@ AM_TESTS_ENVIRONMENT = \
$(XVFB_START) \
$(NULL)
-simple_tests = installed-tests/scripts/testCommandLine.sh
+simple_tests = \
+ installed-tests/scripts/testCommandLine.sh \
+ installed-tests/scripts/testWarnings.sh \
+ $(NULL)
EXTRA_DIST += $(simple_tests)
TESTS = \
diff --git a/installed-tests/scripts/testWarnings.sh b/installed-tests/scripts/testWarnings.sh
new file mode 100755
index 0000000..1cb1dc3
--- /dev/null
+++ b/installed-tests/scripts/testWarnings.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+if test $GJS_USE_UNINSTALLED_FILES -eq 1; then
+ gjs="$TOP_BUILDDIR"/gjs-console
+else
+ gjs=gjs-console
+fi
+
+total=0
+
+report () {
+ exit_code=$?
+ total=`expr $total + 1`
+ if test $exit_code -eq 0; then
+ echo "ok $total - $1"
+ else
+ echo "not ok $total - $1"
+ fi
+}
+
+"$gjs" -c 'imports.signals.addSignalMethods({connect: "foo"})' 2>&1 | \
+ grep -q 'addSignalMethods is replacing existing .* connect method'
+report "overwriting method with Signals.addSignalMethods() should warn"
+
+echo "1..$total"
diff --git a/modules/signals.js b/modules/signals.js
index 0905e53..2b0d03a 100644
--- a/modules/signals.js
+++ b/modules/signals.js
@@ -137,10 +137,19 @@ function _emit(name /* , arg1, arg2 */) {
}
}
+function _addSignalMethod(proto, functionName, func) {
+ if (proto[functionName] && proto[functionName] != func) {
+ log("WARNING: addSignalMethods is replacing existing " +
+ proto + " " + functionName + " method");
+ }
+
+ proto[functionName] = func;
+}
+
function addSignalMethods(proto) {
- proto.connect = _connect;
- proto.disconnect = _disconnect;
- proto.emit = _emit;
+ _addSignalMethod(proto, "connect", _connect);
+ _addSignalMethod(proto, "disconnect", _disconnect);
+ _addSignalMethod(proto, "emit", _emit);
// this one is not in GObject, but useful
- proto.disconnectAll = _disconnectAll;
+ _addSignalMethod(proto, "disconnectAll", _disconnectAll);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]