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