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 #include "test/inspector/task-runner.h" | 5 #include "test/inspector/task-runner.h" |
6 | 6 |
| 7 #include "test/inspector/inspector-impl.h" |
| 8 |
7 #if !defined(_WIN32) && !defined(_WIN64) | 9 #if !defined(_WIN32) && !defined(_WIN64) |
8 #include <unistd.h> // NOLINT | 10 #include <unistd.h> // NOLINT |
9 #endif // !defined(_WIN32) && !defined(_WIN64) | 11 #endif // !defined(_WIN32) && !defined(_WIN64) |
10 | 12 |
11 namespace { | 13 namespace { |
12 | 14 |
13 const int kTaskRunnerIndex = 2; | 15 const int kTaskRunnerIndex = 2; |
14 | 16 |
15 void ReportUncaughtException(v8::Isolate* isolate, | 17 void ReportUncaughtException(v8::Isolate* isolate, |
16 const v8::TryCatch& try_catch) { | 18 const v8::TryCatch& try_catch) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 129 |
128 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) { | 130 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) { |
129 v8::internal::Vector<uint16_t> buffer = | 131 v8::internal::Vector<uint16_t> buffer = |
130 v8::internal::Vector<uint16_t>::New(str->Length()); | 132 v8::internal::Vector<uint16_t>::New(str->Length()); |
131 str->Write(buffer.start(), 0, str->Length()); | 133 str->Write(buffer.start(), 0, str->Length()); |
132 return buffer; | 134 return buffer; |
133 } | 135 } |
134 | 136 |
135 } // namespace | 137 } // namespace |
136 | 138 |
| 139 AsyncTask::AsyncTask(const char* task_name, |
| 140 v8_inspector::V8Inspector* inspector) |
| 141 : inspector_(task_name ? inspector : nullptr) { |
| 142 if (inspector_) { |
| 143 inspector_->asyncTaskScheduled( |
| 144 v8_inspector::StringView(reinterpret_cast<const uint8_t*>(task_name), |
| 145 strlen(task_name)), |
| 146 this, false); |
| 147 } |
| 148 } |
| 149 |
| 150 void AsyncTask::Run(v8::Isolate* isolate, |
| 151 const v8::Global<v8::Context>& context) { |
| 152 if (inspector_) inspector_->asyncTaskStarted(this); |
| 153 AsyncRun(isolate, context); |
| 154 if (inspector_) inspector_->asyncTaskFinished(this); |
| 155 } |
| 156 |
137 ExecuteStringTask::ExecuteStringTask( | 157 ExecuteStringTask::ExecuteStringTask( |
138 const v8::internal::Vector<uint16_t>& expression, | 158 const v8::internal::Vector<uint16_t>& expression, |
139 v8::Local<v8::String> name, v8::Local<v8::Integer> line_offset, | 159 v8::Local<v8::String> name, v8::Local<v8::Integer> line_offset, |
140 v8::Local<v8::Integer> column_offset) | 160 v8::Local<v8::Integer> column_offset, const char* task_name, |
141 : expression_(expression), | 161 v8_inspector::V8Inspector* inspector) |
| 162 : AsyncTask(task_name, inspector), |
| 163 expression_(expression), |
142 name_(ToVector(name)), | 164 name_(ToVector(name)), |
143 line_offset_(line_offset.As<v8::Int32>()->Value()), | 165 line_offset_(line_offset.As<v8::Int32>()->Value()), |
144 column_offset_(column_offset.As<v8::Int32>()->Value()) {} | 166 column_offset_(column_offset.As<v8::Int32>()->Value()) {} |
145 | 167 |
146 ExecuteStringTask::ExecuteStringTask( | 168 ExecuteStringTask::ExecuteStringTask( |
147 const v8::internal::Vector<const char>& expression) | 169 const v8::internal::Vector<const char>& expression) |
148 : expression_utf8_(expression), line_offset_(0), column_offset_(0) {} | 170 : AsyncTask(nullptr, nullptr), |
| 171 expression_utf8_(expression), |
| 172 line_offset_(0), |
| 173 column_offset_(0) {} |
149 | 174 |
150 void ExecuteStringTask::Run(v8::Isolate* isolate, | 175 void ExecuteStringTask::AsyncRun(v8::Isolate* isolate, |
151 const v8::Global<v8::Context>& context) { | 176 const v8::Global<v8::Context>& context) { |
152 v8::MicrotasksScope microtasks_scope(isolate, | 177 v8::MicrotasksScope microtasks_scope(isolate, |
153 v8::MicrotasksScope::kRunMicrotasks); | 178 v8::MicrotasksScope::kRunMicrotasks); |
154 v8::HandleScope handle_scope(isolate); | 179 v8::HandleScope handle_scope(isolate); |
155 v8::Local<v8::Context> local_context = context.Get(isolate); | 180 v8::Local<v8::Context> local_context = context.Get(isolate); |
156 v8::Context::Scope context_scope(local_context); | 181 v8::Context::Scope context_scope(local_context); |
157 | 182 |
158 v8::Local<v8::String> name = | 183 v8::Local<v8::String> name = |
159 v8::String::NewFromTwoByte(isolate, name_.start(), | 184 v8::String::NewFromTwoByte(isolate, name_.start(), |
160 v8::NewStringType::kNormal, name_.length()) | 185 v8::NewStringType::kNormal, name_.length()) |
161 .ToLocalChecked(); | 186 .ToLocalChecked(); |
(...skipping 16 matching lines...) Expand all Loading... |
178 } | 203 } |
179 | 204 |
180 v8::ScriptCompiler::Source scriptSource(source, origin); | 205 v8::ScriptCompiler::Source scriptSource(source, origin); |
181 v8::Local<v8::Script> script; | 206 v8::Local<v8::Script> script; |
182 if (!v8::ScriptCompiler::Compile(local_context, &scriptSource) | 207 if (!v8::ScriptCompiler::Compile(local_context, &scriptSource) |
183 .ToLocal(&script)) | 208 .ToLocal(&script)) |
184 return; | 209 return; |
185 v8::MaybeLocal<v8::Value> result; | 210 v8::MaybeLocal<v8::Value> result; |
186 result = script->Run(local_context); | 211 result = script->Run(local_context); |
187 } | 212 } |
OLD | NEW |