Skip to content

Commit

Permalink
src: harden running native SetImmediate()s slightly
Browse files Browse the repository at this point in the history
Prevent mistakes like the one fixed by the previous commit
by destroying the callback immediately after it has been called.

PR-URL: nodejs#31468
Refs: nodejs#31386
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
addaleax committed Jan 23, 2020
1 parent 1046816 commit 31b31a3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
if (head->is_refed() || !only_refed)
head->Call(this);

head.reset(); // Destroy now so that this is also observed by try_catch.

if (UNLIKELY(try_catch.HasCaught())) {
if (!try_catch.HasTerminated() && can_call_into_js())
errors::TriggerUncaughtException(isolate(), try_catch);
Expand Down

0 comments on commit 31b31a3

Please sign in to comment.