Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 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()); | |
|
dgozman
2016/10/04 18:26:04
I remember you wanted String16::createUninitialize
kozy
2016/10/04 20:34:58
I'll add it in followup.
| |
| 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()) | |
|
dgozman
2016/10/04 18:26:04
missing {}
kozy
2016/10/04 20:34:58
Done.
| |
| 74 url_string = | |
| 75 ToString16(message->GetScriptOrigin().ResourceName().As<v8::String>()); | |
| 76 v8_inspector::StringView url(url_string.characters16(), url_string.length()); | |
| 77 | |
| 78 inspector->exceptionThrown(context, message_text, exception, detailed_message, | |
| 79 url, line_number, column_number, | |
| 80 inspector->createStackTrace(stack), script_id); | |
| 81 } | |
| 82 | |
| 43 } // namespace | 83 } // namespace |
| 44 | 84 |
| 45 class ConnectTask : public TaskRunner::Task { | 85 class ConnectTask : public TaskRunner::Task { |
| 46 public: | 86 public: |
| 47 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore) | 87 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore) |
| 48 : client_(client), ready_semaphore_(ready_semaphore) {} | 88 : client_(client), ready_semaphore_(ready_semaphore) {} |
| 49 virtual ~ConnectTask() = default; | 89 virtual ~ConnectTask() = default; |
| 50 | 90 |
| 51 bool is_inspector_task() final { return true; } | 91 bool is_inspector_task() final { return true; } |
| 52 | 92 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 69 : isolate_(nullptr), | 109 : isolate_(nullptr), |
| 70 task_runner_(task_runner), | 110 task_runner_(task_runner), |
| 71 frontend_channel_(frontend_channel) { | 111 frontend_channel_(frontend_channel) { |
| 72 task_runner_->Append(new ConnectTask(this, ready_semaphore)); | 112 task_runner_->Append(new ConnectTask(this, ready_semaphore)); |
| 73 } | 113 } |
| 74 | 114 |
| 75 InspectorClientImpl::~InspectorClientImpl() {} | 115 InspectorClientImpl::~InspectorClientImpl() {} |
| 76 | 116 |
| 77 void InspectorClientImpl::connect(v8::Local<v8::Context> context) { | 117 void InspectorClientImpl::connect(v8::Local<v8::Context> context) { |
| 78 isolate_ = context->GetIsolate(); | 118 isolate_ = context->GetIsolate(); |
| 119 isolate_->AddMessageListener(MessageHandler); | |
| 79 channel_.reset(new ChannelImpl(frontend_channel_)); | 120 channel_.reset(new ChannelImpl(frontend_channel_)); |
| 80 | 121 |
| 81 inspector_ = v8_inspector::V8Inspector::create(isolate_, this); | 122 inspector_ = v8_inspector::V8Inspector::create(isolate_, this); |
| 82 session_ = inspector_->connect(1, channel_.get(), v8_inspector::StringView()); | 123 session_ = inspector_->connect(1, channel_.get(), v8_inspector::StringView()); |
| 83 | 124 |
| 84 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this); | 125 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this); |
| 85 inspector_->contextCreated( | 126 inspector_->contextCreated( |
| 86 v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); | 127 v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); |
| 87 context_.Reset(isolate_, context); | 128 context_.Reset(isolate_, context); |
| 88 } | 129 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 v8::Isolate* isolate, v8::Local<v8::String> name) { | 188 v8::Isolate* isolate, v8::Local<v8::String> name) { |
| 148 return v8::FunctionTemplate::New( | 189 return v8::FunctionTemplate::New( |
| 149 isolate, SendMessageToBackendExtension::SendMessageToBackend); | 190 isolate, SendMessageToBackendExtension::SendMessageToBackend); |
| 150 } | 191 } |
| 151 | 192 |
| 152 void SendMessageToBackendExtension::SendMessageToBackend( | 193 void SendMessageToBackendExtension::SendMessageToBackend( |
| 153 const v8::FunctionCallbackInfo<v8::Value>& args) { | 194 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 154 CHECK(backend_task_runner_); | 195 CHECK(backend_task_runner_); |
| 155 CHECK(args.Length() == 1 && args[0]->IsString()); | 196 CHECK(args.Length() == 1 && args[0]->IsString()); |
| 156 v8::Local<v8::String> message = args[0].As<v8::String>(); | 197 v8::Local<v8::String> message = args[0].As<v8::String>(); |
| 157 std::unique_ptr<uint16_t[]> buffer(new uint16_t[message->Length()]); | 198 backend_task_runner_->Append( |
| 158 message.As<v8::String>()->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, | 199 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 } | 200 } |
| OLD | NEW |