mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 1141862 - Part 4: Make everything defined with MethodDefinition syntax use the Method FunctionSyntaxKind while parsing. (r=jorendorff)
This commit is contained in:
parent
989c2f8d06
commit
c091ff7694
@ -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;
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user