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 authored and MylesBorins committed Apr 1, 2020
1 parent 1915b5b commit 4d3275b
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 4d3275b

Please sign in to comment.