Chuck wrote:
I have a service which I have tested in C++.  Now, for the first time
I am getting my feet wet with using it with Javascript/XPConnect.

I hope someone will spot some obvious misunderstanding on my part.

So far it appears I can create an instance of the service however I am
having some problem making method calls on it.

IDL:
[scriptable, uuid(BFFEC861-A28B-499c-A30E-3D500CB2F739)]
interface nsITestObjectManager : nsISupports {


void getTestForObject(in nsIIDRef aIID, in string subject,
in PRInt32 type,
[iid_is(aIID),retval] out nsQIResult aObject );
}


Javascript:

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

  var iface = Components.interfaces.nsITestObjectManager;
  var clazz = Components.classes["@ag.com/testobject;1"];
  var inst = clazz.createInstance(iface);

// fails, not enough args...
//  var obj = inst.getTestForObject(Components.interfaces.nsIMyTestV1,
//      "ag.nsIMyTestV1", 2 );

var obj_dummy;
var obj = inst.getTestForObject(Components.interfaces.nsIMyTestV1, "ag.nsIMyTestV1", 2, obj_dummy );




Two problems:

1.  I am getting an exception when making the call to
getTestForObject(), "Not enough arguments."  I thought specifying
retval would signal to xpconnect that the last parameter is actually a
return *not* an argument.  Passing a 4th dummy param removes the
exception but then I get my second problem.

The commented out version looks to me like it correctly fits the idl you show. I'd bet you have been fiddling with the idl definition and your generated .xpt file being loaded by the browser is out of sync with the idl.


FWIW, if you *didn't* declare the last parm as [retval] then the 'obj_dummy' you pass in would need to be declared as...

var obj_dummy = {}; // same as "= new Object();"


2. It appears that I am not specifying the correct type for nsIID (first arg) as I am getting another exception, "Could not convert Javascript argument arg 1." I had assumed that xpconnect would expect and IID to be of the form Components.interfaces.[interface class name].

IIRC the error message references to parameters is zero based (my bad). So "Could not convert Javascript argument arg 1." should be talking about the second arg not the first. Again, I'm thinking your xpt and idl are not in sync.


You can use xpt_dump.exe to verify xpt contents.

John.




Reply via email to