| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { | 87 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { |
| 88 return pre_parser_->ParseV8Intrinsic(ok); | 88 return pre_parser_->ParseV8Intrinsic(ok); |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 PreParserExpression PreParserTraits::ParseFunctionLiteral( | 92 PreParserExpression PreParserTraits::ParseFunctionLiteral( |
| 93 PreParserIdentifier name, Scanner::Location function_name_location, | 93 PreParserIdentifier name, Scanner::Location function_name_location, |
| 94 bool name_is_strict_reserved, FunctionKind kind, | 94 bool name_is_strict_reserved, FunctionKind kind, |
| 95 int function_token_position, FunctionLiteral::FunctionType type, | 95 int function_token_position, FunctionLiteral::FunctionType type, |
| 96 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 96 FunctionLiteral::ArityRestriction arity_restriction, |
| 97 LanguageMode language_mode, bool* ok) { |
| 97 return pre_parser_->ParseFunctionLiteral( | 98 return pre_parser_->ParseFunctionLiteral( |
| 98 name, function_name_location, name_is_strict_reserved, kind, | 99 name, function_name_location, name_is_strict_reserved, kind, |
| 99 function_token_position, type, arity_restriction, ok); | 100 function_token_position, type, arity_restriction, language_mode, ok); |
| 100 } | 101 } |
| 101 | 102 |
| 102 | 103 |
| 103 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 104 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 104 LanguageMode language_mode, FunctionKind kind, ParserRecorder* log, | 105 LanguageMode language_mode, FunctionKind kind, ParserRecorder* log, |
| 105 Scanner::BookmarkScope* bookmark) { | 106 Scanner::BookmarkScope* bookmark) { |
| 106 log_ = log; | 107 log_ = log; |
| 107 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 108 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
| 108 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); | 109 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); |
| 109 PreParserFactory top_factory(NULL); | 110 PreParserFactory top_factory(NULL); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 Expect(Token::FUNCTION, CHECK_OK); | 417 Expect(Token::FUNCTION, CHECK_OK); |
| 417 int pos = position(); | 418 int pos = position(); |
| 418 bool is_generator = Check(Token::MUL); | 419 bool is_generator = Check(Token::MUL); |
| 419 bool is_strict_reserved = false; | 420 bool is_strict_reserved = false; |
| 420 Identifier name = ParseIdentifierOrStrictReservedWord( | 421 Identifier name = ParseIdentifierOrStrictReservedWord( |
| 421 &is_strict_reserved, CHECK_OK); | 422 &is_strict_reserved, CHECK_OK); |
| 422 ParseFunctionLiteral(name, scanner()->location(), is_strict_reserved, | 423 ParseFunctionLiteral(name, scanner()->location(), is_strict_reserved, |
| 423 is_generator ? FunctionKind::kGeneratorFunction | 424 is_generator ? FunctionKind::kGeneratorFunction |
| 424 : FunctionKind::kNormalFunction, | 425 : FunctionKind::kNormalFunction, |
| 425 pos, FunctionLiteral::DECLARATION, | 426 pos, FunctionLiteral::DECLARATION, |
| 426 FunctionLiteral::NORMAL_ARITY, CHECK_OK); | 427 FunctionLiteral::NORMAL_ARITY, language_mode(), |
| 428 CHECK_OK); |
| 427 return Statement::FunctionDeclaration(); | 429 return Statement::FunctionDeclaration(); |
| 428 } | 430 } |
| 429 | 431 |
| 430 | 432 |
| 431 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { | 433 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { |
| 432 Expect(Token::CLASS, CHECK_OK); | 434 Expect(Token::CLASS, CHECK_OK); |
| 433 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { | 435 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { |
| 434 ReportMessage(MessageTemplate::kSloppyLexical); | 436 ReportMessage(MessageTemplate::kSloppyLexical); |
| 435 *ok = false; | 437 *ok = false; |
| 436 return Statement::Default(); | 438 return Statement::Default(); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 if (!*ok) return Expression::Default(); \ | 1024 if (!*ok) return Expression::Default(); \ |
| 1023 ((void)0 | 1025 ((void)0 |
| 1024 #define DUMMY ) // to make indentation work | 1026 #define DUMMY ) // to make indentation work |
| 1025 #undef DUMMY | 1027 #undef DUMMY |
| 1026 | 1028 |
| 1027 | 1029 |
| 1028 PreParser::Expression PreParser::ParseFunctionLiteral( | 1030 PreParser::Expression PreParser::ParseFunctionLiteral( |
| 1029 Identifier function_name, Scanner::Location function_name_location, | 1031 Identifier function_name, Scanner::Location function_name_location, |
| 1030 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 1032 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
| 1031 FunctionLiteral::FunctionType function_type, | 1033 FunctionLiteral::FunctionType function_type, |
| 1032 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 1034 FunctionLiteral::ArityRestriction arity_restriction, |
| 1035 LanguageMode language_mode, bool* ok) { |
| 1033 // Function :: | 1036 // Function :: |
| 1034 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 1037 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 1035 | 1038 |
| 1036 // Parse function body. | 1039 // Parse function body. |
| 1037 bool outer_is_script_scope = scope_->is_script_scope(); | 1040 bool outer_is_script_scope = scope_->is_script_scope(); |
| 1038 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); | 1041 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); |
| 1042 function_scope->SetLanguageMode(language_mode); |
| 1039 PreParserFactory factory(NULL); | 1043 PreParserFactory factory(NULL); |
| 1040 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 1044 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
| 1041 &factory); | 1045 &factory); |
| 1042 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 1046 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
| 1043 ExpressionClassifier formals_classifier(&duplicate_finder); | 1047 ExpressionClassifier formals_classifier(&duplicate_finder); |
| 1044 | 1048 |
| 1045 Expect(Token::LPAREN, CHECK_OK); | 1049 Expect(Token::LPAREN, CHECK_OK); |
| 1046 int start_position = scanner()->location().beg_pos; | 1050 int start_position = scanner()->location().beg_pos; |
| 1047 function_scope->set_start_position(start_position); | 1051 function_scope->set_start_position(start_position); |
| 1048 PreParserFormalParameterParsingState parsing_state(nullptr); | 1052 PreParserFormalParameterParsingState parsing_state(nullptr); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1062 parenthesized_function_ = false; | 1066 parenthesized_function_ = false; |
| 1063 | 1067 |
| 1064 Expect(Token::LBRACE, CHECK_OK); | 1068 Expect(Token::LBRACE, CHECK_OK); |
| 1065 if (is_lazily_parsed) { | 1069 if (is_lazily_parsed) { |
| 1066 ParseLazyFunctionLiteralBody(CHECK_OK); | 1070 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 1067 } else { | 1071 } else { |
| 1068 ParseStatementList(Token::RBRACE, CHECK_OK); | 1072 ParseStatementList(Token::RBRACE, CHECK_OK); |
| 1069 } | 1073 } |
| 1070 Expect(Token::RBRACE, CHECK_OK); | 1074 Expect(Token::RBRACE, CHECK_OK); |
| 1071 | 1075 |
| 1076 // Parsing the body may change the language mode in our scope. |
| 1077 language_mode = function_scope->language_mode(); |
| 1078 |
| 1072 // Validate name and parameter names. We can do this only after parsing the | 1079 // Validate name and parameter names. We can do this only after parsing the |
| 1073 // function, since the function can declare itself strict. | 1080 // function, since the function can declare itself strict. |
| 1074 CheckFunctionName(language_mode(), kind, function_name, | 1081 CheckFunctionName(language_mode, kind, function_name, |
| 1075 name_is_strict_reserved, function_name_location, CHECK_OK); | 1082 name_is_strict_reserved, function_name_location, CHECK_OK); |
| 1076 const bool strict_formal_parameters = | 1083 const bool strict_formal_parameters = |
| 1077 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind); | 1084 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind); |
| 1078 const bool allow_duplicate_parameters = | 1085 const bool allow_duplicate_parameters = |
| 1079 is_sloppy(language_mode()) && !strict_formal_parameters; | 1086 is_sloppy(language_mode) && !strict_formal_parameters; |
| 1080 ValidateFormalParameters(&formals_classifier, language_mode(), | 1087 ValidateFormalParameters(&formals_classifier, language_mode, |
| 1081 allow_duplicate_parameters, CHECK_OK); | 1088 allow_duplicate_parameters, CHECK_OK); |
| 1082 | 1089 |
| 1083 if (is_strict(language_mode())) { | 1090 if (is_strict(language_mode)) { |
| 1084 int end_position = scanner()->location().end_pos; | 1091 int end_position = scanner()->location().end_pos; |
| 1085 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 1092 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
| 1086 } | 1093 } |
| 1087 | 1094 |
| 1088 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { | 1095 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { |
| 1089 if (!function_state.super_location().IsValid()) { | 1096 if (!function_state.super_location().IsValid()) { |
| 1090 ReportMessageAt(function_name_location, | 1097 ReportMessageAt(function_name_location, |
| 1091 MessageTemplate::kStrongSuperCallMissing, | 1098 MessageTemplate::kStrongSuperCallMissing, |
| 1092 kReferenceError); | 1099 kReferenceError); |
| 1093 *ok = false; | 1100 *ok = false; |
| 1094 return Expression::Default(); | 1101 return Expression::Default(); |
| 1095 } | 1102 } |
| 1096 } | 1103 } |
| 1097 | 1104 |
| 1098 return Expression::Default(); | 1105 return Expression::Default(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 | 1199 |
| 1193 DCHECK(!spread_pos.IsValid()); | 1200 DCHECK(!spread_pos.IsValid()); |
| 1194 | 1201 |
| 1195 return Expression::Default(); | 1202 return Expression::Default(); |
| 1196 } | 1203 } |
| 1197 | 1204 |
| 1198 #undef CHECK_OK | 1205 #undef CHECK_OK |
| 1199 | 1206 |
| 1200 | 1207 |
| 1201 } } // v8::internal | 1208 } } // v8::internal |
| OLD | NEW |