Chromium Code Reviews| Index: test/inspector/inspector-test.cc |
| diff --git a/test/inspector/inspector-test.cc b/test/inspector/inspector-test.cc |
| index a935717c9e6a49c416e45d3f9b58b70c2f6f4f41..4735871deb71a90bf4f7a0db32cc5ca53f885e4d 100644 |
| --- a/test/inspector/inspector-test.cc |
| +++ b/test/inspector/inspector-test.cc |
| @@ -51,15 +51,243 @@ v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const char* str) { |
| .ToLocalChecked(); |
| } |
| -class UtilsExtension : public TaskRunner::Task { |
| +class SetTimeoutTask : public AsyncTask { |
|
dgozman
2017/04/20 23:16:38
Why move the code? Put it back for small delta.
kozy
2017/04/20 23:38:19
Done.
|
| + public: |
| + SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function, |
| + const char* task_name, v8_inspector::V8Inspector* inspector) |
| + : AsyncTask(task_name, inspector), function_(isolate, function) {} |
| + virtual ~SetTimeoutTask() {} |
| + |
| + bool is_inspector_task() final { return false; } |
| + |
| + void AsyncRun(v8::Isolate* isolate, |
| + const v8::Global<v8::Context>& global_context) override { |
| + v8::MicrotasksScope microtasks_scope(isolate, |
| + v8::MicrotasksScope::kRunMicrotasks); |
| + v8::HandleScope handle_scope(isolate); |
| + v8::Local<v8::Context> context = global_context.Get(isolate); |
| + v8::Context::Scope context_scope(context); |
| + |
| + v8::Local<v8::Function> function = function_.Get(isolate); |
| + v8::MaybeLocal<v8::Value> result; |
| + result = function->Call(context, context->Global(), 0, nullptr); |
| + } |
| + |
| + private: |
| + v8::Global<v8::Function> function_; |
| +}; |
| + |
| +class SetTimeoutExtension : public TaskRunner::SetupGlobalTask { |
| + public: |
| + void Run(v8::Isolate* isolate, |
| + v8::Local<v8::ObjectTemplate> global) override { |
| + global->Set( |
| + ToV8String(isolate, "setTimeout"), |
| + v8::FunctionTemplate::New(isolate, &SetTimeoutExtension::SetTimeout)); |
| + } |
| + |
| + private: |
| + static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + if (args.Length() != 2 || !args[1]->IsNumber() || |
| + (!args[0]->IsFunction() && !args[0]->IsString()) || |
| + args[1].As<v8::Number>()->Value() != 0.0) { |
| + fprintf(stderr, |
| + "Internal error: only setTimeout(function, 0) is supported."); |
| + Exit(); |
| + } |
| + v8::Isolate* isolate = args.GetIsolate(); |
| + v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| + std::unique_ptr<TaskRunner::Task> task; |
| + v8_inspector::V8Inspector* inspector = |
| + InspectorClientImpl::InspectorFromContext(context); |
| + if (args[0]->IsFunction()) { |
| + task.reset(new SetTimeoutTask(isolate, |
| + v8::Local<v8::Function>::Cast(args[0]), |
| + "setTimeout", inspector)); |
| + } else { |
| + task.reset(new ExecuteStringTask( |
| + ToVector(args[0].As<v8::String>()), v8::String::Empty(isolate), |
| + v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0), |
| + v8::Boolean::New(isolate, false), "setTimeout", inspector)); |
| + } |
| + TaskRunner::FromContext(context)->Append(task.release()); |
| + } |
| +}; |
| + |
| +bool StrictAccessCheck(v8::Local<v8::Context> accessing_context, |
| + v8::Local<v8::Object> accessed_object, |
| + v8::Local<v8::Value> data) { |
| + CHECK(accessing_context.IsEmpty()); |
| + return accessing_context.IsEmpty(); |
| +} |
| + |
| +class InspectorExtension : public TaskRunner::SetupGlobalTask { |
| + public: |
| + ~InspectorExtension() override = default; |
| + void Run(v8::Isolate* isolate, |
| + v8::Local<v8::ObjectTemplate> global) override { |
| + v8::Local<v8::ObjectTemplate> inspector = v8::ObjectTemplate::New(isolate); |
| + inspector->Set( |
| + ToV8String(isolate, "attachInspector"), |
| + v8::FunctionTemplate::New(isolate, &InspectorExtension::Attach)); |
| + inspector->Set( |
| + ToV8String(isolate, "detachInspector"), |
| + v8::FunctionTemplate::New(isolate, &InspectorExtension::Detach)); |
| + inspector->Set(ToV8String(isolate, "setMaxAsyncTaskStacks"), |
| + v8::FunctionTemplate::New( |
| + isolate, &InspectorExtension::SetMaxAsyncTaskStacks)); |
| + inspector->Set( |
| + ToV8String(isolate, "dumpAsyncTaskStacksStateForTest"), |
| + v8::FunctionTemplate::New( |
| + isolate, &InspectorExtension::DumpAsyncTaskStacksStateForTest)); |
| + inspector->Set( |
| + ToV8String(isolate, "breakProgram"), |
| + v8::FunctionTemplate::New(isolate, &InspectorExtension::BreakProgram)); |
| + inspector->Set( |
| + ToV8String(isolate, "createObjectWithStrictCheck"), |
| + v8::FunctionTemplate::New( |
| + isolate, &InspectorExtension::CreateObjectWithStrictCheck)); |
| + inspector->Set(ToV8String(isolate, "callWithScheduledBreak"), |
| + v8::FunctionTemplate::New( |
| + isolate, &InspectorExtension::CallWithScheduledBreak)); |
| + inspector->Set(ToV8String(isolate, "allowAccessorFormatting"), |
| + v8::FunctionTemplate::New( |
| + isolate, &InspectorExtension::AllowAccessorFormatting)); |
| + global->Set(ToV8String(isolate, "inspector"), inspector); |
| + } |
| + |
| + private: |
| + static void Attach(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + v8::Isolate* isolate = args.GetIsolate(); |
| + v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| + v8_inspector::V8Inspector* inspector = |
| + InspectorClientImpl::InspectorFromContext(context); |
| + if (!inspector) { |
| + fprintf(stderr, "Inspector client not found - cannot attach!"); |
| + Exit(); |
| + } |
| + inspector->contextCreated( |
| + v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); |
| + } |
| + |
| + static void Detach(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + v8::Isolate* isolate = args.GetIsolate(); |
| + v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| + v8_inspector::V8Inspector* inspector = |
| + InspectorClientImpl::InspectorFromContext(context); |
| + if (!inspector) { |
| + fprintf(stderr, "Inspector client not found - cannot detach!"); |
| + Exit(); |
| + } |
| + inspector->contextDestroyed(context); |
| + } |
| + |
| + static void SetMaxAsyncTaskStacks( |
| + const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + if (args.Length() != 1 || !args[0]->IsInt32()) { |
| + fprintf(stderr, "Internal error: setMaxAsyncTaskStacks(max)."); |
| + Exit(); |
| + } |
| + v8_inspector::V8Inspector* inspector = |
| + InspectorClientImpl::InspectorFromContext( |
| + args.GetIsolate()->GetCurrentContext()); |
| + CHECK(inspector); |
| + v8_inspector::SetMaxAsyncTaskStacksForTest( |
| + inspector, args[0].As<v8::Int32>()->Value()); |
| + } |
| + |
| + static void DumpAsyncTaskStacksStateForTest( |
| + const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + if (args.Length() != 0) { |
| + fprintf(stderr, "Internal error: dumpAsyncTaskStacksStateForTest()."); |
| + Exit(); |
| + } |
| + v8_inspector::V8Inspector* inspector = |
| + InspectorClientImpl::InspectorFromContext( |
| + args.GetIsolate()->GetCurrentContext()); |
| + CHECK(inspector); |
| + v8_inspector::DumpAsyncTaskStacksStateForTest(inspector); |
| + } |
| + |
| + static void BreakProgram(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString()) { |
| + fprintf(stderr, "Internal error: breakProgram('reason', 'details')."); |
| + Exit(); |
| + } |
| + v8_inspector::V8InspectorSession* session = |
| + InspectorClientImpl::SessionFromContext( |
| + args.GetIsolate()->GetCurrentContext()); |
| + CHECK(session); |
| + |
| + v8::internal::Vector<uint16_t> reason = ToVector(args[0].As<v8::String>()); |
| + v8_inspector::StringView reason_view(reason.start(), reason.length()); |
| + v8::internal::Vector<uint16_t> details = ToVector(args[1].As<v8::String>()); |
| + v8_inspector::StringView details_view(details.start(), details.length()); |
| + session->breakProgram(reason_view, details_view); |
| + } |
| + |
| + static void CreateObjectWithStrictCheck( |
| + const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + if (args.Length() != 0) { |
| + fprintf(stderr, "Internal error: createObjectWithStrictCheck()."); |
| + Exit(); |
| + } |
| + v8::Local<v8::ObjectTemplate> templ = |
| + v8::ObjectTemplate::New(args.GetIsolate()); |
| + templ->SetAccessCheckCallback(&StrictAccessCheck); |
| + args.GetReturnValue().Set( |
| + templ->NewInstance(args.GetIsolate()->GetCurrentContext()) |
| + .ToLocalChecked()); |
| + } |
| + |
| + static void CallWithScheduledBreak( |
| + const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + if (args.Length() != 3 || !args[0]->IsFunction() || !args[1]->IsString() || |
| + !args[2]->IsString()) { |
| + fprintf(stderr, "Internal error: breakProgram('reason', 'details')."); |
| + Exit(); |
| + } |
| + v8_inspector::V8InspectorSession* session = |
| + InspectorClientImpl::SessionFromContext( |
| + args.GetIsolate()->GetCurrentContext()); |
| + CHECK(session); |
| + |
| + v8::internal::Vector<uint16_t> reason = ToVector(args[1].As<v8::String>()); |
| + v8_inspector::StringView reason_view(reason.start(), reason.length()); |
| + v8::internal::Vector<uint16_t> details = ToVector(args[2].As<v8::String>()); |
| + v8_inspector::StringView details_view(details.start(), details.length()); |
| + session->schedulePauseOnNextStatement(reason_view, details_view); |
| + v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
| + v8::MaybeLocal<v8::Value> result; |
| + result = args[0].As<v8::Function>()->Call(context, context->Global(), 0, |
| + nullptr); |
| + session->cancelPauseOnNextStatement(); |
| + } |
| + |
| + static void AllowAccessorFormatting( |
| + const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + if (args.Length() != 1 || !args[0]->IsObject()) { |
| + fprintf(stderr, "Internal error: allowAccessorFormatting('object')."); |
| + Exit(); |
| + } |
| + v8::Local<v8::Object> object = args[0].As<v8::Object>(); |
| + v8::Isolate* isolate = args.GetIsolate(); |
| + v8::Local<v8::Private> shouldFormatAccessorsPrivate = v8::Private::ForApi( |
| + isolate, v8::String::NewFromUtf8(isolate, "allowAccessorFormatting", |
| + v8::NewStringType::kNormal) |
| + .ToLocalChecked()); |
| + object |
| + ->SetPrivate(isolate->GetCurrentContext(), shouldFormatAccessorsPrivate, |
| + v8::Null(isolate)) |
| + .ToChecked(); |
| + } |
| +}; |
| + |
| +class UtilsExtension : public TaskRunner::SetupGlobalTask { |
| public: |
| ~UtilsExtension() override = default; |
| - bool is_inspector_task() override { return true; } |
| void Run(v8::Isolate* isolate, |
| - const v8::Global<v8::Context>& context) override { |
| - v8::HandleScope handle_scope(isolate); |
| - v8::Local<v8::Context> local_context = context.Get(isolate); |
| - v8::Context::Scope context_scope(local_context); |
| + v8::Local<v8::ObjectTemplate> global) override { |
| v8::Local<v8::ObjectTemplate> utils = v8::ObjectTemplate::New(isolate); |
| utils->Set(ToV8String(isolate, "print"), |
| v8::FunctionTemplate::New(isolate, &UtilsExtension::Print)); |
| @@ -94,10 +322,7 @@ class UtilsExtension : public TaskRunner::Task { |
| utils->Set(ToV8String(isolate, "createContextGroup"), |
| v8::FunctionTemplate::New(isolate, |
| &UtilsExtension::CreateContextGroup)); |
| - local_context->Global() |
| - ->Set(local_context, ToV8String(isolate, "utils"), |
| - utils->NewInstance(local_context).ToLocalChecked()) |
| - .ToChecked(); |
| + global->Set(ToV8String(isolate, "utils"), utils); |
| } |
| static void set_backend_task_runner(TaskRunner* runner) { |
| @@ -287,14 +512,13 @@ class UtilsExtension : public TaskRunner::Task { |
| fprintf(stderr, "Internal error: createContextGroup()."); |
| Exit(); |
| } |
| - const char* backend_extensions[] = {"v8_inspector/setTimeout", |
| - "v8_inspector/inspector"}; |
| - v8::ExtensionConfiguration backend_configuration( |
| - arraysize(backend_extensions), backend_extensions); |
| v8::base::Semaphore ready_semaphore(0); |
| int context_group_id = 0; |
| + TaskRunner::SetupGlobalTasks setup_global; |
| + setup_global.emplace_back(new SetTimeoutExtension()); |
| + setup_global.emplace_back(new InspectorExtension()); |
| inspector_client_->scheduleCreateContextGroup( |
| - &backend_configuration, &ready_semaphore, &context_group_id); |
| + std::move(setup_global), &ready_semaphore, &context_group_id); |
| ready_semaphore.Wait(); |
| args.GetReturnValue().Set( |
| v8::Int32::New(args.GetIsolate(), context_group_id)); |
| @@ -304,280 +528,6 @@ class UtilsExtension : public TaskRunner::Task { |
| TaskRunner* UtilsExtension::backend_runner_ = nullptr; |
| InspectorClientImpl* UtilsExtension::inspector_client_ = nullptr; |
| -class SetTimeoutTask : public AsyncTask { |
| - public: |
| - SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function, |
| - const char* task_name, v8_inspector::V8Inspector* inspector) |
| - : AsyncTask(task_name, inspector), function_(isolate, function) {} |
| - virtual ~SetTimeoutTask() {} |
| - |
| - bool is_inspector_task() final { return false; } |
| - |
| - void AsyncRun(v8::Isolate* isolate, |
| - const v8::Global<v8::Context>& global_context) override { |
| - v8::MicrotasksScope microtasks_scope(isolate, |
| - v8::MicrotasksScope::kRunMicrotasks); |
| - v8::HandleScope handle_scope(isolate); |
| - v8::Local<v8::Context> context = global_context.Get(isolate); |
| - v8::Context::Scope context_scope(context); |
| - |
| - v8::Local<v8::Function> function = function_.Get(isolate); |
| - v8::MaybeLocal<v8::Value> result; |
| - result = function->Call(context, context->Global(), 0, nullptr); |
| - } |
| - |
| - private: |
| - v8::Global<v8::Function> function_; |
| -}; |
| - |
| -class SetTimeoutExtension : public v8::Extension { |
| - public: |
| - SetTimeoutExtension() |
| - : v8::Extension("v8_inspector/setTimeout", |
| - "native function setTimeout();") {} |
| - |
| - virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| - v8::Isolate* isolate, v8::Local<v8::String> name) { |
| - return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout); |
| - } |
| - |
| - private: |
| - static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| - if (args.Length() != 2 || !args[1]->IsNumber() || |
| - (!args[0]->IsFunction() && !args[0]->IsString()) || |
| - args[1].As<v8::Number>()->Value() != 0.0) { |
| - fprintf(stderr, |
| - "Internal error: only setTimeout(function, 0) is supported."); |
| - Exit(); |
| - } |
| - v8::Isolate* isolate = args.GetIsolate(); |
| - v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| - std::unique_ptr<TaskRunner::Task> task; |
| - v8_inspector::V8Inspector* inspector = |
| - InspectorClientImpl::InspectorFromContext(context); |
| - if (args[0]->IsFunction()) { |
| - task.reset(new SetTimeoutTask(isolate, |
| - v8::Local<v8::Function>::Cast(args[0]), |
| - "setTimeout", inspector)); |
| - } else { |
| - task.reset(new ExecuteStringTask( |
| - ToVector(args[0].As<v8::String>()), v8::String::Empty(isolate), |
| - v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0), |
| - v8::Boolean::New(isolate, false), "setTimeout", inspector)); |
| - } |
| - TaskRunner::FromContext(context)->Append(task.release()); |
| - } |
| -}; |
| - |
| -bool StrictAccessCheck(v8::Local<v8::Context> accessing_context, |
| - v8::Local<v8::Object> accessed_object, |
| - v8::Local<v8::Value> data) { |
| - CHECK(accessing_context.IsEmpty()); |
| - return accessing_context.IsEmpty(); |
| -} |
| - |
| -class InspectorExtension : public v8::Extension { |
| - public: |
| - InspectorExtension() |
| - : v8::Extension("v8_inspector/inspector", |
| - "native function attachInspector();" |
| - "native function detachInspector();" |
| - "native function setMaxAsyncTaskStacks();" |
| - "native function dumpAsyncTaskStacksStateForTest();" |
| - "native function breakProgram();" |
| - "native function createObjectWithStrictCheck();" |
| - "native function callWithScheduledBreak();" |
| - "native function allowAccessorFormatting();") {} |
| - |
| - virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| - v8::Isolate* isolate, v8::Local<v8::String> name) { |
| - v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| - if (name->Equals(context, |
| - v8::String::NewFromUtf8(isolate, "attachInspector", |
| - v8::NewStringType::kNormal) |
| - .ToLocalChecked()) |
| - .FromJust()) { |
| - return v8::FunctionTemplate::New(isolate, InspectorExtension::Attach); |
| - } else if (name->Equals(context, |
| - v8::String::NewFromUtf8(isolate, "detachInspector", |
| - v8::NewStringType::kNormal) |
| - .ToLocalChecked()) |
| - .FromJust()) { |
| - return v8::FunctionTemplate::New(isolate, InspectorExtension::Detach); |
| - } else if (name->Equals(context, v8::String::NewFromUtf8( |
| - isolate, "setMaxAsyncTaskStacks", |
| - v8::NewStringType::kNormal) |
| - .ToLocalChecked()) |
| - .FromJust()) { |
| - return v8::FunctionTemplate::New( |
| - isolate, InspectorExtension::SetMaxAsyncTaskStacks); |
| - } else if (name->Equals(context, |
| - v8::String::NewFromUtf8( |
| - isolate, "dumpAsyncTaskStacksStateForTest", |
| - v8::NewStringType::kNormal) |
| - .ToLocalChecked()) |
| - .FromJust()) { |
| - return v8::FunctionTemplate::New( |
| - isolate, InspectorExtension::DumpAsyncTaskStacksStateForTest); |
| - } else if (name->Equals(context, |
| - v8::String::NewFromUtf8(isolate, "breakProgram", |
| - v8::NewStringType::kNormal) |
| - .ToLocalChecked()) |
| - .FromJust()) { |
| - return v8::FunctionTemplate::New(isolate, |
| - InspectorExtension::BreakProgram); |
| - } else if (name->Equals(context, v8::String::NewFromUtf8( |
| - isolate, "createObjectWithStrictCheck", |
| - v8::NewStringType::kNormal) |
| - .ToLocalChecked()) |
| - .FromJust()) { |
| - return v8::FunctionTemplate::New( |
| - isolate, InspectorExtension::CreateObjectWithStrictCheck); |
| - } else if (name->Equals(context, v8::String::NewFromUtf8( |
| - isolate, "callWithScheduledBreak", |
| - v8::NewStringType::kNormal) |
| - .ToLocalChecked()) |
| - .FromJust()) { |
| - return v8::FunctionTemplate::New( |
| - isolate, InspectorExtension::CallWithScheduledBreak); |
| - } else if (name->Equals(context, v8::String::NewFromUtf8( |
| - isolate, "allowAccessorFormatting", |
| - v8::NewStringType::kNormal) |
| - .ToLocalChecked()) |
| - .FromJust()) { |
| - return v8::FunctionTemplate::New( |
| - isolate, InspectorExtension::AllowAccessorFormatting); |
| - } |
| - return v8::Local<v8::FunctionTemplate>(); |
| - } |
| - |
| - private: |
| - static void Attach(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| - v8::Isolate* isolate = args.GetIsolate(); |
| - v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| - v8_inspector::V8Inspector* inspector = |
| - InspectorClientImpl::InspectorFromContext(context); |
| - if (!inspector) { |
| - fprintf(stderr, "Inspector client not found - cannot attach!"); |
| - Exit(); |
| - } |
| - inspector->contextCreated( |
| - v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); |
| - } |
| - |
| - static void Detach(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| - v8::Isolate* isolate = args.GetIsolate(); |
| - v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| - v8_inspector::V8Inspector* inspector = |
| - InspectorClientImpl::InspectorFromContext(context); |
| - if (!inspector) { |
| - fprintf(stderr, "Inspector client not found - cannot detach!"); |
| - Exit(); |
| - } |
| - inspector->contextDestroyed(context); |
| - } |
| - |
| - static void SetMaxAsyncTaskStacks( |
| - const v8::FunctionCallbackInfo<v8::Value>& args) { |
| - if (args.Length() != 1 || !args[0]->IsInt32()) { |
| - fprintf(stderr, "Internal error: setMaxAsyncTaskStacks(max)."); |
| - Exit(); |
| - } |
| - v8_inspector::V8Inspector* inspector = |
| - InspectorClientImpl::InspectorFromContext( |
| - args.GetIsolate()->GetCurrentContext()); |
| - CHECK(inspector); |
| - v8_inspector::SetMaxAsyncTaskStacksForTest( |
| - inspector, args[0].As<v8::Int32>()->Value()); |
| - } |
| - |
| - static void DumpAsyncTaskStacksStateForTest( |
| - const v8::FunctionCallbackInfo<v8::Value>& args) { |
| - if (args.Length() != 0) { |
| - fprintf(stderr, "Internal error: dumpAsyncTaskStacksStateForTest()."); |
| - Exit(); |
| - } |
| - v8_inspector::V8Inspector* inspector = |
| - InspectorClientImpl::InspectorFromContext( |
| - args.GetIsolate()->GetCurrentContext()); |
| - CHECK(inspector); |
| - v8_inspector::DumpAsyncTaskStacksStateForTest(inspector); |
| - } |
| - |
| - static void BreakProgram(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| - if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString()) { |
| - fprintf(stderr, "Internal error: breakProgram('reason', 'details')."); |
| - Exit(); |
| - } |
| - v8_inspector::V8InspectorSession* session = |
| - InspectorClientImpl::SessionFromContext( |
| - args.GetIsolate()->GetCurrentContext()); |
| - CHECK(session); |
| - |
| - v8::internal::Vector<uint16_t> reason = ToVector(args[0].As<v8::String>()); |
| - v8_inspector::StringView reason_view(reason.start(), reason.length()); |
| - v8::internal::Vector<uint16_t> details = ToVector(args[1].As<v8::String>()); |
| - v8_inspector::StringView details_view(details.start(), details.length()); |
| - session->breakProgram(reason_view, details_view); |
| - } |
| - |
| - static void CreateObjectWithStrictCheck( |
| - const v8::FunctionCallbackInfo<v8::Value>& args) { |
| - if (args.Length() != 0) { |
| - fprintf(stderr, "Internal error: createObjectWithStrictCheck()."); |
| - Exit(); |
| - } |
| - v8::Local<v8::ObjectTemplate> templ = |
| - v8::ObjectTemplate::New(args.GetIsolate()); |
| - templ->SetAccessCheckCallback(&StrictAccessCheck); |
| - args.GetReturnValue().Set( |
| - templ->NewInstance(args.GetIsolate()->GetCurrentContext()) |
| - .ToLocalChecked()); |
| - } |
| - |
| - static void CallWithScheduledBreak( |
| - const v8::FunctionCallbackInfo<v8::Value>& args) { |
| - if (args.Length() != 3 || !args[0]->IsFunction() || !args[1]->IsString() || |
| - !args[2]->IsString()) { |
| - fprintf(stderr, "Internal error: breakProgram('reason', 'details')."); |
| - Exit(); |
| - } |
| - v8_inspector::V8InspectorSession* session = |
| - InspectorClientImpl::SessionFromContext( |
| - args.GetIsolate()->GetCurrentContext()); |
| - CHECK(session); |
| - |
| - v8::internal::Vector<uint16_t> reason = ToVector(args[1].As<v8::String>()); |
| - v8_inspector::StringView reason_view(reason.start(), reason.length()); |
| - v8::internal::Vector<uint16_t> details = ToVector(args[2].As<v8::String>()); |
| - v8_inspector::StringView details_view(details.start(), details.length()); |
| - session->schedulePauseOnNextStatement(reason_view, details_view); |
| - v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
| - v8::MaybeLocal<v8::Value> result; |
| - result = args[0].As<v8::Function>()->Call(context, context->Global(), 0, |
| - nullptr); |
| - session->cancelPauseOnNextStatement(); |
| - } |
| - |
| - static void AllowAccessorFormatting( |
| - const v8::FunctionCallbackInfo<v8::Value>& args) { |
| - if (args.Length() != 1 || !args[0]->IsObject()) { |
| - fprintf(stderr, "Internal error: allowAccessorFormatting('object')."); |
| - Exit(); |
| - } |
| - v8::Local<v8::Object> object = args[0].As<v8::Object>(); |
| - v8::Isolate* isolate = args.GetIsolate(); |
| - v8::Local<v8::Private> shouldFormatAccessorsPrivate = v8::Private::ForApi( |
| - isolate, v8::String::NewFromUtf8(isolate, "allowAccessorFormatting", |
| - v8::NewStringType::kNormal) |
| - .ToLocalChecked()); |
| - object |
| - ->SetPrivate(isolate->GetCurrentContext(), shouldFormatAccessorsPrivate, |
| - v8::Null(isolate)) |
| - .ToChecked(); |
| - } |
| -}; |
| - |
| v8::Local<v8::String> ToString(v8::Isolate* isolate, |
| const v8_inspector::StringView& string) { |
| if (string.is8Bit()) |
| @@ -634,30 +584,23 @@ int main(int argc, char* argv[]) { |
| v8::V8::InitializeExternalStartupData(argv[0]); |
| v8::V8::Initialize(); |
| - SetTimeoutExtension set_timeout_extension; |
| - v8::RegisterExtension(&set_timeout_extension); |
| - InspectorExtension inspector_extension; |
| - v8::RegisterExtension(&inspector_extension); |
| - SendMessageToBackendExtension send_message_to_backend_extension; |
| - v8::RegisterExtension(&send_message_to_backend_extension); |
| - |
| v8::base::Semaphore ready_semaphore(0); |
| - const char* backend_extensions[] = {"v8_inspector/setTimeout", |
| - "v8_inspector/inspector"}; |
| - v8::ExtensionConfiguration backend_configuration( |
| - arraysize(backend_extensions), backend_extensions); |
| - TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore); |
| + TaskRunner::SetupGlobalTasks backend_extensions; |
| + backend_extensions.emplace_back(new SetTimeoutExtension()); |
| + backend_extensions.emplace_back(new InspectorExtension()); |
| + TaskRunner backend_runner(std::move(backend_extensions), false, |
| + &ready_semaphore); |
| ready_semaphore.Wait(); |
| SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); |
| UtilsExtension::set_backend_task_runner(&backend_runner); |
| - const char* frontend_extensions[] = {"v8_inspector/frontend"}; |
| - v8::ExtensionConfiguration frontend_configuration( |
| - arraysize(frontend_extensions), frontend_extensions); |
| - TaskRunner frontend_runner(&frontend_configuration, true, &ready_semaphore); |
| + TaskRunner::SetupGlobalTasks frontend_extensions; |
| + frontend_extensions.emplace_back(new UtilsExtension()); |
| + frontend_extensions.emplace_back(new SendMessageToBackendExtension()); |
| + TaskRunner frontend_runner(std::move(frontend_extensions), true, |
| + &ready_semaphore); |
| ready_semaphore.Wait(); |
| - frontend_runner.Append(new UtilsExtension()); |
| FrontendChannelImpl frontend_channel(&frontend_runner); |
| InspectorClientImpl inspector_client(&backend_runner, &frontend_channel, |