Skip to content

Commit

Permalink
CB-7868 Use utils.defineGetterSetter instead of Object.defineProperty…
Browse files Browse the repository at this point in the history
… which may or may not be defined
  • Loading branch information
purplecabbage committed Oct 27, 2014
1 parent 14fae3a commit bd5a35f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
17 changes: 8 additions & 9 deletions src/common/init.js
Expand Up @@ -24,6 +24,7 @@ var cordova = require('cordova');
var modulemapper = require('cordova/modulemapper');
var platform = require('cordova/platform');
var pluginloader = require('cordova/pluginloader');
var utils = require('cordova/utils');

var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];

Expand Down Expand Up @@ -55,21 +56,19 @@ function replaceNavigator(origNavigator) {
for (var key in origNavigator) {
if (typeof origNavigator[key] == 'function') {
newNavigator[key] = origNavigator[key].bind(origNavigator);
} else {
}
else {
(function(k) {
Object.defineProperty(newNavigator, k, {
get: function() {
return origNavigator[k];
},
configurable: true,
enumerable: true
});
})(key);
utils.defineGetterSetter(newNavigator,key,function() {
return origNavigator[k];
});
})(key);
}
}
}
return newNavigator;
}

if (window.navigator) {
window.navigator = replaceNavigator(window.navigator);
}
Expand Down
16 changes: 7 additions & 9 deletions src/common/init_b.js
Expand Up @@ -22,6 +22,7 @@
var channel = require('cordova/channel');
var cordova = require('cordova');
var platform = require('cordova/platform');
var utils = require('cordova/utils');

var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady];

Expand Down Expand Up @@ -56,16 +57,13 @@ function replaceNavigator(origNavigator) {
for (var key in origNavigator) {
if (typeof origNavigator[key] == 'function') {
newNavigator[key] = origNavigator[key].bind(origNavigator);
} else {
}
else {
(function(k) {
Object.defineProperty(newNavigator, k, {
get: function() {
return origNavigator[k];
},
configurable: true,
enumerable: true
});
})(key);
utils.defineGetterSetter(newNavigator,key,function() {
return origNavigator[k];
});
})(key);
}
}
}
Expand Down

0 comments on commit bd5a35f

Please sign in to comment.