Skip to content

Commit 99bdafc

Browse files
committed
doc: remove the buffer example using Symbol.toPrimitive
The single buffer API is the only one supporting Symbol.toPrimitive but ideally it should not be used. Remove the documentation to prevent users from potentially using this API.
1 parent 1ed3193 commit 99bdafc

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

doc/api/buffer.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -884,15 +884,18 @@ appropriate for `Buffer.from()` variants.
884884

885885
### Class Method: `Buffer.from(object[, offsetOrEncoding[, length]])`
886886
<!-- YAML
887+
changes:
888+
- version: REPLACEME
889+
pr-url: https://github.com/nodejs/node/pull/27051
890+
description: Dropped support for `Symbol.toPrimitive`.
887891
added: v8.2.0
888892
-->
889893

890-
* `object` {Object} An object supporting `Symbol.toPrimitive` or `valueOf()`.
894+
* `object` {Object} An object supporting `valueOf()`.
891895
* `offsetOrEncoding` {integer|string} A byte-offset or encoding, depending on
892-
the value returned either by `object.valueOf()` or
893-
`object[Symbol.toPrimitive]()`.
894-
* `length` {integer} A length, depending on the value returned either by
895-
`object.valueOf()` or `object[Symbol.toPrimitive]()`.
896+
the value returned by `object.valueOf()`.
897+
* `length` {integer} A length, depending on the value returned by
898+
`object.valueOf()`.
896899

897900
For objects whose `valueOf()` function returns a value not strictly equal to
898901
`object`, returns `Buffer.from(object.valueOf(), offsetOrEncoding, length)`.
@@ -902,20 +905,6 @@ const buf = Buffer.from(new String('this is a test'));
902905
// Prints: <Buffer 74 68 69 73 20 69 73 20 61 20 74 65 73 74>
903906
```
904907

905-
For objects that support `Symbol.toPrimitive`, returns
906-
`Buffer.from(object[Symbol.toPrimitive](), offsetOrEncoding, length)`.
907-
908-
```js
909-
class Foo {
910-
[Symbol.toPrimitive]() {
911-
return 'this is a test';
912-
}
913-
}
914-
915-
const buf = Buffer.from(new Foo(), 'utf8');
916-
// Prints: <Buffer 74 68 69 73 20 69 73 20 61 20 74 65 73 74>
917-
```
918-
919908
A `TypeError` will be thrown if `object` has not mentioned methods or is not of
920909
other type appropriate for `Buffer.from()` variants.
921910

0 commit comments

Comments
 (0)