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

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

Issue 2906153002: [inspector] Support multiple sessions per context group (Closed)
Patch Set: using set per kozy@ Created 3 years, 6 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/sessions/create-session.js » ('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 "src/inspector/test-interface.h"
8 #include "test/inspector/task-runner.h" 8 #include "test/inspector/task-runner.h"
9 9
10 namespace { 10 namespace {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 : task_runner_(task_runner), 47 : task_runner_(task_runner),
48 setup_global_tasks_(std::move(setup_global_tasks)) { 48 setup_global_tasks_(std::move(setup_global_tasks)) {
49 v8::Isolate::CreateParams params; 49 v8::Isolate::CreateParams params;
50 params.array_buffer_allocator = 50 params.array_buffer_allocator =
51 v8::ArrayBuffer::Allocator::NewDefaultAllocator(); 51 v8::ArrayBuffer::Allocator::NewDefaultAllocator();
52 params.snapshot_blob = startup_data; 52 params.snapshot_blob = startup_data;
53 isolate_ = v8::Isolate::New(params); 53 isolate_ = v8::Isolate::New(params);
54 isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); 54 isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
55 if (with_inspector) { 55 if (with_inspector) {
56 isolate_->AddMessageListener(&IsolateData::MessageHandler); 56 isolate_->AddMessageListener(&IsolateData::MessageHandler);
57 isolate_->SetPromiseRejectCallback(&IsolateData::PromiseRejectHandler);
57 inspector_ = v8_inspector::V8Inspector::create(isolate_, this); 58 inspector_ = v8_inspector::V8Inspector::create(isolate_, this);
58 } 59 }
59 } 60 }
60 61
61 IsolateData* IsolateData::FromContext(v8::Local<v8::Context> context) { 62 IsolateData* IsolateData::FromContext(v8::Local<v8::Context> context) {
62 return static_cast<IsolateData*>( 63 return static_cast<IsolateData*>(
63 context->GetAlignedPointerFromEmbedderData(kIsolateDataIndex)); 64 context->GetAlignedPointerFromEmbedderData(kIsolateDataIndex));
64 } 65 }
65 66
66 int IsolateData::CreateContextGroup() { 67 int IsolateData::CreateContextGroup() {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 185
185 void IsolateData::SetMaxAsyncTaskStacksForTest(int limit) { 186 void IsolateData::SetMaxAsyncTaskStacksForTest(int limit) {
186 v8_inspector::SetMaxAsyncTaskStacksForTest(inspector_.get(), limit); 187 v8_inspector::SetMaxAsyncTaskStacksForTest(inspector_.get(), limit);
187 } 188 }
188 189
189 void IsolateData::DumpAsyncTaskStacksStateForTest() { 190 void IsolateData::DumpAsyncTaskStacksStateForTest() {
190 v8_inspector::DumpAsyncTaskStacksStateForTest(inspector_.get()); 191 v8_inspector::DumpAsyncTaskStacksStateForTest(inspector_.get());
191 } 192 }
192 193
193 // static 194 // static
194 void IsolateData::MessageHandler(v8::Local<v8::Message> message, 195 int IsolateData::HandleMessage(v8::Local<v8::Message> message,
195 v8::Local<v8::Value> exception) { 196 v8::Local<v8::Value> exception) {
196 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 197 v8::Isolate* isolate = v8::Isolate::GetCurrent();
197 v8::Local<v8::Context> context = isolate->GetEnteredContext(); 198 v8::Local<v8::Context> context = isolate->GetEnteredContext();
198 if (context.IsEmpty()) return; 199 if (context.IsEmpty()) return 0;
199 v8_inspector::V8Inspector* inspector = 200 v8_inspector::V8Inspector* inspector =
200 IsolateData::FromContext(context)->inspector_.get(); 201 IsolateData::FromContext(context)->inspector_.get();
201 202
202 v8::Local<v8::StackTrace> stack = message->GetStackTrace(); 203 v8::Local<v8::StackTrace> stack = message->GetStackTrace();
203 int script_id = 204 int script_id =
204 static_cast<int>(message->GetScriptOrigin().ScriptID()->Value()); 205 static_cast<int>(message->GetScriptOrigin().ScriptID()->Value());
205 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) { 206 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) {
206 int top_script_id = stack->GetFrame(0)->GetScriptId(); 207 int top_script_id = stack->GetFrame(0)->GetScriptId();
207 if (top_script_id == script_id) script_id = 0; 208 if (top_script_id == script_id) script_id = 0;
208 } 209 }
209 int line_number = message->GetLineNumber(context).FromMaybe(0); 210 int line_number = message->GetLineNumber(context).FromMaybe(0);
210 int column_number = 0; 211 int column_number = 0;
211 if (message->GetStartColumn(context).IsJust()) 212 if (message->GetStartColumn(context).IsJust())
212 column_number = message->GetStartColumn(context).FromJust() + 1; 213 column_number = message->GetStartColumn(context).FromJust() + 1;
213 214
214 v8_inspector::StringView detailed_message; 215 v8_inspector::StringView detailed_message;
215 v8::internal::Vector<uint16_t> message_text_string = ToVector(message->Get()); 216 v8::internal::Vector<uint16_t> message_text_string = ToVector(message->Get());
216 v8_inspector::StringView message_text(message_text_string.start(), 217 v8_inspector::StringView message_text(message_text_string.start(),
217 message_text_string.length()); 218 message_text_string.length());
218 v8::internal::Vector<uint16_t> url_string; 219 v8::internal::Vector<uint16_t> url_string;
219 if (message->GetScriptOrigin().ResourceName()->IsString()) { 220 if (message->GetScriptOrigin().ResourceName()->IsString()) {
220 url_string = 221 url_string =
221 ToVector(message->GetScriptOrigin().ResourceName().As<v8::String>()); 222 ToVector(message->GetScriptOrigin().ResourceName().As<v8::String>());
222 } 223 }
223 v8_inspector::StringView url(url_string.start(), url_string.length()); 224 v8_inspector::StringView url(url_string.start(), url_string.length());
224 225
225 inspector->exceptionThrown(context, message_text, exception, detailed_message, 226 return inspector->exceptionThrown(
226 url, line_number, column_number, 227 context, message_text, exception, detailed_message, url, line_number,
227 inspector->createStackTrace(stack), script_id); 228 column_number, inspector->createStackTrace(stack), script_id);
229 }
230
231 // static
232 void IsolateData::MessageHandler(v8::Local<v8::Message> message,
233 v8::Local<v8::Value> exception) {
234 HandleMessage(message, exception);
235 }
236
237 // static
238 void IsolateData::PromiseRejectHandler(v8::PromiseRejectMessage data) {
239 v8::Isolate* isolate = v8::Isolate::GetCurrent();
240 v8::Local<v8::Context> context = isolate->GetEnteredContext();
241 if (context.IsEmpty()) return;
242 v8::Local<v8::Promise> promise = data.GetPromise();
243 v8::Local<v8::Private> id_private = v8::Private::ForApi(
244 isolate,
245 v8::String::NewFromUtf8(isolate, "id", v8::NewStringType::kNormal)
246 .ToLocalChecked());
247
248 if (data.GetEvent() == v8::kPromiseHandlerAddedAfterReject) {
249 v8::Local<v8::Value> id;
250 if (!promise->GetPrivate(context, id_private).ToLocal(&id)) return;
251 if (!id->IsInt32()) return;
252 v8_inspector::V8Inspector* inspector =
253 IsolateData::FromContext(context)->inspector_.get();
254 const char* reason_str = "Handler added to rejected promise";
255 inspector->exceptionRevoked(
256 context, id.As<v8::Int32>()->Value(),
257 v8_inspector::StringView(reinterpret_cast<const uint8_t*>(reason_str),
258 strlen(reason_str)));
259 return;
260 }
261
262 v8::Local<v8::Value> exception = data.GetValue();
263 int exception_id = HandleMessage(
264 v8::Exception::CreateMessage(isolate, exception), exception);
265 if (exception_id) {
266 promise
267 ->SetPrivate(isolate->GetCurrentContext(), id_private,
268 v8::Int32::New(isolate, exception_id))
269 .ToChecked();
270 }
228 } 271 }
229 272
230 void IsolateData::FireContextCreated(v8::Local<v8::Context> context, 273 void IsolateData::FireContextCreated(v8::Local<v8::Context> context,
231 int context_group_id) { 274 int context_group_id) {
232 v8_inspector::V8ContextInfo info(context, context_group_id, 275 v8_inspector::V8ContextInfo info(context, context_group_id,
233 v8_inspector::StringView()); 276 v8_inspector::StringView());
234 info.hasMemoryOnConsole = true; 277 info.hasMemoryOnConsole = true;
235 inspector_->contextCreated(info); 278 inspector_->contextCreated(info);
236 } 279 }
237 280
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 unsigned lineNumber, unsigned columnNumber, 346 unsigned lineNumber, unsigned columnNumber,
304 v8_inspector::V8StackTrace* stack) { 347 v8_inspector::V8StackTrace* stack) {
305 if (!log_console_api_message_calls_) return; 348 if (!log_console_api_message_calls_) return;
306 Print(isolate_, message); 349 Print(isolate_, message);
307 fprintf(stdout, " ("); 350 fprintf(stdout, " (");
308 Print(isolate_, url); 351 Print(isolate_, url);
309 fprintf(stdout, ":%d:%d)", lineNumber, columnNumber); 352 fprintf(stdout, ":%d:%d)", lineNumber, columnNumber);
310 Print(isolate_, stack->toString()->string()); 353 Print(isolate_, stack->toString()->string());
311 fprintf(stdout, "\n"); 354 fprintf(stdout, "\n");
312 } 355 }
OLDNEW
« no previous file with comments | « test/inspector/isolate-data.h ('k') | test/inspector/sessions/create-session.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698