| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 PreParser::Statement PreParser::ParseSourceElement(bool* ok) { | 119 PreParser::Statement PreParser::ParseSourceElement(bool* ok) { |
| 120 // (Ecma 262 5th Edition, clause 14): | 120 // (Ecma 262 5th Edition, clause 14): |
| 121 // SourceElement: | 121 // SourceElement: |
| 122 // Statement | 122 // Statement |
| 123 // FunctionDeclaration | 123 // FunctionDeclaration |
| 124 // | 124 // |
| 125 // In harmony mode we allow additionally the following productions | 125 // In harmony mode we allow additionally the following productions |
| 126 // SourceElement: | 126 // SourceElement: |
| 127 // LetDeclaration | 127 // LetDeclaration |
| 128 // ConstDeclaration |
| 128 | 129 |
| 129 switch (peek()) { | 130 switch (peek()) { |
| 130 case i::Token::FUNCTION: | 131 case i::Token::FUNCTION: |
| 131 return ParseFunctionDeclaration(ok); | 132 return ParseFunctionDeclaration(ok); |
| 132 case i::Token::LET: | 133 case i::Token::LET: |
| 133 return ParseVariableStatement(kSourceElement, ok); | 134 return ParseVariableStatement(kSourceElement, ok); |
| 135 case i::Token::CONST: |
| 136 if (harmony_scoping_) { |
| 137 return ParseHarmonyConstDeclaration(ok); |
| 138 } |
| 139 // FALLTHROUGH |
| 134 default: | 140 default: |
| 135 return ParseStatement(ok); | 141 return ParseStatement(ok); |
| 136 } | 142 } |
| 137 } | 143 } |
| 138 | 144 |
| 139 | 145 |
| 140 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, | 146 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, |
| 141 bool* ok) { | 147 bool* ok) { |
| 142 // SourceElements :: | 148 // SourceElements :: |
| 143 // (Statement)* <end_token> | 149 // (Statement)* <end_token> |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 VariableDeclarationContext var_context, | 334 VariableDeclarationContext var_context, |
| 329 VariableDeclarationProperties* decl_props, | 335 VariableDeclarationProperties* decl_props, |
| 330 int* num_decl, | 336 int* num_decl, |
| 331 bool* ok) { | 337 bool* ok) { |
| 332 // VariableDeclarations :: | 338 // VariableDeclarations :: |
| 333 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[','] | 339 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[','] |
| 334 | 340 |
| 335 if (peek() == i::Token::VAR) { | 341 if (peek() == i::Token::VAR) { |
| 336 Consume(i::Token::VAR); | 342 Consume(i::Token::VAR); |
| 337 } else if (peek() == i::Token::CONST) { | 343 } else if (peek() == i::Token::CONST) { |
| 344 if (harmony_scoping_) { |
| 345 ASSERT(var_context == kForStatement || |
| 346 var_context == kStatement); |
| 347 i::Scanner::Location location = scanner_->peek_location(); |
| 348 ReportMessageAt(location.beg_pos, location.end_pos, |
| 349 "unprotected_const", NULL); |
| 350 *ok = false; |
| 351 return Statement::Default(); |
| 352 } |
| 338 if (strict_mode()) { | 353 if (strict_mode()) { |
| 339 i::Scanner::Location location = scanner_->peek_location(); | 354 i::Scanner::Location location = scanner_->peek_location(); |
| 340 ReportMessageAt(location, "strict_const", NULL); | 355 ReportMessageAt(location, "strict_const", NULL); |
| 341 *ok = false; | 356 *ok = false; |
| 342 return Statement::Default(); | 357 return Statement::Default(); |
| 343 } | 358 } |
| 344 Consume(i::Token::CONST); | 359 Consume(i::Token::CONST); |
| 345 } else if (peek() == i::Token::LET) { | 360 } else if (peek() == i::Token::LET) { |
| 346 if (var_context != kSourceElement && | 361 if (var_context != kSourceElement && |
| 347 var_context != kForStatement) { | 362 var_context != kForStatement) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); | 394 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); |
| 380 if (decl_props != NULL) *decl_props = kHasInitializers; | 395 if (decl_props != NULL) *decl_props = kHasInitializers; |
| 381 } | 396 } |
| 382 } while (peek() == i::Token::COMMA); | 397 } while (peek() == i::Token::COMMA); |
| 383 | 398 |
| 384 if (num_decl != NULL) *num_decl = nvars; | 399 if (num_decl != NULL) *num_decl = nvars; |
| 385 return Statement::Default(); | 400 return Statement::Default(); |
| 386 } | 401 } |
| 387 | 402 |
| 388 | 403 |
| 404 PreParser::Statement PreParser::ParseHarmonyConstDeclaration(bool* ok) { |
| 405 // ES6 Draft Rev3 |
| 406 // |
| 407 // ConstDeclaration :: |
| 408 // const ConstBinding (',' ConstBinding)* ';' |
| 409 // ConstBinding :: |
| 410 // Identifier '=' AssignmentExpression |
| 411 // |
| 412 // TODO(ES6): |
| 413 // ConstBinding :: |
| 414 // BindingPattern '=' AssignmentExpression |
| 415 |
| 416 Consume(i::Token::CONST); |
| 417 do { |
| 418 // Parse variable name. |
| 419 Identifier identifier = ParseIdentifier(CHECK_OK); |
| 420 if (!identifier.IsValidStrictVariable()) { |
| 421 StrictModeIdentifierViolation(scanner_->location(), |
| 422 "strict_var_name", |
| 423 identifier, |
| 424 ok); |
| 425 return Statement::Default(); |
| 426 } |
| 427 |
| 428 Expect(i::Token::ASSIGN, CHECK_OK); |
| 429 ParseAssignmentExpression(false, CHECK_OK); |
| 430 } while (Check(i::Token::COMMA)); |
| 431 |
| 432 ExpectSemicolon(CHECK_OK); |
| 433 return Statement::Default(); |
| 434 } |
| 435 |
| 436 |
| 389 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 437 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
| 390 // ExpressionStatement | LabelledStatement :: | 438 // ExpressionStatement | LabelledStatement :: |
| 391 // Expression ';' | 439 // Expression ';' |
| 392 // Identifier ':' Statement | 440 // Identifier ':' Statement |
| 393 | 441 |
| 394 Expression expr = ParseExpression(true, CHECK_OK); | 442 Expression expr = ParseExpression(true, CHECK_OK); |
| 395 if (expr.IsRawIdentifier()) { | 443 if (expr.IsRawIdentifier()) { |
| 396 ASSERT(!expr.AsIdentifier().IsFutureReserved()); | 444 ASSERT(!expr.AsIdentifier().IsFutureReserved()); |
| 397 ASSERT(!strict_mode() || !expr.AsIdentifier().IsFutureStrictReserved()); | 445 ASSERT(!strict_mode() || !expr.AsIdentifier().IsFutureStrictReserved()); |
| 398 if (peek() == i::Token::COLON) { | 446 if (peek() == i::Token::COLON) { |
| (...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); | 1739 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); |
| 1692 } | 1740 } |
| 1693 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); | 1741 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); |
| 1694 } | 1742 } |
| 1695 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); | 1743 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); |
| 1696 | 1744 |
| 1697 backing_store_.AddBlock(bytes); | 1745 backing_store_.AddBlock(bytes); |
| 1698 return backing_store_.EndSequence().start(); | 1746 return backing_store_.EndSequence().start(); |
| 1699 } | 1747 } |
| 1700 } } // v8::preparser | 1748 } } // v8::preparser |
| OLD | NEW |