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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
'use strict';
const {
ObjectDefineProperties,
ReflectConstruct,
Symbol,
} = primordials;
const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
},
} = require('internal/errors');
const {
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');
const { validateInternalField } = require('internal/validators');
const { inspect } = require('util');
const kName = Symbol('PerformanceEntry.Name');
const kEntryType = Symbol('PerformanceEntry.EntryType');
const kStartTime = Symbol('PerformanceEntry.StartTime');
const kDuration = Symbol('PerformanceEntry.Duration');
const kDetail = Symbol('NodePerformanceEntry.Detail');
function isPerformanceEntry(obj) {
return obj?.[kName] !== undefined;
}
class PerformanceEntry {
constructor() {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
get name() {
validateInternalField(this, kName, 'PerformanceEntry');
return this[kName];
}
get entryType() {
validateInternalField(this, kEntryType, 'PerformanceEntry');
return this[kEntryType];
}
get startTime() {
validateInternalField(this, kStartTime, 'PerformanceEntry');
return this[kStartTime];
}
get duration() {
validateInternalField(this, kDuration, 'PerformanceEntry');
return this[kDuration];
}
[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() {
validateInternalField(this, kName, 'PerformanceEntry');
return {
name: this[kName],
entryType: this[kEntryType],
startTime: this[kStartTime],
duration: this[kDuration],
};
}
}
ObjectDefineProperties(PerformanceEntry.prototype, {
name: kEnumerableProperty,
entryType: kEnumerableProperty,
startTime: kEnumerableProperty,
duration: kEnumerableProperty,
toJSON: kEnumerableProperty,
});
function initPerformanceEntry(entry, name, type, start, duration) {
entry[kName] = name;
entry[kEntryType] = type;
entry[kStartTime] = start;
entry[kDuration] = duration;
}
function createPerformanceEntry(name, type, start, duration) {
return ReflectConstruct(function PerformanceEntry() {
initPerformanceEntry(this, name, type, start, duration);
}, [], PerformanceEntry);
}
/**
* Node.js specific extension to PerformanceEntry.
*/
class PerformanceNodeEntry extends PerformanceEntry {
get detail() {
validateInternalField(this, kDetail, 'NodePerformanceEntry');
return this[kDetail];
}
toJSON() {
validateInternalField(this, kName, 'PerformanceEntry');
return {
name: this[kName],
entryType: this[kEntryType],
startTime: this[kStartTime],
duration: this[kDuration],
detail: this[kDetail],
};
}
}
function createPerformanceNodeEntry(name, type, start, duration, detail) {
return ReflectConstruct(function PerformanceNodeEntry() {
initPerformanceEntry(this, name, type, start, duration);
this[kDetail] = detail;
}, [], PerformanceNodeEntry);
}
module.exports = {
initPerformanceEntry,
createPerformanceEntry,
PerformanceEntry,
isPerformanceEntry,
PerformanceNodeEntry,
createPerformanceNodeEntry,
};
|