Reviewers: wingo, adamk,
Message:
PTAL
Description:
[es6] Iterators and generators should "extend" %IteratorPrototype%
All the builtin iterators as well as the generator objects have an
object called %IteratorPrototype% in the spec between them and
%ObjectPrototype%.
BUG=v8:3568
LOG=N
Please review this at https://codereview.chromium.org/1128233008/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+17, -53 lines):
M BUILD.gn
M src/array-iterator.js
M src/bootstrapper.cc
M src/collection-iterator.js
M src/generator.js
M src/string-iterator.js
M test/mjsunit/es6/generators-runtime.js
M tools/gyp/v8.gyp
Index: BUILD.gn
diff --git a/BUILD.gn b/BUILD.gn
index
5a743606293a1edfc546cf532be2bcc1fb19634a..fc3682ccea270a09f84f1e5c9f08bc5caa375067
100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -202,7 +202,7 @@ action("js2c") {
sources = [
"src/macros.py",
- "src/messages.h",
+ "src/messages.h",
"src/runtime.js",
"src/v8natives.js",
"src/symbol.js",
@@ -215,6 +215,7 @@ action("js2c") {
"src/regexp.js",
"src/arraybuffer.js",
"src/typedarray.js",
+ "src/iterator-prototype.js",
"src/generator.js",
"src/object-observe.js",
"src/collection.js",
@@ -264,7 +265,7 @@ action("js2c_experimental") {
sources = [
"src/macros.py",
- "src/messages.h",
+ "src/messages.h",
"src/proxy.js",
"src/generator.js",
"src/harmony-array.js",
Index: src/array-iterator.js
diff --git a/src/array-iterator.js b/src/array-iterator.js
index
24bf7e5c9a93da40832e7c72c1c919f55e8a9e86..2d1a2a652c3092e903b8742bd0ce1b4551ea0abe
100644
--- a/src/array-iterator.js
+++ b/src/array-iterator.js
@@ -12,7 +12,6 @@ var $arrayValues;
%CheckIsBootstrapping();
var GlobalArray = global.Array;
-var GlobalObject = global.Object;
macro TYPED_ARRAYS(FUNCTION)
FUNCTION(Uint8Array)
@@ -122,7 +121,7 @@ function ArrayKeys() {
}
-%FunctionSetPrototype(ArrayIterator, new GlobalObject());
+%FunctionSetPrototype(ArrayIterator, {__proto__: $iteratorPrototype});
%FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator');
$installFunctions(ArrayIterator.prototype, DONT_ENUM, [
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index
b1b18f8a0611a1cf7c5cafc318f6c6601b5d8da4..a61dd6beba48699c28159f9bdcc6b46154ab237b
100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -2129,10 +2129,17 @@ bool Genesis::InstallNatives() {
{
// Create generator meta-objects and install them on the builtins
object.
Handle<JSObject> builtins(native_context()->builtins());
+ Handle<JSObject> iterator_prototype =
+ factory()->NewJSObject(isolate()->object_function(), TENURED);
Handle<JSObject> generator_object_prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED);
Handle<JSObject> generator_function_prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED);
+ SetObjectPrototype(generator_object_prototype, iterator_prototype);
+ JSObject::AddProperty(
+ builtins, factory()->InternalizeUtf8String("$iteratorPrototype"),
+ iterator_prototype,
+ static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE |
READ_ONLY));
JSObject::AddProperty(
builtins,
factory()->InternalizeUtf8String("GeneratorFunctionPrototype"),
Index: src/collection-iterator.js
diff --git a/src/collection-iterator.js b/src/collection-iterator.js
index
7aa5208cea5bfc0a9b679cae37d0accdc335bc09..b48b85c1dca7eafa98d90269e6a31b46770b884f
100644
--- a/src/collection-iterator.js
+++ b/src/collection-iterator.js
@@ -14,7 +14,6 @@ var $setValues;
%CheckIsBootstrapping();
var GlobalMap = global.Map;
-var GlobalObject = global.Object;
var GlobalSet = global.Set;
// -------------------------------------------------------------------
@@ -49,11 +48,6 @@ function SetIteratorNextJS() {
}
-function SetIteratorSymbolIterator() {
- return this;
-}
-
-
function SetEntries() {
if (!IS_SET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
@@ -74,15 +68,12 @@ function SetValues() {
// -------------------------------------------------------------------
%SetCode(SetIterator, SetIteratorConstructor);
-%FunctionSetPrototype(SetIterator, new GlobalObject());
+%FunctionSetPrototype(SetIterator, {__proto__: $iteratorPrototype});
%FunctionSetInstanceClassName(SetIterator, 'Set Iterator');
$installFunctions(SetIterator.prototype, DONT_ENUM, [
'next', SetIteratorNextJS
]);
-$setFunctionName(SetIteratorSymbolIterator, symbolIterator);
-%AddNamedProperty(SetIterator.prototype, symbolIterator,
- SetIteratorSymbolIterator, DONT_ENUM);
%AddNamedProperty(SetIterator.prototype, symbolToStringTag,
"Set Iterator", READ_ONLY | DONT_ENUM);
@@ -104,11 +95,6 @@ function MapIteratorConstructor(map, kind) {
}
-function MapIteratorSymbolIterator() {
- return this;
-}
-
-
function MapIteratorNextJS() {
if (!IS_MAP_ITERATOR(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
@@ -164,15 +150,12 @@ function MapValues() {
// -------------------------------------------------------------------
%SetCode(MapIterator, MapIteratorConstructor);
-%FunctionSetPrototype(MapIterator, new GlobalObject());
+%FunctionSetPrototype(MapIterator, {__proto__: $iteratorPrototype});
%FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
$installFunctions(MapIterator.prototype, DONT_ENUM, [
'next', MapIteratorNextJS
]);
-$setFunctionName(MapIteratorSymbolIterator, symbolIterator);
-%AddNamedProperty(MapIterator.prototype, symbolIterator,
- MapIteratorSymbolIterator, DONT_ENUM);
%AddNamedProperty(MapIterator.prototype, symbolToStringTag,
"Map Iterator", READ_ONLY | DONT_ENUM);
Index: src/generator.js
diff --git a/src/generator.js b/src/generator.js
index
ae34ed3a4b4b266720c10372219af91894030596..ef276da50b93021ef7a4417fd447f612a4df6446
100644
--- a/src/generator.js
+++ b/src/generator.js
@@ -66,11 +66,6 @@ function GeneratorObjectThrow(exn) {
}
-function GeneratorObjectIterator() {
- return this;
-}
-
-
function GeneratorFunctionConstructor(arg1) { // length == 1
var source = $newFunctionString(arguments, 'function*');
var global_proxy = %GlobalProxy(GeneratorFunctionConstructor);
@@ -95,9 +90,6 @@ $installFunctions(GeneratorObjectPrototype,
["next", GeneratorObjectNext,
"throw", GeneratorObjectThrow]);
-$setFunctionName(GeneratorObjectIterator, symbolIterator);
-%AddNamedProperty(GeneratorObjectPrototype, symbolIterator,
- GeneratorObjectIterator, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddNamedProperty(GeneratorObjectPrototype, "constructor",
GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY);
%AddNamedProperty(GeneratorObjectPrototype,
Index: src/string-iterator.js
diff --git a/src/string-iterator.js b/src/string-iterator.js
index
c19e808020cee52355bfbfcf28bbd37fd72ee4ef..82493562558a191e0d1ad2cf5df2277f6ac67b10
100644
--- a/src/string-iterator.js
+++ b/src/string-iterator.js
@@ -8,7 +8,6 @@
%CheckIsBootstrapping();
-var GlobalObject = global.Object;
var GlobalString = global.String;
//-------------------------------------------------------------------
@@ -31,12 +30,6 @@ function CreateStringIterator(string) {
}
-// 21.1.5.2.2 %StringIteratorPrototype%[@@iterator]
-function StringIteratorIterator() {
- return this;
-}
-
-
// 21.1.5.2.1 %StringIteratorPrototype%.next( )
function StringIteratorNext() {
var iterator = $toObject(this);
@@ -85,15 +78,12 @@ function StringPrototypeIterator() {
//-------------------------------------------------------------------
-%FunctionSetPrototype(StringIterator, new GlobalObject());
+%FunctionSetPrototype(StringIterator, {__proto__: $iteratorPrototype});
%FunctionSetInstanceClassName(StringIterator, 'String Iterator');
$installFunctions(StringIterator.prototype, DONT_ENUM, [
'next', StringIteratorNext
]);
-$setFunctionName(StringIteratorIterator, symbolIterator);
-%AddNamedProperty(StringIterator.prototype, symbolIterator,
- StringIteratorIterator, DONT_ENUM);
%AddNamedProperty(StringIterator.prototype, symbolToStringTag,
"String Iterator", READ_ONLY | DONT_ENUM);
Index: test/mjsunit/es6/generators-runtime.js
diff --git a/test/mjsunit/es6/generators-runtime.js
b/test/mjsunit/es6/generators-runtime.js
index
115c7a4149908c9f0fd5725983dd2a23d4b6a286..72a47d0fb093c567641ad3b80d07796a5bdcaf94
100644
--- a/test/mjsunit/es6/generators-runtime.js
+++ b/test/mjsunit/es6/generators-runtime.js
@@ -35,6 +35,7 @@ function* g() { yield 1; }
var GeneratorFunctionPrototype = Object.getPrototypeOf(g);
var GeneratorFunction = GeneratorFunctionPrototype.constructor;
var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
+var IteratorPrototype = Object.getPrototypeOf(GeneratorObjectPrototype);
// A generator function should have the same set of properties as any
// other function.
@@ -100,7 +101,7 @@ TestGeneratorFunctionPrototype();
// Functions that we associate with generator objects are actually defined
by
// a common prototype.
function TestGeneratorObjectPrototype() {
- assertSame(Object.prototype,
+ assertSame(IteratorPrototype,
Object.getPrototypeOf(GeneratorObjectPrototype));
assertSame(GeneratorObjectPrototype,
Object.getPrototypeOf((function*(){yield 1}).prototype));
@@ -134,16 +135,6 @@ function TestGeneratorObjectPrototype() {
assertTrue(throw_desc.writable);
assertFalse(throw_desc.enumerable);
assertTrue(throw_desc.configurable);
-
- var 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/gyp/v8.gyp
diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp
index
2785d481d4ce263d6d51b13a523eca079a85cace..066605dfb807828489efe3cf0167cb22ca9ea0b7
100644
--- a/tools/gyp/v8.gyp
+++ b/tools/gyp/v8.gyp
@@ -1721,6 +1721,7 @@
'../../src/regexp.js',
'../../src/arraybuffer.js',
'../../src/typedarray.js',
+ '../../src/iterator-prototype.js',
'../../src/generator.js',
'../../src/object-observe.js',
'../../src/collection.js',
--
--
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.