codehag / documenting-invariants

Proposal to document design invariants in TC39
6 stars 3 forks source link

Invariants: Prototype of (async) iterators #9

Open Jack-Works opened 4 years ago

Jack-Works commented 4 years ago

Description

Iterators/generators should have %IteratorPrototype% as its prototype, or in its prototype chain before any ECMAScript code runs.

Async iterators/generators should have %AsyncIteratorPrototype% as its prototype, or in its prototype chain before any ECMAScript code runs.

Violations?

At the current point, there is nothing violating this in the 262 spec.

Rationale: Why did we have this invariant?

Make Iterator Helpers work for all built-in iterators. (initial discussion https://github.com/tc39/ecma262/pull/2045#issuecomment-664992764)

jmdyck commented 4 years ago

Iterators/generators should have %IteratorPrototype% as its prototype, or in its prototype chain before any ECMAScript code runs.

So I think a better way to express this invariant would be: