Skip to content

Commit

Permalink
Fix IE non-enumerable properties
Browse files Browse the repository at this point in the history
I’m not sure what we were doing before with the `FuncProto`…
  • Loading branch information
jridgewell committed Feb 20, 2015
1 parent cd725e1 commit 5bfd4f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
A.prototype.foo = 'foo';
var b = new A();
b.bar = 'bar';
deepEqual(_.allKeys(b), ['bar', 'foo'], 'should include inherited keys');
deepEqual(_.allKeys(b).sort(), ['bar', 'foo'], 'should include inherited keys');

function y() {}
y.x = 'z';
Expand Down
14 changes: 9 additions & 5 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,17 +896,21 @@

// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString',
var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];

function collectNonEnumProps(obj, keys) {
var nonEnumIdx = nonEnumerableProps.length;
var proto = typeof obj.constructor === 'function' ? FuncProto : ObjProto;
var constructor = obj.constructor;
var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto;

// Constructor is a special case.
var prop = 'constructor';
if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);

while (nonEnumIdx--) {
var prop = nonEnumerableProps[nonEnumIdx];
if (prop === 'constructor' ? _.has(obj, prop) : prop in obj &&
obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
prop = nonEnumerableProps[nonEnumIdx];
if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
keys.push(prop);
}
}
Expand Down

0 comments on commit 5bfd4f9

Please sign in to comment.