console: make .assert standard compliant

The standard does not throw and has no stack trace.
See https://console.spec.whatwg.org/#assert

PR-URL: https://github.com/nodejs/node/pull/17706
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Ruben Bridgewater 2017-12-16 01:40:28 -02:00
parent 9ca4ab1317
commit 15d880bcb6
No known key found for this signature in database
GPG key ID: F07496B3EB3C1762
3 changed files with 28 additions and 66 deletions

View file

@ -194,7 +194,8 @@ Console.prototype.trace = function trace(...args) {
Console.prototype.assert = function assert(expression, ...args) {
if (!expression) {
require('assert').ok(false, util.format.apply(null, args));
args[0] = `Assertion failed${args.length === 0 ? '' : `: ${args[0]}`}`;
this.warn(util.format.apply(null, args));
}
};