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

Side by Side 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: Moar clean ups, return dummy FunctionLiteral for arrow functions Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 pending_error_arg_(NULL), 775 pending_error_arg_(NULL),
776 pending_error_char_arg_(NULL) { 776 pending_error_char_arg_(NULL) {
777 ASSERT(!script_.is_null()); 777 ASSERT(!script_.is_null());
778 isolate_->set_ast_node_id(0); 778 isolate_->set_ast_node_id(0);
779 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 779 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
780 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 780 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
781 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 781 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
782 set_allow_lazy(false); // Must be explicitly enabled. 782 set_allow_lazy(false); // Must be explicitly enabled.
783 set_allow_generators(FLAG_harmony_generators); 783 set_allow_generators(FLAG_harmony_generators);
784 set_allow_for_of(FLAG_harmony_iteration); 784 set_allow_for_of(FLAG_harmony_iteration);
785 set_allow_arrow_functions(FLAG_harmony_arrow_functions);
785 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 786 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
786 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 787 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
787 ++feature) { 788 ++feature) {
788 use_counts_[feature] = 0; 789 use_counts_[feature] = 0;
789 } 790 }
790 } 791 }
791 792
792 793
793 FunctionLiteral* Parser::ParseProgram() { 794 FunctionLiteral* Parser::ParseProgram() {
794 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, 795 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
(...skipping 2519 matching lines...) Expand 10 before | Expand all | Expand 10 after
3314 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); 3315 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot));
3315 return static_cast<LiteralType>(literal_type->value()); 3316 return static_cast<LiteralType>(literal_type->value());
3316 } 3317 }
3317 3318
3318 3319
3319 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 3320 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3320 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 3321 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3321 } 3322 }
3322 3323
3323 3324
3325 bool CheckAndCollectArrowParameter(ParserTraits* traits,
3326 Collector<VariableProxy*>* collector, Expression* expression) {
3327 // Case for empty parameter lists:
3328 // () => ...
3329 if (expression == NULL)
3330 return true;
3331
3332 // Too many parentheses around expression:
3333 // (( ... )) => ...
3334 if (expression->parenthesization_level() > 1)
3335 return false;
3336
3337 // Case for a single parameter:
3338 // (foo) => ...
3339 // foo => ...
3340 if (expression->IsVariableProxy()) {
3341 if (expression->AsVariableProxy()->is_this())
3342 return false;
3343
3344 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name();
3345 if (traits->IsEvalOrArguments(raw_name) ||
3346 traits->IsFutureStrictReserved(raw_name))
3347 return false;
3348
3349 collector->Add(expression->AsVariableProxy());
3350 return true;
3351 }
3352
3353 // Case for more than one parameter:
3354 // (foo, bar [, ...]) => ...
3355 if (expression->IsBinaryOperation()) {
3356 BinaryOperation* binop = expression->AsBinaryOperation();
3357 if (binop->op() != Token::COMMA ||
3358 binop->right()->is_parenthesized() ||
3359 binop->left()->is_parenthesized())
3360 return false;
3361
3362 return CheckAndCollectArrowParameter(traits, collector, binop->right()) &&
3363 CheckAndCollectArrowParameter(traits, collector, binop->left());
3364 }
3365
3366 // Any other kind of expression is not a valid parameter list.
3367 return false;
3368 }
3369
3370
3371 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression(
3372 Expression* expression, bool* ok) {
3373 Collector<VariableProxy*> collector;
3374 *ok = CheckAndCollectArrowParameter(this, &collector, expression);
3375 return collector.ToVector();
3376 }
3377
3378
3324 FunctionLiteral* Parser::ParseFunctionLiteral( 3379 FunctionLiteral* Parser::ParseFunctionLiteral(
3325 const AstRawString* function_name, 3380 const AstRawString* function_name,
3326 Scanner::Location function_name_location, 3381 Scanner::Location function_name_location,
3327 bool name_is_strict_reserved, 3382 bool name_is_strict_reserved,
3328 bool is_generator, 3383 bool is_generator,
3329 int function_token_pos, 3384 int function_token_pos,
3330 FunctionLiteral::FunctionType function_type, 3385 FunctionLiteral::FunctionType function_type,
3331 FunctionLiteral::ArityRestriction arity_restriction, 3386 FunctionLiteral::ArityRestriction arity_restriction,
3332 bool* ok) { 3387 bool* ok) {
3333 // Function :: 3388 // Function ::
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
3733 3788
3734 if (reusable_preparser_ == NULL) { 3789 if (reusable_preparser_ == NULL) {
3735 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); 3790 intptr_t stack_limit = isolate()->stack_guard()->real_climit();
3736 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); 3791 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit);
3737 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); 3792 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping());
3738 reusable_preparser_->set_allow_modules(allow_modules()); 3793 reusable_preparser_->set_allow_modules(allow_modules());
3739 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); 3794 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax());
3740 reusable_preparser_->set_allow_lazy(true); 3795 reusable_preparser_->set_allow_lazy(true);
3741 reusable_preparser_->set_allow_generators(allow_generators()); 3796 reusable_preparser_->set_allow_generators(allow_generators());
3742 reusable_preparser_->set_allow_for_of(allow_for_of()); 3797 reusable_preparser_->set_allow_for_of(allow_for_of());
3798 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions());
3743 reusable_preparser_->set_allow_harmony_numeric_literals( 3799 reusable_preparser_->set_allow_harmony_numeric_literals(
3744 allow_harmony_numeric_literals()); 3800 allow_harmony_numeric_literals());
3745 } 3801 }
3746 PreParser::PreParseResult result = 3802 PreParser::PreParseResult result =
3747 reusable_preparser_->PreParseLazyFunction(strict_mode(), 3803 reusable_preparser_->PreParseLazyFunction(strict_mode(),
3748 is_generator(), 3804 is_generator(),
3749 logger); 3805 logger);
3750 return result; 3806 return result;
3751 } 3807 }
3752 3808
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
4879 info()->SetAstValueFactory(ast_value_factory_); 4935 info()->SetAstValueFactory(ast_value_factory_);
4880 } 4936 }
4881 ast_value_factory_ = NULL; 4937 ast_value_factory_ = NULL;
4882 4938
4883 InternalizeUseCounts(); 4939 InternalizeUseCounts();
4884 4940
4885 return (result != NULL); 4941 return (result != NULL);
4886 } 4942 }
4887 4943
4888 } } // namespace v8::internal 4944 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698