| 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 "include/v8stdint.h" | 7 #include "include/v8stdint.h" |
| 8 | 8 |
| 9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
| 10 #include "src/base/logging.h" | 10 #include "src/base/logging.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 return PreParserIdentifier::Let(); | 71 return PreParserIdentifier::Let(); |
| 72 } else if (scanner->current_token() == Token::YIELD) { | 72 } else if (scanner->current_token() == Token::YIELD) { |
| 73 return PreParserIdentifier::Yield(); | 73 return PreParserIdentifier::Yield(); |
| 74 } | 74 } |
| 75 if (scanner->UnescapedLiteralMatches("eval", 4)) { | 75 if (scanner->UnescapedLiteralMatches("eval", 4)) { |
| 76 return PreParserIdentifier::Eval(); | 76 return PreParserIdentifier::Eval(); |
| 77 } | 77 } |
| 78 if (scanner->UnescapedLiteralMatches("arguments", 9)) { | 78 if (scanner->UnescapedLiteralMatches("arguments", 9)) { |
| 79 return PreParserIdentifier::Arguments(); | 79 return PreParserIdentifier::Arguments(); |
| 80 } | 80 } |
| 81 if (scanner->UnescapedLiteralMatches("prototype", 9)) { |
| 82 return PreParserIdentifier::Prototype(); |
| 83 } |
| 84 if (scanner->UnescapedLiteralMatches("constructor", 11)) { |
| 85 return PreParserIdentifier::Constructor(); |
| 86 } |
| 81 return PreParserIdentifier::Default(); | 87 return PreParserIdentifier::Default(); |
| 82 } | 88 } |
| 83 | 89 |
| 84 | 90 |
| 85 PreParserIdentifier PreParserTraits::GetNumberAsSymbol(Scanner* scanner) { | 91 PreParserIdentifier PreParserTraits::GetNumberAsSymbol(Scanner* scanner) { |
| 86 return PreParserIdentifier::Default(); | 92 return PreParserIdentifier::Default(); |
| 87 } | 93 } |
| 88 | 94 |
| 89 | 95 |
| 90 PreParserExpression PreParserTraits::ExpressionFromString( | 96 PreParserExpression PreParserTraits::ExpressionFromString( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // | 177 // |
| 172 // In harmony mode we allow additionally the following productions | 178 // In harmony mode we allow additionally the following productions |
| 173 // SourceElement: | 179 // SourceElement: |
| 174 // LetDeclaration | 180 // LetDeclaration |
| 175 // ConstDeclaration | 181 // ConstDeclaration |
| 176 // GeneratorDeclaration | 182 // GeneratorDeclaration |
| 177 | 183 |
| 178 switch (peek()) { | 184 switch (peek()) { |
| 179 case Token::FUNCTION: | 185 case Token::FUNCTION: |
| 180 return ParseFunctionDeclaration(ok); | 186 return ParseFunctionDeclaration(ok); |
| 187 case Token::CLASS: |
| 188 return ParseClassDeclaration(ok); |
| 181 case Token::CONST: | 189 case Token::CONST: |
| 182 return ParseVariableStatement(kSourceElement, ok); | 190 return ParseVariableStatement(kSourceElement, ok); |
| 183 case Token::LET: | 191 case Token::LET: |
| 184 DCHECK(allow_harmony_scoping()); | 192 DCHECK(allow_harmony_scoping()); |
| 185 if (strict_mode() == STRICT) { | 193 if (strict_mode() == STRICT) { |
| 186 return ParseVariableStatement(kSourceElement, ok); | 194 return ParseVariableStatement(kSourceElement, ok); |
| 187 } | 195 } |
| 188 // Fall through. | 196 // Fall through. |
| 189 default: | 197 default: |
| 190 return ParseStatement(ok); | 198 return ParseStatement(ok); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 PreParserTraits::ReportMessageAt(start_location.beg_pos, | 306 PreParserTraits::ReportMessageAt(start_location.beg_pos, |
| 299 end_location.end_pos, | 307 end_location.end_pos, |
| 300 "strict_function"); | 308 "strict_function"); |
| 301 *ok = false; | 309 *ok = false; |
| 302 return Statement::Default(); | 310 return Statement::Default(); |
| 303 } else { | 311 } else { |
| 304 return statement; | 312 return statement; |
| 305 } | 313 } |
| 306 } | 314 } |
| 307 | 315 |
| 316 case Token::CLASS: |
| 317 return ParseClassDeclaration(CHECK_OK); |
| 318 |
| 308 case Token::DEBUGGER: | 319 case Token::DEBUGGER: |
| 309 return ParseDebuggerStatement(ok); | 320 return ParseDebuggerStatement(ok); |
| 310 | 321 |
| 311 case Token::VAR: | 322 case Token::VAR: |
| 312 case Token::CONST: | 323 case Token::CONST: |
| 313 return ParseVariableStatement(kStatement, ok); | 324 return ParseVariableStatement(kStatement, ok); |
| 314 | 325 |
| 315 case Token::LET: | 326 case Token::LET: |
| 316 DCHECK(allow_harmony_scoping()); | 327 DCHECK(allow_harmony_scoping()); |
| 317 if (strict_mode() == STRICT) { | 328 if (strict_mode() == STRICT) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 338 &is_strict_reserved, CHECK_OK); | 349 &is_strict_reserved, CHECK_OK); |
| 339 ParseFunctionLiteral(name, scanner()->location(), is_strict_reserved, | 350 ParseFunctionLiteral(name, scanner()->location(), is_strict_reserved, |
| 340 is_generator ? FunctionKind::kGeneratorFunction | 351 is_generator ? FunctionKind::kGeneratorFunction |
| 341 : FunctionKind::kNormalFunction, | 352 : FunctionKind::kNormalFunction, |
| 342 pos, FunctionLiteral::DECLARATION, | 353 pos, FunctionLiteral::DECLARATION, |
| 343 FunctionLiteral::NORMAL_ARITY, CHECK_OK); | 354 FunctionLiteral::NORMAL_ARITY, CHECK_OK); |
| 344 return Statement::FunctionDeclaration(); | 355 return Statement::FunctionDeclaration(); |
| 345 } | 356 } |
| 346 | 357 |
| 347 | 358 |
| 359 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { |
| 360 Expect(Token::CLASS, CHECK_OK); |
| 361 int pos = position(); |
| 362 bool is_strict_reserved = false; |
| 363 Identifier name = |
| 364 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 365 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, |
| 366 CHECK_OK); |
| 367 return Statement::ClassDeclaration(); |
| 368 } |
| 369 |
| 370 |
| 348 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 371 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
| 349 // Block :: | 372 // Block :: |
| 350 // '{' Statement* '}' | 373 // '{' Statement* '}' |
| 351 | 374 |
| 352 // Note that a Block does not introduce a new execution scope! | 375 // Note that a Block does not introduce a new execution scope! |
| 353 // (ECMA-262, 3rd, 12.2) | 376 // (ECMA-262, 3rd, 12.2) |
| 354 // | 377 // |
| 355 Expect(Token::LBRACE, CHECK_OK); | 378 Expect(Token::LBRACE, CHECK_OK); |
| 356 while (peek() != Token::RBRACE) { | 379 while (peek() != Token::RBRACE) { |
| 357 if (allow_harmony_scoping() && strict_mode() == STRICT) { | 380 if (allow_harmony_scoping() && strict_mode() == STRICT) { |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 951 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
| 929 ParseArguments(ok); | 952 ParseArguments(ok); |
| 930 | 953 |
| 931 return Expression::Default(); | 954 return Expression::Default(); |
| 932 } | 955 } |
| 933 | 956 |
| 934 #undef CHECK_OK | 957 #undef CHECK_OK |
| 935 | 958 |
| 936 | 959 |
| 937 } } // v8::internal | 960 } } // v8::internal |
| OLD | NEW |