Re: Function type

Anne van Kesteren:
> On Wed, 28 Dec 2011 07:21:35 +0100, Cameron McCormack <cam@mcc.id.au>
> wrote:
>> I don't think more specs should depend on the definition of Function
>> that's in HTML, since it's kind of non-specific and designed to work
>> with the weirdo timer APIs. We have callbacks in Web IDL now, and
>> specs that need them should define more specific signatures to use.
>
> You suggested using
>
> callback Function = any (any... arguments);
>
> in https://www.w3.org/Bugs/Public/show_bug.cgi?id=14916 I was wondering
> if that includes [TreatNonCallableAsNull] and if not, how that needs to
> be included. That was part of the reason why it would be nice if Web IDL
> had the definition instead, so we could remove [TreatNonCallableAsNull]
> and just have 'function'. (I believe we discussed this already but I
> cannot find it in the archives. Sorry!)

I do remember discussing that somewhere, but I don't think that treating 
bad values as null is something that's consistent with normal type 
conversions, so I don't think it should be written in to any built-in 
type.  So yes, you would need to write:

   callback EventListener = void (Event evt);
   typedef [TreatNonCallableAsNull] EventListener? EventAttribute;

and then you can use EventAttribute is the type of event listener 
attributes everywhere.  (Aside: I think we should be using EventListener 
in place of Function for these attributes, since that's actually the 
signature we want (apart from onerror and maybe some others).)

Received on Wednesday, 28 December 2011 23:46:13 UTC