Hello All,

Is it illegal to access a method in one javascript
XPCOM component from another javascript xpcom
component? Do I need to explicitly define an IDL?

Thanks for any pointers.

Regards,
am
--

ps: (long) detailed context:

I followed:

a) "Share global data in Firefox through javascript
implemented XPCOM" -- http://tinyurl.com/35dszj

b) "passing/getting data from/to custom xpcom service"
-- http://tinyurl.com/3ex225

and
c) created the JS XPCOM components using
http://ted.mielczarek.org/code/mozilla/jscomponentwiz/

(removed the singleton constraint from one of the two
components.)

--

My components:
1.
One javascript xpcom component is Foo. Foo defines the
fields url and handle, and corresponding methods
getUrl(), setUrl(url), getHandle(), and
setHandle(handle). url is a string, handle is a
javascript object. my application needs a method in
handle: handle.execute(string).

Foo is NOT as singleton.

2.
a second javascript xpcom component is Bar. Bar
receives Foo as the subject of an event notification:
i.e., part of observe(subject, topic, data), where
subject == an instance of Foo.

Bar is a singleton.

3.
the documentation says subject needs to be an xpcom
component
http://www.xulplanet.com/tutorials/m...serverserv.php

4.
// Bar's observe() method
observe: function(subject, topic, data)
{
if(topic == "test-work-added")
{
this.dumpln("observed: test-work-added");
this.doWork(subject);
}

},

// execution fails below with message:
// TypeError: subject.getUrl is not a function
doWork : function(subject)
{
if (!subject) {
this.dumpln("empty subject");
return;
}

// execution fails here.
// also fails for subject.url
if (!subject.getUrl()) {
this.dumpln("empty subject.getUrl()");
return;
}

...
...
},
....
....


5.
// the app does the following:

var obsService =
Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverServi ce);


var workItem =
Components.classes["@testext.com/work;1"].getService(Components.interfaces.nsISupports).wra ppedJSObject;


// url and handler have been defined earlier.
workItem.setUrl(url);
workItem.setHandler(handler);
dumpln("workItem.getUrl()=" + workItem.getUrl()); //
shows correct non-null data
obsService.notifyObservers(workItem,
"test-work-added", "newWork");