(name, data, webChannel)
| 173 | }; |
| 174 | |
| 175 | function QObject(name, data, webChannel) |
| 176 | { |
| 177 | this.__id__ = name; |
| 178 | webChannel.objects[name] = this; |
| 179 | |
| 180 | // List of callbacks that get invoked upon signal emission |
| 181 | this.__objectSignals__ = {}; |
| 182 | |
| 183 | // Cache of all properties, updated when a notify signal is emitted |
| 184 | this.__propertyCache__ = {}; |
| 185 | |
| 186 | var object = this; |
| 187 | |
| 188 | // ---------------------------------------------------------------------- |
| 189 | |
| 190 | this.unwrapQObject = function(response) |
| 191 | { |
| 192 | if (response instanceof Array) { |
| 193 | // support list of objects |
| 194 | var ret = new Array(response.length); |
| 195 | for (var i = 0; i < response.length; ++i) { |
| 196 | ret[i] = object.unwrapQObject(response[i]); |
| 197 | } |
| 198 | return ret; |
| 199 | } |
| 200 | if (!response |
| 201 | || !response["__QObject*__"] |
| 202 | || response.id === undefined) { |
| 203 | return response; |
| 204 | } |
| 205 | |
| 206 | var objectId = response.id; |
| 207 | if (webChannel.objects[objectId]) |
| 208 | return webChannel.objects[objectId]; |
| 209 | |
| 210 | if (!response.data) { |
| 211 | console.error("Cannot unwrap unknown QObject " + objectId + " without data."); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | var qObject = new QObject( objectId, response.data, webChannel ); |
| 216 | qObject.destroyed.connect(function() { |
| 217 | if (webChannel.objects[objectId] === qObject) { |
| 218 | delete webChannel.objects[objectId]; |
| 219 | // reset the now deleted QObject to an empty {} object |
| 220 | // just assigning {} though would not have the desired effect, but the |
| 221 | // below also ensures all external references will see the empty map |
| 222 | // NOTE: this detour is necessary to workaround QTBUG-40021 |
| 223 | var propertyNames = []; |
| 224 | for (var propertyName in qObject) { |
| 225 | propertyNames.push(propertyName); |
| 226 | } |
| 227 | for (var idx in propertyNames) { |
| 228 | delete qObject[propertyNames[idx]]; |
| 229 | } |
| 230 | } |
| 231 | }); |
| 232 | // here we are already initialized, and thus must directly unwrap the properties |
nothing calls this directly
no test coverage detected