lib: refactor to use validate function

Throwing error after checking type is repeated. So replace
it with validate function.

PR-URL: https://github.com/nodejs/node/pull/46101
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
Deokjin Kim 2023-01-14 18:52:26 +09:00 committed by GitHub
parent d7d9811407
commit be93b7a582
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 21 deletions

View file

@ -18,7 +18,6 @@ const {
const {
ERR_ASYNC_CALLBACK,
ERR_ASYNC_TYPE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ASYNC_ID
} = require('internal/errors').codes;
const { kEmptyObject } = require('internal/util');
@ -280,10 +279,8 @@ class AsyncLocalStorage {
validateObject(options, 'options');
const { onPropagate = null } = options;
if (onPropagate !== null && typeof onPropagate !== 'function') {
throw new ERR_INVALID_ARG_TYPE('options.onPropagate',
'function',
onPropagate);
if (onPropagate !== null) {
validateFunction(onPropagate, 'options.onPropagate');
}
this.kResourceStore = Symbol('kResourceStore');