lib: extract validateString validator

Pulls out a common argument validator to `internal/validators`

PR-URL: https://github.com/nodejs/node/pull/22101
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Jon Moss 2018-08-02 18:51:02 -04:00
parent 080316b32a
commit e570ae79f5
17 changed files with 52 additions and 85 deletions

View file

@ -2,9 +2,9 @@
const {
ERR_ASYNC_CALLBACK,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ASYNC_ID
} = require('internal/errors').codes;
const { validateString } = require('internal/validators');
const internal_async_hooks = require('internal/async_hooks');
// Get functions
@ -140,8 +140,7 @@ function showEmitBeforeAfterWarning() {
class AsyncResource {
constructor(type, opts = {}) {
if (typeof type !== 'string')
throw new ERR_INVALID_ARG_TYPE('type', 'string', type);
validateString(type, 'type');
if (typeof opts === 'number') {
opts = { triggerAsyncId: opts, requireManualDestroy: false };