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();
}
......
// 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