[SERVER-1672] (new NumberLong(3754)==new NumberLong(3754)) evals to false Created: 24/Aug/10 Updated: 08/Jan/24 Resolved: 20/May/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | JavaScript |
| Affects Version/s: | 1.6.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Trivial - P5 |
| Reporter: | Brian C. Dilley | Assignee: | DO NOT USE - Backlog - Platform Team |
| Resolution: | Won't Fix | Votes: | 3 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Ubuntu Linux - mongo client console |
||
| Issue Links: |
|
||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||
| Description |
|
> (new NumberLong(3754)==new NumberLong(3754)) I ran into this issue when creating a $where function that compared numbers. |
| Comments |
| Comment by Mira Carey [ 20/May/16 ] |
|
Javascript as an ecosystem has made a decision not to support operator overloading, so however much we'd like to make our types operate as native types, we just can't provide those semantics. It might be worth considering an arithmetic library solution that could be extended with our types, but that wouldn't be the asked for functionality in this ticket. |
| Comment by Stephen Nelson [ 30/Apr/12 ] |
|
Workaround: use String(NumberLong(..)) to compare string representations. |
| Comment by Brian C. Dilley [ 17/Sep/11 ] |
|
How is this a "feature request". We're unable to compare equality for numbers of type NumberLong! There must be a way to define an equals implementation for objects in V8... in fact, does it just not use whatever the underlying c++ object uses for equality (ie: == operator)? |
| Comment by Guanqun Lu [ 17/Sep/11 ] |
|
@Antoine I agree that if it's hard to implement it in v8, then we just ignore this feature request... |
| Comment by Antoine Girbal [ 17/Sep/11 ] |
|
Looking at v8 sources, it doesnt seem that there is a way to override the equals behavior. One way to compare would be: |
| Comment by Moses Nakamura [ 12/Jun/11 ] |
|
I think it's more important that (new NumberLong(3754)===new NumberLong(3754)) evaluates to true, rather than with the == equality operator. The == operator should eval both of the NumberLong(3754) to native js 3754 numbers before comparing equality, while === should keep them in NumberLong format and see if they are identical. |
| Comment by Guanqun Lu [ 10/Jan/11 ] |
|
v8 doesn't have as many documents as spidermonkey does. not sure how to do this... btw: I'm ok with the test case being commented out. |
| Comment by Eliot Horowitz (Inactive) [ 08/Jan/11 ] |
|
The only problem with merging this is we need to support v8 at the same time. |
| Comment by Guanqun Lu [ 08/Jan/11 ] |
|
Thanks to Brian's directions, I've made up a simple patch for this and add three test cases for it. |
| Comment by Eliot Horowitz (Inactive) [ 26/Aug/10 ] |
|
Hmm.. missed that. |
| Comment by Brian C. Dilley [ 26/Aug/10 ] |
|
Although I haven't looked at the mongo code at all - i have embedded SpiderMonkey in various applications and game engines - usually you use an JSEqualityOp callback on the JSExtendedClass: |
| Comment by Eliot Horowitz (Inactive) [ 25/Aug/10 ] |
|
This is nearly impossible because of javascript semantics. Unless someone else knows how to do this - I think is not going to be doable. |