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); | |
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 2516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3311 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3312 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
3312 return static_cast<LiteralType>(literal_type->value()); | 3313 return static_cast<LiteralType>(literal_type->value()); |
3313 } | 3314 } |
3314 | 3315 |
3315 | 3316 |
3316 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3317 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
3317 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3318 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
3318 } | 3319 } |
3319 | 3320 |
3320 | 3321 |
3322 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression( | |
marja
2014/07/01 07:23:40
Comment from the previous round:
Here you have th
| |
3323 Expression* expression) { | |
3324 // Parsing the parameter list of an arrow function does not have parameters | |
3325 // (as in: () => ...) returns NULL, so expression being NULL is not an error, | |
3326 // but an valid empty parameter list. | |
3327 if (expression == NULL) | |
3328 return Vector<VariableProxy*>::empty(); | |
3329 | |
3330 Collector<VariableProxy*> collector; | |
3331 | |
3332 // IsValidArrowFunctionParamterList() can be used to check for validity, | |
3333 // here we just ASSERT() that the passed expression is a valid param list. | |
3334 while (expression->IsBinaryOperation()) { | |
3335 BinaryOperation* binop = expression->AsBinaryOperation(); | |
3336 ASSERT_EQ(binop->op(), Token::COMMA); | |
3337 | |
3338 expression = binop->right(); | |
3339 ASSERT(expression->IsVariableProxy()); | |
3340 ASSERT(!expression->AsVariableProxy()->is_this()); | |
3341 ASSERT(!IsEvalOrArguments(expression->AsVariableProxy()->raw_name())); | |
3342 ASSERT(!IsFutureStrictReserved(expression->AsVariableProxy()->raw_name())); | |
3343 | |
3344 collector.Add(expression->AsVariableProxy()); | |
3345 expression = binop->left(); | |
3346 } | |
3347 | |
3348 // Add the remaining item. | |
3349 ASSERT(expression->IsVariableProxy()); | |
3350 ASSERT(!expression->AsVariableProxy()->is_this()); | |
3351 ASSERT(!IsEvalOrArguments(expression->AsVariableProxy()->raw_name())); | |
3352 ASSERT(!IsFutureStrictReserved(expression->AsVariableProxy()->raw_name())); | |
3353 | |
3354 collector.Add(expression->AsVariableProxy()); | |
3355 return collector.ToVector(); | |
3356 } | |
3357 | |
3358 | |
3359 bool ParserTraits::IsValidArrowFunctionParameterList(Expression* expression) { | |
3360 // Case for empty parameter lists: | |
3361 // () => ... | |
3362 if (expression == NULL) | |
3363 return true; | |
3364 | |
3365 // Too many parentheses around expression: | |
3366 // (( ... )) => ... | |
3367 if (expression->parenthesization_level() > 1) | |
3368 return false; | |
3369 | |
3370 // Case for a single parameter: | |
3371 // (foo) => ... | |
3372 // foo => ... | |
3373 if (expression->IsVariableProxy()) { | |
3374 if (expression->AsVariableProxy()->is_this()) return false; | |
3375 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); | |
3376 return !(IsEvalOrArguments(raw_name) || IsFutureStrictReserved(raw_name)); | |
3377 } | |
3378 | |
3379 // Case for more than one parameter: | |
3380 // (foo, bar [, ...]) => ... | |
3381 if (expression->IsBinaryOperation()) { | |
3382 BinaryOperation* binop = expression->AsBinaryOperation(); | |
3383 return binop->op() == Token::COMMA && | |
3384 !binop->right()->is_parenthesized() && | |
3385 !binop->left()->is_parenthesized() && | |
3386 IsValidArrowFunctionParameterList(binop->right()) && | |
3387 IsValidArrowFunctionParameterList(binop->left()); | |
3388 } | |
3389 | |
3390 // Any other kind of expression is not a valid parameter list. | |
3391 return false; | |
3392 } | |
3393 | |
3394 | |
3321 FunctionLiteral* Parser::ParseFunctionLiteral( | 3395 FunctionLiteral* Parser::ParseFunctionLiteral( |
3322 const AstRawString* function_name, | 3396 const AstRawString* function_name, |
3323 Scanner::Location function_name_location, | 3397 Scanner::Location function_name_location, |
3324 bool name_is_strict_reserved, | 3398 bool name_is_strict_reserved, |
3325 bool is_generator, | 3399 bool is_generator, |
3326 int function_token_pos, | 3400 int function_token_pos, |
3327 FunctionLiteral::FunctionType function_type, | 3401 FunctionLiteral::FunctionType function_type, |
3328 FunctionLiteral::ArityRestriction arity_restriction, | 3402 FunctionLiteral::ArityRestriction arity_restriction, |
3329 bool* ok) { | 3403 bool* ok) { |
3330 // Function :: | 3404 // Function :: |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3730 | 3804 |
3731 if (reusable_preparser_ == NULL) { | 3805 if (reusable_preparser_ == NULL) { |
3732 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 3806 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); |
3733 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 3807 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); |
3734 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3808 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
3735 reusable_preparser_->set_allow_modules(allow_modules()); | 3809 reusable_preparser_->set_allow_modules(allow_modules()); |
3736 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3810 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
3737 reusable_preparser_->set_allow_lazy(true); | 3811 reusable_preparser_->set_allow_lazy(true); |
3738 reusable_preparser_->set_allow_generators(allow_generators()); | 3812 reusable_preparser_->set_allow_generators(allow_generators()); |
3739 reusable_preparser_->set_allow_for_of(allow_for_of()); | 3813 reusable_preparser_->set_allow_for_of(allow_for_of()); |
3814 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); | |
3740 reusable_preparser_->set_allow_harmony_numeric_literals( | 3815 reusable_preparser_->set_allow_harmony_numeric_literals( |
3741 allow_harmony_numeric_literals()); | 3816 allow_harmony_numeric_literals()); |
3742 } | 3817 } |
3743 PreParser::PreParseResult result = | 3818 PreParser::PreParseResult result = |
3744 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3819 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
3745 is_generator(), | 3820 is_generator(), |
3746 logger); | 3821 logger); |
3747 return result; | 3822 return result; |
3748 } | 3823 } |
3749 | 3824 |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4863 info()->SetAstValueFactory(ast_value_factory_); | 4938 info()->SetAstValueFactory(ast_value_factory_); |
4864 } | 4939 } |
4865 ast_value_factory_ = NULL; | 4940 ast_value_factory_ = NULL; |
4866 | 4941 |
4867 InternalizeUseCounts(); | 4942 InternalizeUseCounts(); |
4868 | 4943 |
4869 return (result != NULL); | 4944 return (result != NULL); |
4870 } | 4945 } |
4871 | 4946 |
4872 } } // namespace v8::internal | 4947 } } // namespace v8::internal |
OLD | NEW |