Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1410)

Unified Diff: src/parser.cc

Issue 160073006: Implement handling of arrow functions in the parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Version with parsing code only, tests into test-parsing.cc Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/scanner.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index b8855fd8f0ac1c0d267a0c2c583ebd52bec9b892..46e7fc6728d6afa7b04b18ddc306b3690af2a443 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -678,8 +678,9 @@ const AstString* 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);
}
@@ -782,6 +783,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);
}
@@ -3296,6 +3298,66 @@ Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
}
+Vector<VariableProxy*> ParserTraits::ParameterListFromExpression(
+ Expression* expression, bool* ok) {
+
+ // 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();
+
+ const char* error_token = NULL;
+ Collector<VariableProxy*> collector;
+
+ while (expression->IsBinaryOperation()) {
+ BinaryOperation* binop = expression->AsBinaryOperation();
+
+ if (binop->op() != Token::COMMA) {
+ error_token = Token::String(expression->AsBinaryOperation()->op());
+ break;
+ }
+
+ expression = binop->right();
+ if (!expression->IsVariableProxy()) {
+ error_token = "";
marja 2014/06/17 11:47:37 In this case, don't we get an incorrect error end
+ break;
+ }
+ if (expression->AsVariableProxy()->is_this()) {
+ error_token = Token::String(Token::THIS);
+ break;
+ }
+
+ collector.Add(expression->AsVariableProxy());
+ expression = binop->left();
+ }
+
+ // No errors were found in the loop above, try to add the remaining item.
+ if (error_token == NULL) {
+ if (!expression->IsVariableProxy()) {
+ error_token = "";
+ } else if (expression->AsVariableProxy()->is_this()) {
+ error_token = Token::String(Token::THIS);
+ } else {
+ collector.Add(expression->AsVariableProxy());
+ return collector.ToVector();
+ }
+ }
+
+ // Report errors.
+ ASSERT_NE(error_token, NULL);
+ int error_pos = expression->position();
+ int error_token_len = strlen(error_token);
+ ParserTraits::ReportMessageAt(
+ Scanner::Location(error_pos,
+ error_pos + error_token_len ? error_token_len : 1),
+ "unexpected_token",
+ error_token);
+ *ok = false;
+ return Vector<VariableProxy*>::empty();
+}
+
+
FunctionLiteral* Parser::ParseFunctionLiteral(
const AstString* function_name,
Scanner::Location function_name_location,
@@ -3506,34 +3568,15 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
handler_count = function_state.handler_count();
}
- // Validate strict mode. We can do this only after parsing the function,
- // since the function can declare itself strict.
+ // Validate strict mode.
if (strict_mode() == STRICT) {
- if (IsEvalOrArguments(function_name)) {
- ReportMessageAt(function_name_location, "strict_eval_arguments");
- *ok = false;
- return NULL;
- }
- if (name_is_strict_reserved) {
- ReportMessageAt(function_name_location, "unexpected_strict_reserved");
- *ok = false;
- return NULL;
- }
- if (eval_args_error_log.IsValid()) {
- ReportMessageAt(eval_args_error_log, "strict_eval_arguments");
- *ok = false;
- return NULL;
- }
- if (dupe_error_loc.IsValid()) {
- ReportMessageAt(dupe_error_loc, "strict_param_dupe");
- *ok = false;
- return NULL;
- }
- if (reserved_loc.IsValid()) {
- ReportMessageAt(reserved_loc, "unexpected_strict_reserved");
- *ok = false;
- return NULL;
- }
+ CheckStrictFunctionNameAndParameters(function_name,
+ name_is_strict_reserved,
+ function_name_location,
+ eval_args_error_log,
+ dupe_error_loc,
+ reserved_loc,
+ CHECK_OK);
CheckOctalLiteral(scope->start_position(),
scope->end_position(),
CHECK_OK);
@@ -3724,6 +3767,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());
}
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/scanner.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698