.next('yo') in newborn generators

David Bruant bruant.d at gmail.com
Wed Jan 15 12:33:30 PST 2014


Le 15/01/2014 17:50, Allen Wirfs-Brock a écrit :
>
> On Jan 15, 2014, at 8:32 AM, David Bruant wrote:
>
>> Hi,
>>
>> Playing with the test cases of the regenerator project [1], I came 
>> across a case and was wondering what the intention of the spec is 
>> given that Firefox and Chrome recent implementations diverge.
>> Apologies for not reading all the previous discussions on this edge case.
>>
>> Test case:
>> ````js
>> function *gen(x) {
>>    yield x;
>> }
>>
>> var g = gen('whatever');
>> console.log(g.next(0));
>> ````
>>
>> Chrome & regenerator:
>> {value: "whatever", done: false}
>>
>> Firefox (Aurora 28):
>> TypeError: attempt to send 0 to newborn generator
>>
>> From what I understand, the spec says an error should be thrown 
>> because the generator is in "suspendedStart" state and value is not 
>> undefined (25.3.3.2 GeneratorResume step 7).
>
> Yes, that's what the spec, requires.  This check was in the the 
> original Generator proposal 
> http://wiki.ecmascript.org/doku.php?id=harmony:generators#internal_methodsend 
>
>
> It's an error because there is no mechanism for a generator to receive 
> the argument passed by the first next.
Sounds good.
Bugs on V8 and regenerator for those interested:
https://code.google.com/p/v8/issues/detail?id=3099
https://github.com/facebook/regenerator/issues/76

David


More information about the es-discuss mailing list