summaryrefslogtreecommitdiff
path: root/src/env.cc
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2018-01-26 10:53:14 -0800
committerJames M Snell <jasnell@gmail.com>2018-02-05 20:30:45 -0800
commitdf3402995cfdb40da8f997b2f7c627aef41474a2 (patch)
tree01bd1b905cf69e0245d31d330ce8884f2b343013 /src/env.cc
parentd379db31fda166b61dc6e0dfbca57576d578fbb3 (diff)
downloadnode-new-df3402995cfdb40da8f997b2f7c627aef41474a2.tar.gz
src: handle exceptions in env->SetImmediates
PR-URL: https://github.com/nodejs/node/pull/18297 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r--src/env.cc27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/env.cc b/src/env.cc
index b05f0bec81..2b8ad7248a 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -290,13 +290,26 @@ void Environment::RunAndClearNativeImmediates() {
size_t ref_count = 0;
std::vector<NativeImmediateCallback> list;
native_immediate_callbacks_.swap(list);
- for (const auto& cb : list) {
- cb.cb_(this, cb.data_);
- if (cb.keep_alive_)
- cb.keep_alive_->Reset();
- if (cb.refed_)
- ref_count++;
- }
+ auto drain_list = [&]() {
+ v8::TryCatch try_catch(isolate());
+ for (auto it = list.begin(); it != list.end(); ++it) {
+ it->cb_(this, it->data_);
+ if (it->keep_alive_)
+ it->keep_alive_->Reset();
+ if (it->refed_)
+ ref_count++;
+ if (UNLIKELY(try_catch.HasCaught())) {
+ FatalException(isolate(), try_catch);
+ // Bail out, remove the already executed callbacks from list
+ // and set up a new TryCatch for the other pending callbacks.
+ std::move_backward(it, list.end(), list.begin() + (list.end() - it));
+ list.resize(list.end() - it);
+ return true;
+ }
+ }
+ return false;
+ };
+ while (drain_list()) {}
#ifdef DEBUG
CHECK_GE(immediate_info()->count(), count);