| 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 #if !defined(_WIN32) && !defined(_WIN64) | 7 #if !defined(_WIN32) && !defined(_WIN64) |
| 8 #include <unistd.h> // NOLINT | 8 #include <unistd.h> // NOLINT |
| 9 #endif // !defined(_WIN32) && !defined(_WIN64) | 9 #endif // !defined(_WIN32) && !defined(_WIN64) |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const int kTaskRunnerIndex = 2; | 13 const int kTaskRunnerIndex = 2; |
| 14 | 14 |
| 15 void ReportUncaughtException(v8::Isolate* isolate, | 15 void ReportUncaughtException(v8::Isolate* isolate, |
| 16 const v8::TryCatch& try_catch) { | 16 const v8::TryCatch& try_catch) { |
| 17 CHECK(try_catch.HasCaught()); | 17 CHECK(try_catch.HasCaught()); |
| 18 v8::HandleScope handle_scope(isolate); | 18 v8::HandleScope handle_scope(isolate); |
| 19 std::string message = *v8::String::Utf8Value(try_catch.Message()->Get()); | 19 std::string message = *v8::String::Utf8Value(try_catch.Message()->Get()); |
| 20 fprintf(stderr, "Unhandle exception: %s\n", message.data()); | 20 fprintf(stderr, "Unhandle exception: %s\n", message.data()); |
| 21 } | 21 } |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 TaskRunner::TaskRunner(v8::ExtensionConfiguration* extensions, | 25 TaskRunner::TaskRunner(v8::ExtensionConfiguration* extensions, |
| 26 bool catch_exceptions, |
| 26 v8::base::Semaphore* ready_semaphore) | 27 v8::base::Semaphore* ready_semaphore) |
| 27 : Thread(Options("Task Runner")), | 28 : Thread(Options("Task Runner")), |
| 28 extensions_(extensions), | 29 extensions_(extensions), |
| 30 catch_exceptions_(catch_exceptions), |
| 29 ready_semaphore_(ready_semaphore), | 31 ready_semaphore_(ready_semaphore), |
| 30 isolate_(nullptr), | 32 isolate_(nullptr), |
| 31 process_queue_semaphore_(0), | 33 process_queue_semaphore_(0), |
| 32 nested_loop_count_(0) { | 34 nested_loop_count_(0) { |
| 33 Start(); | 35 Start(); |
| 34 } | 36 } |
| 35 | 37 |
| 36 TaskRunner::~TaskRunner() { Join(); } | 38 TaskRunner::~TaskRunner() { Join(); } |
| 37 | 39 |
| 38 void TaskRunner::InitializeContext() { | 40 void TaskRunner::InitializeContext() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 void TaskRunner::Run() { | 59 void TaskRunner::Run() { |
| 58 InitializeContext(); | 60 InitializeContext(); |
| 59 RunMessageLoop(false); | 61 RunMessageLoop(false); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void TaskRunner::RunMessageLoop(bool only_protocol) { | 64 void TaskRunner::RunMessageLoop(bool only_protocol) { |
| 63 int loop_number = ++nested_loop_count_; | 65 int loop_number = ++nested_loop_count_; |
| 64 while (nested_loop_count_ == loop_number) { | 66 while (nested_loop_count_ == loop_number) { |
| 65 TaskRunner::Task* task = GetNext(only_protocol); | 67 TaskRunner::Task* task = GetNext(only_protocol); |
| 66 v8::Isolate::Scope isolate_scope(isolate_); | 68 v8::Isolate::Scope isolate_scope(isolate_); |
| 67 v8::TryCatch try_catch(isolate_); | 69 if (catch_exceptions_) { |
| 68 task->Run(isolate_, context_); | 70 v8::TryCatch try_catch(isolate_); |
| 69 delete task; | 71 task->Run(isolate_, context_); |
| 70 if (try_catch.HasCaught()) { | 72 delete task; |
| 71 ReportUncaughtException(isolate_, try_catch); | 73 if (try_catch.HasCaught()) { |
| 72 fflush(stdout); | 74 ReportUncaughtException(isolate_, try_catch); |
| 73 fflush(stderr); | 75 fflush(stdout); |
| 74 _exit(0); | 76 fflush(stderr); |
| 77 _exit(0); |
| 78 } |
| 79 } else { |
| 80 task->Run(isolate_, context_); |
| 81 delete task; |
| 75 } | 82 } |
| 76 } | 83 } |
| 77 } | 84 } |
| 78 | 85 |
| 79 void TaskRunner::QuitMessageLoop() { | 86 void TaskRunner::QuitMessageLoop() { |
| 80 DCHECK(nested_loop_count_ > 0); | 87 DCHECK(nested_loop_count_ > 0); |
| 81 --nested_loop_count_; | 88 --nested_loop_count_; |
| 82 } | 89 } |
| 83 | 90 |
| 84 void TaskRunner::Append(Task* task) { | 91 void TaskRunner::Append(Task* task) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 .ToLocalChecked(); | 136 .ToLocalChecked(); |
| 130 | 137 |
| 131 v8::ScriptCompiler::Source scriptSource(source, origin); | 138 v8::ScriptCompiler::Source scriptSource(source, origin); |
| 132 v8::Local<v8::Script> script; | 139 v8::Local<v8::Script> script; |
| 133 if (!v8::ScriptCompiler::Compile(local_context, &scriptSource) | 140 if (!v8::ScriptCompiler::Compile(local_context, &scriptSource) |
| 134 .ToLocal(&script)) | 141 .ToLocal(&script)) |
| 135 return; | 142 return; |
| 136 v8::MaybeLocal<v8::Value> result; | 143 v8::MaybeLocal<v8::Value> result; |
| 137 result = script->Run(local_context); | 144 result = script->Run(local_context); |
| 138 } | 145 } |
| OLD | NEW |