W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2011

Re: More questions about contextual reference nodes

From: Cameron McCormack <cam@mcc.id.au>
Date: Fri, 15 Apr 2011 12:11:18 +1200
To: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Cc: Boris Zbarsky <bzbarsky@MIT.EDU>, public-webapps <public-webapps@w3.org>
Message-ID: <20110415001118.GC19784@wok.mcc.id.au>
Lachlan Hunt:
> However, with the way in which the IDL is overloaded, it's not clear
> to me which of the two overloaded methods gets invoked when the
> parameter is null.
> 
> The IDL says:
>   querySelector(in DOMString selectors, in optional Element refElement);
>   querySelector(in DOMString selectors, in sequence<Node> refNodes);
> 
> When the author invokes:
> 
>   x.querySelector("a", null);
> 
> Does it invoke the method with refElement or refNodes?

That is one of the unsatisfactory things about the way overloading is
currently handled in Web IDL.  In situations where null is a valid value
for more than one overload, it needs to be described in prose, but only
if it matters which of the two operations is considered to be invoked.

See the blue box just below this footnote:

  http://dev.w3.org/2006/webapi/WebIDL/#distinguishable-interface-note

Step 4 of the algorithm for the behaviour of Function objects that
correspond to IDL operations

  http://dev.w3.org/2006/webapi/WebIDL/#es-operations

says

  If S contains more than one entry, then the operation call is
  ambiguous. Remove all but one entry from S according to rules
  specified in the description of interface I, or arbitrarily if no such
  rules exist.


Note that it is ambiguous if you have, say

  querySelector(in DOMString selectors, in optional Element refElement);
  querySelector(in DOMString selectors, in Node[] refNodes);

since null is a valid value for both Element and Node[].  With

  querySelector(in DOMString selectors, in optional Element refElement);
  querySelector(in DOMString selectors, in sequence<Node> refNodes);

null is not a valid value for sequence<Node>, so passing null calls the
first of the two overloads.  That is because in the overload resolution
algorithm

  http://dev.w3.org/2006/webapi/WebIDL/#dfn-overload-resolution-algorithm

step 3.2.2 only considers object, interface types, nullable types and
array types when “null” is passed as an argument.

-- 
Cameron McCormack ≝ http://mcc.id.au/
Received on Friday, 15 April 2011 00:11:58 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:44 GMT