Commit 26aaa3b0 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

Debugger: naive implementation of "step into Function.prototype.bind".

Review URL: https://chromiumcodereview.appspot.com/9705018

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11058 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 79a98de9
......@@ -1223,6 +1223,18 @@ void Debug::FloodWithOneShot(Handle<SharedFunctionInfo> shared) {
}
void Debug::FloodBoundFunctionWithOneShot(Handle<JSFunction> function) {
Handle<FixedArray> new_bindings(function->function_bindings());
Handle<Object> bindee(new_bindings->get(JSFunction::kBoundFunctionIndex));
if (!bindee.is_null() && bindee->IsJSFunction() &&
!JSFunction::cast(*bindee)->IsBuiltin()) {
Handle<SharedFunctionInfo> shared_info(JSFunction::cast(*bindee)->shared());
Debug::FloodWithOneShot(shared_info);
}
}
void Debug::FloodHandlerWithOneShot() {
// Iterate through the JavaScript stack looking for handlers.
StackFrame::Id id = break_frame_id();
......@@ -1442,8 +1454,10 @@ void Debug::PrepareStep(StepAction step_action, int step_count) {
expressions_count - 2 - call_function_arg_count);
if (fun->IsJSFunction()) {
Handle<JSFunction> js_function(JSFunction::cast(fun));
if (js_function->shared()->bound()) {
Debug::FloodBoundFunctionWithOneShot(js_function);
} else if (!js_function->IsBuiltin()) {
// Don't step into builtins.
if (!js_function->IsBuiltin()) {
// It will also compile target function if it's not compiled yet.
FloodWithOneShot(Handle<SharedFunctionInfo>(js_function->shared()));
}
......@@ -1639,8 +1653,11 @@ void Debug::HandleStepIn(Handle<JSFunction> function,
// Flood the function with one-shot break points if it is called from where
// step into was requested.
if (fp == step_in_fp()) {
if (function->shared()->bound()) {
// Handle Function.prototype.bind
Debug::FloodBoundFunctionWithOneShot(function);
} else if (!function->IsBuiltin()) {
// Don't allow step into functions in the native context.
if (!function->IsBuiltin()) {
if (function->shared()->code() ==
Isolate::Current()->builtins()->builtin(Builtins::kFunctionApply) ||
function->shared()->code() ==
......
......@@ -239,6 +239,7 @@ class Debug {
void ClearBreakPoint(Handle<Object> break_point_object);
void ClearAllBreakPoints();
void FloodWithOneShot(Handle<SharedFunctionInfo> shared);
void FloodBoundFunctionWithOneShot(Handle<JSFunction> function);
void FloodHandlerWithOneShot();
void ChangeBreakOnException(ExceptionBreakType type, bool enable);
bool IsBreakOnException(ExceptionBreakType type);
......
......@@ -135,8 +135,15 @@ function apply4() {
var yetAnotherLocal = 10;
}
// Test step into bound function.
function bind1() {
var bound = g.bind(null, 3);
debugger;
bound();
}
var testFunctions =
[call1, call2, call3, call4, apply1, apply2, apply3, apply4];
[call1, call2, call3, call4, apply1, apply2, apply3, apply4, bind1];
for (var i = 0; i < testFunctions.length; i++) {
state = 0;
......@@ -145,5 +152,13 @@ for (var i = 0; i < testFunctions.length; i++) {
assertEquals(3, state);
}
// Test global bound function.
state = 0;
var globalBound = g.bind(null, 3);
debugger;
globalBound();
assertNull(exception);
assertEquals(3, state);
// Get rid of the debug event listener.
Debug.setListener(null);
\ No newline at end of file
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