quickjs-emscripten
quickjs-emscripten copied to clipboard
Support generator return values in QuickJSIterator
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"