From 9f78e0985d2f4fdc2588be57c5f25afdd59c6365 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 17 Apr 2014 14:42:15 +0200 Subject: Do not return a function for property getters on the HTML side. This simplifies the usage and lets properties be used just like normal JavaScript properties. This is possible since the properties are cached on the HTML side. Change-Id: Ic60076f4596cd8df063567dfbd630e5bd6403119 Reviewed-by: Pierre Rossi --- src/webchannel/qwebchannel.js | 23 ++++++----------------- tests/auto/qml/data/grouping.html | 2 +- tests/auto/qml/data/property.html | 4 ++-- tests/auto/qml/data/wrapper.html | 2 +- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/webchannel/qwebchannel.js b/src/webchannel/qwebchannel.js index 9529c0b..278f423 100644 --- a/src/webchannel/qwebchannel.js +++ b/src/webchannel/qwebchannel.js @@ -389,24 +389,13 @@ function QObject(name, data, webChannel) }); object.__defineGetter__(propertyName, function () { - return (function (callback) { - var propertyValue = object.__propertyCache__[propertyIndex]; - if (propertyValue === undefined) { - // This shouldn't happen - console.warn("Undefined value in property cache for property \"" + propertyName + "\" in object " + object.__id__); - } + var propertyValue = object.__propertyCache__[propertyIndex]; + if (propertyValue === undefined) { + // This shouldn't happen + console.warn("Undefined value in property cache for property \"" + propertyName + "\" in object " + object.__id__); + } - // TODO: A callback is not required here anymore, but is kept for backwards compatibility - if (callback !== undefined) { - if (typeof(callback) !== "function") { - console.error("Bad callback given to get property " + property); - return; - } - callback(propertyValue); - } else { - return propertyValue; - } - }); + return propertyValue; }); } diff --git a/tests/auto/qml/data/grouping.html b/tests/auto/qml/data/grouping.html index f2d7aec..f6bc33c 100644 --- a/tests/auto/qml/data/grouping.html +++ b/tests/auto/qml/data/grouping.html @@ -6,7 +6,7 @@ //BEGIN SETUP window.channel = createWebChannel(function(channel) { channel.subscribe(QWebChannelMessageTypes.propertyUpdate, function() { - channel.exec({label: "gotPropertyUpdate", values: [myObj.myProperty(), myOtherObj.foo(), myOtherObj.bar()]}); + channel.exec({label: "gotPropertyUpdate", values: [myObj.myProperty, myOtherObj.foo, myOtherObj.bar]}); }); }); //END SETUP diff --git a/tests/auto/qml/data/property.html b/tests/auto/qml/data/property.html index 9565aaa..49b3811 100644 --- a/tests/auto/qml/data/property.html +++ b/tests/auto/qml/data/property.html @@ -5,9 +5,9 @@