mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 12:03:30 +00:00

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>
24 lines
627 B
JavaScript
24 lines
627 B
JavaScript
'use strict';
|
|
|
|
// This tests that AsyncHooks throws an error if bad parameters are passed.
|
|
|
|
const common = require('../common');
|
|
const async_hooks = require('async_hooks');
|
|
const non_function = 10;
|
|
|
|
typeErrorForFunction('init');
|
|
typeErrorForFunction('before');
|
|
typeErrorForFunction('after');
|
|
typeErrorForFunction('destroy');
|
|
typeErrorForFunction('promiseResolve');
|
|
|
|
function typeErrorForFunction(functionName) {
|
|
common.expectsError(() => {
|
|
async_hooks.createHook({ [functionName]: non_function });
|
|
}, {
|
|
code: 'ERR_ASYNC_CALLBACK',
|
|
type: TypeError,
|
|
message: `hook.${functionName} must be a function`
|
|
});
|
|
}
|