summaryrefslogtreecommitdiff
path: root/doc/api/console.md
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-12-16 01:40:28 -0200
committerRuben Bridgewater <ruben@bridgewater.de>2017-12-26 10:46:27 +0100
commit15d880bcb62c628f1e7c3cc7baf659a63b312c7c (patch)
tree22d31adf9129d836fc1236eb8bc4b8979dc0239a /doc/api/console.md
parent9ca4ab13171f2148a986062ac564161a1f6e124f (diff)
downloadandroid-node-v8-15d880bcb62c628f1e7c3cc7baf659a63b312c7c.tar.gz
android-node-v8-15d880bcb62c628f1e7c3cc7baf659a63b312c7c.tar.bz2
android-node-v8-15d880bcb62c628f1e7c3cc7baf659a63b312c7c.zip
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>
Diffstat (limited to 'doc/api/console.md')
-rw-r--r--doc/api/console.md70
1 files changed, 16 insertions, 54 deletions
diff --git a/doc/api/console.md b/doc/api/console.md
index 84b7e2c11d..76f6c6ac46 100644
--- a/doc/api/console.md
+++ b/doc/api/console.md
@@ -103,70 +103,33 @@ The global `console` is a special `Console` whose output is sent to
new Console(process.stdout, process.stderr);
```
-### console.assert(value[, message][, ...args])
+### console.assert(value[, ...message])
<!-- YAML
added: v0.1.101
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/REPLACEME
+ description: The implementation is now spec compliant and does not throw
+ anymore.
-->
-* `value` {any}
-* `message` {any}
-* `...args` {any}
+* `value` {any} The value tested for being truthy.
+* `...message` {any} All arguments besides `value` are used as error message.
A simple assertion test that verifies whether `value` is truthy. If it is not,
-an `AssertionError` is thrown. If provided, the error `message` is formatted
-using [`util.format()`][] and used as the error message.
+`Assertion failed` is logged. If provided, the error `message` is formatted
+using [`util.format()`][] by passing along all message arguments. The output is
+used as the error message.
```js
console.assert(true, 'does nothing');
// OK
-console.assert(false, 'Whoops %s', 'didn\'t work');
-// AssertionError: Whoops didn't work
+console.assert(false, 'Whoops %s work', 'didn\'t');
+// Assertion failed: Whoops didn't work
```
-*Note*: The `console.assert()` method is implemented differently in Node.js
-than the `console.assert()` method [available in browsers][web-api-assert].
-
-Specifically, in browsers, calling `console.assert()` with a falsy
-assertion will cause the `message` to be printed to the console without
-interrupting execution of subsequent code. In Node.js, however, a falsy
-assertion will cause an `AssertionError` to be thrown.
-
-Functionality approximating that implemented by browsers can be implemented
-by extending Node.js' `console` and overriding the `console.assert()` method.
-
-In the following example, a simple module is created that extends and overrides
-the default behavior of `console` in Node.js.
-
-<!-- eslint-disable func-name-matching -->
-```js
-'use strict';
-
-// Creates a simple extension of console with a
-// new impl for assert without monkey-patching.
-const myConsole = Object.create(console, {
- assert: {
- value: function assert(assertion, message, ...args) {
- try {
- console.assert(assertion, message, ...args);
- } catch (err) {
- console.error(err.stack);
- }
- },
- configurable: true,
- enumerable: true,
- writable: true,
- },
-});
-
-module.exports = myConsole;
-```
-
-This can then be used as a direct replacement for the built in console:
-
-```js
-const console = require('./myConsole');
-console.assert(false, 'this message will print, but no error thrown');
-console.log('this will also print');
-```
+*Note*: Calling `console.assert()` with a falsy assertion will only cause the
+`message` to be printed to the console without interrupting execution of
+subsequent code.
### console.clear()
<!-- YAML
@@ -531,4 +494,3 @@ This method does not display anything unless used in the inspector. The
[customizing `util.inspect()` colors]: util.html#util_customizing_util_inspect_colors
[inspector]: debugger.html
[note on process I/O]: process.html#process_a_note_on_process_i_o
-[web-api-assert]: https://developer.mozilla.org/en-US/docs/Web/API/console/assert