Reviewers: rossberg,

Message:
On 2014/06/11 12:24:57, rossberg wrote:
LGTM, though it's not used yet, is it?

Correct; it just needed to be in place for for-of to keep on working when I add
@@iterator support there.

Description:
Add @@iterator for generator objects

[email protected]
BUG=

Please review this at https://codereview.chromium.org/328093002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+23, -7 lines):
  M src/collection-iterator.js
  M src/flag-definitions.h
  M src/generator.js
  M test/mjsunit/harmony/generators-runtime.js
  M tools/generate-runtime-tests.py


Index: src/collection-iterator.js
diff --git a/src/collection-iterator.js b/src/collection-iterator.js
index fbf30ae24068d218cdfefdd1852d93817707b1d2..2436a931e28bc4acde80f5c4a8143cc0bff5b8f3 100644
--- a/src/collection-iterator.js
+++ b/src/collection-iterator.js
@@ -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: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index 1b8a20d7757cbe6595459f0719e65d5331584e4b..9f6d40bb840d4677976dd30dbe225aa82d3def37 100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -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: src/generator.js
diff --git a/src/generator.js b/src/generator.js
index c152e3a6eea369d4c4306bb946df2d5edeeed29e..3133eddf3f3cea113513095ea167b91c589726da 100644
--- a/src/generator.js
+++ b/src/generator.js
@@ -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']);
@@ -56,6 +60,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: test/mjsunit/harmony/generators-runtime.js
diff --git a/test/mjsunit/harmony/generators-runtime.js b/test/mjsunit/harmony/generators-runtime.js index 196adff81b0ae586427115496e5c79b01822f513..9fb70754928e2ebe990694694a352cc4a9c9558d 100644
--- a/test/mjsunit/harmony/generators-runtime.js
+++ b/test/mjsunit/harmony/generators-runtime.js
@@ -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: tools/generate-runtime-tests.py
diff --git a/tools/generate-runtime-tests.py b/tools/generate-runtime-tests.py index 71b46c673f8eed2c7cb8b31b59a02f7a6a00e68d..1811f9e43f2f03ba144f93d63060474bd34d2f8b 100755
--- a/tools/generate-runtime-tests.py
+++ b/tools/generate-runtime-tests.py
@@ -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.


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to