Make the starting callbackId random rather than always 0 to avoid collisions.


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

Branch: refs/heads/master
Commit: 43031f559474657d33165b8580f224dc99eeafd7
Parents: 650e541
Author: Braden Shepherdson <bra...@chromium.org>
Authored: Tue Sep 11 14:39:28 2012 -0400
Committer: Braden Shepherdson <bra...@chromium.org>
Committed: Tue Sep 11 14:39:28 2012 -0400

----------------------------------------------------------------------
 lib/cordova.js |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/43031f55/lib/cordova.js
----------------------------------------------------------------------
diff --git a/lib/cordova.js b/lib/cordova.js
index e076773..6a6521a 100644
--- a/lib/cordova.js
+++ b/lib/cordova.js
@@ -154,7 +154,9 @@ var cordova = {
     /**
      * Plugin callback mechanism.
      */
-    callbackId: 0,
+    // Randomize the starting callbackId to avoid collisions after refreshing 
or navigating.
+    // This way, it's very unlikely that any new callback would get the same 
callbackId as an old callback.
+    callbackId: Math.floor(Math.random() * 2000000000),
     callbacks:  {},
     callbackStatus: {
         NO_RESULT: 0,

Reply via email to