Skip to content

Editorial convention: Yield vs GeneratorYield #3663

@nicolo-ribaudo

Description

@nicolo-ribaudo

Looking through built-in functions defined as generators, some of them use Yield() while other use GeneratorYield(). There doesn't seem to be a clear rule about which one to use when. For example:

  • 7 uses of Yield(), out of which two are for yield; and yield expr;
  • 9 uses of GeneratorYield(), out of which one is in Yield() and three in yield* expr
  • AsyncGeneratorYield() is only used in Yield() and yield* expr
  • https://tc39.es/ecma262/#sec-generatorstart introduces 4 more usages of Yield()

The difference between Yield() and GeneratorYield()/AsyncGeneratorYield() is that Yield() first checks if we are in a sync or async generator, and then dispatches to the right AO.

It'd be great if there was a consistent guideline around it. Either:

  • Always use Yield(). GeneratorYield()/AsyncGeneratorYield() are only called by Yield() itself.
  • Always use the correct one between GeneratorYield()/AsyncGeneratorYield(), whenever it's know whether we are in a sync or async built-in generator. Yield() would only be used to implement the actual yield syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions