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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/inspector/inspector-test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)));
}
« 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