-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
util: Add format for SharedArrayBuffer #8587
util: Add format for SharedArrayBuffer #8587
Conversation
Shouldn't we wait for this feature to become publicly available in V8 first? |
} else if (binding.isSharedArrayBuffer(value)) { | ||
braces = ['{', '}']; | ||
keys.unshift('byteLength'); | ||
visibleKeys.byteLength = true; |
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.
Just a suggestion but I think you can join this with the isArrayBuffer
case using ||
.
@@ -28,7 +28,8 @@ using v8::Value; | |||
V(isRegExp, IsRegExp) \ | |||
V(isSet, IsSet) \ | |||
V(isSetIterator, IsSetIterator) \ | |||
V(isTypedArray, IsTypedArray) | |||
V(isTypedArray, IsTypedArray) \ | |||
V(isSharedArrayBuffer, IsSharedArrayBuffer) |
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.
Note: If you rebase against master, this one should already be in the list due to #8510. Feel free to sort that in alphabetically, though. :)
uint8Array[i] = 'a'; | ||
} | ||
|
||
assert.equal(util.format(sab), 'SharedArrayBuffer { byteLength: 4 }'); |
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.
assert.strictEqual
?
Well, we’ve already done this for SIMD, and I think it’s okay to be prepared for a release where SABs work without |
8bc1f65
to
4e4ab76
Compare
Thank you for your review, I fixed them. |
I think we should wait until we have a strategy related to SharedArrayBuffer first. @petkaantonov worked on a PR that would enable just that (using SharedArrayBuffer like that) but afaik it is stalled. |
@@ -449,7 +449,7 @@ function formatValue(ctx, value, recurseTimes) { | |||
} | |||
// Fast path for ArrayBuffer. Can't do the same for DataView because it | |||
// has a non-primitive .buffer property that we need to recurse for. |
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.
Worth updating this comment too to include reference to SharedArrayBuffer
?
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.
Thanks!
@@ -29,6 +28,7 @@ using v8::Value; | |||
V(isRegExp, IsRegExp) \ | |||
V(isSet, IsSet) \ | |||
V(isSetIterator, IsSetIterator) \ | |||
V(isSharedArrayBuffer, IsSharedArrayBuffer) \ |
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.
Looks like this changes in this file can be removed (it's just moving the line).
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.
I just sort the line in alphabetical order.
const util = require('util'); | ||
|
||
// Pacify eslint. | ||
const SharedArrayBuffer = global.SharedArrayBuffer; |
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.
I don't know if there's a preference, but we can use eslints global
comment to pacify too
/* global SharedArrayBuffer */
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.
Thanks!
4e4ab76
to
e5c6df2
Compare
@benjamingr |
@yosuke-furukawa and what exactly would one do with a SharedArrayBuffer in Node? The underlying cluster implementation does not support it. |
@benjamingr Does that matter for this PR? The data structure is available in node (behind the v8 flag), and when used, the inspect output does not mirror that of the
|
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.
I'm good with adding this now. LGTM
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.
PR-URL: #8587 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Landed in ce7d307. Thank you! |
PR-URL: #8587 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
PR-URL: nodejs#8587 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
PR-URL: #8587 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
util
Description of change
SharedArrayBuffer is a new global object to share memories between workers.
Currently workers does not work in node, but future v8 has those new global objects.
This change supports a format for SharedArrayBuffer.
Note: this PR is from code-and-learn
nodejs/code-and-learn#56 (comment)