From 22b51ed2327cbf817669aa1241762e240fe06952 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 9 Oct 2016 19:54:37 -0700 Subject: [PATCH] Refine `_.isError` checks to avoid false positives on plain objects. --- lodash.js | 6 ++++-- test/test.js | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index fecdae403..9bb98969d 100644 --- a/lodash.js +++ b/lodash.js @@ -88,6 +88,7 @@ arrayTag = '[object Array]', boolTag = '[object Boolean]', dateTag = '[object Date]', + domExcTag = '[object DOMException]', errorTag = '[object Error]', funcTag = '[object Function]', genTag = '[object GeneratorFunction]', @@ -11584,8 +11585,9 @@ if (!isObjectLike(value)) { return false; } - return (baseGetTag(value) == errorTag) || - (typeof value.message == 'string' && typeof value.name == 'string'); + var tag = baseGetTag(value); + return tag == errorTag || tag == domExcTag || + (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); } /** diff --git a/test/test.js b/test/test.js index 77b4be94b..04fb7633a 100644 --- a/test/test.js +++ b/test/test.js @@ -10425,6 +10425,12 @@ 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) { assert.expect(1);