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

Re: How to correctly spec sequences requiring an iterable

From: Allen Wirfs-Brock <allen@wirfs-brock.com>
Date: Fri, 15 Nov 2013 09:40:32 -0800
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-Id: <3C528515-F99D-40A5-8008-38F02D118E9E@wirfs-brock.com>
To: Boris Zbarsky <bzbarsky@MIT.EDU>

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.

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

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