Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: src/d8-debug.cc

Issue 1239053004: Make d8 stop using to-be-deprecated APIs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/d8.gyp ('k') | src/d8-posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) {
(...skipping 11 matching lines...) Expand all
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(isolate); 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", NewStringType::kNormal)
33 Handle<Object> event_data = event_details.GetEventData(); 33 .ToLocalChecked();
34 Local<Object> event_data = event_details.GetEventData();
34 Local<Function> to_json_fun = 35 Local<Function> to_json_fun =
35 Local<Function>::Cast(event_data->Get(to_json_fun_name)); 36 Local<Function>::Cast(event_data->Get(isolate->GetCurrentContext(),
36 Local<Value> event_json = to_json_fun->Call(event_data, 0, NULL); 37 to_json_fun_name).ToLocalChecked());
37 if (try_catch.HasCaught()) { 38 Local<Value> event_json;
39 if (!to_json_fun->Call(isolate->GetCurrentContext(), event_data, 0, NULL)
40 .ToLocal(&event_json)) {
38 Shell::ReportException(isolate, &try_catch); 41 Shell::ReportException(isolate, &try_catch);
39 return; 42 return;
40 } 43 }
41 44
42 // Print the event details. 45 // Print the event details.
43 Handle<Object> details = 46 Local<Object> details =
44 Shell::DebugMessageDetails(isolate, Handle<String>::Cast(event_json)); 47 Shell::DebugMessageDetails(isolate, Local<String>::Cast(event_json));
45 if (try_catch.HasCaught()) { 48 if (try_catch.HasCaught()) {
46 Shell::ReportException(isolate, &try_catch); 49 Shell::ReportException(isolate, &try_catch);
47 return; 50 return;
48 } 51 }
49 String::Utf8Value str(details->Get(String::NewFromUtf8(isolate, "text"))); 52 String::Utf8Value str(
53 details->Get(isolate->GetCurrentContext(),
54 String::NewFromUtf8(isolate, "text", NewStringType::kNormal)
55 .ToLocalChecked()).ToLocalChecked());
50 if (str.length() == 0) { 56 if (str.length() == 0) {
51 // Empty string is used to signal not to process this event. 57 // Empty string is used to signal not to process this event.
52 return; 58 return;
53 } 59 }
54 printf("%s\n", *str); 60 printf("%s\n", *str);
55 61
56 // Get the debug command processor. 62 // Get the debug command processor.
57 Local<String> fun_name = 63 Local<String> fun_name =
58 String::NewFromUtf8(isolate, "debugCommandProcessor"); 64 String::NewFromUtf8(isolate, "debugCommandProcessor",
59 Handle<Object> exec_state = event_details.GetExecutionState(); 65 NewStringType::kNormal).ToLocalChecked();
60 Local<Function> fun = Local<Function>::Cast(exec_state->Get(fun_name)); 66 Local<Object> exec_state = event_details.GetExecutionState();
61 Local<Object> cmd_processor = 67 Local<Function> fun = Local<Function>::Cast(
62 Local<Object>::Cast(fun->Call(exec_state, 0, NULL)); 68 exec_state->Get(isolate->GetCurrentContext(), fun_name).ToLocalChecked());
63 if (try_catch.HasCaught()) { 69 Local<Value> cmd_processor_value;
70 if (!fun->Call(isolate->GetCurrentContext(), exec_state, 0, NULL)
71 .ToLocal(&cmd_processor_value)) {
64 Shell::ReportException(isolate, &try_catch); 72 Shell::ReportException(isolate, &try_catch);
65 return; 73 return;
66 } 74 }
75 Local<Object> cmd_processor = Local<Object>::Cast(cmd_processor_value);
67 76
68 static const int kBufferSize = 256; 77 static const int kBufferSize = 256;
69 bool running = false; 78 bool running = false;
70 while (!running) { 79 while (!running) {
71 char command[kBufferSize]; 80 char command[kBufferSize];
72 PrintPrompt(running); 81 PrintPrompt(running);
73 char* str = fgets(command, kBufferSize, stdin); 82 char* str = fgets(command, kBufferSize, stdin);
74 if (str == NULL) break; 83 if (str == NULL) break;
75 84
76 // Ignore empty commands. 85 // Ignore empty commands.
77 if (strlen(command) == 0) continue; 86 if (strlen(command) == 0) continue;
78 87
79 TryCatch try_catch(isolate); 88 TryCatch try_catch(isolate);
80 89
81 // Convert the debugger command to a JSON debugger request. 90 // Convert the debugger command to a JSON debugger request.
82 Handle<Value> request = Shell::DebugCommandToJSONRequest( 91 Local<Value> request = Shell::DebugCommandToJSONRequest(
83 isolate, String::NewFromUtf8(isolate, command)); 92 isolate, String::NewFromUtf8(isolate, command, NewStringType::kNormal)
93 .ToLocalChecked());
84 if (try_catch.HasCaught()) { 94 if (try_catch.HasCaught()) {
85 Shell::ReportException(isolate, &try_catch); 95 Shell::ReportException(isolate, &try_catch);
86 continue; 96 continue;
87 } 97 }
88 98
89 // If undefined is returned the command was handled internally and there is 99 // If undefined is returned the command was handled internally and there is
90 // no JSON to send. 100 // no JSON to send.
91 if (request->IsUndefined()) { 101 if (request->IsUndefined()) {
92 continue; 102 continue;
93 } 103 }
94 104
95 Handle<String> fun_name; 105 Local<String> fun_name;
96 Handle<Function> fun; 106 Local<Function> fun;
97 // All the functions used below take one argument. 107 // All the functions used below take one argument.
98 static const int kArgc = 1; 108 static const int kArgc = 1;
99 Handle<Value> args[kArgc]; 109 Local<Value> args[kArgc];
100 110
101 // Invoke the JavaScript to convert the debug command line to a JSON 111 // Invoke the JavaScript to convert the debug command line to a JSON
102 // request, invoke the JSON request and convert the JSON respose to a text 112 // request, invoke the JSON request and convert the JSON respose to a text
103 // representation. 113 // representation.
104 fun_name = String::NewFromUtf8(isolate, "processDebugRequest"); 114 fun_name = String::NewFromUtf8(isolate, "processDebugRequest",
105 fun = Handle<Function>::Cast(cmd_processor->Get(fun_name)); 115 NewStringType::kNormal).ToLocalChecked();
116 fun = Local<Function>::Cast(cmd_processor->Get(isolate->GetCurrentContext(),
117 fun_name).ToLocalChecked());
106 args[0] = request; 118 args[0] = request;
107 Handle<Value> response_val = fun->Call(cmd_processor, kArgc, args); 119 Local<Value> response_val;
108 if (try_catch.HasCaught()) { 120 if (!fun->Call(isolate->GetCurrentContext(), cmd_processor, kArgc, args)
121 .ToLocal(&response_val)) {
109 Shell::ReportException(isolate, &try_catch); 122 Shell::ReportException(isolate, &try_catch);
110 continue; 123 continue;
111 } 124 }
112 Handle<String> response = Handle<String>::Cast(response_val); 125 Local<String> response = Local<String>::Cast(response_val);
113 126
114 // Convert the debugger response into text details and the running state. 127 // Convert the debugger response into text details and the running state.
115 Handle<Object> response_details = 128 Local<Object> response_details =
116 Shell::DebugMessageDetails(isolate, response); 129 Shell::DebugMessageDetails(isolate, response);
117 if (try_catch.HasCaught()) { 130 if (try_catch.HasCaught()) {
118 Shell::ReportException(isolate, &try_catch); 131 Shell::ReportException(isolate, &try_catch);
119 continue; 132 continue;
120 } 133 }
121 String::Utf8Value text_str( 134 String::Utf8Value text_str(
122 response_details->Get(String::NewFromUtf8(isolate, "text"))); 135 response_details->Get(isolate->GetCurrentContext(),
136 String::NewFromUtf8(isolate, "text",
137 NewStringType::kNormal)
138 .ToLocalChecked()).ToLocalChecked());
123 if (text_str.length() > 0) { 139 if (text_str.length() > 0) {
124 printf("%s\n", *text_str); 140 printf("%s\n", *text_str);
125 } 141 }
126 running = response_details->Get(String::NewFromUtf8(isolate, "running")) 142 running = response_details->Get(isolate->GetCurrentContext(),
127 ->ToBoolean(isolate) 143 String::NewFromUtf8(isolate, "running",
144 NewStringType::kNormal)
145 .ToLocalChecked())
146 .ToLocalChecked()
147 ->ToBoolean(isolate->GetCurrentContext())
148 .ToLocalChecked()
128 ->Value(); 149 ->Value();
129 } 150 }
130 } 151 }
131 152
132 } // namespace v8 153 } // namespace v8
OLDNEW
« no previous file with comments | « src/d8.gyp ('k') | src/d8-posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698