| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/d8.h" | 5 #include "src/d8.h" |
| 6 #include "src/d8-debug.h" | 6 #include "src/d8-debug.h" |
| 7 | 7 |
| 8 namespace v8 { | 8 namespace v8 { |
| 9 | 9 |
| 10 void PrintPrompt(bool is_running) { | 10 void PrintPrompt(bool is_running) { |
| 11 const char* prompt = is_running? "> " : "dbg> "; | 11 const char* prompt = is_running? "> " : "dbg> "; |
| 12 printf("%s", prompt); | 12 printf("%s", prompt); |
| 13 fflush(stdout); | 13 fflush(stdout); |
| 14 } | 14 } |
| 15 | 15 |
| 16 | 16 |
| 17 void HandleDebugEvent(const Debug::EventDetails& event_details) { | 17 void HandleDebugEvent(const Debug::EventDetails& event_details) { |
| 18 // TODO(svenpanne) There should be a way to retrieve this in the callback. | 18 // TODO(svenpanne) There should be a way to retrieve this in the callback. |
| 19 Isolate* isolate = Isolate::GetCurrent(); | 19 Isolate* isolate = Isolate::GetCurrent(); |
| 20 HandleScope scope(isolate); | 20 HandleScope scope(isolate); |
| 21 | 21 |
| 22 DebugEvent event = event_details.GetEvent(); | 22 DebugEvent event = event_details.GetEvent(); |
| 23 // Check for handled event. | 23 // Check for handled event. |
| 24 if (event != Break && event != Exception && event != AfterCompile) { | 24 if (event != Break && event != Exception && event != AfterCompile) { |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 | 27 |
| 28 TryCatch try_catch; | 28 TryCatch try_catch(isolate); |
| 29 | 29 |
| 30 // Get the toJSONProtocol function on the event and get the JSON format. | 30 // Get the toJSONProtocol function on the event and get the JSON format. |
| 31 Local<String> to_json_fun_name = | 31 Local<String> to_json_fun_name = |
| 32 String::NewFromUtf8(isolate, "toJSONProtocol"); | 32 String::NewFromUtf8(isolate, "toJSONProtocol"); |
| 33 Handle<Object> event_data = event_details.GetEventData(); | 33 Handle<Object> event_data = event_details.GetEventData(); |
| 34 Local<Function> to_json_fun = | 34 Local<Function> to_json_fun = |
| 35 Local<Function>::Cast(event_data->Get(to_json_fun_name)); | 35 Local<Function>::Cast(event_data->Get(to_json_fun_name)); |
| 36 Local<Value> event_json = to_json_fun->Call(event_data, 0, NULL); | 36 Local<Value> event_json = to_json_fun->Call(event_data, 0, NULL); |
| 37 if (try_catch.HasCaught()) { | 37 if (try_catch.HasCaught()) { |
| 38 Shell::ReportException(isolate, &try_catch); | 38 Shell::ReportException(isolate, &try_catch); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 69 bool running = false; | 69 bool running = false; |
| 70 while (!running) { | 70 while (!running) { |
| 71 char command[kBufferSize]; | 71 char command[kBufferSize]; |
| 72 PrintPrompt(running); | 72 PrintPrompt(running); |
| 73 char* str = fgets(command, kBufferSize, stdin); | 73 char* str = fgets(command, kBufferSize, stdin); |
| 74 if (str == NULL) break; | 74 if (str == NULL) break; |
| 75 | 75 |
| 76 // Ignore empty commands. | 76 // Ignore empty commands. |
| 77 if (strlen(command) == 0) continue; | 77 if (strlen(command) == 0) continue; |
| 78 | 78 |
| 79 TryCatch try_catch; | 79 TryCatch try_catch(isolate); |
| 80 | 80 |
| 81 // Convert the debugger command to a JSON debugger request. | 81 // Convert the debugger command to a JSON debugger request. |
| 82 Handle<Value> request = Shell::DebugCommandToJSONRequest( | 82 Handle<Value> request = Shell::DebugCommandToJSONRequest( |
| 83 isolate, String::NewFromUtf8(isolate, command)); | 83 isolate, String::NewFromUtf8(isolate, command)); |
| 84 if (try_catch.HasCaught()) { | 84 if (try_catch.HasCaught()) { |
| 85 Shell::ReportException(isolate, &try_catch); | 85 Shell::ReportException(isolate, &try_catch); |
| 86 continue; | 86 continue; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // If undefined is returned the command was handled internally and there is | 89 // If undefined is returned the command was handled internally and there is |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 if (text_str.length() > 0) { | 123 if (text_str.length() > 0) { |
| 124 printf("%s\n", *text_str); | 124 printf("%s\n", *text_str); |
| 125 } | 125 } |
| 126 running = response_details->Get(String::NewFromUtf8(isolate, "running")) | 126 running = response_details->Get(String::NewFromUtf8(isolate, "running")) |
| 127 ->ToBoolean(isolate) | 127 ->ToBoolean(isolate) |
| 128 ->Value(); | 128 ->Value(); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace v8 | 132 } // namespace v8 |
| OLD | NEW |