Skip to content

Commit

Permalink
doc: note util.isError() @@toStringTag limitations
Browse files Browse the repository at this point in the history
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: nodejs#2201
PR-URL: nodejs#5414
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
cjihrig committed Feb 25, 2016
1 parent 33e51fe commit 54cbf28
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/api/util.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54cbf28

Please sign in to comment.