node/lib/internal/perf/event_loop_delay.js
Chengzhong Wu 38dee8a1c0
src: distinguish HTML transferable and cloneable
The HTML structured serialize algorithm treats transferable and
serializable as two different bits. A web platform interface can be
both transferable and serializable.

Splits BaseObject::TransferMode to be able to compose the two bits
and distinguishes the transferable and cloneable.

PR-URL: https://github.com/nodejs/node/pull/47956
Refs: cf13b9b465
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
2023-07-07 17:00:00 +00:00

92 lines
1.7 KiB
JavaScript

'use strict';
const {
ReflectConstruct,
SafeMap,
Symbol,
} = primordials;
const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_THIS,
},
} = require('internal/errors');
const {
createELDHistogram,
} = internalBinding('performance');
const {
validateInteger,
validateObject,
} = require('internal/validators');
const {
Histogram,
kHandle,
kMap,
} = require('internal/histogram');
const {
kEmptyObject,
} = require('internal/util');
const {
markTransferMode,
} = require('internal/worker/js_transferable');
const kEnabled = Symbol('kEnabled');
class ELDHistogram extends Histogram {
constructor(i) {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
/**
* @returns {boolean}
*/
enable() {
if (this[kEnabled] === undefined)
throw new ERR_INVALID_THIS('ELDHistogram');
if (this[kEnabled]) return false;
this[kEnabled] = true;
this[kHandle].start();
return true;
}
/**
* @returns {boolean}
*/
disable() {
if (this[kEnabled] === undefined)
throw new ERR_INVALID_THIS('ELDHistogram');
if (!this[kEnabled]) return false;
this[kEnabled] = false;
this[kHandle].stop();
return true;
}
}
/**
* @param {{
* resolution : number
* }} [options]
* @returns {ELDHistogram}
*/
function monitorEventLoopDelay(options = kEmptyObject) {
validateObject(options, 'options');
const { resolution = 10 } = options;
validateInteger(resolution, 'options.resolution', 1);
return ReflectConstruct(
function() {
markTransferMode(this, true, false);
this[kEnabled] = false;
this[kHandle] = createELDHistogram(resolution);
this[kMap] = new SafeMap();
}, [], ELDHistogram);
}
module.exports = monitorEventLoopDelay;