Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1457)

Side by Side Diff: src/parser.cc

Issue 1423663006: [es7] Implement async functions parsing Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects-inl.h ('k') | src/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 "src/parser.h" 5 #include "src/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/ast-literal-reindexer.h" 9 #include "src/ast-literal-reindexer.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); 920 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let);
921 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); 921 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters);
922 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters); 922 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters);
923 set_allow_harmony_spread_calls(FLAG_harmony_spread_calls); 923 set_allow_harmony_spread_calls(FLAG_harmony_spread_calls);
924 set_allow_harmony_destructuring(FLAG_harmony_destructuring); 924 set_allow_harmony_destructuring(FLAG_harmony_destructuring);
925 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); 925 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays);
926 set_allow_harmony_new_target(FLAG_harmony_new_target); 926 set_allow_harmony_new_target(FLAG_harmony_new_target);
927 set_allow_strong_mode(FLAG_strong_mode); 927 set_allow_strong_mode(FLAG_strong_mode);
928 set_allow_legacy_const(FLAG_legacy_const); 928 set_allow_legacy_const(FLAG_legacy_const);
929 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); 929 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
930 set_allow_harmony_async_await(FLAG_harmony_async_await);
930 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 931 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
931 ++feature) { 932 ++feature) {
932 use_counts_[feature] = 0; 933 use_counts_[feature] = 0;
933 } 934 }
934 if (info->ast_value_factory() == NULL) { 935 if (info->ast_value_factory() == NULL) {
935 // info takes ownership of AstValueFactory. 936 // info takes ownership of AstValueFactory.
936 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); 937 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed()));
937 info->set_ast_value_factory_owned(); 938 info->set_ast_value_factory_owned();
938 ast_value_factory_ = info->ast_value_factory(); 939 ast_value_factory_ = info->ast_value_factory();
939 } 940 }
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 // Statement 1402 // Statement
1402 // Declaration 1403 // Declaration
1403 1404
1404 if (peek() != Token::CLASS) { 1405 if (peek() != Token::CLASS) {
1405 // No more classes follow; reset the start position for the consecutive 1406 // No more classes follow; reset the start position for the consecutive
1406 // class declaration group. 1407 // class declaration group.
1407 scope_->set_class_declaration_group_start(-1); 1408 scope_->set_class_declaration_group_start(-1);
1408 } 1409 }
1409 1410
1410 switch (peek()) { 1411 switch (peek()) {
1412 case Token::ASYNC:
1413 if (allow_harmony_async_await() && IsNextAsyncFunctionKeyword()) {
1414 return ParseFunctionDeclaration(NULL, ok);
1415 }
1416 break;
1411 case Token::FUNCTION: 1417 case Token::FUNCTION:
1412 return ParseFunctionDeclaration(NULL, ok); 1418 return ParseFunctionDeclaration(NULL, ok);
1413 case Token::CLASS: 1419 case Token::CLASS:
1414 if (scope_->class_declaration_group_start() < 0) { 1420 if (scope_->class_declaration_group_start() < 0) {
1415 scope_->set_class_declaration_group_start( 1421 scope_->set_class_declaration_group_start(
1416 scanner()->peek_location().beg_pos); 1422 scanner()->peek_location().beg_pos);
1417 } 1423 }
1418 return ParseClassDeclaration(NULL, ok); 1424 return ParseClassDeclaration(NULL, ok);
1419 case Token::CONST: 1425 case Token::CONST:
1420 if (allow_const()) { 1426 if (allow_const()) {
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 factory()->NewAssignment( 2228 factory()->NewAssignment(
2223 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition), 2229 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition),
2224 pos); 2230 pos);
2225 } 2231 }
2226 2232
2227 2233
2228 Statement* Parser::ParseFunctionDeclaration( 2234 Statement* Parser::ParseFunctionDeclaration(
2229 ZoneList<const AstRawString*>* names, bool* ok) { 2235 ZoneList<const AstRawString*>* names, bool* ok) {
2230 // FunctionDeclaration :: 2236 // FunctionDeclaration ::
2231 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 2237 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
2238 // AsyncFunctionDeclaration ::
2239 // 'async' 'function' Identifier '(' FormalParameterListopt ')'
2240 // '{' FunctionBody '}'
2232 // GeneratorDeclaration :: 2241 // GeneratorDeclaration ::
2233 // 'function' '*' Identifier '(' FormalParameterListopt ')' 2242 // 'function' '*' Identifier '(' FormalParameterListopt ')'
2234 // '{' FunctionBody '}' 2243 // '{' FunctionBody '}'
2244 bool is_async = allow_harmony_async_await() ? Check(Token::ASYNC) : false;
2235 Expect(Token::FUNCTION, CHECK_OK); 2245 Expect(Token::FUNCTION, CHECK_OK);
2236 int pos = position(); 2246 int pos = position();
2237 bool is_generator = Check(Token::MUL); 2247 bool is_generator = is_async ? false : Check(Token::MUL);
2238 bool is_strict_reserved = false; 2248 bool is_strict_reserved = false;
2239 const AstRawString* name = ParseIdentifierOrStrictReservedWord( 2249 const AstRawString* name = ParseIdentifierOrStrictReservedWord(
2240 &is_strict_reserved, CHECK_OK); 2250 &is_strict_reserved, CHECK_OK);
2241 2251
2242 if (fni_ != NULL) { 2252 if (fni_ != NULL) {
2243 fni_->Enter(); 2253 fni_->Enter();
2244 fni_->PushEnclosingName(name); 2254 fni_->PushEnclosingName(name);
2245 } 2255 }
2256
2257 FunctionKind kind = FunctionKind::kNormalFunction;
2258 if (is_generator) {
2259 kind = FunctionKind::kGeneratorFunction;
2260 } else if (is_async) {
2261 kind = FunctionKind::kAsyncFunction;
2262 }
2263
2246 FunctionLiteral* fun = ParseFunctionLiteral( 2264 FunctionLiteral* fun = ParseFunctionLiteral(
2247 name, scanner()->location(), 2265 name, scanner()->location(),
2248 is_strict_reserved ? kFunctionNameIsStrictReserved 2266 is_strict_reserved ? kFunctionNameIsStrictReserved
2249 : kFunctionNameValidityUnknown, 2267 : kFunctionNameValidityUnknown,
2250 is_generator ? FunctionKind::kGeneratorFunction 2268 kind, pos, FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY,
2251 : FunctionKind::kNormalFunction,
2252 pos, FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY,
2253 language_mode(), CHECK_OK); 2269 language_mode(), CHECK_OK);
2254 if (fni_ != NULL) fni_->Leave(); 2270 if (fni_ != NULL) fni_->Leave();
2255 2271
2256 // Even if we're not at the top-level of the global or a function 2272 // Even if we're not at the top-level of the global or a function
2257 // scope, we treat it as such and introduce the function with its 2273 // scope, we treat it as such and introduce the function with its
2258 // initial value upon entering the corresponding scope. 2274 // initial value upon entering the corresponding scope.
2259 // In ES6, a function behaves as a lexical binding, except in 2275 // In ES6, a function behaves as a lexical binding, except in
2260 // a script scope, or the initial scope of eval or another function. 2276 // a script scope, or the initial scope of eval or another function.
2261 VariableMode mode = 2277 VariableMode mode =
2262 is_strong(language_mode()) 2278 is_strong(language_mode())
(...skipping 2548 matching lines...) Expand 10 before | Expand all | Expand 10 after
4811 SET_ALLOW(harmony_sloppy); 4827 SET_ALLOW(harmony_sloppy);
4812 SET_ALLOW(harmony_sloppy_let); 4828 SET_ALLOW(harmony_sloppy_let);
4813 SET_ALLOW(harmony_rest_parameters); 4829 SET_ALLOW(harmony_rest_parameters);
4814 SET_ALLOW(harmony_default_parameters); 4830 SET_ALLOW(harmony_default_parameters);
4815 SET_ALLOW(harmony_spread_calls); 4831 SET_ALLOW(harmony_spread_calls);
4816 SET_ALLOW(harmony_destructuring); 4832 SET_ALLOW(harmony_destructuring);
4817 SET_ALLOW(harmony_spread_arrays); 4833 SET_ALLOW(harmony_spread_arrays);
4818 SET_ALLOW(harmony_new_target); 4834 SET_ALLOW(harmony_new_target);
4819 SET_ALLOW(strong_mode); 4835 SET_ALLOW(strong_mode);
4820 SET_ALLOW(harmony_do_expressions); 4836 SET_ALLOW(harmony_do_expressions);
4837 SET_ALLOW(harmony_async_await);
4821 #undef SET_ALLOW 4838 #undef SET_ALLOW
4822 } 4839 }
4823 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4840 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4824 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), 4841 language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
4825 logger, bookmark); 4842 logger, bookmark);
4826 if (pre_parse_timer_ != NULL) { 4843 if (pre_parse_timer_ != NULL) {
4827 pre_parse_timer_->Stop(); 4844 pre_parse_timer_->Stop();
4828 } 4845 }
4829 return result; 4846 return result;
4830 } 4847 }
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after
6387 6404
6388 Expression* Parser::SpreadCallNew(Expression* function, 6405 Expression* Parser::SpreadCallNew(Expression* function,
6389 ZoneList<v8::internal::Expression*>* args, 6406 ZoneList<v8::internal::Expression*>* args,
6390 int pos) { 6407 int pos) {
6391 args->InsertAt(0, function, zone()); 6408 args->InsertAt(0, function, zone());
6392 6409
6393 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6410 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6394 } 6411 }
6395 } // namespace internal 6412 } // namespace internal
6396 } // namespace v8 6413 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698