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/09/18 16:47:24 UTC
[6/6] js commit: Add navigator.connection and deprecate
navigator.network.connection.
Add navigator.connection and deprecate navigator.network.connection.
Fixes issue: https://issues.apache.org/jira/browse/CB-1368
This involved:
- Adding a util for creating a property getter (Android 2.1 doesn't
support Object.defineProperty)
- Adding a way to deprecate a namespace via builder.js (and
deprecating navigator.network with it
- Subclassing Navigator so that properties can be set on it.
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/0982d4d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/0982d4d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/0982d4d3
Branch: refs/heads/master
Commit: 0982d4d3e98f4a7b60261b645af1ca36bbef336e
Parents: 9878d97
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Sep 5 16:33:41 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Sep 18 10:46:47 2012 -0400
----------------------------------------------------------------------
lib/common/builder.js | 17 ++++++++++++++---
lib/common/common.js | 6 +++++-
lib/common/utils.js | 11 +++++++++++
lib/scripts/bootstrap.js | 8 ++++++++
4 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0982d4d3/lib/common/builder.js
----------------------------------------------------------------------
diff --git a/lib/common/builder.js b/lib/common/builder.js
index 76386f0..13d1815 100644
--- a/lib/common/builder.js
+++ b/lib/common/builder.js
@@ -29,6 +29,17 @@ function each(objects, func, context) {
}
}
+function assignOrWrapInDeprecateGetter(obj, key, value, message) {
+ if (message) {
+ utils.defineGetter(obj, key, function() {
+ window.console && console.log(message);
+ return value;
+ });
+ } else {
+ obj[key] = value;
+ }
+}
+
function include(parent, objects, clobber, merge) {
each(objects, function (obj, key) {
try {
@@ -37,20 +48,20 @@ function include(parent, objects, clobber, merge) {
if (clobber) {
// Clobber if it doesn't exist.
if (typeof parent[key] === 'undefined') {
- parent[key] = result;
+ assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
} else if (typeof obj.path !== 'undefined') {
// If merging, merge properties onto parent, otherwise, clobber.
if (merge) {
recursiveMerge(parent[key], result);
} else {
- parent[key] = result;
+ assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
}
}
result = parent[key];
} else {
// Overwrite if not currently defined.
if (typeof parent[key] == 'undefined') {
- parent[key] = result;
+ assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
} else if (merge && typeof obj.path !== 'undefined') {
// If merging, merge parent onto result
recursiveMerge(result, parent[key]);
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0982d4d3/lib/common/common.js
----------------------------------------------------------------------
diff --git a/lib/common/common.js b/lib/common/common.js
index 7aa837e..fce0a73 100644
--- a/lib/common/common.js
+++ b/lib/common/common.js
@@ -56,6 +56,9 @@ module.exports = {
compass:{
path: 'cordova/plugin/compass'
},
+ connection: {
+ path: 'cordova/plugin/network'
+ },
contacts: {
path: 'cordova/plugin/contacts'
},
@@ -72,7 +75,8 @@ module.exports = {
network: {
children: {
connection: {
- path: 'cordova/plugin/network'
+ path: 'cordova/plugin/network',
+ deprecated: 'navigator.network.connection is deprecated. Use navigator.connection instead.'
}
}
},
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0982d4d3/lib/common/utils.js
----------------------------------------------------------------------
diff --git a/lib/common/utils.js b/lib/common/utils.js
index 139d723..5b0ac7c 100644
--- a/lib/common/utils.js
+++ b/lib/common/utils.js
@@ -22,6 +22,17 @@
var utils = exports;
/**
+ * Defines a property getter for obj[key].
+ */
+utils.defineGetter = function(obj, key, func) {
+ if (Object.defineProperty) {
+ Object.defineProperty(obj, key, { get: func });
+ } else {
+ obj.__defineGetter__(key, func);
+ }
+};
+
+/**
* Returns an indication of whether the argument is an array or not
*/
utils.isArray = function(a) {
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0982d4d3/lib/scripts/bootstrap.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap.js b/lib/scripts/bootstrap.js
index 4887754..6aa08af 100644
--- a/lib/scripts/bootstrap.js
+++ b/lib/scripts/bootstrap.js
@@ -20,6 +20,14 @@
*/
(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 (typeof navigator != 'undefined') {
+ function CordovaNavigator() {}
+ CordovaNavigator.prototype = navigator;
+ navigator = new CordovaNavigator();
+ }
+
var channel = require("cordova/channel"),
_self = {
boot: function () {