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

Unified Diff: test/inspector-protocol/inspector-client-impl.cc

Issue 2358943002: [inspector] added inspector protocol test runner (Closed)
Patch Set: a Created 4 years, 3 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
Index: test/inspector-protocol/inspector-client-impl.cc
diff --git a/test/inspector-protocol/inspector-client-impl.cc b/test/inspector-protocol/inspector-client-impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7a0d52857cfb770e9aec31e58fb0ebd185484e66
--- /dev/null
+++ b/test/inspector-protocol/inspector-client-impl.cc
@@ -0,0 +1,90 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "test/inspector-protocol/inspector-client-impl.h"
+
+#include "src/base/platform/platform.h"
+#include "src/inspector/string-util.h"
+#include "test/inspector-protocol/channel-impl.h"
+#include "test/inspector-protocol/task-queue.h"
+#include "test/inspector-protocol/task.h"
+
+namespace v8_inspector {
+
+namespace {
+
+const int kInspectorClientIndex = v8::Context::kDebugIdIndex + 1;
+
+V8InspectorClientImpl* FromContext(v8::Local<v8::Context> context) {
+ V8InspectorClientImpl* inspector_client = static_cast<V8InspectorClientImpl*>(
+ context->GetAlignedPointerFromEmbedderData(kInspectorClientIndex));
+ CHECK(inspector_client);
+ return inspector_client;
+}
+}
+
+V8InspectorClientImpl::V8InspectorClientImpl()
+ : isolate_(nullptr), running_message_loop_(false) {}
+
+V8InspectorClientImpl::~V8InspectorClientImpl() {}
+
+void V8InspectorClientImpl::connect(ChannelImpl* channel,
+ v8::Local<v8::Context> context) {
+ isolate_ = context->GetIsolate();
+
+ inspector_ = V8Inspector::create(isolate_, this);
+ session_ = inspector_->connect(1, channel, StringView());
+
+ context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this);
+
+ String16 name("Inspector Test");
+ inspector_->contextCreated(V8ContextInfo(context, 1, toStringView(name)));
+ context_.Reset(isolate_, context);
+}
+
+v8::Local<v8::Context> V8InspectorClientImpl::ensureDefaultContextInGroup(int) {
+ CHECK(isolate_);
+ return context_.Get(isolate_);
+}
+
+double V8InspectorClientImpl::currentTimeMS() {
+ return v8::base::OS::TimeCurrentMillis();
+}
+
+void V8InspectorClientImpl::runMessageLoopOnPause(int) {
+ running_message_loop_ = true;
+ TaskQueue* queue = TaskQueue::FromContext(context_.Get(isolate_));
+ while (Task* task = queue->GetNext(true)) {
+ task->Run(isolate_, context_);
+ delete task;
+ if (!running_message_loop_) break;
+ }
+}
+
+void V8InspectorClientImpl::quitMessageLoopOnPause() {
+ running_message_loop_ = false;
+}
+
+V8Inspector* V8InspectorClientImpl::InspectorFromContext(
+ v8::Local<v8::Context> context) {
+ return FromContext(context)->inspector_.get();
+}
+
+V8InspectorSession* V8InspectorClientImpl::SessionFromContext(
+ v8::Local<v8::Context> context) {
+ return FromContext(context)->session_.get();
+}
+
+ConnectTask::ConnectTask(V8InspectorClientImpl* client, ChannelImpl* channel,
+ v8::base::Semaphore* ready)
+ : client_(client), channel_(channel), ready_(ready) {}
+
+void ConnectTask::Run(v8::Isolate* isolate,
+ const v8::Global<v8::Context>& context) {
+ TaskScope scope(isolate, context);
+ client_->connect(channel_, scope.context());
+ ready_->Signal();
+}
+
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698