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,33 @@ function getMark(name) {
69
66
return ts ;
70
67
}
71
68
72
- class PerformanceMark {
73
- constructor ( name , options = kEmptyObject ) {
74
- if ( arguments . length === 0 ) {
69
+ const kEmptyArg = Symbol ( 'kEmptyArg' ) ;
70
+
71
+ class PerformanceMark extends PerformanceEntry {
72
+ constructor ( name = kEmptyArg , options = undefined ) {
73
+ if ( name === kEmptyArg ) {
75
74
throw new ERR_MISSING_ARGS ( 'name' ) ;
76
75
}
77
76
name = `${ name } ` ;
78
- options ??= kEmptyObject ;
79
77
if ( nodeTimingReadOnlyAttributes . has ( name ) )
80
78
throw new ERR_INVALID_ARG_VALUE ( 'name' , name ) ;
81
- validateObject ( options , 'options' ) ;
82
- const startTime = options . startTime ?? now ( ) ;
79
+ if ( options !== undefined ) {
80
+ validateObject ( options , 'options' ) ;
81
+ }
82
+ const startTime = options ?. startTime ?? now ( ) ;
83
83
validateNumber ( startTime , 'startTime' ) ;
84
84
if ( startTime < 0 )
85
85
throw new ERR_PERFORMANCE_INVALID_TIMESTAMP ( startTime ) ;
86
86
markTimings . set ( name , startTime ) ;
87
87
88
- let detail = options . detail ;
88
+ let detail = options ?. detail ;
89
+ // The usage of != is intentional, we want to skip structuredClone
90
+ // for both undefined and null
89
91
detail = detail != null ?
90
92
structuredClone ( detail ) :
91
93
null ;
92
- initPerformanceEntry ( this , name , 'mark' , startTime , 0 ) ;
94
+
95
+ super ( kSkipThrow , name , 'mark' , startTime , 0 ) ;
93
96
this [ kDetail ] = detail ;
94
97
}
95
98
@@ -108,8 +111,7 @@ class PerformanceMark {
108
111
} ;
109
112
}
110
113
}
111
- ObjectSetPrototypeOf ( PerformanceMark , PerformanceEntry ) ;
112
- ObjectSetPrototypeOf ( PerformanceMark . prototype , PerformanceEntry . prototype ) ;
114
+
113
115
ObjectDefineProperties ( PerformanceMark . prototype , {
114
116
detail : kEnumerableProperty ,
115
117
[ SymbolToStringTag ] : {
@@ -120,8 +122,18 @@ ObjectDefineProperties(PerformanceMark.prototype, {
120
122
} ) ;
121
123
122
124
class PerformanceMeasure extends PerformanceEntry {
123
- constructor ( ) {
124
- throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
125
+ constructor (
126
+ skipThrowSymbol = undefined ,
127
+ name = undefined ,
128
+ type = undefined ,
129
+ start = undefined ,
130
+ duration = undefined ,
131
+ ) {
132
+ if ( skipThrowSymbol !== kSkipThrow ) {
133
+ throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
134
+ }
135
+
136
+ super ( skipThrowSymbol , name , type , start , duration ) ;
125
137
}
126
138
127
139
get detail ( ) {
@@ -139,10 +151,11 @@ ObjectDefineProperties(PerformanceMeasure.prototype, {
139
151
} ) ;
140
152
141
153
function createPerformanceMeasure ( name , start , duration , detail ) {
142
- return ReflectConstruct ( function PerformanceMeasure ( ) {
143
- initPerformanceEntry ( this , name , 'measure' , start , duration ) ;
144
- this [ kDetail ] = detail ;
145
- } , [ ] , PerformanceMeasure ) ;
154
+ const measure = new PerformanceMeasure ( kSkipThrow , name , 'measure' , start , duration ) ;
155
+
156
+ measure [ kDetail ] = detail ;
157
+
158
+ return measure ;
146
159
}
147
160
148
161
function mark ( name , options ) {
0 commit comments