Skip to content

Support generator return values in QuickJSIterator#221

Merged
justjake merged 1 commit intojustjake:mainfrom
melbourne2991:support-generator-return-values
Feb 15, 2026
Merged

Support generator return values in QuickJSIterator#221
justjake merged 1 commit intojustjake:mainfrom
melbourne2991:support-generator-return-values

Conversation

@melbourne2991
Copy link
Copy Markdown
Contributor

Currently the quickjs iterator does not support generator function return values, as it assumes when done === true then value === undefined.

This is not the case for generator-derived iterators

function* () {
   return "some value"
}

MDN docs are a little vague on this so I can understand the confusion

Any JavaScript value returned by the iterator. Can be omitted when done is true.

However - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*#description:

A function* declaration creates a GeneratorFunction object. Each time a generator function is called, it returns a new Generator object, which conforms to the iterator protocol.

A return statement in a generator, when executed, will make the generator finish (i.e. the done property of the object returned by it will be set to true). If a value is returned, it will be set as the value property of the object returned by the generator.

I guess the key word is "can" be omitted, not "must"

@justjake justjake merged commit 57fb97c into justjake:main Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants