File tree Expand file tree Collapse file tree 1 file changed +20
-7
lines changed
Expand file tree Collapse file tree 1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -290,13 +290,26 @@ void Environment::RunAndClearNativeImmediates() {
290290 size_t ref_count = 0 ;
291291 std::vector<NativeImmediateCallback> list;
292292 native_immediate_callbacks_.swap (list);
293- for (const auto & cb : list) {
294- cb.cb_ (this , cb.data_ );
295- if (cb.keep_alive_ )
296- cb.keep_alive_ ->Reset ();
297- if (cb.refed_ )
298- ref_count++;
299- }
293+ auto drain_list = [&]() {
294+ v8::TryCatch try_catch (isolate ());
295+ for (auto it = list.begin (); it != list.end (); ++it) {
296+ it->cb_ (this , it->data_ );
297+ if (it->keep_alive_ )
298+ it->keep_alive_ ->Reset ();
299+ if (it->refed_ )
300+ ref_count++;
301+ if (UNLIKELY (try_catch.HasCaught ())) {
302+ FatalException (isolate (), try_catch);
303+ // Bail out, remove the already executed callbacks from list
304+ // and set up a new TryCatch for the other pending callbacks.
305+ std::move_backward (it, list.end (), list.begin () + (list.end () - it));
306+ list.resize (list.end () - it);
307+ return true ;
308+ }
309+ }
310+ return false ;
311+ };
312+ while (drain_list ()) {}
300313
301314#ifdef DEBUG
302315 CHECK_GE (immediate_info ()->count (), count);
You can’t perform that action at this time.
0 commit comments