- From: Boris Zbarsky <bzbarsky@mit.edu>
- Date: Wed, 25 Mar 2015 09:08:44 -0400
- To: Simon Pieters <simonp@opera.com>, "public-fx@w3.org" <public-fx@w3.org>
- CC: "public-script-coord@w3.org" <public-script-coord@w3.org>
On 3/25/15 4:36 AM, Simon Pieters wrote: > I think we shouldn't require any members in particular here. It should > be OK to do e.g.: > > new DOMQuad({}, {x:1}, {x:1, y:1}, {y:1}); OK... My reaction on reading that code would be confusion, but fine. > Yeah. We'll need to check the properties of the first argument to decide > between rect or quad anyway. The question is if the argument length > should be checked first to decide between points or (rect or quad). > Since WebIDL overload checks argument length, it makes sense to me to be > consistent here. But WebIDL unions would just decide based on the type of an argument. Realistically, both approaches are in use in the wild, but the union-like one is more common. > If invoked with zero arguments: > Let /arg1/ be null _converted_ to a DOMQuadInit. > If invoked with one argument: > If /arg1/ _quacks_ like a DOMRectInit and like a DOMQuadInit, throw > TypeError. > If /arg1/ _quacks_ like a DOMRectInit, _convert_ /arg1/ to a > DOMRectInit. > Otherwise, _convert_ /arg1/ to a DOMQuadInit. > Otherwise: > _Convert_ /arg1/ to a DOMPointInit. > > A WebIDL value /object/ *quacks* like a dicationary type /type/ if > _converting_ /object/ to /type/ results in a dictionary with one or more > dictionary members present. I'd rather we just used HasProperty or HasOwnProperty directly instead of doing conversion to a dictionary then scanning the resulting dictionary. That would also force us to be clear about what the spec actually says. The text above is ambiguous about exactly how the "If /arg1/ _quacks_ like a DOMRectInit and like a DOMQuadInit" step is performed. For example, consider this testcase: var val = ""; val exception; var obj = { get p1() { val += "quad"; throw new Error("quaderr"); }, get x() { val += "rect"; throw new Error("recterr"); } } try { new DOMQuad(obj); exception = "none"; } catch (e) { exception = e; } What is the value of "exception" after the above code has run? What is the value of "val"? All of that goes away if we're more explicit about which properties we're checking in which order. We could also get there with more explicit ordering of quacks checks, I guess, but that's harder to keep in mind. Also, explicit checks for particular members are more robust in cases in which dictionaries might have some overlapping member names (which, granted, they don't in this case). -Boris
Received on Wednesday, 25 March 2015 13:09:17 UTC