[SERVER-2667] Cannot compare different instances of ObjectIds with same value Created: 02/Mar/11 Updated: 06/Apr/23 Resolved: 09/May/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | JavaScript |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Yuriy Bogdanov | Assignee: | DO NOT USE - Backlog - Platform Team |
| Resolution: | Won't Fix | Votes: | 4 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
shell |
||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||
| Description |
|
Simple test:
For example, PHP driver works great with it:
Followed by discussion in groups: |
| Comments |
| Comment by Mira Carey [ 09/May/16 ] | |||||||||||
|
Unfortunately, it's not possible to provide a custom overload for equality in SpiderMonkey, so the asked for functionality isn't possible. | |||||||||||
| Comment by Ben Becker [ 19/Feb/13 ] | |||||||||||
|
Simply modifying the runtime is not enough to implement custom equality support. The following simple cases of equality comparison do not enter the runtime:
When comparing objects, it looks like CompareStub::Generate() and ICCompareStub::GenerateObject() have a fast case which compares the pointer locations of the two operand registers (rax and rdx for x64). These cases immediately return 0 or 1 for the equality operator. Under certain conditions (e.g. boolean == object), these stubs invoke the EQUALS() built-in (in runtime.js). It seems feasible to modify this code to either compare a hidden Map entry, or call a custom built-in. | |||||||||||
| Comment by Ben Becker [ 16/Feb/13 ] | |||||||||||
|
v8 doesn't support custom object comparisons, but it may be be possible to modify v8. I'll review the code to see how feasible this is, and what additional runtime costs we would incur for a simple implementation. Some quick notes: Other options:
| |||||||||||
| Comment by Eliot Horowitz (Inactive) [ 16/Feb/13 ] | |||||||||||
|
Ben - anyway to do this in v8? | |||||||||||
| Comment by Scott Lowe [ 12/Feb/13 ] | |||||||||||
|
Any update on this? It's making life difficult because it's currently impossible to do indexOf on an array of object ids - I'm going to have to either store as strings for now or use a very slow comparison function. | |||||||||||
| Comment by Eliot Horowitz (Inactive) [ 03/Mar/11 ] | |||||||||||
|
Not sure if its possible to make this work in spidermonkey or v8. |