Skip to content

Support generator return values in QuickJSIterator #221

New issue

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

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

Already on GitHub? # to your account

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

Conversation

melbourne2991
Copy link

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"

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

Successfully merging this pull request may close these issues.

1 participant