-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
buffer: make Buffer.from
throw on DataView
#48410
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This is a breaking change right? I think we should add semver-major label. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, the existing behavior of Buffer.from()
is compatible with Uint8Array.from()
in this regard, and since Buffer
extends Uint8Array
, it seems wrong to intentionally deviate from spec'd behavior.
Uint8Array.from(new DataView(new ArrayBuffer(100))).byteLength === 0
Uint8Array.from({ buffer: new ArrayBuffer(100) }).byteLength === 0
The specs of both 23.2.2.1
assert.deepStrictEqual(new Uint8Array(), Uint8Array.from({ buffer: new ArrayBuffer(8) }));
assert.deepStrictEqual(new Uint8Array(), Uint8Array.from(new DataView(new ArrayBuffer(8))));
assert.deepStrictEqual(new Uint8Array(), Uint8Array.from({ buffer: null }));
assert.deepStrictEqual(new Uint8Array(), Uint8Array.from({}));
assert.deepStrictEqual(new Uint8Array(), Uint8Array.from(123));
assert.deepStrictEqual(new Uint8Array(), Uint8Array.from(123n));
assert.deepStrictEqual(new Uint8Array(), Uint8Array.from(true)); Does that mean that |
I don't know. I am not generally in favor of adopting more web APIs where they don't make sense, but intentionally reducing compatibility with web APIs (as in this PR) does not seem helpful to me either. |
Passing
DataView
instance or arbitrary object with any ArrayBuffer in itsbuffer
property and without numericlength
property results in a new emptyBuffer
.This behaviour isn't documented, and is confusing since
buffer
property is checked but not used.