Ensure _.keys and _.keysIn always skip the constructor property on prototype objects.

This commit is contained in:
John-David Dalton
2014-04-19 11:54:39 -07:00
parent 966283dd6d
commit f718284538
2 changed files with 24 additions and 16 deletions

View File

@@ -6572,8 +6572,11 @@
* // => ['x', 'y'] (property order is not guaranteed across environments)
*/
var keys = !nativeKeys ? shimKeys : function(object) {
var length = object ? object.length : 0;
if (typeof length == 'number' && length > 0) {
var ctor = object && object.constructor,
length = object ? object.length : 0;
if (typeof length == 'number' && length > 0 ||
(ctor && object === ctor.prototype)) {
return shimKeys(object);
}
return isObject(object) ? nativeKeys(object) : [];
@@ -6609,7 +6612,9 @@
(support.nonEnumArgs && isArguments(object))) && length) >>> 0;
var keyIndex,
ctor = object.constructor,
index = -1,
isProto = ctor && object === ctor.prototype,
maxIndex = length - 1,
result = Array(length),
skipIndexes = length > 0,
@@ -6620,7 +6625,8 @@
result[index] = String(index);
}
for (var key in object) {
if (!(skipProto && key == 'prototype') &&
if (!(isProto && key == 'constructor') &&
!(skipProto && key == 'prototype') &&
!(skipErrorProps && (key == 'message' || key == 'name')) &&
!(skipIndexes && (keyIndex = +key, keyIndex > -1 && keyIndex <= maxIndex && keyIndex % 1 == 0))) {
result.push(key);
@@ -6631,11 +6637,10 @@
// attribute of an existing property and the `constructor` property of a
// prototype defaults to non-enumerable.
if (support.nonEnumShadows && object !== objectProto) {
var ctor = object.constructor;
index = -1;
length = shadowedProps.length;
if (object === (ctor && ctor.prototype)) {
if (isProto) {
var className = object === stringProto ? stringClass : object === errorProto ? errorClass : toString.call(object),
nonEnum = nonEnumProps[className];
}