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 #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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 class UtilsExtension : public v8::Extension { | 49 class UtilsExtension : public v8::Extension { |
50 public: | 50 public: |
51 UtilsExtension() | 51 UtilsExtension() |
52 : v8::Extension("v8_inspector/utils", | 52 : v8::Extension("v8_inspector/utils", |
53 "native function print();" | 53 "native function print();" |
54 "native function quit();" | 54 "native function quit();" |
55 "native function setlocale();" | 55 "native function setlocale();" |
56 "native function load();" | 56 "native function load();" |
57 "native function compileAndRunWithOrigin();") {} | 57 "native function compileAndRunWithOrigin();" |
| 58 "native function setCurrentTimeMSForTest();") {} |
58 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( | 59 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
59 v8::Isolate* isolate, v8::Local<v8::String> name) { | 60 v8::Isolate* isolate, v8::Local<v8::String> name) { |
60 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 61 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
61 if (name->Equals(context, v8::String::NewFromUtf8( | 62 if (name->Equals(context, v8::String::NewFromUtf8( |
62 isolate, "print", v8::NewStringType::kNormal) | 63 isolate, "print", v8::NewStringType::kNormal) |
63 .ToLocalChecked()) | 64 .ToLocalChecked()) |
64 .FromJust()) { | 65 .FromJust()) { |
65 return v8::FunctionTemplate::New(isolate, UtilsExtension::Print); | 66 return v8::FunctionTemplate::New(isolate, UtilsExtension::Print); |
66 } else if (name->Equals(context, | 67 } else if (name->Equals(context, |
67 v8::String::NewFromUtf8(isolate, "quit", | 68 v8::String::NewFromUtf8(isolate, "quit", |
(...skipping 13 matching lines...) Expand all Loading... |
81 .ToLocalChecked()) | 82 .ToLocalChecked()) |
82 .FromJust()) { | 83 .FromJust()) { |
83 return v8::FunctionTemplate::New(isolate, UtilsExtension::Load); | 84 return v8::FunctionTemplate::New(isolate, UtilsExtension::Load); |
84 } else if (name->Equals(context, v8::String::NewFromUtf8( | 85 } else if (name->Equals(context, v8::String::NewFromUtf8( |
85 isolate, "compileAndRunWithOrigin", | 86 isolate, "compileAndRunWithOrigin", |
86 v8::NewStringType::kNormal) | 87 v8::NewStringType::kNormal) |
87 .ToLocalChecked()) | 88 .ToLocalChecked()) |
88 .FromJust()) { | 89 .FromJust()) { |
89 return v8::FunctionTemplate::New(isolate, | 90 return v8::FunctionTemplate::New(isolate, |
90 UtilsExtension::CompileAndRunWithOrigin); | 91 UtilsExtension::CompileAndRunWithOrigin); |
| 92 } else if (name->Equals(context, v8::String::NewFromUtf8( |
| 93 isolate, "setCurrentTimeMSForTest", |
| 94 v8::NewStringType::kNormal) |
| 95 .ToLocalChecked()) |
| 96 .FromJust()) { |
| 97 return v8::FunctionTemplate::New(isolate, |
| 98 UtilsExtension::SetCurrentTimeMSForTest); |
91 } | 99 } |
92 return v8::Local<v8::FunctionTemplate>(); | 100 return v8::Local<v8::FunctionTemplate>(); |
93 } | 101 } |
94 | 102 |
95 static void set_backend_task_runner(TaskRunner* runner) { | 103 static void set_backend_task_runner(TaskRunner* runner) { |
96 backend_runner_ = runner; | 104 backend_runner_ = runner; |
97 } | 105 } |
98 | 106 |
| 107 static void set_inspector_client(InspectorClientImpl* client) { |
| 108 inspector_client_ = client; |
| 109 } |
| 110 |
99 private: | 111 private: |
100 static TaskRunner* backend_runner_; | 112 static TaskRunner* backend_runner_; |
| 113 static InspectorClientImpl* inspector_client_; |
101 | 114 |
102 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args) { | 115 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args) { |
103 for (int i = 0; i < args.Length(); i++) { | 116 for (int i = 0; i < args.Length(); i++) { |
104 v8::HandleScope handle_scope(args.GetIsolate()); | 117 v8::HandleScope handle_scope(args.GetIsolate()); |
105 if (i != 0) { | 118 if (i != 0) { |
106 printf(" "); | 119 printf(" "); |
107 } | 120 } |
108 | 121 |
109 // Explicitly catch potential exceptions in toString(). | 122 // Explicitly catch potential exceptions in toString(). |
110 v8::TryCatch try_catch(args.GetIsolate()); | 123 v8::TryCatch try_catch(args.GetIsolate()); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 fprintf(stderr, | 186 fprintf(stderr, |
174 "Internal error: compileAndRunWithOrigin(source, name, line, " | 187 "Internal error: compileAndRunWithOrigin(source, name, line, " |
175 "column)."); | 188 "column)."); |
176 Exit(); | 189 Exit(); |
177 } | 190 } |
178 | 191 |
179 backend_runner_->Append(new ExecuteStringTask( | 192 backend_runner_->Append(new ExecuteStringTask( |
180 ToVector(args[0].As<v8::String>()), args[1].As<v8::String>(), | 193 ToVector(args[0].As<v8::String>()), args[1].As<v8::String>(), |
181 args[2].As<v8::Int32>(), args[3].As<v8::Int32>(), nullptr, nullptr)); | 194 args[2].As<v8::Int32>(), args[3].As<v8::Int32>(), nullptr, nullptr)); |
182 } | 195 } |
| 196 |
| 197 static void SetCurrentTimeMSForTest( |
| 198 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 199 if (args.Length() != 1 || !args[0]->IsNumber()) { |
| 200 fprintf(stderr, "Internal error: setCurrentTimeMSForTest(time)."); |
| 201 Exit(); |
| 202 } |
| 203 inspector_client_->setCurrentTimeMSForTest( |
| 204 args[0].As<v8::Number>()->Value()); |
| 205 } |
183 }; | 206 }; |
184 | 207 |
185 TaskRunner* UtilsExtension::backend_runner_ = nullptr; | 208 TaskRunner* UtilsExtension::backend_runner_ = nullptr; |
| 209 InspectorClientImpl* UtilsExtension::inspector_client_ = nullptr; |
186 | 210 |
187 class SetTimeoutTask : public AsyncTask { | 211 class SetTimeoutTask : public AsyncTask { |
188 public: | 212 public: |
189 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function, | 213 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function, |
190 const char* task_name, v8_inspector::V8Inspector* inspector) | 214 const char* task_name, v8_inspector::V8Inspector* inspector) |
191 : AsyncTask(task_name, inspector), function_(isolate, function) {} | 215 : AsyncTask(task_name, inspector), function_(isolate, function) {} |
192 virtual ~SetTimeoutTask() {} | 216 virtual ~SetTimeoutTask() {} |
193 | 217 |
194 bool is_inspector_task() final { return false; } | 218 bool is_inspector_task() final { return false; } |
195 | 219 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 "v8_inspector/frontend"}; | 432 "v8_inspector/frontend"}; |
409 v8::ExtensionConfiguration frontend_configuration( | 433 v8::ExtensionConfiguration frontend_configuration( |
410 arraysize(frontend_extensions), frontend_extensions); | 434 arraysize(frontend_extensions), frontend_extensions); |
411 TaskRunner frontend_runner(&frontend_configuration, true, &ready_semaphore); | 435 TaskRunner frontend_runner(&frontend_configuration, true, &ready_semaphore); |
412 ready_semaphore.Wait(); | 436 ready_semaphore.Wait(); |
413 | 437 |
414 FrontendChannelImpl frontend_channel(&frontend_runner); | 438 FrontendChannelImpl frontend_channel(&frontend_runner); |
415 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel, | 439 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel, |
416 &ready_semaphore); | 440 &ready_semaphore); |
417 ready_semaphore.Wait(); | 441 ready_semaphore.Wait(); |
| 442 UtilsExtension::set_inspector_client(&inspector_client); |
418 | 443 |
419 task_runners.push_back(&frontend_runner); | 444 task_runners.push_back(&frontend_runner); |
420 task_runners.push_back(&backend_runner); | 445 task_runners.push_back(&backend_runner); |
421 | 446 |
422 for (int i = 1; i < argc; ++i) { | 447 for (int i = 1; i < argc; ++i) { |
423 if (argv[i][0] == '-') break; | 448 if (argv[i][0] == '-') break; |
424 | 449 |
425 bool exists = false; | 450 bool exists = false; |
426 v8::internal::Vector<const char> chars = | 451 v8::internal::Vector<const char> chars = |
427 v8::internal::ReadFile(argv[i], &exists, true); | 452 v8::internal::ReadFile(argv[i], &exists, true); |
428 if (!exists) { | 453 if (!exists) { |
429 fprintf(stderr, "Internal error: script file doesn't exists: %s\n", | 454 fprintf(stderr, "Internal error: script file doesn't exists: %s\n", |
430 argv[i]); | 455 argv[i]); |
431 Exit(); | 456 Exit(); |
432 } | 457 } |
433 frontend_runner.Append(new ExecuteStringTask(chars)); | 458 frontend_runner.Append(new ExecuteStringTask(chars)); |
434 } | 459 } |
435 | 460 |
436 frontend_runner.Join(); | 461 frontend_runner.Join(); |
437 backend_runner.Join(); | 462 backend_runner.Join(); |
438 return 0; | 463 return 0; |
439 } | 464 } |
OLD | NEW |