mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
console: treat non-strings as separate argument in console.assert()
fixes #49680 PR-URL: https://github.com/nodejs/node/pull/49722 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
30950864d3
commit
60e836427e
@ -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);
|
||||
}
|
||||
|
5
test/message/console_assert.js
Normal file
5
test/message/console_assert.js
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
|
||||
console.assert(false, Symbol('hello'));
|
1
test/message/console_assert.out
Normal file
1
test/message/console_assert.out
Normal file
@ -0,0 +1 @@
|
||||
Assertion failed* Symbol(hello)
|
Loading…
Reference in New Issue
Block a user