| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 | 103 |
| 104 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 104 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 105 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, | 105 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, |
| 106 bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark, | 106 bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark, |
| 107 int* use_counts) { | 107 int* use_counts) { |
| 108 parsing_module_ = parsing_module; | 108 parsing_module_ = parsing_module; |
| 109 log_ = log; | 109 log_ = log; |
| 110 use_counts_ = use_counts; | 110 use_counts_ = use_counts; |
| 111 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 111 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
| 112 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); | 112 DCHECK_NULL(state_); |
| 113 PreParserFactory top_factory(NULL); | 113 Scope* top_scope = NewScope(nullptr, SCRIPT_SCOPE); |
| 114 FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction, | 114 PreParserFactory top_factory(nullptr); |
| 115 FunctionState top_state(&function_state_, &state_, top_scope, kNormalFunction, |
| 115 &top_factory); | 116 &top_factory); |
| 116 scope_->SetLanguageMode(language_mode); | 117 scope()->SetLanguageMode(language_mode); |
| 117 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); | 118 Scope* function_scope = NewScope(scope(), FUNCTION_SCOPE, kind); |
| 118 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); | 119 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); |
| 119 PreParserFactory function_factory(NULL); | 120 PreParserFactory function_factory(nullptr); |
| 120 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 121 FunctionState function_state(&function_state_, &state_, function_scope, kind, |
| 121 &function_factory); | 122 &function_factory); |
| 122 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 123 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
| 123 bool ok = true; | 124 bool ok = true; |
| 124 int start_position = peek_position(); | 125 int start_position = peek_position(); |
| 125 ParseLazyFunctionLiteralBody(&ok, bookmark); | 126 ParseLazyFunctionLiteralBody(&ok, bookmark); |
| 126 use_counts_ = nullptr; | 127 use_counts_ = nullptr; |
| 127 if (bookmark && bookmark->HasBeenReset()) { | 128 if (bookmark && bookmark->HasBeenReset()) { |
| 128 // Do nothing, as we've just aborted scanning this function. | 129 // Do nothing, as we've just aborted scanning this function. |
| 129 } else if (stack_overflow()) { | 130 } else if (stack_overflow()) { |
| 130 return kPreParseStackOverflow; | 131 return kPreParseStackOverflow; |
| 131 } else if (!ok) { | 132 } else if (!ok) { |
| 132 ReportUnexpectedToken(scanner()->current_token()); | 133 ReportUnexpectedToken(scanner()->current_token()); |
| 133 } else { | 134 } else { |
| 134 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 135 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| 135 if (is_strict(scope_->language_mode())) { | 136 if (is_strict(scope()->language_mode())) { |
| 136 int end_pos = scanner()->location().end_pos; | 137 int end_pos = scanner()->location().end_pos; |
| 137 CheckStrictOctalLiteral(start_position, end_pos, &ok); | 138 CheckStrictOctalLiteral(start_position, end_pos, &ok); |
| 138 CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos); | 139 CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos); |
| 139 if (!ok) return kPreParseSuccess; | 140 if (!ok) return kPreParseSuccess; |
| 140 } | 141 } |
| 141 } | 142 } |
| 142 return kPreParseSuccess; | 143 return kPreParseSuccess; |
| 143 } | 144 } |
| 144 | 145 |
| 145 PreParserExpression PreParserTraits::ParseClassLiteral( | 146 PreParserExpression PreParserTraits::ParseClassLiteral( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 227 } |
| 227 bool starts_with_identifier = peek() == Token::IDENTIFIER; | 228 bool starts_with_identifier = peek() == Token::IDENTIFIER; |
| 228 Scanner::Location token_loc = scanner()->peek_location(); | 229 Scanner::Location token_loc = scanner()->peek_location(); |
| 229 Statement statement = ParseStatementListItem(ok); | 230 Statement statement = ParseStatementListItem(ok); |
| 230 if (!*ok) return; | 231 if (!*ok) return; |
| 231 | 232 |
| 232 if (directive_prologue) { | 233 if (directive_prologue) { |
| 233 bool use_strict_found = statement.IsUseStrictLiteral(); | 234 bool use_strict_found = statement.IsUseStrictLiteral(); |
| 234 | 235 |
| 235 if (use_strict_found) { | 236 if (use_strict_found) { |
| 236 scope_->SetLanguageMode( | 237 scope()->SetLanguageMode( |
| 237 static_cast<LanguageMode>(scope_->language_mode() | STRICT)); | 238 static_cast<LanguageMode>(scope()->language_mode() | STRICT)); |
| 238 } else if (!statement.IsStringLiteral()) { | 239 } else if (!statement.IsStringLiteral()) { |
| 239 directive_prologue = false; | 240 directive_prologue = false; |
| 240 } | 241 } |
| 241 | 242 |
| 242 if (use_strict_found && !scope_->HasSimpleParameters()) { | 243 if (use_strict_found && !scope()->HasSimpleParameters()) { |
| 243 // TC39 deemed "use strict" directives to be an error when occurring | 244 // TC39 deemed "use strict" directives to be an error when occurring |
| 244 // in the body of a function with non-simple parameter list, on | 245 // in the body of a function with non-simple parameter list, on |
| 245 // 29/7/2015. https://goo.gl/ueA7Ln | 246 // 29/7/2015. https://goo.gl/ueA7Ln |
| 246 PreParserTraits::ReportMessageAt( | 247 PreParserTraits::ReportMessageAt( |
| 247 token_loc, MessageTemplate::kIllegalLanguageModeDirective, | 248 token_loc, MessageTemplate::kIllegalLanguageModeDirective, |
| 248 "use strict"); | 249 "use strict"); |
| 249 *ok = false; | 250 *ok = false; |
| 250 return; | 251 return; |
| 251 } | 252 } |
| 252 } | 253 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return Statement::Default(); | 286 return Statement::Default(); |
| 286 } | 287 } |
| 287 return ParseSubStatement(allow_function, ok); | 288 return ParseSubStatement(allow_function, ok); |
| 288 } | 289 } |
| 289 | 290 |
| 290 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { | 291 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { |
| 291 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 292 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
| 292 (legacy && allow_harmony_restrictive_declarations())) { | 293 (legacy && allow_harmony_restrictive_declarations())) { |
| 293 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); | 294 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); |
| 294 } else { | 295 } else { |
| 295 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); | 296 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE); |
| 296 BlockState block_state(&scope_, body_scope); | 297 BlockState block_state(&state_, body_scope); |
| 297 return ParseFunctionDeclaration(ok); | 298 return ParseFunctionDeclaration(ok); |
| 298 } | 299 } |
| 299 } | 300 } |
| 300 | 301 |
| 301 PreParser::Statement PreParser::ParseSubStatement( | 302 PreParser::Statement PreParser::ParseSubStatement( |
| 302 AllowLabelledFunctionStatement allow_function, bool* ok) { | 303 AllowLabelledFunctionStatement allow_function, bool* ok) { |
| 303 // Statement :: | 304 // Statement :: |
| 304 // Block | 305 // Block |
| 305 // VariableStatement | 306 // VariableStatement |
| 306 // EmptyStatement | 307 // EmptyStatement |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 ParseClassLiteral(nullptr, name, scanner()->location(), is_strict_reserved, | 457 ParseClassLiteral(nullptr, name, scanner()->location(), is_strict_reserved, |
| 457 pos, CHECK_OK); | 458 pos, CHECK_OK); |
| 458 return Statement::Default(); | 459 return Statement::Default(); |
| 459 } | 460 } |
| 460 | 461 |
| 461 | 462 |
| 462 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 463 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
| 463 // Block :: | 464 // Block :: |
| 464 // '{' StatementList '}' | 465 // '{' StatementList '}' |
| 465 | 466 |
| 466 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 467 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE); |
| 467 Expect(Token::LBRACE, CHECK_OK); | 468 Expect(Token::LBRACE, CHECK_OK); |
| 468 Statement final = Statement::Default(); | 469 Statement final = Statement::Default(); |
| 469 { | 470 { |
| 470 BlockState block_state(&scope_, block_scope); | 471 BlockState block_state(&state_, block_scope); |
| 471 while (peek() != Token::RBRACE) { | 472 while (peek() != Token::RBRACE) { |
| 472 final = ParseStatementListItem(CHECK_OK); | 473 final = ParseStatementListItem(CHECK_OK); |
| 473 } | 474 } |
| 474 } | 475 } |
| 475 Expect(Token::RBRACE, ok); | 476 Expect(Token::RBRACE, ok); |
| 476 return final; | 477 return final; |
| 477 } | 478 } |
| 478 | 479 |
| 479 | 480 |
| 480 PreParser::Statement PreParser::ParseVariableStatement( | 481 PreParser::Statement PreParser::ParseVariableStatement( |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 Expect(Token::WITH, CHECK_OK); | 771 Expect(Token::WITH, CHECK_OK); |
| 771 if (is_strict(language_mode())) { | 772 if (is_strict(language_mode())) { |
| 772 ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith); | 773 ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith); |
| 773 *ok = false; | 774 *ok = false; |
| 774 return Statement::Default(); | 775 return Statement::Default(); |
| 775 } | 776 } |
| 776 Expect(Token::LPAREN, CHECK_OK); | 777 Expect(Token::LPAREN, CHECK_OK); |
| 777 ParseExpression(true, CHECK_OK); | 778 ParseExpression(true, CHECK_OK); |
| 778 Expect(Token::RPAREN, CHECK_OK); | 779 Expect(Token::RPAREN, CHECK_OK); |
| 779 | 780 |
| 780 Scope* with_scope = NewScope(scope_, WITH_SCOPE); | 781 Scope* with_scope = NewScope(scope(), WITH_SCOPE); |
| 781 BlockState block_state(&scope_, with_scope); | 782 BlockState block_state(&state_, with_scope); |
| 782 ParseScopedStatement(true, CHECK_OK); | 783 ParseScopedStatement(true, CHECK_OK); |
| 783 return Statement::Default(); | 784 return Statement::Default(); |
| 784 } | 785 } |
| 785 | 786 |
| 786 | 787 |
| 787 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { | 788 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { |
| 788 // SwitchStatement :: | 789 // SwitchStatement :: |
| 789 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 790 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
| 790 | 791 |
| 791 Expect(Token::SWITCH, CHECK_OK); | 792 Expect(Token::SWITCH, CHECK_OK); |
| 792 Expect(Token::LPAREN, CHECK_OK); | 793 Expect(Token::LPAREN, CHECK_OK); |
| 793 ParseExpression(true, CHECK_OK); | 794 ParseExpression(true, CHECK_OK); |
| 794 Expect(Token::RPAREN, CHECK_OK); | 795 Expect(Token::RPAREN, CHECK_OK); |
| 795 | 796 |
| 796 Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); | 797 Scope* cases_scope = NewScope(scope(), BLOCK_SCOPE); |
| 797 { | 798 { |
| 798 BlockState cases_block_state(&scope_, cases_scope); | 799 BlockState cases_block_state(&state_, cases_scope); |
| 799 Expect(Token::LBRACE, CHECK_OK); | 800 Expect(Token::LBRACE, CHECK_OK); |
| 800 Token::Value token = peek(); | 801 Token::Value token = peek(); |
| 801 while (token != Token::RBRACE) { | 802 while (token != Token::RBRACE) { |
| 802 if (token == Token::CASE) { | 803 if (token == Token::CASE) { |
| 803 Expect(Token::CASE, CHECK_OK); | 804 Expect(Token::CASE, CHECK_OK); |
| 804 ParseExpression(true, CHECK_OK); | 805 ParseExpression(true, CHECK_OK); |
| 805 } else { | 806 } else { |
| 806 Expect(Token::DEFAULT, CHECK_OK); | 807 Expect(Token::DEFAULT, CHECK_OK); |
| 807 } | 808 } |
| 808 Expect(Token::COLON, CHECK_OK); | 809 Expect(Token::COLON, CHECK_OK); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 ParseScopedStatement(true, ok); | 848 ParseScopedStatement(true, ok); |
| 848 return Statement::Default(); | 849 return Statement::Default(); |
| 849 } | 850 } |
| 850 | 851 |
| 851 | 852 |
| 852 PreParser::Statement PreParser::ParseForStatement(bool* ok) { | 853 PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
| 853 // ForStatement :: | 854 // ForStatement :: |
| 854 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 855 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
| 855 | 856 |
| 856 // Create an in-between scope for let-bound iteration variables. | 857 // Create an in-between scope for let-bound iteration variables. |
| 857 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); | 858 Scope* for_scope = NewScope(scope(), BLOCK_SCOPE); |
| 858 bool has_lexical = false; | 859 bool has_lexical = false; |
| 859 | 860 |
| 860 BlockState block_state(&scope_, for_scope); | 861 BlockState block_state(&state_, for_scope); |
| 861 Expect(Token::FOR, CHECK_OK); | 862 Expect(Token::FOR, CHECK_OK); |
| 862 Expect(Token::LPAREN, CHECK_OK); | 863 Expect(Token::LPAREN, CHECK_OK); |
| 863 if (peek() != Token::SEMICOLON) { | 864 if (peek() != Token::SEMICOLON) { |
| 864 ForEachStatement::VisitMode mode; | 865 ForEachStatement::VisitMode mode; |
| 865 if (peek() == Token::VAR || peek() == Token::CONST || | 866 if (peek() == Token::VAR || peek() == Token::CONST || |
| 866 (peek() == Token::LET && IsNextLetKeyword())) { | 867 (peek() == Token::LET && IsNextLetKeyword())) { |
| 867 int decl_count; | 868 int decl_count; |
| 868 bool is_lexical; | 869 bool is_lexical; |
| 869 bool is_binding_pattern; | 870 bool is_binding_pattern; |
| 870 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); | 871 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 | 939 |
| 939 if (mode == ForEachStatement::ITERATE) { | 940 if (mode == ForEachStatement::ITERATE) { |
| 940 ExpressionClassifier classifier(this); | 941 ExpressionClassifier classifier(this); |
| 941 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 942 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 942 RewriteNonPattern(&classifier, CHECK_OK); | 943 RewriteNonPattern(&classifier, CHECK_OK); |
| 943 } else { | 944 } else { |
| 944 ParseExpression(true, CHECK_OK); | 945 ParseExpression(true, CHECK_OK); |
| 945 } | 946 } |
| 946 | 947 |
| 947 Expect(Token::RPAREN, CHECK_OK); | 948 Expect(Token::RPAREN, CHECK_OK); |
| 948 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); | 949 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE); |
| 949 { | 950 { |
| 950 BlockState block_state(&scope_, body_scope); | 951 BlockState block_state(&state_, body_scope); |
| 951 ParseScopedStatement(true, CHECK_OK); | 952 ParseScopedStatement(true, CHECK_OK); |
| 952 } | 953 } |
| 953 return Statement::Default(); | 954 return Statement::Default(); |
| 954 } | 955 } |
| 955 } | 956 } |
| 956 } | 957 } |
| 957 | 958 |
| 958 // Parsed initializer at this point. | 959 // Parsed initializer at this point. |
| 959 Expect(Token::SEMICOLON, CHECK_OK); | 960 Expect(Token::SEMICOLON, CHECK_OK); |
| 960 | 961 |
| 961 // If there are let bindings, then condition and the next statement of the | 962 // If there are let bindings, then condition and the next statement of the |
| 962 // for loop must be parsed in a new scope. | 963 // for loop must be parsed in a new scope. |
| 963 Scope* inner_scope = scope_; | 964 Scope* inner_scope = scope(); |
| 964 if (has_lexical) inner_scope = NewScope(for_scope, BLOCK_SCOPE); | 965 if (has_lexical) inner_scope = NewScope(for_scope, BLOCK_SCOPE); |
| 965 | 966 |
| 966 { | 967 { |
| 967 BlockState block_state(&scope_, inner_scope); | 968 BlockState block_state(&state_, inner_scope); |
| 968 | 969 |
| 969 if (peek() != Token::SEMICOLON) { | 970 if (peek() != Token::SEMICOLON) { |
| 970 ParseExpression(true, CHECK_OK); | 971 ParseExpression(true, CHECK_OK); |
| 971 } | 972 } |
| 972 Expect(Token::SEMICOLON, CHECK_OK); | 973 Expect(Token::SEMICOLON, CHECK_OK); |
| 973 | 974 |
| 974 if (peek() != Token::RPAREN) { | 975 if (peek() != Token::RPAREN) { |
| 975 ParseExpression(true, CHECK_OK); | 976 ParseExpression(true, CHECK_OK); |
| 976 } | 977 } |
| 977 Expect(Token::RPAREN, CHECK_OK); | 978 Expect(Token::RPAREN, CHECK_OK); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 if (tok != Token::CATCH && tok != Token::FINALLY) { | 1023 if (tok != Token::CATCH && tok != Token::FINALLY) { |
| 1023 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally); | 1024 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally); |
| 1024 *ok = false; | 1025 *ok = false; |
| 1025 return Statement::Default(); | 1026 return Statement::Default(); |
| 1026 } | 1027 } |
| 1027 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); | 1028 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); |
| 1028 bool catch_block_exists = false; | 1029 bool catch_block_exists = false; |
| 1029 if (tok == Token::CATCH) { | 1030 if (tok == Token::CATCH) { |
| 1030 Consume(Token::CATCH); | 1031 Consume(Token::CATCH); |
| 1031 Expect(Token::LPAREN, CHECK_OK); | 1032 Expect(Token::LPAREN, CHECK_OK); |
| 1032 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); | 1033 Scope* catch_scope = NewScope(scope(), CATCH_SCOPE); |
| 1033 ExpressionClassifier pattern_classifier(this); | 1034 ExpressionClassifier pattern_classifier(this); |
| 1034 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | 1035 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
| 1035 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | 1036 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
| 1036 Expect(Token::RPAREN, CHECK_OK); | 1037 Expect(Token::RPAREN, CHECK_OK); |
| 1037 { | 1038 { |
| 1038 CollectExpressionsInTailPositionToListScope | 1039 CollectExpressionsInTailPositionToListScope |
| 1039 collect_tail_call_expressions_scope( | 1040 collect_tail_call_expressions_scope( |
| 1040 function_state_, &tail_call_expressions_in_catch_block); | 1041 function_state_, &tail_call_expressions_in_catch_block); |
| 1041 BlockState block_state(&scope_, catch_scope); | 1042 BlockState block_state(&state_, catch_scope); |
| 1042 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 1043 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE); |
| 1043 { | 1044 { |
| 1044 BlockState block_state(&scope_, block_scope); | 1045 BlockState block_state(&state_, block_scope); |
| 1045 ParseBlock(CHECK_OK); | 1046 ParseBlock(CHECK_OK); |
| 1046 } | 1047 } |
| 1047 } | 1048 } |
| 1048 catch_block_exists = true; | 1049 catch_block_exists = true; |
| 1049 tok = peek(); | 1050 tok = peek(); |
| 1050 } | 1051 } |
| 1051 if (tok == Token::FINALLY) { | 1052 if (tok == Token::FINALLY) { |
| 1052 Consume(Token::FINALLY); | 1053 Consume(Token::FINALLY); |
| 1053 ParseBlock(CHECK_OK); | 1054 ParseBlock(CHECK_OK); |
| 1054 if (FLAG_harmony_explicit_tailcalls && catch_block_exists && | 1055 if (FLAG_harmony_explicit_tailcalls && catch_block_exists && |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 | 1089 |
| 1089 PreParser::Expression PreParser::ParseFunctionLiteral( | 1090 PreParser::Expression PreParser::ParseFunctionLiteral( |
| 1090 Identifier function_name, Scanner::Location function_name_location, | 1091 Identifier function_name, Scanner::Location function_name_location, |
| 1091 FunctionNameValidity function_name_validity, FunctionKind kind, | 1092 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 1092 int function_token_pos, FunctionLiteral::FunctionType function_type, | 1093 int function_token_pos, FunctionLiteral::FunctionType function_type, |
| 1093 LanguageMode language_mode, bool* ok) { | 1094 LanguageMode language_mode, bool* ok) { |
| 1094 // Function :: | 1095 // Function :: |
| 1095 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 1096 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 1096 | 1097 |
| 1097 // Parse function body. | 1098 // Parse function body. |
| 1098 bool outer_is_script_scope = scope_->is_script_scope(); | 1099 bool outer_is_script_scope = scope()->is_script_scope(); |
| 1099 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); | 1100 Scope* function_scope = NewScope(scope(), FUNCTION_SCOPE, kind); |
| 1100 function_scope->SetLanguageMode(language_mode); | 1101 function_scope->SetLanguageMode(language_mode); |
| 1101 PreParserFactory factory(NULL); | 1102 PreParserFactory factory(NULL); |
| 1102 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 1103 FunctionState function_state(&function_state_, &state_, function_scope, kind, |
| 1103 &factory); | 1104 &factory); |
| 1104 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 1105 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
| 1105 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 1106 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
| 1106 | 1107 |
| 1107 Expect(Token::LPAREN, CHECK_OK); | 1108 Expect(Token::LPAREN, CHECK_OK); |
| 1108 int start_position = scanner()->location().beg_pos; | 1109 int start_position = scanner()->location().beg_pos; |
| 1109 function_scope->set_start_position(start_position); | 1110 function_scope->set_start_position(start_position); |
| 1110 PreParserFormalParameters formals(function_scope); | 1111 PreParserFormalParameters formals(function_scope); |
| 1111 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); | 1112 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); |
| 1112 Expect(Token::RPAREN, CHECK_OK); | 1113 Expect(Token::RPAREN, CHECK_OK); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 ParseStatementList(Token::RBRACE, ok, bookmark); | 1189 ParseStatementList(Token::RBRACE, ok, bookmark); |
| 1189 if (!*ok) return; | 1190 if (!*ok) return; |
| 1190 if (bookmark && bookmark->HasBeenReset()) return; | 1191 if (bookmark && bookmark->HasBeenReset()) return; |
| 1191 | 1192 |
| 1192 // Position right after terminal '}'. | 1193 // Position right after terminal '}'. |
| 1193 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 1194 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| 1194 int body_end = scanner()->peek_location().end_pos; | 1195 int body_end = scanner()->peek_location().end_pos; |
| 1195 log_->LogFunction(body_start, body_end, | 1196 log_->LogFunction(body_start, body_end, |
| 1196 function_state_->materialized_literal_count(), | 1197 function_state_->materialized_literal_count(), |
| 1197 function_state_->expected_property_count(), language_mode(), | 1198 function_state_->expected_property_count(), language_mode(), |
| 1198 scope_->uses_super_property(), scope_->calls_eval()); | 1199 scope()->uses_super_property(), scope()->calls_eval()); |
| 1199 } | 1200 } |
| 1200 | 1201 |
| 1201 PreParserExpression PreParser::ParseClassLiteral( | 1202 PreParserExpression PreParser::ParseClassLiteral( |
| 1202 ExpressionClassifier* classifier, PreParserIdentifier name, | 1203 ExpressionClassifier* classifier, PreParserIdentifier name, |
| 1203 Scanner::Location class_name_location, bool name_is_strict_reserved, | 1204 Scanner::Location class_name_location, bool name_is_strict_reserved, |
| 1204 int pos, bool* ok) { | 1205 int pos, bool* ok) { |
| 1205 // All parts of a ClassDeclaration and ClassExpression are strict code. | 1206 // All parts of a ClassDeclaration and ClassExpression are strict code. |
| 1206 if (name_is_strict_reserved) { | 1207 if (name_is_strict_reserved) { |
| 1207 ReportMessageAt(class_name_location, | 1208 ReportMessageAt(class_name_location, |
| 1208 MessageTemplate::kUnexpectedStrictReserved); | 1209 MessageTemplate::kUnexpectedStrictReserved); |
| 1209 *ok = false; | 1210 *ok = false; |
| 1210 return EmptyExpression(); | 1211 return EmptyExpression(); |
| 1211 } | 1212 } |
| 1212 if (IsEvalOrArguments(name)) { | 1213 if (IsEvalOrArguments(name)) { |
| 1213 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); | 1214 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
| 1214 *ok = false; | 1215 *ok = false; |
| 1215 return EmptyExpression(); | 1216 return EmptyExpression(); |
| 1216 } | 1217 } |
| 1217 | 1218 |
| 1218 LanguageMode class_language_mode = language_mode(); | 1219 LanguageMode class_language_mode = language_mode(); |
| 1219 Scope* scope = NewScope(scope_, BLOCK_SCOPE); | 1220 Scope* scope = NewScope(this->scope(), BLOCK_SCOPE); |
| 1220 BlockState block_state(&scope_, scope); | 1221 BlockState block_state(&state_, scope); |
| 1221 scope_->SetLanguageMode( | 1222 this->scope()->SetLanguageMode( |
| 1222 static_cast<LanguageMode>(class_language_mode | STRICT)); | 1223 static_cast<LanguageMode>(class_language_mode | STRICT)); |
| 1223 // TODO(marja): Make PreParser use scope names too. | 1224 // TODO(marja): Make PreParser use scope names too. |
| 1224 // scope_->SetScopeName(name); | 1225 // this->scope()->SetScopeName(name); |
| 1225 | 1226 |
| 1226 bool has_extends = Check(Token::EXTENDS); | 1227 bool has_extends = Check(Token::EXTENDS); |
| 1227 if (has_extends) { | 1228 if (has_extends) { |
| 1228 ExpressionClassifier extends_classifier(this); | 1229 ExpressionClassifier extends_classifier(this); |
| 1229 ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); | 1230 ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); |
| 1230 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); | 1231 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); |
| 1231 ValidateExpression(&extends_classifier, CHECK_OK); | 1232 ValidateExpression(&extends_classifier, CHECK_OK); |
| 1232 if (classifier != nullptr) { | 1233 if (classifier != nullptr) { |
| 1233 classifier->Accumulate(&extends_classifier, | 1234 classifier->Accumulate(&extends_classifier, |
| 1234 ExpressionClassifier::ExpressionProductions); | 1235 ExpressionClassifier::ExpressionProductions); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 while (peek() != Token::RBRACE) { | 1292 while (peek() != Token::RBRACE) { |
| 1292 ParseStatementListItem(CHECK_OK); | 1293 ParseStatementListItem(CHECK_OK); |
| 1293 } | 1294 } |
| 1294 Expect(Token::RBRACE, CHECK_OK); | 1295 Expect(Token::RBRACE, CHECK_OK); |
| 1295 return PreParserExpression::Default(); | 1296 return PreParserExpression::Default(); |
| 1296 } | 1297 } |
| 1297 | 1298 |
| 1298 void PreParserTraits::ParseAsyncArrowSingleExpressionBody( | 1299 void PreParserTraits::ParseAsyncArrowSingleExpressionBody( |
| 1299 PreParserStatementList body, bool accept_IN, | 1300 PreParserStatementList body, bool accept_IN, |
| 1300 Type::ExpressionClassifier* classifier, int pos, bool* ok) { | 1301 Type::ExpressionClassifier* classifier, int pos, bool* ok) { |
| 1301 Scope* scope = pre_parser_->scope_; | 1302 Scope* scope = pre_parser_->scope(); |
| 1302 scope->ForceContextAllocation(); | 1303 scope->ForceContextAllocation(); |
| 1303 | 1304 |
| 1304 PreParserExpression return_value = | 1305 PreParserExpression return_value = |
| 1305 pre_parser_->ParseAssignmentExpression(accept_IN, classifier, ok); | 1306 pre_parser_->ParseAssignmentExpression(accept_IN, classifier, ok); |
| 1306 if (!*ok) return; | 1307 if (!*ok) return; |
| 1307 | 1308 |
| 1308 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 1309 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
| 1309 } | 1310 } |
| 1310 | 1311 |
| 1311 #undef CHECK_OK | 1312 #undef CHECK_OK |
| 1312 | 1313 |
| 1313 | 1314 |
| 1314 } // namespace internal | 1315 } // namespace internal |
| 1315 } // namespace v8 | 1316 } // namespace v8 |
| OLD | NEW |