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

Unified Diff: test/inspector-protocol/inspector-extension.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-extension.cc
diff --git a/test/inspector-protocol/inspector-extension.cc b/test/inspector-protocol/inspector-extension.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9db04cb723e001183feea161bdd3ffcf4c74af6b
--- /dev/null
+++ b/test/inspector-protocol/inspector-extension.cc
@@ -0,0 +1,70 @@
+// 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-extension.h"
+
+#include "src/inspector/string-util.h"
+#include "test/inspector-protocol/inspector-client-impl.h"
+#include "test/inspector-protocol/task-queue.h"
+#include "test/inspector-protocol/task.h"
+
+namespace v8_inspector {
+
+TaskQueue* BackendExtension::frontend_queue_ = NULL;
+
+v8::Local<v8::FunctionTemplate> BackendExtension::GetNativeFunctionTemplate(
+ v8::Isolate* isolate, v8::Local<v8::String> name) {
+ return v8::FunctionTemplate::New(isolate,
+ BackendExtension::EvaluateInFrontend);
+}
+
+void BackendExtension::EvaluateInFrontend(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ CHECK(frontend_queue_);
+ CHECK(args.Length() == 1 && args[0]->IsString());
+ frontend_queue_->Append(new ExecuteStringTask(
+ toStringView(toProtocolString(v8::Local<v8::String>::Cast(args[0])))));
+}
+
+namespace {
+
+class ProcessMessageOnBackend : public v8_inspector::Task {
+ public:
+ ProcessMessageOnBackend(const StringView& message)
+ : message_(toString16(message)) {}
+
+ bool is_protocol_task() final { return true; }
+
+ void Run(v8::Isolate* isolate,
+ const v8::Global<v8::Context>& global_context) override {
+ v8_inspector::TaskScope task_scope(isolate, global_context);
+ v8::Local<v8::Context> context = task_scope.context();
+ V8InspectorSession* session =
+ V8InspectorClientImpl::SessionFromContext(context);
+ session->dispatchProtocolMessage(toStringView(message_));
+ }
+
+ private:
+ String16 message_;
+};
+
+} // namespace
+
+TaskQueue* FrontendExtension::backend_queue_ = NULL;
+
+v8::Local<v8::FunctionTemplate> FrontendExtension::GetNativeFunctionTemplate(
+ v8::Isolate* isolate, v8::Local<v8::String> name) {
+ return v8::FunctionTemplate::New(isolate,
+ FrontendExtension::SendMessageToBackend);
+}
+
+void FrontendExtension::SendMessageToBackend(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ CHECK(backend_queue_);
+ CHECK(args.Length() == 1 && args[0]->IsString());
+ backend_queue_->Append(new ProcessMessageOnBackend(
+ toStringView(toProtocolString(v8::Local<v8::String>::Cast(args[0])))));
+}
+
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698