Reviewers: Yang,

Description:
Allow debugger evaluate expressions to mute local variables

Please review this at https://codereview.chromium.org/17636007/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/mirror-debugger.js
  M src/runtime.cc


Index: src/mirror-debugger.js
diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js
index e1fd872f3b980f0224bb3b1741989ea3dcea2718..ff9786b5d80cdd9dd9b9896489febfcdd67ae13b 100644
--- a/src/mirror-debugger.js
+++ b/src/mirror-debugger.js
@@ -1671,13 +1671,28 @@ FrameMirror.prototype.scope = function(index) {

 FrameMirror.prototype.evaluate = function(source, disable_break,
                                           opt_context_object) {
-  var result = %DebugEvaluate(this.break_id_,
-                              this.details_.frameId(),
-                              this.details_.inlinedFrameIndex(),
-                              source,
-                              Boolean(disable_break),
-                              opt_context_object);
-  return MakeMirror(result);
+  var resultArray = %DebugEvaluate(this.break_id_,
+                                   this.details_.frameId(),
+                                   this.details_.inlinedFrameIndex(),
+                                   source,
+                                   Boolean(disable_break),
+                                   opt_context_object);
+  // TODO: Check against optimized function somehow.
+  var localScopeBefore = resultArray[1];
+  var localScopeAfter = resultArray[2];
+  for (var n in localScopeAfter) {
+    var valueBefore = localScopeBefore[n];
+    var valueAfter = localScopeAfter[n];
+    if (valueBefore !== valueAfter) {
+      %SetScopeVariableValue(this.break_id_,
+                             this.details_.frameId(),
+                             this.details_.inlinedFrameIndex(),
+                             0,
+                             n,
+                             valueAfter);
+    }
+  }
+  return MakeMirror(resultArray[0]);
 };


Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 02a97e24b17156f16e7a407bcbaa30af594356ab..d03e2dc9d30ddbcdf8353fec94e19da49c02a1e0 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -12372,6 +12372,13 @@ static MaybeObject* DebugEvaluate(Isolate* isolate,
 // the same view of the values of parameters and local variables as if the
 // piece of JavaScript was evaluated at the point where the function on the
// stack frame is currently stopped when we compile and run the (direct) eval.
+// Returns array of
+// #0: evaluate result
+// #1: local variables scope materizalized as object before evaluation
+// #2: local variables scope materizalized as object after evaluation
+// Since user expression only reaches (and modifies) copies of local variables, +// those copies are returned to the caller to allow it track the changes and
+// manually update the actual variables.
 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluate) {
   HandleScope scope(isolate);

@@ -12471,7 +12478,23 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluate) {
   }

   Handle<Object> receiver(frame->receiver(), isolate);
- return DebugEvaluate(isolate, context, context_extension, receiver, source);
+  Object* evaluate_result_object;
+  { MaybeObject* maybe_result =
+    DebugEvaluate(isolate, context, context_extension, receiver, source);
+ if (!maybe_result->ToObject(&evaluate_result_object)) return maybe_result;
+  }
+  Handle<Object> evaluate_result(evaluate_result_object, isolate);
+
+ Handle<JSObject> local_scope_after = MaterializeLocalScopeWithFrameInspector(
+      isolate, frame, &frame_inspector);
+
+  Handle<FixedArray> resultArray =
+      isolate->factory()->NewFixedArray(3);
+  resultArray->set(0, *evaluate_result);
+  resultArray->set(2, *local_scope);
+  resultArray->set(1, *local_scope_after);
+
+  return *(isolate->factory()->NewJSArrayWithElements(resultArray));
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to