All files / lib/internal/perf performance_entry.js

87.2% Statements 75/86
100% Branches 9/9
88.88% Functions 8/9
87.2% Lines 75/86

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 8730x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 339x 339x 339x 30x 30x 30x     30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x                   30x 30x 130x 130x 130x 130x 130x 130x 130x 130x 30x 30x 30x 30x 346x 346x 346x 346x 346x 346x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x  
'use strict';
 
const {
  ObjectSetPrototypeOf,
  Symbol,
} = primordials;
 
const {
  codes: {
    ERR_ILLEGAL_CONSTRUCTOR,
  }
} = require('internal/errors');
 
const {
  customInspectSymbol: kInspect,
} = require('internal/util');
 
const { inspect } = require('util');
 
const kName = Symbol('kName');
const kType = Symbol('kType');
const kStart = Symbol('kStart');
const kDuration = Symbol('kDuration');
const kDetail = Symbol('kDetail');
 
function isPerformanceEntry(obj) {
  return obj?.[kName] !== undefined;
}
 
class PerformanceEntry {
  constructor() {
    throw new ERR_ILLEGAL_CONSTRUCTOR();
  }
 
  get name() { return this[kName]; }
 
  get entryType() { return this[kType]; }
 
  get startTime() { return this[kStart]; }
 
  get duration() { return this[kDuration]; }
 
  get detail() { return this[kDetail]; }
 
  [kInspect](depth, options) {
    if (depth < 0) return this;

    const opts = {
      ...options,
      depth: options.depth == null ? null : options.depth - 1
    };

    return `${this.constructor.name} ${inspect(this.toJSON(), opts)}`;
  }
 
  toJSON() {
    return {
      name: this.name,
      entryType: this.entryType,
      startTime: this.startTime,
      duration: this.duration,
      detail: this.detail,
    };
  }
}
 
class InternalPerformanceEntry {
  constructor(name, type, start, duration, detail) {
    this[kName] = name;
    this[kType] = type;
    this[kStart] = start;
    this[kDuration] = duration;
    this[kDetail] = detail;
  }
}
 
InternalPerformanceEntry.prototype.constructor = PerformanceEntry;
ObjectSetPrototypeOf(
  InternalPerformanceEntry.prototype,
  PerformanceEntry.prototype);
 
module.exports = {
  InternalPerformanceEntry,
  PerformanceEntry,
  isPerformanceEntry,
};