mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Refine _.isError checks to avoid false positives on plain objects.
This commit is contained in:
@@ -88,6 +88,7 @@
|
|||||||
arrayTag = '[object Array]',
|
arrayTag = '[object Array]',
|
||||||
boolTag = '[object Boolean]',
|
boolTag = '[object Boolean]',
|
||||||
dateTag = '[object Date]',
|
dateTag = '[object Date]',
|
||||||
|
domExcTag = '[object DOMException]',
|
||||||
errorTag = '[object Error]',
|
errorTag = '[object Error]',
|
||||||
funcTag = '[object Function]',
|
funcTag = '[object Function]',
|
||||||
genTag = '[object GeneratorFunction]',
|
genTag = '[object GeneratorFunction]',
|
||||||
@@ -11584,8 +11585,9 @@
|
|||||||
if (!isObjectLike(value)) {
|
if (!isObjectLike(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (baseGetTag(value) == errorTag) ||
|
var tag = baseGetTag(value);
|
||||||
(typeof value.message == 'string' && typeof value.name == 'string');
|
return tag == errorTag || tag == domExcTag ||
|
||||||
|
(typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10425,6 +10425,12 @@
|
|||||||
assert.strictEqual(_.isError(symbol), false);
|
assert.strictEqual(_.isError(symbol), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should return `false` for plain objects', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
assert.strictEqual(_.isError({ 'name': 'Error', 'message': '' }), false);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should work with an error object from another realm', function(assert) {
|
QUnit.test('should work with an error object from another realm', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user