Ensure shimIsPlainObject returns true for plain objects with a constructor property that has a function value.

This commit is contained in:
John-David Dalton
2014-01-05 13:49:18 -06:00
parent b926ed7b00
commit 16dfdbe314
2 changed files with 15 additions and 10 deletions

View File

@@ -1948,7 +1948,8 @@
// avoid non Object objects, `arguments` objects, and DOM elements
if (!(value && toString.call(value) == objectClass) ||
(ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor)) ||
(!hasOwnProperty.call(value, 'constructor') &&
(ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor))) ||
(!support.argsClass && isArguments(value)) ||
(!support.nodeClass && isNode(value))) {
return false;

View File

@@ -4519,20 +4519,20 @@
this.a = 1;
}
strictEqual(_.isPlainObject(new Foo(1)), false);
strictEqual(_.isPlainObject([1, 2, 3]), false);
strictEqual(_.isPlainObject({}), true);
strictEqual(_.isPlainObject({ 'a': 1 }), true);
strictEqual(_.isPlainObject({ 'constructor': Foo }), true);
strictEqual(_.isPlainObject([1, 2, 3]), false);
strictEqual(_.isPlainObject(new Foo(1)), false);
});
test('should return `true` for objects a [[Prototype]] of `null`', 1, function() {
if (create) {
strictEqual(_.isPlainObject(create(null)), true);
} else {
skipTest();
}
if (element) {
strictEqual(_.isPlainObject(element), false);
} else {
skipTest();
}
});
test('should return `true` for plain objects with a custom `valueOf` property', 2, function() {
@@ -4549,8 +4549,12 @@
}
});
test('should return `true` for empty objects', 1, function() {
strictEqual(_.isPlainObject({}), true);
test('should return `false` for DOM elements', 1, function() {
if (element) {
strictEqual(_.isPlainObject(element), false);
} else {
skipTest();
}
});
test('should return `false` for Object objects without a [[Class]] of "Object"', 3, function() {