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/vector.h" | 13 #include "src/vector.h" |
| 14 #include "test/inspector/inspector-impl.h" |
14 | 15 |
15 class TaskRunner; | 16 class TaskRunner; |
16 | 17 |
17 class IsolateData { | 18 class IsolateData { |
18 public: | 19 public: |
19 class SetupGlobalTask { | 20 class SetupGlobalTask { |
20 public: | 21 public: |
21 virtual ~SetupGlobalTask() = default; | 22 virtual ~SetupGlobalTask() = default; |
22 virtual void Run(v8::Isolate* isolate, | 23 virtual void Run(v8::Isolate* isolate, |
23 v8::Local<v8::ObjectTemplate> global) = 0; | 24 v8::Local<v8::ObjectTemplate> global) = 0; |
24 }; | 25 }; |
25 using SetupGlobalTasks = std::vector<std::unique_ptr<SetupGlobalTask>>; | 26 using SetupGlobalTasks = std::vector<std::unique_ptr<SetupGlobalTask>>; |
26 | 27 |
27 IsolateData(TaskRunner* task_runner, SetupGlobalTasks setup_global_tasks, | 28 IsolateData(TaskRunner* task_runner, SetupGlobalTasks setup_global_tasks, |
28 v8::StartupData* startup_data); | 29 v8::StartupData* startup_data, |
| 30 InspectorClientImpl::FrontendChannel* channel); |
29 static IsolateData* FromContext(v8::Local<v8::Context> context); | 31 static IsolateData* FromContext(v8::Local<v8::Context> context); |
30 | 32 |
31 v8::Isolate* isolate() const { return isolate_; } | 33 v8::Isolate* isolate() const { return isolate_; } |
| 34 InspectorClientImpl* inspector() const { return inspector_.get(); } |
32 TaskRunner* task_runner() const { return task_runner_; } | 35 TaskRunner* task_runner() const { return task_runner_; } |
33 int CreateContextGroup(); | 36 int CreateContextGroup(); |
34 v8::Local<v8::Context> GetContext(int context_group_id); | 37 v8::Local<v8::Context> GetContext(int context_group_id); |
| 38 int GetContextGroupId(v8::Local<v8::Context> context); |
35 void RegisterModule(v8::Local<v8::Context> context, | 39 void RegisterModule(v8::Local<v8::Context> context, |
36 v8::internal::Vector<uint16_t> name, | 40 v8::internal::Vector<uint16_t> name, |
37 v8::ScriptCompiler::Source* source); | 41 v8::ScriptCompiler::Source* source); |
38 | 42 |
39 private: | 43 private: |
40 struct VectorCompare { | 44 struct VectorCompare { |
41 bool operator()(const v8::internal::Vector<uint16_t>& lhs, | 45 bool operator()(const v8::internal::Vector<uint16_t>& lhs, |
42 const v8::internal::Vector<uint16_t>& rhs) const { | 46 const v8::internal::Vector<uint16_t>& rhs) const { |
43 for (int i = 0; i < lhs.length() && i < rhs.length(); ++i) { | 47 for (int i = 0; i < lhs.length() && i < rhs.length(); ++i) { |
44 if (lhs[i] != rhs[i]) return lhs[i] < rhs[i]; | 48 if (lhs[i] != rhs[i]) return lhs[i] < rhs[i]; |
45 } | 49 } |
46 return false; | 50 return false; |
47 } | 51 } |
48 }; | 52 }; |
49 static v8::MaybeLocal<v8::Module> ModuleResolveCallback( | 53 static v8::MaybeLocal<v8::Module> ModuleResolveCallback( |
50 v8::Local<v8::Context> context, v8::Local<v8::String> specifier, | 54 v8::Local<v8::Context> context, v8::Local<v8::String> specifier, |
51 v8::Local<v8::Module> referrer); | 55 v8::Local<v8::Module> referrer); |
52 | 56 |
53 TaskRunner* task_runner_; | 57 TaskRunner* task_runner_; |
54 SetupGlobalTasks setup_global_tasks_; | 58 SetupGlobalTasks setup_global_tasks_; |
55 v8::Isolate* isolate_; | 59 v8::Isolate* isolate_; |
| 60 std::unique_ptr<InspectorClientImpl> inspector_; |
56 int last_context_group_id_ = 0; | 61 int last_context_group_id_ = 0; |
57 std::map<int, v8::Global<v8::Context>> contexts_; | 62 std::map<int, v8::Global<v8::Context>> contexts_; |
58 std::map<v8::internal::Vector<uint16_t>, v8::Global<v8::Module>, | 63 std::map<v8::internal::Vector<uint16_t>, v8::Global<v8::Module>, |
59 VectorCompare> | 64 VectorCompare> |
60 modules_; | 65 modules_; |
61 }; | 66 }; |
62 #endif // V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_ | 67 #endif // V8_TEST_INSPECTOR_PROTOCOL_ISOLATE_DATA_H_ |
OLD | NEW |