This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26562 - The IDL for createImageBitmap seems to be wrong
Summary: The IDL for createImageBitmap seems to be wrong
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-12 18:21 UTC by Ehsan Akhgari [:ehsan]
Modified: 2014-09-17 22:43 UTC (History)
3 users (show)

See Also:


Attachments

Description Ehsan Akhgari [:ehsan] 2014-08-12 18:21:24 UTC
From the prose it seems like the spec is trying to only allow calling this function with 1 or 5 arguments, so the IDL should be something along the lines of:

  Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image);
  Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, long sx, long sy, long sw, long sh);
Comment 1 Ian 'Hixie' Hickson 2014-08-18 20:42:24 UTC
You sure? I thought "optional" as used here did exactly what I wanted, i.e. the same as what you list.
Comment 2 Ehsan Akhgari [:ehsan] 2014-08-18 21:07:51 UTC
I can't find anything in http://heycam.github.io/webidl/ to suggest that it would work like that.
Comment 3 Boris Zbarsky 2014-08-21 05:08:02 UTC
In Web IDL as currently specified, I believe doing this:

  void foo(optional long a, long b);

will construct an effective overload set with only one element, since it will immediately run into a non-optional argument.  Therefore only a call with 2 arguments will be allowed.

Similarly, in the createImageBitmap spec as currently written only calls with 5 arguments are allowed.  Unless I'm totally misreading http://heycam.github.io/webidl/#dfn-effective-overload-set somehow, of course...
Comment 4 Ian 'Hixie' Hickson 2014-08-25 20:47:07 UTC
Well in that case WebIDL should either ban that case or make it work like I describe...
Comment 5 Ehsan Akhgari [:ehsan] 2014-08-25 21:11:33 UTC
I think it should be banned.  The behavior you're describing is totally non-intuitive. :)
Comment 6 Boris Zbarsky 2014-08-26 04:12:36 UTC
IDL very purposefully _allowed_ this case to align more closely with how arguments work in ES.

Keep in mind that "optional" in IDL right now doesn't just mean "can be omitted".  It also means "can have undefined explicitly passed to mean the argument is missing".

So there is a practical difference between these two methods:

  void foo(optional long a, long b);
  void bar(long a, long b);

both expect to be called with two arguments, but the former allows passing undefined for the first argument and treats that as "not passed", while the latter coerces undefined to 0.  Or to make it more interesting:

  void foo(optional Node a, long b);
  void bar(Node a, long b);

the second method requires a Node as the first argument while the first one will accept a Node or undefined, with the latter meaning "no node".
Comment 7 Ian 'Hixie' Hickson 2014-08-26 17:55:59 UTC
That's highly unintuitive to me. I think a [TreatUndefinedAsUndefined] annotation would be clearer.
Comment 8 Boris Zbarsky 2014-08-26 18:01:22 UTC
The current setup is basically where we ended up after a bunch of public-script-coord discussion with the ES folks.
Comment 9 Ian 'Hixie' Hickson 2014-09-17 22:42:59 UTC
Well I still think the definition of 'optional' here is unintuitive, but I've updated the spec to avoid this case by never having non-optional arguments after optional ones.
Comment 10 contributor 2014-09-17 22:43:12 UTC
Checked in as WHATWG revision r8783.
Check-in comment: Fix IDL blocks due to my misunderstanding what 'optional' meant
https://html5.org/tools/web-apps-tracker?from=8782&to=8783