State of generators?

# Juan Ignacio Dopazo (12 years ago)

Hello,

I'm having trouble understanding the current status of generators. Last time I checked, the standard was what V8 has just implemented:

  • Generator objects had next(), send(), throw() and close() methods
  • These methods returned objects with "value" and "done" properties

It seems now that:

  • send() and close() are gone
  • next(value) seems to be the same as send(value)
  • All methods seem to return the yielded result, not an object with a "value" property

So, is StopIteration back? How do we know if a generator is done?

Thanks, Juan

# Brian Di Palma (12 years ago)

I don't know what version of V8 you are using but I'm using them in unstable Node.js so V8 is v3.19. The StopIteration is gone and they do return an object with the "value" property.

I think Chrome 29 would be the browser version you should be testing with.

# Allen Wirfs-Brock (12 years ago)

The currently posted spec draft is up to date WRT generators

# Rick Waldron (12 years ago)

I've just filed these:

ecmascript#1555, ecmascript#1556

# Allen Wirfs-Brock (12 years ago)

close and send have been eliminated. The latest spec draft (rev 15) reflects that and includes an updated diagram

# Allen Wirfs-Brock (12 years ago)

On Jun 8, 2013, at 1:42 PM, Juan Ignacio Dopazo wrote:

I'm having trouble understanding the current status of generators. Last time I checked, the standard was what V8 has just implemented:

  • Generator objects had next(), send(), throw() and close() methods
  • These methods returned objects with "value" and "done" properties

It seems now that:

  • send() and close() are gone

yes, those have been eliminated

  • next(value) seems to be the same as send(value)

yes, next(value) replaces send(value)

  • All methods seem to return the yielded result, not an object with a "value" property

No, yield produces a nextResult object. The last line of the yield runtime semantics in 13.4.1.2 is:

Return the result of GeneratorYield(CreateItrResultObject(value, false)).

Note that a iteration result object is being created and passed to the abstract operation at does the actual context switch.

So, is StopIteration back? How do we know if a generator is done?

No. via a object that implements the ItrResult (name subject to change) interface as specified in 15.19.1.3

# Juan Ignacio Dopazo (12 years ago)

I totally missed the CreateItrResultObject part. Thank you very much!

# Rick Waldron (12 years ago)

On Sat, Jun 8, 2013 at 7:29 PM, Rick Waldron <waldron.rick at gmail.com> wrote:

I've just filed these:

ecmascript#1555, ecmascript#1556

Thanks to Allen for the follow up clarifications on this thread and to the bugs filed above. I've filed a bug against the v8 implementation:

code.google.com/p/v8/issues/detail?id=2715