assert: support symbols as assertion messages

Currently, assertion messages are implicitly converted to strings,
which causes symbols to throw. This commit adds an explicit
string conversion.

PR-URL: https://github.com/nodejs/node/pull/20693
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
pull/20693/head
cjihrig 2018-05-12 22:15:06 -04:00
parent ee2a7703e7
commit 810af50ba2
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
2 changed files with 11 additions and 1 deletions

View File

@ -196,7 +196,7 @@ class AssertionError extends Error {
} = options;
if (message != null) {
super(message);
super(String(message));
} else {
if (process.stdout.isTTY) {
// Reset on each call to make sure we handle dynamically set environment

View File

@ -640,6 +640,16 @@ common.expectsError(
}
);
common.expectsError(
() => assert(false, Symbol('foo')),
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
generatedMessage: false,
message: 'Symbol(foo)'
}
);
{
// Test caching.
const fs = process.binding('fs');