Bug 1141862 - Part 4: Make everything defined with MethodDefinition syntax use the Method FunctionSyntaxKind while parsing. (r=jorendorff)

This commit is contained in:
Eric Faust 2015-04-02 19:20:17 -07:00
parent 989c2f8d06
commit c091ff7694
3 changed files with 12 additions and 12 deletions

View File

@ -8304,7 +8304,7 @@ Parser<ParseHandler>::propertyList(PropListType type)
return null();
} else if (tt == TOK_LP) {
tokenStream.ungetToken();
if (!methodDefinition(type, propList, propname, Normal, Method,
if (!methodDefinition(type, propList, propname, Normal,
isGenerator ? StarGenerator : NotGenerator, isStatic, op)) {
return null();
}
@ -8313,9 +8313,8 @@ Parser<ParseHandler>::propertyList(PropListType type)
return null();
}
} else {
/* NB: Getter function in { get x(){} } is unnamed. */
if (!methodDefinition(type, propList, propname, op == JSOP_INITPROP_GETTER ? Getter : Setter,
Expression, NotGenerator, isStatic, op)) {
NotGenerator, isStatic, op)) {
return null();
}
}
@ -8346,17 +8345,17 @@ Parser<ParseHandler>::propertyList(PropListType type)
template <typename ParseHandler>
bool
Parser<ParseHandler>::methodDefinition(PropListType listType, Node propList, Node propname,
FunctionType type, FunctionSyntaxKind kind,
GeneratorKind generatorKind,
FunctionType type, GeneratorKind generatorKind,
bool isStatic, JSOp op)
{
/* NB: Getter function in { get x(){} } is unnamed. */
RootedPropertyName funName(context);
if (kind == Method && tokenStream.isCurrentTokenType(TOK_NAME))
if (type == Normal && tokenStream.isCurrentTokenType(TOK_NAME))
funName = tokenStream.currentName();
else
funName = nullptr;
Node fn = functionDef(funName, type, kind, generatorKind);
Node fn = functionDef(funName, type, Method, generatorKind);
if (!fn)
return false;

View File

@ -576,8 +576,7 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter
Node exprInParens();
bool methodDefinition(PropListType listType, Node propList, Node propname, FunctionType type,
FunctionSyntaxKind kind, GeneratorKind generatorKind,
bool isStatic, JSOp Op);
GeneratorKind generatorKind, bool isStatic, JSOp Op);
/*
* Additional JS parsers.

View File

@ -1006,9 +1006,11 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool bodyOnly, bool lamb
return out.finishString();
}
}
bool funIsMethodOrNonArrowLambda = (fun->isLambda() && !fun->isArrow()) || fun->isMethod();
if (!bodyOnly) {
// If we're not in pretty mode, put parentheses around lambda functions.
if (fun->isInterpreted() && !lambdaParen && fun->isLambda() && !fun->isArrow()) {
// If we're not in pretty mode, put parentheses around lambda functions and methods.
if (fun->isInterpreted() && !lambdaParen && funIsMethodOrNonArrowLambda) {
if (!out.append("("))
return nullptr;
}
@ -1129,7 +1131,7 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool bodyOnly, bool lamb
// Slap a semicolon on the end of functions with an expression body.
if (exprBody && !out.append(";"))
return nullptr;
} else if (!lambdaParen && fun->isLambda() && !fun->isArrow()) {
} else if (!lambdaParen && funIsMethodOrNonArrowLambda) {
if (!out.append(")"))
return nullptr;
}