File: ThreadDebugger.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (115 lines) | stat: -rw-r--r-- 4,488 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ThreadDebugger_h
#define ThreadDebugger_h

#include "core/CoreExport.h"
#include "core/inspector/ConsoleTypes.h"
#include "platform/Timer.h"
#include "platform/UserGestureIndicator.h"
#include "wtf/Forward.h"
#include "wtf/Vector.h"
#include <memory>
#include <v8-inspector.h>
#include <v8-profiler.h>
#include <v8.h>

namespace blink {

class ExecutionContext;
class SourceLocation;

// TODO(dgozman): rename this to ThreadInspector (and subclasses).
class CORE_EXPORT ThreadDebugger : public v8_inspector::V8InspectorClient {
  WTF_MAKE_NONCOPYABLE(ThreadDebugger);

 public:
  explicit ThreadDebugger(v8::Isolate*);
  ~ThreadDebugger() override;

  static ThreadDebugger* from(v8::Isolate*);
  virtual bool isWorker() = 0;
  v8_inspector::V8Inspector* v8Inspector() const { return m_v8Inspector.get(); }

  static void willExecuteScript(v8::Isolate*, int scriptId);
  static void didExecuteScript(v8::Isolate*);
  static void idleStarted(v8::Isolate*);
  static void idleFinished(v8::Isolate*);

  void asyncTaskScheduled(const String& taskName, void* task, bool recurring);
  void asyncTaskCanceled(void* task);
  void allAsyncTasksCanceled();
  void asyncTaskStarted(void* task);
  void asyncTaskFinished(void* task);
  unsigned promiseRejected(v8::Local<v8::Context>,
                           const String& errorMessage,
                           v8::Local<v8::Value> exception,
                           std::unique_ptr<SourceLocation>);
  void promiseRejectionRevoked(v8::Local<v8::Context>,
                               unsigned promiseRejectionId);

 protected:
  virtual int contextGroupId(ExecutionContext*) = 0;
  virtual void reportConsoleMessage(ExecutionContext*,
                                    MessageSource,
                                    MessageLevel,
                                    const String& message,
                                    SourceLocation*) = 0;
  void installAdditionalCommandLineAPI(v8::Local<v8::Context>,
                                       v8::Local<v8::Object>) override;
  void createFunctionProperty(v8::Local<v8::Context>,
                              v8::Local<v8::Object>,
                              const char* name,
                              v8::FunctionCallback,
                              const char* description);
  static v8::Maybe<bool> createDataPropertyInArray(v8::Local<v8::Context>,
                                                   v8::Local<v8::Array>,
                                                   int index,
                                                   v8::Local<v8::Value>);
  static MessageLevel consoleAPITypeToMessageLevel(
      v8_inspector::V8ConsoleAPIType);

  v8::Isolate* m_isolate;

 private:
  // V8InspectorClient implementation.
  void beginUserGesture() override;
  void endUserGesture() override;
  std::unique_ptr<v8_inspector::StringBuffer> valueSubtype(
      v8::Local<v8::Value>) override;
  bool formatAccessorsAsProperties(v8::Local<v8::Value>) override;
  double currentTimeMS() override;
  bool isInspectableHeapObject(v8::Local<v8::Object>) override;
  void consoleTime(const v8_inspector::StringView& title) override;
  void consoleTimeEnd(const v8_inspector::StringView& title) override;
  void consoleTimeStamp(const v8_inspector::StringView& title) override;
  void startRepeatingTimer(double,
                           v8_inspector::V8InspectorClient::TimerCallback,
                           void* data) override;
  void cancelTimer(void* data) override;

  void onTimer(TimerBase*);

  static void setMonitorEventsCallback(
      const v8::FunctionCallbackInfo<v8::Value>&,
      bool enabled);
  static void monitorEventsCallback(const v8::FunctionCallbackInfo<v8::Value>&);
  static void unmonitorEventsCallback(
      const v8::FunctionCallbackInfo<v8::Value>&);

  static void getEventListenersCallback(
      const v8::FunctionCallbackInfo<v8::Value>&);

  std::unique_ptr<v8_inspector::V8Inspector> m_v8Inspector;
  std::unique_ptr<v8::TracingCpuProfiler> m_v8TracingCpuProfiler;
  Vector<std::unique_ptr<Timer<ThreadDebugger>>> m_timers;
  Vector<v8_inspector::V8InspectorClient::TimerCallback> m_timerCallbacks;
  Vector<void*> m_timerData;
  std::unique_ptr<UserGestureIndicator> m_userGestureIndicator;
};

}  // namespace blink

#endif  // ThreadDebugger_h