Author: [email protected]
Date: Mon Mar  2 11:02:27 2009
New Revision: 1399

Modified:
    branches/bleeding_edge/src/d8-debug.cc
    branches/bleeding_edge/src/d8.cc
    branches/bleeding_edge/src/d8.h
    branches/bleeding_edge/src/d8.js

Log:
Unify the handling of the event and response JSON in developer shell  
debugger.

Formatting of both debugger events and debugger responses are now unified  
into one function. This is mainly in preparation for the upcomming remote  
debugging support where having it a one function simplify things.
Review URL: http://codereview.chromium.org/27330

Modified: branches/bleeding_edge/src/d8-debug.cc
==============================================================================
--- branches/bleeding_edge/src/d8-debug.cc      (original)
+++ branches/bleeding_edge/src/d8-debug.cc      Mon Mar  2 11:02:27 2009
@@ -57,13 +57,17 @@
    }

    // Print the event details.
-  Handle<String> details =
-      Shell::DebugEventToText(Handle<String>::Cast(event_json));
-  if (details->Length() == 0) {
+  Handle<Object> details =
+      Shell::DebugMessageDetails(Handle<String>::Cast(event_json));
+  if (try_catch.HasCaught()) {
+    Shell::ReportException(&try_catch);
+    return;
+  }
+  String::Utf8Value str(details->Get(String::New("text")));
+  if (str.length() == 0) {
      // Empty string is used to signal not to process this event.
      return;
    }
-  String::Utf8Value str(details);
    printf("%s\n", *str);

    // Get the debug command processor.
@@ -123,7 +127,7 @@
      Handle<String> response = Handle<String>::Cast(response_val);

      // Convert the debugger response into text details and the running  
state.
-    Handle<Object> response_details =  
Shell::DebugResponseDetails(response);
+    Handle<Object> response_details = Shell::DebugMessageDetails(response);
      if (try_catch.HasCaught()) {
        Shell::ReportException(&try_catch);
        continue;

Modified: branches/bleeding_edge/src/d8.cc
==============================================================================
--- branches/bleeding_edge/src/d8.cc    (original)
+++ branches/bleeding_edge/src/d8.cc    Mon Mar  2 11:02:27 2009
@@ -232,21 +232,14 @@
  }


-Handle<String> Shell::DebugEventToText(Handle<String> event) {
-  HandleScope handle_scope;
+Handle<Object> Shell::DebugMessageDetails(Handle<String> message) {
    Context::Scope context_scope(utility_context_);
    Handle<Object> global = utility_context_->Global();
-  Handle<Value> fun = global->Get(String::New("DebugEventToText"));
-  TryCatch try_catch;
-  try_catch.SetVerbose(true);
+  Handle<Value> fun = global->Get(String::New("DebugMessageDetails"));
    static const int kArgc = 1;
-  Handle<Value> argv[kArgc] = { event };
+  Handle<Value> argv[kArgc] = { message };
    Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc,  
argv);
-  if (try_catch.HasCaught()) {
-    return handle_scope.Close(try_catch.Exception()->ToString());
-  } else {
-    return handle_scope.Close(Handle<String>::Cast(val));
-  }
+  return Handle<Object>::Cast(val);
  }


@@ -258,17 +251,6 @@
    Handle<Value> argv[kArgc] = { command };
    Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc,  
argv);
    return val;
-}
-
-
-Handle<Object> Shell::DebugResponseDetails(Handle<String> response) {
-  Context::Scope context_scope(utility_context_);
-  Handle<Object> global = utility_context_->Global();
-  Handle<Value> fun = global->Get(String::New("DebugResponseDetails"));
-  static const int kArgc = 1;
-  Handle<Value> argv[kArgc] = { response };
-  Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc,  
argv);
-  return Handle<Object>::Cast(val);
  }



Modified: branches/bleeding_edge/src/d8.h
==============================================================================
--- branches/bleeding_edge/src/d8.h     (original)
+++ branches/bleeding_edge/src/d8.h     Mon Mar  2 11:02:27 2009
@@ -88,9 +88,8 @@
    static int Main(int argc, char* argv[]);
    static Handle<Array> GetCompletions(Handle<String> text,
                                        Handle<String> full);
-  static Handle<String> DebugEventToText(Handle<String> event);
+  static Handle<Object> DebugMessageDetails(Handle<String> message);
    static Handle<Value> DebugCommandToJSONRequest(Handle<String> command);
-  static Handle<Object> DebugResponseDetails(Handle<String> response);

    static Handle<Value> Print(const Arguments& args);
    static Handle<Value> Quit(const Arguments& args);

Modified: branches/bleeding_edge/src/d8.js
==============================================================================
--- branches/bleeding_edge/src/d8.js    (original)
+++ branches/bleeding_edge/src/d8.js    Mon Mar  2 11:02:27 2009
@@ -102,85 +102,98 @@
  var trace_compile = false;  // Tracing all compile events?


-function DebugEventToText(event) {
+// Process a debugger JSON message into a display text and a running  
status.
+// This function returns an object with properties "text" and "running"  
holding
+// this information.
+function DebugMessageDetails(message) {
    // Convert the JSON string to an object.
-  var response = new ProtocolPackage(event);
+  var response = new ProtocolPackage(message);
+
+  if (response.type() == 'event') {
+    return DebugEventDetails(response);
+  } else {
+    return DebugResponseDetails(response);
+  }
+}
+
+function DebugEventDetails(response) {
+  details = {text:'', running:false}
+
+  // Get the running state.
+  details.running = response.running();

-  // Build the text.
    var body = response.body();
-  var details = '';
+  var result = '';
    switch (response.event()) {
      case 'break':
        if (body.breakpoints) {
-        details += 'breakpoint';
+        result += 'breakpoint';
          if (body.breakpoints.length > 1) {
-          details += 's';
+          result += 's';
          }
-        details += ' #';
+        result += ' #';
          for (var i = 0; i < body.breakpoints.length; i++) {
            if (i > 0) {
-            details += ', #';
+            result += ', #';
            }
-          details += body.breakpoints[i];
+          result += body.breakpoints[i];
          }
        } else {
-        details += 'break';
+        result += 'break';
        }
-      details += ' in ';
-      details += body.invocationText;
-      details += ', ';
-      details += SourceInfo(body);
-      details += '\n';
-      details += SourceUnderline(body.sourceLineText, body.sourceColumn);
+      result += ' in ';
+      result += body.invocationText;
+      result += ', ';
+      result += SourceInfo(body);
+      result += '\n';
+      result += SourceUnderline(body.sourceLineText, body.sourceColumn);
        Debug.State.currentSourceLine = body.sourceLine;
        Debug.State.currentFrame = 0;
-      return details;
+      details.text = result;
+      break;

      case 'exception':
        if (body.uncaught) {
-        details += 'Uncaught: ';
+        result += 'Uncaught: ';
        } else {
-        details += 'Exception: ';
+        result += 'Exception: ';
        }
-      details += '"';
-      details += body.exception.text;
-      details += '"';
+      result += '"';
+      result += body.exception.text;
+      result += '"';
        if (body.sourceLine >= 0) {
-        details += ', ';
-        details += SourceInfo(body);
-        details += '\n';
-        details += SourceUnderline(body.sourceLineText, body.sourceColumn);
+        result += ', ';
+        result += SourceInfo(body);
+        result += '\n';
+        result += SourceUnderline(body.sourceLineText, body.sourceColumn);
          Debug.State.currentSourceLine = body.sourceLine;
          Debug.State.currentFrame = 0;
        } else {
-        details += ' (empty stack)';
+        result += ' (empty stack)';
          Debug.State.currentSourceLine = -1;
          Debug.State.currentFrame = kNoFrame;
        }
-      return details;
+      details.text = result;
+      break;

-    case 'exception':
-      if (trace_compile) {
-        details = 'Source ' + body.script.name + ' compiled:\n'
-      } else {
-        return '';
-      }
-
      case 'afterCompile':
        if (trace_compile) {
-        details = 'Source ' + event.script().name() + ' compiled:\n'
+        result = 'Source ' + body.script.name + ' compiled:\n'
          var source = body.script.source;
          if (!(source[source.length - 1] == '\n')) {
-          details += source;
+          result += source;
          } else {
-          details += source.substring(0, source.length - 1);
+          result += source.substring(0, source.length - 1);
          }
-        return details;
-      } else {
-        return '';
        }
+      details.text = result;
+      break;
+
+    default:
+      details.text = 'Unknown debug event ' + response.event();
    }
-  return 'Unknown debug event ' + response.event();
+
+  return details;
  };


@@ -749,13 +762,10 @@


  // Convert a JSON response to text for display in a text based debugger.
-function DebugResponseDetails(json_response) {
+function DebugResponseDetails(response) {
    details = {text:'', running:false}

    try {
-    // Convert the JSON string to an object.
-    var response = new ProtocolPackage(json_response);
-
      if (!response.success()) {
        details.text = response.message();
        return details;

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

Reply via email to