| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 bool name_is_strict_reserved, FunctionKind kind, | 95 bool name_is_strict_reserved, FunctionKind kind, |
| 96 int function_token_position, FunctionLiteral::FunctionType type, | 96 int function_token_position, FunctionLiteral::FunctionType type, |
| 97 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 97 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
| 98 return pre_parser_->ParseFunctionLiteral( | 98 return pre_parser_->ParseFunctionLiteral( |
| 99 name, function_name_location, name_is_strict_reserved, kind, | 99 name, function_name_location, name_is_strict_reserved, kind, |
| 100 function_token_position, type, arity_restriction, ok); | 100 function_token_position, type, arity_restriction, ok); |
| 101 } | 101 } |
| 102 | 102 |
| 103 | 103 |
| 104 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 104 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 105 LanguageMode language_mode, bool is_generator, ParserRecorder* log) { | 105 LanguageMode language_mode, FunctionKind kind, ParserRecorder* log) { |
| 106 log_ = log; | 106 log_ = log; |
| 107 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 107 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
| 108 PreParserScope top_scope(scope_, SCRIPT_SCOPE); | 108 PreParserScope top_scope(scope_, SCRIPT_SCOPE); |
| 109 PreParserFactory top_factory(NULL); | 109 PreParserFactory top_factory(NULL); |
| 110 FunctionState top_state(&function_state_, &scope_, &top_scope, &top_factory); | 110 FunctionState top_state(&function_state_, &scope_, &top_scope, |
| 111 kNormalFunction, &top_factory); |
| 111 scope_->SetLanguageMode(language_mode); | 112 scope_->SetLanguageMode(language_mode); |
| 112 PreParserScope function_scope(scope_, FUNCTION_SCOPE); | 113 PreParserScope function_scope(scope_, FUNCTION_SCOPE); |
| 113 PreParserFactory function_factory(NULL); | 114 PreParserFactory function_factory(NULL); |
| 114 FunctionState function_state(&function_state_, &scope_, &function_scope, | 115 FunctionState function_state(&function_state_, &scope_, &function_scope, kind, |
| 115 &function_factory); | 116 &function_factory); |
| 116 function_state.set_is_generator(is_generator); | |
| 117 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 117 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
| 118 bool ok = true; | 118 bool ok = true; |
| 119 int start_position = peek_position(); | 119 int start_position = peek_position(); |
| 120 ParseLazyFunctionLiteralBody(&ok); | 120 ParseLazyFunctionLiteralBody(&ok); |
| 121 if (stack_overflow()) return kPreParseStackOverflow; | 121 if (stack_overflow()) return kPreParseStackOverflow; |
| 122 if (!ok) { | 122 if (!ok) { |
| 123 ReportUnexpectedToken(scanner()->current_token()); | 123 ReportUnexpectedToken(scanner()->current_token()); |
| 124 } else { | 124 } else { |
| 125 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 125 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| 126 if (is_strict(scope_->language_mode())) { | 126 if (is_strict(scope_->language_mode())) { |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 857 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
| 858 FunctionLiteral::FunctionType function_type, | 858 FunctionLiteral::FunctionType function_type, |
| 859 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 859 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
| 860 // Function :: | 860 // Function :: |
| 861 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 861 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 862 | 862 |
| 863 // Parse function body. | 863 // Parse function body. |
| 864 ScopeType outer_scope_type = scope_->type(); | 864 ScopeType outer_scope_type = scope_->type(); |
| 865 PreParserScope function_scope(scope_, FUNCTION_SCOPE); | 865 PreParserScope function_scope(scope_, FUNCTION_SCOPE); |
| 866 PreParserFactory factory(NULL); | 866 PreParserFactory factory(NULL); |
| 867 FunctionState function_state(&function_state_, &scope_, &function_scope, | 867 FunctionState function_state(&function_state_, &scope_, &function_scope, kind, |
| 868 &factory); | 868 &factory); |
| 869 function_state.set_is_generator(IsGeneratorFunction(kind)); | |
| 870 // FormalParameterList :: | 869 // FormalParameterList :: |
| 871 // '(' (Identifier)*[','] ')' | 870 // '(' (Identifier)*[','] ')' |
| 872 Expect(Token::LPAREN, CHECK_OK); | 871 Expect(Token::LPAREN, CHECK_OK); |
| 873 int start_position = position(); | 872 int start_position = position(); |
| 874 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 873 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
| 875 // We don't yet know if the function will be strict, so we cannot yet produce | 874 // We don't yet know if the function will be strict, so we cannot yet produce |
| 876 // errors for parameter names or duplicates. However, we remember the | 875 // errors for parameter names or duplicates. However, we remember the |
| 877 // locations of these errors if they occur and produce the errors later. | 876 // locations of these errors if they occur and produce the errors later. |
| 878 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); | 877 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); |
| 879 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 878 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 1041 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
| 1043 ParseArguments(ok); | 1042 ParseArguments(ok); |
| 1044 | 1043 |
| 1045 return Expression::Default(); | 1044 return Expression::Default(); |
| 1046 } | 1045 } |
| 1047 | 1046 |
| 1048 #undef CHECK_OK | 1047 #undef CHECK_OK |
| 1049 | 1048 |
| 1050 | 1049 |
| 1051 } } // v8::internal | 1050 } } // v8::internal |
| OLD | NEW |