Bug 14916 - WebIDL has no function type
WebIDL has no function type
Status: CLOSED WONTFIX
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL
unspecified
All All
: P2 normal
: ---
Assigned To: Cameron McCormack
public-webapps-bugzilla
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-11-23 18:53 UTC by Aryeh Gregor
Modified: 2011-12-28 16:34 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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:

  http://www.whatwg.org/specs/web-apps/current-work/#function

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 http://www.w3.org/mid/op.v5atfs1x64w2qv@annevk-macbookpro.local )
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.)