Your idl declares 'attach' as a method that takes a string param.
That means that your call
dh.attach(document.getElementById('t1')); will convert
document.getElementById('t1') to a string and your 'attach' impl
then tries to call the equivelent of "foo".getAttribute('id').
You can see why that wouldn't work. It looks to me like you can
just fix your idl to declare the correct interface type for the
param to 'attach' and you should see something more like what you
expect.
John.
Praki Prakash wrote:
>
> John,
>
> Here is some code: The runTest invokes getAttribute('id') which suceeds.
> When the same thing is attempted from the attach method of the nsIDocHandler
> component, it fails.
>
> (This is a meaningless testcase to illustrate my problem.)
>
> Thanks, Praki
> ======== test.xul========
> <?xml version="1.0"?>
> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
> <window height="100" width="200"
> xmlns:html = "http://www.w3.org/1999/xhtml"
> xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
> xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
> >
> <script>
> var dh =
> Components.classes["@mprakash.acm.org/dochandler;1"].createInstance();
> dh = dh.QueryInterface(Components.interfaces.nsIDocHandler);
> dump(dh);
> function runTest()
> {
> alert('invoke getAttribute: ' +
> document.getElementById('t1').getAttribute('id'));
> dh.attach(document.getElementById('t1'));
> }
> </script>
>
> <vbox flex="1">
> <text id="t1" value="Hello!"/>
> <button label="Click" onclick="runTest()"/>
> </vbox>
> </window>
> ==============nsIDocHandler.xpidl=================
> /**
> * xpidl -m typelib -I e:\mozilla\dist\idl nsIDocHandler.xpidl
> * xpidl -m header -I e:\mozilla\dist\idl nsIDocHandler.xpidl
> */
> #include "nsISupports.idl"
>
> [scriptable, uuid(00000FB1-E222-11D2-9FC4-00105A1C56C0)]
> interface nsIDocHandler : nsISupports
> {
> void attach(in string filename);
> void detach();
> boolean canHandle(in string filename);
> };
> ==================== nsDocHandler.js =============
> /*
> * Constants
> */
> const DOC_HANDLER_CONTRACTID = '@mprakash.acm.org/dochandler;1';
> const DOC_HANDLER_CID =
> Components.ID('{00000FB1-E222-11D2-9FC4-00105A1C56C0}');
> const DOC_HANDLER_IID = Components.interfaces.nsIDocHandler;
> /*
> * Class definitions
> */
> function nsDocHandler() {
> }
>
> nsDocHandler.prototype= {
> editor: null,
> QueryInterface: function(iid) {
> if (!iid.equals(Components.interfaces.nsISupports) &&
> !iid.equals(DOC_HANDLER_IID))
> throw Components.results.NS_ERROR_NO_INTERFACE;
> return this;
> },
>
> canHandle: function(fileName) {
> dump('\n'+fileName+'\n');
> return true;
> },
>
> attach: function(e) {
> dump('\n**** attach' + e + '\n');
> e.getAttribute('id'));
> }
> };
> var nsDocHandlerModule = {
> registerSelf: function(compMgr, fileSpec, location, type) {
> compMgr.registerComponentWithType(DOC_HANDLER_CID,
> "nsDocHandler JS component", DOC_HANDLER_CONTRACTID,
> fileSpec, location,
> true, true, type);
> },
> getClassObject: function(compMgr, cid, iid) {
> if (!cid.equals(DOC_HANDLER_CID))
> throw Components.results.NS_ERROR_NO_INTERFACE;
> if (!iid.equals(Components.interfaces.nsIFactory))
> throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
> return nsDocHandlerFactory;
> },
> canUnload: function(compMgr) { return true; }
> };
>
> var nsDocHandlerFactory = {
> createInstance: function(outer, iid) {
> if (outer != null)
> throw Components.results.NS_ERROR_NO_AGGREGATION;
> if (!iid.equals(DOC_HANDLER_IID) &&
> !iid.equals(Components.interfaces.nsISupports))
> throw Components.results.NS_ERROR_INVALID_ARG;
> return new nsDocHandler();
> }
> }
>
> /* module initialisation */
> function NSGetModule(comMgr, fileSpec) { return nsDocHandlerModule; }
> =================== end =======================
>
> "John Bandhauer" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Please post some of your code (or a simplified test case). It is
> > not clear (to me) from your description exactly what your code is
> > doing.
> >
> > John.
> >
> > Praki Prakash wrote:
> > >
> > > I hope this makes sense to someone.
> > >
> > > I am passing a XULElement as an argument to a XPConnect wrapped Java
> script
> > > method(nsIDocHandler::attach. It is a component implemented in
> Javascript)
> > > When I invoke any method (even getAttribute) on the argument, the method
> > > received, I get the following error.
> > >
> > > * Call to xpconnect wrapped JSObject produced this error: *
> > > [Exception... "'[JavaScript Error: "e.getAttribute is not a function"
> {file:
> > > "e:\mozilla\dist\win32_d.obj\bin\components\nsDocHandler.js" line: 53}]'
> > > when calling method: [nsIDocHandler::attach]" nsresult: "0x80570021
> > > (NS_ERROR_XPC_JAVASCR
> > > IPT_ERROR_WITH_DETAILS)" location: "JS frame ::
> > > chrome://makara/content/ContentArea.js :: anonymous :: line 57" data:
> yes]
> > > ************************************************************
> > > [Exception... "'[JavaScript Error: "e.getAttribute is not a function"
> {file:
> > > "e:\mozilla\dist\win32_d.obj\bin\components\nsDocHandler.js" line: 53}]'
> > > when calling method: [nsIDocHandler::attach]" nsresult: "0x80570021
> > > (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)" location: "JS frame ::
> > > chrome://makara/content/ContentArea.js :: anonymous :: line 57" data:
> yes]
> > >
> > > I am at a complete loss as to what is happening. All I can see in the
> > > javascript interpreter is that at the time this error is reported, the
> > > interpreter is expecting the callee to be an object and it is not. I can
> > > invoke the same getAttribute method at the call site just fine. dump on
> the
> > > argument displays the object class to be XULElement as expected.
> > >
> > > Any insight into what is happening? Are components implemented in
> Javascript
> > > second class citizens?
> > >
> > > Thanks, Praki