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

Unified Diff: test/inspector-protocol/set-timeout-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/set-timeout-extension.cc
diff --git a/test/inspector-protocol/set-timeout-extension.cc b/test/inspector-protocol/set-timeout-extension.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2f631667dd440a1b9e6fc69f3133873fbb7e4563
--- /dev/null
+++ b/test/inspector-protocol/set-timeout-extension.cc
@@ -0,0 +1,59 @@
+// 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/set-timeout-extension.h"
+
+#include "include/v8-inspector.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 {
+
+namespace {
+
+class SetTimeoutTask : public v8_inspector::Task {
+ public:
+ SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function)
+ : function_(isolate, function) {}
+ virtual ~SetTimeoutTask() {}
+
+ bool is_protocol_task() final { return false; }
+
+ 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();
+ v8::Local<v8::Function> function = function_.Get(isolate);
+ v8::MaybeLocal<v8::Value> result;
+ V8Inspector* inspector =
+ V8InspectorClientImpl::InspectorFromContext(context);
+ if (inspector) inspector->willExecuteScript(context, function->ScriptId());
+ result = function->Call(context, context->Global(), 0, NULL);
+ if (inspector) inspector->didExecuteScript(context);
+ }
+
+ private:
+ v8::Global<v8::Function> function_;
+};
+
+} // namespace
+
+v8::Local<v8::FunctionTemplate> SetTimeoutExtension::GetNativeFunctionTemplate(
+ v8::Isolate* isolate, v8::Local<v8::String> str) {
+ return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout);
+}
+
+void SetTimeoutExtension::SetTimeout(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ CHECK(args.Length() == 2 && args[1]->IsNumber() && args[0]->IsFunction());
+ double delay = args[1].As<v8::Number>()->Value();
+ // setTimeout supports only zero delay.
+ CHECK(delay == 0.0);
+ v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
+ v8_inspector::TaskQueue::FromContext(context)->Append(new SetTimeoutTask(
+ args.GetIsolate(), v8::Local<v8::Function>::Cast(args[0])));
+}
+
+} // namespace v8_inspector

Powered by Google App Engine
This is Rietveld 408576698