Re: More questions about contextual reference nodes

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 UTC