OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_ | 5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_ |
6 #define V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_ | 6 #define V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "include/v8-inspector.h" | 10 #include "include/v8-inspector.h" |
11 #include "include/v8-platform.h" | 11 #include "include/v8-platform.h" |
12 #include "include/v8.h" | 12 #include "include/v8.h" |
13 #include "src/base/macros.h" | 13 #include "src/base/macros.h" |
14 #include "src/base/platform/platform.h" | 14 #include "src/base/platform/platform.h" |
15 #include "src/vector.h" | 15 #include "src/vector.h" |
16 | 16 |
17 class TaskRunner; | 17 class TaskRunner; |
18 | 18 |
19 class IsolateData : public v8_inspector::V8InspectorClient { | 19 class IsolateData : public v8_inspector::V8InspectorClient { |
20 public: | 20 public: |
21 class SetupGlobalTask { | 21 class SetupGlobalTask { |
22 public: | 22 public: |
23 virtual ~SetupGlobalTask() = default; | 23 virtual ~SetupGlobalTask() = default; |
24 virtual void Run(v8::Isolate* isolate, | 24 virtual void Run(v8::Isolate* isolate, |
25 v8::Local<v8::ObjectTemplate> global) = 0; | 25 v8::Local<v8::ObjectTemplate> global) = 0; |
26 }; | 26 }; |
27 using SetupGlobalTasks = std::vector<std::unique_ptr<SetupGlobalTask>>; | 27 using SetupGlobalTasks = std::vector<std::unique_ptr<SetupGlobalTask>>; |
28 | 28 |
29 class FrontendChannel { | |
30 public: | |
31 virtual ~FrontendChannel() = default; | |
32 virtual void SendMessageToFrontend( | |
33 int session_id, const v8_inspector::StringView& message) = 0; | |
34 }; | |
35 | |
36 IsolateData(TaskRunner* task_runner, SetupGlobalTasks setup_global_tasks, | 29 IsolateData(TaskRunner* task_runner, SetupGlobalTasks setup_global_tasks, |
37 v8::StartupData* startup_data, FrontendChannel* channel); | 30 v8::StartupData* startup_data, bool with_inspector); |
38 static IsolateData* FromContext(v8::Local<v8::Context> context); | 31 static IsolateData* FromContext(v8::Local<v8::Context> context); |
39 | 32 |
40 v8::Isolate* isolate() const { return isolate_; } | 33 v8::Isolate* isolate() const { return isolate_; } |
41 v8_inspector::V8Inspector* inspector() const { return inspector_.get(); } | |
42 TaskRunner* task_runner() const { return task_runner_; } | 34 TaskRunner* task_runner() const { return task_runner_; } |
43 | 35 |
44 // Setting things up. | 36 // Setting things up. |
45 int CreateContextGroup(); | 37 int CreateContextGroup(); |
46 v8::Local<v8::Context> GetContext(int context_group_id); | 38 v8::Local<v8::Context> GetContext(int context_group_id); |
47 int GetContextGroupId(v8::Local<v8::Context> context); | 39 int GetContextGroupId(v8::Local<v8::Context> context); |
48 void RegisterModule(v8::Local<v8::Context> context, | 40 void RegisterModule(v8::Local<v8::Context> context, |
49 v8::internal::Vector<uint16_t> name, | 41 v8::internal::Vector<uint16_t> name, |
50 v8::ScriptCompiler::Source* source); | 42 v8::ScriptCompiler::Source* source); |
51 | 43 |
52 // Working with V8Inspector api. | 44 // Working with V8Inspector api. |
53 int ConnectSession(int context_group_id, | 45 int ConnectSession(int context_group_id, |
54 const v8_inspector::StringView& state); | 46 const v8_inspector::StringView& state, |
| 47 v8_inspector::V8Inspector::Channel* channel); |
55 std::unique_ptr<v8_inspector::StringBuffer> DisconnectSession(int session_id); | 48 std::unique_ptr<v8_inspector::StringBuffer> DisconnectSession(int session_id); |
56 void SendMessage(int session_id, const v8_inspector::StringView& message); | 49 void SendMessage(int session_id, const v8_inspector::StringView& message); |
57 void BreakProgram(int context_group_id, | 50 void BreakProgram(int context_group_id, |
58 const v8_inspector::StringView& reason, | 51 const v8_inspector::StringView& reason, |
59 const v8_inspector::StringView& details); | 52 const v8_inspector::StringView& details); |
60 void SchedulePauseOnNextStatement(int context_group_id, | 53 void SchedulePauseOnNextStatement(int context_group_id, |
61 const v8_inspector::StringView& reason, | 54 const v8_inspector::StringView& reason, |
62 const v8_inspector::StringView& details); | 55 const v8_inspector::StringView& details); |
63 void CancelPauseOnNextStatement(int context_group_id); | 56 void CancelPauseOnNextStatement(int context_group_id); |
| 57 void AsyncTaskScheduled(const v8_inspector::StringView& name, void* task, |
| 58 bool recurring); |
| 59 void AsyncTaskStarted(void* task); |
| 60 void AsyncTaskFinished(void* task); |
64 | 61 |
65 // Test utilities. | 62 // Test utilities. |
66 void SetCurrentTimeMS(double time); | 63 void SetCurrentTimeMS(double time); |
67 void SetMemoryInfo(v8::Local<v8::Value> memory_info); | 64 void SetMemoryInfo(v8::Local<v8::Value> memory_info); |
68 void SetLogConsoleApiMessageCalls(bool log); | 65 void SetLogConsoleApiMessageCalls(bool log); |
| 66 void SetMaxAsyncTaskStacksForTest(int limit); |
| 67 void DumpAsyncTaskStacksStateForTest(); |
69 void FireContextCreated(v8::Local<v8::Context> context, int context_group_id); | 68 void FireContextCreated(v8::Local<v8::Context> context, int context_group_id); |
70 void FireContextDestroyed(v8::Local<v8::Context> context); | 69 void FireContextDestroyed(v8::Local<v8::Context> context); |
71 | 70 |
72 private: | 71 private: |
73 struct VectorCompare { | 72 struct VectorCompare { |
74 bool operator()(const v8::internal::Vector<uint16_t>& lhs, | 73 bool operator()(const v8::internal::Vector<uint16_t>& lhs, |
75 const v8::internal::Vector<uint16_t>& rhs) const { | 74 const v8::internal::Vector<uint16_t>& rhs) const { |
76 for (int i = 0; i < lhs.length() && i < rhs.length(); ++i) { | 75 for (int i = 0; i < lhs.length() && i < rhs.length(); ++i) { |
77 if (lhs[i] != rhs[i]) return lhs[i] < rhs[i]; | 76 if (lhs[i] != rhs[i]) return lhs[i] < rhs[i]; |
78 } | 77 } |
(...skipping 28 matching lines...) Expand all Loading... |
107 v8::Isolate* isolate_; | 106 v8::Isolate* isolate_; |
108 std::unique_ptr<v8_inspector::V8Inspector> inspector_; | 107 std::unique_ptr<v8_inspector::V8Inspector> inspector_; |
109 int last_context_group_id_ = 0; | 108 int last_context_group_id_ = 0; |
110 std::map<int, v8::Global<v8::Context>> contexts_; | 109 std::map<int, v8::Global<v8::Context>> contexts_; |
111 std::map<v8::internal::Vector<uint16_t>, v8::Global<v8::Module>, | 110 std::map<v8::internal::Vector<uint16_t>, v8::Global<v8::Module>, |
112 VectorCompare> | 111 VectorCompare> |
113 modules_; | 112 modules_; |
114 int last_session_id_ = 0; | 113 int last_session_id_ = 0; |
115 std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_; | 114 std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_; |
116 std::map<v8_inspector::V8InspectorSession*, int> context_group_by_session_; | 115 std::map<v8_inspector::V8InspectorSession*, int> context_group_by_session_; |
117 std::map<int, std::unique_ptr<v8_inspector::V8Inspector::Channel>> channels_; | |
118 v8::Global<v8::Value> memory_info_; | 116 v8::Global<v8::Value> memory_info_; |
119 FrontendChannel* frontend_channel_; | |
120 bool current_time_set_ = false; | 117 bool current_time_set_ = false; |
121 double current_time_ = 0.0; | 118 double current_time_ = 0.0; |
122 bool log_console_api_message_calls_ = false; | 119 bool log_console_api_message_calls_ = false; |
123 | 120 |
124 DISALLOW_COPY_AND_ASSIGN(IsolateData); | 121 DISALLOW_COPY_AND_ASSIGN(IsolateData); |
125 }; | 122 }; |
126 | 123 |
127 #endif // V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_ | 124 #endif // V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_ |
OLD | NEW |