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 14916 - WebIDL has no function type
Summary: WebIDL has no function type
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
Depends on:
Reported: 2011-11-23 18:53 UTC by Aryeh Gregor
Modified: 2011-12-28 16:34 UTC (History)
5 users (show)

See Also:


Description Aryeh Gregor 2011-11-23 18:53:57 UTC
HTML has tons of IDL attributes like

  [TreatNonCallableAsNull] attribute Function? onabort;

Function is actually an interface it defines:

This is very weird, and probably contradicts ES in some details (like whether the .call property of the prototype is configurable).  It would make more sense for WebIDL to have a dedicated function type.  The algorithm for converting to a function should probably return null if the thing passed in isn't callable, so the above could become just

  attribute function? onabort;

since every single usage of Function? in HTML seems to use [TreatNonCallableAsNull], so it may as well just be the behavior all the time.
Comment 1 Ian 'Hixie' Hickson 2011-11-23 19:04:32 UTC
This may also be the last remaining use of [Callback=FunctionOnly], so providing a dedicated interface for this would let us kill both FunctionOnly and TreatNonCallableAsNull.
Comment 2 Ian 'Hixie' Hickson 2011-11-23 19:07:29 UTC
(Note though that this wouldn't let people create event handlers without referencing HTML, as some people would like; see )
Comment 3 Cameron McCormack 2011-12-28 06:19:18 UTC
We now have callbacks in Web IDL, so HTML's Function can be defined as:

  callback Function = any (any... arguments);

This is less weird.  I don't think we really need to move it across to Web IDL; the weirdness of the Timer APIs is not something I think we want to propagate to new APIs.

Aryeh, let me know if not adding this definition to Web IDL itself is acceptable, thanks.
Comment 4 Aryeh Gregor 2011-12-28 16:34:21 UTC
That seems okay to me.  I don't think we need a special "function" type, because in fact most of the users of Function in HTML should get a callback with a specific signature, not just any old function.

(It seems to make no actual difference what the signature for the callback is, except that it theoretically guarantees the type of the parameters and puts some constraints on how some return values will behave.  But it's still handy as documentation.)