Skip to content

Commit

Permalink
console: treat non-strings as separate argument in console.assert()
Browse files Browse the repository at this point in the history
fixes #49680

PR-URL: #49722
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
jcbhmr authored Nov 1, 2023
1 parent 3095086 commit 60e8364
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,14 @@ const consoleMethods = {
this.error(err.stack);
},

// Defined by: https://console.spec.whatwg.org/#assert
assert(expression, ...args) {
if (!expression) {
args[0] = `Assertion failed${args.length === 0 ? '' : `: ${args[0]}`}`;
if (args.length && typeof args[0] === 'string') {
args[0] = `Assertion failed: ${args[0]}`;
} else {
ArrayPrototypeUnshift(args, 'Assertion failed');
}
// The arguments will be formatted in warn() again
ReflectApply(this.warn, this, args);
}
Expand Down
5 changes: 5 additions & 0 deletions test/message/console_assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

require('../common');

console.assert(false, Symbol('hello'));
1 change: 1 addition & 0 deletions test/message/console_assert.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Assertion failed* Symbol(hello)

0 comments on commit 60e8364

Please sign in to comment.