W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2013

Re: How to correctly spec sequences requiring an iterable

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Fri, 15 Nov 2013 11:21:50 -0500
Message-ID: <52864A1E.1050503@mit.edu>
To: Domenic Denicola <domenic@domenicdenicola.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>
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.

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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:19 UTC