mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Ensure shimIsPlainObject returns true for plain objects with a constructor property that has a function value.
This commit is contained in:
@@ -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;
|
||||
|
||||
22
test/test.js
22
test/test.js
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user