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