aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Angular.js12
-rw-r--r--test/AngularSpec.js8
2 files changed, 19 insertions, 1 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 53b53239..98d32a7e 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -3,6 +3,16 @@
////////////////////////////////////
/**
+ * hasOwnProperty may be overriden by a property of the same name, or entirely
+ * absent from an object that does not inherit Object.prototype; this copy is
+ * used instead
+ */
+var hasOwnPropertyFn = Object.prototype.hasOwnProperty;
+var hasOwnPropertyLocal = function(obj, key) {
+ return hasOwnPropertyFn.call(obj, key);
+};
+
+/**
* @ngdoc function
* @name angular.lowercase
* @function
@@ -685,7 +695,7 @@ function equals(o1, o2) {
keySet[key] = true;
}
for(key in o2) {
- if (!keySet[key] &&
+ if (!keySet.hasOwnProperty(key) &&
key.charAt(0) !== '$' &&
o2[key] !== undefined &&
!isFunction(o2[key])) return false;
diff --git a/test/AngularSpec.js b/test/AngularSpec.js
index 8fda7a65..bf952249 100644
--- a/test/AngularSpec.js
+++ b/test/AngularSpec.js
@@ -270,6 +270,14 @@ describe('angular', function() {
expect(equals(new Date(0), 0)).toBe(false);
expect(equals(0, new Date(0))).toBe(false);
});
+
+ it('should correctly test for keys that are present on Object.prototype', function() {
+ // MS IE8 just doesn't work for this kind of thing, since "for ... in" doesn't return
+ // things like hasOwnProperty even if it is explicitly defined on the actual object!
+ if (msie<=8) return;
+ expect(equals({}, {hasOwnProperty: 1})).toBe(false);
+ expect(equals({}, {toString: null})).toBe(false);
+ });
});
describe('size', function() {