Avoid a hasOwnProperty bug in IE 10-11 where objects with a [[Prototype]] of null incorrectly report false for own index properties.

This commit is contained in:
John-David Dalton
2015-10-01 22:16:13 -07:00
parent b3f6426d36
commit 9558048906
2 changed files with 39 additions and 20 deletions

View File

@@ -2322,7 +2322,13 @@
* @returns {boolean} Returns `true` if `key` exists, else `false`.
*/
function baseHas(object, key) {
return object != null && hasOwnProperty.call(object, key);
if (object == null) {
return false;
}
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`
// incorrectly report `false` for own index properties.
return hasOwnProperty.call(object, key) ||
(typeof object == 'object' && key in object && getPrototypeOf(object) === null);
}
/**
@@ -3984,7 +3990,7 @@
var index = objLength;
while (index--) {
var key = objProps[index];
if (!(isPartial ? key in other : hasOwnProperty.call(other, key)) ||
if (!(isPartial ? key in other : baseHas(other, key)) ||
!(isUnordered || key == othProps[index])) {
return false;
}
@@ -9941,7 +9947,7 @@
skipIndexes = !!length;
for (var key in object) {
if (hasOwnProperty.call(object, key) &&
if (baseHas(object, key) &&
!(skipIndexes && isIndex(key, length)) &&
!(isProto && key == 'constructor')) {
result.push(key);