Three Monkeys, Three Typewriters, Two Days

October 23, 2009

Sane way to return arrays to JS from XPCOM methods

With bug 523817 fixed, you can now write an interface like this:

  void getSomething([optional] out unsigned long count,
                    [retval, array, size_is(count)] out whatever outArray);

and js consumers can do:

  var myArr = foo.getSomething();

to get an array without having to have a dummy argument for the length. Word of warning: this only works if the length has no required non-retval arguments after it, so put that length at the end, right before the retval array.

Posted by bzbarsky at October 23, 2009 6:19 PM