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

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

Issue 2574803002: [inspector] add async instrumentation for setTimeout in tests (Closed)
Patch Set: addressed comments Created 4 years 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/debugger/async-set-timeout-expected.txt ('k') | test/inspector/protocol-test.js » ('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 #if !defined(_WIN32) && !defined(_WIN64) 5 #if !defined(_WIN32) && !defined(_WIN64)
6 #include <unistd.h> // NOLINT 6 #include <unistd.h> // NOLINT
7 #endif // !defined(_WIN32) && !defined(_WIN64) 7 #endif // !defined(_WIN32) && !defined(_WIN64)
8 8
9 #include <locale.h> 9 #include <locale.h>
10 10
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString() || 170 if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString() ||
171 !args[2]->IsInt32() || !args[3]->IsInt32()) { 171 !args[2]->IsInt32() || !args[3]->IsInt32()) {
172 fprintf(stderr, 172 fprintf(stderr,
173 "Internal error: compileAndRunWithOrigin(source, name, line, " 173 "Internal error: compileAndRunWithOrigin(source, name, line, "
174 "column)."); 174 "column).");
175 Exit(); 175 Exit();
176 } 176 }
177 177
178 backend_runner_->Append(new ExecuteStringTask( 178 backend_runner_->Append(new ExecuteStringTask(
179 ToVector(args[0].As<v8::String>()), args[1].As<v8::String>(), 179 ToVector(args[0].As<v8::String>()), args[1].As<v8::String>(),
180 args[2].As<v8::Int32>(), args[3].As<v8::Int32>())); 180 args[2].As<v8::Int32>(), args[3].As<v8::Int32>(), nullptr, nullptr));
181 } 181 }
182 }; 182 };
183 183
184 TaskRunner* UtilsExtension::backend_runner_ = nullptr; 184 TaskRunner* UtilsExtension::backend_runner_ = nullptr;
185 185
186 class SetTimeoutTask : public TaskRunner::Task { 186 class SetTimeoutTask : public AsyncTask {
187 public: 187 public:
188 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function) 188 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function,
189 : function_(isolate, function) {} 189 const char* task_name, v8_inspector::V8Inspector* inspector)
190 : AsyncTask(task_name, inspector), function_(isolate, function) {}
190 virtual ~SetTimeoutTask() {} 191 virtual ~SetTimeoutTask() {}
191 192
192 bool is_inspector_task() final { return false; } 193 bool is_inspector_task() final { return false; }
193 194
194 void Run(v8::Isolate* isolate, 195 void AsyncRun(v8::Isolate* isolate,
195 const v8::Global<v8::Context>& global_context) override { 196 const v8::Global<v8::Context>& global_context) override {
196 v8::MicrotasksScope microtasks_scope(isolate, 197 v8::MicrotasksScope microtasks_scope(isolate,
197 v8::MicrotasksScope::kRunMicrotasks); 198 v8::MicrotasksScope::kRunMicrotasks);
198 v8::HandleScope handle_scope(isolate); 199 v8::HandleScope handle_scope(isolate);
199 v8::Local<v8::Context> context = global_context.Get(isolate); 200 v8::Local<v8::Context> context = global_context.Get(isolate);
200 v8::Context::Scope context_scope(context); 201 v8::Context::Scope context_scope(context);
201 202
202 v8::Local<v8::Function> function = function_.Get(isolate); 203 v8::Local<v8::Function> function = function_.Get(isolate);
203 v8::MaybeLocal<v8::Value> result; 204 v8::MaybeLocal<v8::Value> result;
204 v8_inspector::V8Inspector* inspector = 205 v8_inspector::V8Inspector* inspector =
205 InspectorClientImpl::InspectorFromContext(context); 206 InspectorClientImpl::InspectorFromContext(context);
(...skipping 21 matching lines...) Expand all
227 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { 228 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) {
228 if (args.Length() != 2 || !args[1]->IsNumber() || 229 if (args.Length() != 2 || !args[1]->IsNumber() ||
229 (!args[0]->IsFunction() && !args[0]->IsString()) || 230 (!args[0]->IsFunction() && !args[0]->IsString()) ||
230 args[1].As<v8::Number>()->Value() != 0.0) { 231 args[1].As<v8::Number>()->Value() != 0.0) {
231 fprintf(stderr, 232 fprintf(stderr,
232 "Internal error: only setTimeout(function, 0) is supported."); 233 "Internal error: only setTimeout(function, 0) is supported.");
233 Exit(); 234 Exit();
234 } 235 }
235 v8::Isolate* isolate = args.GetIsolate(); 236 v8::Isolate* isolate = args.GetIsolate();
236 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 237 v8::Local<v8::Context> context = isolate->GetCurrentContext();
238 std::unique_ptr<TaskRunner::Task> task;
239 v8_inspector::V8Inspector* inspector =
240 InspectorClientImpl::InspectorFromContext(context);
237 if (args[0]->IsFunction()) { 241 if (args[0]->IsFunction()) {
238 TaskRunner::FromContext(context)->Append( 242 task.reset(new SetTimeoutTask(isolate,
239 new SetTimeoutTask(isolate, v8::Local<v8::Function>::Cast(args[0]))); 243 v8::Local<v8::Function>::Cast(args[0]),
244 "setTimeout", inspector));
240 } else { 245 } else {
241 TaskRunner::FromContext(context)->Append(new ExecuteStringTask( 246 task.reset(new ExecuteStringTask(
242 ToVector(args[0].As<v8::String>()), v8::String::Empty(isolate), 247 ToVector(args[0].As<v8::String>()), v8::String::Empty(isolate),
243 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0))); 248 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0),
249 "setTimeout", inspector));
244 } 250 }
251 TaskRunner::FromContext(context)->Append(task.release());
245 } 252 }
246 }; 253 };
247 254
248 class InspectorExtension : public v8::Extension { 255 class InspectorExtension : public v8::Extension {
249 public: 256 public:
250 InspectorExtension() 257 InspectorExtension()
251 : v8::Extension("v8_inspector/inspector", 258 : v8::Extension("v8_inspector/inspector",
252 "native function attachInspector();" 259 "native function attachInspector();"
253 "native function detachInspector();") {} 260 "native function detachInspector();") {}
254 261
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 v8::NewStringType::kInternalized) 334 v8::NewStringType::kInternalized)
328 .ToLocalChecked(); 335 .ToLocalChecked();
329 v8::Local<v8::String> message_string = ToString(isolate, message); 336 v8::Local<v8::String> message_string = ToString(isolate, message);
330 v8::Local<v8::String> suffix = 337 v8::Local<v8::String> suffix =
331 v8::String::NewFromUtf8(isolate, ")", v8::NewStringType::kInternalized) 338 v8::String::NewFromUtf8(isolate, ")", v8::NewStringType::kInternalized)
332 .ToLocalChecked(); 339 .ToLocalChecked();
333 340
334 v8::Local<v8::String> result = v8::String::Concat(prefix, message_string); 341 v8::Local<v8::String> result = v8::String::Concat(prefix, message_string);
335 result = v8::String::Concat(result, suffix); 342 result = v8::String::Concat(result, suffix);
336 343
337 frontend_task_runner_->Append(new ExecuteStringTask( 344 frontend_task_runner_->Append(
338 ToVector(result), v8::String::Empty(isolate), 345 new ExecuteStringTask(ToVector(result), v8::String::Empty(isolate),
339 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0))); 346 v8::Integer::New(isolate, 0),
347 v8::Integer::New(isolate, 0), nullptr, nullptr));
340 } 348 }
341 349
342 private: 350 private:
343 TaskRunner* frontend_task_runner_; 351 TaskRunner* frontend_task_runner_;
344 }; 352 };
345 353
346 } // namespace 354 } // namespace
347 355
348 int main(int argc, char* argv[]) { 356 int main(int argc, char* argv[]) {
349 v8::V8::InitializeICUDefaultLocation(argv[0]); 357 v8::V8::InitializeICUDefaultLocation(argv[0]);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 argv[i]); 407 argv[i]);
400 Exit(); 408 Exit();
401 } 409 }
402 frontend_runner.Append(new ExecuteStringTask(chars)); 410 frontend_runner.Append(new ExecuteStringTask(chars));
403 } 411 }
404 412
405 frontend_runner.Join(); 413 frontend_runner.Join();
406 backend_runner.Join(); 414 backend_runner.Join();
407 return 0; 415 return 0;
408 } 416 }
OLDNEW
« no previous file with comments | « test/inspector/debugger/async-set-timeout-expected.txt ('k') | test/inspector/protocol-test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698