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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 return pre_parser_->ParseFunctionLiteral( | 100 return pre_parser_->ParseFunctionLiteral( |
101 name, function_name_location, name_is_strict_reserved, kind, | 101 name, function_name_location, name_is_strict_reserved, kind, |
102 function_token_position, type, arity_restriction, ok); | 102 function_token_position, type, arity_restriction, ok); |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 106 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
107 LanguageMode language_mode, FunctionKind kind, ParserRecorder* log) { | 107 LanguageMode language_mode, FunctionKind kind, ParserRecorder* log) { |
108 log_ = log; | 108 log_ = log; |
109 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 109 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
110 PreParserScope top_scope(scope_, SCRIPT_SCOPE); | 110 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); |
111 PreParserFactory top_factory(NULL); | 111 PreParserFactory top_factory(NULL); |
112 FunctionState top_state(&function_state_, &scope_, &top_scope, | 112 FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction, |
113 kNormalFunction, &top_factory); | 113 &top_factory); |
114 scope_->SetLanguageMode(language_mode); | 114 scope_->SetLanguageMode(language_mode); |
115 PreParserScope function_scope(scope_, FUNCTION_SCOPE); | 115 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); |
116 PreParserFactory function_factory(NULL); | 116 PreParserFactory function_factory(NULL); |
117 FunctionState function_state(&function_state_, &scope_, &function_scope, kind, | 117 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
118 &function_factory); | 118 &function_factory); |
119 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 119 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
120 bool ok = true; | 120 bool ok = true; |
121 int start_position = peek_position(); | 121 int start_position = peek_position(); |
122 ParseLazyFunctionLiteralBody(&ok); | 122 ParseLazyFunctionLiteralBody(&ok); |
123 if (stack_overflow()) return kPreParseStackOverflow; | 123 if (stack_overflow()) return kPreParseStackOverflow; |
124 if (!ok) { | 124 if (!ok) { |
125 ReportUnexpectedToken(scanner()->current_token()); | 125 ReportUnexpectedToken(scanner()->current_token()); |
126 } else { | 126 } else { |
127 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 127 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 Expect(Token::WITH, CHECK_OK); | 630 Expect(Token::WITH, CHECK_OK); |
631 if (is_strict(language_mode())) { | 631 if (is_strict(language_mode())) { |
632 ReportMessageAt(scanner()->location(), "strict_mode_with"); | 632 ReportMessageAt(scanner()->location(), "strict_mode_with"); |
633 *ok = false; | 633 *ok = false; |
634 return Statement::Default(); | 634 return Statement::Default(); |
635 } | 635 } |
636 Expect(Token::LPAREN, CHECK_OK); | 636 Expect(Token::LPAREN, CHECK_OK); |
637 ParseExpression(true, CHECK_OK); | 637 ParseExpression(true, CHECK_OK); |
638 Expect(Token::RPAREN, CHECK_OK); | 638 Expect(Token::RPAREN, CHECK_OK); |
639 | 639 |
640 PreParserScope with_scope(scope_, WITH_SCOPE); | 640 Scope* with_scope = NewScope(scope_, WITH_SCOPE); |
641 BlockState block_state(&scope_, &with_scope); | 641 BlockState block_state(&scope_, with_scope); |
642 ParseStatement(CHECK_OK); | 642 ParseStatement(CHECK_OK); |
643 return Statement::Default(); | 643 return Statement::Default(); |
644 } | 644 } |
645 | 645 |
646 | 646 |
647 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { | 647 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { |
648 // SwitchStatement :: | 648 // SwitchStatement :: |
649 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 649 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
650 | 650 |
651 Expect(Token::SWITCH, CHECK_OK); | 651 Expect(Token::SWITCH, CHECK_OK); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 ReportMessageAt(scanner()->location(), "no_catch_or_finally"); | 815 ReportMessageAt(scanner()->location(), "no_catch_or_finally"); |
816 *ok = false; | 816 *ok = false; |
817 return Statement::Default(); | 817 return Statement::Default(); |
818 } | 818 } |
819 if (tok == Token::CATCH) { | 819 if (tok == Token::CATCH) { |
820 Consume(Token::CATCH); | 820 Consume(Token::CATCH); |
821 Expect(Token::LPAREN, CHECK_OK); | 821 Expect(Token::LPAREN, CHECK_OK); |
822 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 822 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
823 Expect(Token::RPAREN, CHECK_OK); | 823 Expect(Token::RPAREN, CHECK_OK); |
824 { | 824 { |
825 PreParserScope with_scope(scope_, WITH_SCOPE); | 825 Scope* with_scope = NewScope(scope_, WITH_SCOPE); |
826 BlockState block_state(&scope_, &with_scope); | 826 BlockState block_state(&scope_, with_scope); |
827 ParseBlock(CHECK_OK); | 827 ParseBlock(CHECK_OK); |
828 } | 828 } |
829 tok = peek(); | 829 tok = peek(); |
830 } | 830 } |
831 if (tok == Token::FINALLY) { | 831 if (tok == Token::FINALLY) { |
832 Consume(Token::FINALLY); | 832 Consume(Token::FINALLY); |
833 ParseBlock(CHECK_OK); | 833 ParseBlock(CHECK_OK); |
834 } | 834 } |
835 return Statement::Default(); | 835 return Statement::Default(); |
836 } | 836 } |
(...skipping 22 matching lines...) Expand all Loading... | |
859 | 859 |
860 PreParser::Expression PreParser::ParseFunctionLiteral( | 860 PreParser::Expression PreParser::ParseFunctionLiteral( |
861 Identifier function_name, Scanner::Location function_name_location, | 861 Identifier function_name, Scanner::Location function_name_location, |
862 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 862 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
863 FunctionLiteral::FunctionType function_type, | 863 FunctionLiteral::FunctionType function_type, |
864 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 864 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
865 // Function :: | 865 // Function :: |
866 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 866 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
867 | 867 |
868 // Parse function body. | 868 // Parse function body. |
869 ScopeType outer_scope_type = scope_->type(); | 869 bool outer_is_script_scope = scope_->is_script_scope(); |
870 PreParserScope function_scope(scope_, FUNCTION_SCOPE); | 870 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); |
871 PreParserFactory factory(NULL); | 871 PreParserFactory factory(NULL); |
872 FunctionState function_state(&function_state_, &scope_, &function_scope, kind, | 872 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
873 &factory); | 873 &factory); |
874 // FormalParameterList :: | 874 // FormalParameterList :: |
875 // '(' (Identifier)*[','] ')' | 875 // '(' (Identifier)*[','] ')' |
876 Expect(Token::LPAREN, CHECK_OK); | 876 Expect(Token::LPAREN, CHECK_OK); |
877 int start_position = position(); | 877 int start_position = position(); |
878 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 878 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
879 // We don't yet know if the function will be strict, so we cannot yet produce | 879 // We don't yet know if the function will be strict, so we cannot yet produce |
880 // errors for parameter names or duplicates. However, we remember the | 880 // errors for parameter names or duplicates. However, we remember the |
881 // locations of these errors if they occur and produce the errors later. | 881 // locations of these errors if they occur and produce the errors later. |
882 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); | 882 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 *ok = false; | 917 *ok = false; |
918 return Expression::Default(); | 918 return Expression::Default(); |
919 } | 919 } |
920 Expect(Token::COMMA, CHECK_OK); | 920 Expect(Token::COMMA, CHECK_OK); |
921 } | 921 } |
922 } | 922 } |
923 Expect(Token::RPAREN, CHECK_OK); | 923 Expect(Token::RPAREN, CHECK_OK); |
924 | 924 |
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 = |
928 !parenthesized_function_); | 928 (outer_is_script_scope && allow_lazy() && !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 ParseSourceElements(Token::RBRACE, ok); |
936 } | 936 } |
937 Expect(Token::RBRACE, CHECK_OK); | 937 Expect(Token::RBRACE, CHECK_OK); |
938 | 938 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
996 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); | 996 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); |
997 *ok = false; | 997 *ok = false; |
998 return EmptyExpression(); | 998 return EmptyExpression(); |
999 } | 999 } |
1000 if (IsEvalOrArguments(name)) { | 1000 if (IsEvalOrArguments(name)) { |
1001 ReportMessageAt(class_name_location, "strict_eval_arguments"); | 1001 ReportMessageAt(class_name_location, "strict_eval_arguments"); |
1002 *ok = false; | 1002 *ok = false; |
1003 return EmptyExpression(); | 1003 return EmptyExpression(); |
1004 } | 1004 } |
1005 | 1005 |
1006 PreParserScope scope = NewScope(scope_, BLOCK_SCOPE); | 1006 Scope* scope = NewScope(scope_, BLOCK_SCOPE); |
1007 BlockState block_state(&scope_, &scope); | 1007 BlockState block_state(&scope_, scope); |
1008 scope_->SetLanguageMode( | 1008 scope_->SetLanguageMode( |
1009 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); | 1009 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
1010 scope_->SetScopeName(name); | 1010 // TODO(marja): Make PreParser use scope names too. |
1011 // scope_->SetScopeName(name); | |
marja
2015/02/10 13:05:39
This will be fixed when PreParser starts to handle
| |
1011 | 1012 |
1012 bool has_extends = Check(Token::EXTENDS); | 1013 bool has_extends = Check(Token::EXTENDS); |
1013 if (has_extends) { | 1014 if (has_extends) { |
1014 ParseLeftHandSideExpression(CHECK_OK); | 1015 ParseLeftHandSideExpression(CHECK_OK); |
1015 } | 1016 } |
1016 | 1017 |
1017 ClassLiteralChecker checker(this); | 1018 ClassLiteralChecker checker(this); |
1018 bool has_seen_constructor = false; | 1019 bool has_seen_constructor = false; |
1019 | 1020 |
1020 Expect(Token::LBRACE, CHECK_OK); | 1021 Expect(Token::LBRACE, CHECK_OK); |
(...skipping 25 matching lines...) Expand all Loading... | |
1046 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 1047 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
1047 ParseArguments(ok); | 1048 ParseArguments(ok); |
1048 | 1049 |
1049 return Expression::Default(); | 1050 return Expression::Default(); |
1050 } | 1051 } |
1051 | 1052 |
1052 #undef CHECK_OK | 1053 #undef CHECK_OK |
1053 | 1054 |
1054 | 1055 |
1055 } } // v8::internal | 1056 } } // v8::internal |
OLD | NEW |