Commit 416e423f authored by yangguo's avatar yangguo Committed by Commit bot

[debugger] step-next across yield should not leave the generator.

Stepping in a generator now behaves similar to stepping inside an
async function. Stepping in or next at a yield expression will result in
a break inside the same generator when we return to the generator.
Behavior of step-out does not change.

R=jgruber@chromium.org, neis@chromium.org
BUG=chromium:496865

Review-Url: https://codereview.chromium.org/2519853002
Cr-Commit-Position: refs/heads/master@{#41132}
parent b94b53a2
...@@ -1430,9 +1430,16 @@ bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position, ...@@ -1430,9 +1430,16 @@ bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position,
return false; return false;
} }
void Debug::RecordAsyncFunction(Handle<JSGeneratorObject> generator_object) { void Debug::RecordGenerator(Handle<JSGeneratorObject> generator_object) {
if (last_step_action() <= StepOut) return; if (last_step_action() <= StepOut) return;
if (!IsAsyncFunction(generator_object->function()->shared()->kind())) return;
if (last_step_action() == StepNext) {
// Only consider this generator a step-next target if not stepping in.
JavaScriptFrameIterator stack_iterator(isolate_);
JavaScriptFrame* frame = stack_iterator.frame();
if (frame->UnpaddedFP() < thread_local_.target_fp_) return;
}
DCHECK(!has_suspended_generator()); DCHECK(!has_suspended_generator());
thread_local_.suspended_generator_ = *generator_object; thread_local_.suspended_generator_ = *generator_object;
ClearStepping(); ClearStepping();
......
...@@ -464,7 +464,7 @@ class Debug { ...@@ -464,7 +464,7 @@ class Debug {
bool GetPossibleBreakpoints(Handle<Script> script, int start_position, bool GetPossibleBreakpoints(Handle<Script> script, int start_position,
int end_position, std::set<int>* positions); int end_position, std::set<int>* positions);
void RecordAsyncFunction(Handle<JSGeneratorObject> generator_object); void RecordGenerator(Handle<JSGeneratorObject> generator_object);
// Returns whether the operation succeeded. Compilation can only be triggered // Returns whether the operation succeeded. Compilation can only be triggered
// if a valid closure is passed as the second argument, otherwise the shared // if a valid closure is passed as the second argument, otherwise the shared
......
...@@ -2766,7 +2766,7 @@ void Interpreter::DoSuspendGenerator(InterpreterAssembler* assembler) { ...@@ -2766,7 +2766,7 @@ void Interpreter::DoSuspendGenerator(InterpreterAssembler* assembler) {
__ Bind(&if_stepping); __ Bind(&if_stepping);
{ {
Node* context = __ GetContext(); Node* context = __ GetContext();
__ CallRuntime(Runtime::kDebugRecordAsyncFunction, context, generator); __ CallRuntime(Runtime::kDebugRecordGenerator, context, generator);
__ Goto(&ok); __ Goto(&ok);
} }
} }
......
...@@ -1888,12 +1888,12 @@ RUNTIME_FUNCTION(Runtime_DebugPrepareStepInSuspendedGenerator) { ...@@ -1888,12 +1888,12 @@ RUNTIME_FUNCTION(Runtime_DebugPrepareStepInSuspendedGenerator) {
return isolate->heap()->undefined_value(); return isolate->heap()->undefined_value();
} }
RUNTIME_FUNCTION(Runtime_DebugRecordAsyncFunction) { RUNTIME_FUNCTION(Runtime_DebugRecordGenerator) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
CHECK(isolate->debug()->last_step_action() >= StepNext); CHECK(isolate->debug()->last_step_action() >= StepNext);
isolate->debug()->RecordAsyncFunction(generator); isolate->debug()->RecordGenerator(generator);
return isolate->heap()->undefined_value(); return isolate->heap()->undefined_value();
} }
......
...@@ -54,7 +54,7 @@ RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { ...@@ -54,7 +54,7 @@ RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) {
DCHECK(frame->function()->shared()->is_compiled()); DCHECK(frame->function()->shared()->is_compiled());
DCHECK(!frame->function()->IsOptimized()); DCHECK(!frame->function()->IsOptimized());
isolate->debug()->RecordAsyncFunction(generator_object); isolate->debug()->RecordGenerator(generator_object);
// The caller should have saved the context and continuation already. // The caller should have saved the context and continuation already.
DCHECK_EQ(generator_object->context(), Context::cast(frame->context())); DCHECK_EQ(generator_object->context(), Context::cast(frame->context()));
......
...@@ -194,7 +194,7 @@ namespace internal { ...@@ -194,7 +194,7 @@ namespace internal {
F(ScriptSourceLine, 2, 1) \ F(ScriptSourceLine, 2, 1) \
F(DebugPrepareStepInIfStepping, 1, 1) \ F(DebugPrepareStepInIfStepping, 1, 1) \
F(DebugPrepareStepInSuspendedGenerator, 0, 1) \ F(DebugPrepareStepInSuspendedGenerator, 0, 1) \
F(DebugRecordAsyncFunction, 1, 1) \ F(DebugRecordGenerator, 1, 1) \
F(DebugPushPromise, 1, 1) \ F(DebugPushPromise, 1, 1) \
F(DebugPopPromise, 0, 1) \ F(DebugPopPromise, 0, 1) \
F(DebugNextMicrotaskId, 0, 1) \ F(DebugNextMicrotaskId, 0, 1) \
......
...@@ -14,7 +14,11 @@ function listener(event, exec_state, event_data, data) { ...@@ -14,7 +14,11 @@ function listener(event, exec_state, event_data, data) {
print(source); print(source);
if (/stop stepping/.test(source)) return; if (/stop stepping/.test(source)) return;
if (/yield/.test(source)) yields++; if (/yield/.test(source)) yields++;
if (yields == 4) {
exec_state.prepareStep(Debug.StepAction.StepOut);
} else {
exec_state.prepareStep(Debug.StepAction.StepIn); exec_state.prepareStep(Debug.StepAction.StepIn);
}
} catch (e) { } catch (e) {
print(e, e.stack); print(e, e.stack);
exception = e; exception = e;
......
// 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.
Debug = debug.Debug
var exception = null;
var breaks = 0;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var source = exec_state.frame(0).sourceLineText();
assertTrue(RegExp(`B${breaks++}`).test(source));
if (/stop/.test(source)) return;
if (/step out/.test(source)) {
exec_state.prepareStep(Debug.StepAction.StepOut);
} else if (/step in/.test(source)) {
exec_state.prepareStep(Debug.StepAction.StepIn);
} else {
exec_state.prepareStep(Debug.StepAction.StepNext);
}
} catch (e) {
print(e, e.stack);
exception = e;
}
}
Debug.setListener(listener);
function * g() {
debugger; // B0
yield 1; // B1
yield 2; // B2 step out
yield 3; // B5
yield 4; // B6 step out
return 2 * (yield 5);
}
var i = g();
assertEquals(1, i.next().value);
assertEquals(2, i.next().value); // B3
assertEquals(3, i.next().value); // B4 step in
assertEquals(4, i.next().value); // B7
assertEquals(5, i.next().value); // B8
assertEquals(6, i.next(3).value); // B9 stop
assertNull(exception);
assertEquals(10, breaks);
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