summaryrefslogtreecommitdiff
path: root/lib/events.js
diff options
context:
space:
mode:
authorRongjian Zhang <pd4d10@gmail.com>2021-05-16 19:22:48 +0800
committerJames M Snell <jasnell@gmail.com>2021-05-19 09:22:56 -0700
commit5d7b6c249740824035aa779bceb20b738ae587fd (patch)
tree66e42bb88b48e169e6d5af52be07a929079b184a /lib/events.js
parent2eeb4e1d944b4ebebcf80261d9250bc86eadc89a (diff)
downloadnode-new-5d7b6c249740824035aa779bceb20b738ae587fd.tar.gz
lib: refactor to reuse validators
PR-URL: https://github.com/nodejs/node/pull/38608 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/events.js')
-rw-r--r--lib/events.js11
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/events.js b/lib/events.js
index 7d219606a2..72fc867da4 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -62,6 +62,7 @@ const {
const {
validateAbortSignal,
+ validateBoolean,
validateFunction,
} = require('internal/validators');
@@ -89,10 +90,7 @@ ObjectDefineProperty(EventEmitter, 'captureRejections', {
return EventEmitter.prototype[kCapture];
},
set(value) {
- if (typeof value !== 'boolean') {
- throw new ERR_INVALID_ARG_TYPE('EventEmitter.captureRejections',
- 'boolean', value);
- }
+ validateBoolean(value, 'EventEmitter.captureRejections');
EventEmitter.prototype[kCapture] = value;
},
@@ -190,10 +188,7 @@ EventEmitter.init = function(opts) {
if (opts?.captureRejections) {
- if (typeof opts.captureRejections !== 'boolean') {
- throw new ERR_INVALID_ARG_TYPE('options.captureRejections',
- 'boolean', opts.captureRejections);
- }
+ validateBoolean(opts.captureRejections, 'options.captureRejections');
this[kCapture] = Boolean(opts.captureRejections);
} else {
// Assigning the kCapture property directly saves an expensive