| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 namespace v8 { | 37 namespace v8 { |
| 38 namespace internal { | 38 namespace internal { |
| 39 | 39 |
| 40 // Common base class shared between parser and pre-parser. | 40 // Common base class shared between parser and pre-parser. |
| 41 template <typename Traits> | 41 template <typename Traits> |
| 42 class ParserBase : public Traits { | 42 class ParserBase : public Traits { |
| 43 public: | 43 public: |
| 44 ParserBase(Scanner* scanner, uintptr_t stack_limit, | 44 ParserBase(Scanner* scanner, uintptr_t stack_limit, |
| 45 v8::Extension* extension, | 45 v8::Extension* extension, |
| 46 typename Traits::Type::Zone* zone, |
| 46 typename Traits::Type::Parser this_object) | 47 typename Traits::Type::Parser this_object) |
| 47 : Traits(this_object), | 48 : Traits(this_object), |
| 48 parenthesized_function_(false), | 49 parenthesized_function_(false), |
| 49 scope_(NULL), | 50 scope_(NULL), |
| 50 function_state_(NULL), | 51 function_state_(NULL), |
| 51 extension_(extension), | 52 extension_(extension), |
| 52 scanner_(scanner), | 53 scanner_(scanner), |
| 53 stack_limit_(stack_limit), | 54 stack_limit_(stack_limit), |
| 54 stack_overflow_(false), | 55 stack_overflow_(false), |
| 55 allow_lazy_(false), | 56 allow_lazy_(false), |
| 56 allow_natives_syntax_(false), | 57 allow_natives_syntax_(false), |
| 57 allow_generators_(false), | 58 allow_generators_(false), |
| 58 allow_for_of_(false) { } | 59 allow_for_of_(false), |
| 60 zone_(zone) { } |
| 59 | 61 |
| 60 // Getters that indicate whether certain syntactical constructs are | 62 // Getters that indicate whether certain syntactical constructs are |
| 61 // allowed to be parsed by this instance of the parser. | 63 // allowed to be parsed by this instance of the parser. |
| 62 bool allow_lazy() const { return allow_lazy_; } | 64 bool allow_lazy() const { return allow_lazy_; } |
| 63 bool allow_natives_syntax() const { return allow_natives_syntax_; } | 65 bool allow_natives_syntax() const { return allow_natives_syntax_; } |
| 64 bool allow_generators() const { return allow_generators_; } | 66 bool allow_generators() const { return allow_generators_; } |
| 65 bool allow_for_of() const { return allow_for_of_; } | 67 bool allow_for_of() const { return allow_for_of_; } |
| 66 bool allow_modules() const { return scanner()->HarmonyModules(); } | 68 bool allow_modules() const { return scanner()->HarmonyModules(); } |
| 67 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } | 69 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } |
| 68 bool allow_harmony_numeric_literals() const { | 70 bool allow_harmony_numeric_literals() const { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 typename Traits::Type::Factory factory_; | 180 typename Traits::Type::Factory factory_; |
| 179 | 181 |
| 180 friend class ParserTraits; | 182 friend class ParserTraits; |
| 181 }; | 183 }; |
| 182 | 184 |
| 183 Scanner* scanner() const { return scanner_; } | 185 Scanner* scanner() const { return scanner_; } |
| 184 int position() { return scanner_->location().beg_pos; } | 186 int position() { return scanner_->location().beg_pos; } |
| 185 int peek_position() { return scanner_->peek_location().beg_pos; } | 187 int peek_position() { return scanner_->peek_location().beg_pos; } |
| 186 bool stack_overflow() const { return stack_overflow_; } | 188 bool stack_overflow() const { return stack_overflow_; } |
| 187 void set_stack_overflow() { stack_overflow_ = true; } | 189 void set_stack_overflow() { stack_overflow_ = true; } |
| 190 typename Traits::Type::Zone* zone() const { return zone_; } |
| 188 | 191 |
| 189 INLINE(Token::Value peek()) { | 192 INLINE(Token::Value peek()) { |
| 190 if (stack_overflow_) return Token::ILLEGAL; | 193 if (stack_overflow_) return Token::ILLEGAL; |
| 191 return scanner()->peek(); | 194 return scanner()->peek(); |
| 192 } | 195 } |
| 193 | 196 |
| 194 INLINE(Token::Value Next()) { | 197 INLINE(Token::Value Next()) { |
| 195 if (stack_overflow_) return Token::ILLEGAL; | 198 if (stack_overflow_) return Token::ILLEGAL; |
| 196 { | 199 { |
| 197 int marker; | 200 int marker; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 typename Traits::Type::Identifier ParseIdentifierName(bool* ok); | 331 typename Traits::Type::Identifier ParseIdentifierName(bool* ok); |
| 329 // Parses an identifier and determines whether or not it is 'get' or 'set'. | 332 // Parses an identifier and determines whether or not it is 'get' or 'set'. |
| 330 typename Traits::Type::Identifier ParseIdentifierNameOrGetOrSet(bool* is_get, | 333 typename Traits::Type::Identifier ParseIdentifierNameOrGetOrSet(bool* is_get, |
| 331 bool* is_set, | 334 bool* is_set, |
| 332 bool* ok); | 335 bool* ok); |
| 333 | 336 |
| 334 typename Traits::Type::Expression ParseRegExpLiteral(bool seen_equal, | 337 typename Traits::Type::Expression ParseRegExpLiteral(bool seen_equal, |
| 335 bool* ok); | 338 bool* ok); |
| 336 | 339 |
| 337 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok); | 340 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok); |
| 341 typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok); |
| 342 typename Traits::Type::Expression ParseArrayLiteral(bool* ok); |
| 338 | 343 |
| 339 // Used to detect duplicates in object literals. Each of the values | 344 // Used to detect duplicates in object literals. Each of the values |
| 340 // kGetterProperty, kSetterProperty and kValueProperty represents | 345 // kGetterProperty, kSetterProperty and kValueProperty represents |
| 341 // a type of object literal property. When parsing a property, its | 346 // a type of object literal property. When parsing a property, its |
| 342 // type value is stored in the DuplicateFinder for the property name. | 347 // type value is stored in the DuplicateFinder for the property name. |
| 343 // Values are chosen so that having intersection bits means the there is | 348 // Values are chosen so that having intersection bits means the there is |
| 344 // an incompatibility. | 349 // an incompatibility. |
| 345 // I.e., you can add a getter to a property that already has a setter, since | 350 // I.e., you can add a getter to a property that already has a setter, since |
| 346 // kGetterProperty and kSetterProperty doesn't intersect, but not if it | 351 // kGetterProperty and kSetterProperty doesn't intersect, but not if it |
| 347 // already has a getter or a value. Adding the getter to an existing | 352 // already has a getter or a value. Adding the getter to an existing |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 407 |
| 403 private: | 408 private: |
| 404 Scanner* scanner_; | 409 Scanner* scanner_; |
| 405 uintptr_t stack_limit_; | 410 uintptr_t stack_limit_; |
| 406 bool stack_overflow_; | 411 bool stack_overflow_; |
| 407 | 412 |
| 408 bool allow_lazy_; | 413 bool allow_lazy_; |
| 409 bool allow_natives_syntax_; | 414 bool allow_natives_syntax_; |
| 410 bool allow_generators_; | 415 bool allow_generators_; |
| 411 bool allow_for_of_; | 416 bool allow_for_of_; |
| 417 |
| 418 typename Traits::Type::Zone* zone_; // Only used by Parser. |
| 412 }; | 419 }; |
| 413 | 420 |
| 414 | 421 |
| 415 class PreParserIdentifier { | 422 class PreParserIdentifier { |
| 416 public: | 423 public: |
| 417 static PreParserIdentifier Default() { | 424 static PreParserIdentifier Default() { |
| 418 return PreParserIdentifier(kUnknownIdentifier); | 425 return PreParserIdentifier(kUnknownIdentifier); |
| 419 } | 426 } |
| 420 static PreParserIdentifier Eval() { | 427 static PreParserIdentifier Eval() { |
| 421 return PreParserIdentifier(kEvalIdentifier); | 428 return PreParserIdentifier(kEvalIdentifier); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 kThisPropertyExpression = 8, | 541 kThisPropertyExpression = 8, |
| 535 kStrictFunctionExpression = 12 | 542 kStrictFunctionExpression = 12 |
| 536 }; | 543 }; |
| 537 | 544 |
| 538 explicit PreParserExpression(int expression_code) : code_(expression_code) {} | 545 explicit PreParserExpression(int expression_code) : code_(expression_code) {} |
| 539 | 546 |
| 540 int code_; | 547 int code_; |
| 541 }; | 548 }; |
| 542 | 549 |
| 543 | 550 |
| 551 // PreParserExpressionList doesn't actually store the expressions because |
| 552 // PreParser doesn't need to. |
| 553 class PreParserExpressionList { |
| 554 public: |
| 555 // These functions make list->Add(some_expression) work (and do nothing). |
| 556 PreParserExpressionList* operator->() { return this; } |
| 557 void Add(PreParserExpression, void*) { } |
| 558 }; |
| 559 |
| 560 |
| 544 class PreParserScope { | 561 class PreParserScope { |
| 545 public: | 562 public: |
| 546 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type) | 563 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type) |
| 547 : scope_type_(scope_type) { | 564 : scope_type_(scope_type) { |
| 548 if (outer_scope) { | 565 if (outer_scope) { |
| 549 scope_inside_with_ = | 566 scope_inside_with_ = |
| 550 outer_scope->scope_inside_with_ || is_with_scope(); | 567 outer_scope->scope_inside_with_ || is_with_scope(); |
| 551 language_mode_ = outer_scope->language_mode(); | 568 language_mode_ = outer_scope->language_mode(); |
| 552 } else { | 569 } else { |
| 553 scope_inside_with_ = is_with_scope(); | 570 scope_inside_with_ = is_with_scope(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 582 class PreParserFactory { | 599 class PreParserFactory { |
| 583 public: | 600 public: |
| 584 explicit PreParserFactory(void* extra_param) {} | 601 explicit PreParserFactory(void* extra_param) {} |
| 585 | 602 |
| 586 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 603 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
| 587 PreParserIdentifier js_flags, | 604 PreParserIdentifier js_flags, |
| 588 int literal_index, | 605 int literal_index, |
| 589 int pos) { | 606 int pos) { |
| 590 return PreParserExpression::Default(); | 607 return PreParserExpression::Default(); |
| 591 } | 608 } |
| 609 PreParserExpression NewBinaryOperation(Token::Value op, |
| 610 PreParserExpression left, |
| 611 PreParserExpression right, int pos) { |
| 612 return PreParserExpression::Default(); |
| 613 } |
| 614 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
| 615 int literal_index, |
| 616 int pos) { |
| 617 return PreParserExpression::Default(); |
| 618 } |
| 592 }; | 619 }; |
| 593 | 620 |
| 594 | 621 |
| 595 class PreParser; | 622 class PreParser; |
| 596 | 623 |
| 597 class PreParserTraits { | 624 class PreParserTraits { |
| 598 public: | 625 public: |
| 599 struct Type { | 626 struct Type { |
| 600 typedef PreParser* Parser; | 627 typedef PreParser* Parser; |
| 601 | 628 |
| 602 // Types used by FunctionState and BlockState. | 629 // Types used by FunctionState and BlockState. |
| 603 typedef PreParserScope Scope; | 630 typedef PreParserScope Scope; |
| 604 typedef PreParserFactory Factory; | 631 typedef PreParserFactory Factory; |
| 605 // PreParser doesn't need to store generator variables. | 632 // PreParser doesn't need to store generator variables. |
| 606 typedef void GeneratorVariable; | 633 typedef void GeneratorVariable; |
| 607 // No interaction with Zones. | 634 // No interaction with Zones. |
| 608 typedef void Zone; | 635 typedef void Zone; |
| 609 | 636 |
| 610 // Return types for traversing functions. | 637 // Return types for traversing functions. |
| 611 typedef PreParserIdentifier Identifier; | 638 typedef PreParserIdentifier Identifier; |
| 612 typedef PreParserExpression Expression; | 639 typedef PreParserExpression Expression; |
| 640 typedef PreParserExpressionList ExpressionList; |
| 613 }; | 641 }; |
| 614 | 642 |
| 615 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} | 643 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} |
| 616 | 644 |
| 617 // Custom operations executed when FunctionStates are created and | 645 // Custom operations executed when FunctionStates are created and |
| 618 // destructed. (The PreParser doesn't need to do anything.) | 646 // destructed. (The PreParser doesn't need to do anything.) |
| 619 template<typename FS> | 647 template<typename FS> |
| 620 static void SetUpFunctionState(FS* function_state, void*) {} | 648 static void SetUpFunctionState(FS* function_state, void*) {} |
| 621 template<typename FS> | 649 template<typename FS> |
| 622 static void TearDownFunctionState(FS* function_state) {} | 650 static void TearDownFunctionState(FS* function_state) {} |
| (...skipping 16 matching lines...) Expand all Loading... |
| 639 const char* name_opt); | 667 const char* name_opt); |
| 640 | 668 |
| 641 // "null" return type creators. | 669 // "null" return type creators. |
| 642 static PreParserIdentifier EmptyIdentifier() { | 670 static PreParserIdentifier EmptyIdentifier() { |
| 643 return PreParserIdentifier::Default(); | 671 return PreParserIdentifier::Default(); |
| 644 } | 672 } |
| 645 static PreParserExpression EmptyExpression() { | 673 static PreParserExpression EmptyExpression() { |
| 646 return PreParserExpression::Default(); | 674 return PreParserExpression::Default(); |
| 647 } | 675 } |
| 648 | 676 |
| 677 // Odd-ball literal creators. |
| 678 static PreParserExpression GetLiteralTheHole(int position, |
| 679 PreParserFactory* factory) { |
| 680 return PreParserExpression::Default(); |
| 681 } |
| 682 |
| 649 // Producing data during the recursive descent. | 683 // Producing data during the recursive descent. |
| 650 PreParserIdentifier GetSymbol(Scanner* scanner); | 684 PreParserIdentifier GetSymbol(Scanner* scanner); |
| 651 static PreParserIdentifier NextLiteralString(Scanner* scanner, | 685 static PreParserIdentifier NextLiteralString(Scanner* scanner, |
| 652 PretenureFlag tenured) { | 686 PretenureFlag tenured) { |
| 653 return PreParserIdentifier::Default(); | 687 return PreParserIdentifier::Default(); |
| 654 } | 688 } |
| 655 | 689 |
| 656 static PreParserExpression ThisExpression(PreParserScope* scope, | 690 static PreParserExpression ThisExpression(PreParserScope* scope, |
| 657 PreParserFactory* factory) { | 691 PreParserFactory* factory) { |
| 658 return PreParserExpression::This(); | 692 return PreParserExpression::This(); |
| 659 } | 693 } |
| 660 | 694 |
| 661 static PreParserExpression ExpressionFromLiteral( | 695 static PreParserExpression ExpressionFromLiteral( |
| 662 Token::Value token, int pos, Scanner* scanner, | 696 Token::Value token, int pos, Scanner* scanner, |
| 663 PreParserFactory* factory) { | 697 PreParserFactory* factory) { |
| 664 return PreParserExpression::Default(); | 698 return PreParserExpression::Default(); |
| 665 } | 699 } |
| 666 | 700 |
| 667 static PreParserExpression ExpressionFromIdentifier( | 701 static PreParserExpression ExpressionFromIdentifier( |
| 668 PreParserIdentifier name, int pos, PreParserScope* scope, | 702 PreParserIdentifier name, int pos, PreParserScope* scope, |
| 669 PreParserFactory* factory) { | 703 PreParserFactory* factory) { |
| 670 return PreParserExpression::FromIdentifier(name); | 704 return PreParserExpression::FromIdentifier(name); |
| 671 } | 705 } |
| 672 | 706 |
| 673 PreParserExpression ExpressionFromString(int pos, | 707 PreParserExpression ExpressionFromString(int pos, |
| 674 Scanner* scanner, | 708 Scanner* scanner, |
| 675 PreParserFactory* factory = NULL); | 709 PreParserFactory* factory = NULL); |
| 676 | 710 |
| 711 static PreParserExpressionList NewExpressionList(int size, void* zone) { |
| 712 return PreParserExpressionList(); |
| 713 } |
| 714 |
| 677 // Temporary glue; these functions will move to ParserBase. | 715 // Temporary glue; these functions will move to ParserBase. |
| 678 PreParserExpression ParseArrayLiteral(bool* ok); | 716 PreParserExpression ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 679 PreParserExpression ParseObjectLiteral(bool* ok); | 717 PreParserExpression ParseObjectLiteral(bool* ok); |
| 680 PreParserExpression ParseExpression(bool accept_IN, bool* ok); | |
| 681 PreParserExpression ParseV8Intrinsic(bool* ok); | 718 PreParserExpression ParseV8Intrinsic(bool* ok); |
| 682 | 719 |
| 683 private: | 720 private: |
| 684 PreParser* pre_parser_; | 721 PreParser* pre_parser_; |
| 685 }; | 722 }; |
| 686 | 723 |
| 687 | 724 |
| 688 // Preparsing checks a JavaScript program and emits preparse-data that helps | 725 // Preparsing checks a JavaScript program and emits preparse-data that helps |
| 689 // a later parsing to be faster. | 726 // a later parsing to be faster. |
| 690 // See preparse-data-format.h for the data format. | 727 // See preparse-data-format.h for the data format. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 703 typedef PreParserExpression Expression; | 740 typedef PreParserExpression Expression; |
| 704 | 741 |
| 705 enum PreParseResult { | 742 enum PreParseResult { |
| 706 kPreParseStackOverflow, | 743 kPreParseStackOverflow, |
| 707 kPreParseSuccess | 744 kPreParseSuccess |
| 708 }; | 745 }; |
| 709 | 746 |
| 710 PreParser(Scanner* scanner, | 747 PreParser(Scanner* scanner, |
| 711 ParserRecorder* log, | 748 ParserRecorder* log, |
| 712 uintptr_t stack_limit) | 749 uintptr_t stack_limit) |
| 713 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, this), | 750 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, NULL, this), |
| 714 log_(log) {} | 751 log_(log) {} |
| 715 | 752 |
| 716 // Pre-parse the program from the character stream; returns true on | 753 // Pre-parse the program from the character stream; returns true on |
| 717 // success (even if parsing failed, the pre-parse data successfully | 754 // success (even if parsing failed, the pre-parse data successfully |
| 718 // captured the syntax error), and false if a stack-overflow happened | 755 // captured the syntax error), and false if a stack-overflow happened |
| 719 // during parsing. | 756 // during parsing. |
| 720 PreParseResult PreParseProgram() { | 757 PreParseResult PreParseProgram() { |
| 721 PreParserScope scope(scope_, GLOBAL_SCOPE); | 758 PreParserScope scope(scope_, GLOBAL_SCOPE); |
| 722 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); | 759 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); |
| 723 bool ok = true; | 760 bool ok = true; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 Statement ParseReturnStatement(bool* ok); | 876 Statement ParseReturnStatement(bool* ok); |
| 840 Statement ParseWithStatement(bool* ok); | 877 Statement ParseWithStatement(bool* ok); |
| 841 Statement ParseSwitchStatement(bool* ok); | 878 Statement ParseSwitchStatement(bool* ok); |
| 842 Statement ParseDoWhileStatement(bool* ok); | 879 Statement ParseDoWhileStatement(bool* ok); |
| 843 Statement ParseWhileStatement(bool* ok); | 880 Statement ParseWhileStatement(bool* ok); |
| 844 Statement ParseForStatement(bool* ok); | 881 Statement ParseForStatement(bool* ok); |
| 845 Statement ParseThrowStatement(bool* ok); | 882 Statement ParseThrowStatement(bool* ok); |
| 846 Statement ParseTryStatement(bool* ok); | 883 Statement ParseTryStatement(bool* ok); |
| 847 Statement ParseDebuggerStatement(bool* ok); | 884 Statement ParseDebuggerStatement(bool* ok); |
| 848 | 885 |
| 849 Expression ParseExpression(bool accept_IN, bool* ok); | |
| 850 Expression ParseAssignmentExpression(bool accept_IN, bool* ok); | 886 Expression ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 851 Expression ParseYieldExpression(bool* ok); | 887 Expression ParseYieldExpression(bool* ok); |
| 852 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 888 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
| 853 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 889 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 854 Expression ParseUnaryExpression(bool* ok); | 890 Expression ParseUnaryExpression(bool* ok); |
| 855 Expression ParsePostfixExpression(bool* ok); | 891 Expression ParsePostfixExpression(bool* ok); |
| 856 Expression ParseLeftHandSideExpression(bool* ok); | 892 Expression ParseLeftHandSideExpression(bool* ok); |
| 857 Expression ParseMemberExpression(bool* ok); | 893 Expression ParseMemberExpression(bool* ok); |
| 858 Expression ParseMemberExpressionContinuation(PreParserExpression expression, | 894 Expression ParseMemberExpressionContinuation(PreParserExpression expression, |
| 859 bool* ok); | 895 bool* ok); |
| 860 Expression ParseMemberWithNewPrefixesExpression(bool* ok); | 896 Expression ParseMemberWithNewPrefixesExpression(bool* ok); |
| 861 Expression ParseArrayLiteral(bool* ok); | |
| 862 Expression ParseObjectLiteral(bool* ok); | 897 Expression ParseObjectLiteral(bool* ok); |
| 863 Expression ParseV8Intrinsic(bool* ok); | 898 Expression ParseV8Intrinsic(bool* ok); |
| 864 | 899 |
| 865 Arguments ParseArguments(bool* ok); | 900 Arguments ParseArguments(bool* ok); |
| 866 Expression ParseFunctionLiteral( | 901 Expression ParseFunctionLiteral( |
| 867 Identifier name, | 902 Identifier name, |
| 868 Scanner::Location function_name_location, | 903 Scanner::Location function_name_location, |
| 869 bool name_is_strict_reserved, | 904 bool name_is_strict_reserved, |
| 870 bool is_generator, | 905 bool is_generator, |
| 871 bool* ok); | 906 bool* ok); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 default: { | 1180 default: { |
| 1146 Next(); | 1181 Next(); |
| 1147 ReportUnexpectedToken(token); | 1182 ReportUnexpectedToken(token); |
| 1148 *ok = false; | 1183 *ok = false; |
| 1149 } | 1184 } |
| 1150 } | 1185 } |
| 1151 | 1186 |
| 1152 return result; | 1187 return result; |
| 1153 } | 1188 } |
| 1154 | 1189 |
| 1190 // Precedence = 1 |
| 1191 template <class Traits> |
| 1192 typename Traits::Type::Expression ParserBase<Traits>::ParseExpression( |
| 1193 bool accept_IN, bool* ok) { |
| 1194 // Expression :: |
| 1195 // AssignmentExpression |
| 1196 // Expression ',' AssignmentExpression |
| 1197 |
| 1198 typename Traits::Type::Expression result = |
| 1199 this->ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 1200 while (peek() == Token::COMMA) { |
| 1201 Expect(Token::COMMA, CHECK_OK); |
| 1202 int pos = position(); |
| 1203 typename Traits::Type::Expression right = |
| 1204 this->ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 1205 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); |
| 1206 } |
| 1207 return result; |
| 1208 } |
| 1209 |
| 1210 |
| 1211 template <class Traits> |
| 1212 typename Traits::Type::Expression ParserBase<Traits>::ParseArrayLiteral( |
| 1213 bool* ok) { |
| 1214 // ArrayLiteral :: |
| 1215 // '[' Expression? (',' Expression?)* ']' |
| 1216 |
| 1217 int pos = peek_position(); |
| 1218 typename Traits::Type::ExpressionList values = |
| 1219 this->NewExpressionList(4, zone_); |
| 1220 Expect(Token::LBRACK, CHECK_OK); |
| 1221 while (peek() != Token::RBRACK) { |
| 1222 typename Traits::Type::Expression elem = this->EmptyExpression(); |
| 1223 if (peek() == Token::COMMA) { |
| 1224 elem = this->GetLiteralTheHole(peek_position(), factory()); |
| 1225 } else { |
| 1226 elem = this->ParseAssignmentExpression(true, CHECK_OK); |
| 1227 } |
| 1228 values->Add(elem, zone_); |
| 1229 if (peek() != Token::RBRACK) { |
| 1230 Expect(Token::COMMA, CHECK_OK); |
| 1231 } |
| 1232 } |
| 1233 Expect(Token::RBRACK, CHECK_OK); |
| 1234 |
| 1235 // Update the scope information before the pre-parsing bailout. |
| 1236 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
| 1237 |
| 1238 return factory()->NewArrayLiteral(values, literal_index, pos); |
| 1239 } |
| 1240 |
| 1155 #undef CHECK_OK | 1241 #undef CHECK_OK |
| 1156 | 1242 |
| 1157 | 1243 |
| 1158 template <typename Traits> | 1244 template <typename Traits> |
| 1159 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 1245 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
| 1160 Token::Value property, | 1246 Token::Value property, |
| 1161 PropertyKind type, | 1247 PropertyKind type, |
| 1162 bool* ok) { | 1248 bool* ok) { |
| 1163 int old; | 1249 int old; |
| 1164 if (property == Token::NUMBER) { | 1250 if (property == Token::NUMBER) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1186 "accessor_get_set"); | 1272 "accessor_get_set"); |
| 1187 } | 1273 } |
| 1188 *ok = false; | 1274 *ok = false; |
| 1189 } | 1275 } |
| 1190 } | 1276 } |
| 1191 | 1277 |
| 1192 | 1278 |
| 1193 } } // v8::internal | 1279 } } // v8::internal |
| 1194 | 1280 |
| 1195 #endif // V8_PREPARSER_H | 1281 #endif // V8_PREPARSER_H |
| OLD | NEW |