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" | 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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) { | 26 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) { |
27 v8::internal::Vector<uint16_t> buffer = | 27 v8::internal::Vector<uint16_t> buffer = |
28 v8::internal::Vector<uint16_t>::New(str->Length()); | 28 v8::internal::Vector<uint16_t>::New(str->Length()); |
29 str->Write(buffer.start(), 0, str->Length()); | 29 str->Write(buffer.start(), 0, str->Length()); |
30 return buffer; | 30 return buffer; |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 TaskRunner::TaskRunner(v8::ExtensionConfiguration* extensions, | 35 TaskRunner::TaskRunner(TaskRunner::SetupGlobalTasks setup_global_tasks, |
36 bool catch_exceptions, | 36 bool catch_exceptions, |
37 v8::base::Semaphore* ready_semaphore) | 37 v8::base::Semaphore* ready_semaphore) |
38 : Thread(Options("Task Runner")), | 38 : Thread(Options("Task Runner")), |
39 extensions_(extensions), | 39 setup_global_tasks_(std::move(setup_global_tasks)), |
40 catch_exceptions_(catch_exceptions), | 40 catch_exceptions_(catch_exceptions), |
41 ready_semaphore_(ready_semaphore), | 41 ready_semaphore_(ready_semaphore), |
42 isolate_(nullptr), | 42 isolate_(nullptr), |
43 process_queue_semaphore_(0), | 43 process_queue_semaphore_(0), |
44 nested_loop_count_(0) { | 44 nested_loop_count_(0) { |
45 Start(); | 45 Start(); |
46 } | 46 } |
47 | 47 |
48 TaskRunner::~TaskRunner() { Join(); } | 48 TaskRunner::~TaskRunner() { Join(); } |
49 | 49 |
50 void TaskRunner::InitializeIsolate() { | 50 void TaskRunner::InitializeIsolate() { |
51 v8::Isolate::CreateParams params; | 51 v8::Isolate::CreateParams params; |
52 params.array_buffer_allocator = | 52 params.array_buffer_allocator = |
53 v8::ArrayBuffer::Allocator::NewDefaultAllocator(); | 53 v8::ArrayBuffer::Allocator::NewDefaultAllocator(); |
54 isolate_ = v8::Isolate::New(params); | 54 isolate_ = v8::Isolate::New(params); |
55 isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); | 55 isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); |
56 v8::Isolate::Scope isolate_scope(isolate_); | 56 v8::Isolate::Scope isolate_scope(isolate_); |
57 v8::HandleScope handle_scope(isolate_); | 57 v8::HandleScope handle_scope(isolate_); |
58 NewContextGroup(); | 58 NewContextGroup(setup_global_tasks_); |
59 if (ready_semaphore_) ready_semaphore_->Signal(); | 59 if (ready_semaphore_) ready_semaphore_->Signal(); |
60 } | 60 } |
61 | 61 |
62 v8::Local<v8::Context> TaskRunner::NewContextGroup() { | 62 v8::Local<v8::Context> TaskRunner::NewContextGroup( |
| 63 const TaskRunner::SetupGlobalTasks& setup_global_tasks) { |
63 v8::Local<v8::ObjectTemplate> global_template = | 64 v8::Local<v8::ObjectTemplate> global_template = |
64 v8::ObjectTemplate::New(isolate_); | 65 v8::ObjectTemplate::New(isolate_); |
| 66 for (auto it = setup_global_tasks.begin(); it != setup_global_tasks.end(); |
| 67 ++it) { |
| 68 (*it)->Run(isolate_, global_template); |
| 69 } |
65 v8::Local<v8::Context> context = | 70 v8::Local<v8::Context> context = |
66 v8::Context::New(isolate_, extensions_, global_template); | 71 v8::Context::New(isolate_, nullptr, global_template); |
67 context->SetAlignedPointerInEmbedderData(kTaskRunnerIndex, this); | 72 context->SetAlignedPointerInEmbedderData(kTaskRunnerIndex, this); |
68 intptr_t context_group_id = ++last_context_group_id_; | 73 intptr_t context_group_id = ++last_context_group_id_; |
69 // Should be 2-byte aligned. | 74 // Should be 2-byte aligned. |
70 context->SetAlignedPointerInEmbedderData( | 75 context->SetAlignedPointerInEmbedderData( |
71 kContextGroupIdIndex, reinterpret_cast<void*>(context_group_id * 2)); | 76 kContextGroupIdIndex, reinterpret_cast<void*>(context_group_id * 2)); |
72 contexts_[context_group_id].Reset(isolate_, context); | 77 contexts_[context_group_id].Reset(isolate_, context); |
73 return context; | 78 return context; |
74 } | 79 } |
75 | 80 |
76 v8::Local<v8::Context> TaskRunner::GetContext(int context_group_id) { | 81 v8::Local<v8::Context> TaskRunner::GetContext(int context_group_id) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 return; | 255 return; |
251 } | 256 } |
252 if (!module->Instantiate(local_context, &TaskRunner::ModuleResolveCallback)) | 257 if (!module->Instantiate(local_context, &TaskRunner::ModuleResolveCallback)) |
253 return; | 258 return; |
254 v8::Local<v8::Value> result; | 259 v8::Local<v8::Value> result; |
255 if (!module->Evaluate(local_context).ToLocal(&result)) return; | 260 if (!module->Evaluate(local_context).ToLocal(&result)) return; |
256 TaskRunner* runner = TaskRunner::FromContext(local_context); | 261 TaskRunner* runner = TaskRunner::FromContext(local_context); |
257 runner->RegisterModule(name_, module); | 262 runner->RegisterModule(name_, module); |
258 } | 263 } |
259 } | 264 } |
OLD | NEW |