From 95231d6cf12d1e5b7f219fdf9f1cf502a5f7d52c Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Fri, 15 Feb 2013 14:19:25 +0100 Subject: Be more forgiving in bad API usage, show proper error messages. Change-Id: I7eeedea7666268a42db3c31c52255f12026e3fa3 Reviewed-by: Pierre Rossi --- src/qobject.js | 11 ++++++++++- src/qtmetaobjectpublisher.cpp | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/qobject.js b/src/qobject.js index aa238cd..e3ca060 100644 --- a/src/qobject.js +++ b/src/qobject.js @@ -63,14 +63,19 @@ function QObject(name, data, webChannel) { } webChannel.exec(JSON.stringify({"type": "Qt.invokeMethod", "object": object.__id__, "method": method, "args": args}), function(response) { - if (response.length) + if (response.length && callback) { (callback)(JSON.parse(response)); + } }); }; }); function connectToSignal(signal) { object[signal].connect = function(callback) { + if (typeof(callback) !== "function") { + console.error("Bad callback given to connect to signal " + signal); + return; + } object.__objectSignals__[signal] = object.__objectSignals__[signal] || []; webChannel.exec(JSON.stringify({"type": "Qt.connectToSignal", "object": object.__id__, "signal": signal})); object.__objectSignals__[signal].push(callback); @@ -88,6 +93,10 @@ function QObject(name, data, webChannel) { object.__defineGetter__(property, function() { return (function(callback) { webChannel.exec(JSON.stringify({"type": "Qt.getProperty", "object": object.__id__, "property": property}), function(response) { + if (typeof(callback) !== "function") { + console.error("Bad callback given to get property " + property); + return; + } callback(JSON.parse(response)); }); }); diff --git a/src/qtmetaobjectpublisher.cpp b/src/qtmetaobjectpublisher.cpp index b073fb0..ed736e4 100644 --- a/src/qtmetaobjectpublisher.cpp +++ b/src/qtmetaobjectpublisher.cpp @@ -54,6 +54,10 @@ QtMetaObjectPublisher::QtMetaObjectPublisher(QObject *parent) QVariantMap QtMetaObjectPublisher::classInfoForObject(QObject *object) const { QVariantMap data; + if (!object) { + qWarning("null object given to MetaObjectPublisher - bad API usage?"); + return data; + } QStringList qtSignals, qtMethods, qtProperties; const QMetaObject* metaObject = object->metaObject(); for (int i = 0; i < metaObject->propertyCount(); ++i) -- cgit v1.2.1