OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 123 } |
124 | 124 |
125 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 125 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
126 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, | 126 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, |
127 bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark, | 127 bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark, |
128 int* use_counts) { | 128 int* use_counts) { |
129 parsing_module_ = parsing_module; | 129 parsing_module_ = parsing_module; |
130 log_ = log; | 130 log_ = log; |
131 use_counts_ = use_counts; | 131 use_counts_ = use_counts; |
132 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 132 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
133 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); | 133 DCHECK_NULL(scope_state_); |
134 PreParserFactory top_factory(NULL); | 134 Scope* top_scope = NewScope(nullptr, SCRIPT_SCOPE); |
135 FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction, | 135 PreParserFactory top_factory(nullptr); |
136 &top_factory); | 136 FunctionState top_state(&function_state_, &scope_state_, top_scope, |
137 scope_->SetLanguageMode(language_mode); | 137 kNormalFunction, &top_factory); |
138 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); | 138 scope()->SetLanguageMode(language_mode); |
| 139 Scope* function_scope = NewScope(scope(), FUNCTION_SCOPE, kind); |
139 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); | 140 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); |
140 PreParserFactory function_factory(NULL); | 141 PreParserFactory function_factory(nullptr); |
141 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 142 FunctionState function_state(&function_state_, &scope_state_, function_scope, |
142 &function_factory); | 143 kind, &function_factory); |
143 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 144 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
144 bool ok = true; | 145 bool ok = true; |
145 int start_position = peek_position(); | 146 int start_position = peek_position(); |
146 ParseLazyFunctionLiteralBody(&ok, bookmark); | 147 ParseLazyFunctionLiteralBody(&ok, bookmark); |
147 use_counts_ = nullptr; | 148 use_counts_ = nullptr; |
148 if (bookmark && bookmark->HasBeenReset()) { | 149 if (bookmark && bookmark->HasBeenReset()) { |
149 // Do nothing, as we've just aborted scanning this function. | 150 // Do nothing, as we've just aborted scanning this function. |
150 } else if (stack_overflow()) { | 151 } else if (stack_overflow()) { |
151 return kPreParseStackOverflow; | 152 return kPreParseStackOverflow; |
152 } else if (!ok) { | 153 } else if (!ok) { |
153 ReportUnexpectedToken(scanner()->current_token()); | 154 ReportUnexpectedToken(scanner()->current_token()); |
154 } else { | 155 } else { |
155 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 156 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
156 if (is_strict(scope_->language_mode())) { | 157 if (is_strict(scope()->language_mode())) { |
157 int end_pos = scanner()->location().end_pos; | 158 int end_pos = scanner()->location().end_pos; |
158 CheckStrictOctalLiteral(start_position, end_pos, &ok); | 159 CheckStrictOctalLiteral(start_position, end_pos, &ok); |
159 CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos); | 160 CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos); |
160 if (!ok) return kPreParseSuccess; | 161 if (!ok) return kPreParseSuccess; |
161 } | 162 } |
162 } | 163 } |
163 return kPreParseSuccess; | 164 return kPreParseSuccess; |
164 } | 165 } |
165 | 166 |
166 PreParserExpression PreParserTraits::ParseClassLiteral( | 167 PreParserExpression PreParserTraits::ParseClassLiteral( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 directive_prologue = false; | 247 directive_prologue = false; |
247 } | 248 } |
248 bool starts_with_identifier = peek() == Token::IDENTIFIER; | 249 bool starts_with_identifier = peek() == Token::IDENTIFIER; |
249 Scanner::Location token_loc = scanner()->peek_location(); | 250 Scanner::Location token_loc = scanner()->peek_location(); |
250 Statement statement = ParseStatementListItem(CHECK_OK_CUSTOM(Void)); | 251 Statement statement = ParseStatementListItem(CHECK_OK_CUSTOM(Void)); |
251 | 252 |
252 if (directive_prologue) { | 253 if (directive_prologue) { |
253 bool use_strict_found = statement.IsUseStrictLiteral(); | 254 bool use_strict_found = statement.IsUseStrictLiteral(); |
254 | 255 |
255 if (use_strict_found) { | 256 if (use_strict_found) { |
256 scope_->SetLanguageMode( | 257 scope()->SetLanguageMode( |
257 static_cast<LanguageMode>(scope_->language_mode() | STRICT)); | 258 static_cast<LanguageMode>(scope()->language_mode() | STRICT)); |
258 } else if (!statement.IsStringLiteral()) { | 259 } else if (!statement.IsStringLiteral()) { |
259 directive_prologue = false; | 260 directive_prologue = false; |
260 } | 261 } |
261 | 262 |
262 if (use_strict_found && !scope_->HasSimpleParameters()) { | 263 if (use_strict_found && !scope()->HasSimpleParameters()) { |
263 // TC39 deemed "use strict" directives to be an error when occurring | 264 // TC39 deemed "use strict" directives to be an error when occurring |
264 // in the body of a function with non-simple parameter list, on | 265 // in the body of a function with non-simple parameter list, on |
265 // 29/7/2015. https://goo.gl/ueA7Ln | 266 // 29/7/2015. https://goo.gl/ueA7Ln |
266 PreParserTraits::ReportMessageAt( | 267 PreParserTraits::ReportMessageAt( |
267 token_loc, MessageTemplate::kIllegalLanguageModeDirective, | 268 token_loc, MessageTemplate::kIllegalLanguageModeDirective, |
268 "use strict"); | 269 "use strict"); |
269 *ok = false; | 270 *ok = false; |
270 return; | 271 return; |
271 } | 272 } |
272 } | 273 } |
(...skipping 26 matching lines...) Expand all Loading... |
299 return Statement::Default(); | 300 return Statement::Default(); |
300 } | 301 } |
301 return ParseSubStatement(allow_function, ok); | 302 return ParseSubStatement(allow_function, ok); |
302 } | 303 } |
303 | 304 |
304 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { | 305 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { |
305 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 306 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
306 (legacy && allow_harmony_restrictive_declarations())) { | 307 (legacy && allow_harmony_restrictive_declarations())) { |
307 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); | 308 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); |
308 } else { | 309 } else { |
309 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); | 310 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE); |
310 BlockState block_state(&scope_, body_scope); | 311 BlockState block_state(&scope_state_, body_scope); |
311 return ParseFunctionDeclaration(ok); | 312 return ParseFunctionDeclaration(ok); |
312 } | 313 } |
313 } | 314 } |
314 | 315 |
315 PreParser::Statement PreParser::ParseSubStatement( | 316 PreParser::Statement PreParser::ParseSubStatement( |
316 AllowLabelledFunctionStatement allow_function, bool* ok) { | 317 AllowLabelledFunctionStatement allow_function, bool* ok) { |
317 // Statement :: | 318 // Statement :: |
318 // Block | 319 // Block |
319 // VariableStatement | 320 // VariableStatement |
320 // EmptyStatement | 321 // EmptyStatement |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 ParseClassLiteral(nullptr, name, scanner()->location(), is_strict_reserved, | 471 ParseClassLiteral(nullptr, name, scanner()->location(), is_strict_reserved, |
471 pos, CHECK_OK); | 472 pos, CHECK_OK); |
472 return Statement::Default(); | 473 return Statement::Default(); |
473 } | 474 } |
474 | 475 |
475 | 476 |
476 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 477 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
477 // Block :: | 478 // Block :: |
478 // '{' StatementList '}' | 479 // '{' StatementList '}' |
479 | 480 |
480 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 481 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE); |
481 Expect(Token::LBRACE, CHECK_OK); | 482 Expect(Token::LBRACE, CHECK_OK); |
482 Statement final = Statement::Default(); | 483 Statement final = Statement::Default(); |
483 { | 484 { |
484 BlockState block_state(&scope_, block_scope); | 485 BlockState block_state(&scope_state_, block_scope); |
485 while (peek() != Token::RBRACE) { | 486 while (peek() != Token::RBRACE) { |
486 final = ParseStatementListItem(CHECK_OK); | 487 final = ParseStatementListItem(CHECK_OK); |
487 } | 488 } |
488 } | 489 } |
489 Expect(Token::RBRACE, ok); | 490 Expect(Token::RBRACE, ok); |
490 return final; | 491 return final; |
491 } | 492 } |
492 | 493 |
493 | 494 |
494 PreParser::Statement PreParser::ParseVariableStatement( | 495 PreParser::Statement PreParser::ParseVariableStatement( |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 Expect(Token::WITH, CHECK_OK); | 785 Expect(Token::WITH, CHECK_OK); |
785 if (is_strict(language_mode())) { | 786 if (is_strict(language_mode())) { |
786 ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith); | 787 ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith); |
787 *ok = false; | 788 *ok = false; |
788 return Statement::Default(); | 789 return Statement::Default(); |
789 } | 790 } |
790 Expect(Token::LPAREN, CHECK_OK); | 791 Expect(Token::LPAREN, CHECK_OK); |
791 ParseExpression(true, CHECK_OK); | 792 ParseExpression(true, CHECK_OK); |
792 Expect(Token::RPAREN, CHECK_OK); | 793 Expect(Token::RPAREN, CHECK_OK); |
793 | 794 |
794 Scope* with_scope = NewScope(scope_, WITH_SCOPE); | 795 Scope* with_scope = NewScope(scope(), WITH_SCOPE); |
795 BlockState block_state(&scope_, with_scope); | 796 BlockState block_state(&scope_state_, with_scope); |
796 ParseScopedStatement(true, CHECK_OK); | 797 ParseScopedStatement(true, CHECK_OK); |
797 return Statement::Default(); | 798 return Statement::Default(); |
798 } | 799 } |
799 | 800 |
800 | 801 |
801 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { | 802 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { |
802 // SwitchStatement :: | 803 // SwitchStatement :: |
803 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 804 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
804 | 805 |
805 Expect(Token::SWITCH, CHECK_OK); | 806 Expect(Token::SWITCH, CHECK_OK); |
806 Expect(Token::LPAREN, CHECK_OK); | 807 Expect(Token::LPAREN, CHECK_OK); |
807 ParseExpression(true, CHECK_OK); | 808 ParseExpression(true, CHECK_OK); |
808 Expect(Token::RPAREN, CHECK_OK); | 809 Expect(Token::RPAREN, CHECK_OK); |
809 | 810 |
810 Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); | 811 Scope* cases_scope = NewScope(scope(), BLOCK_SCOPE); |
811 { | 812 { |
812 BlockState cases_block_state(&scope_, cases_scope); | 813 BlockState cases_block_state(&scope_state_, cases_scope); |
813 Expect(Token::LBRACE, CHECK_OK); | 814 Expect(Token::LBRACE, CHECK_OK); |
814 Token::Value token = peek(); | 815 Token::Value token = peek(); |
815 while (token != Token::RBRACE) { | 816 while (token != Token::RBRACE) { |
816 if (token == Token::CASE) { | 817 if (token == Token::CASE) { |
817 Expect(Token::CASE, CHECK_OK); | 818 Expect(Token::CASE, CHECK_OK); |
818 ParseExpression(true, CHECK_OK); | 819 ParseExpression(true, CHECK_OK); |
819 } else { | 820 } else { |
820 Expect(Token::DEFAULT, CHECK_OK); | 821 Expect(Token::DEFAULT, CHECK_OK); |
821 } | 822 } |
822 Expect(Token::COLON, CHECK_OK); | 823 Expect(Token::COLON, CHECK_OK); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 ParseScopedStatement(true, ok); | 862 ParseScopedStatement(true, ok); |
862 return Statement::Default(); | 863 return Statement::Default(); |
863 } | 864 } |
864 | 865 |
865 | 866 |
866 PreParser::Statement PreParser::ParseForStatement(bool* ok) { | 867 PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
867 // ForStatement :: | 868 // ForStatement :: |
868 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 869 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
869 | 870 |
870 // Create an in-between scope for let-bound iteration variables. | 871 // Create an in-between scope for let-bound iteration variables. |
871 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); | 872 Scope* for_scope = NewScope(scope(), BLOCK_SCOPE); |
872 bool has_lexical = false; | 873 bool has_lexical = false; |
873 | 874 |
874 BlockState block_state(&scope_, for_scope); | 875 BlockState block_state(&scope_state_, for_scope); |
875 Expect(Token::FOR, CHECK_OK); | 876 Expect(Token::FOR, CHECK_OK); |
876 Expect(Token::LPAREN, CHECK_OK); | 877 Expect(Token::LPAREN, CHECK_OK); |
877 if (peek() != Token::SEMICOLON) { | 878 if (peek() != Token::SEMICOLON) { |
878 ForEachStatement::VisitMode mode; | 879 ForEachStatement::VisitMode mode; |
879 if (peek() == Token::VAR || peek() == Token::CONST || | 880 if (peek() == Token::VAR || peek() == Token::CONST || |
880 (peek() == Token::LET && IsNextLetKeyword())) { | 881 (peek() == Token::LET && IsNextLetKeyword())) { |
881 int decl_count; | 882 int decl_count; |
882 bool is_lexical; | 883 bool is_lexical; |
883 bool is_binding_pattern; | 884 bool is_binding_pattern; |
884 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); | 885 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 | 952 |
952 if (mode == ForEachStatement::ITERATE) { | 953 if (mode == ForEachStatement::ITERATE) { |
953 ExpressionClassifier classifier(this); | 954 ExpressionClassifier classifier(this); |
954 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 955 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
955 RewriteNonPattern(&classifier, CHECK_OK); | 956 RewriteNonPattern(&classifier, CHECK_OK); |
956 } else { | 957 } else { |
957 ParseExpression(true, CHECK_OK); | 958 ParseExpression(true, CHECK_OK); |
958 } | 959 } |
959 | 960 |
960 Expect(Token::RPAREN, CHECK_OK); | 961 Expect(Token::RPAREN, CHECK_OK); |
961 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); | 962 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE); |
962 { | 963 { |
963 BlockState block_state(&scope_, body_scope); | 964 BlockState block_state(&scope_state_, body_scope); |
964 ParseScopedStatement(true, CHECK_OK); | 965 ParseScopedStatement(true, CHECK_OK); |
965 } | 966 } |
966 return Statement::Default(); | 967 return Statement::Default(); |
967 } | 968 } |
968 } | 969 } |
969 } | 970 } |
970 | 971 |
971 // Parsed initializer at this point. | 972 // Parsed initializer at this point. |
972 Expect(Token::SEMICOLON, CHECK_OK); | 973 Expect(Token::SEMICOLON, CHECK_OK); |
973 | 974 |
974 // If there are let bindings, then condition and the next statement of the | 975 // If there are let bindings, then condition and the next statement of the |
975 // for loop must be parsed in a new scope. | 976 // for loop must be parsed in a new scope. |
976 Scope* inner_scope = scope_; | 977 Scope* inner_scope = scope(); |
977 if (has_lexical) inner_scope = NewScope(for_scope, BLOCK_SCOPE); | 978 if (has_lexical) inner_scope = NewScope(for_scope, BLOCK_SCOPE); |
978 | 979 |
979 { | 980 { |
980 BlockState block_state(&scope_, inner_scope); | 981 BlockState block_state(&scope_state_, inner_scope); |
981 | 982 |
982 if (peek() != Token::SEMICOLON) { | 983 if (peek() != Token::SEMICOLON) { |
983 ParseExpression(true, CHECK_OK); | 984 ParseExpression(true, CHECK_OK); |
984 } | 985 } |
985 Expect(Token::SEMICOLON, CHECK_OK); | 986 Expect(Token::SEMICOLON, CHECK_OK); |
986 | 987 |
987 if (peek() != Token::RPAREN) { | 988 if (peek() != Token::RPAREN) { |
988 ParseExpression(true, CHECK_OK); | 989 ParseExpression(true, CHECK_OK); |
989 } | 990 } |
990 Expect(Token::RPAREN, CHECK_OK); | 991 Expect(Token::RPAREN, CHECK_OK); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 if (tok != Token::CATCH && tok != Token::FINALLY) { | 1036 if (tok != Token::CATCH && tok != Token::FINALLY) { |
1036 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally); | 1037 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally); |
1037 *ok = false; | 1038 *ok = false; |
1038 return Statement::Default(); | 1039 return Statement::Default(); |
1039 } | 1040 } |
1040 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); | 1041 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); |
1041 bool catch_block_exists = false; | 1042 bool catch_block_exists = false; |
1042 if (tok == Token::CATCH) { | 1043 if (tok == Token::CATCH) { |
1043 Consume(Token::CATCH); | 1044 Consume(Token::CATCH); |
1044 Expect(Token::LPAREN, CHECK_OK); | 1045 Expect(Token::LPAREN, CHECK_OK); |
1045 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); | 1046 Scope* catch_scope = NewScope(scope(), CATCH_SCOPE); |
1046 ExpressionClassifier pattern_classifier(this); | 1047 ExpressionClassifier pattern_classifier(this); |
1047 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | 1048 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
1048 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | 1049 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
1049 Expect(Token::RPAREN, CHECK_OK); | 1050 Expect(Token::RPAREN, CHECK_OK); |
1050 { | 1051 { |
1051 CollectExpressionsInTailPositionToListScope | 1052 CollectExpressionsInTailPositionToListScope |
1052 collect_tail_call_expressions_scope( | 1053 collect_tail_call_expressions_scope( |
1053 function_state_, &tail_call_expressions_in_catch_block); | 1054 function_state_, &tail_call_expressions_in_catch_block); |
1054 BlockState block_state(&scope_, catch_scope); | 1055 BlockState block_state(&scope_state_, catch_scope); |
1055 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 1056 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE); |
1056 { | 1057 { |
1057 BlockState block_state(&scope_, block_scope); | 1058 BlockState block_state(&scope_state_, block_scope); |
1058 ParseBlock(CHECK_OK); | 1059 ParseBlock(CHECK_OK); |
1059 } | 1060 } |
1060 } | 1061 } |
1061 catch_block_exists = true; | 1062 catch_block_exists = true; |
1062 tok = peek(); | 1063 tok = peek(); |
1063 } | 1064 } |
1064 if (tok == Token::FINALLY) { | 1065 if (tok == Token::FINALLY) { |
1065 Consume(Token::FINALLY); | 1066 Consume(Token::FINALLY); |
1066 ParseBlock(CHECK_OK); | 1067 ParseBlock(CHECK_OK); |
1067 if (FLAG_harmony_explicit_tailcalls && catch_block_exists && | 1068 if (FLAG_harmony_explicit_tailcalls && catch_block_exists && |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 | 1103 |
1103 PreParser::Expression PreParser::ParseFunctionLiteral( | 1104 PreParser::Expression PreParser::ParseFunctionLiteral( |
1104 Identifier function_name, Scanner::Location function_name_location, | 1105 Identifier function_name, Scanner::Location function_name_location, |
1105 FunctionNameValidity function_name_validity, FunctionKind kind, | 1106 FunctionNameValidity function_name_validity, FunctionKind kind, |
1106 int function_token_pos, FunctionLiteral::FunctionType function_type, | 1107 int function_token_pos, FunctionLiteral::FunctionType function_type, |
1107 LanguageMode language_mode, bool* ok) { | 1108 LanguageMode language_mode, bool* ok) { |
1108 // Function :: | 1109 // Function :: |
1109 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 1110 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
1110 | 1111 |
1111 // Parse function body. | 1112 // Parse function body. |
1112 bool outer_is_script_scope = scope_->is_script_scope(); | 1113 bool outer_is_script_scope = scope()->is_script_scope(); |
1113 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); | 1114 Scope* function_scope = NewScope(scope(), FUNCTION_SCOPE, kind); |
1114 function_scope->SetLanguageMode(language_mode); | 1115 function_scope->SetLanguageMode(language_mode); |
1115 PreParserFactory factory(NULL); | 1116 PreParserFactory factory(NULL); |
1116 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 1117 FunctionState function_state(&function_state_, &scope_state_, function_scope, |
1117 &factory); | 1118 kind, &factory); |
1118 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 1119 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
1119 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 1120 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
1120 | 1121 |
1121 Expect(Token::LPAREN, CHECK_OK); | 1122 Expect(Token::LPAREN, CHECK_OK); |
1122 int start_position = scanner()->location().beg_pos; | 1123 int start_position = scanner()->location().beg_pos; |
1123 function_scope->set_start_position(start_position); | 1124 function_scope->set_start_position(start_position); |
1124 PreParserFormalParameters formals(function_scope); | 1125 PreParserFormalParameters formals(function_scope); |
1125 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); | 1126 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); |
1126 Expect(Token::RPAREN, CHECK_OK); | 1127 Expect(Token::RPAREN, CHECK_OK); |
1127 int formals_end_position = scanner()->location().end_pos; | 1128 int formals_end_position = scanner()->location().end_pos; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 ParseStatementList(Token::RBRACE, ok, bookmark); | 1203 ParseStatementList(Token::RBRACE, ok, bookmark); |
1203 if (!*ok) return; | 1204 if (!*ok) return; |
1204 if (bookmark && bookmark->HasBeenReset()) return; | 1205 if (bookmark && bookmark->HasBeenReset()) return; |
1205 | 1206 |
1206 // Position right after terminal '}'. | 1207 // Position right after terminal '}'. |
1207 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 1208 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
1208 int body_end = scanner()->peek_location().end_pos; | 1209 int body_end = scanner()->peek_location().end_pos; |
1209 log_->LogFunction(body_start, body_end, | 1210 log_->LogFunction(body_start, body_end, |
1210 function_state_->materialized_literal_count(), | 1211 function_state_->materialized_literal_count(), |
1211 function_state_->expected_property_count(), language_mode(), | 1212 function_state_->expected_property_count(), language_mode(), |
1212 scope_->uses_super_property(), scope_->calls_eval()); | 1213 scope()->uses_super_property(), scope()->calls_eval()); |
1213 } | 1214 } |
1214 | 1215 |
1215 PreParserExpression PreParser::ParseClassLiteral( | 1216 PreParserExpression PreParser::ParseClassLiteral( |
1216 ExpressionClassifier* classifier, PreParserIdentifier name, | 1217 ExpressionClassifier* classifier, PreParserIdentifier name, |
1217 Scanner::Location class_name_location, bool name_is_strict_reserved, | 1218 Scanner::Location class_name_location, bool name_is_strict_reserved, |
1218 int pos, bool* ok) { | 1219 int pos, bool* ok) { |
1219 // All parts of a ClassDeclaration and ClassExpression are strict code. | 1220 // All parts of a ClassDeclaration and ClassExpression are strict code. |
1220 if (name_is_strict_reserved) { | 1221 if (name_is_strict_reserved) { |
1221 ReportMessageAt(class_name_location, | 1222 ReportMessageAt(class_name_location, |
1222 MessageTemplate::kUnexpectedStrictReserved); | 1223 MessageTemplate::kUnexpectedStrictReserved); |
1223 *ok = false; | 1224 *ok = false; |
1224 return EmptyExpression(); | 1225 return EmptyExpression(); |
1225 } | 1226 } |
1226 if (IsEvalOrArguments(name)) { | 1227 if (IsEvalOrArguments(name)) { |
1227 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); | 1228 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
1228 *ok = false; | 1229 *ok = false; |
1229 return EmptyExpression(); | 1230 return EmptyExpression(); |
1230 } | 1231 } |
1231 | 1232 |
1232 LanguageMode class_language_mode = language_mode(); | 1233 LanguageMode class_language_mode = language_mode(); |
1233 Scope* scope = NewScope(scope_, BLOCK_SCOPE); | 1234 Scope* scope = NewScope(this->scope(), BLOCK_SCOPE); |
1234 BlockState block_state(&scope_, scope); | 1235 BlockState block_state(&scope_state_, scope); |
1235 scope_->SetLanguageMode( | 1236 this->scope()->SetLanguageMode( |
1236 static_cast<LanguageMode>(class_language_mode | STRICT)); | 1237 static_cast<LanguageMode>(class_language_mode | STRICT)); |
1237 // TODO(marja): Make PreParser use scope names too. | 1238 // TODO(marja): Make PreParser use scope names too. |
1238 // scope_->SetScopeName(name); | 1239 // this->scope()->SetScopeName(name); |
1239 | 1240 |
1240 bool has_extends = Check(Token::EXTENDS); | 1241 bool has_extends = Check(Token::EXTENDS); |
1241 if (has_extends) { | 1242 if (has_extends) { |
1242 ExpressionClassifier extends_classifier(this); | 1243 ExpressionClassifier extends_classifier(this); |
1243 ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); | 1244 ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); |
1244 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); | 1245 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); |
1245 ValidateExpression(&extends_classifier, CHECK_OK); | 1246 ValidateExpression(&extends_classifier, CHECK_OK); |
1246 if (classifier != nullptr) { | 1247 if (classifier != nullptr) { |
1247 classifier->Accumulate(&extends_classifier, | 1248 classifier->Accumulate(&extends_classifier, |
1248 ExpressionClassifier::ExpressionProductions); | 1249 ExpressionClassifier::ExpressionProductions); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 while (peek() != Token::RBRACE) { | 1306 while (peek() != Token::RBRACE) { |
1306 ParseStatementListItem(CHECK_OK); | 1307 ParseStatementListItem(CHECK_OK); |
1307 } | 1308 } |
1308 Expect(Token::RBRACE, CHECK_OK); | 1309 Expect(Token::RBRACE, CHECK_OK); |
1309 return PreParserExpression::Default(); | 1310 return PreParserExpression::Default(); |
1310 } | 1311 } |
1311 | 1312 |
1312 void PreParserTraits::ParseAsyncArrowSingleExpressionBody( | 1313 void PreParserTraits::ParseAsyncArrowSingleExpressionBody( |
1313 PreParserStatementList body, bool accept_IN, | 1314 PreParserStatementList body, bool accept_IN, |
1314 Type::ExpressionClassifier* classifier, int pos, bool* ok) { | 1315 Type::ExpressionClassifier* classifier, int pos, bool* ok) { |
1315 Scope* scope = pre_parser_->scope_; | 1316 Scope* scope = pre_parser_->scope(); |
1316 scope->ForceContextAllocation(); | 1317 scope->ForceContextAllocation(); |
1317 | 1318 |
1318 PreParserExpression return_value = pre_parser_->ParseAssignmentExpression( | 1319 PreParserExpression return_value = pre_parser_->ParseAssignmentExpression( |
1319 accept_IN, classifier, CHECK_OK_CUSTOM(Void)); | 1320 accept_IN, classifier, CHECK_OK_CUSTOM(Void)); |
1320 | 1321 |
1321 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 1322 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
1322 } | 1323 } |
1323 | 1324 |
1324 #undef CHECK_OK | 1325 #undef CHECK_OK |
1325 #undef CHECK_OK_CUSTOM | 1326 #undef CHECK_OK_CUSTOM |
1326 | 1327 |
1327 | 1328 |
1328 } // namespace internal | 1329 } // namespace internal |
1329 } // namespace v8 | 1330 } // namespace v8 |
OLD | NEW |