Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index 80cbb2daa3d8705298296300b0f16e91f181a6d6..f8622f6a9145eccc7244999f84c9c77222c25d41 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -678,8 +678,9 @@ const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
Expression* ParserTraits::ThisExpression( |
Scope* scope, |
- AstNodeFactory<AstConstructionVisitor>* factory) { |
- return factory->NewVariableProxy(scope->receiver()); |
+ AstNodeFactory<AstConstructionVisitor>* factory, |
+ int pos) { |
+ return factory->NewVariableProxy(scope->receiver(), pos); |
} |
@@ -784,6 +785,7 @@ Parser::Parser(CompilationInfo* info) |
set_allow_lazy(false); // Must be explicitly enabled. |
set_allow_generators(FLAG_harmony_generators); |
set_allow_for_of(FLAG_harmony_iteration); |
+ set_allow_arrow_functions(FLAG_harmony_arrow_functions); |
set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
} |
@@ -3305,6 +3307,79 @@ Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
} |
+Vector<VariableProxy*> ParserTraits::ParameterListFromExpression( |
marja
2014/06/26 14:38:13
Here you have the same logic in 2 functions; would
|
+ Expression* expression) { |
+ // Parsing the parameter list of an arrow function does not have parameters |
+ // (as in: () => ...) returns NULL, so expression being NULL is not an error, |
+ // but an valid empty parameter list. |
+ if (expression == NULL) |
+ return Vector<VariableProxy*>::empty(); |
+ |
+ Collector<VariableProxy*> collector; |
+ |
+ // IsValidArrowFunctionParamterList() can be used to check for validity, |
+ // here we just ASSERT() that the passed expression is a valid param list. |
+ while (expression->IsBinaryOperation()) { |
+ BinaryOperation* binop = expression->AsBinaryOperation(); |
+ ASSERT_EQ(binop->op(), Token::COMMA); |
+ |
+ expression = binop->right(); |
+ ASSERT(expression->IsVariableProxy()); |
+ ASSERT(!expression->AsVariableProxy()->is_this()); |
+ ASSERT(!IsEvalOrArguments(expression->AsVariableProxy()->raw_name())); |
+ ASSERT(!IsFutureStrictReserved(expression->AsVariableProxy()->raw_name())); |
+ |
+ collector.Add(expression->AsVariableProxy()); |
+ expression = binop->left(); |
+ } |
+ |
+ // Add the remaining item. |
+ ASSERT(expression->IsVariableProxy()); |
+ ASSERT(!expression->AsVariableProxy()->is_this()); |
+ ASSERT(!IsEvalOrArguments(expression->AsVariableProxy()->raw_name())); |
+ ASSERT(!IsFutureStrictReserved(expression->AsVariableProxy()->raw_name())); |
+ |
+ collector.Add(expression->AsVariableProxy()); |
+ return collector.ToVector(); |
+} |
+ |
+ |
+bool ParserTraits::IsValidArrowFunctionParameterList(Expression* expression) { |
+ // Case for empty parameter lists: |
+ // () => ... |
+ if (expression == NULL) |
+ return true; |
+ |
+ // Too many parentheses around expression: |
+ // (( ... )) => ... |
+ if (expression->parenthesization_level() > 1) |
+ return false; |
+ |
+ // Case for a single parameter: |
+ // (foo) => ... |
+ // foo => ... |
+ if (expression->IsVariableProxy()) { |
+ if (expression->AsVariableProxy()->is_this()) return false; |
+ const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); |
+ return !(IsEvalOrArguments(raw_name) || IsFutureStrictReserved(raw_name)); |
+ } |
+ |
+ // Case for more than one parameter: |
+ // (foo, bar [, ...]) => ... |
+ if (expression->IsBinaryOperation()) { |
+ BinaryOperation* binop = expression->AsBinaryOperation(); |
+ return binop->op() == Token::COMMA && |
+ !binop->right()->is_parenthesized() && |
+ !binop->left()->is_parenthesized() && |
+ IsValidArrowFunctionParameterList(binop->right()) && |
+ IsValidArrowFunctionParameterList(binop->left()); |
+ } |
+ |
+ // Any other kind of expression is not a valid parameter list. |
+ return false; |
+} |
+ |
+ |
FunctionLiteral* Parser::ParseFunctionLiteral( |
const AstRawString* function_name, |
Scanner::Location function_name_location, |
@@ -3724,6 +3799,7 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( |
reusable_preparser_->set_allow_lazy(true); |
reusable_preparser_->set_allow_generators(allow_generators()); |
reusable_preparser_->set_allow_for_of(allow_for_of()); |
+ reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); |
reusable_preparser_->set_allow_harmony_numeric_literals( |
allow_harmony_numeric_literals()); |
} |