| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -296,13 +296,26 @@ void Environment::RunAndClearNativeImmediates() { | |||
| 296 | 296 | size_t ref_count = 0; | |
| 297 | 297 | std::vector<NativeImmediateCallback> list; | |
| 298 | 298 | native_immediate_callbacks_.swap(list); | |
| 299 | - for (const auto& cb : list) { | ||
| 300 | - cb.cb_(this, cb.data_); | ||
| 301 | - if (cb.keep_alive_) | ||
| 302 | - cb.keep_alive_->Reset(); | ||
| 303 | - if (cb.refed_) | ||
| 304 | - ref_count++; | ||
| 305 | - } | ||
| 299 | + auto drain_list = [&]() { | ||
| 300 | + v8::TryCatch try_catch(isolate()); | ||
| 301 | + for (auto it = list.begin(); it != list.end(); ++it) { | ||
| 302 | + it->cb_(this, it->data_); | ||
| 303 | + if (it->keep_alive_) | ||
| 304 | + it->keep_alive_->Reset(); | ||
| 305 | + if (it->refed_) | ||
| 306 | + ref_count++; | ||
| 307 | + if (UNLIKELY(try_catch.HasCaught())) { | ||
| 308 | + FatalException(isolate(), try_catch); | ||
| 309 | + // Bail out, remove the already executed callbacks from list | ||
| 310 | + // and set up a new TryCatch for the other pending callbacks. | ||
| 311 | + std::move_backward(it, list.end(), list.begin() + (list.end() - it)); | ||
| 312 | + list.resize(list.end() - it); | ||
| 313 | + return true; | ||
| 314 | + } | ||
| 315 | + } | ||
| 316 | + return false; | ||
| 317 | + }; | ||
| 318 | + while (drain_list()) {} | ||
| 306 | 319 | ||
| 307 | 320 | #ifdef DEBUG | |
| 308 | 321 | CHECK_GE(immediate_info()->count(), count); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments