Browse Source

doc: note util.isError() @@toStringTag limitations

util.isError() is the only remaining util.is*() method that
depends on Object.prototype.toString() behavior. This commit
notes the limitations of isError() related to @@toStringTag.

Refs: https://github.com/nodejs/node/pull/2201
PR-URL: https://github.com/nodejs/node/pull/5414
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
v5.x
cjihrig 9 years ago
committed by Rod Vagg
parent
commit
e46915f2f3
  1. 16
      doc/api/util.markdown

16
doc/api/util.markdown

@ -335,6 +335,22 @@ util.isError({ name: 'Error', message: 'an error occurred' })
// false
```
Note that this method relies on `Object.prototype.toString()` behavior. It is
possible to obtain an incorrect result when the `object` argument manipulates
`@@toStringTag`.
```js
// This example requires the `--harmony-tostring` flag
const util = require('util');
const obj = { name: 'Error', message: 'an error occurred' };
util.isError(obj);
// false
obj[Symbol.toStringTag] = 'Error';
util.isError(obj);
// true
```
## util.isFunction(object)
Stability: 0 - Deprecated

Loading…
Cancel
Save