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

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

Issue 2636613002: [inspector] expose V8InspectorSession::breakProgram in test harness. (Closed)
Patch Set: addressed comments Created 3 years, 11 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 | « test/inspector/inspector-impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 class UtilsExtension : public v8::Extension { 49 class UtilsExtension : public v8::Extension {
50 public: 50 public:
51 UtilsExtension() 51 UtilsExtension()
52 : v8::Extension("v8_inspector/utils", 52 : v8::Extension("v8_inspector/utils",
53 "native function print();" 53 "native function print();"
54 "native function quit();" 54 "native function quit();"
55 "native function setlocale();" 55 "native function setlocale();"
56 "native function load();" 56 "native function load();"
57 "native function compileAndRunWithOrigin();" 57 "native function compileAndRunWithOrigin();"
58 "native function setCurrentTimeMSForTest();") {} 58 "native function setCurrentTimeMSForTest();"
59 "native function schedulePauseOnNextStatement();"
60 "native function cancelPauseOnNextStatement();") {}
59 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( 61 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
60 v8::Isolate* isolate, v8::Local<v8::String> name) { 62 v8::Isolate* isolate, v8::Local<v8::String> name) {
61 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 63 v8::Local<v8::Context> context = isolate->GetCurrentContext();
62 if (name->Equals(context, v8::String::NewFromUtf8( 64 if (name->Equals(context, v8::String::NewFromUtf8(
63 isolate, "print", v8::NewStringType::kNormal) 65 isolate, "print", v8::NewStringType::kNormal)
64 .ToLocalChecked()) 66 .ToLocalChecked())
65 .FromJust()) { 67 .FromJust()) {
66 return v8::FunctionTemplate::New(isolate, UtilsExtension::Print); 68 return v8::FunctionTemplate::New(isolate, UtilsExtension::Print);
67 } else if (name->Equals(context, 69 } else if (name->Equals(context,
68 v8::String::NewFromUtf8(isolate, "quit", 70 v8::String::NewFromUtf8(isolate, "quit",
(...skipping 20 matching lines...) Expand all
89 .FromJust()) { 91 .FromJust()) {
90 return v8::FunctionTemplate::New(isolate, 92 return v8::FunctionTemplate::New(isolate,
91 UtilsExtension::CompileAndRunWithOrigin); 93 UtilsExtension::CompileAndRunWithOrigin);
92 } else if (name->Equals(context, v8::String::NewFromUtf8( 94 } else if (name->Equals(context, v8::String::NewFromUtf8(
93 isolate, "setCurrentTimeMSForTest", 95 isolate, "setCurrentTimeMSForTest",
94 v8::NewStringType::kNormal) 96 v8::NewStringType::kNormal)
95 .ToLocalChecked()) 97 .ToLocalChecked())
96 .FromJust()) { 98 .FromJust()) {
97 return v8::FunctionTemplate::New(isolate, 99 return v8::FunctionTemplate::New(isolate,
98 UtilsExtension::SetCurrentTimeMSForTest); 100 UtilsExtension::SetCurrentTimeMSForTest);
101 } else if (name->Equals(context,
102 v8::String::NewFromUtf8(
103 isolate, "schedulePauseOnNextStatement",
104 v8::NewStringType::kNormal)
105 .ToLocalChecked())
106 .FromJust()) {
107 return v8::FunctionTemplate::New(
108 isolate, UtilsExtension::SchedulePauseOnNextStatement);
109 } else if (name->Equals(context, v8::String::NewFromUtf8(
110 isolate, "cancelPauseOnNextStatement",
111 v8::NewStringType::kNormal)
112 .ToLocalChecked())
113 .FromJust()) {
114 return v8::FunctionTemplate::New(
115 isolate, UtilsExtension::CancelPauseOnNextStatement);
99 } 116 }
100 return v8::Local<v8::FunctionTemplate>(); 117 return v8::Local<v8::FunctionTemplate>();
101 } 118 }
102 119
103 static void set_backend_task_runner(TaskRunner* runner) { 120 static void set_backend_task_runner(TaskRunner* runner) {
104 backend_runner_ = runner; 121 backend_runner_ = runner;
105 } 122 }
106 123
107 static void set_inspector_client(InspectorClientImpl* client) { 124 static void set_inspector_client(InspectorClientImpl* client) {
108 inspector_client_ = client; 125 inspector_client_ = client;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 213
197 static void SetCurrentTimeMSForTest( 214 static void SetCurrentTimeMSForTest(
198 const v8::FunctionCallbackInfo<v8::Value>& args) { 215 const v8::FunctionCallbackInfo<v8::Value>& args) {
199 if (args.Length() != 1 || !args[0]->IsNumber()) { 216 if (args.Length() != 1 || !args[0]->IsNumber()) {
200 fprintf(stderr, "Internal error: setCurrentTimeMSForTest(time)."); 217 fprintf(stderr, "Internal error: setCurrentTimeMSForTest(time).");
201 Exit(); 218 Exit();
202 } 219 }
203 inspector_client_->setCurrentTimeMSForTest( 220 inspector_client_->setCurrentTimeMSForTest(
204 args[0].As<v8::Number>()->Value()); 221 args[0].As<v8::Number>()->Value());
205 } 222 }
223
224 static void SchedulePauseOnNextStatement(
225 const v8::FunctionCallbackInfo<v8::Value>& args) {
226 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString()) {
227 fprintf(
228 stderr,
229 "Internal error: schedulePauseOnNextStatement('reason', 'details').");
230 Exit();
231 }
232 v8::internal::Vector<uint16_t> reason = ToVector(args[0].As<v8::String>());
233 v8_inspector::StringView reason_view(reason.start(), reason.length());
234 v8::internal::Vector<uint16_t> details = ToVector(args[1].As<v8::String>());
235 v8_inspector::StringView details_view(details.start(), details.length());
236 inspector_client_->session()->schedulePauseOnNextStatement(reason_view,
237 details_view);
238 }
239
240 static void CancelPauseOnNextStatement(
241 const v8::FunctionCallbackInfo<v8::Value>& args) {
242 if (args.Length() != 0) {
243 fprintf(stderr, "Internal error: cancelPauseOnNextStatement().");
244 Exit();
245 }
246 inspector_client_->session()->cancelPauseOnNextStatement();
247 }
206 }; 248 };
207 249
208 TaskRunner* UtilsExtension::backend_runner_ = nullptr; 250 TaskRunner* UtilsExtension::backend_runner_ = nullptr;
209 InspectorClientImpl* UtilsExtension::inspector_client_ = nullptr; 251 InspectorClientImpl* UtilsExtension::inspector_client_ = nullptr;
210 252
211 class SetTimeoutTask : public AsyncTask { 253 class SetTimeoutTask : public AsyncTask {
212 public: 254 public:
213 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function, 255 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function,
214 const char* task_name, v8_inspector::V8Inspector* inspector) 256 const char* task_name, v8_inspector::V8Inspector* inspector)
215 : AsyncTask(task_name, inspector), function_(isolate, function) {} 257 : AsyncTask(task_name, inspector), function_(isolate, function) {}
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 TaskRunner::FromContext(context)->Append(task.release()); 318 TaskRunner::FromContext(context)->Append(task.release());
277 } 319 }
278 }; 320 };
279 321
280 class InspectorExtension : public v8::Extension { 322 class InspectorExtension : public v8::Extension {
281 public: 323 public:
282 InspectorExtension() 324 InspectorExtension()
283 : v8::Extension("v8_inspector/inspector", 325 : v8::Extension("v8_inspector/inspector",
284 "native function attachInspector();" 326 "native function attachInspector();"
285 "native function detachInspector();" 327 "native function detachInspector();"
286 "native function setMaxAsyncTaskStacks();") {} 328 "native function setMaxAsyncTaskStacks();"
329 "native function breakProgram();") {}
287 330
288 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( 331 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
289 v8::Isolate* isolate, v8::Local<v8::String> name) { 332 v8::Isolate* isolate, v8::Local<v8::String> name) {
290 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 333 v8::Local<v8::Context> context = isolate->GetCurrentContext();
291 if (name->Equals(context, 334 if (name->Equals(context,
292 v8::String::NewFromUtf8(isolate, "attachInspector", 335 v8::String::NewFromUtf8(isolate, "attachInspector",
293 v8::NewStringType::kNormal) 336 v8::NewStringType::kNormal)
294 .ToLocalChecked()) 337 .ToLocalChecked())
295 .FromJust()) { 338 .FromJust()) {
296 return v8::FunctionTemplate::New(isolate, InspectorExtension::Attach); 339 return v8::FunctionTemplate::New(isolate, InspectorExtension::Attach);
297 } else if (name->Equals(context, 340 } else if (name->Equals(context,
298 v8::String::NewFromUtf8(isolate, "detachInspector", 341 v8::String::NewFromUtf8(isolate, "detachInspector",
299 v8::NewStringType::kNormal) 342 v8::NewStringType::kNormal)
300 .ToLocalChecked()) 343 .ToLocalChecked())
301 .FromJust()) { 344 .FromJust()) {
302 return v8::FunctionTemplate::New(isolate, InspectorExtension::Detach); 345 return v8::FunctionTemplate::New(isolate, InspectorExtension::Detach);
303 } else if (name->Equals(context, v8::String::NewFromUtf8( 346 } else if (name->Equals(context, v8::String::NewFromUtf8(
304 isolate, "setMaxAsyncTaskStacks", 347 isolate, "setMaxAsyncTaskStacks",
305 v8::NewStringType::kNormal) 348 v8::NewStringType::kNormal)
306 .ToLocalChecked()) 349 .ToLocalChecked())
307 .FromJust()) { 350 .FromJust()) {
308 return v8::FunctionTemplate::New( 351 return v8::FunctionTemplate::New(
309 isolate, InspectorExtension::SetMaxAsyncTaskStacks); 352 isolate, InspectorExtension::SetMaxAsyncTaskStacks);
353 } else if (name->Equals(context,
354 v8::String::NewFromUtf8(isolate, "breakProgram",
355 v8::NewStringType::kNormal)
356 .ToLocalChecked())
357 .FromJust()) {
358 return v8::FunctionTemplate::New(isolate,
359 InspectorExtension::BreakProgram);
310 } 360 }
311 return v8::Local<v8::FunctionTemplate>(); 361 return v8::Local<v8::FunctionTemplate>();
312 } 362 }
313 363
314 private: 364 private:
315 static void Attach(const v8::FunctionCallbackInfo<v8::Value>& args) { 365 static void Attach(const v8::FunctionCallbackInfo<v8::Value>& args) {
316 v8::Isolate* isolate = args.GetIsolate(); 366 v8::Isolate* isolate = args.GetIsolate();
317 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 367 v8::Local<v8::Context> context = isolate->GetCurrentContext();
318 v8_inspector::V8Inspector* inspector = 368 v8_inspector::V8Inspector* inspector =
319 InspectorClientImpl::InspectorFromContext(context); 369 InspectorClientImpl::InspectorFromContext(context);
(...skipping 23 matching lines...) Expand all
343 fprintf(stderr, "Internal error: setMaxAsyncTaskStacks(max)."); 393 fprintf(stderr, "Internal error: setMaxAsyncTaskStacks(max).");
344 Exit(); 394 Exit();
345 } 395 }
346 v8_inspector::V8Inspector* inspector = 396 v8_inspector::V8Inspector* inspector =
347 InspectorClientImpl::InspectorFromContext( 397 InspectorClientImpl::InspectorFromContext(
348 args.GetIsolate()->GetCurrentContext()); 398 args.GetIsolate()->GetCurrentContext());
349 CHECK(inspector); 399 CHECK(inspector);
350 v8_inspector::SetMaxAsyncTaskStacksForTest( 400 v8_inspector::SetMaxAsyncTaskStacksForTest(
351 inspector, args[0].As<v8::Int32>()->Value()); 401 inspector, args[0].As<v8::Int32>()->Value());
352 } 402 }
403
404 static void BreakProgram(const v8::FunctionCallbackInfo<v8::Value>& args) {
405 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString()) {
406 fprintf(stderr, "Internal error: breakProgram('reason', 'details').");
407 Exit();
408 }
409 v8_inspector::V8InspectorSession* session =
410 InspectorClientImpl::SessionFromContext(
411 args.GetIsolate()->GetCurrentContext());
412 CHECK(session);
413
414 v8::internal::Vector<uint16_t> reason = ToVector(args[0].As<v8::String>());
415 v8_inspector::StringView reason_view(reason.start(), reason.length());
416 v8::internal::Vector<uint16_t> details = ToVector(args[1].As<v8::String>());
417 v8_inspector::StringView details_view(details.start(), details.length());
418 session->breakProgram(reason_view, details_view);
419 }
353 }; 420 };
354 421
355 v8::Local<v8::String> ToString(v8::Isolate* isolate, 422 v8::Local<v8::String> ToString(v8::Isolate* isolate,
356 const v8_inspector::StringView& string) { 423 const v8_inspector::StringView& string) {
357 if (string.is8Bit()) 424 if (string.is8Bit())
358 return v8::String::NewFromOneByte(isolate, string.characters8(), 425 return v8::String::NewFromOneByte(isolate, string.characters8(),
359 v8::NewStringType::kNormal, 426 v8::NewStringType::kNormal,
360 static_cast<int>(string.length())) 427 static_cast<int>(string.length()))
361 .ToLocalChecked(); 428 .ToLocalChecked();
362 else 429 else
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 argv[i]); 522 argv[i]);
456 Exit(); 523 Exit();
457 } 524 }
458 frontend_runner.Append(new ExecuteStringTask(chars)); 525 frontend_runner.Append(new ExecuteStringTask(chars));
459 } 526 }
460 527
461 frontend_runner.Join(); 528 frontend_runner.Join();
462 backend_runner.Join(); 529 backend_runner.Join();
463 return 0; 530 return 0;
464 } 531 }
OLDNEW
« no previous file with comments | « test/inspector/inspector-impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698