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.
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].