Re: How to correctly spec sequences requiring an iterable

On Nov 15, 2013, at 8:38 AM, Boris Zbarsky wrote:

> On 11/15/13 11:26 AM, Allen Wirfs-Brock wrote:
>> It is defined in the ES6 spec.  See
>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-common-iteration-interfaces
> 
> So if I read this right, this is proposing:
> 
> 1)  Check that |iterator = GetProperty(obj, @@iterator)| returns a
>    callable object.
> 2)  Check that |obj2 = iterator.call(obj)| returns an object.
> 3)  Check that GetProperty(obj2, "next") is a function.
> 4)  ???
> 
> Or am I misreading the "Requirements" column in that only the "Value" column determines whether something implements the interface?

To be a  fully conforming implementation of the interface, an object must support the requirements from all the columns.  But normally, you would not try to check all those requirements to make a union-type discrimination check  for an interface. Normally, you would only check for the existence of property keys from the Property column.  Even there, not necessarily all of them.  For example for IteratorResult you would only want to check for 'done' if you needed to discriminate it.

In general you want to make the smallest useful union discrimination check and then let any other interface requirements turn into runtime usage errors.

Allen

Received on Friday, 15 November 2013 17:41:01 UTC