Re: How to correctly spec sequences requiring an iterable

On 11/15/13 11:15 AM, Domenic Denicola wrote:
> Channeling Allen... I think the "correct" (or, less prescriptively, "idiomatic") way to do this would be to just iterate over the incoming object and see what happens, letting any thrown errors bubble out.

That's not quite feasible if it's used in a union type; in that case you 
have to move on to the next union member if the given thing is not 
actually a useful sequence.

In practice this only affects unions of sequence with 
string/numeric/boolean types.  So a plausible option for the union case 
is to just check whether it's an object and if so go ahead and iterate 
it, I guess.

This is extra fun is that you can in fact iterate over a primitive string...

> But, bringing us back to reality, i.e. to WebIDL's argument-check-immediately paradigm, trying to iterate over anything except something where GetProperty(obj, @@iterator) returns a callable object will throw a TypeError pretty quickly. So I think it's that.

OK.  That does still leave the string issue; should a string be 
considered a sequence when the union contains both sequence and 
DOMString?  What if it's a union of sequence and number?

A priori, I would guess people would be surprised if a primitive string 
got considered a sequence.

-Boris

Received on Friday, 15 November 2013 16:22:17 UTC