Skip to content
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

Fixes an issue where Buffer.from was not supporting SharedArrayBuffer #8510

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ function fromObject(obj) {
}

if (obj) {
if (isArrayBuffer(obj.buffer) || 'length' in obj) {
if (isArrayBuffer(obj.buffer) || 'length' in obj ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mscdex changed the style here.

isSharedArrayBuffer(obj)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ojss Should this have been obj.buffer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax you're right! I am so sorry about this mistake, I will fix this right away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry I didn’t notice that during review myself! :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we're at it can we do something about 'length' in obj? by "do something" i mean let's just simplify it for !!obj.length or some such. using in here is wasting a lot of performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait. this already landed. okay, ill take care of it another time.

if (typeof obj.length !== 'number' || obj.length !== obj.length) {
return new FastBuffer();
}
Expand Down Expand Up @@ -351,8 +352,10 @@ function base64ByteLength(str, bytes) {

function byteLength(string, encoding) {
if (typeof string !== 'string') {
if (ArrayBuffer.isView(string) || isArrayBuffer(string))
if (ArrayBuffer.isView(string) || isArrayBuffer(string) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the style and added {}

isSharedArrayBuffer(string)) {
return string.byteLength;
}

string = '' + string;
}
Expand Down