OLD | NEW |
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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 328 } |
329 | 329 |
330 class InspectorExtension : public v8::Extension { | 330 class InspectorExtension : public v8::Extension { |
331 public: | 331 public: |
332 InspectorExtension() | 332 InspectorExtension() |
333 : v8::Extension("v8_inspector/inspector", | 333 : v8::Extension("v8_inspector/inspector", |
334 "native function attachInspector();" | 334 "native function attachInspector();" |
335 "native function detachInspector();" | 335 "native function detachInspector();" |
336 "native function setMaxAsyncTaskStacks();" | 336 "native function setMaxAsyncTaskStacks();" |
337 "native function breakProgram();" | 337 "native function breakProgram();" |
338 "native function createObjectWithStrictCheck();") {} | 338 "native function createObjectWithStrictCheck();" |
| 339 "native function callWithScheduledBreak();") {} |
339 | 340 |
340 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( | 341 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
341 v8::Isolate* isolate, v8::Local<v8::String> name) { | 342 v8::Isolate* isolate, v8::Local<v8::String> name) { |
342 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 343 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
343 if (name->Equals(context, | 344 if (name->Equals(context, |
344 v8::String::NewFromUtf8(isolate, "attachInspector", | 345 v8::String::NewFromUtf8(isolate, "attachInspector", |
345 v8::NewStringType::kNormal) | 346 v8::NewStringType::kNormal) |
346 .ToLocalChecked()) | 347 .ToLocalChecked()) |
347 .FromJust()) { | 348 .FromJust()) { |
348 return v8::FunctionTemplate::New(isolate, InspectorExtension::Attach); | 349 return v8::FunctionTemplate::New(isolate, InspectorExtension::Attach); |
(...skipping 17 matching lines...) Expand all Loading... |
366 .FromJust()) { | 367 .FromJust()) { |
367 return v8::FunctionTemplate::New(isolate, | 368 return v8::FunctionTemplate::New(isolate, |
368 InspectorExtension::BreakProgram); | 369 InspectorExtension::BreakProgram); |
369 } else if (name->Equals(context, v8::String::NewFromUtf8( | 370 } else if (name->Equals(context, v8::String::NewFromUtf8( |
370 isolate, "createObjectWithStrictCheck", | 371 isolate, "createObjectWithStrictCheck", |
371 v8::NewStringType::kNormal) | 372 v8::NewStringType::kNormal) |
372 .ToLocalChecked()) | 373 .ToLocalChecked()) |
373 .FromJust()) { | 374 .FromJust()) { |
374 return v8::FunctionTemplate::New( | 375 return v8::FunctionTemplate::New( |
375 isolate, InspectorExtension::CreateObjectWithStrictCheck); | 376 isolate, InspectorExtension::CreateObjectWithStrictCheck); |
| 377 } else if (name->Equals(context, v8::String::NewFromUtf8( |
| 378 isolate, "callWithScheduledBreak", |
| 379 v8::NewStringType::kNormal) |
| 380 .ToLocalChecked()) |
| 381 .FromJust()) { |
| 382 return v8::FunctionTemplate::New( |
| 383 isolate, InspectorExtension::CallWithScheduledBreak); |
376 } | 384 } |
377 return v8::Local<v8::FunctionTemplate>(); | 385 return v8::Local<v8::FunctionTemplate>(); |
378 } | 386 } |
379 | 387 |
380 private: | 388 private: |
381 static void Attach(const v8::FunctionCallbackInfo<v8::Value>& args) { | 389 static void Attach(const v8::FunctionCallbackInfo<v8::Value>& args) { |
382 v8::Isolate* isolate = args.GetIsolate(); | 390 v8::Isolate* isolate = args.GetIsolate(); |
383 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 391 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
384 v8_inspector::V8Inspector* inspector = | 392 v8_inspector::V8Inspector* inspector = |
385 InspectorClientImpl::InspectorFromContext(context); | 393 InspectorClientImpl::InspectorFromContext(context); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 fprintf(stderr, "Internal error: createObjectWithStrictCheck()."); | 448 fprintf(stderr, "Internal error: createObjectWithStrictCheck()."); |
441 Exit(); | 449 Exit(); |
442 } | 450 } |
443 v8::Local<v8::ObjectTemplate> templ = | 451 v8::Local<v8::ObjectTemplate> templ = |
444 v8::ObjectTemplate::New(args.GetIsolate()); | 452 v8::ObjectTemplate::New(args.GetIsolate()); |
445 templ->SetAccessCheckCallback(&StrictAccessCheck); | 453 templ->SetAccessCheckCallback(&StrictAccessCheck); |
446 args.GetReturnValue().Set( | 454 args.GetReturnValue().Set( |
447 templ->NewInstance(args.GetIsolate()->GetCurrentContext()) | 455 templ->NewInstance(args.GetIsolate()->GetCurrentContext()) |
448 .ToLocalChecked()); | 456 .ToLocalChecked()); |
449 } | 457 } |
| 458 |
| 459 static void CallWithScheduledBreak( |
| 460 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 461 if (args.Length() != 3 || !args[0]->IsFunction() || !args[1]->IsString() || |
| 462 !args[2]->IsString()) { |
| 463 fprintf(stderr, "Internal error: breakProgram('reason', 'details')."); |
| 464 Exit(); |
| 465 } |
| 466 v8_inspector::V8InspectorSession* session = |
| 467 InspectorClientImpl::SessionFromContext( |
| 468 args.GetIsolate()->GetCurrentContext()); |
| 469 CHECK(session); |
| 470 |
| 471 v8::internal::Vector<uint16_t> reason = ToVector(args[1].As<v8::String>()); |
| 472 v8_inspector::StringView reason_view(reason.start(), reason.length()); |
| 473 v8::internal::Vector<uint16_t> details = ToVector(args[2].As<v8::String>()); |
| 474 v8_inspector::StringView details_view(details.start(), details.length()); |
| 475 session->schedulePauseOnNextStatement(reason_view, details_view); |
| 476 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
| 477 v8::MaybeLocal<v8::Value> result; |
| 478 result = args[0].As<v8::Function>()->Call(context, context->Global(), 0, |
| 479 nullptr); |
| 480 session->cancelPauseOnNextStatement(); |
| 481 } |
450 }; | 482 }; |
451 | 483 |
452 v8::Local<v8::String> ToString(v8::Isolate* isolate, | 484 v8::Local<v8::String> ToString(v8::Isolate* isolate, |
453 const v8_inspector::StringView& string) { | 485 const v8_inspector::StringView& string) { |
454 if (string.is8Bit()) | 486 if (string.is8Bit()) |
455 return v8::String::NewFromOneByte(isolate, string.characters8(), | 487 return v8::String::NewFromOneByte(isolate, string.characters8(), |
456 v8::NewStringType::kNormal, | 488 v8::NewStringType::kNormal, |
457 static_cast<int>(string.length())) | 489 static_cast<int>(string.length())) |
458 .ToLocalChecked(); | 490 .ToLocalChecked(); |
459 else | 491 else |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 argv[i]); | 584 argv[i]); |
553 Exit(); | 585 Exit(); |
554 } | 586 } |
555 frontend_runner.Append(new ExecuteStringTask(chars)); | 587 frontend_runner.Append(new ExecuteStringTask(chars)); |
556 } | 588 } |
557 | 589 |
558 frontend_runner.Join(); | 590 frontend_runner.Join(); |
559 backend_runner.Join(); | 591 backend_runner.Join(); |
560 return 0; | 592 return 0; |
561 } | 593 } |
OLD | NEW |