Skip to content

Commit 0c2b7c0

Browse files
seishuncodebytere
authored andcommitted
doc: fix Buffer.from(object) documentation
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]>
1 parent d153832 commit 0c2b7c0

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

doc/api/buffer.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,8 @@ added: v8.2.0
657657
-->
658658

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

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

674671
For objects that support `Symbol.toPrimitive`, returns
675-
`Buffer.from(object[Symbol.toPrimitive](), offsetOrEncoding, length)`.
672+
`Buffer.from(object[Symbol.toPrimitive]('string'), offsetOrEncoding)`.
676673

677674
```js
678675
class Foo {

0 commit comments

Comments
 (0)