Returning an array from a JavaScript XPCOM

IDL

The second last word is the type of the objects in the array.

void getArray(out unsigned long count, [array, size_is(count), retval] out string retv); 

XPCOM


getArray: function(count) {
	var returnValue = ["foo", "bar", "baz"];
	count.value = returnValue.size;
	return returnValue;
}

Calling code


var xpcom = Components.classes["@example.com;1"].getService(Components.interfaces.nsIExample);
var array = xpcom.getArray({});

Leave a Reply

Adventures in development - Web standards and Firefox extensions