OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 | 129 |
130 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { | 130 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { |
131 return pre_parser_->ParseV8Intrinsic(ok); | 131 return pre_parser_->ParseV8Intrinsic(ok); |
132 } | 132 } |
133 | 133 |
134 | 134 |
135 PreParserExpression PreParserTraits::ParseFunctionLiteral( | 135 PreParserExpression PreParserTraits::ParseFunctionLiteral( |
136 PreParserIdentifier name, | 136 PreParserIdentifier name, |
137 Scanner::Location function_name_location, | 137 Scanner::Location function_name_location, |
138 bool name_is_strict_reserved, | 138 bool name_is_strict_reserved, |
139 bool is_generator, | 139 FunctionParsingMode parsing_mode, |
140 PreParserExpression params_ast, | |
140 int function_token_position, | 141 int function_token_position, |
141 FunctionLiteral::FunctionType type, | 142 FunctionLiteral::FunctionType type, |
142 bool* ok) { | 143 bool* ok) { |
143 return pre_parser_->ParseFunctionLiteral( | 144 return pre_parser_->ParseFunctionLiteral( |
144 name, function_name_location, name_is_strict_reserved, is_generator, | 145 name, function_name_location, name_is_strict_reserved, parsing_mode, |
145 function_token_position, type, ok); | 146 params_ast, function_token_position, type, ok); |
146 } | 147 } |
147 | 148 |
148 | 149 |
149 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 150 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
150 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { | 151 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { |
151 log_ = log; | 152 log_ = log; |
152 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 153 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
153 PreParserScope top_scope(scope_, GLOBAL_SCOPE); | 154 PreParserScope top_scope(scope_, GLOBAL_SCOPE); |
154 FunctionState top_state(&function_state_, &scope_, &top_scope); | 155 FunctionState top_state(&function_state_, &scope_, &top_scope); |
155 scope_->SetStrictMode(strict_mode); | 156 scope_->SetStrictMode(strict_mode); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 | 349 |
349 | 350 |
350 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { | 351 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
351 // FunctionDeclaration :: | 352 // FunctionDeclaration :: |
352 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 353 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
353 // GeneratorDeclaration :: | 354 // GeneratorDeclaration :: |
354 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 355 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
355 // '{' FunctionBody '}' | 356 // '{' FunctionBody '}' |
356 Expect(Token::FUNCTION, CHECK_OK); | 357 Expect(Token::FUNCTION, CHECK_OK); |
357 int pos = position(); | 358 int pos = position(); |
358 bool is_generator = allow_generators() && Check(Token::MUL); | 359 FunctionParsingMode parsing_mode = (allow_generators() && Check(Token::MUL)) |
360 ? kGeneratorFunction | |
361 : kNormalFunction; | |
359 bool is_strict_reserved = false; | 362 bool is_strict_reserved = false; |
360 Identifier name = ParseIdentifierOrStrictReservedWord( | 363 Identifier name = ParseIdentifierOrStrictReservedWord( |
361 &is_strict_reserved, CHECK_OK); | 364 &is_strict_reserved, CHECK_OK); |
362 ParseFunctionLiteral(name, | 365 ParseFunctionLiteral(name, |
363 scanner()->location(), | 366 scanner()->location(), |
364 is_strict_reserved, | 367 is_strict_reserved, |
365 is_generator, | 368 parsing_mode, |
369 EmptyExpression(), | |
366 pos, | 370 pos, |
367 FunctionLiteral::DECLARATION, | 371 FunctionLiteral::DECLARATION, |
368 CHECK_OK); | 372 CHECK_OK); |
369 return Statement::FunctionDeclaration(); | 373 return Statement::FunctionDeclaration(); |
370 } | 374 } |
371 | 375 |
372 | 376 |
373 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 377 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
374 // Block :: | 378 // Block :: |
375 // '{' Statement* '}' | 379 // '{' Statement* '}' |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
830 | 834 |
831 | 835 |
832 #undef CHECK_OK | 836 #undef CHECK_OK |
833 #define CHECK_OK ok); \ | 837 #define CHECK_OK ok); \ |
834 if (!*ok) return Expression::Default(); \ | 838 if (!*ok) return Expression::Default(); \ |
835 ((void)0 | 839 ((void)0 |
836 #define DUMMY ) // to make indentation work | 840 #define DUMMY ) // to make indentation work |
837 #undef DUMMY | 841 #undef DUMMY |
838 | 842 |
839 | 843 |
840 PreParser::Expression PreParser::ParseFunctionLiteral( | 844 PreParser::Expression PreParser::ParseFunctionLiteral( |
marja
2014/03/24 09:04:06
... this doesn't handle arrow funcs yet? (Like, si
aperez
2014/04/09 08:47:16
FWIW, I will add the tests, but provided that I am
| |
841 Identifier function_name, | 845 Identifier function_name, |
842 Scanner::Location function_name_location, | 846 Scanner::Location function_name_location, |
843 bool name_is_strict_reserved, | 847 bool name_is_strict_reserved, |
844 bool is_generator, | 848 FunctionParsingMode parsing_mode, |
849 PreParserExpression params_ast, | |
845 int function_token_pos, | 850 int function_token_pos, |
846 FunctionLiteral::FunctionType function_type, | 851 FunctionLiteral::FunctionType function_type, |
847 bool* ok) { | 852 bool* ok) { |
848 // Function :: | 853 // Function :: |
849 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 854 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
850 | 855 |
851 // Parse function body. | 856 // Parse function body. |
852 ScopeType outer_scope_type = scope_->type(); | 857 ScopeType outer_scope_type = scope_->type(); |
853 bool inside_with = scope_->inside_with(); | 858 bool inside_with = scope_->inside_with(); |
854 PreParserScope function_scope(scope_, FUNCTION_SCOPE); | 859 PreParserScope function_scope(scope_, FUNCTION_SCOPE); |
855 FunctionState function_state(&function_state_, &scope_, &function_scope); | 860 FunctionState function_state(&function_state_, &scope_, &function_scope); |
856 function_state.set_is_generator(is_generator); | 861 function_state.set_is_generator(parsing_mode == kGeneratorFunction); |
857 // FormalParameterList :: | 862 // FormalParameterList :: |
858 // '(' (Identifier)*[','] ')' | 863 // '(' (Identifier)*[','] ')' |
859 Expect(Token::LPAREN, CHECK_OK); | 864 Expect(Token::LPAREN, CHECK_OK); |
860 int start_position = position(); | 865 int start_position = position(); |
861 bool done = (peek() == Token::RPAREN); | 866 bool done = (peek() == Token::RPAREN); |
862 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 867 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
863 // We don't yet know if the function will be strict, so we cannot yet produce | 868 // We don't yet know if the function will be strict, so we cannot yet produce |
864 // errors for parameter names or duplicates. However, we remember the | 869 // errors for parameter names or duplicates. However, we remember the |
865 // locations of these errors if they occur and produce the errors later. | 870 // locations of these errors if they occur and produce the errors later. |
866 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); | 871 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 | 984 |
980 | 985 |
981 void PreParser::LogSymbol() { | 986 void PreParser::LogSymbol() { |
982 if (log_->ShouldLogSymbols()) { | 987 if (log_->ShouldLogSymbols()) { |
983 scanner()->LogSymbol(log_, position()); | 988 scanner()->LogSymbol(log_, position()); |
984 } | 989 } |
985 } | 990 } |
986 | 991 |
987 | 992 |
988 } } // v8::internal | 993 } } // v8::internal |
OLD | NEW |