You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2014/02/06 03:25:08 UTC
js commit: CB-5973 blackberry: add support for sync exec
Updated Branches:
refs/heads/3.4.x 624c75f96 -> 9508bcc21
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/9508bcc2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/9508bcc2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/9508bcc2
Branch: refs/heads/3.4.x
Commit: 9508bcc217c2642745104607fe9a80e105203e96
Parents: 624c75f
Author: Josh Soref <js...@blackberry.com>
Authored: Tue Feb 4 17:59:47 2014 -0500
Committer: Bryan Higgins <br...@bryanhiggins.net>
Committed: Wed Feb 5 21:24:19 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/9508bcc2/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
+ );
+ }
}
};