Passing objects between a Javascript-based XPCOM component and its client
function WrapperClass(object) {
this.wrappedJSObject = this;
this.object = object;
}
WrapperClass.prototype = {
QueryInterface : function(iid) {
if (!iid.equals(Components.interfaces.nsISupports)) {
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
}
}
Now you can call the first XPCOM component passing in any kind of object by wrapping it first:
theComponent.foo(new WrapperClass(theObject))
And inside foo(), the wrapped object can be retrieved as follows:
foo : function(arg) {
var theActualObject = arg.wrappedJSObject.object;
}
In the interface definition of theComponent (in your IDL file), you need to declare that foo() takes an nsISupports parameter.

