mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1166950 - Make generator methods constructors. r=efaust
This commit is contained in:
parent
d42ec1b025
commit
fe0dbd43f9
@ -1210,7 +1210,8 @@ struct BindData
|
||||
|
||||
template <typename ParseHandler>
|
||||
JSFunction*
|
||||
Parser<ParseHandler>::newFunction(HandleAtom atom, FunctionSyntaxKind kind, HandleObject proto)
|
||||
Parser<ParseHandler>::newFunction(HandleAtom atom, FunctionSyntaxKind kind,
|
||||
GeneratorKind generatorKind, HandleObject proto)
|
||||
{
|
||||
MOZ_ASSERT_IF(kind == Statement, atom != nullptr);
|
||||
|
||||
@ -1227,7 +1228,11 @@ Parser<ParseHandler>::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<ParseHandler>::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<ParseHandler>::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();
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user