Closed Bug 325636 Opened 20 years ago Closed 7 years ago

XPConnect wrapping makes object identity testing hard

Categories

(Core :: XPConnect, defect)

defect
Not set
normal

Tracking

()

RESOLVED INACTIVE

People

(Reporter: dmosedale, Unassigned)

Details

In COM itself, clients are allowed to compare any two interface pointers to determine whether they point to the same object (Essential COM, chapter 4, "Uniqueness and Identity" section). In C++, XPCOM allows this as well. Furthermore, various interfaces in Mozilla depend on this by having interface pointers as in params which are used as keys into lists of objects. Because XPCOM interface pointers can be mapped to JS objects in variety of different ways, doing object identity tests when implementing such interfaces is complicated. It would be really nice if this could be made easier. One possibility suggested by bz would be to make |x == x.wrappedJSObject| return true.
"when implementing such interfaces" should read "when implementing such interfaces in JS".
It's been pointed out to me that the pointer equivalence rule I mentioned is specific to IUnknown in COM, and not general to all interface pointers.
Just in case people need a solution sooner... var SIP=Components.Constructor("@mozilla.org/supports-interface-pointer;1", Components.interfaces.nsISupportsInterfacePointer); function compare_js_object_to_xpconnect_object(jsObject, xpconnectObject) { var sip = new SIP; sip.data = jsObject; return sip.data == xpconnectObject; }
Assignee: dbradley → nobody
QA Contact: pschwartau → xpconnect
Per policy at https://wiki.mozilla.org/Bug_Triage/Projects/Bug_Handling/Bug_Husbandry#Inactive_Bugs. If this bug is not an enhancement request or a bug not present in a supported release of Firefox, then it may be reopened.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.