Bug 1225396 part 3 - Make %GeneratorPrototype% inherit from %IteratorPrototype%. r=jorendorff

This commit is contained in:
Jan de Mooij 2015-12-09 22:55:50 -05:00
parent 1c94156bf7
commit 718316dc71
2 changed files with 13 additions and 5 deletions

View File

@ -59,10 +59,12 @@ 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 =
@ -72,6 +74,9 @@ function TestGeneratorObjectPrototype() {
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();

View File

@ -235,7 +235,6 @@ const Class StarGeneratorObject::class_ = {
};
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),
@ -296,8 +295,12 @@ 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;