trace_events: refactor to use validateStringArray

`options.categories` is string[]. So used `validateStringArray`

Refs: https://nodejs.org/dist/latest-v19.x/docs/api/tracing.html#trace_eventscreatetracingoptions
PR-URL: https://github.com/nodejs/node/pull/46012
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Deokjin Kim 2023-01-19 18:08:38 +09:00 committed by GitHub
parent 94199c8ab6
commit 8a74477ddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
'use strict';
const {
ArrayIsArray,
ArrayPrototypeJoin,
SafeSet,
Symbol,
@ -17,7 +16,6 @@ const kMaxTracingCount = 10;
const {
ERR_TRACE_EVENTS_CATEGORY_REQUIRED,
ERR_TRACE_EVENTS_UNAVAILABLE,
ERR_INVALID_ARG_TYPE
} = require('internal/errors').codes;
const { ownsProcessState } = require('internal/worker');
@ -29,6 +27,7 @@ const { customInspectSymbol } = require('internal/util');
const { format } = require('internal/util/inspect');
const {
validateObject,
validateStringArray,
} = require('internal/validators');
const enabledTracingObjects = new SafeSet();
@ -84,11 +83,7 @@ class Tracing {
function createTracing(options) {
validateObject(options, 'options');
if (!ArrayIsArray(options.categories)) {
throw new ERR_INVALID_ARG_TYPE('options.categories', 'string[]',
options.categories);
}
validateStringArray(options.categories, 'options.categories');
if (options.categories.length <= 0)
throw new ERR_TRACE_EVENTS_CATEGORY_REQUIRED();