Add @@iterator for generator objects
authorwingo@igalia.com <wingo@igalia.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 12 Jun 2014 08:53:07 +0000 (08:53 +0000)
committerwingo@igalia.com <wingo@igalia.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 12 Jun 2014 08:53:07 +0000 (08:53 +0000)
R=arv@chromium.org, rossberg@chromium.org
BUG=

Review URL: https://codereview.chromium.org/328093002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21797 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/collection-iterator.js
src/flag-definitions.h
src/generator.js
test/mjsunit/harmony/generators-runtime.js
tools/generate-runtime-tests.py

index fbf30ae..2436a93 100644 (file)
@@ -59,7 +59,7 @@ function SetUpSetIterator() {
   ));
 
   %FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
-  %SetProperty(SetIterator.prototype, InternalSymbol('Symbol.iterator'),
+  %SetProperty(SetIterator.prototype, symbolIterator,
       SetIteratorSymbolIterator, DONT_ENUM);
 }
 
@@ -74,7 +74,7 @@ function ExtendSetPrototype() {
     'values', SetValues
   ));
 
-  %SetProperty($Set.prototype, InternalSymbol('Symbol.iterator'), SetValues,
+  %SetProperty($Set.prototype, symbolIterator, SetValues,
       DONT_ENUM);
 }
 
@@ -139,7 +139,7 @@ function SetUpMapIterator() {
   ));
 
   %FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
-  %SetProperty(MapIterator.prototype, InternalSymbol('Symbol.iterator'),
+  %SetProperty(MapIterator.prototype, symbolIterator,
       MapIteratorSymbolIterator, DONT_ENUM);
 }
 
@@ -155,7 +155,7 @@ function ExtendMapPrototype() {
     'values', MapValues
   ));
 
-  %SetProperty($Map.prototype, InternalSymbol('Symbol.iterator'), MapEntries,
+  %SetProperty($Map.prototype, symbolIterator, MapEntries,
       DONT_ENUM);
 }
 
index 1b8a20d..9f6d40b 100644 (file)
@@ -179,6 +179,7 @@ DEFINE_implication(harmony, harmony_strings)
 DEFINE_implication(harmony, harmony_arrays)
 DEFINE_implication(harmony_modules, harmony_scoping)
 DEFINE_implication(harmony_collections, harmony_symbols)
+DEFINE_implication(harmony_generators, harmony_symbols)
 
 DEFINE_implication(harmony, es_staging)
 DEFINE_implication(es_staging, harmony_maths)
index 1ca3fd4..abcb867 100644 (file)
@@ -32,6 +32,10 @@ function GeneratorObjectThrow(exn) {
   return %_GeneratorThrow(this, exn);
 }
 
+function GeneratorObjectIterator() {
+  return this;
+}
+
 function GeneratorFunctionPrototypeConstructor(x) {
   if (%_IsConstructCall()) {
     throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']);
@@ -58,6 +62,8 @@ function SetUpGenerators() {
                    DONT_ENUM | DONT_DELETE | READ_ONLY,
                    ["next", GeneratorObjectNext,
                     "throw", GeneratorObjectThrow]);
+  %SetProperty(GeneratorObjectPrototype, symbolIterator, GeneratorObjectIterator,
+      DONT_ENUM | DONT_DELETE | READ_ONLY);
   %SetProperty(GeneratorObjectPrototype, "constructor",
                GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY);
   %SetPrototype(GeneratorFunctionPrototype, $Function.prototype);
index 196adff..9fb7075 100644 (file)
@@ -29,9 +29,8 @@
 
 // Test aspects of the generator runtime.
 
-// FIXME(wingo): Replace this reference with a more official link.
 // See:
-// http://wiki.ecmascript.org/lib/exe/fetch.php?cache=cache&media=harmony:es6_generator_object_model_3-29-13.png
+// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorfunction-objects
 
 function f() { }
 function* g() { yield 1; }
@@ -101,6 +100,16 @@ function TestGeneratorObjectPrototype() {
   found_property_names.sort();
 
   assertArrayEquals(expected_property_names, found_property_names);
+
+  iterator_desc = Object.getOwnPropertyDescriptor(GeneratorObjectPrototype,
+      Symbol.iterator);
+  assertTrue(iterator_desc !== undefined);
+  assertFalse(iterator_desc.writable);
+  assertFalse(iterator_desc.enumerable);
+  assertFalse(iterator_desc.configurable);
+
+  // The generator object's "iterator" function is just the identity.
+  assertSame(iterator_desc.value.call(42), 42);
 }
 TestGeneratorObjectPrototype();
 
index 71b46c6..1811f9e 100755 (executable)
@@ -51,7 +51,7 @@ EXPECTED_FUNCTION_COUNT = 358
 EXPECTED_FUZZABLE_COUNT = 325
 EXPECTED_CCTEST_COUNT = 6
 EXPECTED_UNKNOWN_COUNT = 5
-EXPECTED_BUILTINS_COUNT = 796
+EXPECTED_BUILTINS_COUNT = 797
 
 
 # Don't call these at all.