OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 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_TASK_RUNNER_H_ | 5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
6 #define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | 6 #define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "include/v8-inspector.h" | 10 #include "include/v8-inspector.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 return false; | 25 return false; |
26 } | 26 } |
27 }; | 27 }; |
28 | 28 |
29 class TaskRunner : public v8::base::Thread { | 29 class TaskRunner : public v8::base::Thread { |
30 public: | 30 public: |
31 class Task { | 31 class Task { |
32 public: | 32 public: |
33 virtual ~Task() {} | 33 virtual ~Task() {} |
34 virtual bool is_inspector_task() = 0; | 34 virtual bool is_inspector_task() = 0; |
35 virtual void Run(v8::Isolate* isolate, | 35 void RunOnTaskRunner(TaskRunner* task_runner) { |
36 const v8::Global<v8::Context>& context) = 0; | 36 task_runner_ = task_runner; |
| 37 Run(); |
| 38 task_runner_ = nullptr; |
| 39 } |
| 40 |
| 41 protected: |
| 42 virtual void Run() = 0; |
| 43 v8::Isolate* isolate() const { return task_runner_->isolate_; } |
| 44 v8::Local<v8::Context> default_context() const { |
| 45 return task_runner_->contexts_.begin()->second.Get(isolate()); |
| 46 } |
| 47 |
| 48 private: |
| 49 TaskRunner* task_runner_ = nullptr; |
37 }; | 50 }; |
38 | 51 |
39 class SetupGlobalTask { | 52 class SetupGlobalTask { |
40 public: | 53 public: |
41 virtual ~SetupGlobalTask() = default; | 54 virtual ~SetupGlobalTask() = default; |
42 virtual void Run(v8::Isolate* isolate, | 55 virtual void Run(v8::Isolate* isolate, |
43 v8::Local<v8::ObjectTemplate> global) = 0; | 56 v8::Local<v8::ObjectTemplate> global) = 0; |
44 }; | 57 }; |
45 using SetupGlobalTasks = std::vector<std::unique_ptr<SetupGlobalTask>>; | 58 using SetupGlobalTasks = std::vector<std::unique_ptr<SetupGlobalTask>>; |
46 | 59 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 v8::base::AtomicNumber<int> is_terminated_; | 116 v8::base::AtomicNumber<int> is_terminated_; |
104 | 117 |
105 DISALLOW_COPY_AND_ASSIGN(TaskRunner); | 118 DISALLOW_COPY_AND_ASSIGN(TaskRunner); |
106 }; | 119 }; |
107 | 120 |
108 class AsyncTask : public TaskRunner::Task { | 121 class AsyncTask : public TaskRunner::Task { |
109 public: | 122 public: |
110 AsyncTask(const char* task_name, v8_inspector::V8Inspector* inspector); | 123 AsyncTask(const char* task_name, v8_inspector::V8Inspector* inspector); |
111 virtual ~AsyncTask() = default; | 124 virtual ~AsyncTask() = default; |
112 | 125 |
113 void Run(v8::Isolate* isolate, | 126 protected: |
114 const v8::Global<v8::Context>& context) override; | 127 virtual void AsyncRun() = 0; |
115 virtual void AsyncRun(v8::Isolate* isolate, | 128 void Run() override; |
116 const v8::Global<v8::Context>& context) = 0; | |
117 | 129 |
118 protected: | |
119 v8_inspector::V8Inspector* inspector_; | 130 v8_inspector::V8Inspector* inspector_; |
120 }; | 131 }; |
121 | 132 |
122 class ExecuteStringTask : public AsyncTask { | 133 class ExecuteStringTask : public AsyncTask { |
123 public: | 134 public: |
124 ExecuteStringTask(const v8::internal::Vector<uint16_t>& expression, | 135 ExecuteStringTask(const v8::internal::Vector<uint16_t>& expression, |
125 v8::Local<v8::String> name, | 136 v8::Local<v8::String> name, |
126 v8::Local<v8::Integer> line_offset, | 137 v8::Local<v8::Integer> line_offset, |
127 v8::Local<v8::Integer> column_offset, | 138 v8::Local<v8::Integer> column_offset, |
128 v8::Local<v8::Boolean> is_module, const char* task_name, | 139 v8::Local<v8::Boolean> is_module, const char* task_name, |
129 v8_inspector::V8Inspector* inspector); | 140 v8_inspector::V8Inspector* inspector); |
130 explicit ExecuteStringTask( | 141 explicit ExecuteStringTask( |
131 const v8::internal::Vector<const char>& expression); | 142 const v8::internal::Vector<const char>& expression); |
132 bool is_inspector_task() override { return false; } | 143 bool is_inspector_task() override { return false; } |
133 | 144 |
134 void AsyncRun(v8::Isolate* isolate, | 145 private: |
135 const v8::Global<v8::Context>& context) override; | 146 void AsyncRun() override; |
136 | 147 |
137 private: | |
138 v8::internal::Vector<uint16_t> expression_; | 148 v8::internal::Vector<uint16_t> expression_; |
139 v8::internal::Vector<const char> expression_utf8_; | 149 v8::internal::Vector<const char> expression_utf8_; |
140 v8::internal::Vector<uint16_t> name_; | 150 v8::internal::Vector<uint16_t> name_; |
141 int32_t line_offset_ = 0; | 151 int32_t line_offset_ = 0; |
142 int32_t column_offset_ = 0; | 152 int32_t column_offset_ = 0; |
143 bool is_module_ = false; | 153 bool is_module_ = false; |
144 | 154 |
145 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); | 155 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); |
146 }; | 156 }; |
147 | 157 |
148 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | 158 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
OLD | NEW |