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

Side by Side Diff: src/parser.cc

Issue 385553003: Implement handling of arrow functions in the parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Base patch set, makes ASAN choke 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') | no next file with comments »
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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 pending_error_arg_(NULL), 711 pending_error_arg_(NULL),
712 pending_error_char_arg_(NULL) { 712 pending_error_char_arg_(NULL) {
713 ASSERT(!script_.is_null()); 713 ASSERT(!script_.is_null());
714 isolate_->set_ast_node_id(0); 714 isolate_->set_ast_node_id(0);
715 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 715 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
716 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 716 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
717 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 717 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
718 set_allow_lazy(false); // Must be explicitly enabled. 718 set_allow_lazy(false); // Must be explicitly enabled.
719 set_allow_generators(FLAG_harmony_generators); 719 set_allow_generators(FLAG_harmony_generators);
720 set_allow_for_of(FLAG_harmony_iteration); 720 set_allow_for_of(FLAG_harmony_iteration);
721 set_allow_arrow_functions(FLAG_harmony_arrow_functions);
721 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 722 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
722 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 723 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
723 ++feature) { 724 ++feature) {
724 use_counts_[feature] = 0; 725 use_counts_[feature] = 0;
725 } 726 }
726 } 727 }
727 728
728 729
729 FunctionLiteral* Parser::ParseProgram() { 730 FunctionLiteral* Parser::ParseProgram() {
730 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, 731 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
(...skipping 2533 matching lines...) Expand 10 before | Expand all | Expand 10 after
3264 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); 3265 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot));
3265 return static_cast<LiteralType>(literal_type->value()); 3266 return static_cast<LiteralType>(literal_type->value());
3266 } 3267 }
3267 3268
3268 3269
3269 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 3270 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3270 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 3271 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3271 } 3272 }
3272 3273
3273 3274
3275 bool CheckAndCollectArrowParameter(ParserTraits* traits,
3276 Collector<VariableProxy*>* collector,
3277 Expression* expression) {
3278 // Case for empty parameter lists:
3279 // () => ...
3280 if (expression == NULL) return true;
3281
3282 // Too many parentheses around expression:
3283 // (( ... )) => ...
3284 if (expression->parenthesization_level() > 1) return false;
3285
3286 // Case for a single parameter:
3287 // (foo) => ...
3288 // foo => ...
3289 if (expression->IsVariableProxy()) {
3290 if (expression->AsVariableProxy()->is_this()) return false;
3291
3292 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name();
3293 if (traits->IsEvalOrArguments(raw_name) ||
3294 traits->IsFutureStrictReserved(raw_name))
3295 return false;
3296
3297 collector->Add(expression->AsVariableProxy());
3298 return true;
3299 }
3300
3301 // Case for more than one parameter:
3302 // (foo, bar [, ...]) => ...
3303 if (expression->IsBinaryOperation()) {
3304 BinaryOperation* binop = expression->AsBinaryOperation();
3305 if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() ||
3306 binop->right()->is_parenthesized())
3307 return false;
3308
3309 return CheckAndCollectArrowParameter(traits, collector, binop->left()) &&
3310 CheckAndCollectArrowParameter(traits, collector, binop->right());
3311 }
3312
3313 // Any other kind of expression is not a valid parameter list.
3314 return false;
3315 }
3316
3317
3318 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression(
3319 Expression* expression, bool* ok) {
3320 Collector<VariableProxy*> collector;
3321 *ok = CheckAndCollectArrowParameter(this, &collector, expression);
3322 return collector.ToVector();
3323 }
3324
3325
3274 FunctionLiteral* Parser::ParseFunctionLiteral( 3326 FunctionLiteral* Parser::ParseFunctionLiteral(
3275 const AstRawString* function_name, 3327 const AstRawString* function_name,
3276 Scanner::Location function_name_location, 3328 Scanner::Location function_name_location,
3277 bool name_is_strict_reserved, 3329 bool name_is_strict_reserved,
3278 bool is_generator, 3330 bool is_generator,
3279 int function_token_pos, 3331 int function_token_pos,
3280 FunctionLiteral::FunctionType function_type, 3332 FunctionLiteral::FunctionType function_type,
3281 FunctionLiteral::ArityRestriction arity_restriction, 3333 FunctionLiteral::ArityRestriction arity_restriction,
3282 bool* ok) { 3334 bool* ok) {
3283 // Function :: 3335 // Function ::
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
3673 3725
3674 if (reusable_preparser_ == NULL) { 3726 if (reusable_preparser_ == NULL) {
3675 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); 3727 intptr_t stack_limit = isolate()->stack_guard()->real_climit();
3676 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); 3728 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit);
3677 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); 3729 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping());
3678 reusable_preparser_->set_allow_modules(allow_modules()); 3730 reusable_preparser_->set_allow_modules(allow_modules());
3679 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); 3731 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax());
3680 reusable_preparser_->set_allow_lazy(true); 3732 reusable_preparser_->set_allow_lazy(true);
3681 reusable_preparser_->set_allow_generators(allow_generators()); 3733 reusable_preparser_->set_allow_generators(allow_generators());
3682 reusable_preparser_->set_allow_for_of(allow_for_of()); 3734 reusable_preparser_->set_allow_for_of(allow_for_of());
3735 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions());
3683 reusable_preparser_->set_allow_harmony_numeric_literals( 3736 reusable_preparser_->set_allow_harmony_numeric_literals(
3684 allow_harmony_numeric_literals()); 3737 allow_harmony_numeric_literals());
3685 } 3738 }
3686 PreParser::PreParseResult result = 3739 PreParser::PreParseResult result =
3687 reusable_preparser_->PreParseLazyFunction(strict_mode(), 3740 reusable_preparser_->PreParseLazyFunction(strict_mode(),
3688 is_generator(), 3741 is_generator(),
3689 logger); 3742 logger);
3690 return result; 3743 return result;
3691 } 3744 }
3692 3745
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
4742 info()->SetAstValueFactory(ast_value_factory_); 4795 info()->SetAstValueFactory(ast_value_factory_);
4743 } 4796 }
4744 ast_value_factory_ = NULL; 4797 ast_value_factory_ = NULL;
4745 4798
4746 InternalizeUseCounts(); 4799 InternalizeUseCounts();
4747 4800
4748 return (result != NULL); 4801 return (result != NULL);
4749 } 4802 }
4750 4803
4751 } } // namespace v8::internal 4804 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698