Closed Bug 666404 Opened 13 years ago Closed 11 years ago

allow returning values from generators

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: dherman, Unassigned)

References

(Blocks 1 open bug, )

Details

Harmony is extending generators to allow them to return values, similarly to Python's PEP 380.

One API detail that hasn't been worked out: presently our generators throw StopIteration when a generator returns. We want to preserve that the following two statements are equivalent:

    return;
    return (void 0);

but if StopIteration becomes a constructor that wraps a value, then we'll be incompatible with existing SpiderMonkey code that tests (e === StopIteration). We could special-case the StopIteration function to produce itself when called on the undefined value, but that's a little warty if it's just being done for Firefox backwards-compatibility.

I'll do some spelunking through the Firefox codebase and the addons to see how often code is comparing StopIteration via === or ==, to try to get some data.

Dave
Blocks: es6
This bug is probably moot with the updated iterator protocol where each iteration returns an object. In a generator:

> yield 5;
> //-> { done: false, value: 5 }

> return 5;
> //-> { done: true, value: 5 }

rendering ES6 iterators/generators completely incompatible with JS1.8 ones.
I think this can be resolved WORKSFORME with star generators having been mostly landed.
ES6 generators have been fully implemented now, resolving this.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.