yield* desugaring

Andy Wingo wingo at igalia.com
Mon Apr 29 08:37:51 PDT 2013


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:


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)
      try {
        received = yield next.value;  // ***
        send = true;
      } catch (e) {
        received = e;
        send = false;

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.


More information about the es-discuss mailing list