OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
750 | 750 |
751 | 751 |
752 Handle<String> ParserTraits::NextLiteralString(Scanner* scanner, | 752 Handle<String> ParserTraits::NextLiteralString(Scanner* scanner, |
753 PretenureFlag tenured) { | 753 PretenureFlag tenured) { |
754 return scanner->AllocateNextLiteralString(parser_->isolate(), tenured); | 754 return scanner->AllocateNextLiteralString(parser_->isolate(), tenured); |
755 } | 755 } |
756 | 756 |
757 | 757 |
758 Expression* ParserTraits::ThisExpression( | 758 Expression* ParserTraits::ThisExpression( |
759 Scope* scope, | 759 Scope* scope, |
760 AstNodeFactory<AstConstructionVisitor>* factory) { | 760 AstNodeFactory<AstConstructionVisitor>* factory, |
761 return factory->NewVariableProxy(scope->receiver()); | 761 int pos) { |
762 return factory->NewVariableProxy(scope->receiver(), pos); | |
762 } | 763 } |
763 | 764 |
764 | 765 |
765 Literal* ParserTraits::ExpressionFromLiteral( | 766 Literal* ParserTraits::ExpressionFromLiteral( |
766 Token::Value token, int pos, | 767 Token::Value token, int pos, |
767 Scanner* scanner, | 768 Scanner* scanner, |
768 AstNodeFactory<AstConstructionVisitor>* factory) { | 769 AstNodeFactory<AstConstructionVisitor>* factory) { |
769 Factory* isolate_factory = parser_->isolate()->factory(); | 770 Factory* isolate_factory = parser_->isolate()->factory(); |
770 switch (token) { | 771 switch (token) { |
771 case Token::NULL_LITERAL: | 772 case Token::NULL_LITERAL: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 cached_data_mode_(NO_CACHED_DATA), | 853 cached_data_mode_(NO_CACHED_DATA), |
853 info_(info) { | 854 info_(info) { |
854 ASSERT(!script_.is_null()); | 855 ASSERT(!script_.is_null()); |
855 isolate_->set_ast_node_id(0); | 856 isolate_->set_ast_node_id(0); |
856 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 857 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
857 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 858 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
858 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 859 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
859 set_allow_lazy(false); // Must be explicitly enabled. | 860 set_allow_lazy(false); // Must be explicitly enabled. |
860 set_allow_generators(FLAG_harmony_generators); | 861 set_allow_generators(FLAG_harmony_generators); |
861 set_allow_for_of(FLAG_harmony_iteration); | 862 set_allow_for_of(FLAG_harmony_iteration); |
863 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | |
862 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 864 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
863 } | 865 } |
864 | 866 |
865 | 867 |
866 FunctionLiteral* Parser::ParseProgram() { | 868 FunctionLiteral* Parser::ParseProgram() { |
867 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 869 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
868 // see comment for HistogramTimerScope class. | 870 // see comment for HistogramTimerScope class. |
869 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); | 871 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); |
870 Handle<String> source(String::cast(script_->source())); | 872 Handle<String> source(String::cast(script_->source())); |
871 isolate()->counters()->total_parse_size()->Increment(source->length()); | 873 isolate()->counters()->total_parse_size()->Increment(source->length()); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
987 body, | 989 body, |
988 function_state.materialized_literal_count(), | 990 function_state.materialized_literal_count(), |
989 function_state.expected_property_count(), | 991 function_state.expected_property_count(), |
990 function_state.handler_count(), | 992 function_state.handler_count(), |
991 0, | 993 0, |
992 FunctionLiteral::kNoDuplicateParameters, | 994 FunctionLiteral::kNoDuplicateParameters, |
993 FunctionLiteral::ANONYMOUS_EXPRESSION, | 995 FunctionLiteral::ANONYMOUS_EXPRESSION, |
994 FunctionLiteral::kGlobalOrEval, | 996 FunctionLiteral::kGlobalOrEval, |
995 FunctionLiteral::kNotParenthesized, | 997 FunctionLiteral::kNotParenthesized, |
996 FunctionLiteral::kNotGenerator, | 998 FunctionLiteral::kNotGenerator, |
999 FunctionLiteral::kNotArrow, | |
997 0); | 1000 0); |
998 result->set_ast_properties(factory()->visitor()->ast_properties()); | 1001 result->set_ast_properties(factory()->visitor()->ast_properties()); |
999 result->set_slot_processor(factory()->visitor()->slot_processor()); | 1002 result->set_slot_processor(factory()->visitor()->slot_processor()); |
1000 result->set_dont_optimize_reason( | 1003 result->set_dont_optimize_reason( |
1001 factory()->visitor()->dont_optimize_reason()); | 1004 factory()->visitor()->dont_optimize_reason()); |
1002 } else if (stack_overflow()) { | 1005 } else if (stack_overflow()) { |
1003 isolate()->StackOverflow(); | 1006 isolate()->StackOverflow(); |
1004 } | 1007 } |
1005 } | 1008 } |
1006 | 1009 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1072 original_scope_ = scope; | 1075 original_scope_ = scope; |
1073 FunctionState function_state(&function_state_, &scope_, scope, zone()); | 1076 FunctionState function_state(&function_state_, &scope_, scope, zone()); |
1074 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); | 1077 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); |
1075 ASSERT(info()->strict_mode() == shared_info->strict_mode()); | 1078 ASSERT(info()->strict_mode() == shared_info->strict_mode()); |
1076 scope->SetStrictMode(shared_info->strict_mode()); | 1079 scope->SetStrictMode(shared_info->strict_mode()); |
1077 FunctionLiteral::FunctionType function_type = shared_info->is_expression() | 1080 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
1078 ? (shared_info->is_anonymous() | 1081 ? (shared_info->is_anonymous() |
1079 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 1082 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
1080 : FunctionLiteral::NAMED_EXPRESSION) | 1083 : FunctionLiteral::NAMED_EXPRESSION) |
1081 : FunctionLiteral::DECLARATION; | 1084 : FunctionLiteral::DECLARATION; |
1085 bool is_generator = shared_info->is_generator(); | |
1082 bool ok = true; | 1086 bool ok = true; |
1083 result = ParseFunctionLiteral(name, | 1087 |
1084 Scanner::Location::invalid(), | 1088 if (shared_info->is_arrow()) { |
1085 false, // Strict mode name already checked. | 1089 ASSERT(!is_generator); |
1086 shared_info->is_generator(), | 1090 result = reinterpret_cast<FunctionLiteral*>( |
1087 RelocInfo::kNoPosition, | 1091 ParseArrowFunctionLiteral(shared_info->start_position(), NULL, &ok)); |
1088 function_type, | 1092 } else { |
1089 &ok); | 1093 result = ParseFunctionLiteral(name, |
1094 Scanner::Location::invalid(), | |
1095 false, // Strict mode name already checked. | |
1096 is_generator, | |
1097 RelocInfo::kNoPosition, | |
1098 function_type, | |
1099 &ok); | |
1100 } | |
1090 // Make sure the results agree. | 1101 // Make sure the results agree. |
1091 ASSERT(ok == (result != NULL)); | 1102 ASSERT(ok == (result != NULL)); |
1092 } | 1103 } |
1093 | 1104 |
1094 // Make sure the target stack is empty. | 1105 // Make sure the target stack is empty. |
1095 ASSERT(target_stack_ == NULL); | 1106 ASSERT(target_stack_ == NULL); |
1096 | 1107 |
1097 if (result == NULL) { | 1108 if (result == NULL) { |
1098 if (stack_overflow()) isolate()->StackOverflow(); | 1109 if (stack_overflow()) isolate()->StackOverflow(); |
1099 } else { | 1110 } else { |
(...skipping 2081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3181 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3192 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
3182 return static_cast<LiteralType>(literal_type->value()); | 3193 return static_cast<LiteralType>(literal_type->value()); |
3183 } | 3194 } |
3184 | 3195 |
3185 | 3196 |
3186 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3197 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
3187 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3198 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
3188 } | 3199 } |
3189 | 3200 |
3190 | 3201 |
3202 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression( | |
marja
2014/04/24 08:08:06
It looks like this doesn't check that the expressi
aperez
2014/04/24 12:38:37
The example you mention would be a comma-expressio
marja
2014/04/29 09:38:44
Hmm, okay. It would be good to add test cases to m
| |
3203 Expression* expression, bool* ok) { | |
3204 | |
3205 // Parsing the parameter list of an arrow function does not have parameters | |
3206 // (as in: () => ...) returns NULL, so expression being NULL is not an error, | |
3207 // but an valid empty parameter list. | |
3208 if (expression == NULL) | |
3209 return Vector<VariableProxy*>::empty(); | |
3210 | |
3211 const char* error_token = Token::String(Token::THIS); | |
3212 int error_pos = RelocInfo::kNoPosition; | |
3213 | |
3214 Collector<VariableProxy*> collector; | |
3215 while (expression->IsBinaryOperation()) { | |
3216 BinaryOperation* binop = expression->AsBinaryOperation(); | |
3217 | |
3218 if (binop->op() != Token::COMMA) { | |
3219 error_token = Token::String(expression->AsBinaryOperation()->op()); | |
3220 goto invalid_token; | |
marja
2014/04/24 08:08:06
Afaics, it would be possible to write this in a go
aperez
2014/04/24 12:38:37
Sure thing, I will do that. The function will not
| |
3221 } | |
3222 | |
3223 expression = binop->right(); | |
3224 if (!expression->IsVariableProxy()) | |
3225 goto not_variable_proxy; | |
3226 if (expression->AsVariableProxy()->is_this()) | |
3227 goto invalid_token; | |
3228 | |
3229 collector.Add(expression->AsVariableProxy()); | |
3230 expression = binop->left(); | |
3231 } | |
3232 | |
3233 if (!expression->IsVariableProxy()) | |
3234 goto not_variable_proxy; | |
3235 if (expression->AsVariableProxy()->is_this()) | |
3236 goto invalid_token; | |
3237 | |
3238 collector.Add(expression->AsVariableProxy()); | |
3239 return collector.ToVector(); | |
3240 | |
3241 not_variable_proxy: | |
3242 error_token = ""; | |
3243 // fall-through | |
3244 invalid_token: | |
3245 error_pos = expression->position(); | |
3246 ParserTraits::ReportMessageAt( | |
3247 Scanner::Location(error_pos, error_pos + strlen(error_token)), | |
3248 "unexpected_token", | |
3249 Vector<const char*>(&error_token, *error_token ? 1 : 0)); | |
3250 *ok = false; | |
3251 return Vector<VariableProxy*>::empty(); | |
3252 } | |
3253 | |
3254 | |
3191 FunctionLiteral* Parser::ParseFunctionLiteral( | 3255 FunctionLiteral* Parser::ParseFunctionLiteral( |
3192 Handle<String> function_name, | 3256 Handle<String> function_name, |
3193 Scanner::Location function_name_location, | 3257 Scanner::Location function_name_location, |
3194 bool name_is_strict_reserved, | 3258 bool name_is_strict_reserved, |
3195 bool is_generator, | 3259 bool is_generator, |
3196 int function_token_pos, | 3260 int function_token_pos, |
3197 FunctionLiteral::FunctionType function_type, | 3261 FunctionLiteral::FunctionType function_type, |
3198 bool* ok) { | 3262 bool* ok) { |
3199 // Function :: | 3263 // Function :: |
3200 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 3264 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3446 body, | 3510 body, |
3447 materialized_literal_count, | 3511 materialized_literal_count, |
3448 expected_property_count, | 3512 expected_property_count, |
3449 handler_count, | 3513 handler_count, |
3450 num_parameters, | 3514 num_parameters, |
3451 duplicate_parameters, | 3515 duplicate_parameters, |
3452 function_type, | 3516 function_type, |
3453 FunctionLiteral::kIsFunction, | 3517 FunctionLiteral::kIsFunction, |
3454 parenthesized, | 3518 parenthesized, |
3455 generator, | 3519 generator, |
3520 FunctionLiteral::kNotArrow, | |
3456 pos); | 3521 pos); |
3457 function_literal->set_function_token_position(function_token_pos); | 3522 function_literal->set_function_token_position(function_token_pos); |
3458 function_literal->set_ast_properties(&ast_properties); | 3523 function_literal->set_ast_properties(&ast_properties); |
3459 function_literal->set_slot_processor(slot_processor); | 3524 function_literal->set_slot_processor(slot_processor); |
3460 function_literal->set_dont_optimize_reason(dont_optimize_reason); | 3525 function_literal->set_dont_optimize_reason(dont_optimize_reason); |
3461 | 3526 |
3462 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 3527 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
3463 return function_literal; | 3528 return function_literal; |
3464 } | 3529 } |
3465 | 3530 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3613 | 3678 |
3614 if (reusable_preparser_ == NULL) { | 3679 if (reusable_preparser_ == NULL) { |
3615 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 3680 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); |
3616 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 3681 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); |
3617 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3682 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
3618 reusable_preparser_->set_allow_modules(allow_modules()); | 3683 reusable_preparser_->set_allow_modules(allow_modules()); |
3619 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3684 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
3620 reusable_preparser_->set_allow_lazy(true); | 3685 reusable_preparser_->set_allow_lazy(true); |
3621 reusable_preparser_->set_allow_generators(allow_generators()); | 3686 reusable_preparser_->set_allow_generators(allow_generators()); |
3622 reusable_preparser_->set_allow_for_of(allow_for_of()); | 3687 reusable_preparser_->set_allow_for_of(allow_for_of()); |
3688 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); | |
3623 reusable_preparser_->set_allow_harmony_numeric_literals( | 3689 reusable_preparser_->set_allow_harmony_numeric_literals( |
3624 allow_harmony_numeric_literals()); | 3690 allow_harmony_numeric_literals()); |
3625 } | 3691 } |
3626 PreParser::PreParseResult result = | 3692 PreParser::PreParseResult result = |
3627 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3693 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
3628 is_generator(), | 3694 is_generator(), |
3629 logger); | 3695 logger); |
3630 return result; | 3696 return result; |
3631 } | 3697 } |
3632 | 3698 |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4693 ASSERT(info()->isolate()->has_pending_exception()); | 4759 ASSERT(info()->isolate()->has_pending_exception()); |
4694 } else { | 4760 } else { |
4695 result = ParseProgram(); | 4761 result = ParseProgram(); |
4696 } | 4762 } |
4697 } | 4763 } |
4698 info()->SetFunction(result); | 4764 info()->SetFunction(result); |
4699 return (result != NULL); | 4765 return (result != NULL); |
4700 } | 4766 } |
4701 | 4767 |
4702 } } // namespace v8::internal | 4768 } } // namespace v8::internal |
OLD | NEW |