| 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_INSPECTOR_IMPL_H_ | 5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ |
| 6 #define V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ | 6 #define V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 |
| 8 #include "include/v8-inspector.h" | 10 #include "include/v8-inspector.h" |
| 9 #include "include/v8.h" | 11 #include "include/v8.h" |
| 10 #include "src/base/macros.h" | 12 #include "src/base/macros.h" |
| 11 #include "src/base/platform/platform.h" | 13 #include "src/base/platform/platform.h" |
| 12 #include "test/inspector/task-runner.h" | 14 |
| 15 class TaskRunner; |
| 13 | 16 |
| 14 class InspectorClientImpl : public v8_inspector::V8InspectorClient { | 17 class InspectorClientImpl : public v8_inspector::V8InspectorClient { |
| 15 public: | 18 public: |
| 16 class FrontendChannel { | 19 class FrontendChannel { |
| 17 public: | 20 public: |
| 18 virtual ~FrontendChannel() = default; | 21 virtual ~FrontendChannel() = default; |
| 19 virtual void SendMessageToFrontend( | 22 virtual void SendMessageToFrontend( |
| 20 const v8_inspector::StringView& message) = 0; | 23 int session_id, const v8_inspector::StringView& message) = 0; |
| 21 }; | 24 }; |
| 22 | 25 |
| 23 InspectorClientImpl(TaskRunner* task_runner, | 26 InspectorClientImpl(v8::Isolate* isolate, TaskRunner* task_runner, |
| 24 FrontendChannel* frontend_channel, | 27 FrontendChannel* frontend_channel); |
| 25 v8::base::Semaphore* ready_semaphore); | |
| 26 virtual ~InspectorClientImpl(); | 28 virtual ~InspectorClientImpl(); |
| 27 | 29 |
| 28 void scheduleReconnect(v8::base::Semaphore* ready_semaphore); | 30 v8_inspector::V8Inspector* inspector() const { return inspector_.get(); } |
| 29 void scheduleDisconnect(v8::base::Semaphore* ready_semaphore); | 31 int ConnectSession(int context_group_id, |
| 30 void scheduleCreateContextGroup( | 32 const v8_inspector::StringView& state); |
| 31 IsolateData::SetupGlobalTasks setup_global_tasks, | 33 std::unique_ptr<v8_inspector::StringBuffer> DisconnectSession(int session_id); |
| 32 v8::base::Semaphore* ready_semaphore, int* context_group_id); | 34 void SendMessage(int session_id, const v8_inspector::StringView& message); |
| 33 | 35 void BreakProgram(int context_group_id, |
| 34 static v8_inspector::V8Inspector* InspectorFromContext( | 36 const v8_inspector::StringView& reason, |
| 35 v8::Local<v8::Context> context); | 37 const v8_inspector::StringView& details); |
| 36 static v8_inspector::V8InspectorSession* SessionFromContext( | 38 void SchedulePauseOnNextStatement(int context_group_id, |
| 37 v8::Local<v8::Context> context); | 39 const v8_inspector::StringView& reason, |
| 38 | 40 const v8_inspector::StringView& details); |
| 39 // context_group_id = 0 means default context group. | 41 void CancelPauseOnNextStatement(int context_group_id); |
| 40 v8_inspector::V8InspectorSession* session(int context_group_id = 0); | 42 void SetCurrentTimeMSForTest(double time); |
| 41 | 43 void SetMemoryInfoForTest(v8::Local<v8::Value> memory_info); |
| 42 void setCurrentTimeMSForTest(double time); | 44 void SetLogConsoleApiMessageCalls(bool log); |
| 43 void setMemoryInfoForTest(v8::Local<v8::Value> memory_info); | 45 void ContextCreated(v8::Local<v8::Context> context, int context_group_id); |
| 44 void setLogConsoleApiMessageCalls(bool log); | 46 void ContextDestroyed(v8::Local<v8::Context> context); |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 // V8InspectorClient implementation. | 49 // V8InspectorClient implementation. |
| 48 bool formatAccessorsAsProperties(v8::Local<v8::Value>) override; | 50 bool formatAccessorsAsProperties(v8::Local<v8::Value>) override; |
| 49 v8::Local<v8::Context> ensureDefaultContextInGroup( | 51 v8::Local<v8::Context> ensureDefaultContextInGroup( |
| 50 int context_group_id) override; | 52 int context_group_id) override; |
| 51 double currentTimeMS() override; | 53 double currentTimeMS() override; |
| 52 v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate* isolate, | 54 v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate* isolate, |
| 53 v8::Local<v8::Context>) override; | 55 v8::Local<v8::Context>) override; |
| 54 void runMessageLoopOnPause(int context_group_id) override; | 56 void runMessageLoopOnPause(int context_group_id) override; |
| 55 void quitMessageLoopOnPause() override; | 57 void quitMessageLoopOnPause() override; |
| 56 void consoleAPIMessage(int contextGroupId, | 58 void consoleAPIMessage(int contextGroupId, |
| 57 v8::Isolate::MessageErrorLevel level, | 59 v8::Isolate::MessageErrorLevel level, |
| 58 const v8_inspector::StringView& message, | 60 const v8_inspector::StringView& message, |
| 59 const v8_inspector::StringView& url, | 61 const v8_inspector::StringView& url, |
| 60 unsigned lineNumber, unsigned columnNumber, | 62 unsigned lineNumber, unsigned columnNumber, |
| 61 v8_inspector::V8StackTrace*) override; | 63 v8_inspector::V8StackTrace*) override; |
| 62 friend class SendMessageToBackendTask; | |
| 63 | |
| 64 friend class ConnectTask; | |
| 65 void connect(); | |
| 66 void ConnectToContextGroup(int context_group_id, | |
| 67 v8_inspector::StringView state); | |
| 68 friend class DisconnectTask; | |
| 69 void disconnect(bool reset_inspector); | |
| 70 friend class CreateContextGroupTask; | |
| 71 int createContextGroup( | |
| 72 const IsolateData::SetupGlobalTasks& setup_global_tasks); | |
| 73 | 64 |
| 74 std::unique_ptr<v8_inspector::V8Inspector> inspector_; | 65 std::unique_ptr<v8_inspector::V8Inspector> inspector_; |
| 75 std::unique_ptr<v8_inspector::V8Inspector::Channel> channel_; | 66 int last_session_id_ = 0; |
| 76 | |
| 77 std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_; | 67 std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_; |
| 78 std::map<int, std::unique_ptr<v8_inspector::StringBuffer>> states_; | 68 std::map<v8_inspector::V8InspectorSession*, int> context_group_by_session_; |
| 79 | 69 std::map<int, std::unique_ptr<v8_inspector::V8Inspector::Channel>> channels_; |
| 70 TaskRunner* task_runner_; |
| 80 v8::Isolate* isolate_; | 71 v8::Isolate* isolate_; |
| 81 v8::Global<v8::Value> memory_info_; | 72 v8::Global<v8::Value> memory_info_; |
| 82 | |
| 83 TaskRunner* task_runner_; | |
| 84 FrontendChannel* frontend_channel_; | 73 FrontendChannel* frontend_channel_; |
| 85 | |
| 86 bool current_time_set_for_test_ = false; | 74 bool current_time_set_for_test_ = false; |
| 87 double current_time_ = 0.0; | 75 double current_time_ = 0.0; |
| 88 bool log_console_api_message_calls_ = false; | 76 bool log_console_api_message_calls_ = false; |
| 89 | 77 |
| 90 DISALLOW_COPY_AND_ASSIGN(InspectorClientImpl); | 78 DISALLOW_COPY_AND_ASSIGN(InspectorClientImpl); |
| 91 }; | 79 }; |
| 92 | 80 |
| 93 class SendMessageToBackendExtension : public IsolateData::SetupGlobalTask { | |
| 94 public: | |
| 95 void Run(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> global) override; | |
| 96 | |
| 97 static void set_backend_task_runner(TaskRunner* task_runner) { | |
| 98 backend_task_runner_ = task_runner; | |
| 99 } | |
| 100 | |
| 101 private: | |
| 102 static void SendMessageToBackend( | |
| 103 const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 104 | |
| 105 static TaskRunner* backend_task_runner_; | |
| 106 }; | |
| 107 | |
| 108 #endif // V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ | 81 #endif // V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ |
| OLD | NEW |