Revision: 11058
Author:   [email protected]
Date:     Thu Mar 15 07:17:22 2012
Log: Debugger: naive implementation of "step into Function.prototype.bind".

Review URL: https://chromiumcodereview.appspot.com/9705018
http://code.google.com/p/v8/source/detail?r=11058

Modified:
 /branches/bleeding_edge/src/debug.cc
 /branches/bleeding_edge/src/debug.h
 /branches/bleeding_edge/test/mjsunit/debug-stepin-function-call.js

=======================================
--- /branches/bleeding_edge/src/debug.cc        Sun Feb 26 23:49:14 2012
+++ /branches/bleeding_edge/src/debug.cc        Thu Mar 15 07:17:22 2012
@@ -1221,6 +1221,18 @@
     it.Next();
   }
 }
+
+
+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() {
@@ -1442,8 +1454,10 @@
           expressions_count - 2 - call_function_arg_count);
       if (fun->IsJSFunction()) {
         Handle<JSFunction> js_function(JSFunction::cast(fun));
-        // Don't step into builtins.
-        if (!js_function->IsBuiltin()) {
+        if (js_function->shared()->bound()) {
+          Debug::FloodBoundFunctionWithOneShot(js_function);
+        } else if (!js_function->IsBuiltin()) {
+          // Don't step into builtins.
           // It will also compile target function if it's not compiled yet.
FloodWithOneShot(Handle<SharedFunctionInfo>(js_function->shared()));
         }
@@ -1639,8 +1653,11 @@
// Flood the function with one-shot break points if it is called from where
   // step into was requested.
   if (fp == step_in_fp()) {
-    // Don't allow step into functions in the native context.
-    if (!function->IsBuiltin()) {
+    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->shared()->code() ==
Isolate::Current()->builtins()->builtin(Builtins::kFunctionApply) ||
           function->shared()->code() ==
=======================================
--- /branches/bleeding_edge/src/debug.h Fri Jan 27 08:09:20 2012
+++ /branches/bleeding_edge/src/debug.h Thu Mar 15 07:17:22 2012
@@ -239,6 +239,7 @@
   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);
=======================================
--- /branches/bleeding_edge/test/mjsunit/debug-stepin-function-call.js Tue Dec 7 03:01:02 2010 +++ /branches/bleeding_edge/test/mjsunit/debug-stepin-function-call.js Thu Mar 15 07:17:22 2012
@@ -134,9 +134,16 @@
   var anotherLocalVar  = g(aLocalVar) + 's';
   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;
@@ -144,6 +151,14 @@
   assertNull(exception);
   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);

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to