Merge branch 'fixMemoryLeak' of https://github.com/csantanapr/cordova-js into 3.1.x
diff --git a/lib/windows8/exec.js b/lib/windows8/exec.js
index 4583594..a8717a3 100644
--- a/lib/windows8/exec.js
+++ b/lib/windows8/exec.js
@@ -19,6 +19,9 @@
*
*/
+/*jslint sloppy:true, plusplus:true*/
+/*global require, module, console */
+
var cordova = require('cordova');
var commandProxy = require('cordova/windows8/commandProxy');
@@ -36,23 +39,42 @@
* @param {String} action Action to be run in cordova
* @param {String[]} [args] Zero or more arguments to pass to the method
*/
-module.exports = function(success, fail, service, action, args) {
+module.exports = function (success, fail, service, action, args) {
- var proxy = commandProxy.get(service,action);
- if(proxy) {
- var callbackId = service + cordova.callbackId++;
+ var proxy = commandProxy.get(service, action),
+ callbackId,
+ onSuccess,
+ onError;
+
+ if (proxy) {
+ callbackId = service + cordova.callbackId++;
// console.log("EXEC:" + service + " : " + action);
- if (typeof success == "function" || typeof fail == "function") {
- cordova.callbacks[callbackId] = {success:success, fail:fail};
+ if (typeof success === "function" || typeof fail === "function") {
+ cordova.callbacks[callbackId] = {success: success, fail: fail};
}
try {
- proxy(success, fail, args);
- }
- catch(e) {
+ onSuccess = function (result) {
+ cordova.callbackSuccess(callbackId,
+ {
+ status: cordova.callbackStatus.OK,
+ message: result
+ });
+ };
+ onError = function (err) {
+ cordova.callbackError(callbackId,
+ {
+ status: cordova.callbackStatus.ERROR,
+ message: err
+ });
+ };
+ proxy(onSuccess, onError, args);
+
+ } catch (e) {
console.log("Exception calling native with command :: " + service + " :: " + action + " ::exception=" + e);
}
- }
- else {
- fail && fail("Missing Command Error");
+ } else {
+ if (typeof fail === "function") {
+ fail("Missing Command Error");
+ }
}
};