Skip to content

Commit

Permalink
doc: fix Buffer.from(object) documentation
Browse files Browse the repository at this point in the history
Only strings are supported for objects supporting `Symbol.toPrimitive`.

PR-URL: #33327
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
seishun authored and codebytere committed Jun 18, 2020
1 parent d153832 commit 0c2b7c0
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,8 @@ added: v8.2.0
-->

* `object` {Object} An object supporting `Symbol.toPrimitive` or `valueOf()`.
* `offsetOrEncoding` {integer|string} A byte-offset or encoding, depending on
the value returned either by `object.valueOf()` or
`object[Symbol.toPrimitive]()`.
* `length` {integer} A length, depending on the value returned either by
`object.valueOf()` or `object[Symbol.toPrimitive]()`.
* `offsetOrEncoding` {integer|string} A byte-offset or encoding.
* `length` {integer} A length.

For objects whose `valueOf()` function returns a value not strictly equal to
`object`, returns `Buffer.from(object.valueOf(), offsetOrEncoding, length)`.
Expand All @@ -672,7 +669,7 @@ const buf = Buffer.from(new String('this is a test'));
```

For objects that support `Symbol.toPrimitive`, returns
`Buffer.from(object[Symbol.toPrimitive](), offsetOrEncoding, length)`.
`Buffer.from(object[Symbol.toPrimitive]('string'), offsetOrEncoding)`.

```js
class Foo {
Expand Down

0 comments on commit 0c2b7c0

Please sign in to comment.