This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html Multipage: http://www.whatwg.org/C#function Complete: http://www.whatwg.org/c#function Comment: Use the new callback syntax for Function and event handler attributes. Posted from: 83.85.115.123 by annevk@opera.com User agent: Opera/9.80 (Macintosh; Intel Mac OS X 10.7.2; U; en) Presto/2.10.229 Version/11.60
In particular it should be something like this: callback EventHandlerListener = void (Event evt); typedef [TreatNonCallableAsNull] EventHandlerListener? EventHandler; Event handler IDL attributes can then be defined as attribute EventHandler onclick; The event handler attributes that take a different argument (onerror, others?) it probably makes sense to define a distinct callback so it is clear they are special from the IDL as well. Cameron suggested EventListener elsewhere but that would be incompatible with the DOM (where it is a callback interface).
Wouldn't this mean you can't assign a zero-argument method as a callback? Surely the return value should be boolean, not void. What about things like onbeforeunload, where the value can be as string, too?
(In reply to comment #2) > Wouldn't this mean you can't assign a zero-argument method as a callback? No, zero-argument Functions can be passed in just like they could before with [Callback] interface. > Surely the return value should be boolean, not void. What about things like > onbeforeunload, where the value can be as string, too? Either broaden the return type, or use separate callback definitions for the event handler IDL attributes that have different return types.
*** Bug 15694 has been marked as a duplicate of this bug. ***
The new syntax for this is: [TreatNonCallableAsNull] callback EventHandler = any (Event event); For window.onerror you will need something special, e.g. [TreatNonCallableAsNull] callback ErrorEventHandler = any (any... args); To reference it you would use "EventHandler?".
*** Bug 16320 has been marked as a duplicate of this bug. ***
*** Bug 17556 has been marked as a duplicate of this bug. ***
Would the difference between onclick and onerror be detectable in any way?
As far as I can tell from reading IDL they would be treated identically in JavaScript so I suppose you might as well merge them and add a comment that in the common case an Event object is passed or some such.
I think there is some value in keeping the types of onerror and the others different, just to help people reading the IDL. For the same reason you use the most restrictive type for your attributes, rather than interface HTMLElement { ... readonly attribute any classList; };
Seems this was fixed in http://html5.org/r/7146