Hi,
  I am currently writting a small xpcom component that are to be
access from Javascript. In one of the function, it is suppose to
return an array contain string.

----Component Source Code----
.........
char * data = "Testing";
nsISupportsArray * array;
nsresult rv = NS_NewISupportsArray(&array);
rv = nsComponentManager::CreateInstance(NS_SUPPORTS_STRING_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsString), (void**) &xpcomString);
xpcomString->SetData(data);
array->AppendElement(xpcomString);
*_retval = array;
.........
---End---
The javascript that accessing this function was able to get the
nsISupportsArray that this function return. But it was not able to
access the value inside the array.

---JS Source Code---
var sample = Components.classes["@mozilla.org/mtest;1"].createInstance();
sample = sample.QueryInterface(Components.interfaces.nsIMTest);
dump("sample = " + sample + "\n");
var myArray = sample.GetWindowList();
dump(myArray + "\n");
dump("::" + myArray[0] + "\n");
---End---
The dump from myArray display a nsISupportsArray object but the
myArray[0] display an undefined value.

What am I doing wrong ? Why can't the JS access my nsISupportString ?

from
James

Reply via email to