Closed Bug 380597 Opened 17 years ago Closed 15 years ago

Methods returning an array suck for JS implementations/callers

Categories

(Core :: XPConnect, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 523817
Future

People

(Reporter: Dolske, Unassigned)

Details

While rewriting password manager as a JS component (bug 374723), I wanted a couple of functions to return arrays. For example, nsIPasswordManager.idl has this:

void getAllDisabledLogins(out unsigned long count,
              [retval, array, size_is(count)] out wstring hostnames);

The header generated for C++ is sensible:

NS_IMETHOD GetAllDisabledLogins(PRUint32 *count, PRUnichar ***hostnames) = 0;

But JS callers are stuck with having to provide a useless argument for the |count| outparm:

var dummy = { value : null; }
var hostnames = pwmgr.getAllDisabledLogins(dummy);
if (hostnames.length != dummy.value) { /* omgwtfbbq? */ }

That can be reduced to .getAllDisabledLogins({}), but it doesn't serve any obvious purpose and is confusing for callers.

Fodder for Mozilla2, perhaps.
The flip side of this problem is that JS implementations needlessly have to set the array length as an outparam, XPCOM ought to do that automatically (when the caller needs it).

JS code irritatingly has to do the following:

function returnsAnArray(count) {
    var foo = [1, 2, 3];
    count.value = foo.length;
    return foo;
}

instead of just

function returnsAnArray() {
    var foo = [1, 2, 3];
    return foo;
}
Summary: Methods returning an array shouldn't expose the length as an argument to JS callers → Methods returning an array suck for JS implementations/callers
See bug 380839; I think that should make this easier.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.