| 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" |
| 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/atomic-utils.h" | 13 #include "src/base/atomic-utils.h" |
| 14 #include "src/base/macros.h" | 14 #include "src/base/macros.h" |
| 15 #include "src/base/platform/platform.h" | 15 #include "src/base/platform/platform.h" |
| 16 #include "src/locked-queue-inl.h" | 16 #include "src/locked-queue-inl.h" |
| 17 #include "src/vector.h" | 17 #include "src/vector.h" |
| 18 #include "test/inspector/isolate-data.h" | 18 #include "test/inspector/isolate-data.h" |
| 19 | 19 |
| 20 class TaskRunner : public v8::base::Thread { | 20 class TaskRunner : public v8::base::Thread { |
| 21 public: | 21 public: |
| 22 class Task { | 22 class Task { |
| 23 public: | 23 public: |
| 24 virtual ~Task() {} | 24 virtual ~Task() {} |
| 25 virtual bool is_inspector_task() = 0; | 25 virtual bool is_inspector_task() = 0; |
| 26 void RunOnTaskRunner(TaskRunner* task_runner) { | 26 void RunOnIsolate(IsolateData* data) { |
| 27 task_runner_ = task_runner; | 27 data_ = data; |
| 28 Run(); | 28 Run(); |
| 29 task_runner_ = nullptr; | 29 data_ = nullptr; |
| 30 } | 30 } |
| 31 | 31 |
| 32 protected: | 32 protected: |
| 33 virtual void Run() = 0; | 33 virtual void Run() = 0; |
| 34 v8::Isolate* isolate() const { return task_runner_->data_->isolate(); } | 34 v8::Isolate* isolate() const { return data_->isolate(); } |
| 35 v8::Local<v8::Context> default_context() const { | 35 IsolateData* data() const { return data_; } |
| 36 return task_runner_->data_->GetContext( | |
| 37 task_runner_->default_context_group_id_); | |
| 38 } | |
| 39 | 36 |
| 40 private: | 37 private: |
| 41 TaskRunner* task_runner_ = nullptr; | 38 IsolateData* data_ = nullptr; |
| 42 }; | 39 }; |
| 43 | 40 |
| 44 TaskRunner(IsolateData::SetupGlobalTasks setup_global_tasks, | 41 TaskRunner(IsolateData::SetupGlobalTasks setup_global_tasks, |
| 45 bool catch_exceptions, v8::base::Semaphore* ready_semaphore, | 42 bool catch_exceptions, v8::base::Semaphore* ready_semaphore, |
| 46 v8::StartupData* startup_data); | 43 v8::StartupData* startup_data, |
| 44 InspectorClientImpl::FrontendChannel* channel); |
| 47 virtual ~TaskRunner(); | 45 virtual ~TaskRunner(); |
| 48 IsolateData* data() const { return data_.get(); } | 46 IsolateData* data() const { return data_.get(); } |
| 49 int default_context_group_id() const { return default_context_group_id_; } | |
| 50 | 47 |
| 51 // Thread implementation. | 48 // Thread implementation. |
| 52 void Run() override; | 49 void Run() override; |
| 53 | 50 |
| 54 // Should be called from the same thread and only from task. | 51 // Should be called from the same thread and only from task. |
| 55 void RunMessageLoop(bool only_protocol); | 52 void RunMessageLoop(bool only_protocol); |
| 56 void QuitMessageLoop(); | 53 void QuitMessageLoop(); |
| 57 | 54 |
| 58 // TaskRunner takes ownership. | 55 // TaskRunner takes ownership. |
| 59 void Append(Task* task); | 56 void Append(Task* task); |
| 60 | 57 |
| 61 void Terminate(); | 58 void Terminate(); |
| 62 | 59 |
| 63 private: | 60 private: |
| 64 Task* GetNext(bool only_protocol); | 61 Task* GetNext(bool only_protocol); |
| 65 v8::Isolate* isolate() const { return data_->isolate(); } | 62 v8::Isolate* isolate() const { return data_->isolate(); } |
| 66 | 63 |
| 67 IsolateData::SetupGlobalTasks setup_global_tasks_; | 64 IsolateData::SetupGlobalTasks setup_global_tasks_; |
| 68 v8::StartupData* startup_data_; | 65 v8::StartupData* startup_data_; |
| 66 InspectorClientImpl::FrontendChannel* channel_; |
| 69 bool catch_exceptions_; | 67 bool catch_exceptions_; |
| 70 v8::base::Semaphore* ready_semaphore_; | 68 v8::base::Semaphore* ready_semaphore_; |
| 71 std::unique_ptr<IsolateData> data_; | 69 std::unique_ptr<IsolateData> data_; |
| 72 int default_context_group_id_; | |
| 73 | 70 |
| 74 // deferred_queue_ combined with queue_ (in this order) have all tasks in the | 71 // deferred_queue_ combined with queue_ (in this order) have all tasks in the |
| 75 // correct order. Sometimes we skip non-protocol tasks by moving them from | 72 // correct order. Sometimes we skip non-protocol tasks by moving them from |
| 76 // queue_ to deferred_queue_. | 73 // queue_ to deferred_queue_. |
| 77 v8::internal::LockedQueue<Task*> queue_; | 74 v8::internal::LockedQueue<Task*> queue_; |
| 78 v8::internal::LockedQueue<Task*> deffered_queue_; | 75 v8::internal::LockedQueue<Task*> deffered_queue_; |
| 79 v8::base::Semaphore process_queue_semaphore_; | 76 v8::base::Semaphore process_queue_semaphore_; |
| 80 | 77 |
| 81 int nested_loop_count_; | 78 int nested_loop_count_; |
| 82 | 79 |
| 83 v8::base::AtomicNumber<int> is_terminated_; | 80 v8::base::AtomicNumber<int> is_terminated_; |
| 84 | 81 |
| 85 DISALLOW_COPY_AND_ASSIGN(TaskRunner); | 82 DISALLOW_COPY_AND_ASSIGN(TaskRunner); |
| 86 }; | 83 }; |
| 87 | 84 |
| 88 class AsyncTask : public TaskRunner::Task { | 85 class AsyncTask : public TaskRunner::Task { |
| 89 public: | 86 public: |
| 90 AsyncTask(const char* task_name, v8_inspector::V8Inspector* inspector); | 87 AsyncTask(IsolateData* data, const char* task_name); |
| 91 virtual ~AsyncTask() = default; | 88 virtual ~AsyncTask() = default; |
| 92 | 89 |
| 93 protected: | 90 protected: |
| 94 virtual void AsyncRun() = 0; | 91 virtual void AsyncRun() = 0; |
| 95 void Run() override; | 92 void Run() override; |
| 96 | 93 |
| 97 v8_inspector::V8Inspector* inspector_; | 94 bool instrumenting_; |
| 98 }; | 95 }; |
| 99 | 96 |
| 100 class ExecuteStringTask : public AsyncTask { | 97 class ExecuteStringTask : public AsyncTask { |
| 101 public: | 98 public: |
| 102 ExecuteStringTask(const v8::internal::Vector<uint16_t>& expression, | 99 ExecuteStringTask(IsolateData* data, int context_group_id, |
| 100 const char* task_name, |
| 101 const v8::internal::Vector<uint16_t>& expression, |
| 103 v8::Local<v8::String> name, | 102 v8::Local<v8::String> name, |
| 104 v8::Local<v8::Integer> line_offset, | 103 v8::Local<v8::Integer> line_offset, |
| 105 v8::Local<v8::Integer> column_offset, | 104 v8::Local<v8::Integer> column_offset, |
| 106 v8::Local<v8::Boolean> is_module, const char* task_name, | 105 v8::Local<v8::Boolean> is_module); |
| 107 v8_inspector::V8Inspector* inspector); | 106 ExecuteStringTask(const v8::internal::Vector<const char>& expression, |
| 108 explicit ExecuteStringTask( | 107 int context_group_id); |
| 109 const v8::internal::Vector<const char>& expression); | |
| 110 bool is_inspector_task() override { return false; } | 108 bool is_inspector_task() override { return false; } |
| 111 | 109 |
| 112 private: | 110 private: |
| 113 void AsyncRun() override; | 111 void AsyncRun() override; |
| 114 | 112 |
| 115 v8::internal::Vector<uint16_t> expression_; | 113 v8::internal::Vector<uint16_t> expression_; |
| 116 v8::internal::Vector<const char> expression_utf8_; | 114 v8::internal::Vector<const char> expression_utf8_; |
| 117 v8::internal::Vector<uint16_t> name_; | 115 v8::internal::Vector<uint16_t> name_; |
| 118 int32_t line_offset_ = 0; | 116 int32_t line_offset_ = 0; |
| 119 int32_t column_offset_ = 0; | 117 int32_t column_offset_ = 0; |
| 120 bool is_module_ = false; | 118 bool is_module_ = false; |
| 119 int context_group_id_; |
| 121 | 120 |
| 122 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); | 121 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); |
| 123 }; | 122 }; |
| 124 | 123 |
| 125 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | 124 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
| OLD | NEW |