2
2
3
3
const {
4
4
ObjectDefineProperties,
5
- ObjectSetPrototypeOf,
6
5
SafeMap,
7
6
SafeSet,
8
7
SafeArrayIterator,
9
8
Symbol,
10
9
SymbolToStringTag,
11
- ReflectConstruct,
12
10
} = primordials ;
13
11
14
- const { initPerformanceEntry , PerformanceEntry } = require ( 'internal/perf/performance_entry' ) ;
12
+ const { PerformanceEntry , kSkipThrow } = require ( 'internal/perf/performance_entry' ) ;
15
13
const { now } = require ( 'internal/perf/utils' ) ;
16
14
const { enqueue, bufferUserTiming } = require ( 'internal/perf/observe' ) ;
17
15
const nodeTiming = require ( 'internal/perf/nodetiming' ) ;
@@ -35,7 +33,6 @@ const {
35
33
36
34
const { structuredClone } = require ( 'internal/structured_clone' ) ;
37
35
const {
38
- kEmptyObject,
39
36
lazyDOMException,
40
37
kEnumerableProperty,
41
38
} = require ( 'internal/util' ) ;
@@ -69,27 +66,29 @@ function getMark(name) {
69
66
return ts ;
70
67
}
71
68
72
- class PerformanceMark {
73
- constructor ( name , options = kEmptyObject ) {
69
+ class PerformanceMark extends PerformanceEntry {
70
+ constructor ( name , options = undefined ) {
74
71
if ( arguments . length === 0 ) {
75
72
throw new ERR_MISSING_ARGS ( 'name' ) ;
76
73
}
77
74
name = `${ name } ` ;
78
- options ??= kEmptyObject ;
79
75
if ( nodeTimingReadOnlyAttributes . has ( name ) )
80
76
throw new ERR_INVALID_ARG_VALUE ( 'name' , name ) ;
81
- validateObject ( options , 'options' ) ;
82
- const startTime = options . startTime ?? now ( ) ;
77
+ if ( options != null ) {
78
+ validateObject ( options , 'options' ) ;
79
+ }
80
+ const startTime = options ?. startTime ?? now ( ) ;
83
81
validateNumber ( startTime , 'startTime' ) ;
84
82
if ( startTime < 0 )
85
83
throw new ERR_PERFORMANCE_INVALID_TIMESTAMP ( startTime ) ;
86
84
markTimings . set ( name , startTime ) ;
87
85
88
- let detail = options . detail ;
86
+ let detail = options ? .detail ;
89
87
detail = detail != null ?
90
88
structuredClone ( detail ) :
91
89
null ;
92
- initPerformanceEntry ( this , name , 'mark' , startTime , 0 ) ;
90
+
91
+ super ( kSkipThrow , name , 'mark' , startTime , 0 ) ;
93
92
this [ kDetail ] = detail ;
94
93
}
95
94
@@ -108,8 +107,7 @@ class PerformanceMark {
108
107
} ;
109
108
}
110
109
}
111
- ObjectSetPrototypeOf ( PerformanceMark , PerformanceEntry ) ;
112
- ObjectSetPrototypeOf ( PerformanceMark . prototype , PerformanceEntry . prototype ) ;
110
+
113
111
ObjectDefineProperties ( PerformanceMark . prototype , {
114
112
detail : kEnumerableProperty ,
115
113
[ SymbolToStringTag ] : {
@@ -120,8 +118,18 @@ ObjectDefineProperties(PerformanceMark.prototype, {
120
118
} ) ;
121
119
122
120
class PerformanceMeasure extends PerformanceEntry {
123
- constructor ( ) {
124
- throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
121
+ constructor (
122
+ skipThrowSymbol = undefined ,
123
+ name = undefined ,
124
+ type = undefined ,
125
+ start = undefined ,
126
+ duration = undefined ,
127
+ ) {
128
+ if ( skipThrowSymbol !== kSkipThrow ) {
129
+ throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
130
+ }
131
+
132
+ super ( skipThrowSymbol , name , type , start , duration ) ;
125
133
}
126
134
127
135
get detail ( ) {
@@ -139,10 +147,11 @@ ObjectDefineProperties(PerformanceMeasure.prototype, {
139
147
} ) ;
140
148
141
149
function createPerformanceMeasure ( name , start , duration , detail ) {
142
- return ReflectConstruct ( function PerformanceMeasure ( ) {
143
- initPerformanceEntry ( this , name , 'measure' , start , duration ) ;
144
- this [ kDetail ] = detail ;
145
- } , [ ] , PerformanceMeasure ) ;
150
+ const measure = new PerformanceMeasure ( kSkipThrow , name , 'measure' , start , duration ) ;
151
+
152
+ measure [ kDetail ] = detail ;
153
+
154
+ return measure ;
146
155
}
147
156
148
157
function mark ( name , options ) {
0 commit comments