cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhigg...@apache.org
Subject js commit: CB-5973 blackberry: add support for sync exec
Date Thu, 06 Feb 2014 02:25:30 GMT
Updated Branches:
  refs/heads/master 12a6fdbb6 -> 7d02fb809


CB-5973 blackberry: add support for sync exec


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/7d02fb80
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/7d02fb80
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/7d02fb80

Branch: refs/heads/master
Commit: 7d02fb809ece39ed0eceae3ae4342b394641714d
Parents: 12a6fdb
Author: Josh Soref <jsoref@blackberry.com>
Authored: Tue Feb 4 17:59:47 2014 -0500
Committer: Bryan Higgins <bryan@bryanhiggins.net>
Committed: Wed Feb 5 21:25:21 2014 -0500

----------------------------------------------------------------------
 src/blackberry10/exec.js | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/7d02fb80/src/blackberry10/exec.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/exec.js b/src/blackberry10/exec.js
index 31f9b7c..c48ddff 100644
--- a/src/blackberry10/exec.js
+++ b/src/blackberry10/exec.js
@@ -76,13 +76,24 @@ function RemoteFunctionCall(functionUri) {
 
         request.send(JSON.stringify(params));
     };
+
+    this.makeSyncCall = function () {
+        var requestUri = composeUri(),
+        request = createXhrRequest(requestUri, false),
+        response;
+        request.send(JSON.stringify(params));
+        response = JSON.parse(decodeURIComponent(request.responseText) || "null");
+        return response;
+    };
+
 }
 
-module.exports = function (success, fail, service, action, args) {
+module.exports = function (success, fail, service, action, args, sync) {
     var uri = service + "/" + action,
     request = new RemoteFunctionCall(uri),
     callbackId = service + cordova.callbackId++,
     proxy,
+    response,
     name,
     didSucceed;
 
@@ -107,7 +118,30 @@ module.exports = function (success, fail, service, action, args) {
             }
         }
 
-        request.makeAsyncCall();
+        sync = false || arguments[5];
+
+        if (!sync) {
+            request.makeAsyncCall();
+            return;
+        }
+
+        response = request.makeSyncCall();
+
+        if (response.code < 0) {
+            if (fail) {
+                fail(response.msg, response);
+            }
+            delete cordova.callbacks[callbackId];
+        } else {
+            didSucceed = response.code === cordova.callbackStatus.OK || response.code ===
cordova.callbackStatus.NO_RESULT;
+            cordova.callbackFromNative(
+                callbackId,
+                didSucceed,
+                response.code,
+                [ didSucceed ? response.data : response.msg ],
+                !!response.keepCallback
+            );
+        }
     }
 
 };


Mime
View raw message