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

Side by Side Diff: src/parsing/parser-base.h

Issue 2488493003: [inspector] fix positions for single expression arrow function (Closed)
Patch Set: addressed comments Created 4 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/parsing/parser.cc ('k') | src/parsing/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 #ifndef V8_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 2258 matching lines...) Expand 10 before | Expand all | Expand 10 after
2269 } 2269 }
2270 initializer_scope->set_end_position(scanner()->location().end_pos); 2270 initializer_scope->set_end_position(scanner()->location().end_pos);
2271 typename Types::StatementList body = impl()->NewStatementList(1); 2271 typename Types::StatementList body = impl()->NewStatementList(1);
2272 body->Add(factory()->NewReturnStatement(value, kNoSourcePosition), zone()); 2272 body->Add(factory()->NewReturnStatement(value, kNoSourcePosition), zone());
2273 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( 2273 FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
2274 impl()->EmptyIdentifierString(), initializer_scope, body, 2274 impl()->EmptyIdentifierString(), initializer_scope, body,
2275 initializer_state.materialized_literal_count(), 2275 initializer_state.materialized_literal_count(),
2276 initializer_state.expected_property_count(), 0, 0, 2276 initializer_state.expected_property_count(), 0, 0,
2277 FunctionLiteral::kNoDuplicateParameters, 2277 FunctionLiteral::kNoDuplicateParameters,
2278 FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_, 2278 FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_,
2279 initializer_scope->start_position()); 2279 initializer_scope->start_position(), true);
2280 function_literal->set_is_class_field_initializer(true); 2280 function_literal->set_is_class_field_initializer(true);
2281 return function_literal; 2281 return function_literal;
2282 } 2282 }
2283 2283
2284 template <typename Impl> 2284 template <typename Impl>
2285 typename ParserBase<Impl>::ObjectLiteralPropertyT 2285 typename ParserBase<Impl>::ObjectLiteralPropertyT
2286 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, 2286 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker,
2287 bool* is_computed_name, 2287 bool* is_computed_name,
2288 bool* ok) { 2288 bool* ok) {
2289 bool is_get = false; 2289 bool is_get = false;
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after
3903 FunctionKind kind = formal_parameters.scope->function_kind(); 3903 FunctionKind kind = formal_parameters.scope->function_kind();
3904 FunctionLiteral::EagerCompileHint eager_compile_hint = 3904 FunctionLiteral::EagerCompileHint eager_compile_hint =
3905 default_eager_compile_hint_; 3905 default_eager_compile_hint_;
3906 bool can_preparse = impl()->parse_lazily() && 3906 bool can_preparse = impl()->parse_lazily() &&
3907 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; 3907 eager_compile_hint == FunctionLiteral::kShouldLazyCompile;
3908 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this 3908 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this
3909 // handling in Scope::ResolveVariable needs to change. 3909 // handling in Scope::ResolveVariable needs to change.
3910 bool is_lazy_top_level_function = 3910 bool is_lazy_top_level_function =
3911 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); 3911 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables();
3912 bool should_be_used_once_hint = false; 3912 bool should_be_used_once_hint = false;
3913 bool has_braces = true;
3913 { 3914 {
3914 FunctionState function_state(&function_state_, &scope_state_, 3915 FunctionState function_state(&function_state_, &scope_state_,
3915 formal_parameters.scope); 3916 formal_parameters.scope);
3916 3917
3917 function_state.SkipMaterializedLiterals( 3918 function_state.SkipMaterializedLiterals(
3918 formal_parameters.materialized_literals_count); 3919 formal_parameters.materialized_literals_count);
3919 3920
3920 impl()->ReindexLiterals(formal_parameters); 3921 impl()->ReindexLiterals(formal_parameters);
3921 3922
3922 Expect(Token::ARROW, CHECK_OK); 3923 Expect(Token::ARROW, CHECK_OK);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3965 Consume(Token::LBRACE); 3966 Consume(Token::LBRACE);
3966 body = impl()->ParseEagerFunctionBody( 3967 body = impl()->ParseEagerFunctionBody(
3967 impl()->EmptyIdentifier(), kNoSourcePosition, formal_parameters, 3968 impl()->EmptyIdentifier(), kNoSourcePosition, formal_parameters,
3968 kind, FunctionLiteral::kAnonymousExpression, CHECK_OK); 3969 kind, FunctionLiteral::kAnonymousExpression, CHECK_OK);
3969 materialized_literal_count = 3970 materialized_literal_count =
3970 function_state.materialized_literal_count(); 3971 function_state.materialized_literal_count();
3971 expected_property_count = function_state.expected_property_count(); 3972 expected_property_count = function_state.expected_property_count();
3972 } 3973 }
3973 } else { 3974 } else {
3974 // Single-expression body 3975 // Single-expression body
3976 has_braces = false;
3975 int pos = position(); 3977 int pos = position();
3976 DCHECK(ReturnExprContext::kInsideValidBlock == 3978 DCHECK(ReturnExprContext::kInsideValidBlock ==
3977 function_state_->return_expr_context()); 3979 function_state_->return_expr_context());
3978 ReturnExprScope allow_tail_calls( 3980 ReturnExprScope allow_tail_calls(
3979 function_state_, ReturnExprContext::kInsideValidReturnStatement); 3981 function_state_, ReturnExprContext::kInsideValidReturnStatement);
3980 body = impl()->NewStatementList(1); 3982 body = impl()->NewStatementList(1);
3981 impl()->AddParameterInitializationBlock( 3983 impl()->AddParameterInitializationBlock(
3982 formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK); 3984 formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK);
3983 ExpressionClassifier classifier(this); 3985 ExpressionClassifier classifier(this);
3984 if (kind == kAsyncArrowFunction) { 3986 if (kind == kAsyncArrowFunction) {
3985 ParseAsyncFunctionBody(scope(), body, kAsyncArrowFunction, 3987 ParseAsyncFunctionBody(scope(), body, kAsyncArrowFunction,
3986 FunctionBodyType::kSingleExpression, accept_IN, 3988 FunctionBodyType::kSingleExpression, accept_IN,
3987 pos, CHECK_OK); 3989 pos, CHECK_OK);
3988 impl()->RewriteNonPattern(CHECK_OK); 3990 impl()->RewriteNonPattern(CHECK_OK);
3989 } else { 3991 } else {
3990 ExpressionT expression = ParseAssignmentExpression(accept_IN, CHECK_OK); 3992 ExpressionT expression = ParseAssignmentExpression(accept_IN, CHECK_OK);
3991 impl()->RewriteNonPattern(CHECK_OK); 3993 impl()->RewriteNonPattern(CHECK_OK);
3992 body->Add(factory()->NewReturnStatement(expression, pos), zone()); 3994 body->Add(
3995 factory()->NewReturnStatement(expression, expression->position()),
3996 zone());
3993 if (allow_tailcalls() && !is_sloppy(language_mode())) { 3997 if (allow_tailcalls() && !is_sloppy(language_mode())) {
3994 // ES6 14.6.1 Static Semantics: IsInTailPosition 3998 // ES6 14.6.1 Static Semantics: IsInTailPosition
3995 impl()->MarkTailPosition(expression); 3999 impl()->MarkTailPosition(expression);
3996 } 4000 }
3997 } 4001 }
3998 materialized_literal_count = function_state.materialized_literal_count(); 4002 materialized_literal_count = function_state.materialized_literal_count();
3999 expected_property_count = function_state.expected_property_count(); 4003 expected_property_count = function_state.expected_property_count();
4000 impl()->MarkCollectedTailCallExpressions(); 4004 impl()->MarkCollectedTailCallExpressions();
4001 } 4005 }
4002 4006
(...skipping 22 matching lines...) Expand all
4025 PrintF(" [%s]: %i-%i (arrow function)\n", 4029 PrintF(" [%s]: %i-%i (arrow function)\n",
4026 is_lazy_top_level_function ? "Preparse no-resolution" : "Full parse", 4030 is_lazy_top_level_function ? "Preparse no-resolution" : "Full parse",
4027 scope->start_position(), scope->end_position()); 4031 scope->start_position(), scope->end_position());
4028 } 4032 }
4029 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( 4033 FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
4030 impl()->EmptyIdentifierString(), formal_parameters.scope, body, 4034 impl()->EmptyIdentifierString(), formal_parameters.scope, body,
4031 materialized_literal_count, expected_property_count, 4035 materialized_literal_count, expected_property_count,
4032 formal_parameters.num_parameters(), formal_parameters.function_length, 4036 formal_parameters.num_parameters(), formal_parameters.function_length,
4033 FunctionLiteral::kNoDuplicateParameters, 4037 FunctionLiteral::kNoDuplicateParameters,
4034 FunctionLiteral::kAnonymousExpression, eager_compile_hint, 4038 FunctionLiteral::kAnonymousExpression, eager_compile_hint,
4035 formal_parameters.scope->start_position()); 4039 formal_parameters.scope->start_position(), has_braces);
4036 4040
4037 function_literal->set_function_token_position( 4041 function_literal->set_function_token_position(
4038 formal_parameters.scope->start_position()); 4042 formal_parameters.scope->start_position());
4039 if (should_be_used_once_hint) { 4043 if (should_be_used_once_hint) {
4040 function_literal->set_should_be_used_once_hint(); 4044 function_literal->set_should_be_used_once_hint();
4041 } 4045 }
4042 4046
4043 impl()->AddFunctionForNameInference(function_literal); 4047 impl()->AddFunctionForNameInference(function_literal);
4044 4048
4045 return function_literal; 4049 return function_literal;
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after
5442 has_seen_constructor_ = true; 5446 has_seen_constructor_ = true;
5443 return; 5447 return;
5444 } 5448 }
5445 } 5449 }
5446 5450
5447 5451
5448 } // namespace internal 5452 } // namespace internal
5449 } // namespace v8 5453 } // namespace v8
5450 5454
5451 #endif // V8_PARSING_PARSER_BASE_H 5455 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698