MCPcopy Create free account
hub / github.com/nodejs/node / observe

Method observe

lib/internal/perf/observe.js:250–317  ·  view source on GitHub ↗
(options = kEmptyObject)

Source from the content-addressed store, hash-verified

248 }
249
250 observe(options = kEmptyObject) {
251 validateObject(options, 'options');
252 const {
253 entryTypes,
254 type,
255 buffered,
256 } = { ...options };
257 if (entryTypes === undefined && type === undefined)
258 throw new ERR_MISSING_ARGS('options.entryTypes', 'options.type');
259 if (entryTypes != null && type != null)
260 throw new ERR_INVALID_ARG_VALUE('options.entryTypes',
261 entryTypes,
262 'options.entryTypes can not set with ' +
263 'options.type together');
264
265 switch (this.#type) {
266 case undefined:
267 if (entryTypes !== undefined) this.#type = kTypeMultiple;
268 if (type !== undefined) this.#type = kTypeSingle;
269 break;
270 case kTypeSingle:
271 if (entryTypes !== undefined)
272 throw lazyDOMException(
273 'PerformanceObserver can not change to multiple observations',
274 'InvalidModificationError');
275 break;
276 case kTypeMultiple:
277 if (type !== undefined)
278 throw lazyDOMException(
279 'PerformanceObserver can not change to single observation',
280 'InvalidModificationError');
281 break;
282 }
283
284 if (this.#type === kTypeMultiple) {
285 if (!ArrayIsArray(entryTypes)) {
286 throw new ERR_INVALID_ARG_TYPE(
287 'options.entryTypes',
288 'string[]',
289 entryTypes);
290 }
291 maybeDecrementObserverCounts(this.#entryTypes);
292 this.#entryTypes.clear();
293 for (let n = 0; n < entryTypes.length; n++) {
294 if (ArrayPrototypeIncludes(kSupportedEntryTypes, entryTypes[n])) {
295 this.#entryTypes.add(entryTypes[n]);
296 maybeIncrementObserverCount(entryTypes[n]);
297 }
298 }
299 } else {
300 if (!ArrayPrototypeIncludes(kSupportedEntryTypes, type))
301 return;
302 this.#entryTypes.add(type);
303 maybeIncrementObserverCount(type);
304 if (buffered) {
305 const entries = filterBufferMapByNameAndType(undefined, type);
306 SafeArrayPrototypePushApply(this.#buffer, entries);
307 kPending.add(this);

Callers 15

mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
testRequestFunction · 0.95
accumulateEntriesFunction · 0.95
accumulateEntryFunction · 0.95

Calls 8

disconnectMethod · 0.95
lazyDOMExceptionFunction · 0.85
queuePendingFunction · 0.85
clearMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected