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 "include/v8stdint.h" | 7 #include "include/v8stdint.h" |
8 | 8 |
9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
10 #include "src/base/logging.h" | 10 #include "src/base/logging.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return PreParserExpression::StringLiteral(); | 95 return PreParserExpression::StringLiteral(); |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { | 99 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { |
100 return pre_parser_->ParseV8Intrinsic(ok); | 100 return pre_parser_->ParseV8Intrinsic(ok); |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 PreParserExpression PreParserTraits::ParseFunctionLiteral( | 104 PreParserExpression PreParserTraits::ParseFunctionLiteral( |
105 PreParserIdentifier name, | 105 PreParserIdentifier name, Scanner::Location function_name_location, |
106 Scanner::Location function_name_location, | 106 bool name_is_strict_reserved, FunctionKind kind, |
107 bool name_is_strict_reserved, | 107 int function_token_position, FunctionLiteral::FunctionType type, |
108 bool is_generator, | 108 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
109 int function_token_position, | |
110 FunctionLiteral::FunctionType type, | |
111 FunctionLiteral::ArityRestriction arity_restriction, | |
112 bool* ok) { | |
113 return pre_parser_->ParseFunctionLiteral( | 109 return pre_parser_->ParseFunctionLiteral( |
114 name, function_name_location, name_is_strict_reserved, is_generator, | 110 name, function_name_location, name_is_strict_reserved, kind, |
115 function_token_position, type, arity_restriction, ok); | 111 function_token_position, type, arity_restriction, ok); |
116 } | 112 } |
117 | 113 |
118 | 114 |
119 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 115 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
120 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { | 116 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { |
121 log_ = log; | 117 log_ = log; |
122 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 118 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
123 PreParserScope top_scope(scope_, GLOBAL_SCOPE); | 119 PreParserScope top_scope(scope_, GLOBAL_SCOPE); |
124 FunctionState top_state(&function_state_, &scope_, &top_scope, NULL, | 120 FunctionState top_state(&function_state_, &scope_, &top_scope, NULL, |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 329 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
334 // GeneratorDeclaration :: | 330 // GeneratorDeclaration :: |
335 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 331 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
336 // '{' FunctionBody '}' | 332 // '{' FunctionBody '}' |
337 Expect(Token::FUNCTION, CHECK_OK); | 333 Expect(Token::FUNCTION, CHECK_OK); |
338 int pos = position(); | 334 int pos = position(); |
339 bool is_generator = allow_generators() && Check(Token::MUL); | 335 bool is_generator = allow_generators() && Check(Token::MUL); |
340 bool is_strict_reserved = false; | 336 bool is_strict_reserved = false; |
341 Identifier name = ParseIdentifierOrStrictReservedWord( | 337 Identifier name = ParseIdentifierOrStrictReservedWord( |
342 &is_strict_reserved, CHECK_OK); | 338 &is_strict_reserved, CHECK_OK); |
343 ParseFunctionLiteral(name, | 339 ParseFunctionLiteral(name, scanner()->location(), is_strict_reserved, |
344 scanner()->location(), | 340 is_generator ? FunctionKind::kGeneratorFunction |
345 is_strict_reserved, | 341 : FunctionKind::kNormalFunction, |
346 is_generator, | 342 pos, FunctionLiteral::DECLARATION, |
347 pos, | 343 FunctionLiteral::NORMAL_ARITY, CHECK_OK); |
348 FunctionLiteral::DECLARATION, | |
349 FunctionLiteral::NORMAL_ARITY, | |
350 CHECK_OK); | |
351 return Statement::FunctionDeclaration(); | 344 return Statement::FunctionDeclaration(); |
352 } | 345 } |
353 | 346 |
354 | 347 |
355 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 348 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
356 // Block :: | 349 // Block :: |
357 // '{' Statement* '}' | 350 // '{' Statement* '}' |
358 | 351 |
359 // Note that a Block does not introduce a new execution scope! | 352 // Note that a Block does not introduce a new execution scope! |
360 // (ECMA-262, 3rd, 12.2) | 353 // (ECMA-262, 3rd, 12.2) |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 | 791 |
799 #undef CHECK_OK | 792 #undef CHECK_OK |
800 #define CHECK_OK ok); \ | 793 #define CHECK_OK ok); \ |
801 if (!*ok) return Expression::Default(); \ | 794 if (!*ok) return Expression::Default(); \ |
802 ((void)0 | 795 ((void)0 |
803 #define DUMMY ) // to make indentation work | 796 #define DUMMY ) // to make indentation work |
804 #undef DUMMY | 797 #undef DUMMY |
805 | 798 |
806 | 799 |
807 PreParser::Expression PreParser::ParseFunctionLiteral( | 800 PreParser::Expression PreParser::ParseFunctionLiteral( |
808 Identifier function_name, | 801 Identifier function_name, Scanner::Location function_name_location, |
809 Scanner::Location function_name_location, | 802 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
810 bool name_is_strict_reserved, | |
811 bool is_generator, | |
812 int function_token_pos, | |
813 FunctionLiteral::FunctionType function_type, | 803 FunctionLiteral::FunctionType function_type, |
814 FunctionLiteral::ArityRestriction arity_restriction, | 804 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
815 bool* ok) { | |
816 // Function :: | 805 // Function :: |
817 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 806 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
818 | 807 |
819 // Parse function body. | 808 // Parse function body. |
820 ScopeType outer_scope_type = scope_->type(); | 809 ScopeType outer_scope_type = scope_->type(); |
821 PreParserScope function_scope(scope_, FUNCTION_SCOPE); | 810 PreParserScope function_scope(scope_, FUNCTION_SCOPE); |
822 FunctionState function_state(&function_state_, &scope_, &function_scope, NULL, | 811 FunctionState function_state(&function_state_, &scope_, &function_scope, NULL, |
823 this->ast_value_factory()); | 812 this->ast_value_factory()); |
824 function_state.set_is_generator(is_generator); | 813 function_state.set_is_generator(IsGeneratorFunction(kind)); |
825 // FormalParameterList :: | 814 // FormalParameterList :: |
826 // '(' (Identifier)*[','] ')' | 815 // '(' (Identifier)*[','] ')' |
827 Expect(Token::LPAREN, CHECK_OK); | 816 Expect(Token::LPAREN, CHECK_OK); |
828 int start_position = position(); | 817 int start_position = position(); |
829 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 818 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
830 // We don't yet know if the function will be strict, so we cannot yet produce | 819 // We don't yet know if the function will be strict, so we cannot yet produce |
831 // errors for parameter names or duplicates. However, we remember the | 820 // errors for parameter names or duplicates. However, we remember the |
832 // locations of these errors if they occur and produce the errors later. | 821 // locations of these errors if they occur and produce the errors later. |
833 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); | 822 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); |
834 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 823 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 Expect(Token::LBRACE, CHECK_OK); | 858 Expect(Token::LBRACE, CHECK_OK); |
870 if (is_lazily_parsed) { | 859 if (is_lazily_parsed) { |
871 ParseLazyFunctionLiteralBody(CHECK_OK); | 860 ParseLazyFunctionLiteralBody(CHECK_OK); |
872 } else { | 861 } else { |
873 ParseSourceElements(Token::RBRACE, ok); | 862 ParseSourceElements(Token::RBRACE, ok); |
874 } | 863 } |
875 Expect(Token::RBRACE, CHECK_OK); | 864 Expect(Token::RBRACE, CHECK_OK); |
876 | 865 |
877 // Validate strict mode. We can do this only after parsing the function, | 866 // Validate strict mode. We can do this only after parsing the function, |
878 // since the function can declare itself strict. | 867 // since the function can declare itself strict. |
879 if (strict_mode() == STRICT) { | 868 // Concise methods use StrictFormalParameters. |
| 869 if (strict_mode() == STRICT || IsConciseMethod(kind)) { |
880 if (function_name.IsEvalOrArguments()) { | 870 if (function_name.IsEvalOrArguments()) { |
881 ReportMessageAt(function_name_location, "strict_eval_arguments"); | 871 ReportMessageAt(function_name_location, "strict_eval_arguments"); |
882 *ok = false; | 872 *ok = false; |
883 return Expression::Default(); | 873 return Expression::Default(); |
884 } | 874 } |
885 if (name_is_strict_reserved) { | 875 if (name_is_strict_reserved) { |
886 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); | 876 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); |
887 *ok = false; | 877 *ok = false; |
888 return Expression::Default(); | 878 return Expression::Default(); |
889 } | 879 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 928 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
939 ParseArguments(ok); | 929 ParseArguments(ok); |
940 | 930 |
941 return Expression::Default(); | 931 return Expression::Default(); |
942 } | 932 } |
943 | 933 |
944 #undef CHECK_OK | 934 #undef CHECK_OK |
945 | 935 |
946 | 936 |
947 } } // v8::internal | 937 } } // v8::internal |
OLD | NEW |