Index: test/inspector/inspector-impl.cc |
diff --git a/test/inspector/inspector-impl.cc b/test/inspector/inspector-impl.cc |
index 956227695393d4c3abf59c822f799c21b5053f40..57499215b9565040bd024dee82af8287feda2577 100644 |
--- a/test/inspector/inspector-impl.cc |
+++ b/test/inspector/inspector-impl.cc |
@@ -40,6 +40,47 @@ InspectorClientImpl* InspectorClientFromContext( |
return inspector_client; |
} |
+v8_inspector::String16 ToString16(v8::Local<v8::String> str) { |
+ std::unique_ptr<uint16_t[]> buffer(new uint16_t[str->Length()]); |
+ str->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, str->Length()); |
+ return v8_inspector::String16(buffer.get(), str->Length()); |
+} |
+ |
+void MessageHandler(v8::Local<v8::Message> message, |
+ v8::Local<v8::Value> exception) { |
+ v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ v8::Local<v8::Context> context = isolate->GetEnteredContext(); |
+ if (context.IsEmpty()) return; |
+ v8_inspector::V8Inspector* inspector = |
+ InspectorClientImpl::InspectorFromContext(context); |
+ |
+ v8::Local<v8::StackTrace> stack = message->GetStackTrace(); |
+ int script_id = message->GetScriptOrigin().ScriptID()->Value(); |
+ if (!stack.IsEmpty() && stack->GetFrameCount() > 0) { |
+ int top_script_id = stack->GetFrame(0)->GetScriptId(); |
+ if (top_script_id == script_id) script_id = 0; |
+ } |
+ int line_number = message->GetLineNumber(context).FromMaybe(0); |
+ int column_number = 0; |
+ if (message->GetStartColumn(context).IsJust()) |
+ column_number = message->GetStartColumn(context).FromJust() + 1; |
+ |
+ v8_inspector::StringView detailed_message; |
+ v8_inspector::String16 message_text_string = ToString16(message->Get()); |
+ v8_inspector::StringView message_text(message_text_string.characters16(), |
+ message_text_string.length()); |
+ v8_inspector::String16 url_string; |
+ if (message->GetScriptOrigin().ResourceName()->IsString()) { |
+ url_string = |
+ ToString16(message->GetScriptOrigin().ResourceName().As<v8::String>()); |
+ } |
+ v8_inspector::StringView url(url_string.characters16(), url_string.length()); |
+ |
+ inspector->exceptionThrown(context, message_text, exception, detailed_message, |
+ url, line_number, column_number, |
+ inspector->createStackTrace(stack), script_id); |
+} |
+ |
} // namespace |
class ConnectTask : public TaskRunner::Task { |
@@ -76,6 +117,7 @@ InspectorClientImpl::~InspectorClientImpl() {} |
void InspectorClientImpl::connect(v8::Local<v8::Context> context) { |
isolate_ = context->GetIsolate(); |
+ isolate_->AddMessageListener(MessageHandler); |
channel_.reset(new ChannelImpl(frontend_channel_)); |
inspector_ = v8_inspector::V8Inspector::create(isolate_, this); |
@@ -154,9 +196,6 @@ void SendMessageToBackendExtension::SendMessageToBackend( |
CHECK(backend_task_runner_); |
CHECK(args.Length() == 1 && args[0]->IsString()); |
v8::Local<v8::String> message = args[0].As<v8::String>(); |
- std::unique_ptr<uint16_t[]> buffer(new uint16_t[message->Length()]); |
- message.As<v8::String>()->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, |
- message->Length()); |
- v8_inspector::String16 message_string(buffer.get(), message->Length()); |
- backend_task_runner_->Append(new SendMessageToBackendTask(message_string)); |
+ backend_task_runner_->Append( |
+ new SendMessageToBackendTask(ToString16(message))); |
} |