@@ -82,12 +82,14 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) {
|
82 | 82 | } |
83 | 83 | |
84 | 84 | void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) { |
| 85 | +CHECK_NE(flush_tasks_, nullptr); |
85 | 86 | foreground_tasks_.Push(std::move(task)); |
86 | 87 | uv_async_send(flush_tasks_); |
87 | 88 | } |
88 | 89 | |
89 | 90 | void PerIsolatePlatformData::PostDelayedTask( |
90 | 91 | std::unique_ptr<Task> task, double delay_in_seconds) { |
| 92 | +CHECK_NE(flush_tasks_, nullptr); |
91 | 93 | std::unique_ptr<DelayedTask> delayed(new DelayedTask()); |
92 | 94 | delayed->task = std::move(task); |
93 | 95 | delayed->platform_data = shared_from_this(); |
@@ -97,13 +99,21 @@ void PerIsolatePlatformData::PostDelayedTask(
|
97 | 99 | } |
98 | 100 | |
99 | 101 | PerIsolatePlatformData::~PerIsolatePlatformData() { |
| 102 | +Shutdown(); |
| 103 | +} |
| 104 | + |
| 105 | +void PerIsolatePlatformData::Shutdown() { |
| 106 | +if (flush_tasks_ == nullptr) |
| 107 | +return; |
| 108 | + |
100 | 109 | while (FlushForegroundTasksInternal()) {} |
101 | 110 | CancelPendingDelayedTasks(); |
102 | 111 | |
103 | 112 | uv_close(reinterpret_cast<uv_handle_t*>(flush_tasks_), |
104 | 113 | [](uv_handle_t* handle) { |
105 | 114 | delete reinterpret_cast<uv_async_t*>(handle); |
106 | 115 | }); |
| 116 | + flush_tasks_ = nullptr; |
107 | 117 | } |
108 | 118 | |
109 | 119 | void PerIsolatePlatformData::ref() { |
@@ -144,6 +154,7 @@ void NodePlatform::UnregisterIsolate(IsolateData* isolate_data) {
|
144 | 154 | std::shared_ptr<PerIsolatePlatformData> existing = per_isolate_[isolate]; |
145 | 155 | CHECK(existing); |
146 | 156 | if (existing->unref() == 0) { |
| 157 | + existing->Shutdown(); |
147 | 158 | per_isolate_.erase(isolate); |
148 | 159 | } |
149 | 160 | } |
|