| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 84 } |
| 85 | 85 |
| 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 FunctionNameValidity function_name_validity, 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, bool* ok) { |
| 97 return pre_parser_->ParseFunctionLiteral( | 97 return pre_parser_->ParseFunctionLiteral( |
| 98 name, function_name_location, name_is_strict_reserved, kind, | 98 name, function_name_location, function_name_validity, kind, |
| 99 function_token_position, type, arity_restriction, ok); | 99 function_token_position, type, arity_restriction, ok); |
| 100 } | 100 } |
| 101 | 101 |
| 102 | 102 |
| 103 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 103 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 104 LanguageMode language_mode, FunctionKind kind, ParserRecorder* log, | 104 LanguageMode language_mode, FunctionKind kind, ParserRecorder* log, |
| 105 Scanner::BookmarkScope* bookmark) { | 105 Scanner::BookmarkScope* bookmark) { |
| 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 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); | 108 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 412 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
| 413 // GeneratorDeclaration :: | 413 // GeneratorDeclaration :: |
| 414 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 414 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
| 415 // '{' FunctionBody '}' | 415 // '{' FunctionBody '}' |
| 416 Expect(Token::FUNCTION, CHECK_OK); | 416 Expect(Token::FUNCTION, CHECK_OK); |
| 417 int pos = position(); | 417 int pos = position(); |
| 418 bool is_generator = Check(Token::MUL); | 418 bool is_generator = Check(Token::MUL); |
| 419 bool is_strict_reserved = false; | 419 bool is_strict_reserved = false; |
| 420 Identifier name = ParseIdentifierOrStrictReservedWord( | 420 Identifier name = ParseIdentifierOrStrictReservedWord( |
| 421 &is_strict_reserved, CHECK_OK); | 421 &is_strict_reserved, CHECK_OK); |
| 422 ParseFunctionLiteral(name, scanner()->location(), is_strict_reserved, | 422 ParseFunctionLiteral(name, scanner()->location(), |
| 423 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 424 : kFunctionNameValidityUnknown, |
| 423 is_generator ? FunctionKind::kGeneratorFunction | 425 is_generator ? FunctionKind::kGeneratorFunction |
| 424 : FunctionKind::kNormalFunction, | 426 : FunctionKind::kNormalFunction, |
| 425 pos, FunctionLiteral::DECLARATION, | 427 pos, FunctionLiteral::DECLARATION, |
| 426 FunctionLiteral::NORMAL_ARITY, CHECK_OK); | 428 FunctionLiteral::NORMAL_ARITY, 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); |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 #undef CHECK_OK | 1023 #undef CHECK_OK |
| 1022 #define CHECK_OK ok); \ | 1024 #define CHECK_OK ok); \ |
| 1023 if (!*ok) return Expression::Default(); \ | 1025 if (!*ok) return Expression::Default(); \ |
| 1024 ((void)0 | 1026 ((void)0 |
| 1025 #define DUMMY ) // to make indentation work | 1027 #define DUMMY ) // to make indentation work |
| 1026 #undef DUMMY | 1028 #undef DUMMY |
| 1027 | 1029 |
| 1028 | 1030 |
| 1029 PreParser::Expression PreParser::ParseFunctionLiteral( | 1031 PreParser::Expression PreParser::ParseFunctionLiteral( |
| 1030 Identifier function_name, Scanner::Location function_name_location, | 1032 Identifier function_name, Scanner::Location function_name_location, |
| 1031 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 1033 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 1032 FunctionLiteral::FunctionType function_type, | 1034 int function_token_pos, FunctionLiteral::FunctionType function_type, |
| 1033 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 1035 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
| 1034 // Function :: | 1036 // Function :: |
| 1035 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 1037 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 1036 | 1038 |
| 1037 // Parse function body. | 1039 // Parse function body. |
| 1038 bool outer_is_script_scope = scope_->is_script_scope(); | 1040 bool outer_is_script_scope = scope_->is_script_scope(); |
| 1039 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); | 1041 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); |
| 1040 PreParserFactory factory(NULL); | 1042 PreParserFactory factory(NULL); |
| 1041 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 1043 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
| 1042 &factory); | 1044 &factory); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1065 Expect(Token::LBRACE, CHECK_OK); | 1067 Expect(Token::LBRACE, CHECK_OK); |
| 1066 if (is_lazily_parsed) { | 1068 if (is_lazily_parsed) { |
| 1067 ParseLazyFunctionLiteralBody(CHECK_OK); | 1069 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 1068 } else { | 1070 } else { |
| 1069 ParseStatementList(Token::RBRACE, CHECK_OK); | 1071 ParseStatementList(Token::RBRACE, CHECK_OK); |
| 1070 } | 1072 } |
| 1071 Expect(Token::RBRACE, CHECK_OK); | 1073 Expect(Token::RBRACE, CHECK_OK); |
| 1072 | 1074 |
| 1073 // Validate name and parameter names. We can do this only after parsing the | 1075 // Validate name and parameter names. We can do this only after parsing the |
| 1074 // function, since the function can declare itself strict. | 1076 // function, since the function can declare itself strict. |
| 1075 CheckFunctionName(language_mode(), kind, function_name, | 1077 CheckFunctionName(language_mode(), function_name, function_name_validity, |
| 1076 name_is_strict_reserved, function_name_location, CHECK_OK); | 1078 function_name_location, CHECK_OK); |
| 1077 const bool strict_formal_parameters = | 1079 const bool strict_formal_parameters = |
| 1078 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind); | 1080 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind); |
| 1079 const bool allow_duplicate_parameters = | 1081 const bool allow_duplicate_parameters = |
| 1080 is_sloppy(language_mode()) && !strict_formal_parameters; | 1082 is_sloppy(language_mode()) && !strict_formal_parameters; |
| 1081 ValidateFormalParameters(&formals_classifier, language_mode(), | 1083 ValidateFormalParameters(&formals_classifier, language_mode(), |
| 1082 allow_duplicate_parameters, CHECK_OK); | 1084 allow_duplicate_parameters, CHECK_OK); |
| 1083 | 1085 |
| 1084 if (is_strict(language_mode())) { | 1086 if (is_strict(language_mode())) { |
| 1085 int end_position = scanner()->location().end_pos; | 1087 int end_position = scanner()->location().end_pos; |
| 1086 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 1088 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 | 1195 |
| 1194 DCHECK(!spread_pos.IsValid()); | 1196 DCHECK(!spread_pos.IsValid()); |
| 1195 | 1197 |
| 1196 return Expression::Default(); | 1198 return Expression::Default(); |
| 1197 } | 1199 } |
| 1198 | 1200 |
| 1199 #undef CHECK_OK | 1201 #undef CHECK_OK |
| 1200 | 1202 |
| 1201 | 1203 |
| 1202 } } // v8::internal | 1204 } } // v8::internal |
| OLD | NEW |