Allow stepping into Object.observe handlers.

BUG=chromium:432468
R=yangguo@chromium.org, adamk@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/739523002

Cr-Commit-Position: refs/heads/master@{#25423}
This commit is contained in:
aandrey 2014-11-19 07:16:30 -08:00 committed by Commit bot
parent 24c36ff71c
commit f07b0f214b
5 changed files with 107 additions and 18 deletions

View File

@ -503,6 +503,8 @@ class Debug {
return reinterpret_cast<Address>(&thread_local_.step_into_fp_);
}
StepAction last_step_action() { return thread_local_.last_step_action_; }
private:
explicit Debug(Isolate* isolate);

View File

@ -2731,7 +2731,9 @@ RUNTIME_FUNCTION(Runtime_GetScript) {
// to a built-in function such as Array.forEach.
RUNTIME_FUNCTION(Runtime_DebugCallbackSupportsStepping) {
DCHECK(args.length() == 1);
if (!isolate->debug()->is_active() || !isolate->debug()->StepInActive()) {
Debug* debug = isolate->debug();
if (!debug->is_active() || !debug->IsStepping() ||
debug->last_step_action() != StepIn) {
return isolate->heap()->false_value();
}
CONVERT_ARG_CHECKED(Object, callback, 0);

View File

@ -5,6 +5,7 @@
#include "src/v8.h"
#include "src/arguments.h"
#include "src/debug.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
@ -63,6 +64,18 @@ RUNTIME_FUNCTION(Runtime_DeliverObservationChangeRecords) {
// we make a call inside a verbose TryCatch.
catcher.SetVerbose(true);
Handle<Object> argv[] = {argument};
// Allow stepping into the observer callback.
Debug* debug = isolate->debug();
if (debug->is_active() && debug->IsStepping() &&
debug->last_step_action() == StepIn) {
// Previous StepIn may have activated a StepOut if it was at the frame exit.
// In this case to be able to step into the callback again, we need to clear
// the step out first.
debug->ClearStepOut();
debug->FloodWithOneShot(callback);
}
USE(Execution::Call(isolate, callback, isolate->factory()->undefined_value(),
arraysize(argv), argv));
if (isolate->has_pending_exception()) {

View File

@ -0,0 +1,51 @@
// Copyright 2014 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-debug-as debug
// Tests stepping into through Array.prototype.forEach callbacks.
Debug = debug.Debug
var exception = null;
var break_count = 0;
var expected_breaks = -1;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace");
if (!break_count) {
// Count number of expected breakpoints in this source file.
var source_text = exec_state.frame(0).func().script().source();
expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length;
print("Expected breaks: " + expected_breaks);
}
var source = exec_state.frame(0).sourceLineText();
print("paused at: " + source);
assertTrue(source.indexOf("// Break " + break_count + ".") > 0,
"Unexpected pause at: " + source + "\n" +
"Expected: // Break " + break_count + ".");
++break_count;
if (break_count !== expected_breaks) {
exec_state.prepareStep(Debug.StepAction.StepIn, 1);
}
}
} catch(e) {
exception = e;
print(e, e.stack);
}
};
Debug.setListener(listener);
debugger; // Break 0.
[1,2].forEach(callback); // Break 1.
function callback(x) {
return x; // Break 2. // Break 4.
} // Break 3. // Break 5.
assertNull(exception); // Break 6.
assertEquals(expected_breaks, break_count);
Debug.setListener(null);

View File

@ -7,27 +7,29 @@
Debug = debug.Debug
var exception = null;
var break_count = 0;
var expected_breaks = 7;
var expected_breaks = -1;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace");
if (!break_count) {
// Count number of expected breakpoints in this source file.
var source_text = exec_state.frame(0).func().script().source();
expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length;
print("Expected breaks: " + expected_breaks);
}
var source = exec_state.frame(0).sourceLineText();
print("paused at: " + source);
assertTrue(source.indexOf("// Break " + break_count + ".") > 0,
"Unexpected pause at: " + source);
"Unexpected pause at: " + source + "\n" +
"Expected: // Break " + break_count + ".");
if (source.indexOf("StepOver.") !== -1) {
exec_state.prepareStep(Debug.StepAction.StepNext, 1);
} else {
exec_state.prepareStep(Debug.StepAction.StepIn, 1);
}
++break_count;
} else if (event == Debug.DebugEvent.AsyncTaskEvent &&
event_data.type() === "willHandle" &&
event_data.name() !== "Object.observe" &&
break_count > 0) {
exec_state.prepareStep(Debug.StepAction.StepIn, 1);
}
} catch (e) {
exception = e;
@ -42,30 +44,49 @@ Promise.resolve(42)
.then(Object) // Should skip stepping into native.
.then(Boolean) // Should skip stepping into native.
.then(promise2)
.then(undefined, promise3)
.catch(promise3)
.catch(function(e) {
%AbortJS("FAIL: uncaught exception " + e);
});
function promise1()
{
function promise1() {
debugger; // Break 0.
return exception || 1; // Break 1.
} // Break 2.
function promise2()
{
function promise2() {
throw new Error; // Break 3.
}
function promise3()
{
finalize(); // Break 4. StepOver.
function promise3() {
installObservers(); // Break 4. StepOver.
return break_count; // Break 5.
} // Break 6.
function finalize()
{
function installObservers() {
var dummy = {};
Object.observe(dummy, observer1);
Object.observe(dummy, Object); // Should skip stepping into native.
Object.observe(dummy, Boolean); // Should skip stepping into native.
Object.observe(dummy, observer2);
dummy.foo = 1;
}
function observer1() {
return exception || 3; // Break 7.
} // Break 8.
function observer2() {
Promise.resolve().then(promise4); // Break 9. StepOver.
return break_count + 1; // Break 10.
} // Break 11.
function promise4() {
finalize(); // Break 12. StepOver.
return 0; // Break 13.
} // Break 14. StepOver.
function finalize() {
var dummy = {};
Object.observe(dummy, function() {
if (expected_breaks !== break_count) {