Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator function default parameter value initializers should be evaluated when the generator function is called not at first next() call #300

Closed
ianwjhalliday opened this issue Feb 11, 2016 · 5 comments
Assignees
Milestone

Comments

@ianwjhalliday
Copy link
Collaborator

Currently default parameter value initializers are evaluated on the first call to next() on the resulting generator object from a call to a generator function. The ES spec says they should be evaluated on the call to the generator function itself, before it returns the generator object.

E.g.

let x = 0;
function* gf(a = x = 1) { }
let g = gf();
print(x); // should print 1, not 0

One simple solution might be to put a yield between the default parameter initializers and the body in the bytecode and then in the generator function call stub, call next() once, then return the generator object.

@ljharb
Copy link
Collaborator

ljharb commented Feb 11, 2016

If I've modified %IteratorPrototype%.next, wouldn't that be observable?

@ianwjhalliday
Copy link
Collaborator Author

We would call the generator next function directly for this purpose. Indeed we'd only do it this way if we can guarantee no observable effects. I believe this is possible but haven't explored the idea in depth.

@abchatra abchatra added this to the 1.2 milestone Mar 10, 2016
@abchatra
Copy link
Contributor

abchatra commented May 4, 2016

@ianwjhalliday Any update on this issue?

@ianwjhalliday
Copy link
Collaborator Author

No, have not had and still do not have time to look into this yet. If someone else can take it up that would be great. @aneeshdk?

@abchatra abchatra assigned aneeshdk and unassigned ianwjhalliday May 4, 2016
@abchatra abchatra removed this from the 1.2 milestone May 5, 2016
@dilijev dilijev modified the milestone: Backlog Dec 16, 2016
@aneeshdk
Copy link
Contributor

#2941

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants