From 99bdafceebfd603827bba8c93afdb01b7f91d2ef Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 12 Jan 2020 23:36:11 +0100 Subject: [PATCH] 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. --- doc/api/buffer.md | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index c94f03fa065a36..04040e324be39a 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -884,15 +884,18 @@ appropriate for `Buffer.from()` variants. ### Class Method: `Buffer.from(object[, offsetOrEncoding[, length]])` -* `object` {Object} An object supporting `Symbol.toPrimitive` or `valueOf()`. +* `object` {Object} An object supporting `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]()`. + the value returned by `object.valueOf()`. +* `length` {integer} A length, depending on the value returned by + `object.valueOf()`. For objects whose `valueOf()` function returns a value not strictly equal to `object`, returns `Buffer.from(object.valueOf(), offsetOrEncoding, length)`. @@ -902,20 +905,6 @@ const buf = Buffer.from(new String('this is a test')); // Prints: ``` -For objects that support `Symbol.toPrimitive`, returns -`Buffer.from(object[Symbol.toPrimitive](), offsetOrEncoding, length)`. - -```js -class Foo { - [Symbol.toPrimitive]() { - return 'this is a test'; - } -} - -const buf = Buffer.from(new Foo(), 'utf8'); -// Prints: -``` - A `TypeError` will be thrown if `object` has not mentioned methods or is not of other type appropriate for `Buffer.from()` variants.