buffer: support boxed strings and toPrimitive#13725
buffer: support boxed strings and toPrimitive#13725jasnell wants to merge 1 commit intonodejs:masterfrom
Conversation
lib/buffer.js
Outdated
lib/buffer.js
Outdated
There was a problem hiding this comment.
IMHO we should be promoting this and the other more common cases to the top of this function. This is why typeof value === 'number' was at the very end for example.
There was a problem hiding this comment.
yeah, good point, I updated and shifted the number check back down a bit. It cannot be at the bottom like before because doing so causes the valueOf option to go into a recursion loop.
lib/buffer.js
Outdated
There was a problem hiding this comment.
I guess it would be good to use internal/errors here.
There was a problem hiding this comment.
I'm going to be updating the buffer errors all at once very soon.
lib/buffer.js
Outdated
There was a problem hiding this comment.
I wonder if we should be more cautious here or not, in case someone passes say Object.create(null). Perhaps value.valueOf && value.valueOf() at the very least ?
lib/buffer.js
Outdated
There was a problem hiding this comment.
We should call value[Symbol.toPrimitive] with a hint argument of 'string', I would say
lib/buffer.js
Outdated
There was a problem hiding this comment.
Now that we're supposedly no longer bound by Crankshaft's inlining limitations, perhaps we might also move the isUint8Array() case from fromObject() into this function, right below the isAnyArrayBuffer() case?
There was a problem hiding this comment.
I'm updating to handle the other suggestions, I'll look at this one separately.
|
Is there any real use to supporting |
doc/api/buffer.md
Outdated
There was a problem hiding this comment.
Maybe it's just me, but I'm missing the outcome. Like:
buf.toString() === 'this is a test'Or even:
console.log(buf)outputs:
<Buffer 74 68 69 73 20 69 73 20 61 20 74 65 73 74>
There was a problem hiding this comment.
Not sure I understand your point here.
There was a problem hiding this comment.
You show the correct usage, but not the expected outcome. It feels incomplete, but I don't have a strong opinion.
There was a problem hiding this comment.
Except something @addaleax wrote somewhere, maybe we'll be able to run the snippets in the docs as a sort of acceptance test. For that we need some assertion on outcomes.
lib/buffer.js
Outdated
There was a problem hiding this comment.
tiny nit: you can try to access properties on any !(value === undefined || value === null) value so maybe just (typeof value[Symbol.toPrimitive] === 'function')?
|
@Fishrock123 ... it's more about principle of least-surprise. The lack of support for |
9baef7f to
b38d925
Compare
|
Looks like this needs rebasing and lint errors fixed. |
Add support for `Buffer.from(new String('...'))` and
`Buffer.from({[Symbol.toPrimitive]() { return '...'; }})`
|
Ugh. The most recent commit on master broke linting and was force pushed 2 hours after landing. It appears that it was force pushed as I was submitting this which broke everything. Rebasing now and will restart it |
b38d925 to
9b4c8b2
Compare
Add support for `Buffer.from(new String('...'))` and
`Buffer.from({[Symbol.toPrimitive]() { return '...'; }})`
PR-URL: #13725
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
|
Landed in 22cf25c |
Add support for `Buffer.from(new String('...'))` and
`Buffer.from({[Symbol.toPrimitive]() { return '...'; }})`
PR-URL: #13725
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Add support for `Buffer.from(new String('...'))` and
`Buffer.from({[Symbol.toPrimitive]() { return '...'; }})`
PR-URL: #13725
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Add support for `Buffer.from(new String('...'))` and
`Buffer.from({[Symbol.toPrimitive]() { return '...'; }})`
PR-URL: #13725
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Add support for `Buffer.from(new String('...'))` and
`Buffer.from({[Symbol.toPrimitive]() { return '...'; }})`
PR-URL: #13725
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Add support for `Buffer.from(new String('...'))` and
`Buffer.from({[Symbol.toPrimitive]() { return '...'; }})`
PR-URL: #13725
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Add support for `Buffer.from(new String('...'))` and
`Buffer.from({[Symbol.toPrimitive]() { return '...'; }})`
PR-URL: #13725
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
|
Release team decided not to land on v6.x, if you disagree let us know. |
Add support for
Buffer.from(new String('...'))andBuffer.from({[Symbol.toPrimitive]() { return '...'; }})/cc @bnoordhuis @addaleax
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
buffer