async_hooks: ensure event after been emitted on runInAsyncScope

The exception handler user-defined will not automatically emit after
for the async resource.

Also removes a duplicated case
`test-emit-after-uncaught-exception-runInAsyncScope.js`
which is identical to test-emit-after-uncaught-exception.js.

Refs: https://github.com/nodejs/node/pull/30965
PR-URL: https://github.com/nodejs/node/pull/31784
Fixes: https://github.com/nodejs/node/issues/31783
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
legendecas 2020-02-14 11:30:33 +08:00 committed by Anna Henningsen
parent df1592d2e9
commit 75311dbc2f
No known key found for this signature in database
GPG key ID: 9C63F3A6CD2AD8F9
3 changed files with 19 additions and 45 deletions

View file

@ -22,6 +22,7 @@ const {
executionAsyncId,
triggerAsyncId,
// Private API
hasAsyncIdStack,
getHookArrays,
enableHooks,
disableHooks,
@ -179,12 +180,16 @@ class AsyncResource {
const asyncId = this[async_id_symbol];
emitBefore(asyncId, this[trigger_async_id_symbol], this);
const ret = thisArg === undefined ?
fn(...args) :
ReflectApply(fn, thisArg, args);
try {
const ret = thisArg === undefined ?
fn(...args) :
ReflectApply(fn, thisArg, args);
emitAfter(asyncId);
return ret;
return ret;
} finally {
if (hasAsyncIdStack())
emitAfter(asyncId);
}
}
emitDestroy() {