You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2013/02/25 14:40:49 UTC

[44/50] js commit: [2526] Ensure navigator keeps "this" object for native functions

[2526] Ensure navigator keeps "this" object for native functions


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

Branch: refs/heads/multipart_plugin_result
Commit: efefa97dfe97a05aaad7d2d283b672ebf313a8f7
Parents: 6abe4c9
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Feb 22 14:01:40 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Feb 22 14:01:40 2013 -0500

----------------------------------------------------------------------
 lib/scripts/bootstrap.js |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/efefa97d/lib/scripts/bootstrap.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap.js b/lib/scripts/bootstrap.js
index 437604d..6213165 100644
--- a/lib/scripts/bootstrap.js
+++ b/lib/scripts/bootstrap.js
@@ -22,10 +22,23 @@
 (function (context) {
     // Replace navigator before any modules are required(), to ensure it happens as soon as possible.
     // We replace it so that properties that can't be clobbered can instead be overridden.
-    if (context.navigator) {
+    function replaceNavigator(origNavigator) {
         var CordovaNavigator = function() {};
-        CordovaNavigator.prototype = context.navigator;
-        context.navigator = new CordovaNavigator();
+        CordovaNavigator.prototype = origNavigator;
+        var newNavigator = new CordovaNavigator();
+        // This work-around really only applies to new APIs that are newer than Function.bind.
+        // Without it, APIs such as getGamepads() break.
+        if (CordovaNavigator.bind) {
+            for (var key in origNavigator) {
+                if (typeof origNavigator[key] == 'function') {
+                    newNavigator[key] = origNavigator[key].bind(origNavigator);
+                }
+            }
+        }
+        return newNavigator;
+    }
+    if (context.navigator) {
+        context.navigator = replaceNavigator(context.navigator);
     }
 
     var channel = require("cordova/channel");