RE: removeEventListener with only one passed parameter...

I'm saying that your option 2 is better than your options 3, 4, or 5, as in normal JavaScript semantics null is not a default-triggerer or other type of special case.

Failing that, options 4 and 5 are better than option 3.

(And, as Anne pointed out, this is just a matter of the future; I'm not pushing hard for any of the options, if implementers don't want to churn.)
________________________________________
From: Boris Zbarsky <bzbarsky@MIT.EDU>
Sent: Tuesday, June 10, 2014 09:47
To: Domenic Denicola; Anne van Kesteren
Cc: public-script-coord
Subject: Re: removeEventListener with only one passed parameter...

On 6/10/14, 2:27 AM, Domenic Denicola wrote:
> It would in general be preferable for undefined and missing to have the same behavior, as in most ES functions.

WebIDL does provide a facility for this: you mark the argument as optional.

> (It seems like the takeaway here is that ? should not be used for params, and optional should be instead, to enforce normal ES semantics.)

I'm not sure why you say "instead".  The interaction of null and
undefined for, say, a nominally object-type argument can look like one
of the following cases:

1)  "Node arg"
2)  "optional Node arg"
3)  "Node? arg"
4)  "optional Node? arg"
5)  "optional Node? arg = null"

which have the following behavior:

1)  Throws if anything but a Node object is passed in, and requires
     something to be passed in (via arguments.length check).
2)  Throws if anything but a Node object or undefined is passed in,
     allows the argument to be missing.  Prose needs to handle the
     "not passed" (=== undefined) case.
3)  Throws if anything but a Node object, null, or undefined is passed
     in, requires something to be passed via arguments.length.
     Undefined is converted to null; prose has to handle the null case.
4)  Throws if anything but a Node object, null, or undefined is passed
     in, allows the argument to be missing.  Prose has to handle the
     separate "not passed" and "null" cases.
5)  Throws if anything but a Node object, null, or undefined is passed
     in, allows the argument to be missing. Undefined is converted to
     null; prose has to handle the null case.

Obviously you can define #4, in prose, to have the same behavior as #5
would have....  Whether you want #4/#5 or #2 depends on whether the API
should throw when null is passed, basically.

In any case, the spec right now has #3, and Blink implements something
like #5, I believe.

-Boris

Received on Tuesday, 10 June 2014 14:04:43 UTC