Bug 1141862 - Part 2: Allow Lazy script to pass the Method FunctionSyntaxKind during delazification. (r=jorendorff)

This commit is contained in:
Eric Faust 2015-04-02 19:20:02 -07:00
parent b6634d58ab
commit 711bc1ca0f
3 changed files with 25 additions and 12 deletions

View File

@ -1660,7 +1660,7 @@ enum ParseReportKind
ParseStrictError
};
enum FunctionSyntaxKind { Expression, Statement, Arrow, Method, Lazy };
enum FunctionSyntaxKind { Expression, Statement, Arrow, Method };
static inline ParseNode*
FunctionArgsList(ParseNode* fn, unsigned* numFormals)

View File

@ -1211,11 +1211,23 @@ Parser<ParseHandler>::newFunction(HandleAtom atom, FunctionSyntaxKind kind, Hand
MOZ_ASSERT_IF(kind == Statement, atom != nullptr);
RootedFunction fun(context);
JSFunction::Flags flags = (kind == Expression)
? JSFunction::INTERPRETED_LAMBDA
: (kind == Arrow)
? JSFunction::INTERPRETED_LAMBDA_ARROW
: JSFunction::INTERPRETED;
JSFunction::Flags flags;
switch(kind) {
case Expression:
flags = JSFunction::INTERPRETED_LAMBDA;
break;
case Arrow:
flags = JSFunction::INTERPRETED_LAMBDA_ARROW;
break;
case Method:
flags = JSFunction::INTERPRETED_METHOD;
break;
default:
flags = JSFunction::INTERPRETED;
break;
}
gc::AllocKind allocKind = JSFunction::FinalizeKind;
if (kind == Arrow)
allocKind = JSFunction::ExtendedFinalizeKind;
@ -2453,7 +2465,8 @@ Parser<FullParseHandler>::standaloneLazyFunction(HandleFunction fun, unsigned st
if (!funpc.init(tokenStream))
return null();
if (!functionArgsAndBodyGeneric(pn, fun, Normal, Lazy)) {
FunctionSyntaxKind syntaxKind = fun->isMethod() ? Method : Statement;
if (!functionArgsAndBodyGeneric(pn, fun, Normal, syntaxKind)) {
MOZ_ASSERT(directives == newDirectives);
return null();
}
@ -2538,11 +2551,8 @@ Parser<ParseHandler>::functionArgsAndBodyGeneric(Node pn, HandleFunction fun, Fu
if (!body)
return false;
if (kind != Method && kind != Lazy &&
fun->name() && !checkStrictBinding(fun->name(), pn))
{
if (kind != Method && fun->name() && !checkStrictBinding(fun->name(), pn))
return false;
}
if (bodyType == StatementListBody) {
bool matched;
@ -2560,7 +2570,7 @@ Parser<ParseHandler>::functionArgsAndBodyGeneric(Node pn, HandleFunction fun, Fu
if (tokenStream.hadError())
return false;
funbox->bufEnd = pos().end;
if ((kind == Statement || kind == Lazy) && !MatchOrInsertSemicolon(tokenStream))
if (kind == Statement && !MatchOrInsertSemicolon(tokenStream))
return false;
}

View File

@ -31,6 +31,7 @@ class JSFunction : public js::NativeObject
enum FunctionKind {
NormalFunction = 0,
Arrow, /* ES6 '(args) => body' syntax */
Method, /* ES6 MethodDefinition */
AsmJS /* function is an asm.js module or exported function */
};
@ -65,6 +66,7 @@ class JSFunction : public js::NativeObject
NATIVE_FUN = 0,
ASMJS_CTOR = ASMJS_KIND | NATIVE_CTOR,
ASMJS_LAMBDA_CTOR = ASMJS_KIND | NATIVE_CTOR | LAMBDA,
INTERPRETED_METHOD = INTERPRETED | (Method << FUNCTION_KIND_SHIFT),
INTERPRETED_LAMBDA = INTERPRETED | LAMBDA,
INTERPRETED_LAMBDA_ARROW = INTERPRETED | LAMBDA | ARROW_KIND,
STABLE_ACROSS_CLONES = NATIVE_CTOR | IS_FUN_PROTO | EXPR_BODY | HAS_GUESSED_ATOM |
@ -149,6 +151,7 @@ class JSFunction : public js::NativeObject
// Arrow functions store their lexical |this| in the first extended slot.
bool isArrow() const { return kind() == Arrow; }
bool isMethod() const { return kind() == Method; }
bool hasResolvedLength() const { return flags() & RESOLVED_LENGTH; }
bool hasResolvedName() const { return flags() & RESOLVED_NAME; }