mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
fix(angular.equals): do not match keys defined in the prototype chain
Merely testing for object[key] will give incorrect results on keys defined in Object.prototype. Note: IE8 is generally broken in this regard since `for...in` never returns certain property keys even if they are defined directly on the object. See #2141 - partially merges this PR
This commit is contained in:
committed by
Pete Bacon Darwin
parent
d88dc4a64f
commit
7829c50f9e
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user