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

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

Issue 2886903003: [inspector] Pass TaskRunner instead of Context to all tasks (Closed)
Patch Set: methods visibility 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/task-runner.h ('k') | no next file » | 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 #include "test/inspector/task-runner.h" 5 #include "test/inspector/task-runner.h"
6 6
7 #include "test/inspector/inspector-impl.h" 7 #include "test/inspector/inspector-impl.h"
8 8
9 #if !defined(_WIN32) && !defined(_WIN64) 9 #if !defined(_WIN32) && !defined(_WIN64)
10 #include <unistd.h> // NOLINT 10 #include <unistd.h> // NOLINT
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 void TaskRunner::RunMessageLoop(bool only_protocol) { 100 void TaskRunner::RunMessageLoop(bool only_protocol) {
101 int loop_number = ++nested_loop_count_; 101 int loop_number = ++nested_loop_count_;
102 while (nested_loop_count_ == loop_number && !is_terminated_.Value()) { 102 while (nested_loop_count_ == loop_number && !is_terminated_.Value()) {
103 TaskRunner::Task* task = GetNext(only_protocol); 103 TaskRunner::Task* task = GetNext(only_protocol);
104 if (!task) return; 104 if (!task) return;
105 v8::Isolate::Scope isolate_scope(isolate_); 105 v8::Isolate::Scope isolate_scope(isolate_);
106 if (catch_exceptions_) { 106 if (catch_exceptions_) {
107 v8::TryCatch try_catch(isolate_); 107 v8::TryCatch try_catch(isolate_);
108 task->Run(isolate_, contexts_.begin()->second); 108 task->RunOnTaskRunner(this);
109 delete task; 109 delete task;
110 if (try_catch.HasCaught()) { 110 if (try_catch.HasCaught()) {
111 ReportUncaughtException(isolate_, try_catch); 111 ReportUncaughtException(isolate_, try_catch);
112 fflush(stdout); 112 fflush(stdout);
113 fflush(stderr); 113 fflush(stderr);
114 _exit(0); 114 _exit(0);
115 } 115 }
116 } else { 116 } else {
117 task->Run(isolate_, contexts_.begin()->second); 117 task->RunOnTaskRunner(this);
118 delete task; 118 delete task;
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 void TaskRunner::QuitMessageLoop() { 123 void TaskRunner::QuitMessageLoop() {
124 DCHECK(nested_loop_count_ > 0); 124 DCHECK(nested_loop_count_ > 0);
125 --nested_loop_count_; 125 --nested_loop_count_;
126 } 126 }
127 127
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 v8_inspector::V8Inspector* inspector) 176 v8_inspector::V8Inspector* inspector)
177 : inspector_(task_name ? inspector : nullptr) { 177 : inspector_(task_name ? inspector : nullptr) {
178 if (inspector_) { 178 if (inspector_) {
179 inspector_->asyncTaskScheduled( 179 inspector_->asyncTaskScheduled(
180 v8_inspector::StringView(reinterpret_cast<const uint8_t*>(task_name), 180 v8_inspector::StringView(reinterpret_cast<const uint8_t*>(task_name),
181 strlen(task_name)), 181 strlen(task_name)),
182 this, false); 182 this, false);
183 } 183 }
184 } 184 }
185 185
186 void AsyncTask::Run(v8::Isolate* isolate, 186 void AsyncTask::Run() {
187 const v8::Global<v8::Context>& context) {
188 if (inspector_) inspector_->asyncTaskStarted(this); 187 if (inspector_) inspector_->asyncTaskStarted(this);
189 AsyncRun(isolate, context); 188 AsyncRun();
190 if (inspector_) inspector_->asyncTaskFinished(this); 189 if (inspector_) inspector_->asyncTaskFinished(this);
191 } 190 }
192 191
193 ExecuteStringTask::ExecuteStringTask( 192 ExecuteStringTask::ExecuteStringTask(
194 const v8::internal::Vector<uint16_t>& expression, 193 const v8::internal::Vector<uint16_t>& expression,
195 v8::Local<v8::String> name, v8::Local<v8::Integer> line_offset, 194 v8::Local<v8::String> name, v8::Local<v8::Integer> line_offset,
196 v8::Local<v8::Integer> column_offset, v8::Local<v8::Boolean> is_module, 195 v8::Local<v8::Integer> column_offset, v8::Local<v8::Boolean> is_module,
197 const char* task_name, v8_inspector::V8Inspector* inspector) 196 const char* task_name, v8_inspector::V8Inspector* inspector)
198 : AsyncTask(task_name, inspector), 197 : AsyncTask(task_name, inspector),
199 expression_(expression), 198 expression_(expression),
200 name_(ToVector(name)), 199 name_(ToVector(name)),
201 line_offset_(line_offset.As<v8::Int32>()->Value()), 200 line_offset_(line_offset.As<v8::Int32>()->Value()),
202 column_offset_(column_offset.As<v8::Int32>()->Value()), 201 column_offset_(column_offset.As<v8::Int32>()->Value()),
203 is_module_(is_module->Value()) {} 202 is_module_(is_module->Value()) {}
204 203
205 ExecuteStringTask::ExecuteStringTask( 204 ExecuteStringTask::ExecuteStringTask(
206 const v8::internal::Vector<const char>& expression) 205 const v8::internal::Vector<const char>& expression)
207 : AsyncTask(nullptr, nullptr), expression_utf8_(expression) {} 206 : AsyncTask(nullptr, nullptr), expression_utf8_(expression) {}
208 207
209 void ExecuteStringTask::AsyncRun(v8::Isolate* isolate, 208 void ExecuteStringTask::AsyncRun() {
210 const v8::Global<v8::Context>& context) { 209 v8::MicrotasksScope microtasks_scope(isolate(),
211 v8::MicrotasksScope microtasks_scope(isolate,
212 v8::MicrotasksScope::kRunMicrotasks); 210 v8::MicrotasksScope::kRunMicrotasks);
213 v8::HandleScope handle_scope(isolate); 211 v8::HandleScope handle_scope(isolate());
214 v8::Local<v8::Context> local_context = context.Get(isolate); 212 v8::Local<v8::Context> context = default_context();
215 v8::Context::Scope context_scope(local_context); 213 v8::Context::Scope context_scope(context);
216 214
217 v8::Local<v8::String> name = 215 v8::Local<v8::String> name =
218 v8::String::NewFromTwoByte(isolate, name_.start(), 216 v8::String::NewFromTwoByte(isolate(), name_.start(),
219 v8::NewStringType::kNormal, name_.length()) 217 v8::NewStringType::kNormal, name_.length())
220 .ToLocalChecked(); 218 .ToLocalChecked();
221 v8::Local<v8::Integer> line_offset = v8::Integer::New(isolate, line_offset_); 219 v8::Local<v8::Integer> line_offset =
220 v8::Integer::New(isolate(), line_offset_);
222 v8::Local<v8::Integer> column_offset = 221 v8::Local<v8::Integer> column_offset =
223 v8::Integer::New(isolate, column_offset_); 222 v8::Integer::New(isolate(), column_offset_);
224 223
225 v8::ScriptOrigin origin( 224 v8::ScriptOrigin origin(
226 name, line_offset, column_offset, 225 name, line_offset, column_offset,
227 /* resource_is_shared_cross_origin */ v8::Local<v8::Boolean>(), 226 /* resource_is_shared_cross_origin */ v8::Local<v8::Boolean>(),
228 /* script_id */ v8::Local<v8::Integer>(), 227 /* script_id */ v8::Local<v8::Integer>(),
229 /* source_map_url */ v8::Local<v8::Value>(), 228 /* source_map_url */ v8::Local<v8::Value>(),
230 /* resource_is_opaque */ v8::Local<v8::Boolean>(), 229 /* resource_is_opaque */ v8::Local<v8::Boolean>(),
231 /* is_wasm */ v8::Local<v8::Boolean>(), 230 /* is_wasm */ v8::Local<v8::Boolean>(),
232 v8::Boolean::New(isolate, is_module_)); 231 v8::Boolean::New(isolate(), is_module_));
233 v8::Local<v8::String> source; 232 v8::Local<v8::String> source;
234 if (expression_.length()) { 233 if (expression_.length()) {
235 source = v8::String::NewFromTwoByte(isolate, expression_.start(), 234 source = v8::String::NewFromTwoByte(isolate(), expression_.start(),
236 v8::NewStringType::kNormal, 235 v8::NewStringType::kNormal,
237 expression_.length()) 236 expression_.length())
238 .ToLocalChecked(); 237 .ToLocalChecked();
239 } else { 238 } else {
240 source = v8::String::NewFromUtf8(isolate, expression_utf8_.start(), 239 source = v8::String::NewFromUtf8(isolate(), expression_utf8_.start(),
241 v8::NewStringType::kNormal, 240 v8::NewStringType::kNormal,
242 expression_utf8_.length()) 241 expression_utf8_.length())
243 .ToLocalChecked(); 242 .ToLocalChecked();
244 } 243 }
245 244
246 v8::ScriptCompiler::Source scriptSource(source, origin); 245 v8::ScriptCompiler::Source scriptSource(source, origin);
247 if (!is_module_) { 246 if (!is_module_) {
248 v8::Local<v8::Script> script; 247 v8::Local<v8::Script> script;
249 if (!v8::ScriptCompiler::Compile(local_context, &scriptSource) 248 if (!v8::ScriptCompiler::Compile(context, &scriptSource).ToLocal(&script))
250 .ToLocal(&script))
251 return; 249 return;
252 v8::MaybeLocal<v8::Value> result; 250 v8::MaybeLocal<v8::Value> result;
253 result = script->Run(local_context); 251 result = script->Run(context);
254 } else { 252 } else {
255 v8::Local<v8::Module> module; 253 v8::Local<v8::Module> module;
256 if (!v8::ScriptCompiler::CompileModule(isolate, &scriptSource) 254 if (!v8::ScriptCompiler::CompileModule(isolate(), &scriptSource)
257 .ToLocal(&module)) { 255 .ToLocal(&module)) {
258 return; 256 return;
259 } 257 }
260 if (!module->Instantiate(local_context, &TaskRunner::ModuleResolveCallback)) 258 if (!module->Instantiate(context, &TaskRunner::ModuleResolveCallback))
261 return; 259 return;
262 v8::Local<v8::Value> result; 260 v8::Local<v8::Value> result;
263 if (!module->Evaluate(local_context).ToLocal(&result)) return; 261 if (!module->Evaluate(context).ToLocal(&result)) return;
264 TaskRunner* runner = TaskRunner::FromContext(local_context); 262 TaskRunner* runner = TaskRunner::FromContext(context);
265 runner->RegisterModule(name_, module); 263 runner->RegisterModule(name_, module);
266 } 264 }
267 } 265 }
OLDNEW
« no previous file with comments | « test/inspector/task-runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698