W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

Re: [TreatNonCallableAsNull] alternative?

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Thu, 16 Feb 2012 10:50:12 -0500
Message-ID: <4F3D25B4.90409@mit.edu>
To: public-script-coord@w3.org
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;


   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, 

Received on Thursday, 16 February 2012 15:50:39 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:05 UTC