Hi,
I use the following code to notify observers of custom events. I can pass 
native types like booleans and strings to observers using nsISsupports*** 
wrappers, but how can I pass an instance of my own JS XPCOM component 
(non-service) to observers?

var gObsSvc = 
CC["@mozilla.org/observer-service;1"].getService(CI.nsIObserverService);
gBroadcast = function(subj, topic, data) {
  var bool = 
CC["@mozilla.org/supports-PRBool;1"].createInstance(CI.nsISupportsPRBool);
  bool.data = subj;        
  var d;
  if (typeof(data) == "string") {
    var  d = 
CC["@mozilla.org/supports-string;1"].createInstance(CI.nsISupportsString);
      d.data = data;
    }
    else {
      // d is an instance of my custom JS XPCOM component. How to wrap it?
    }
    gObsSvc.notifyObservers(bool, topic, d);    
};

// code which calls the above:
gBroadcast(true, "my-custom-event1", "foobar");
gBroadcast(false, "my-custom-event2", myCustomJSXPCOMobject);


Thanks for any suggestions,
Eric

_______________________________________________
Project_owners mailing list
[email protected]
http://mozdev.org/mailman/listinfo/project_owners

Reply via email to