0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

assert: improve error check

Minor performance improvement.

PR-URL: https://github.com/nodejs/node/pull/17574
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Ruben Bridgewater 2017-12-09 14:13:34 -02:00
parent 4e15679c02
commit b5825e125c
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -342,11 +342,14 @@ class AssertionError extends Error {
red = '\u001b[31m';
}
const util = lazyUtil();
if (actual && actual.stack && actual instanceof Error)
if (typeof actual === 'object' && actual !== null &&
'stack' in actual && actual instanceof Error) {
actual = `${actual.name}: ${actual.message}`;
if (expected && expected.stack && expected instanceof Error)
}
if (typeof expected === 'object' && expected !== null &&
'stack' in expected && expected instanceof Error) {
expected = `${expected.name}: ${expected.message}`;
}
if (errorDiff === 0) {
let res = util.inspect(actual);