You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/10/04 21:55:58 UTC
[5/11] Update JS with new exec() bridge functions.
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/780be09f/bin/templates/project/www/cordova-2.1.0.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/www/cordova-2.1.0.js b/bin/templates/project/www/cordova-2.1.0.js
index 8d02a6c..6971d90 100644
--- a/bin/templates/project/www/cordova-2.1.0.js
+++ b/bin/templates/project/www/cordova-2.1.0.js
@@ -1,6 +1,6 @@
-// commit 27d9aedd5bf520f305e20fcf350da2eef244d53d
+// commit 5df805075ca294e35b86b9a3dd30171a186e6ac8
-// File generated at :: Wed Oct 03 2012 13:16:23 GMT-0400 (EDT)
+// File generated at :: Thu Oct 04 2012 13:52:03 GMT-0400 (EDT)
/*
Licensed to the Apache Software Foundation (ASF) under one
@@ -234,14 +234,6 @@ var cordova = {
}
},
- // TODO: iOS only
- // This queue holds the currently executing command and all pending
- // commands executed with cordova.exec().
- commandQueue:[],
- // Indicates if we're currently in the middle of flushing the command
- // queue on the native side.
- commandQueueFlushing:false,
- // END TODO
/**
* Plugin callback mechanism.
*/
@@ -901,7 +893,6 @@ define("cordova/exec", function(require, exports, module) {
*/
var cordova = require('cordova'),
channel = require('cordova/channel'),
- nativecomm = require('cordova/plugin/ios/nativecomm'),
utils = require('cordova/utils'),
jsToNativeModes = {
IFRAME_NAV: 0,
@@ -915,7 +906,9 @@ var cordova = require('cordova'),
bridgeMode = navigator.userAgent.indexOf(' 4_') == -1 ? jsToNativeModes.XHR_NO_PAYLOAD : jsToNativeModes.IFRAME_NAV,
execIframe,
execXhr,
- requestCount = 0;
+ requestCount = 0,
+ commandQueue = [], // Contains pending JS->Native messages.
+ isInContextOfEvalJs = 0;
function createExecIframe() {
var iframe = document.createElement("iframe");
@@ -930,8 +923,8 @@ function shouldBundleCommandJson() {
}
if (bridgeMode == jsToNativeModes.XHR_OPTIONAL_PAYLOAD) {
var payloadLength = 0;
- for (var i = 0; i < cordova.commandQueue.length; ++i) {
- payloadLength += cordova.commandQueue[i].length;
+ for (var i = 0; i < commandQueue.length; ++i) {
+ payloadLength += commandQueue[i].length;
}
// The value here was determined using the benchmark within CordovaLibApp on an iPad 3.
return payloadLength < 4500;
@@ -982,9 +975,9 @@ function iOSExec() {
// Stringify and queue the command. We stringify to command now to
// effectively clone the command arguments in case they are mutated before
// the command is executed.
- cordova.commandQueue.push(JSON.stringify(command));
+ commandQueue.push(JSON.stringify(command));
- if (!cordova.commandQueueFlushing) {
+ if (!isInContextOfEvalJs) {
if (bridgeMode != jsToNativeModes.IFRAME_NAV) {
// Re-using the XHR improves exec() performance by about 10%.
// It is possible for a native stringByEvaluatingJavascriptFromString call
@@ -1001,7 +994,7 @@ function iOSExec() {
execXhr.setRequestHeader('vc', cordova.iOSVCAddr);
execXhr.setRequestHeader('rc', ++requestCount);
if (shouldBundleCommandJson()) {
- execXhr.setRequestHeader('cmds', nativecomm());
+ execXhr.setRequestHeader('cmds', iOSExec.nativeFetchMessages());
}
execXhr.send(null);
} else {
@@ -1024,6 +1017,28 @@ iOSExec.setJsToNativeBridgeMode = function(mode) {
bridgeMode = mode;
};
+iOSExec.nativeFetchMessages = function() {
+ // Each entry in commandQueue is a JSON string already.
+ if (!commandQueue.length) {
+ return '';
+ }
+ var json = '[' + commandQueue.join(',') + ']';
+ commandQueue.length = 0;
+ return json;
+};
+
+iOSExec.nativeCallback = function(callbackId, status, payload, keepCallback) {
+ // This shouldn't be nested, but better to be safe.
+ isInContextOfEvalJs++;
+ try {
+ var success = status == 0 || status == 1;
+ cordova.callbackFromNative(callbackId, success, status, payload, keepCallback);
+ return iOSExec.nativeFetchMessages();
+ } finally {
+ isInContextOfEvalJs--;
+ }
+};
+
module.exports = iOSExec;
});
@@ -5293,23 +5308,6 @@ module.exports = {
});
-// file: lib/ios/plugin/ios/nativecomm.js
-define("cordova/plugin/ios/nativecomm", function(require, exports, module) {
-
-var cordova = require('cordova');
-
-/**
- * Called by native code to retrieve all queued commands and clear the queue.
- */
-module.exports = function() {
- // Each entry in commandQueue is a JSON string already.
- var json = '[' + cordova.commandQueue.join(',') + ']';
- cordova.commandQueue.length = 0;
- return json;
-};
-
-});
-
// file: lib/ios/plugin/ios/notification.js
define("cordova/plugin/ios/notification", function(require, exports, module) {