node/lib/internal/perf/event_loop_delay.js
Mestery 2913211ba8 lib: use ERR_ILLEGAL_CONSTRUCTOR
Use ERR_ILLEGAL_CONSTRUCTOR error instead of `illegal constructor` or
`Illegal constructor` TypeError.

PR-URL: https://github.com/nodejs/node/pull/39556
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2021-08-01 14:24:26 +00:00

60 lines
1.1 KiB
JavaScript

'use strict';
const {
Symbol,
} = primordials;
const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
}
} = require('internal/errors');
const {
ELDHistogram: _ELDHistogram,
} = internalBinding('performance');
const {
validateInteger,
validateObject,
} = require('internal/validators');
const {
Histogram,
kHandle,
} = require('internal/histogram');
const kEnabled = Symbol('kEnabled');
class ELDHistogram extends Histogram {
constructor(i) {
if (!(i instanceof _ELDHistogram)) {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
super(i);
this[kEnabled] = false;
}
enable() {
if (this[kEnabled]) return false;
this[kEnabled] = true;
this[kHandle].start();
return true;
}
disable() {
if (!this[kEnabled]) return false;
this[kEnabled] = false;
this[kHandle].stop();
return true;
}
}
function monitorEventLoopDelay(options = {}) {
validateObject(options, 'options');
const { resolution = 10 } = options;
validateInteger(resolution, 'options.resolution', 1);
return new ELDHistogram(new _ELDHistogram(resolution));
}
module.exports = monitorEventLoopDelay;