mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Ensure _.keys and _.keysIn always skip the constructor property on prototype objects.
This commit is contained in:
15
lodash.js
15
lodash.js
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user