Commit 8e165acb authored by wingo@igalia.com's avatar wingo@igalia.com

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
parent 07f6d619
...@@ -59,7 +59,7 @@ function SetUpSetIterator() { ...@@ -59,7 +59,7 @@ function SetUpSetIterator() {
)); ));
%FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]'); %FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
%SetProperty(SetIterator.prototype, InternalSymbol('Symbol.iterator'), %SetProperty(SetIterator.prototype, symbolIterator,
SetIteratorSymbolIterator, DONT_ENUM); SetIteratorSymbolIterator, DONT_ENUM);
} }
...@@ -74,7 +74,7 @@ function ExtendSetPrototype() { ...@@ -74,7 +74,7 @@ function ExtendSetPrototype() {
'values', SetValues 'values', SetValues
)); ));
%SetProperty($Set.prototype, InternalSymbol('Symbol.iterator'), SetValues, %SetProperty($Set.prototype, symbolIterator, SetValues,
DONT_ENUM); DONT_ENUM);
} }
...@@ -139,7 +139,7 @@ function SetUpMapIterator() { ...@@ -139,7 +139,7 @@ function SetUpMapIterator() {
)); ));
%FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]'); %FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
%SetProperty(MapIterator.prototype, InternalSymbol('Symbol.iterator'), %SetProperty(MapIterator.prototype, symbolIterator,
MapIteratorSymbolIterator, DONT_ENUM); MapIteratorSymbolIterator, DONT_ENUM);
} }
...@@ -155,7 +155,7 @@ function ExtendMapPrototype() { ...@@ -155,7 +155,7 @@ function ExtendMapPrototype() {
'values', MapValues 'values', MapValues
)); ));
%SetProperty($Map.prototype, InternalSymbol('Symbol.iterator'), MapEntries, %SetProperty($Map.prototype, symbolIterator, MapEntries,
DONT_ENUM); DONT_ENUM);
} }
......
...@@ -179,6 +179,7 @@ DEFINE_implication(harmony, harmony_strings) ...@@ -179,6 +179,7 @@ DEFINE_implication(harmony, harmony_strings)
DEFINE_implication(harmony, harmony_arrays) DEFINE_implication(harmony, harmony_arrays)
DEFINE_implication(harmony_modules, harmony_scoping) DEFINE_implication(harmony_modules, harmony_scoping)
DEFINE_implication(harmony_collections, harmony_symbols) DEFINE_implication(harmony_collections, harmony_symbols)
DEFINE_implication(harmony_generators, harmony_symbols)
DEFINE_implication(harmony, es_staging) DEFINE_implication(harmony, es_staging)
DEFINE_implication(es_staging, harmony_maths) DEFINE_implication(es_staging, harmony_maths)
......
...@@ -32,6 +32,10 @@ function GeneratorObjectThrow(exn) { ...@@ -32,6 +32,10 @@ function GeneratorObjectThrow(exn) {
return %_GeneratorThrow(this, exn); return %_GeneratorThrow(this, exn);
} }
function GeneratorObjectIterator() {
return this;
}
function GeneratorFunctionPrototypeConstructor(x) { function GeneratorFunctionPrototypeConstructor(x) {
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']); throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']);
...@@ -58,6 +62,8 @@ function SetUpGenerators() { ...@@ -58,6 +62,8 @@ function SetUpGenerators() {
DONT_ENUM | DONT_DELETE | READ_ONLY, DONT_ENUM | DONT_DELETE | READ_ONLY,
["next", GeneratorObjectNext, ["next", GeneratorObjectNext,
"throw", GeneratorObjectThrow]); "throw", GeneratorObjectThrow]);
%SetProperty(GeneratorObjectPrototype, symbolIterator, GeneratorObjectIterator,
DONT_ENUM | DONT_DELETE | READ_ONLY);
%SetProperty(GeneratorObjectPrototype, "constructor", %SetProperty(GeneratorObjectPrototype, "constructor",
GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY);
%SetPrototype(GeneratorFunctionPrototype, $Function.prototype); %SetPrototype(GeneratorFunctionPrototype, $Function.prototype);
......
...@@ -29,9 +29,8 @@ ...@@ -29,9 +29,8 @@
// Test aspects of the generator runtime. // Test aspects of the generator runtime.
// FIXME(wingo): Replace this reference with a more official link.
// See: // 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 f() { }
function* g() { yield 1; } function* g() { yield 1; }
...@@ -101,6 +100,16 @@ function TestGeneratorObjectPrototype() { ...@@ -101,6 +100,16 @@ function TestGeneratorObjectPrototype() {
found_property_names.sort(); found_property_names.sort();
assertArrayEquals(expected_property_names, found_property_names); 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(); TestGeneratorObjectPrototype();
......
...@@ -51,7 +51,7 @@ EXPECTED_FUNCTION_COUNT = 358 ...@@ -51,7 +51,7 @@ EXPECTED_FUNCTION_COUNT = 358
EXPECTED_FUZZABLE_COUNT = 325 EXPECTED_FUZZABLE_COUNT = 325
EXPECTED_CCTEST_COUNT = 6 EXPECTED_CCTEST_COUNT = 6
EXPECTED_UNKNOWN_COUNT = 5 EXPECTED_UNKNOWN_COUNT = 5
EXPECTED_BUILTINS_COUNT = 796 EXPECTED_BUILTINS_COUNT = 797
# Don't call these at all. # Don't call these at all.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment