Closed Bug 559614 Opened 14 years ago Closed 13 years ago

Rectify availability of the Generator constructor in JS

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
minor

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: dimsal.public, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)

The Generator constructor from JS1.7+ appears to be irregular: it is reported only when inquiring the type of generator expressions/variables but appears to be undefined otherwise unlike regular javascript functions/objects.

Reproducible: Always

Steps to Reproduce:
1. alert(x for (x in [null]));
2. alert((x for (x in [null])).__proto__);
3. alert(typeof Generator);
4. Generator.prototype.subject = function(functor) (functor(i) for(i in this));
5. Generator.prototype.run = function(functor) { for(i in this) functor(i); };
Actual Results:  
1. alert(x for (x in [null])); >>> [object Generator] (ok!)
2. alert((x for (x in [null])).__proto__); >>> [object Generator] (ok!)
3. alert(typeof Generator); >>> undefined (surprise: not ok!)
4. Generator.prototype.subject = function(functor)... >>> ReferenceError: Generator is not defined (not ok!)
5. Generator.prototype.run = function(functor) ... >>> ReferenceError: Generator is not defined (not ok!)

Expected Results:  
3. alert(typeof Generator) => function


Regular access to the Generator should enable useful and interesting methods through prototype extensions (trivial sample cases are demonstrated with Generator.prototype.subject and Generator.prototype.run). This should enhance the expressive power of the generator expressions, especially once methods for chaining and modification of existing generators (sort of LINQ-style) are defined.
Closing this since generator prototype can be obtained indirectly via __proto__ or Object.getPrototypeOf() with a dummy generator, and no further discussion came out of this request.
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.