Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 54cbf28

Browse filesBrowse files
committed
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: #2201 PR-URL: #5414 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent 33e51fe commit 54cbf28
Copy full SHA for 54cbf28

File tree

Expand file treeCollapse file tree

1 file changed

+16
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/util.markdown‎

Copy file name to clipboardExpand all lines: doc/api/util.markdown
+16Lines changed: 16 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,22 @@ util.isError({ name: 'Error', message: 'an error occurred' })
335335
// false
336336
```
337337

338+
Note that this method relies on `Object.prototype.toString()` behavior. It is
339+
possible to obtain an incorrect result when the `object` argument manipulates
340+
`@@toStringTag`.
341+
342+
```js
343+
// This example requires the `--harmony-tostring` flag
344+
const util = require('util');
345+
const obj = { name: 'Error', message: 'an error occurred' };
346+
347+
util.isError(obj);
348+
// false
349+
obj[Symbol.toStringTag] = 'Error';
350+
util.isError(obj);
351+
// true
352+
```
353+
338354
## util.isFunction(object)
339355

340356
Stability: 0 - Deprecated

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.