| 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 #include "test/inspector/inspector-impl.h" | 5 #include "test/inspector/inspector-impl.h" |
| 6 | 6 |
| 7 #include "include/v8.h" | 7 #include "include/v8.h" |
| 8 #include "src/inspector/string-16.h" | 8 #include "src/inspector/string-16.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 void sendProtocolNotification( | 25 void sendProtocolNotification( |
| 26 const v8_inspector::StringView& message) override { | 26 const v8_inspector::StringView& message) override { |
| 27 frontend_channel_->SendMessageToFrontend(message); | 27 frontend_channel_->SendMessageToFrontend(message); |
| 28 } | 28 } |
| 29 void flushProtocolNotifications() override {} | 29 void flushProtocolNotifications() override {} |
| 30 | 30 |
| 31 InspectorClientImpl::FrontendChannel* frontend_channel_; | 31 InspectorClientImpl::FrontendChannel* frontend_channel_; |
| 32 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); | 32 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 InspectorClientImpl* InspectorClientFromContext( | |
| 36 v8::Local<v8::Context> context) { | |
| 37 InspectorClientImpl* inspector_client = static_cast<InspectorClientImpl*>( | |
| 38 context->GetAlignedPointerFromEmbedderData(kInspectorClientIndex)); | |
| 39 CHECK(inspector_client); | |
| 40 return inspector_client; | |
| 41 } | |
| 42 | |
| 43 } // namespace | 35 } // namespace |
| 44 | 36 |
| 45 class ConnectTask : public TaskRunner::Task { | 37 class ConnectTask : public TaskRunner::Task { |
| 46 public: | 38 public: |
| 47 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore) | 39 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore) |
| 48 : client_(client), ready_semaphore_(ready_semaphore) {} | 40 : client_(client), ready_semaphore_(ready_semaphore) {} |
| 49 virtual ~ConnectTask() = default; | 41 virtual ~ConnectTask() = default; |
| 50 | 42 |
| 51 bool is_inspector_task() final { return true; } | 43 bool is_inspector_task() final { return true; } |
| 52 | 44 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 89 } |
| 98 | 90 |
| 99 void InspectorClientImpl::runMessageLoopOnPause(int) { | 91 void InspectorClientImpl::runMessageLoopOnPause(int) { |
| 100 task_runner_->RunMessageLoop(true); | 92 task_runner_->RunMessageLoop(true); |
| 101 } | 93 } |
| 102 | 94 |
| 103 void InspectorClientImpl::quitMessageLoopOnPause() { | 95 void InspectorClientImpl::quitMessageLoopOnPause() { |
| 104 task_runner_->QuitMessageLoop(); | 96 task_runner_->QuitMessageLoop(); |
| 105 } | 97 } |
| 106 | 98 |
| 107 v8_inspector::V8Inspector* InspectorClientImpl::InspectorFromContext( | |
| 108 v8::Local<v8::Context> context) { | |
| 109 return InspectorClientFromContext(context)->inspector_.get(); | |
| 110 } | |
| 111 | |
| 112 v8_inspector::V8InspectorSession* InspectorClientImpl::SessionFromContext( | 99 v8_inspector::V8InspectorSession* InspectorClientImpl::SessionFromContext( |
| 113 v8::Local<v8::Context> context) { | 100 v8::Local<v8::Context> context) { |
| 114 return InspectorClientFromContext(context)->session_.get(); | 101 InspectorClientImpl* inspector_client = static_cast<InspectorClientImpl*>( |
| 102 context->GetAlignedPointerFromEmbedderData(kInspectorClientIndex)); |
| 103 CHECK(inspector_client); |
| 104 return inspector_client->session_.get(); |
| 115 } | 105 } |
| 116 | 106 |
| 117 class SendMessageToBackendTask : public TaskRunner::Task { | 107 class SendMessageToBackendTask : public TaskRunner::Task { |
| 118 public: | 108 public: |
| 119 explicit SendMessageToBackendTask(const v8_inspector::String16& message) | 109 explicit SendMessageToBackendTask(const v8_inspector::String16& message) |
| 120 : message_(message) {} | 110 : message_(message) {} |
| 121 | 111 |
| 122 bool is_inspector_task() final { return true; } | 112 bool is_inspector_task() final { return true; } |
| 123 | 113 |
| 124 void Run(v8::Isolate* isolate, | 114 void Run(v8::Isolate* isolate, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 153 const v8::FunctionCallbackInfo<v8::Value>& args) { | 143 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 154 CHECK(backend_task_runner_); | 144 CHECK(backend_task_runner_); |
| 155 CHECK(args.Length() == 1 && args[0]->IsString()); | 145 CHECK(args.Length() == 1 && args[0]->IsString()); |
| 156 v8::Local<v8::String> message = args[0].As<v8::String>(); | 146 v8::Local<v8::String> message = args[0].As<v8::String>(); |
| 157 std::unique_ptr<uint16_t[]> buffer(new uint16_t[message->Length()]); | 147 std::unique_ptr<uint16_t[]> buffer(new uint16_t[message->Length()]); |
| 158 message.As<v8::String>()->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, | 148 message.As<v8::String>()->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, |
| 159 message->Length()); | 149 message->Length()); |
| 160 v8_inspector::String16 message_string(buffer.get(), message->Length()); | 150 v8_inspector::String16 message_string(buffer.get(), message->Length()); |
| 161 backend_task_runner_->Append(new SendMessageToBackendTask(message_string)); | 151 backend_task_runner_->Append(new SendMessageToBackendTask(message_string)); |
| 162 } | 152 } |
| OLD | NEW |