- From: Cameron McCormack <cam@mcc.id.au>
- Date: Fri, 09 Dec 2011 12:30:13 +1100
- To: Simon Pieters <simonp@opera.com>
- CC: "public-script-coord@w3.org" <public-script-coord@w3.org>
Cameron McCormack: >> The simplest choice is probably to select the exactly matching >> overload if there is one, otherwise to select the first overload >> regardless of the types of the actual arguments. So for the above >> example that would select f(object, object). Simon Peters: > interface HTMLOptionsCollection : HTMLCollection { > void add(HTMLOptionElement element, optional HTMLElement? before); > void add(HTMLOptGroupElement element, optional HTMLElement? before); > void add(HTMLOptionElement element, long before); > void add(HTMLOptGroupElement element, long before); > > (HTMLFormElement also has these variants.) > > Consider: > > options.add(document.createElement('optgroup'), "foo"); > > (maybe the second argument comes from an <input type=number> and the > author forgot to convert it from a string to an int.) That's a good argument against the simple choice I proposed. > interface CanvasRenderingContext2D { > CanvasPattern createPattern(HTMLImageElement image, DOMString repetition); > CanvasPattern createPattern(HTMLCanvasElement image, DOMString repetition); > CanvasPattern createPattern(HTMLVideoElement image, DOMString repetition); > void drawImage(HTMLImageElement image, double dx, double dy); > void drawImage(HTMLImageElement image, double dx, double dy, double dw, > double dh); > void drawImage(HTMLImageElement image, double sx, double sy, double sw, > double sh, double dx, double dy, double dw, double dh); > void drawImage(HTMLCanvasElement image, double dx, double dy); > void drawImage(HTMLCanvasElement image, double dx, double dy, double dw, > double dh); > void drawImage(HTMLCanvasElement image, double sx, double sy, double sw, > double sh, double dx, double dy, double dw, double dh); > void drawImage(HTMLVideoElement image, double dx, double dy); > void drawImage(HTMLVideoElement image, double dx, double dy, double dw, > double dh); > void drawImage(HTMLVideoElement image, double sx, double sy, double sw, > double sh, double dx, double dy, double dw, double dh); > > Consider using a <canvas> or <video> in the first argument, but using > the wrong type in another argument. Yes, fair enough. > How does it work when there are different number of arguments? > > ImageData createImageData(double sw, double sh); > ImageData createImageData(ImageData imagedata); Elimination of candidate overloads due to number of arguments is done before looking at the types of values passed in. So if you did createImageData(anImageData, 123); this would select the first overload and convert anImageData to a double. > [NoInterfaceObject] > interface WindowTimers { > long setTimeout(Function handler, optional long timeout, any... args); > long setTimeout([AllowAny] DOMString handler, optional long timeout, > any... args); > long setInterval(Function handler, optional long timeout, any... args); > long setInterval([AllowAny] DOMString handler, optional long timeout, > any... args); > > This already uses [AllowAny], so the wrong type on the first argument > would convert to DOMString. But what if the second argument is of the > wrong type? > > interface WebSocket : EventTarget { > void send(DOMString data); > void send(ArrayBuffer data); > void send(Blob data); > > This should probably convert to DOMString for other types. > > The above extracts are the overloads I found in the HTML spec. What they > have in common is that the first argument is more important than the > other arguments, such that we should try not to convert the first > argument if it's of a matching type. Yes. I'd be reluctant to enshrine overload resolution that favours the first argument, though. It seems just as likely that if you had interface A { void f(float x, Node y); void f(DOMString x, Blob y); }; then you'd want f("0", node) to select the first one. Not sure what the right way forward is yet.
Received on Friday, 9 December 2011 01:30:45 UTC