- From: Marcos Caceres <w3c@marcosc.com>
- Date: Thu, 16 Feb 2012 16:02:51 +0000
- To: Boris Zbarsky <bzbarsky@mit.edu>, Cameron McCormack <cam@mcc.id.au>
- Cc: public-script-coord@w3.org
On Thursday, 16 February 2012 at 15:50, Boris Zbarsky wrote:
> On 2/16/12 10:46 AM, Marcos Caceres wrote:
> > The WebIDL spec warns against using [TreatNonCallableAsNull] "unless required to specify the behavior of legacy APIs", but does not provide guidance on what to do in a situation where an Editor might need such a thing
>
>
>
> If you're writing IDL for something that's already in the wild with this
> behavior, you need it.
>
> If you're writing a spec for something new, you don't.
>
> > Can you please add some more text to the warning saying what the alternative is
>
> Just don't use the extended attribute.
>
> > Interface SomeThing : EventTarget{
> > [TreatNonCallableAsNull] attribute SomeCallBack? onclose;
> > }
> >
> > So I could have both:
> >
> > window.something.onclose = function(){ ... }
> > window.something.addEventListener("close"….)
>
>
>
> You don't need the extended attribute for that. That will just work.
>
> What you need [TreatNonCallableAsNull] is if you want this:
>
> window.something.onclose = 5;
>
> or
>
> window.something.onclose = "monkeypants";
>
> to just silently remove the event handler, if any, set via onclose
> before instead of throwing an exception.
>
> For new specs, it seems like throwing an exception would be preferable,
> right?
>
I was not sure; I guess that is exactly the question I wanted to ask - and probably what should be stated in the spec :) Ideally, I wanted my new "something.onclose" to work exactly the same as window.onclose (which gives the magic behaviour of [TreatNonCallableAsNull] for error handling) … but if new "best practice" is just to throw, I'm happy to not use [TreatNonCallableAsNull].
Cam, can you please add to the spec "For new specs, throwing an exception is preferable to relying on the legacy behaviour of [TreatNonCallableAsNull]." or some such.
Received on Thursday, 16 February 2012 16:03:26 UTC