for-of loops, IteratorClose and the rest of the iterations in the spec

Domenic Denicola domenic at domenicdenicola.com
Wed Sep 10 14:12:34 PDT 2014


From: Boris Zbarsky [mailto:bzbarsky at mit.edu] 

> On 9/10/14, 4:57 PM, Domenic Denicola wrote:
>> Relatedly, it would be *really* nice to have a spec-level for-of, both for ES and for web specs.
>
> You mean so people don't have to write things like http://heycam.github.io/webidl/#add-map-elements-from-iterable by hand? 

Sorry, my mail client didn't see the threading on this, so after getting through the rest of my emails I realize that's what much of the rest of the conversation was about. But yes, exactly :)

For https://github.com/heycam/webidl/pull/18, I think it would be ideal to use exact for-of if possible, perhaps after an initial discrimination, instead of manually doing all those things to the iterable.

So yeah, ideally we should define something so that specs can say

> 1. For <var>x</var> of <var>someIterable</var>,
>    1. Use <var>x</var> in some way.

Perhaps WebIDL is the best place to do that for now.

>> (Not to mention a spec-level try/catch, but that's another story...)
>
> Abrupt completions sort of give you that in ES.  Or did you mean so you don't have to sprinkle ReturnIfAbrupt() everywhere?

Right. ReturnIfAbrupt always felt to me like an overreaction to the problem of underspecified exception handling behavior. Something like: "Try: (... substeps ...) Catch _e_: ( ... substeps ... )" would be quite nice, at times.

Relatedly, I am documenting a variety of small [deviations from ES's algorithm conventions that I plan to use while writing the stream spec][1]. We should probably incorporate these into either ES or WebIDL at some point. The intention is to lose some of the verbosity of the ES conventions to the extent that they hurt clarity, while staying within the realm of precision so that the algorithms are unambiguously interpreted by all implementers. Feedback welcome, probably on the repo's issue tracker. Even if the feedback is "this is a bad idea; just do things exactly like ES does to minimize dialects."

[1]: https://github.com/whatwg/streams/blob/move-readable-stream/spec-conventions.md


More information about the es-discuss mailing list