Use type checks when checking for a prototype property.

This commit is contained in:
John-David Dalton
2014-09-20 11:47:34 -07:00
parent 7976aa4b28
commit 1aafb6c2c1
2 changed files with 8 additions and 4 deletions

View File

@@ -7627,7 +7627,7 @@
var Ctor = object.constructor, var Ctor = object.constructor,
length = object.length; length = object.length;
} }
if ((Ctor && Ctor.prototype === object) || if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
(typeof length == 'number' && length > 0) || (typeof length == 'number' && length > 0) ||
(support.enumPrototypes && typeof object == 'function')) { (support.enumPrototypes && typeof object == 'function')) {
return shimKeys(object); return shimKeys(object);
@@ -7670,7 +7670,7 @@
var keyIndex, var keyIndex,
Ctor = object.constructor, Ctor = object.constructor,
index = -1, index = -1,
isProto = Ctor && Ctor.prototype === object, isProto = typeof Ctor == 'function' && Ctor.prototype === object,
maxIndex = length - 1, maxIndex = length - 1,
result = Array(length), result = Array(length),
skipIndexes = length > 0, skipIndexes = length > 0,
@@ -7947,7 +7947,7 @@
accumulator = []; accumulator = [];
} else if (isObject(object)) { } else if (isObject(object)) {
var Ctor = object.constructor; var Ctor = object.constructor;
accumulator = baseCreate(Ctor && Ctor.prototype); accumulator = baseCreate(typeof Ctor == 'function' && Ctor.prototype);
} else { } else {
accumulator = {}; accumulator = {};
} }

View File

@@ -6818,7 +6818,7 @@
deepEqual(func(Foo).sort(), expected); deepEqual(func(Foo).sort(), expected);
}); });
test('`_.' + methodName + '` skips the `constructor` property on prototype objects', 2, function() { test('`_.' + methodName + '` skips the `constructor` property on prototype objects', 3, function() {
function Foo() {} function Foo() {}
Foo.prototype.a = 1; Foo.prototype.a = 1;
@@ -6827,6 +6827,10 @@
Foo.prototype = { 'constructor': Foo, 'a': 1 }; Foo.prototype = { 'constructor': Foo, 'a': 1 };
deepEqual(func(Foo.prototype), ['a']); deepEqual(func(Foo.prototype), ['a']);
var Fake = { 'prototype': {} };
Fake.prototype.constructor = Fake;
deepEqual(func(Fake.prototype), ['constructor']);
}); });
test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties', 1, function() { test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties', 1, function() {