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

Side by Side Diff: test/inspector/task-runner.h

Issue 2663743002: [inspector] added test infrastructure and test for es6 modules (Closed)
Patch Set: addressed comment Created 3 years, 10 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/runtime/es6-module-expected.txt ('k') | test/inspector/task-runner.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 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>
9
8 #include "include/v8-inspector.h" 10 #include "include/v8-inspector.h"
9 #include "include/v8-platform.h" 11 #include "include/v8-platform.h"
10 #include "include/v8.h" 12 #include "include/v8.h"
11 #include "src/base/atomic-utils.h" 13 #include "src/base/atomic-utils.h"
12 #include "src/base/macros.h" 14 #include "src/base/macros.h"
13 #include "src/base/platform/platform.h" 15 #include "src/base/platform/platform.h"
14 #include "src/locked-queue-inl.h" 16 #include "src/locked-queue-inl.h"
15 #include "src/vector.h" 17 #include "src/vector.h"
16 18
19 struct VectorCompare {
20 bool operator()(const v8::internal::Vector<uint16_t>& lhs,
21 const v8::internal::Vector<uint16_t>& rhs) const {
22 for (int i = 0; i < lhs.length() && i < rhs.length(); ++i) {
23 if (lhs[i] != rhs[i]) return lhs[i] < rhs[i];
24 }
25 return false;
26 }
27 };
28
17 class TaskRunner : public v8::base::Thread { 29 class TaskRunner : public v8::base::Thread {
18 public: 30 public:
19 class Task { 31 class Task {
20 public: 32 public:
21 virtual ~Task() {} 33 virtual ~Task() {}
22 virtual bool is_inspector_task() = 0; 34 virtual bool is_inspector_task() = 0;
23 virtual void Run(v8::Isolate* isolate, 35 virtual void Run(v8::Isolate* isolate,
24 const v8::Global<v8::Context>& context) = 0; 36 const v8::Global<v8::Context>& context) = 0;
25 }; 37 };
26 38
27 TaskRunner(v8::ExtensionConfiguration* extensions, bool catch_exceptions, 39 TaskRunner(v8::ExtensionConfiguration* extensions, bool catch_exceptions,
28 v8::base::Semaphore* ready_semaphore); 40 v8::base::Semaphore* ready_semaphore);
29 virtual ~TaskRunner(); 41 virtual ~TaskRunner();
30 42
31 // Thread implementation. 43 // Thread implementation.
32 void Run() override; 44 void Run() override;
33 45
34 // Should be called from the same thread and only from task. 46 // Should be called from the same thread and only from task.
35 void RunMessageLoop(bool only_protocol); 47 void RunMessageLoop(bool only_protocol);
36 void QuitMessageLoop(); 48 void QuitMessageLoop();
37 49
38 // TaskRunner takes ownership. 50 // TaskRunner takes ownership.
39 void Append(Task* task); 51 void Append(Task* task);
40 52
41 static TaskRunner* FromContext(v8::Local<v8::Context>); 53 static TaskRunner* FromContext(v8::Local<v8::Context>);
42 54
43 void Terminate(); 55 void Terminate();
44 56
57 void RegisterModule(v8::internal::Vector<uint16_t> name,
58 v8::Local<v8::Module> module);
59 static v8::MaybeLocal<v8::Module> ModuleResolveCallback(
60 v8::Local<v8::Context> context, v8::Local<v8::String> specifier,
61 v8::Local<v8::Module> referrer);
62
45 private: 63 private:
46 void InitializeContext(); 64 void InitializeContext();
47 Task* GetNext(bool only_protocol); 65 Task* GetNext(bool only_protocol);
48 66
49 v8::ExtensionConfiguration* extensions_; 67 v8::ExtensionConfiguration* extensions_;
50 bool catch_exceptions_; 68 bool catch_exceptions_;
51 v8::base::Semaphore* ready_semaphore_; 69 v8::base::Semaphore* ready_semaphore_;
52 70
53 v8::Isolate* isolate_; 71 v8::Isolate* isolate_;
54 v8::Global<v8::Context> context_; 72 v8::Global<v8::Context> context_;
55 73
56 // deferred_queue_ combined with queue_ (in this order) have all tasks in the 74 // deferred_queue_ combined with queue_ (in this order) have all tasks in the
57 // correct order. Sometimes we skip non-protocol tasks by moving them from 75 // correct order. Sometimes we skip non-protocol tasks by moving them from
58 // queue_ to deferred_queue_. 76 // queue_ to deferred_queue_.
59 v8::internal::LockedQueue<Task*> queue_; 77 v8::internal::LockedQueue<Task*> queue_;
60 v8::internal::LockedQueue<Task*> deffered_queue_; 78 v8::internal::LockedQueue<Task*> deffered_queue_;
61 v8::base::Semaphore process_queue_semaphore_; 79 v8::base::Semaphore process_queue_semaphore_;
62 80
81 std::map<v8::internal::Vector<uint16_t>, v8::Global<v8::Module>,
82 VectorCompare>
83 modules_;
84
63 int nested_loop_count_; 85 int nested_loop_count_;
64 86
65 v8::base::AtomicNumber<int> is_terminated_; 87 v8::base::AtomicNumber<int> is_terminated_;
66 88
67 DISALLOW_COPY_AND_ASSIGN(TaskRunner); 89 DISALLOW_COPY_AND_ASSIGN(TaskRunner);
68 }; 90 };
69 91
70 class AsyncTask : public TaskRunner::Task { 92 class AsyncTask : public TaskRunner::Task {
71 public: 93 public:
72 AsyncTask(const char* task_name, v8_inspector::V8Inspector* inspector); 94 AsyncTask(const char* task_name, v8_inspector::V8Inspector* inspector);
73 virtual ~AsyncTask() = default; 95 virtual ~AsyncTask() = default;
74 96
75 void Run(v8::Isolate* isolate, 97 void Run(v8::Isolate* isolate,
76 const v8::Global<v8::Context>& context) override; 98 const v8::Global<v8::Context>& context) override;
77 virtual void AsyncRun(v8::Isolate* isolate, 99 virtual void AsyncRun(v8::Isolate* isolate,
78 const v8::Global<v8::Context>& context) = 0; 100 const v8::Global<v8::Context>& context) = 0;
79 101
80 private: 102 private:
81 v8_inspector::V8Inspector* inspector_; 103 v8_inspector::V8Inspector* inspector_;
82 }; 104 };
83 105
84 class ExecuteStringTask : public AsyncTask { 106 class ExecuteStringTask : public AsyncTask {
85 public: 107 public:
86 ExecuteStringTask(const v8::internal::Vector<uint16_t>& expression, 108 ExecuteStringTask(const v8::internal::Vector<uint16_t>& expression,
87 v8::Local<v8::String> name, 109 v8::Local<v8::String> name,
88 v8::Local<v8::Integer> line_offset, 110 v8::Local<v8::Integer> line_offset,
89 v8::Local<v8::Integer> column_offset, const char* task_name, 111 v8::Local<v8::Integer> column_offset,
112 v8::Local<v8::Boolean> is_module, const char* task_name,
90 v8_inspector::V8Inspector* inspector); 113 v8_inspector::V8Inspector* inspector);
91 explicit ExecuteStringTask( 114 explicit ExecuteStringTask(
92 const v8::internal::Vector<const char>& expression); 115 const v8::internal::Vector<const char>& expression);
93 bool is_inspector_task() override { return false; } 116 bool is_inspector_task() override { return false; }
94 117
95 void AsyncRun(v8::Isolate* isolate, 118 void AsyncRun(v8::Isolate* isolate,
96 const v8::Global<v8::Context>& context) override; 119 const v8::Global<v8::Context>& context) override;
97 120
98 private: 121 private:
99 v8::internal::Vector<uint16_t> expression_; 122 v8::internal::Vector<uint16_t> expression_;
100 v8::internal::Vector<const char> expression_utf8_; 123 v8::internal::Vector<const char> expression_utf8_;
101 v8::internal::Vector<uint16_t> name_; 124 v8::internal::Vector<uint16_t> name_;
102 int32_t line_offset_; 125 int32_t line_offset_ = 0;
103 int32_t column_offset_; 126 int32_t column_offset_ = 0;
127 bool is_module_ = false;
104 128
105 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); 129 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask);
106 }; 130 };
107 131
108 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ 132 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_
OLDNEW
« no previous file with comments | « test/inspector/runtime/es6-module-expected.txt ('k') | test/inspector/task-runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698