-
-
Notifications
You must be signed in to change notification settings - Fork 564
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
ES6 Generators #824
base: main
Are you sure you want to change the base?
ES6 Generators #824
Conversation
👏 |
Bump? Looking to use generators to represent coroutines and this pr would be extremely helpful |
@roobscoob would you want to make contributions to push this forward? |
I would love to, though I don't think I'm good enough at c# to make meaningful contributions that won't waste people's time fixing. That said I'll take a look at src and figure out what's left to do. If I can, I'll give it a go |
9afa790
to
ac536ce
Compare
2a6cabb
to
aeea811
Compare
aeea811
to
161eeda
Compare
Current status is quite good, some 4500 more passing tests now. main:
this branch:
|
09c4148
to
79a0d87
Compare
I should disallow force-pushing ;) |
That would be quite beautiful commit history indeed... |
may be splitting this PR into small parts that can be merged improve failing tests score and make possible other guys help with other PRs |
@cesarchefinho would you be contributing? |
8cc1487
to
29dfdf6
Compare
Is this PR still in progress? |
Yes. |
29dfdf6
to
3a5756c
Compare
fedcf93
to
f4aa3ed
Compare
Are there plans to support yield* (with asterisk)? |
I believe it's this. |
Granted I may not understand this implementation too well I was wondering about this piece of code in JintStatementList.cs
Unlike normal yield, yield* should not just skip to the next statement (_index = i + 1) if its source iterator / generator isn't yet finished. If I misunderstand it please explain why this expression is actually correct for delegating yield. |
Yes as you can see the tests aren't passing yet and this in a draft PR, it isn't fully working. |
I also tried a few more tests below: public void ForLoopYield()
{
// https://jsfiddle.net/rbwht2ve/3/
const string Script = """
const foo = function*() {
for(var i = 0; i < 5; yield i++) {}
};
let str = '';
for (const val of foo()) {
str += val;
}
return str;
""";
var engine = new Engine();
Assert.Equal("01234", engine.Evaluate(Script));
}
[Fact]
public void DelegateYield()
{
// https://jsfiddle.net/164sp2Ld/
const string Script = """
function* bar() {
yield 'a';
yield 'b';
}
function* foo() {
yield 'x';
yield* bar(); // Delegating yield to bar
yield 'y';
}
let str = '';
for (const val of foo()) {
str += val;
}
return str;
""";
var engine = new Engine();
Assert.Equal("xaby", engine.Evaluate(Script));
} This would require modifying several *Statement.cs files including For, While, DoWhile, or even Switch. ExecutionContext may also need to accommodate for those changes. I'm not sure how you would modify the JintForStatement to accommodate for yield in any of the three statements (init; condition; update) (also see my test above) but if you can get it started I can follow your example and implement it in While; DoWhile; Switch and wherever else it could be used. |
No description provided.