From b3f14df485d89ad7866573536fe07783e516a5ae Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Sat, 9 May 2020 18:41:53 +0300 Subject: [PATCH] doc: fix Buffer.from(object) documentation Only strings are supported for objects supporting `Symbol.toPrimitive`. PR-URL: https://github.com/nodejs/node/pull/33327 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater --- doc/api/buffer.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index c32060563faa49..89b08922339e61 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -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)`. @@ -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 {