From e46915f2f3f76eff06f138110c1bfa5938ec3efe Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 24 Feb 2016 12:00:23 -0500 Subject: [PATCH] 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 --- doc/api/util.markdown | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/api/util.markdown b/doc/api/util.markdown index 713bded8bceacb..d9ad0df3138cfc 100644 --- a/doc/api/util.markdown +++ b/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