Skip to content

Commit 60e8364

Browse files
authored
console: treat non-strings as separate argument in console.assert()
fixes #49680 PR-URL: #49722 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 3095086 commit 60e8364

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/internal/console/constructor.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,14 @@ const consoleMethods = {
430430
this.error(err.stack);
431431
},
432432

433+
// Defined by: https://console.spec.whatwg.org/#assert
433434
assert(expression, ...args) {
434435
if (!expression) {
435-
args[0] = `Assertion failed${args.length === 0 ? '' : `: ${args[0]}`}`;
436+
if (args.length && typeof args[0] === 'string') {
437+
args[0] = `Assertion failed: ${args[0]}`;
438+
} else {
439+
ArrayPrototypeUnshift(args, 'Assertion failed');
440+
}
436441
// The arguments will be formatted in warn() again
437442
ReflectApply(this.warn, this, args);
438443
}

test/message/console_assert.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
console.assert(false, Symbol('hello'));

test/message/console_assert.out

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Assertion failed* Symbol(hello)

0 commit comments

Comments
 (0)