From: wingo@igalia.com Date: Thu, 12 Jun 2014 08:53:07 +0000 (+0000) Subject: Add @@iterator for generator objects X-Git-Tag: upstream/4.7.83~8716 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e165acbdff28c2d36487735f3161e562ab1ca91;p=platform%2Fupstream%2Fv8.git Add @@iterator for generator objects 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 --- diff --git a/src/collection-iterator.js b/src/collection-iterator.js index fbf30ae..2436a93 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); } diff --git a/src/flag-definitions.h b/src/flag-definitions.h index 1b8a20d..9f6d40b 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) diff --git a/src/generator.js b/src/generator.js index 1ca3fd4..abcb867 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']); @@ -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); diff --git a/test/mjsunit/harmony/generators-runtime.js b/test/mjsunit/harmony/generators-runtime.js index 196adff..9fb7075 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(); diff --git a/tools/generate-runtime-tests.py b/tools/generate-runtime-tests.py index 71b46c6..1811f9e 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.