-
Notifications
You must be signed in to change notification settings - Fork 24
STREAMS-1895: Add old shell compatibility of NumberLong for JS Engine #16
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
Conversation
snippets/mongocompat/mongotypes.js
Outdated
|
|
||
| NumberLong.prototype.nativeToString = NumberLong.prototype.toString; | ||
| NumberLong.prototype.toString = function () { | ||
| return `NumberLong(${this.nativeToString()})`; |
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.
That won't catch all cases correctly – if the number is larger than 2**31-1 in magnitude, then the legacy server added quotes around the value
(mongosh intentionally always adds quotes, and I'd consider going that route here too, even if it limits compatibility with the legacy server shell/$function)
snippets/mongocompat/mongotypes.js
Outdated
| const str = this.nativeToString(); | ||
| const bigIntValue = BigInt(str); | ||
| const unsigned64 = bigIntValue < 0n | ||
| ? bigIntValue + (1n << 64n) | ||
| : bigIntValue; | ||
| return Number((unsigned64 >> 32n) & 0xFFFFFFFFn); |
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.
| const str = this.nativeToString(); | |
| const bigIntValue = BigInt(str); | |
| const unsigned64 = bigIntValue < 0n | |
| ? bigIntValue + (1n << 64n) | |
| : bigIntValue; | |
| return Number((unsigned64 >> 32n) & 0xFFFFFFFFn); | |
| return this.high; |
snippets/mongocompat/mongotypes.js
Outdated
| const str = this.nativeToString(); | ||
| const bigIntValue = BigInt(str); | ||
| const unsigned64 = bigIntValue < 0n | ||
| ? bigIntValue + (1n << 64n) | ||
| : bigIntValue; | ||
| return Number(unsigned64 & 0xFFFFFFFFn); |
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.
| const str = this.nativeToString(); | |
| const bigIntValue = BigInt(str); | |
| const unsigned64 = bigIntValue < 0n | |
| ? bigIntValue + (1n << 64n) | |
| : bigIntValue; | |
| return Number(unsigned64 & 0xFFFFFFFFn); | |
| return this.low; |
(you'll want to also verify that these have the correct signedness for negative values)
|
Published in |
No description provided.