Align _.keys with ES6 and coerce primitives to objects.

This commit is contained in:
John-David Dalton
2014-06-16 12:27:21 -07:00
parent 4f9da35b76
commit 73f6fd49d0
4 changed files with 26 additions and 18 deletions

View File

@@ -6990,15 +6990,17 @@
* // => ['x', 'y'] (property order is not guaranteed across environments)
*/
var keys = !nativeKeys ? shimKeys : function(object) {
var Ctor = object && object.constructor,
length = object ? object.length : 0;
object = Object(object);
var Ctor = object.constructor,
length = object.length;
if ((Ctor && object === Ctor.prototype) ||
(typeof length == 'number' && length > 0) ||
(support.enumPrototypes && typeof object == 'function')) {
return shimKeys(object);
}
return isObject(object) ? nativeKeys(object) : [];
return nativeKeys(object);
};
/**
@@ -7022,9 +7024,8 @@
* // => ['x', 'y', 'z'] (property order is not guaranteed across environments)
*/
function keysIn(object) {
if (!isObject(object)) {
return [];
}
object = Object(object);
var length = object.length;
length = (typeof length == 'number' && length > 0 &&
(isArray(object) || (support.nonEnumStrings && isString(object)) ||