| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // it is used) are generally omitted. | 156 // it is used) are generally omitted. |
| 157 | 157 |
| 158 | 158 |
| 159 #define CHECK_OK ok); \ | 159 #define CHECK_OK ok); \ |
| 160 if (!*ok) return kUnknownSourceElements; \ | 160 if (!*ok) return kUnknownSourceElements; \ |
| 161 ((void)0 | 161 ((void)0 |
| 162 #define DUMMY ) // to make indentation work | 162 #define DUMMY ) // to make indentation work |
| 163 #undef DUMMY | 163 #undef DUMMY |
| 164 | 164 |
| 165 | 165 |
| 166 PreParser::Statement PreParser::ParseSourceElement(bool* ok) { | 166 PreParser::Statement PreParser::ParseStatementListItem(bool* ok) { |
| 167 // ECMA 262 6th Edition | 167 // ECMA 262 6th Edition |
| 168 // StatementListItem[Yield, Return] : | 168 // StatementListItem[Yield, Return] : |
| 169 // Statement[?Yield, ?Return] | 169 // Statement[?Yield, ?Return] |
| 170 // Declaration[?Yield] | 170 // Declaration[?Yield] |
| 171 // | 171 // |
| 172 // Declaration[Yield] : | 172 // Declaration[Yield] : |
| 173 // HoistableDeclaration[?Yield] | 173 // HoistableDeclaration[?Yield] |
| 174 // ClassDeclaration[?Yield] | 174 // ClassDeclaration[?Yield] |
| 175 // LexicalDeclaration[In, ?Yield] | 175 // LexicalDeclaration[In, ?Yield] |
| 176 // | 176 // |
| (...skipping 16 matching lines...) Expand all Loading... |
| 193 if (is_strict(language_mode())) { | 193 if (is_strict(language_mode())) { |
| 194 return ParseVariableStatement(kSourceElement, ok); | 194 return ParseVariableStatement(kSourceElement, ok); |
| 195 } | 195 } |
| 196 // Fall through. | 196 // Fall through. |
| 197 default: | 197 default: |
| 198 return ParseStatement(ok); | 198 return ParseStatement(ok); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 | 202 |
| 203 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, | 203 PreParser::SourceElements PreParser::ParseStatementList(int end_token, |
| 204 bool* ok) { | 204 bool* ok) { |
| 205 // SourceElements :: | 205 // SourceElements :: |
| 206 // (Statement)* <end_token> | 206 // (Statement)* <end_token> |
| 207 | 207 |
| 208 bool directive_prologue = true; | 208 bool directive_prologue = true; |
| 209 while (peek() != end_token) { | 209 while (peek() != end_token) { |
| 210 if (directive_prologue && peek() != Token::STRING) { | 210 if (directive_prologue && peek() != Token::STRING) { |
| 211 directive_prologue = false; | 211 directive_prologue = false; |
| 212 } | 212 } |
| 213 Statement statement = ParseSourceElement(CHECK_OK); | 213 Statement statement = ParseStatementListItem(CHECK_OK); |
| 214 if (directive_prologue) { | 214 if (directive_prologue) { |
| 215 if (statement.IsUseStrictLiteral()) { | 215 if (statement.IsUseStrictLiteral()) { |
| 216 scope_->SetLanguageMode( | 216 scope_->SetLanguageMode( |
| 217 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); | 217 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
| 218 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) { | 218 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) { |
| 219 scope_->SetLanguageMode(static_cast<LanguageMode>( | 219 scope_->SetLanguageMode(static_cast<LanguageMode>( |
| 220 scope_->language_mode() | STRICT_BIT | STRONG_BIT)); | 220 scope_->language_mode() | STRICT_BIT | STRONG_BIT)); |
| 221 } else if (!statement.IsStringLiteral()) { | 221 } else if (!statement.IsStringLiteral()) { |
| 222 directive_prologue = false; | 222 directive_prologue = false; |
| 223 } | 223 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 380 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
| 381 // Block :: | 381 // Block :: |
| 382 // '{' Statement* '}' | 382 // '{' Statement* '}' |
| 383 | 383 |
| 384 // Note that a Block does not introduce a new execution scope! | 384 // Note that a Block does not introduce a new execution scope! |
| 385 // (ECMA-262, 3rd, 12.2) | 385 // (ECMA-262, 3rd, 12.2) |
| 386 // | 386 // |
| 387 Expect(Token::LBRACE, CHECK_OK); | 387 Expect(Token::LBRACE, CHECK_OK); |
| 388 while (peek() != Token::RBRACE) { | 388 while (peek() != Token::RBRACE) { |
| 389 if (allow_harmony_scoping() && is_strict(language_mode())) { | 389 if (allow_harmony_scoping() && is_strict(language_mode())) { |
| 390 ParseSourceElement(CHECK_OK); | 390 ParseStatementListItem(CHECK_OK); |
| 391 } else { | 391 } else { |
| 392 ParseStatement(CHECK_OK); | 392 ParseStatement(CHECK_OK); |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 Expect(Token::RBRACE, ok); | 395 Expect(Token::RBRACE, ok); |
| 396 return Statement::Default(); | 396 return Statement::Default(); |
| 397 } | 397 } |
| 398 | 398 |
| 399 | 399 |
| 400 PreParser::Statement PreParser::ParseVariableStatement( | 400 PreParser::Statement PreParser::ParseVariableStatement( |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 // See Parser::ParseFunctionLiteral for more information about lazy parsing | 925 // See Parser::ParseFunctionLiteral for more information about lazy parsing |
| 926 // and lazy compilation. | 926 // and lazy compilation. |
| 927 bool is_lazily_parsed = (outer_scope_type == SCRIPT_SCOPE && allow_lazy() && | 927 bool is_lazily_parsed = (outer_scope_type == SCRIPT_SCOPE && allow_lazy() && |
| 928 !parenthesized_function_); | 928 !parenthesized_function_); |
| 929 parenthesized_function_ = false; | 929 parenthesized_function_ = false; |
| 930 | 930 |
| 931 Expect(Token::LBRACE, CHECK_OK); | 931 Expect(Token::LBRACE, CHECK_OK); |
| 932 if (is_lazily_parsed) { | 932 if (is_lazily_parsed) { |
| 933 ParseLazyFunctionLiteralBody(CHECK_OK); | 933 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 934 } else { | 934 } else { |
| 935 ParseSourceElements(Token::RBRACE, ok); | 935 ParseStatementList(Token::RBRACE, ok); |
| 936 } | 936 } |
| 937 Expect(Token::RBRACE, CHECK_OK); | 937 Expect(Token::RBRACE, CHECK_OK); |
| 938 | 938 |
| 939 // Validate name and parameter names. We can do this only after parsing the | 939 // Validate name and parameter names. We can do this only after parsing the |
| 940 // function, since the function can declare itself strict. | 940 // function, since the function can declare itself strict. |
| 941 CheckFunctionName(language_mode(), kind, function_name, | 941 CheckFunctionName(language_mode(), kind, function_name, |
| 942 name_is_strict_reserved, function_name_location, CHECK_OK); | 942 name_is_strict_reserved, function_name_location, CHECK_OK); |
| 943 const bool use_strict_params = is_rest || IsConciseMethod(kind); | 943 const bool use_strict_params = is_rest || IsConciseMethod(kind); |
| 944 CheckFunctionParameterNames(language_mode(), use_strict_params, | 944 CheckFunctionParameterNames(language_mode(), use_strict_params, |
| 945 eval_args_error_loc, dupe_error_loc, | 945 eval_args_error_loc, dupe_error_loc, |
| 946 reserved_error_loc, CHECK_OK); | 946 reserved_error_loc, CHECK_OK); |
| 947 | 947 |
| 948 if (is_strict(language_mode())) { | 948 if (is_strict(language_mode())) { |
| 949 int end_position = scanner()->location().end_pos; | 949 int end_position = scanner()->location().end_pos; |
| 950 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 950 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
| 951 } | 951 } |
| 952 | 952 |
| 953 return Expression::Default(); | 953 return Expression::Default(); |
| 954 } | 954 } |
| 955 | 955 |
| 956 | 956 |
| 957 void PreParser::ParseLazyFunctionLiteralBody(bool* ok) { | 957 void PreParser::ParseLazyFunctionLiteralBody(bool* ok) { |
| 958 int body_start = position(); | 958 int body_start = position(); |
| 959 ParseSourceElements(Token::RBRACE, ok); | 959 ParseStatementList(Token::RBRACE, ok); |
| 960 if (!*ok) return; | 960 if (!*ok) return; |
| 961 | 961 |
| 962 // Position right after terminal '}'. | 962 // Position right after terminal '}'. |
| 963 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 963 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| 964 int body_end = scanner()->peek_location().end_pos; | 964 int body_end = scanner()->peek_location().end_pos; |
| 965 log_->LogFunction( | 965 log_->LogFunction( |
| 966 body_start, body_end, function_state_->materialized_literal_count(), | 966 body_start, body_end, function_state_->materialized_literal_count(), |
| 967 function_state_->expected_property_count(), language_mode()); | 967 function_state_->expected_property_count(), language_mode()); |
| 968 } | 968 } |
| 969 | 969 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 1026 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
| 1027 ParseArguments(ok); | 1027 ParseArguments(ok); |
| 1028 | 1028 |
| 1029 return Expression::Default(); | 1029 return Expression::Default(); |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 #undef CHECK_OK | 1032 #undef CHECK_OK |
| 1033 | 1033 |
| 1034 | 1034 |
| 1035 } } // v8::internal | 1035 } } // v8::internal |
| OLD | NEW |