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

ES6 Generators #824

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

ES6 Generators #824

wants to merge 1 commit into from

Conversation

lahma
Copy link
Collaborator

@lahma lahma commented Jan 3, 2021

No description provided.

@ayende
Copy link
Contributor

ayende commented Jan 4, 2021

👏

@roobscoob
Copy link

Bump? Looking to use generators to represent coroutines and this pr would be extremely helpful

@lahma
Copy link
Collaborator Author

lahma commented Feb 20, 2021

@roobscoob would you want to make contributions to push this forward?

@roobscoob
Copy link

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

@lahma lahma force-pushed the es6-generators branch 2 times, most recently from 9afa790 to ac536ce Compare July 20, 2021 19:33
@lahma lahma added the es6 label Dec 12, 2021
@lahma
Copy link
Collaborator Author

lahma commented Jul 6, 2022

Current status is quite good, some 4500 more passing tests now.

main:

Passed!  - Failed:     0, Passed: 47164, Skipped: 13520, Total: 60684, Duration: 31 s - Jint.Tests.Test262.dll (net6.0)

this branch:

Failed!  - Failed:   490, Passed: 51675, Skipped: 10040, Total: 62205, Duration: 32 s - Jint.Tests.Test262.dll (net6.0)

@sebastienros
Copy link
Owner

I should disallow force-pushing ;)

@lahma
Copy link
Collaborator Author

lahma commented Oct 24, 2022

That would be quite beautiful commit history indeed...

@cesarchefinho
Copy link

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

@lahma
Copy link
Collaborator Author

lahma commented Dec 29, 2022

@cesarchefinho would you be contributing?

@scgm0
Copy link
Contributor

scgm0 commented Dec 20, 2023

Is this PR still in progress?

@lahma
Copy link
Collaborator Author

lahma commented Dec 20, 2023

Is this PR still in progress?

Yes.

@ClearCutDevel
Copy link

Are there plans to support yield* (with asterisk)?

@lahma
Copy link
Collaborator Author

lahma commented Mar 6, 2024

Are there plans to support yield* (with asterisk)?

I believe it's this.

@ClearCutDevel
Copy link

Granted I may not understand this implementation too well I was wondering about this piece of code in JintStatementList.cs

if (_generator) { if (context.Engine.ExecutionContext.Suspended) { _index = i + 1; c = new Completion(CompletionType.Return, c.Value, pair.Statement._statement); break; } }

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.

@lahma
Copy link
Collaborator Author

lahma commented Mar 8, 2024

Yes as you can see the tests aren't passing yet and this in a draft PR, it isn't fully working.

@ClearCutDevel
Copy link

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.

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

Successfully merging this pull request may close these issues.

7 participants