Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
console: treat non-strings as separate argument in console.assert()
fixes #49680
  • Loading branch information
jcbhmr authored Sep 19, 2023
commit 9ac6528588ea7785b99e4433381cfa523591db87
7 changes: 6 additions & 1 deletion lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,12 @@ const consoleMethods = {

assert(expression, ...args) {
if (!expression) {
args[0] = `Assertion failed${args.length === 0 ? '' : `: ${args[0]}`}`;
// https://console.spec.whatwg.org/#assert step 4.2:
if (typeof args[0] === "string") {
args[0] = `Assertion failed: ${args[0]}`
} else {
ArrayPrototypeUnshift(args, "Assertion failed")
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// https://console.spec.whatwg.org/#assert step 4.2:
if (typeof args[0] === "string") {
args[0] = `Assertion failed: ${args[0]}`
} else {
ArrayPrototypeUnshift(args, "Assertion failed")
}
let baseMessage = 'Assertion failed';
if (args.length > 0) {
baseMessage += ':';
}
ArrayPrototypeUnshift(args, "Assertion failed");

That way it's always consistent and I would not add the documentation reference as it might change it's location without the comment being updated.

// The arguments will be formatted in warn() again
ReflectApply(this.warn, this, args);
}
Expand Down