diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 8d520af769ae..1c80fe4aaf79 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -1210,7 +1210,8 @@ struct BindData template JSFunction* -Parser::newFunction(HandleAtom atom, FunctionSyntaxKind kind, HandleObject proto) +Parser::newFunction(HandleAtom atom, FunctionSyntaxKind kind, + GeneratorKind generatorKind, HandleObject proto) { MOZ_ASSERT_IF(kind == Statement, atom != nullptr); @@ -1227,7 +1228,11 @@ Parser::newFunction(HandleAtom atom, FunctionSyntaxKind kind, Hand allocKind = gc::AllocKind::FUNCTION_EXTENDED; break; case Method: - flags = JSFunction::INTERPRETED_METHOD; + MOZ_ASSERT(generatorKind == NotGenerator || generatorKind == StarGenerator); + if (generatorKind == NotGenerator) + flags = JSFunction::INTERPRETED_METHOD; + else + flags = JSFunction::INTERPRETED_METHOD_GENERATOR; allocKind = gc::AllocKind::FUNCTION_EXTENDED; break; case ClassConstructor: @@ -2193,7 +2198,7 @@ Parser::functionDef(InHandling inHandling, YieldHandling yieldHand if (!proto) return null(); } - RootedFunction fun(context, newFunction(funName, kind, proto)); + RootedFunction fun(context, newFunction(funName, kind, generatorKind, proto)); if (!fun) return null(); @@ -7340,7 +7345,7 @@ Parser::generatorComprehensionLambda(GeneratorKind comprehensionKi return null(); } - RootedFunction fun(context, newFunction(/* atom = */ nullptr, Expression, proto)); + RootedFunction fun(context, newFunction(/* atom = */ nullptr, Expression, comprehensionKind, proto)); if (!fun) return null(); diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index 85eff2966246..f864be99c85b 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -445,7 +445,8 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter * Create a new function object given a name (which is optional if this is * a function expression). */ - JSFunction* newFunction(HandleAtom atom, FunctionSyntaxKind kind, HandleObject proto); + JSFunction* newFunction(HandleAtom atom, FunctionSyntaxKind kind, GeneratorKind generatorKind, + HandleObject proto); void trace(JSTracer* trc); diff --git a/js/src/jsfun.h b/js/src/jsfun.h index 0b228cb96d3f..c583267fcd9d 100644 --- a/js/src/jsfun.h +++ b/js/src/jsfun.h @@ -74,6 +74,7 @@ class JSFunction : public js::NativeObject ASMJS_CTOR = ASMJS_KIND | NATIVE_CTOR, ASMJS_LAMBDA_CTOR = ASMJS_KIND | NATIVE_CTOR | LAMBDA, INTERPRETED_METHOD = INTERPRETED | METHOD_KIND, + INTERPRETED_METHOD_GENERATOR = INTERPRETED | METHOD_KIND | CONSTRUCTOR, INTERPRETED_CLASS_CONSTRUCTOR = INTERPRETED | CLASSCONSTRUCTOR_KIND | CONSTRUCTOR, INTERPRETED_GETTER = INTERPRETED | GETTER_KIND, INTERPRETED_SETTER = INTERPRETED | SETTER_KIND, diff --git a/js/src/tests/ecma_6/Class/methDefnGen.js b/js/src/tests/ecma_6/Class/methDefnGen.js index 30f96db03f61..596d55477f5b 100644 --- a/js/src/tests/ecma_6/Class/methDefnGen.js +++ b/js/src/tests/ecma_6/Class/methDefnGen.js @@ -72,4 +72,13 @@ assertEq(a.b(1).next().value, 1); a = {*["b"](c){"use strict";return c;}}; assertEq(a.b(1).next().value, 1); +// Constructing +a = {*g() { yield 1; }} +it = new a.g; +next = it.next(); +assertEq(next.done, false); +assertEq(next.value, 1); +next = it.next(); +assertEq(next.done, true); + reportCompare(0, 0, "ok");