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

Side by Side Diff: test/inspector/inspector-test.cc

Issue 2465553003: [inspector] added Debugger.getPossibleBreakpoints method (Closed)
Patch Set: minor improvement Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 #if !defined(_WIN32) && !defined(_WIN64) 5 #if !defined(_WIN32) && !defined(_WIN64)
6 #include <unistd.h> // NOLINT 6 #include <unistd.h> // NOLINT
7 #endif // !defined(_WIN32) && !defined(_WIN64) 7 #endif // !defined(_WIN32) && !defined(_WIN64)
8 8
9 #include <locale.h> 9 #include <locale.h>
10 10
(...skipping 20 matching lines...) Expand all
31 std::vector<TaskRunner*> empty; 31 std::vector<TaskRunner*> empty;
32 task_runners.swap(empty); 32 task_runners.swap(empty);
33 } 33 }
34 34
35 void Exit() { 35 void Exit() {
36 fflush(stdout); 36 fflush(stdout);
37 fflush(stderr); 37 fflush(stderr);
38 Terminate(); 38 Terminate();
39 } 39 }
40 40
41 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) {
42 v8::internal::Vector<uint16_t> buffer =
43 v8::internal::Vector<uint16_t>::New(str->Length());
44 str->Write(buffer.start(), 0, str->Length());
45 return buffer;
46 }
47
41 class UtilsExtension : public v8::Extension { 48 class UtilsExtension : public v8::Extension {
42 public: 49 public:
43 UtilsExtension() 50 UtilsExtension()
44 : v8::Extension("v8_inspector/utils", 51 : v8::Extension("v8_inspector/utils",
45 "native function print();" 52 "native function print();"
46 "native function quit();" 53 "native function quit();"
47 "native function setlocale();" 54 "native function setlocale();"
48 "native function load();") {} 55 "native function load();"
56 "native function compileAndRunWithOrigin();") {}
49 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( 57 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
50 v8::Isolate* isolate, v8::Local<v8::String> name) { 58 v8::Isolate* isolate, v8::Local<v8::String> name) {
51 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 59 v8::Local<v8::Context> context = isolate->GetCurrentContext();
52 if (name->Equals(context, v8::String::NewFromUtf8( 60 if (name->Equals(context, v8::String::NewFromUtf8(
53 isolate, "print", v8::NewStringType::kNormal) 61 isolate, "print", v8::NewStringType::kNormal)
54 .ToLocalChecked()) 62 .ToLocalChecked())
55 .FromJust()) { 63 .FromJust()) {
56 return v8::FunctionTemplate::New(isolate, UtilsExtension::Print); 64 return v8::FunctionTemplate::New(isolate, UtilsExtension::Print);
57 } else if (name->Equals(context, 65 } else if (name->Equals(context,
58 v8::String::NewFromUtf8(isolate, "quit", 66 v8::String::NewFromUtf8(isolate, "quit",
59 v8::NewStringType::kNormal) 67 v8::NewStringType::kNormal)
60 .ToLocalChecked()) 68 .ToLocalChecked())
61 .FromJust()) { 69 .FromJust()) {
62 return v8::FunctionTemplate::New(isolate, UtilsExtension::Quit); 70 return v8::FunctionTemplate::New(isolate, UtilsExtension::Quit);
63 } else if (name->Equals(context, 71 } else if (name->Equals(context,
64 v8::String::NewFromUtf8(isolate, "setlocale", 72 v8::String::NewFromUtf8(isolate, "setlocale",
65 v8::NewStringType::kNormal) 73 v8::NewStringType::kNormal)
66 .ToLocalChecked()) 74 .ToLocalChecked())
67 .FromJust()) { 75 .FromJust()) {
68 return v8::FunctionTemplate::New(isolate, UtilsExtension::SetLocale); 76 return v8::FunctionTemplate::New(isolate, UtilsExtension::SetLocale);
69 } else if (name->Equals(context, 77 } else if (name->Equals(context,
70 v8::String::NewFromUtf8(isolate, "load", 78 v8::String::NewFromUtf8(isolate, "load",
71 v8::NewStringType::kNormal) 79 v8::NewStringType::kNormal)
72 .ToLocalChecked()) 80 .ToLocalChecked())
73 .FromJust()) { 81 .FromJust()) {
74 return v8::FunctionTemplate::New(isolate, UtilsExtension::Load); 82 return v8::FunctionTemplate::New(isolate, UtilsExtension::Load);
83 } else if (name->Equals(context, v8::String::NewFromUtf8(
84 isolate, "compileAndRunWithOrigin",
85 v8::NewStringType::kNormal)
86 .ToLocalChecked())
87 .FromJust()) {
88 return v8::FunctionTemplate::New(isolate,
89 UtilsExtension::CompileAndRunWithOrigin);
75 } 90 }
76 return v8::Local<v8::FunctionTemplate>(); 91 return v8::Local<v8::FunctionTemplate>();
77 } 92 }
78 93
94 static void set_backend_task_runner(TaskRunner* runner) {
95 backend_runner_ = runner;
96 }
97
79 private: 98 private:
99 static TaskRunner* backend_runner_;
100
80 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args) { 101 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
81 for (int i = 0; i < args.Length(); i++) { 102 for (int i = 0; i < args.Length(); i++) {
82 v8::HandleScope handle_scope(args.GetIsolate()); 103 v8::HandleScope handle_scope(args.GetIsolate());
83 if (i != 0) { 104 if (i != 0) {
84 printf(" "); 105 printf(" ");
85 } 106 }
86 107
87 // Explicitly catch potential exceptions in toString(). 108 // Explicitly catch potential exceptions in toString().
88 v8::TryCatch try_catch(args.GetIsolate()); 109 v8::TryCatch try_catch(args.GetIsolate());
89 v8::Local<v8::Value> arg = args[i]; 110 v8::Local<v8::Value> arg = args[i];
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 isolate->ThrowException( 157 isolate->ThrowException(
137 v8::String::NewFromUtf8(isolate, "Error loading file", 158 v8::String::NewFromUtf8(isolate, "Error loading file",
138 v8::NewStringType::kNormal) 159 v8::NewStringType::kNormal)
139 .ToLocalChecked()); 160 .ToLocalChecked());
140 return; 161 return;
141 } 162 }
142 ExecuteStringTask task(chars); 163 ExecuteStringTask task(chars);
143 v8::Global<v8::Context> context(isolate, isolate->GetCurrentContext()); 164 v8::Global<v8::Context> context(isolate, isolate->GetCurrentContext());
144 task.Run(isolate, context); 165 task.Run(isolate, context);
145 } 166 }
167
168 static void CompileAndRunWithOrigin(
169 const v8::FunctionCallbackInfo<v8::Value>& args) {
170 if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString() ||
171 !args[2]->IsInt32() || !args[3]->IsInt32()) {
172 fprintf(stderr,
173 "Internal error: compileAndRunWithOrigin(source, name, line, "
174 "column).");
175 Exit();
176 }
177
178 backend_runner_->Append(new ExecuteStringTask(
179 ToVector(args[0].As<v8::String>()), args[1].As<v8::String>(),
180 args[2].As<v8::Int32>(), args[3].As<v8::Int32>()));
181 }
146 }; 182 };
147 183
184 TaskRunner* UtilsExtension::backend_runner_ = nullptr;
185
148 class SetTimeoutTask : public TaskRunner::Task { 186 class SetTimeoutTask : public TaskRunner::Task {
149 public: 187 public:
150 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function) 188 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function)
151 : function_(isolate, function) {} 189 : function_(isolate, function) {}
152 virtual ~SetTimeoutTask() {} 190 virtual ~SetTimeoutTask() {}
153 191
154 bool is_inspector_task() final { return false; } 192 bool is_inspector_task() final { return false; }
155 193
156 void Run(v8::Isolate* isolate, 194 void Run(v8::Isolate* isolate,
157 const v8::Global<v8::Context>& global_context) override { 195 const v8::Global<v8::Context>& global_context) override {
158 v8::MicrotasksScope microtasks_scope(isolate, 196 v8::MicrotasksScope microtasks_scope(isolate,
159 v8::MicrotasksScope::kRunMicrotasks); 197 v8::MicrotasksScope::kRunMicrotasks);
160 v8::HandleScope handle_scope(isolate); 198 v8::HandleScope handle_scope(isolate);
161 v8::Local<v8::Context> context = global_context.Get(isolate); 199 v8::Local<v8::Context> context = global_context.Get(isolate);
162 v8::Context::Scope context_scope(context); 200 v8::Context::Scope context_scope(context);
163 201
164 v8::Local<v8::Function> function = function_.Get(isolate); 202 v8::Local<v8::Function> function = function_.Get(isolate);
165 v8::MaybeLocal<v8::Value> result; 203 v8::MaybeLocal<v8::Value> result;
166 v8_inspector::V8Inspector* inspector = 204 v8_inspector::V8Inspector* inspector =
167 InspectorClientImpl::InspectorFromContext(context); 205 InspectorClientImpl::InspectorFromContext(context);
168 if (inspector) inspector->willExecuteScript(context, function->ScriptId()); 206 if (inspector) inspector->willExecuteScript(context, function->ScriptId());
169 result = function->Call(context, context->Global(), 0, nullptr); 207 result = function->Call(context, context->Global(), 0, nullptr);
170 if (inspector) inspector->didExecuteScript(context); 208 if (inspector) inspector->didExecuteScript(context);
171 } 209 }
172 210
173 private: 211 private:
174 v8::Global<v8::Function> function_; 212 v8::Global<v8::Function> function_;
175 }; 213 };
176 214
177 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) {
178 v8::internal::Vector<uint16_t> buffer =
179 v8::internal::Vector<uint16_t>::New(str->Length());
180 str->Write(buffer.start(), 0, str->Length());
181 return buffer;
182 }
183
184 class SetTimeoutExtension : public v8::Extension { 215 class SetTimeoutExtension : public v8::Extension {
185 public: 216 public:
186 SetTimeoutExtension() 217 SetTimeoutExtension()
187 : v8::Extension("v8_inspector/setTimeout", 218 : v8::Extension("v8_inspector/setTimeout",
188 "native function setTimeout();") {} 219 "native function setTimeout();") {}
189 220
190 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( 221 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
191 v8::Isolate* isolate, v8::Local<v8::String> name) { 222 v8::Isolate* isolate, v8::Local<v8::String> name) {
192 return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout); 223 return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout);
193 } 224 }
194 225
195 private: 226 private:
196 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { 227 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) {
197 if (args.Length() != 2 || !args[1]->IsNumber() || 228 if (args.Length() != 2 || !args[1]->IsNumber() ||
198 (!args[0]->IsFunction() && !args[0]->IsString()) || 229 (!args[0]->IsFunction() && !args[0]->IsString()) ||
199 args[1].As<v8::Number>()->Value() != 0.0) { 230 args[1].As<v8::Number>()->Value() != 0.0) {
200 fprintf(stderr, 231 fprintf(stderr,
201 "Internal error: only setTimeout(function, 0) is supported."); 232 "Internal error: only setTimeout(function, 0) is supported.");
202 Exit(); 233 Exit();
203 } 234 }
204 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); 235 v8::Isolate* isolate = args.GetIsolate();
236 v8::Local<v8::Context> context = isolate->GetCurrentContext();
205 if (args[0]->IsFunction()) { 237 if (args[0]->IsFunction()) {
206 TaskRunner::FromContext(context)->Append(new SetTimeoutTask( 238 TaskRunner::FromContext(context)->Append(
207 args.GetIsolate(), v8::Local<v8::Function>::Cast(args[0]))); 239 new SetTimeoutTask(isolate, v8::Local<v8::Function>::Cast(args[0])));
208 } else { 240 } else {
209 TaskRunner::FromContext(context)->Append( 241 TaskRunner::FromContext(context)->Append(new ExecuteStringTask(
210 new ExecuteStringTask(ToVector(args[0].As<v8::String>()))); 242 ToVector(args[0].As<v8::String>()), v8::String::Empty(isolate),
243 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0)));
211 } 244 }
212 } 245 }
213 }; 246 };
214 247
215 class InspectorExtension : public v8::Extension { 248 class InspectorExtension : public v8::Extension {
216 public: 249 public:
217 InspectorExtension() 250 InspectorExtension()
218 : v8::Extension("v8_inspector/inspector", 251 : v8::Extension("v8_inspector/inspector",
219 "native function attachInspector();" 252 "native function attachInspector();"
220 "native function detachInspector();") {} 253 "native function detachInspector();") {}
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 v8::NewStringType::kInternalized) 327 v8::NewStringType::kInternalized)
295 .ToLocalChecked(); 328 .ToLocalChecked();
296 v8::Local<v8::String> message_string = ToString(isolate, message); 329 v8::Local<v8::String> message_string = ToString(isolate, message);
297 v8::Local<v8::String> suffix = 330 v8::Local<v8::String> suffix =
298 v8::String::NewFromUtf8(isolate, ")", v8::NewStringType::kInternalized) 331 v8::String::NewFromUtf8(isolate, ")", v8::NewStringType::kInternalized)
299 .ToLocalChecked(); 332 .ToLocalChecked();
300 333
301 v8::Local<v8::String> result = v8::String::Concat(prefix, message_string); 334 v8::Local<v8::String> result = v8::String::Concat(prefix, message_string);
302 result = v8::String::Concat(result, suffix); 335 result = v8::String::Concat(result, suffix);
303 336
304 frontend_task_runner_->Append(new ExecuteStringTask(ToVector(result))); 337 frontend_task_runner_->Append(new ExecuteStringTask(
338 ToVector(result), v8::String::Empty(isolate),
339 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0)));
305 } 340 }
306 341
307 private: 342 private:
308 TaskRunner* frontend_task_runner_; 343 TaskRunner* frontend_task_runner_;
309 }; 344 };
310 345
311 } // namespace 346 } // namespace
312 347
313 int main(int argc, char* argv[]) { 348 int main(int argc, char* argv[]) {
314 v8::V8::InitializeICUDefaultLocation(argv[0]); 349 v8::V8::InitializeICUDefaultLocation(argv[0]);
(...skipping 14 matching lines...) Expand all
329 364
330 v8::base::Semaphore ready_semaphore(0); 365 v8::base::Semaphore ready_semaphore(0);
331 366
332 const char* backend_extensions[] = {"v8_inspector/setTimeout", 367 const char* backend_extensions[] = {"v8_inspector/setTimeout",
333 "v8_inspector/inspector"}; 368 "v8_inspector/inspector"};
334 v8::ExtensionConfiguration backend_configuration( 369 v8::ExtensionConfiguration backend_configuration(
335 arraysize(backend_extensions), backend_extensions); 370 arraysize(backend_extensions), backend_extensions);
336 TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore); 371 TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore);
337 ready_semaphore.Wait(); 372 ready_semaphore.Wait();
338 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); 373 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner);
374 UtilsExtension::set_backend_task_runner(&backend_runner);
339 375
340 const char* frontend_extensions[] = {"v8_inspector/utils", 376 const char* frontend_extensions[] = {"v8_inspector/utils",
341 "v8_inspector/frontend"}; 377 "v8_inspector/frontend"};
342 v8::ExtensionConfiguration frontend_configuration( 378 v8::ExtensionConfiguration frontend_configuration(
343 arraysize(frontend_extensions), frontend_extensions); 379 arraysize(frontend_extensions), frontend_extensions);
344 TaskRunner frontend_runner(&frontend_configuration, true, &ready_semaphore); 380 TaskRunner frontend_runner(&frontend_configuration, true, &ready_semaphore);
345 ready_semaphore.Wait(); 381 ready_semaphore.Wait();
346 382
347 FrontendChannelImpl frontend_channel(&frontend_runner); 383 FrontendChannelImpl frontend_channel(&frontend_runner);
348 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel, 384 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel,
(...skipping 14 matching lines...) Expand all
363 argv[i]); 399 argv[i]);
364 Exit(); 400 Exit();
365 } 401 }
366 frontend_runner.Append(new ExecuteStringTask(chars)); 402 frontend_runner.Append(new ExecuteStringTask(chars));
367 } 403 }
368 404
369 frontend_runner.Join(); 405 frontend_runner.Join();
370 backend_runner.Join(); 406 backend_runner.Join();
371 return 0; 407 return 0;
372 } 408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698