cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [3/3] js commit: [all] Use JS getters to clobber getters in buider.js
Date Wed, 07 Nov 2012 20:19:04 GMT
[all] Use JS getters to clobber getters in buider.js

Required to get navigator.connection to work correctly (CB-1807)


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/41ef8a73
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/41ef8a73
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/41ef8a73

Branch: refs/heads/master
Commit: 41ef8a73d4eae43640f3d8242e965eb5eba22ec0
Parents: 72bf85c
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Nov 7 15:10:38 2012 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Nov 7 15:17:52 2012 -0500

----------------------------------------------------------------------
 lib/common/builder.js |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/41ef8a73/lib/common/builder.js
----------------------------------------------------------------------
diff --git a/lib/common/builder.js b/lib/common/builder.js
index 475ed29..1c74bff 100644
--- a/lib/common/builder.js
+++ b/lib/common/builder.js
@@ -29,14 +29,24 @@ function each(objects, func, context) {
     }
 }
 
+function clobber(obj, key, value) {
+    obj[key] = value;
+    // Getters can only be overridden by getters.
+    if (obj[key] !== value) {
+        utils.defineGetter(obj, key, function() {
+            return value;
+        });
+    }
+}
+
 function assignOrWrapInDeprecateGetter(obj, key, value, message) {
     if (message) {
         utils.defineGetter(obj, key, function() {
-            window.console && console.log(message);
+            console.log(message);
             return value;
         });
     } else {
-        obj[key] = value;
+        clobber(obj, key, value);
     }
 }
 
@@ -95,8 +105,11 @@ function recursiveMerge(target, src) {
                 // If the target object is a constructor override off prototype.
                 target.prototype[prop] = src[prop];
             } else {
-                target[prop] = typeof src[prop] === 'object' ? recursiveMerge(
-                        target[prop], src[prop]) : src[prop];
+                if (typeof src[prop] === 'object') {
+                    target[prop] = recursiveMerge(target[prop], src[prop]);
+                } else {
+                    clobber(target, prop, src[prop]);
+                }
             }
         }
     }


Mime
View raw message