mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 06:08:50 +02:00
src: fix error message in async_hooks constructor
There are two minor issues in the AsyncHook constructor, if the object passed in has an after and/or destroy property that are not functions the errors thrown will still be: TypeError [ERR_ASYNC_CALLBACK]: before must be a function This commit updates the code and adds a unit test. PR-URL: https://github.com/nodejs/node/pull/19000 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
This commit is contained in:
parent
a27e6d7321
commit
f2defcac4d
2 changed files with 28 additions and 5 deletions
|
@ -41,15 +41,15 @@ const {
|
|||
class AsyncHook {
|
||||
constructor({ init, before, after, destroy, promiseResolve }) {
|
||||
if (init !== undefined && typeof init !== 'function')
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'init');
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.init');
|
||||
if (before !== undefined && typeof before !== 'function')
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'before');
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.before');
|
||||
if (after !== undefined && typeof after !== 'function')
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'before');
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.after');
|
||||
if (destroy !== undefined && typeof destroy !== 'function')
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'before');
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.destroy');
|
||||
if (promiseResolve !== undefined && typeof promiseResolve !== 'function')
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'promiseResolve');
|
||||
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.promiseResolve');
|
||||
|
||||
this[init_symbol] = init;
|
||||
this[before_symbol] = before;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue