[webkit-dev] Optional parameter in IDL and undefined JS value

Cameron McCormack cam at mcc.id.au
Wed Apr 20 23:17:34 PDT 2011

Jian Li:
> > I am referring to Blob.slice(start, end) that mimics Array.slice. Where in
> > WebIDL has this behavior defined? Sorry I can't find it in the spec.
> >
> > For Array.slice(start, end), both Safari and Chrome treat passing undefined
> > as omitted parameter, while Firefox and IE treat passing undefined as 0.

Ryosuke Niwa:
> Doesn't that mean the current behavior (i.e. treating undefined as 0) is
> correct since that's what other browsers do?

The File API spec currently says:

  Blob slice(in optional long long start,
             in optional long long end,
             in optional DOMString contentType);

and Web IDL says that if you call

  blob.slice(10, undefined);

then this is calling the function with two arguments, where the second
argument will be converted to 0 due to how the conversion of JS
undefined to an IDL long long value is defined.  This is not the same as


Whenever some optional arguments are omitted, the prose for the
definition of the operation defines what that means; it’s not
automatically “convert from undefined”.

There is no way in Web IDL to state that when undefined is passed as an
argument explicitly that it is handled differently from the rules in
http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping (although the
authors of the File API spec could include this additional requirement
in prose, overriding Web IDL, if they wanted).

Cameron McCormack ≝ http://mcc.id.au/

More information about the webkit-dev mailing list