Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: test/inspector/isolate-data.h

Issue 2894773003: [inspector] Merge InspectorClientImpl into IsolateData (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/inspector/inspector-test.cc ('k') | test/inspector/isolate-data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
14 #include "src/base/platform/platform.h"
13 #include "src/vector.h" 15 #include "src/vector.h"
14 #include "test/inspector/inspector-impl.h"
15 16
16 class TaskRunner; 17 class TaskRunner;
17 18
18 class IsolateData { 19 class IsolateData : public v8_inspector::V8InspectorClient {
19 public: 20 public:
20 class SetupGlobalTask { 21 class SetupGlobalTask {
21 public: 22 public:
22 virtual ~SetupGlobalTask() = default; 23 virtual ~SetupGlobalTask() = default;
23 virtual void Run(v8::Isolate* isolate, 24 virtual void Run(v8::Isolate* isolate,
24 v8::Local<v8::ObjectTemplate> global) = 0; 25 v8::Local<v8::ObjectTemplate> global) = 0;
25 }; 26 };
26 using SetupGlobalTasks = std::vector<std::unique_ptr<SetupGlobalTask>>; 27 using SetupGlobalTasks = std::vector<std::unique_ptr<SetupGlobalTask>>;
27 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
28 IsolateData(TaskRunner* task_runner, SetupGlobalTasks setup_global_tasks, 36 IsolateData(TaskRunner* task_runner, SetupGlobalTasks setup_global_tasks,
29 v8::StartupData* startup_data, 37 v8::StartupData* startup_data, FrontendChannel* channel);
30 InspectorClientImpl::FrontendChannel* channel);
31 static IsolateData* FromContext(v8::Local<v8::Context> context); 38 static IsolateData* FromContext(v8::Local<v8::Context> context);
32 39
33 v8::Isolate* isolate() const { return isolate_; } 40 v8::Isolate* isolate() const { return isolate_; }
34 InspectorClientImpl* inspector() const { return inspector_.get(); } 41 v8_inspector::V8Inspector* inspector() const { return inspector_.get(); }
35 TaskRunner* task_runner() const { return task_runner_; } 42 TaskRunner* task_runner() const { return task_runner_; }
43
44 // Setting things up.
36 int CreateContextGroup(); 45 int CreateContextGroup();
37 v8::Local<v8::Context> GetContext(int context_group_id); 46 v8::Local<v8::Context> GetContext(int context_group_id);
38 int GetContextGroupId(v8::Local<v8::Context> context); 47 int GetContextGroupId(v8::Local<v8::Context> context);
39 void RegisterModule(v8::Local<v8::Context> context, 48 void RegisterModule(v8::Local<v8::Context> context,
40 v8::internal::Vector<uint16_t> name, 49 v8::internal::Vector<uint16_t> name,
41 v8::ScriptCompiler::Source* source); 50 v8::ScriptCompiler::Source* source);
42 51
52 // Working with V8Inspector api.
53 int ConnectSession(int context_group_id,
54 const v8_inspector::StringView& state);
55 std::unique_ptr<v8_inspector::StringBuffer> DisconnectSession(int session_id);
56 void SendMessage(int session_id, const v8_inspector::StringView& message);
57 void BreakProgram(int context_group_id,
58 const v8_inspector::StringView& reason,
59 const v8_inspector::StringView& details);
60 void SchedulePauseOnNextStatement(int context_group_id,
61 const v8_inspector::StringView& reason,
62 const v8_inspector::StringView& details);
63 void CancelPauseOnNextStatement(int context_group_id);
64
65 // Test utilities.
66 void SetCurrentTimeMS(double time);
67 void SetMemoryInfo(v8::Local<v8::Value> memory_info);
68 void SetLogConsoleApiMessageCalls(bool log);
69 void FireContextCreated(v8::Local<v8::Context> context, int context_group_id);
70 void FireContextDestroyed(v8::Local<v8::Context> context);
71
43 private: 72 private:
44 struct VectorCompare { 73 struct VectorCompare {
45 bool operator()(const v8::internal::Vector<uint16_t>& lhs, 74 bool operator()(const v8::internal::Vector<uint16_t>& lhs,
46 const v8::internal::Vector<uint16_t>& rhs) const { 75 const v8::internal::Vector<uint16_t>& rhs) const {
47 for (int i = 0; i < lhs.length() && i < rhs.length(); ++i) { 76 for (int i = 0; i < lhs.length() && i < rhs.length(); ++i) {
48 if (lhs[i] != rhs[i]) return lhs[i] < rhs[i]; 77 if (lhs[i] != rhs[i]) return lhs[i] < rhs[i];
49 } 78 }
50 return false; 79 return false;
51 } 80 }
52 }; 81 };
53 static v8::MaybeLocal<v8::Module> ModuleResolveCallback( 82 static v8::MaybeLocal<v8::Module> ModuleResolveCallback(
54 v8::Local<v8::Context> context, v8::Local<v8::String> specifier, 83 v8::Local<v8::Context> context, v8::Local<v8::String> specifier,
55 v8::Local<v8::Module> referrer); 84 v8::Local<v8::Module> referrer);
85 static void MessageHandler(v8::Local<v8::Message> message,
86 v8::Local<v8::Value> exception);
87 std::vector<int> GetSessionIds(int context_group_id);
88
89 // V8InspectorClient implementation.
90 bool formatAccessorsAsProperties(v8::Local<v8::Value>) override;
91 v8::Local<v8::Context> ensureDefaultContextInGroup(
92 int context_group_id) override;
93 double currentTimeMS() override;
94 v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate* isolate,
95 v8::Local<v8::Context>) override;
96 void runMessageLoopOnPause(int context_group_id) override;
97 void quitMessageLoopOnPause() override;
98 void consoleAPIMessage(int contextGroupId,
99 v8::Isolate::MessageErrorLevel level,
100 const v8_inspector::StringView& message,
101 const v8_inspector::StringView& url,
102 unsigned lineNumber, unsigned columnNumber,
103 v8_inspector::V8StackTrace*) override;
56 104
57 TaskRunner* task_runner_; 105 TaskRunner* task_runner_;
58 SetupGlobalTasks setup_global_tasks_; 106 SetupGlobalTasks setup_global_tasks_;
59 v8::Isolate* isolate_; 107 v8::Isolate* isolate_;
60 std::unique_ptr<InspectorClientImpl> inspector_; 108 std::unique_ptr<v8_inspector::V8Inspector> inspector_;
61 int last_context_group_id_ = 0; 109 int last_context_group_id_ = 0;
62 std::map<int, v8::Global<v8::Context>> contexts_; 110 std::map<int, v8::Global<v8::Context>> contexts_;
63 std::map<v8::internal::Vector<uint16_t>, v8::Global<v8::Module>, 111 std::map<v8::internal::Vector<uint16_t>, v8::Global<v8::Module>,
64 VectorCompare> 112 VectorCompare>
65 modules_; 113 modules_;
114 int last_session_id_ = 0;
115 std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_;
116 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_;
119 FrontendChannel* frontend_channel_;
120 bool current_time_set_ = false;
121 double current_time_ = 0.0;
122 bool log_console_api_message_calls_ = false;
123
124 DISALLOW_COPY_AND_ASSIGN(IsolateData);
66 }; 125 };
126
67 #endif // V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_ 127 #endif // V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_
OLDNEW
« no previous file with comments | « test/inspector/inspector-test.cc ('k') | test/inspector/isolate-data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698