github at esdiscuss.org (2013-07-12T02:27:00.483Z)
I understand that the consensus among those present at the last TC39
meeting was that iterators should box their return values in objects of
the form
```js
{ value: VALUE, done: DONE }
```
where DONE is true or false. Notes here:
https://github.com/rwldrn/tc39-notes/blob/master/es6/2013-03/mar-12.md#412-stopiterationgenerator
For what it's worth (which is very little) this seems like a decent
plan to me.
The desugaring of `yield* EXPR` with boxed return values would be:
```js
let (g = EXPR) {
let received = void 0, send = true;
while (true) {
let next = send ? g.send(received) : g.throw(received);
if (next.done)
break;
try {
received = yield next.value; // ***
send = true;
} catch (e) {
received = e;
send = false;
}
}
next.value;
}
```
As you can see on the line marked "***", to desugar to plain `yield` you
would have to unbox the value and then allow yield to rebox it. This
loses any state on `next` -- there could be other properties set on
`next`, for example if `g` is a non-generator.
IMHO `yield*` should be specified to return the result object as-is,
without re-boxing. This precludes a straightforward desugaring, but it
is probably more flexible.
Hello, I understand that the consensus among those present at the last TC39 meeting was that iterators should box their return values in objects of the form { value: VALUE, done: DONE } where DONE is true or false. Notes here: https://github.com/rwldrn/tc39-notes/blob/master/es6/2013-03/mar-12.md#412-stopiterationgenerator For what it's worth (which is very little) this seems like a decent plan to me. The desugaring of "yield* EXPR" with boxed return values would be: let (g = EXPR) { let received = void 0, send = true; while (true) { let next = send ? g.send(received) : g.throw(received); if (next.done) break; try { received = yield next.value; // *** send = true; } catch (e) { received = e; send = false; } } next.value; } As you can see on the line marked "***", to desugar to plain "yield" you would have to unbox the value and then allow yield to rebox it. This loses any state on "next" -- there could be other properties set on "next", for example if "g" is a non-generator. IMHO yield* should be specified to return the result object as-is, without re-boxing. This precludes a straightforward desugaring, but it is probably more flexible. Andy