Bug 1225396 part 3 - Make %GeneratorPrototype% inherit from %IteratorPrototype%. r=jorendorff
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 09 Dec 2015 22:55:50 -0500
changeset 276057 de72e2291ae84ca9798ce7e27976f4b839780a9a
parent 276056 0eb91b63bf26dd32861376a017f77bad372854d3
child 276058 151ce2b0e3f6b73505be35561f148678577dcbcb
push id29781
push usercbook@mozilla.com
push dateThu, 10 Dec 2015 11:07:51 +0000
treeherdermozilla-central@412e4d7ce98c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1225396
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1225396 part 3 - Make %GeneratorPrototype% inherit from %IteratorPrototype%. r=jorendorff
js/src/tests/ecma_6/Generators/runtime.js
js/src/vm/GeneratorObject.cpp
--- a/js/src/tests/ecma_6/Generators/runtime.js
+++ b/js/src/tests/ecma_6/Generators/runtime.js
@@ -54,29 +54,34 @@ function TestGeneratorFunctionPrototype(
                GeneratorFunctionPrototype);
 }
 TestGeneratorFunctionPrototype();
 
 
 // Functions that we associate with generator objects are actually defined by
 // a common prototype.
 function TestGeneratorObjectPrototype() {
+    // %GeneratorPrototype% must inherit from %IteratorPrototype%.
+    var iterProto = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
     assertEq(Object.getPrototypeOf(GeneratorObjectPrototype),
-               Object.prototype);
+             iterProto);
     assertEq(Object.getPrototypeOf((function*(){yield 1}).prototype),
-               GeneratorObjectPrototype);
+             GeneratorObjectPrototype);
 
     var expected_property_names = ["next", "return", "throw", "constructor"];
     var found_property_names =
         Object.getOwnPropertyNames(GeneratorObjectPrototype);
 
     expected_property_names.sort();
     found_property_names.sort();
 
     assertDeepEq(found_property_names, expected_property_names);
+
+    // No symbol properties, at least until we have @@toStringTag.
+    assertEq(Object.getOwnPropertySymbols(GeneratorObjectPrototype).length, 0);
 }
 TestGeneratorObjectPrototype();
 
 
 // This tests the object that would be called "GeneratorFunction", if it were
 // like "Function".
 function TestGeneratorFunction() {
     assertEq(GeneratorFunctionPrototype, GeneratorFunction.prototype);
--- a/js/src/vm/GeneratorObject.cpp
+++ b/js/src/vm/GeneratorObject.cpp
@@ -230,17 +230,16 @@ const Class LegacyGeneratorObject::class
 };
 
 const Class StarGeneratorObject::class_ = {
     "Generator",
     JSCLASS_HAS_RESERVED_SLOTS(GeneratorObject::RESERVED_SLOTS)
 };
 
 static const JSFunctionSpec star_generator_methods[] = {
-    JS_SELF_HOSTED_SYM_FN(iterator, "IteratorIdentity", 0, 0),
     JS_SELF_HOSTED_FN("next", "StarGeneratorNext", 1, 0),
     JS_SELF_HOSTED_FN("throw", "StarGeneratorThrow", 1, 0),
     JS_SELF_HOSTED_FN("return", "StarGeneratorReturn", 1, 0),
     JS_FS_END
 };
 
 #define JSPROP_ROPERM   (JSPROP_READONLY | JSPROP_PERMANENT)
 
@@ -291,18 +290,22 @@ GlobalObject::initLegacyGeneratorProto(J
 }
 
 /* static */ bool
 GlobalObject::initStarGenerators(JSContext* cx, Handle<GlobalObject*> global)
 {
     if (global->getReservedSlot(STAR_GENERATOR_OBJECT_PROTO).isObject())
         return true;
 
-    RootedObject genObjectProto(cx, NewSingletonObjectWithObjectPrototype(cx, global));
-    if (!genObjectProto || !genObjectProto->setDelegate(cx))
+    RootedObject iteratorProto(cx, GlobalObject::getOrCreateIteratorPrototype(cx, global));
+    if (!iteratorProto)
+        return false;
+
+    RootedPlainObject genObjectProto(cx, NewObjectWithGivenProto<PlainObject>(cx, iteratorProto));
+    if (!genObjectProto)
         return false;
     if (!DefinePropertiesAndFunctions(cx, genObjectProto, nullptr, star_generator_methods))
         return false;
 
     RootedObject genFunctionProto(cx, NewSingletonObjectWithFunctionPrototype(cx, global));
     if (!genFunctionProto || !genFunctionProto->setDelegate(cx))
         return false;
     if (!LinkConstructorAndPrototype(cx, genFunctionProto, genObjectProto))