OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "test/inspector-protocol/inspector-client-impl.h" |
| 6 |
| 7 #include "src/base/platform/platform.h" |
| 8 #include "src/inspector/string-util.h" |
| 9 #include "test/inspector-protocol/channel-impl.h" |
| 10 #include "test/inspector-protocol/task-queue.h" |
| 11 #include "test/inspector-protocol/task.h" |
| 12 |
| 13 namespace v8_inspector { |
| 14 |
| 15 namespace { |
| 16 |
| 17 const int kInspectorClientIndex = v8::Context::kDebugIdIndex + 1; |
| 18 |
| 19 V8InspectorClientImpl* FromContext(v8::Local<v8::Context> context) { |
| 20 V8InspectorClientImpl* inspector_client = static_cast<V8InspectorClientImpl*>( |
| 21 context->GetAlignedPointerFromEmbedderData(kInspectorClientIndex)); |
| 22 CHECK(inspector_client); |
| 23 return inspector_client; |
| 24 } |
| 25 } |
| 26 |
| 27 V8InspectorClientImpl::V8InspectorClientImpl() |
| 28 : isolate_(nullptr), running_message_loop_(false) {} |
| 29 |
| 30 V8InspectorClientImpl::~V8InspectorClientImpl() {} |
| 31 |
| 32 void V8InspectorClientImpl::connect(ChannelImpl* channel, |
| 33 v8::Local<v8::Context> context) { |
| 34 isolate_ = context->GetIsolate(); |
| 35 |
| 36 inspector_ = V8Inspector::create(isolate_, this); |
| 37 session_ = inspector_->connect(1, channel, StringView()); |
| 38 |
| 39 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this); |
| 40 |
| 41 String16 name("Inspector Test"); |
| 42 inspector_->contextCreated(V8ContextInfo(context, 1, toStringView(name))); |
| 43 context_.Reset(isolate_, context); |
| 44 } |
| 45 |
| 46 v8::Local<v8::Context> V8InspectorClientImpl::ensureDefaultContextInGroup(int) { |
| 47 CHECK(isolate_); |
| 48 return context_.Get(isolate_); |
| 49 } |
| 50 |
| 51 double V8InspectorClientImpl::currentTimeMS() { |
| 52 return v8::base::OS::TimeCurrentMillis(); |
| 53 } |
| 54 |
| 55 void V8InspectorClientImpl::runMessageLoopOnPause(int) { |
| 56 running_message_loop_ = true; |
| 57 TaskQueue* queue = TaskQueue::FromContext(context_.Get(isolate_)); |
| 58 while (Task* task = queue->GetNext(true)) { |
| 59 task->Run(isolate_, context_); |
| 60 delete task; |
| 61 if (!running_message_loop_) break; |
| 62 } |
| 63 } |
| 64 |
| 65 void V8InspectorClientImpl::quitMessageLoopOnPause() { |
| 66 running_message_loop_ = false; |
| 67 } |
| 68 |
| 69 V8Inspector* V8InspectorClientImpl::InspectorFromContext( |
| 70 v8::Local<v8::Context> context) { |
| 71 return FromContext(context)->inspector_.get(); |
| 72 } |
| 73 |
| 74 V8InspectorSession* V8InspectorClientImpl::SessionFromContext( |
| 75 v8::Local<v8::Context> context) { |
| 76 return FromContext(context)->session_.get(); |
| 77 } |
| 78 |
| 79 ConnectTask::ConnectTask(V8InspectorClientImpl* client, ChannelImpl* channel, |
| 80 v8::base::Semaphore* ready) |
| 81 : client_(client), channel_(channel), ready_(ready) {} |
| 82 |
| 83 void ConnectTask::Run(v8::Isolate* isolate, |
| 84 const v8::Global<v8::Context>& context) { |
| 85 TaskScope scope(isolate, context); |
| 86 client_->connect(channel_, scope.context()); |
| 87 ready_->Signal(); |
| 88 } |
| 89 |
| 90 } // namespace v8 |
OLD | NEW |