| OLD | NEW |
| 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 Loading... |
| 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); | |
| 786 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 785 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 787 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 786 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 788 ++feature) { | 787 ++feature) { |
| 789 use_counts_[feature] = 0; | 788 use_counts_[feature] = 0; |
| 790 } | 789 } |
| 791 } | 790 } |
| 792 | 791 |
| 793 | 792 |
| 794 FunctionLiteral* Parser::ParseProgram() { | 793 FunctionLiteral* Parser::ParseProgram() { |
| 795 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 794 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
| (...skipping 2519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3315 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3314 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
| 3316 return static_cast<LiteralType>(literal_type->value()); | 3315 return static_cast<LiteralType>(literal_type->value()); |
| 3317 } | 3316 } |
| 3318 | 3317 |
| 3319 | 3318 |
| 3320 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3319 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
| 3321 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3320 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
| 3322 } | 3321 } |
| 3323 | 3322 |
| 3324 | 3323 |
| 3325 bool CheckAndCollectArrowParameter(ParserTraits* traits, | |
| 3326 Collector<VariableProxy*>* collector, | |
| 3327 Expression* expression) { | |
| 3328 // Case for empty parameter lists: | |
| 3329 // () => ... | |
| 3330 if (expression == NULL) return true; | |
| 3331 | |
| 3332 // Too many parentheses around expression: | |
| 3333 // (( ... )) => ... | |
| 3334 if (expression->parenthesization_level() > 1) return false; | |
| 3335 | |
| 3336 // Case for a single parameter: | |
| 3337 // (foo) => ... | |
| 3338 // foo => ... | |
| 3339 if (expression->IsVariableProxy()) { | |
| 3340 if (expression->AsVariableProxy()->is_this()) return false; | |
| 3341 | |
| 3342 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); | |
| 3343 if (traits->IsEvalOrArguments(raw_name) || | |
| 3344 traits->IsFutureStrictReserved(raw_name)) | |
| 3345 return false; | |
| 3346 | |
| 3347 collector->Add(expression->AsVariableProxy()); | |
| 3348 return true; | |
| 3349 } | |
| 3350 | |
| 3351 // Case for more than one parameter: | |
| 3352 // (foo, bar [, ...]) => ... | |
| 3353 if (expression->IsBinaryOperation()) { | |
| 3354 BinaryOperation* binop = expression->AsBinaryOperation(); | |
| 3355 if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() || | |
| 3356 binop->right()->is_parenthesized()) | |
| 3357 return false; | |
| 3358 | |
| 3359 return CheckAndCollectArrowParameter(traits, collector, binop->left()) && | |
| 3360 CheckAndCollectArrowParameter(traits, collector, binop->right()); | |
| 3361 } | |
| 3362 | |
| 3363 // Any other kind of expression is not a valid parameter list. | |
| 3364 return false; | |
| 3365 } | |
| 3366 | |
| 3367 | |
| 3368 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression( | |
| 3369 Expression* expression, bool* ok) { | |
| 3370 Collector<VariableProxy*> collector; | |
| 3371 *ok = CheckAndCollectArrowParameter(this, &collector, expression); | |
| 3372 return collector.ToVector(); | |
| 3373 } | |
| 3374 | |
| 3375 | |
| 3376 FunctionLiteral* Parser::ParseFunctionLiteral( | 3324 FunctionLiteral* Parser::ParseFunctionLiteral( |
| 3377 const AstRawString* function_name, | 3325 const AstRawString* function_name, |
| 3378 Scanner::Location function_name_location, | 3326 Scanner::Location function_name_location, |
| 3379 bool name_is_strict_reserved, | 3327 bool name_is_strict_reserved, |
| 3380 bool is_generator, | 3328 bool is_generator, |
| 3381 int function_token_pos, | 3329 int function_token_pos, |
| 3382 FunctionLiteral::FunctionType function_type, | 3330 FunctionLiteral::FunctionType function_type, |
| 3383 FunctionLiteral::ArityRestriction arity_restriction, | 3331 FunctionLiteral::ArityRestriction arity_restriction, |
| 3384 bool* ok) { | 3332 bool* ok) { |
| 3385 // Function :: | 3333 // Function :: |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3785 | 3733 |
| 3786 if (reusable_preparser_ == NULL) { | 3734 if (reusable_preparser_ == NULL) { |
| 3787 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 3735 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); |
| 3788 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 3736 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); |
| 3789 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3737 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
| 3790 reusable_preparser_->set_allow_modules(allow_modules()); | 3738 reusable_preparser_->set_allow_modules(allow_modules()); |
| 3791 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3739 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
| 3792 reusable_preparser_->set_allow_lazy(true); | 3740 reusable_preparser_->set_allow_lazy(true); |
| 3793 reusable_preparser_->set_allow_generators(allow_generators()); | 3741 reusable_preparser_->set_allow_generators(allow_generators()); |
| 3794 reusable_preparser_->set_allow_for_of(allow_for_of()); | 3742 reusable_preparser_->set_allow_for_of(allow_for_of()); |
| 3795 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); | |
| 3796 reusable_preparser_->set_allow_harmony_numeric_literals( | 3743 reusable_preparser_->set_allow_harmony_numeric_literals( |
| 3797 allow_harmony_numeric_literals()); | 3744 allow_harmony_numeric_literals()); |
| 3798 } | 3745 } |
| 3799 PreParser::PreParseResult result = | 3746 PreParser::PreParseResult result = |
| 3800 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3747 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
| 3801 is_generator(), | 3748 is_generator(), |
| 3802 logger); | 3749 logger); |
| 3803 return result; | 3750 return result; |
| 3804 } | 3751 } |
| 3805 | 3752 |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4919 info()->SetAstValueFactory(ast_value_factory_); | 4866 info()->SetAstValueFactory(ast_value_factory_); |
| 4920 } | 4867 } |
| 4921 ast_value_factory_ = NULL; | 4868 ast_value_factory_ = NULL; |
| 4922 | 4869 |
| 4923 InternalizeUseCounts(); | 4870 InternalizeUseCounts(); |
| 4924 | 4871 |
| 4925 return (result != NULL); | 4872 return (result != NULL); |
| 4926 } | 4873 } |
| 4927 | 4874 |
| 4928 } } // namespace v8::internal | 4875 } } // namespace v8::internal |
| OLD | NEW |