Subj : Re: Sharing Javascript objects between different XUL windows. To : netscape.public.mozilla.jseng From : Peter Wilson Date : Thu Dec 23 2004 08:33 am I'm using Javascript only within XUL forms. The reference is to an XULElement and it remains an XULElement - just a different object with the same attributes. This gist of what I am doing is that a main form contains an XUL document used as a data structure. This is loaded using nsIDOMParser. The main form launches one or more tools which register themselves to receive notifications when the currently selected DOM element changes. Each tool maintains a map of its view element id's back to the originating DOM element. When a tool user selects an item in its view, the view id is used to retrieve the DOM XULElement from its map. The main form is then notified of the change and it then proceeds to notify all registered listeners - including the tool which raised the event. FormMain================================================ var theDom // containing a particular XULElement: theXULElementA var theXULElementA // hardwired to reference the particular "E3" // XULElement using DOM API operations. function NotifyAll(selectedXULElement).... assert(selectedXULElement === theXULElementA) // OK for all registeredNotifyListeners aListener.onNotify(selectedXULElement) FormTool================================================ var theDom // a reference to theDOM in FormMain, passed as a // parameter during window creation. var theXULElementB // hardwired to reference the particular "E3" // XULElement in theDOM using DOM API operations. var formMain // a reference to the Form Main, passed as a // parameter during window creation. function onload() theMap put all elements in theDOM assert(theMap.get("E3")===theXULElementB) // OK. build theTree containing treeitem myid="E3" formMain.registerNotifyListener(this); function onclick() // we prsume the user clicks on the E3 item in the // tree. selectedXULElement = theMap.get("E3") assert(selectedElement === theXULElementB) // OK. formMain.notifyAll(selectedXULElement) function onNotify(selectedXULElement) sequence through map looking for selectedXULElement. // This fails to find selectedXULElement. // The map still contains an entry for element "E3" but // somehow selectedXULElement and the map object are now // different. assert(selectedXULElement === theXULElementB) // FALSE. // So either selectedXULELement was changed by the cross window call from formMain.NotifyAll or, alternatively, the local reference theXULElementB was altered during this process. Some interesting Venkman output (tmpSrcNode is tmpXULElementB above and srcNode is selectedXULElement, I changed the actual field names for this message to make them moer explanatory): 0001: tmpSrcNode $[0] = [XULElement] [class: XULElement] {0} 0001: tmpSrcNode === srcNode $[1] = [boolean] false 0001: tmpSrcNode.document === srcNode.document $[2] = [boolean] true 0001: tmpSrcNode.parent === srcNode.parent $[3] = [boolean] true 0001: tmpSrcNode.nextSibling === srcNode.nextSibling $[5] = [boolean] true 0001: tmpSrcNode.nextSibling $[6] = [Text] [class: Text] {0} 0001: tmpSrcNode.nextSibling.nextSibling $[7] = [XULElement] [class: XULElement] {0} 0001: tmpSrcNode.nextSibling.nextSibling === srcNode.nextSibling.nextSibling $[8] = [boolean] true So its in the same document, it has the same parent and its siblings are the same. BUT it is not the same object!! .