[whatwg] Media Stream API: What is the intended behaviour for undefined mandatory arguments?

Aryeh Gregor Simetrical+w3c at gmail.com
Wed Jun 1 13:09:53 PDT 2011

2011/6/1 Tommy Widenflycht (ᛏᚮᛘᛘᚤ) <tommyw at google.com>:
> Hi Ian and the rest of the list,
> We are having a bit of discussion regarding the correct behaviour
> when mandatory arguments are undefined, see this webkit bug for history:
> https://bugs.webkit.org/show_bug.cgi?id=60622
> Could we have some clarification for the below cases, please:
> var u;
> var n = null;
> // Should throw since u is undefined or just abort?
> navigator.webkitGetUserMedia("audio", u);
> // Will not throw but will abort.
> navigator.webkitGetUserMedia("audio", n);
> // Should throw because we are expecting at least two arguments.
> navigator.webkitGetUserMedia("audio");

This is defined by WebIDL, although somewhat complicatedly:


The key is the two steps "Initialize S to the effective overload set .
. ." and "Set S to the result of passing S and arg0..n−1 to the
overload resolution algorithm."  Basically, that means "Let S be the
set of all the methods with this name on this object, then remove from
the set any methods that can't accept the provided arguments."  I
*think* the overload resolution algorithm specifies that if too few or
too many arguments are passed, the method is rejected.  Then you fall
through to "If S is empty, throw a TypeError", so that's apparently
the specified behavior.  But WebIDL always confuses me, so I wouldn't
swear to it.

But there's an open issue that says "Need to test how implementations
actually behave when passed too few or too many arguments."  So I
wouldn't assume the standard is right.  Maybe data would be useful on
how different browsers behave here -- although I suspect that it will
vary greatly from method to method.  I can tell you from experience
that Gecko throws if you pass fewer than three arguments to
document.execCommand().  It makes sense to me -- if we want the API to
not throw if the argument is omitted, why isn't the argument optional?

More information about the whatwg mailing list