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

Unified Diff: test/inspector-protocol/task.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/task.cc
diff --git a/test/inspector-protocol/task.cc b/test/inspector-protocol/task.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1169014a7b566077b440f8d60ff9aa15780ec87d
--- /dev/null
+++ b/test/inspector-protocol/task.cc
@@ -0,0 +1,76 @@
+// 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/task.h"
+
+#include "src/base/platform/platform.h"
+#include "src/inspector/string-util.h"
+#include "test/inspector-protocol/task-queue.h"
+#include "test/inspector-protocol/task-runner.h"
+
+namespace v8_inspector {
+
+TaskScope::TaskScope(v8::Isolate* isolate,
+ const v8::Global<v8::Context>& context)
+ : isolate_(isolate),
+ isolate_scope_(isolate),
+ handle_scope_(isolate),
+ context_(context.Get(isolate)),
+ context_scope_(context_),
+ microtasks_scope_(isolate_, v8::MicrotasksScope::kRunMicrotasks),
+ try_catch_(isolate_) {}
+
+TaskScope::~TaskScope() {
+ if (try_catch_.HasCaught()) {
+ v8_inspector::String16 message =
+ v8_inspector::toProtocolString(try_catch_.Message()->Get());
+ fprintf(stderr, "Unhandle exception: %s\n", message.utf8().data());
+ fflush(stdout);
+ fflush(stderr);
+ _exit(0);
+ }
+}
+
+ExecuteStringTask::ExecuteStringTask(const StringView& expression)
+ : expression_(toString16(expression)) {}
+
+void ExecuteStringTask::Run(v8::Isolate* isolate,
+ const v8::Global<v8::Context>& global_context) {
+ TaskScope task_scope(isolate, global_context);
+ v8::Local<v8::Context> context = task_scope.context();
+ v8::ScriptOrigin origin(v8::String::Empty(isolate));
+ v8::ScriptCompiler::Source scriptSource(toV8String(isolate, expression_),
+ origin);
+ v8::Local<v8::Script> script;
+ if (!v8::ScriptCompiler::Compile(context, &scriptSource).ToLocal(&script))
+ return;
+ v8::MaybeLocal<v8::Value> result;
+ result = script->Run(context);
+}
+
+InitTask::InitTask(v8::ExtensionConfiguration* extensions,
+ v8_inspector::TaskRunner* task_runner,
+ v8::base::Semaphore* ready)
+ : extensions_(extensions), task_runner_(task_runner), ready_(ready) {}
+
+void InitTask::Run() {
+ v8::Isolate::CreateParams params;
+ params.array_buffer_allocator =
+ v8::ArrayBuffer::Allocator::NewDefaultAllocator();
+ v8::Isolate* isolate = v8::Isolate::New(params);
+ isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
+ v8::Isolate::Scope isolate_scope(isolate);
+ v8::HandleScope handle_scope(isolate);
+
+ v8::Local<v8::ObjectTemplate> global_template =
+ v8::ObjectTemplate::New(isolate);
+ v8::Local<v8::Context> context =
+ v8::Context::New(isolate, extensions_, global_template);
+ task_runner_->Queue()->SetContext(context);
+ task_runner_->SetContext(context);
+
+ if (ready_) ready_->Signal();
+}
+
+} // v8_inspector

Powered by Google App Engine
This is Rietveld 408576698