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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "test/inspector-protocol/set-timeout-extension.h"
6
7 #include "include/v8-inspector.h"
8 #include "test/inspector-protocol/inspector-client-impl.h"
9 #include "test/inspector-protocol/task-queue.h"
10 #include "test/inspector-protocol/task.h"
11
12 namespace v8_inspector {
13
14 namespace {
15
16 class SetTimeoutTask : public v8_inspector::Task {
17 public:
18 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function)
19 : function_(isolate, function) {}
20 virtual ~SetTimeoutTask() {}
21
22 bool is_protocol_task() final { return false; }
23
24 void Run(v8::Isolate* isolate,
25 const v8::Global<v8::Context>& global_context) override {
26 v8_inspector::TaskScope task_scope(isolate, global_context);
27 v8::Local<v8::Context> context = task_scope.context();
28 v8::Local<v8::Function> function = function_.Get(isolate);
29 v8::MaybeLocal<v8::Value> result;
30 V8Inspector* inspector =
31 V8InspectorClientImpl::InspectorFromContext(context);
32 if (inspector) inspector->willExecuteScript(context, function->ScriptId());
33 result = function->Call(context, context->Global(), 0, NULL);
34 if (inspector) inspector->didExecuteScript(context);
35 }
36
37 private:
38 v8::Global<v8::Function> function_;
39 };
40
41 } // namespace
42
43 v8::Local<v8::FunctionTemplate> SetTimeoutExtension::GetNativeFunctionTemplate(
44 v8::Isolate* isolate, v8::Local<v8::String> str) {
45 return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout);
46 }
47
48 void SetTimeoutExtension::SetTimeout(
49 const v8::FunctionCallbackInfo<v8::Value>& args) {
50 CHECK(args.Length() == 2 && args[1]->IsNumber() && args[0]->IsFunction());
51 double delay = args[1].As<v8::Number>()->Value();
52 // setTimeout supports only zero delay.
53 CHECK(delay == 0.0);
54 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
55 v8_inspector::TaskQueue::FromContext(context)->Append(new SetTimeoutTask(
56 args.GetIsolate(), v8::Local<v8::Function>::Cast(args[0])));
57 }
58
59 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698