Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread Brendan Eich
Sorry, this is both foolish consistency and a boilerplate tax on users. Worse, it removes a special form (syntax dedicated to a new primitive) that implementations need to parse, in order to compile and optimize the function using the primitive. We are not going to add a Generator constructor.

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread Dmitry A. Soshnikov
On 15.03.2011 21:13, John J. Barton wrote: On 11:59 AM, Dmitry A. Soshnikov wrote: Moreover, forgot to mention. Passing the generator function ("g-function" and "g-object" for shortness) as an argument for the `Generator` constructor is not good for dynamically bound `this` value (notice, that

Re: Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread John J. Barton
On 11:59 AM, David Herman wrote: P.S.: A small change, e.g. can be to make next as a getter since it doesn't accept arguments. g.next; // 1 g.next; // 2 But, it's a cosmetic and actually not so needed change. -1 The purpose of the next interface is to change the state of the iterator. A ge

Re: Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread John J. Barton
On 11:59 AM, Dmitry A. Soshnikov wrote: Moreover, forgot to mention. Passing the generator function ("g-function" and "g-object" for shortness) as an argument for the `Generator` constructor is not good for dynamically bound `this` value (notice, that in Python's `self` is just a casual variabl

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread David Herman
I agree with Dmitry on these points. In short: the new Generator(...) syntax still requires its argument to be a generator function, so you've just added pointless extra make-work to create one. And as Dmitry points out, you can always implement that constructor yourself in JS. What I think is

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread Dmitry A. Soshnikov
On 15.03.2011 20:21, David Herman wrote: P.S.: A small change, e.g. can be to make next as a getter since it doesn't accept arguments. g.next; // 1 g.next; // 2 But, it's a cosmetic and actually not so needed change. -1 The purpose of the next interface is to change the state of the iterato

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread Dmitry A. Soshnikov
Moreover, forgot to mention. Passing the generator function ("g-function" and "g-object" for shortness) as an argument for the `Generator` constructor is not good for dynamically bound `this` value (notice, that in Python's `self` is just a casual variable/argument, which should be passed manua

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread David Herman
> P.S.: > > A small change, e.g. can be to make next as a getter since it doesn't accept > arguments. > > g.next; // 1 > g.next; // 2 > > But, it's a cosmetic and actually not so needed change. -1 The purpose of the next interface is to change the state of the iterator. A getter interface ob

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread Dmitry A. Soshnikov
On 15.03.2011 17:58, John J. Barton wrote: On 3/14/2011 10:08 PM, Brendan Eich wrote: On Mar 14, 2011, at 11:50 PM, John J. Barton wrote: On 11:59 AM, Brendan Eich wrote: However, there's no way for a generator function to return that instance, because a generator function always implicitly r

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-15 Thread John J. Barton
On 3/14/2011 10:08 PM, Brendan Eich wrote: On Mar 14, 2011, at 11:50 PM, John J. Barton wrote: On 11:59 AM, Brendan Eich wrote: However, there's no way for a generator function to return that instance, because a generator function always implicitly returns a fresh generator iterator when inv

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-14 Thread Brendan Eich
On Mar 14, 2011, at 11:50 PM, John J. Barton wrote: > On 11:59 AM, Brendan Eich wrote: >> However, there's no way for a generator function to return that instance, >> because a generator function always implicitly returns a fresh generator >> iterator when invoked. It could store |this| in the h

Re: Re: yield and new : SpiderMonkey and the draft Spec

2011-03-14 Thread John J. Barton
On 11:59 AM, Brendan Eich wrote: However, there's no way for a generator function to return that instance, because a generator function always implicitly returns a fresh generator iterator when invoked. It could store |this| in the heap, and whatever value |this| receives is saved as part of t

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-14 Thread Dmitry A. Soshnikov
On 14.03.2011 23:02, Brendan Eich wrote: I.e. again, what I notice (and asked), is that there's no any info in the draft spec about `this` value of the generator's context. I think it would be good to add this information. A generator function is still a function, and |this| binding is orthogo

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-14 Thread Brendan Eich
> I.e. again, what I notice (and asked), is that there's no any info in the > draft spec about `this` value of the generator's context. I think it would be > good to add this information. A generator function is still a function, and |this| binding is orthogonal to yield making the surrounding

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-14 Thread Dmitry A. Soshnikov
On 14.03.2011 16:51, Brendan Eich wrote: On Mar 14, 2011, at 3:02 AM, Dmitry Soshnikov wrote: Yep, thanks Brendan, I filed the bug https://bugzilla.mozilla.org/show_bug.cgi?id=641436 But the thing with `this` is still interesting for me. So in this particular case `this` should be set to `un

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-14 Thread Brendan Eich
On Mar 14, 2011, at 3:02 AM, Dmitry Soshnikov wrote: > Yep, thanks Brendan, > > I filed the bug https://bugzilla.mozilla.org/show_bug.cgi?id=641436 > > But the thing with `this` is still interesting for me. So in this particular > case `this` should be set to `undefined`. No, |this| is not set

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-14 Thread Dmitry Soshnikov
Yep, thanks Brendan, I filed the bug https://bugzilla.mozilla.org/show_bug.cgi?id=641436 But the thing with `this` is still interesting for me. So in this particular case `this` should be set to `undefined`. Should it be always set to `undefined` (strict) / global object and regardless -- calling

Re: yield and new : SpiderMonkey and the draft Spec

2011-03-13 Thread Brendan Eich
Hi Dmitry, It looks to me like you've just found a bug in SpiderMonkey's generator implementation, which pre-dates the strawman:generators proposal by four+ years. Please file it in the right place: https://bugzilla.mozilla.org/. Thanks. The bug is a regression. Here's what my Firefox 3-era JS

yield and new : SpiderMonkey and the draft Spec

2011-03-13 Thread Dmitry A. Soshnikov
Hello, I hope you can help with explaining of what is going on with `this` value inside the body of a generator? Consider e.g. the following case: // infinite objects generator let g = new function () { this.x = 10; while (true) { yield; } }; // generate an array of 3 objects let o