cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtan...@apache.org
Subject [23/31] js commit: [2526] Ensure navigator keeps "this" object for native functions
Date Wed, 27 Feb 2013 21:09:56 GMT
[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/next
Commit: efefa97dfe97a05aaad7d2d283b672ebf313a8f7
Parents: 6abe4c9
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Feb 22 14:01:40 2013 -0500
Committer: Andrew Grieve <agrieve@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");


Mime
View raw message