Re: [webidl] Unions involving a primitive and a string don't make any sense

Boris Zbarsky:
> In particular, unions are allowed to contain both a string (or enum) and
> a primitive, but if you try to convert a JS value to such a union the
> string is always picked (http://dev.w3.org/2006/webapi/WebIDL/#es-union
> step 7).  That seems wrong.

Yes, that's wrong.  The intention was to allow

   void f((float or DOMString) x);

to be written because

   void f(float x);
   void f(DOMString x);

was not allowed, since the two types are not distinguishable.  DOMString 
would be used as the type of last resort, but if a JS Number were passed 
then it would be converted into the float.

I wonder now with the changes we've made to simplify overloading if it's 
actually useful to have different behaviour between unions and overloads 
like this.  Probably not.  So we should either make primitives and 
DOMString distinguishable for overloading, defaulting to selecting 
DOMString when there isn't an exact type match like unions were meant to 
do, or unions shouldn't allow both types.

I'm not aware of an API that needs to handle floats and DOMStrings 
separately -- is there one?  If not, we should just disallow it.

Received on Saturday, 31 March 2012 00:13:56 UTC