Fixes an issue where Buffer.from was not supporting SharedArrayBuffer#8510
Fixes an issue where Buffer.from was not supporting SharedArrayBuffer#8510ojss wants to merge 6 commits intonodejs:masterfrom
Conversation
There was a problem hiding this comment.
This is already set in the main project .eslintrc file so this comment should be unnecessary, unless there's something I'm missing.
There was a problem hiding this comment.
The second line isn't necessary but the first one is absolutely required or else the linter fails.
add value method map to check if given object is a SharedArrayBuffer.
add an isSharedBuffer check to Buffer.from() fromArrayBuffer() can now handle a SharedArrayBuffer object. Fixes an issue where Buffer.from was not supporting SharedArrayBuffer Fixes: nodejs#8440
refer issue nodejs#8440
|
@mscdex I will be force pushing a squashed set of commits is that alright? |
|
@ojss Yes |
| ar[1] = 4000; | ||
|
|
||
| var arr_buf = Buffer.from(arr.buffer); | ||
| var ar_buf = Buffer.from(ar.buffer); |
There was a problem hiding this comment.
I think these can be const, too
|
Hi @ojss, this looks great so far! There are a couple of other places in |
|
@addaleax namely these areas I assume: Will do. :) |
|
@ojss exactly, thanks! |
Updated test-buffer-sharedarraybuffer.js to have more readable variable names. Replaced var definitions with const.
|
@addaleax please have a look. |
lib/buffer.js
Outdated
There was a problem hiding this comment.
Although I prefer this style as well, this project's style places the operators on the right-hand side:
if (isArrayBuffer(obj.buffer) || 'length' in obj ||
isSharedArrayBuffer(obj)) {You might also move the second condition to a new line as well to make the code easier to scan visually.
Added a isSharedArrayBuffer check in Buffer.byteLength method. Added a isSharedArrayBuffer check in fromObject method. Buffer.byteLength can potentially benefit from this change as it can be used interchangeably with the byteLength property of SharedArrayBuffer.
The new assertion checks of the output of Buffer.byteLength() is equal to the SharedArrayBuffer property byteLength.
|
|
||
| if (obj) { | ||
| if (isArrayBuffer(obj.buffer) || 'length' in obj) { | ||
| if (isArrayBuffer(obj.buffer) || 'length' in obj || |
|
@ojss Just CI infrastructure issues. LGTM. |
|
Awesome, great to have you on board! It’s quite usual that it takes a couple of days until PRs are landed, but if you feel like something is ready to land and it has been a while, pinging is exactly the right thing to do. |
| if (obj) { | ||
| if (isArrayBuffer(obj.buffer) || 'length' in obj) { | ||
| if (isArrayBuffer(obj.buffer) || 'length' in obj || | ||
| isSharedArrayBuffer(obj)) { |
There was a problem hiding this comment.
@addaleax you're right! I am so sorry about this mistake, I will fix this right away.
There was a problem hiding this comment.
Yeah, sorry I didn’t notice that during review myself! :/
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
wait. this already landed. okay, ill take care of it another time.
|
@thealphanerd yeah… no… maybe? Is there some kind of succinct description of what commits should or should not go into LTS branches that one could judge commits by? I think I’ve heard something like “changes that increase stability”, and I wouldn’t count this as such. It’s really not that important for v4, it only adds more support for a feature that’s still behind a flag. |
|
@addaleax that was exactly what I wanted to know, if it is behind a flag then it shouldn't land Thanks |
isSharedArrayBuffer in fromObject was missing obj.buffer moved the 'length' in obj check so that it is checked first making the code slightly more performant and able to handle SharedArrayBuffer without relying on an explicit check. Ref: #8510 PR-URL: #8739 Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
isSharedArrayBuffer in fromObject was missing obj.buffer moved the 'length' in obj check so that it is checked first making the code slightly more performant and able to handle SharedArrayBuffer without relying on an explicit check. Ref: #8510 PR-URL: #8739 Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
isSharedArrayBuffer in fromObject was missing obj.buffer moved the 'length' in obj check so that it is checked first making the code slightly more performant and able to handle SharedArrayBuffer without relying on an explicit check. Ref: #8510 PR-URL: #8739 Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Checklist
make -j4 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
Description of change
Exposes
isSharedArrayBufferto check forSharedArrayBuffertype object in JS.Buffer.from can now take a
SharedArrayBufferas an argument.refer to issue #8440.