Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
buffer: add{read|write}[U]Int64{BE|LE} methods#15152
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
mscdex commented Sep 2, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I'm leaning more towards -1 because of the current lack of support in the language (and thus an inconsistency with the return values for the 64-bit However, it is probably best to just wait until something like the BigInt ES proposal gets accepted before adding 64-bit integer support. |
seishun commented Sep 2, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
(edited because the message above was edited)
Do we do that anywhere where the integer could be greater than
They can use Would you be less opposed to returning a number when it's less than
That's far in the future. Besides, with BigInt reading 64-bit integers would still be inconsistent. |
mscdex commented Sep 2, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
So there would be an inconsistency in how we deal with 64-bit integer values in core. I don't think that would be a good thing.
Maybe, maybe not. It's already at stage 3. Besides, we've gone this long without 64-bit integer Buffer |
seishun commented Sep 2, 2017
Can you give specific examples?
I'm not convinced that using BigInt would be the most appropriate way. A common usecase for 64-bit integers is some kind of an identifier, in which case a primitive is more convenient (and actually more consistent with other read/write functions). |
addaleax left a comment
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 see anything terribly wrong with this, fwiw.
doc/api/buffer.md 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.
<!-- YAML added: replaceme --> :)
src/node_buffer.cc 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.
Can you use the overload that takes a context argument?
seishunSep 11, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
doc/api/buffer.md 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.
is this accurate?
src/node_buffer.cc 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.
ditto (using the non-deprecated overload taking a context argument)
seishunSep 3, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
@addaleax I didn't realize that this overload is deprecated. Is this documented somewhere?
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.
@seishun Yes:
Lines 2297 to 2309 in 94be2b1
| V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const; | |
| V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const; | |
| V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue( | |
| Local<Context> context) const; | |
| V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value( | |
| Local<Context> context) const; | |
| V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const; | |
| V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const); | |
| V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const); | |
| V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const); | |
| V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const); | |
| V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const); |
And also V8 API changes:
Ongoing and Planned Changes
... APIs that are marked as
V8_DEPRECATE_SOONwill be marked asV8_DEPRECATEDin the future. APIs marked asV8_DEPRECATEDwill usually be removed after one V8 release.
- Introduction of MaybeLocal<> and Maybe<> APIs: bug
- ...
TimothyGu commented Sep 3, 2017
I don't see the necessity of waiting until BigInt. In fact when it's introduced we can add a readBig[U]Int64 to match DataView. IMO returning a string isn't ideal, but the fact that the developer can cast it easily to a number by prefixing a |
jasnell commented Sep 5, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Just alternatively, the return could be an array similar to that used by |
seishun commented Sep 7, 2017
@jasnell an array is difficult to convert to either a number or a string, and it would be inconsistent with other |
tniessen left a comment
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 wonder which possible use cases this might benefit. Sure, people can read 64 bit values as strings, and can then parse (some of them!) as numbers, but there is not even a guarantee that arithmetic operations with those numbers will be accurate, and there is still no fixed-size arithmetic.
If you decide to return numbers as a decimal representation, that should probably be mentioned in the docs.
doc/api/buffer.md 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.
32 → 64
doc/api/buffer.md 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.
32 → 64
seishun commented Sep 8, 2017
Not everyone requires arithmetic operations on the values they read or write. As I've mentioned before, 64-bit integers are often used as identifiers, for example SteamID. |
seishun commented Sep 10, 2017
cc @nodejs/collaborators need more input. |
benjamingr commented Sep 11, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@littledan how far is BigInt from V8? Edit: found https://bugs.chromium.org/p/v8/issues/detail?id=6791 |
mcollina commented Sep 12, 2017
IMHO we should wait for BigInt. |
bnoordhuis commented Sep 12, 2017
Sorry, missed that I was asked to review this. I'm also in the "Waiting for Godot^WBigInt" camp; it's at stage 3, implementation work has started, it won't be long (no C programmer pun intended.) |
littledan commented Sep 12, 2017
I'm working on BigInt specifically in order to enable these use cases. Strings seem like a functioning workaround, but I'm wondering what's motivating adding this to core right now at a time when BigInts are actually under development. |
benjamingr commented Sep 12, 2017
Well, there are several reasons Node.js might do this:
That said, I vote "wait for BigInt" too. |
tniessen commented Sep 12, 2017
Whether BigInt is coming or not, I am not convinced that we should represent decimals as strings just to make them accessible at all (even though I won't block this PR). I think very few users need to represent 64 bit numbers as decimal strings and even fewer need to use a buffer to convert to and from those numbers. With BigInt coming up, we got a promising alternative, which only reinforces my opinion. |
ronkorving commented Sep 13, 2017
I believe we should be conservative with breaking (in this case, future) API, and we should always aim for consistency and elegance when it comes to naming things. Given that, I'm also voting we wait for BigInt. |
benjamingr left a comment
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.
Making it explicit
BridgeAR commented Sep 13, 2017
@seishun I am sure this was quite some work but I think this will not land and I would rather close it for now. Are you ok with that? I think it is a good basis for a PR as soon as v8 supports BigInt out of the box! |
seishun commented Sep 13, 2017
Yes, I'm okay with that. |
seishun commented Sep 23, 2017
@littledan@mscdex@bnoordhuis Any way I can be informed when a V8 version with BigInt support makes it to Node.js? |
mscdex commented Sep 23, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@seishun Not really (other than reading V8/node changelogs), but for right now you can track the BigInt repo or the ECMAScript finished proposals list to watch for when the BigInt proposal reaches stage 4 (finished). I doubt V8 would add support for BigInt (behind a flag or otherwise) before it reaches stage 4, but I could be wrong about that as I don't know of their plans. |
vsemozhetbyt commented Sep 23, 2017
@seishun You can also track this issue: https://bugs.chromium.org/p/v8/issues/detail?id=6791 |
mscdex commented Sep 23, 2017
It does look like they do have it behind a flag ( |
This is basically a resurrection of @TooTallNate's PR #1750 with a couple differences:
read[U]Int64{BE|LE}always returns strings to make the output more predictable.address()method, and thus no changes to the inspect output for BuffersI'm not sure how to deal with attribution. @TooTallNate did most of the work here, but I also did significant work rebasing and updating.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
buffer