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

Side by Side Diff: test/inspector/inspector-impl.cc

Issue 2384373002: [inspector] introduced exceptionThrown support in test runner (Closed)
Patch Set: addressed comments Created 4 years, 2 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 | « no previous file | test/inspector/inspector-test.cc » ('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 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 22 matching lines...) Expand all
33 }; 33 };
34 34
35 InspectorClientImpl* InspectorClientFromContext( 35 InspectorClientImpl* InspectorClientFromContext(
36 v8::Local<v8::Context> context) { 36 v8::Local<v8::Context> context) {
37 InspectorClientImpl* inspector_client = static_cast<InspectorClientImpl*>( 37 InspectorClientImpl* inspector_client = static_cast<InspectorClientImpl*>(
38 context->GetAlignedPointerFromEmbedderData(kInspectorClientIndex)); 38 context->GetAlignedPointerFromEmbedderData(kInspectorClientIndex));
39 CHECK(inspector_client); 39 CHECK(inspector_client);
40 return inspector_client; 40 return inspector_client;
41 } 41 }
42 42
43 v8_inspector::String16 ToString16(v8::Local<v8::String> str) {
44 std::unique_ptr<uint16_t[]> buffer(new uint16_t[str->Length()]);
45 str->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, str->Length());
46 return v8_inspector::String16(buffer.get(), str->Length());
47 }
48
49 void MessageHandler(v8::Local<v8::Message> message,
50 v8::Local<v8::Value> exception) {
51 v8::Isolate* isolate = v8::Isolate::GetCurrent();
52 v8::Local<v8::Context> context = isolate->GetEnteredContext();
53 if (context.IsEmpty()) return;
54 v8_inspector::V8Inspector* inspector =
55 InspectorClientImpl::InspectorFromContext(context);
56
57 v8::Local<v8::StackTrace> stack = message->GetStackTrace();
58 int script_id = message->GetScriptOrigin().ScriptID()->Value();
59 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) {
60 int top_script_id = stack->GetFrame(0)->GetScriptId();
61 if (top_script_id == script_id) script_id = 0;
62 }
63 int line_number = message->GetLineNumber(context).FromMaybe(0);
64 int column_number = 0;
65 if (message->GetStartColumn(context).IsJust())
66 column_number = message->GetStartColumn(context).FromJust() + 1;
67
68 v8_inspector::StringView detailed_message;
69 v8_inspector::String16 message_text_string = ToString16(message->Get());
70 v8_inspector::StringView message_text(message_text_string.characters16(),
71 message_text_string.length());
72 v8_inspector::String16 url_string;
73 if (message->GetScriptOrigin().ResourceName()->IsString()) {
74 url_string =
75 ToString16(message->GetScriptOrigin().ResourceName().As<v8::String>());
76 }
77 v8_inspector::StringView url(url_string.characters16(), url_string.length());
78
79 inspector->exceptionThrown(context, message_text, exception, detailed_message,
80 url, line_number, column_number,
81 inspector->createStackTrace(stack), script_id);
82 }
83
43 } // namespace 84 } // namespace
44 85
45 class ConnectTask : public TaskRunner::Task { 86 class ConnectTask : public TaskRunner::Task {
46 public: 87 public:
47 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore) 88 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore)
48 : client_(client), ready_semaphore_(ready_semaphore) {} 89 : client_(client), ready_semaphore_(ready_semaphore) {}
49 virtual ~ConnectTask() = default; 90 virtual ~ConnectTask() = default;
50 91
51 bool is_inspector_task() final { return true; } 92 bool is_inspector_task() final { return true; }
52 93
(...skipping 16 matching lines...) Expand all
69 : isolate_(nullptr), 110 : isolate_(nullptr),
70 task_runner_(task_runner), 111 task_runner_(task_runner),
71 frontend_channel_(frontend_channel) { 112 frontend_channel_(frontend_channel) {
72 task_runner_->Append(new ConnectTask(this, ready_semaphore)); 113 task_runner_->Append(new ConnectTask(this, ready_semaphore));
73 } 114 }
74 115
75 InspectorClientImpl::~InspectorClientImpl() {} 116 InspectorClientImpl::~InspectorClientImpl() {}
76 117
77 void InspectorClientImpl::connect(v8::Local<v8::Context> context) { 118 void InspectorClientImpl::connect(v8::Local<v8::Context> context) {
78 isolate_ = context->GetIsolate(); 119 isolate_ = context->GetIsolate();
120 isolate_->AddMessageListener(MessageHandler);
79 channel_.reset(new ChannelImpl(frontend_channel_)); 121 channel_.reset(new ChannelImpl(frontend_channel_));
80 122
81 inspector_ = v8_inspector::V8Inspector::create(isolate_, this); 123 inspector_ = v8_inspector::V8Inspector::create(isolate_, this);
82 session_ = inspector_->connect(1, channel_.get(), v8_inspector::StringView()); 124 session_ = inspector_->connect(1, channel_.get(), v8_inspector::StringView());
83 125
84 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this); 126 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this);
85 inspector_->contextCreated( 127 inspector_->contextCreated(
86 v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); 128 v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView()));
87 context_.Reset(isolate_, context); 129 context_.Reset(isolate_, context);
88 } 130 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 v8::Isolate* isolate, v8::Local<v8::String> name) { 189 v8::Isolate* isolate, v8::Local<v8::String> name) {
148 return v8::FunctionTemplate::New( 190 return v8::FunctionTemplate::New(
149 isolate, SendMessageToBackendExtension::SendMessageToBackend); 191 isolate, SendMessageToBackendExtension::SendMessageToBackend);
150 } 192 }
151 193
152 void SendMessageToBackendExtension::SendMessageToBackend( 194 void SendMessageToBackendExtension::SendMessageToBackend(
153 const v8::FunctionCallbackInfo<v8::Value>& args) { 195 const v8::FunctionCallbackInfo<v8::Value>& args) {
154 CHECK(backend_task_runner_); 196 CHECK(backend_task_runner_);
155 CHECK(args.Length() == 1 && args[0]->IsString()); 197 CHECK(args.Length() == 1 && args[0]->IsString());
156 v8::Local<v8::String> message = args[0].As<v8::String>(); 198 v8::Local<v8::String> message = args[0].As<v8::String>();
157 std::unique_ptr<uint16_t[]> buffer(new uint16_t[message->Length()]); 199 backend_task_runner_->Append(
158 message.As<v8::String>()->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, 200 new SendMessageToBackendTask(ToString16(message)));
159 message->Length());
160 v8_inspector::String16 message_string(buffer.get(), message->Length());
161 backend_task_runner_->Append(new SendMessageToBackendTask(message_string));
162 } 201 }
OLDNEW
« no previous file with comments | « no previous file | test/inspector/inspector-test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698