Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: test/inspector/isolate-data.cc

Issue 2901523003: [inspector] Cleanup inspector test (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/inspector/isolate-data.h ('k') | test/inspector/task-runner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 the V8 project authors. All rights reserved. 1 // Copyright 2017 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/isolate-data.h" 5 #include "test/inspector/isolate-data.h"
6 6
7 #include "src/inspector/test-interface.h"
7 #include "test/inspector/task-runner.h" 8 #include "test/inspector/task-runner.h"
8 9
9 namespace { 10 namespace {
10 11
11 const int kIsolateDataIndex = 2; 12 const int kIsolateDataIndex = 2;
12 const int kContextGroupIdIndex = 3; 13 const int kContextGroupIdIndex = 3;
13 14
14 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) { 15 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) {
15 v8::internal::Vector<uint16_t> buffer = 16 v8::internal::Vector<uint16_t> buffer =
16 v8::internal::Vector<uint16_t>::New(str->Length()); 17 v8::internal::Vector<uint16_t>::New(str->Length());
(...skipping 14 matching lines...) Expand all
31 static_cast<int>(string.length())) 32 static_cast<int>(string.length()))
32 .ToLocalChecked(); 33 .ToLocalChecked();
33 } 34 }
34 35
35 void Print(v8::Isolate* isolate, const v8_inspector::StringView& string) { 36 void Print(v8::Isolate* isolate, const v8_inspector::StringView& string) {
36 v8::Local<v8::String> v8_string = ToString(isolate, string); 37 v8::Local<v8::String> v8_string = ToString(isolate, string);
37 v8::String::Utf8Value utf8_string(v8_string); 38 v8::String::Utf8Value utf8_string(v8_string);
38 fwrite(*utf8_string, sizeof(**utf8_string), utf8_string.length(), stdout); 39 fwrite(*utf8_string, sizeof(**utf8_string), utf8_string.length(), stdout);
39 } 40 }
40 41
41 class ChannelImpl final : public v8_inspector::V8Inspector::Channel {
42 public:
43 ChannelImpl(IsolateData::FrontendChannel* frontend_channel, int session_id)
44 : frontend_channel_(frontend_channel), session_id_(session_id) {}
45 virtual ~ChannelImpl() = default;
46
47 private:
48 void sendResponse(
49 int callId,
50 std::unique_ptr<v8_inspector::StringBuffer> message) override {
51 frontend_channel_->SendMessageToFrontend(session_id_, message->string());
52 }
53 void sendNotification(
54 std::unique_ptr<v8_inspector::StringBuffer> message) override {
55 frontend_channel_->SendMessageToFrontend(session_id_, message->string());
56 }
57 void flushProtocolNotifications() override {}
58
59 IsolateData::FrontendChannel* frontend_channel_;
60 int session_id_;
61 DISALLOW_COPY_AND_ASSIGN(ChannelImpl);
62 };
63
64 } // namespace 42 } // namespace
65 43
66 IsolateData::IsolateData(TaskRunner* task_runner, 44 IsolateData::IsolateData(TaskRunner* task_runner,
67 IsolateData::SetupGlobalTasks setup_global_tasks, 45 IsolateData::SetupGlobalTasks setup_global_tasks,
68 v8::StartupData* startup_data, 46 v8::StartupData* startup_data, bool with_inspector)
69 FrontendChannel* channel)
70 : task_runner_(task_runner), 47 : task_runner_(task_runner),
71 setup_global_tasks_(std::move(setup_global_tasks)), 48 setup_global_tasks_(std::move(setup_global_tasks)) {
72 frontend_channel_(channel) {
73 v8::Isolate::CreateParams params; 49 v8::Isolate::CreateParams params;
74 params.array_buffer_allocator = 50 params.array_buffer_allocator =
75 v8::ArrayBuffer::Allocator::NewDefaultAllocator(); 51 v8::ArrayBuffer::Allocator::NewDefaultAllocator();
76 params.snapshot_blob = startup_data; 52 params.snapshot_blob = startup_data;
77 isolate_ = v8::Isolate::New(params); 53 isolate_ = v8::Isolate::New(params);
78 isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); 54 isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
79 if (frontend_channel_) { 55 if (with_inspector) {
80 isolate_->AddMessageListener(&IsolateData::MessageHandler); 56 isolate_->AddMessageListener(&IsolateData::MessageHandler);
81 inspector_ = v8_inspector::V8Inspector::create(isolate_, this); 57 inspector_ = v8_inspector::V8Inspector::create(isolate_, this);
82 } 58 }
83 } 59 }
84 60
85 IsolateData* IsolateData::FromContext(v8::Local<v8::Context> context) { 61 IsolateData* IsolateData::FromContext(v8::Local<v8::Context> context) {
86 return static_cast<IsolateData*>( 62 return static_cast<IsolateData*>(
87 context->GetAlignedPointerFromEmbedderData(kIsolateDataIndex)); 63 context->GetAlignedPointerFromEmbedderData(kIsolateDataIndex));
88 } 64 }
89 65
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // static 110 // static
135 v8::MaybeLocal<v8::Module> IsolateData::ModuleResolveCallback( 111 v8::MaybeLocal<v8::Module> IsolateData::ModuleResolveCallback(
136 v8::Local<v8::Context> context, v8::Local<v8::String> specifier, 112 v8::Local<v8::Context> context, v8::Local<v8::String> specifier,
137 v8::Local<v8::Module> referrer) { 113 v8::Local<v8::Module> referrer) {
138 std::string str = *v8::String::Utf8Value(specifier); 114 std::string str = *v8::String::Utf8Value(specifier);
139 IsolateData* data = IsolateData::FromContext(context); 115 IsolateData* data = IsolateData::FromContext(context);
140 return data->modules_[ToVector(specifier)].Get(data->isolate_); 116 return data->modules_[ToVector(specifier)].Get(data->isolate_);
141 } 117 }
142 118
143 int IsolateData::ConnectSession(int context_group_id, 119 int IsolateData::ConnectSession(int context_group_id,
144 const v8_inspector::StringView& state) { 120 const v8_inspector::StringView& state,
121 v8_inspector::V8Inspector::Channel* channel) {
145 int session_id = ++last_session_id_; 122 int session_id = ++last_session_id_;
146 channels_[session_id].reset(new ChannelImpl(frontend_channel_, session_id)); 123 sessions_[session_id] = inspector_->connect(context_group_id, channel, state);
147 sessions_[session_id] =
148 inspector_->connect(context_group_id, channels_[session_id].get(), state);
149 context_group_by_session_[sessions_[session_id].get()] = context_group_id; 124 context_group_by_session_[sessions_[session_id].get()] = context_group_id;
150 return session_id; 125 return session_id;
151 } 126 }
152 127
153 std::unique_ptr<v8_inspector::StringBuffer> IsolateData::DisconnectSession( 128 std::unique_ptr<v8_inspector::StringBuffer> IsolateData::DisconnectSession(
154 int session_id) { 129 int session_id) {
155 auto it = sessions_.find(session_id); 130 auto it = sessions_.find(session_id);
156 CHECK(it != sessions_.end()); 131 CHECK(it != sessions_.end());
157 context_group_by_session_.erase(it->second.get()); 132 context_group_by_session_.erase(it->second.get());
158 std::unique_ptr<v8_inspector::StringBuffer> result = it->second->stateJSON(); 133 std::unique_ptr<v8_inspector::StringBuffer> result = it->second->stateJSON();
159 sessions_.erase(it); 134 sessions_.erase(it);
160 channels_.erase(session_id);
161 return result; 135 return result;
162 } 136 }
163 137
164 void IsolateData::SendMessage(int session_id, 138 void IsolateData::SendMessage(int session_id,
165 const v8_inspector::StringView& message) { 139 const v8_inspector::StringView& message) {
166 auto it = sessions_.find(session_id); 140 auto it = sessions_.find(session_id);
167 if (it != sessions_.end()) it->second->dispatchProtocolMessage(message); 141 if (it != sessions_.end()) it->second->dispatchProtocolMessage(message);
168 } 142 }
169 143
170 void IsolateData::BreakProgram(int context_group_id, 144 void IsolateData::BreakProgram(int context_group_id,
(...skipping 15 matching lines...) Expand all
186 } 160 }
187 } 161 }
188 162
189 void IsolateData::CancelPauseOnNextStatement(int context_group_id) { 163 void IsolateData::CancelPauseOnNextStatement(int context_group_id) {
190 for (int session_id : GetSessionIds(context_group_id)) { 164 for (int session_id : GetSessionIds(context_group_id)) {
191 auto it = sessions_.find(session_id); 165 auto it = sessions_.find(session_id);
192 if (it != sessions_.end()) it->second->cancelPauseOnNextStatement(); 166 if (it != sessions_.end()) it->second->cancelPauseOnNextStatement();
193 } 167 }
194 } 168 }
195 169
170 void IsolateData::AsyncTaskScheduled(const v8_inspector::StringView& name,
171 void* task, bool recurring) {
172 inspector_->asyncTaskScheduled(name, task, recurring);
173 }
174
175 void IsolateData::AsyncTaskStarted(void* task) {
176 inspector_->asyncTaskStarted(task);
177 }
178
179 void IsolateData::AsyncTaskFinished(void* task) {
180 inspector_->asyncTaskFinished(task);
181 }
182
183 void IsolateData::SetMaxAsyncTaskStacksForTest(int limit) {
184 v8_inspector::SetMaxAsyncTaskStacksForTest(inspector_.get(), limit);
185 }
186
187 void IsolateData::DumpAsyncTaskStacksStateForTest() {
188 v8_inspector::DumpAsyncTaskStacksStateForTest(inspector_.get());
189 }
190
196 // static 191 // static
197 void IsolateData::MessageHandler(v8::Local<v8::Message> message, 192 void IsolateData::MessageHandler(v8::Local<v8::Message> message,
198 v8::Local<v8::Value> exception) { 193 v8::Local<v8::Value> exception) {
199 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 194 v8::Isolate* isolate = v8::Isolate::GetCurrent();
200 v8::Local<v8::Context> context = isolate->GetEnteredContext(); 195 v8::Local<v8::Context> context = isolate->GetEnteredContext();
201 if (context.IsEmpty()) return; 196 if (context.IsEmpty()) return;
202 v8_inspector::V8Inspector* inspector = 197 v8_inspector::V8Inspector* inspector =
203 IsolateData::FromContext(context)->inspector_.get(); 198 IsolateData::FromContext(context)->inspector_.get();
204 199
205 v8::Local<v8::StackTrace> stack = message->GetStackTrace(); 200 v8::Local<v8::StackTrace> stack = message->GetStackTrace();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 unsigned lineNumber, unsigned columnNumber, 301 unsigned lineNumber, unsigned columnNumber,
307 v8_inspector::V8StackTrace* stack) { 302 v8_inspector::V8StackTrace* stack) {
308 if (!log_console_api_message_calls_) return; 303 if (!log_console_api_message_calls_) return;
309 Print(isolate_, message); 304 Print(isolate_, message);
310 fprintf(stdout, " ("); 305 fprintf(stdout, " (");
311 Print(isolate_, url); 306 Print(isolate_, url);
312 fprintf(stdout, ":%d:%d)", lineNumber, columnNumber); 307 fprintf(stdout, ":%d:%d)", lineNumber, columnNumber);
313 Print(isolate_, stack->toString()->string()); 308 Print(isolate_, stack->toString()->string());
314 fprintf(stdout, "\n"); 309 fprintf(stdout, "\n");
315 } 310 }
OLDNEW
« no previous file with comments | « test/inspector/isolate-data.h ('k') | test/inspector/task-runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698