Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: treat non-strings as separate argument in console.assert() #49722

Merged
merged 6 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)