Commit dd4ce25c authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] fix positions for single expression arrow function

Currently function like "() => 239" contains offset 3 as begin of function and 8 as end of function.
This CL changes this to 6 and 9 respectively.

BUG=chromium:566801
R=yangguo@chromium.org,dgozman@chromium.org
TBR=adamk@chromium.org
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_precise_blink_rel

Review-Url: https://codereview.chromium.org/2488493003
Cr-Commit-Position: refs/heads/master@{#40864}
parent 12af4128
......@@ -2707,6 +2707,10 @@ class FunctionLiteral final : public Expression {
IsClassFieldInitializer::update(bit_field_, is_class_field_initializer);
}
int return_position() {
return std::max(start_position(), end_position() - (has_braces_ ? 1 : 0));
}
private:
friend class AstNodeFactory;
......@@ -2717,7 +2721,7 @@ class FunctionLiteral final : public Expression {
int function_length, FunctionType function_type,
ParameterFlag has_duplicate_parameters,
EagerCompileHint eager_compile_hint, int position,
bool is_function)
bool is_function, bool has_braces)
: Expression(position, kFunctionLiteral),
materialized_literal_count_(materialized_literal_count),
expected_property_count_(expected_property_count),
......@@ -2725,6 +2729,7 @@ class FunctionLiteral final : public Expression {
function_length_(function_length),
function_token_position_(kNoSourcePosition),
yield_count_(0),
has_braces_(has_braces),
raw_name_(name),
scope_(scope),
body_(body),
......@@ -2762,6 +2767,7 @@ class FunctionLiteral final : public Expression {
int function_length_;
int function_token_position_;
int yield_count_;
bool has_braces_;
const AstString* raw_name_;
DeclarationScope* scope_;
......@@ -3457,12 +3463,13 @@ class AstNodeFactory final BASE_EMBEDDED {
int expected_property_count, int parameter_count, int function_length,
FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type,
FunctionLiteral::EagerCompileHint eager_compile_hint, int position) {
FunctionLiteral::EagerCompileHint eager_compile_hint, int position,
bool has_braces) {
return new (zone_) FunctionLiteral(
zone_, name, ast_value_factory_, scope, body,
materialized_literal_count, expected_property_count, parameter_count,
function_length, function_type, has_duplicate_parameters,
eager_compile_hint, position, true);
eager_compile_hint, position, true, has_braces);
}
// Creates a FunctionLiteral representing a top-level script, the
......@@ -3477,7 +3484,7 @@ class AstNodeFactory final BASE_EMBEDDED {
body, materialized_literal_count, expected_property_count,
parameter_count, parameter_count, FunctionLiteral::kAnonymousExpression,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kShouldLazyCompile, 0, false);
FunctionLiteral::kShouldLazyCompile, 0, false, true);
}
ClassLiteral::Property* NewClassLiteralProperty(
......
......@@ -682,8 +682,7 @@ void FullCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) {
void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) {
// For default constructors, start position equals end position, and there
// is no source code besides the class literal.
int pos = std::max(fun->start_position(), fun->end_position() - 1);
RecordStatementPosition(pos);
RecordStatementPosition(fun->return_position());
if (info_->is_debug()) {
// Always emit a debug break slot before a return.
DebugCodegen::GenerateSlot(masm_, RelocInfo::DEBUG_BREAK_SLOT_AT_RETURN);
......
......@@ -51,9 +51,7 @@ BytecodeArrayBuilder::BytecodeArrayBuilder(
pipeline_);
}
return_position_ =
literal ? std::max(literal->start_position(), literal->end_position() - 1)
: kNoSourcePosition;
return_position_ = literal ? literal->return_position() : kNoSourcePosition;
}
Register BytecodeArrayBuilder::first_context_register() const {
......
......@@ -2276,7 +2276,7 @@ ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer,
initializer_state.expected_property_count(), 0, 0,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_,
initializer_scope->start_position());
initializer_scope->start_position(), true);
function_literal->set_is_class_field_initializer(true);
return function_literal;
}
......@@ -3910,6 +3910,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
bool is_lazy_top_level_function =
can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables();
bool should_be_used_once_hint = false;
bool has_braces = true;
{
FunctionState function_state(&function_state_, &scope_state_,
formal_parameters.scope);
......@@ -3972,6 +3973,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
}
} else {
// Single-expression body
has_braces = false;
int pos = position();
DCHECK(ReturnExprContext::kInsideValidBlock ==
function_state_->return_expr_context());
......@@ -3989,7 +3991,9 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
} else {
ExpressionT expression = ParseAssignmentExpression(accept_IN, CHECK_OK);
impl()->RewriteNonPattern(CHECK_OK);
body->Add(factory()->NewReturnStatement(expression, pos), zone());
body->Add(
factory()->NewReturnStatement(expression, expression->position()),
zone());
if (allow_tailcalls() && !is_sloppy(language_mode())) {
// ES6 14.6.1 Static Semantics: IsInTailPosition
impl()->MarkTailPosition(expression);
......@@ -4032,7 +4036,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
formal_parameters.num_parameters(), formal_parameters.function_length,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, eager_compile_hint,
formal_parameters.scope->start_position());
formal_parameters.scope->start_position(), has_braces);
function_literal->set_function_token_position(
formal_parameters.scope->start_position());
......
......@@ -285,7 +285,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
name, function_scope, body, materialized_literal_count,
expected_property_count, parameter_count, parameter_count,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, default_eager_compile_hint(), pos);
FunctionLiteral::kAnonymousExpression, default_eager_compile_hint(), pos,
true);
function_literal->set_requires_class_field_init(requires_class_field_init);
......@@ -2722,7 +2723,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
function_name, scope, body, materialized_literal_count,
expected_property_count, num_parameters, function_length,
duplicate_parameters, function_type, eager_compile_hint, pos);
duplicate_parameters, function_type, eager_compile_hint, pos, true);
function_literal->set_function_token_position(function_token_pos);
if (should_be_used_once_hint)
function_literal->set_should_be_used_once_hint();
......@@ -3416,7 +3417,8 @@ FunctionLiteral* Parser::SynthesizeClassFieldInitializer(int count) {
initializer_state.expected_property_count(), 0, count,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression,
FunctionLiteral::kShouldLazyCompile, initializer_scope->start_position());
FunctionLiteral::kShouldLazyCompile, initializer_scope->start_position(),
true);
function_literal->set_is_class_field_initializer(true);
return function_literal;
}
......
......@@ -661,7 +661,8 @@ class PreParserFactory {
int parameter_count, int function_length,
FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type,
FunctionLiteral::EagerCompileHint eager_compile_hint, int position) {
FunctionLiteral::EagerCompileHint eager_compile_hint, int position,
bool has_braces) {
return PreParserExpression::Default();
}
......
......@@ -88,12 +88,12 @@ Test end is undefined
scriptId : <scriptId>
}
[3] : {
columnNumber : 49
columnNumber : 52
lineNumber : 1
scriptId : <scriptId>
}
[4] : {
columnNumber : 53
columnNumber : 54
lineNumber : 1
scriptId : <scriptId>
}
......@@ -131,12 +131,12 @@ Test end.lineNumber > scripts.lineCount()
scriptId : <scriptId>
}
[3] : {
columnNumber : 49
columnNumber : 52
lineNumber : 1
scriptId : <scriptId>
}
[4] : {
columnNumber : 53
columnNumber : 54
lineNumber : 1
scriptId : <scriptId>
}
......@@ -201,37 +201,37 @@ Running test: getPossibleBreakpointsInArrow
scriptId : <scriptId>
}
[1] : {
columnNumber : 50
columnNumber : 53
lineNumber : 0
scriptId : <scriptId>
}
[2] : {
columnNumber : 55
columnNumber : 56
lineNumber : 0
scriptId : <scriptId>
}
[3] : {
columnNumber : 66
columnNumber : 69
lineNumber : 0
scriptId : <scriptId>
}
[4] : {
columnNumber : 70
columnNumber : 71
lineNumber : 0
scriptId : <scriptId>
}
[5] : {
columnNumber : 81
columnNumber : 84
lineNumber : 0
scriptId : <scriptId>
}
[6] : {
columnNumber : 87
columnNumber : 90
lineNumber : 0
scriptId : <scriptId>
}
[7] : {
columnNumber : 91
columnNumber : 92
lineNumber : 0
scriptId : <scriptId>
}
......@@ -255,12 +255,12 @@ Running test: arrowFunctionFirstLine
scriptId : <scriptId>
}
[1] : {
columnNumber : 44
columnNumber : 47
lineNumber : 0
scriptId : <scriptId>
}
[2] : {
columnNumber : 48
columnNumber : 49
lineNumber : 0
scriptId : <scriptId>
}
......@@ -287,7 +287,7 @@ Running test: arrowFunctionFirstLine
id : <messageId>
result : {
actualLocation : {
columnNumber : 44
columnNumber : 47
lineNumber : 0
scriptId : <scriptId>
}
......@@ -298,7 +298,7 @@ Running test: arrowFunctionFirstLine
id : <messageId>
result : {
actualLocation : {
columnNumber : 48
columnNumber : 49
lineNumber : 0
scriptId : <scriptId>
}
......@@ -330,13 +330,13 @@ paused in foo1
}
paused in Promise.resolve.then
{
columnNumber : 44
columnNumber : 47
lineNumber : 0
scriptId : <scriptId>
}
paused in Promise.resolve.then
{
columnNumber : 48
columnNumber : 49
lineNumber : 0
scriptId : <scriptId>
}
......@@ -357,12 +357,12 @@ Running test: arrowFunctionOnPause
scriptId : <scriptId>
}
[2] : {
columnNumber : 54
columnNumber : 57
lineNumber : 0
scriptId : <scriptId>
}
[3] : {
columnNumber : 58
columnNumber : 59
lineNumber : 0
scriptId : <scriptId>
}
......@@ -377,12 +377,12 @@ Running test: arrowFunctionOnPause
scriptId : <scriptId>
}
[6] : {
columnNumber : 44
columnNumber : 47
lineNumber : 1
scriptId : <scriptId>
}
[7] : {
columnNumber : 48
columnNumber : 49
lineNumber : 1
scriptId : <scriptId>
}
......@@ -435,7 +435,7 @@ Running test: arrowFunctionOnPause
id : <messageId>
result : {
actualLocation : {
columnNumber : 54
columnNumber : 57
lineNumber : 0
scriptId : <scriptId>
}
......@@ -446,7 +446,7 @@ Running test: arrowFunctionOnPause
id : <messageId>
result : {
actualLocation : {
columnNumber : 58
columnNumber : 59
lineNumber : 0
scriptId : <scriptId>
}
......@@ -479,7 +479,7 @@ Running test: arrowFunctionOnPause
id : <messageId>
result : {
actualLocation : {
columnNumber : 44
columnNumber : 47
lineNumber : 1
scriptId : <scriptId>
}
......@@ -490,7 +490,7 @@ Running test: arrowFunctionOnPause
id : <messageId>
result : {
actualLocation : {
columnNumber : 48
columnNumber : 49
lineNumber : 1
scriptId : <scriptId>
}
......@@ -567,25 +567,25 @@ paused in foo4
}
paused in Promise.resolve.then
{
columnNumber : 54
columnNumber : 57
lineNumber : 0
scriptId : <scriptId>
}
paused in Promise.resolve.then
{
columnNumber : 58
columnNumber : 59
lineNumber : 0
scriptId : <scriptId>
}
paused in Promise.resolve.then
{
columnNumber : 44
columnNumber : 47
lineNumber : 1
scriptId : <scriptId>
}
paused in Promise.resolve.then
{
columnNumber : 48
columnNumber : 49
lineNumber : 1
scriptId : <scriptId>
}
......@@ -654,12 +654,12 @@ Test end is undefined
scriptId : <scriptId>
}
[3] : {
columnNumber : 49
columnNumber : 52
lineNumber : 2
scriptId : <scriptId>
}
[4] : {
columnNumber : 53
columnNumber : 54
lineNumber : 2
scriptId : <scriptId>
}
......@@ -697,12 +697,12 @@ Test end.lineNumber > scripts.lineCount()
scriptId : <scriptId>
}
[3] : {
columnNumber : 49
columnNumber : 52
lineNumber : 2
scriptId : <scriptId>
}
[4] : {
columnNumber : 53
columnNumber : 54
lineNumber : 2
scriptId : <scriptId>
}
......@@ -767,12 +767,12 @@ Running test: withOffset
scriptId : <scriptId>
}
[1] : {
columnNumber : 62
columnNumber : 65
lineNumber : 3
scriptId : <scriptId>
}
[2] : {
columnNumber : 66
columnNumber : 67
lineNumber : 3
scriptId : <scriptId>
}
......@@ -787,12 +787,12 @@ Running test: withOffset
scriptId : <scriptId>
}
[5] : {
columnNumber : 44
columnNumber : 47
lineNumber : 4
scriptId : <scriptId>
}
[6] : {
columnNumber : 48
columnNumber : 49
lineNumber : 4
scriptId : <scriptId>
}
......@@ -819,7 +819,7 @@ Running test: withOffset
id : <messageId>
result : {
actualLocation : {
columnNumber : 62
columnNumber : 65
lineNumber : 3
scriptId : <scriptId>
}
......@@ -830,7 +830,7 @@ Running test: withOffset
id : <messageId>
result : {
actualLocation : {
columnNumber : 66
columnNumber : 67
lineNumber : 3
scriptId : <scriptId>
}
......@@ -863,7 +863,7 @@ Running test: withOffset
id : <messageId>
result : {
actualLocation : {
columnNumber : 44
columnNumber : 47
lineNumber : 4
scriptId : <scriptId>
}
......@@ -874,7 +874,7 @@ Running test: withOffset
id : <messageId>
result : {
actualLocation : {
columnNumber : 48
columnNumber : 49
lineNumber : 4
scriptId : <scriptId>
}
......@@ -918,25 +918,174 @@ paused in foo6
}
paused in Promise.resolve.then
{
columnNumber : 62
columnNumber : 65
lineNumber : 3
scriptId : <scriptId>
}
paused in Promise.resolve.then
{
columnNumber : 66
columnNumber : 67
lineNumber : 3
scriptId : <scriptId>
}
paused in Promise.resolve.then
{
columnNumber : 44
columnNumber : 47
lineNumber : 4
scriptId : <scriptId>
}
paused in Promise.resolve.then
{
columnNumber : 48
columnNumber : 49
lineNumber : 4
scriptId : <scriptId>
}
Running test: arrowFunctionReturn
{
id : <messageId>
result : {
locations : [
[0] : {
columnNumber : 0
lineNumber : 0
scriptId : <scriptId>
}
[1] : {
columnNumber : 6
lineNumber : 0
scriptId : <scriptId>
}
[2] : {
columnNumber : 9
lineNumber : 0
scriptId : <scriptId>
}
]
}
}
{
id : <messageId>
result : {
locations : [
[0] : {
columnNumber : 34
lineNumber : 0
scriptId : <scriptId>
}
[1] : {
columnNumber : 45
lineNumber : 0
scriptId : <scriptId>
}
[2] : {
columnNumber : 48
lineNumber : 0
scriptId : <scriptId>
}
[3] : {
columnNumber : 49
lineNumber : 0
scriptId : <scriptId>
}
]
}
}
{
id : <messageId>
result : {
locations : [
[0] : {
columnNumber : 0
lineNumber : 0
scriptId : <scriptId>
}
[1] : {
columnNumber : 8
lineNumber : 0
scriptId : <scriptId>
}
[2] : {
columnNumber : 12
lineNumber : 0
scriptId : <scriptId>
}
[3] : {
columnNumber : 13
lineNumber : 0
scriptId : <scriptId>
}
]
}
}
{
id : <messageId>
result : {
locations : [
[0] : {
columnNumber : 17
lineNumber : 0
scriptId : <scriptId>
}
[1] : {
columnNumber : 21
lineNumber : 0
scriptId : <scriptId>
}
[2] : {
columnNumber : 22
lineNumber : 0
scriptId : <scriptId>
}
]
}
}
{
id : <messageId>
result : {
locations : [
[0] : {
columnNumber : 0
lineNumber : 0
scriptId : <scriptId>
}
[1] : {
columnNumber : 6
lineNumber : 0
scriptId : <scriptId>
}
[2] : {
columnNumber : 8
lineNumber : 0
scriptId : <scriptId>
}
[3] : {
columnNumber : 9
lineNumber : 0
scriptId : <scriptId>
}
]
}
}
{
id : <messageId>
result : {
locations : [
[0] : {
columnNumber : 0
lineNumber : 0
scriptId : <scriptId>
}
[1] : {
columnNumber : 8
lineNumber : 0
scriptId : <scriptId>
}
[2] : {
columnNumber : 19
lineNumber : 0
scriptId : <scriptId>
}
]
}
}
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-gc
print("Test for Debugger.getPossibleBreakpoints");
......@@ -9,6 +8,7 @@ Protocol.Runtime.enable();
Protocol.Debugger.enable();
InspectorTest.runTestSuite([
function getPossibleBreakpointsInRange(next) {
var source = "function foo(){ return Promise.resolve(); }\nfunction boo(){ return Promise.resolve().then(() => 42); }\n\n";
var scriptId;
......@@ -138,8 +138,26 @@ function foo6() { Promise.resolve().then(() => 42) }`;
.then(setAllBreakpoints)
.then(() => Protocol.Runtime.evaluate({ expression: "foo5(); foo6()"}))
.then(next);
}
},
function arrowFunctionReturn(next) {
waitForPossibleBreakpoints("() => 239\n", { lineNumber: 0, columnNumber: 0 })
.then(InspectorTest.logMessage)
.then(() => waitForPossibleBreakpoints("function foo() { function boo() { return 239 } }\n", { lineNumber: 0, columnNumber: 0 }))
.then(InspectorTest.logMessage)
.then(() => waitForPossibleBreakpoints("() => { 239 }\n", { lineNumber: 0, columnNumber: 0 }))
.then(InspectorTest.logMessage)
// TODO(kozyatinskiy): lineNumber for return position should be 21 instead of 22.
.then(() => waitForPossibleBreakpoints("function foo() { 239 }\n", { lineNumber: 0, columnNumber: 0 }))
.then(InspectorTest.logMessage)
// TODO(kozyatinskiy): lineNumber for return position should be only 9, not 8.
.then(() => waitForPossibleBreakpoints("() => 239", { lineNumber: 0, columnNumber: 0 }))
.then(InspectorTest.logMessage)
// TODO(kozyatinskiy): lineNumber for return position should be only 19, not 20.
.then(() => waitForPossibleBreakpoints("() => { return 239 }", { lineNumber: 0, columnNumber: 0 }))
.then(InspectorTest.logMessage)
.then(next)
}
]);
function compileScript(source, origin) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment