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: #2201
PR-URL: #5414
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
  • Loading branch information
cjihrig authored and rvagg committed Feb 27, 2016
1 parent 51db48f commit e46915f
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 e46915f

Please sign in to comment.