wrappedJSObject
If you implement an XPConnect interface in Javascript (e.g. nsITreeView if you don't want to use RDF to display data in a tree), you might need to access properties or methods inside your javascript object which are not part of the interface.
This can be easily achieved using a special object property.
This property is called wrappedJSObject and is part of every XPConnect interface. Here is an example.
// in the interface-implementing code, set the property to this
function my_interface() {
this.wrappedJSObject = this;
}
// whatever you assigned to wrappedJSObject can be retrieved through the XPConnect wrapper
function get_obj(tree) {
return tree.view
? tree.view.wrappedJSObject
: null;
}
Why this is necessary is explained in nsIXPConnect.idl:
* When JavaScript code uses a component that is itself implemeted in
* JavaScript then XPConnect will build a wrapper rather than directly
* expose the JSObject of the component. This allows components implemented
* in JavaScript to 'look' just like any other xpcom component (from the
* perspective of the JavaScript caller). This insulates the component from
* the caller and hides any properties or methods that are not part of the
* interface as declared in xpidl. Usually this is a good thing.
*
* However, in some cases it is useful to allow the JS caller access to the
* JS component's underlying implementation. In order to facilitate this
* XPConnect supports the 'wrappedJSObject' property.
