@@ -61,13 +61,9 @@ const {
61
61
62
62
const { inspect } = require ( 'util' ) ;
63
63
64
- const kBuffer = Symbol ( 'kBuffer' ) ;
65
- const kCallback = Symbol ( 'kCallback' ) ;
66
64
const kDispatch = Symbol ( 'kDispatch' ) ;
67
- const kEntryTypes = Symbol ( 'kEntryTypes' ) ;
68
65
const kMaybeBuffer = Symbol ( 'kMaybeBuffer' ) ;
69
66
const kDeprecatedFields = Symbol ( 'kDeprecatedFields' ) ;
70
- const kType = Symbol ( 'kType' ) ;
71
67
72
68
const kDeprecationMessage =
73
69
'Custom PerformanceEntry accessors are deprecated. ' +
@@ -151,32 +147,34 @@ function maybeIncrementObserverCount(type) {
151
147
}
152
148
153
149
class PerformanceObserverEntryList {
150
+ #buffer = [ ] ;
151
+
154
152
constructor ( entries ) {
155
- this [ kBuffer ] = ArrayPrototypeSort ( entries , ( first , second ) => {
153
+ this . #buffer = ArrayPrototypeSort ( entries , ( first , second ) => {
156
154
return first . startTime - second . startTime ;
157
155
} ) ;
158
156
}
159
157
160
158
getEntries ( ) {
161
- return ArrayPrototypeSlice ( this [ kBuffer ] ) ;
159
+ return ArrayPrototypeSlice ( this . #buffer ) ;
162
160
}
163
161
164
162
getEntriesByType ( type ) {
165
163
type = `${ type } ` ;
166
164
return ArrayPrototypeFilter (
167
- this [ kBuffer ] ,
165
+ this . #buffer ,
168
166
( entry ) => entry . entryType === type ) ;
169
167
}
170
168
171
169
getEntriesByName ( name , type ) {
172
170
name = `${ name } ` ;
173
171
if ( type != null /** not nullish */ ) {
174
172
return ArrayPrototypeFilter (
175
- this [ kBuffer ] ,
173
+ this . #buffer ,
176
174
( entry ) => entry . name === name && entry . entryType === type ) ;
177
175
}
178
176
return ArrayPrototypeFilter (
179
- this [ kBuffer ] ,
177
+ this . #buffer ,
180
178
( entry ) => entry . name === name ) ;
181
179
}
182
180
@@ -188,20 +186,19 @@ class PerformanceObserverEntryList {
188
186
depth : options . depth == null ? null : options . depth - 1
189
187
} ;
190
188
191
- return `PerformanceObserverEntryList ${ inspect ( this [ kBuffer ] , opts ) } ` ;
189
+ return `PerformanceObserverEntryList ${ inspect ( this . #buffer , opts ) } ` ;
192
190
}
193
191
}
194
192
195
193
class PerformanceObserver {
194
+ #buffer = [ ] ;
195
+ #entryTypes = new SafeSet ( ) ;
196
+ #type;
197
+ #callback;
198
+
196
199
constructor ( callback ) {
197
- // TODO(joyeecheung): V8 snapshot does not support instance member
198
- // initializers for now:
199
- // https://bugs.chromium.org/p/v8/issues/detail?id=10704
200
- this [ kBuffer ] = [ ] ;
201
- this [ kEntryTypes ] = new SafeSet ( ) ;
202
- this [ kType ] = undefined ;
203
200
validateFunction ( callback , 'callback' ) ;
204
- this [ kCallback ] = callback ;
201
+ this . #callback = callback ;
205
202
}
206
203
207
204
observe ( options = { } ) {
@@ -219,10 +216,10 @@ class PerformanceObserver {
219
216
'options.entryTypes can not set with ' +
220
217
'options.type together' ) ;
221
218
222
- switch ( this [ kType ] ) {
219
+ switch ( this . #type ) {
223
220
case undefined :
224
- if ( entryTypes !== undefined ) this [ kType ] = kTypeMultiple ;
225
- if ( type !== undefined ) this [ kType ] = kTypeSingle ;
221
+ if ( entryTypes !== undefined ) this . #type = kTypeMultiple ;
222
+ if ( type !== undefined ) this . #type = kTypeSingle ;
226
223
break ;
227
224
case kTypeSingle :
228
225
if ( entryTypes !== undefined )
@@ -238,53 +235,53 @@ class PerformanceObserver {
238
235
break ;
239
236
}
240
237
241
- if ( this [ kType ] === kTypeMultiple ) {
238
+ if ( this . #type === kTypeMultiple ) {
242
239
if ( ! ArrayIsArray ( entryTypes ) ) {
243
240
throw new ERR_INVALID_ARG_TYPE (
244
241
'options.entryTypes' ,
245
242
'string[]' ,
246
243
entryTypes ) ;
247
244
}
248
- maybeDecrementObserverCounts ( this [ kEntryTypes ] ) ;
249
- this [ kEntryTypes ] . clear ( ) ;
245
+ maybeDecrementObserverCounts ( this . #entryTypes ) ;
246
+ this . #entryTypes . clear ( ) ;
250
247
for ( let n = 0 ; n < entryTypes . length ; n ++ ) {
251
248
if ( ArrayPrototypeIncludes ( kSupportedEntryTypes , entryTypes [ n ] ) ) {
252
- this [ kEntryTypes ] . add ( entryTypes [ n ] ) ;
249
+ this . #entryTypes . add ( entryTypes [ n ] ) ;
253
250
maybeIncrementObserverCount ( entryTypes [ n ] ) ;
254
251
}
255
252
}
256
253
} else {
257
254
if ( ! ArrayPrototypeIncludes ( kSupportedEntryTypes , type ) )
258
255
return ;
259
- this [ kEntryTypes ] . add ( type ) ;
256
+ this . #entryTypes . add ( type ) ;
260
257
maybeIncrementObserverCount ( type ) ;
261
258
if ( buffered ) {
262
259
const entries = filterBufferMapByNameAndType ( undefined , type ) ;
263
- ArrayPrototypePushApply ( this [ kBuffer ] , entries ) ;
260
+ ArrayPrototypePushApply ( this . #buffer , entries ) ;
264
261
kPending . add ( this ) ;
265
262
if ( kPending . size )
266
263
queuePending ( ) ;
267
264
}
268
265
}
269
266
270
- if ( this [ kEntryTypes ] . size )
267
+ if ( this . #entryTypes . size )
271
268
kObservers . add ( this ) ;
272
269
else
273
270
this . disconnect ( ) ;
274
271
}
275
272
276
273
disconnect ( ) {
277
- maybeDecrementObserverCounts ( this [ kEntryTypes ] ) ;
274
+ maybeDecrementObserverCounts ( this . #entryTypes ) ;
278
275
kObservers . delete ( this ) ;
279
276
kPending . delete ( this ) ;
280
- this [ kBuffer ] = [ ] ;
281
- this [ kEntryTypes ] . clear ( ) ;
282
- this [ kType ] = undefined ;
277
+ this . #buffer = [ ] ;
278
+ this . #entryTypes . clear ( ) ;
279
+ this . #type = undefined ;
283
280
}
284
281
285
282
takeRecords ( ) {
286
- const list = this [ kBuffer ] ;
287
- this [ kBuffer ] = [ ] ;
283
+ const list = this . #buffer ;
284
+ this . #buffer = [ ] ;
288
285
return list ;
289
286
}
290
287
@@ -293,17 +290,17 @@ class PerformanceObserver {
293
290
}
294
291
295
292
[ kMaybeBuffer ] ( entry ) {
296
- if ( ! this [ kEntryTypes ] . has ( entry . entryType ) )
293
+ if ( ! this . #entryTypes . has ( entry . entryType ) )
297
294
return ;
298
- ArrayPrototypePush ( this [ kBuffer ] , entry ) ;
295
+ ArrayPrototypePush ( this . #buffer , entry ) ;
299
296
kPending . add ( this ) ;
300
297
if ( kPending . size )
301
298
queuePending ( ) ;
302
299
}
303
300
304
301
[ kDispatch ] ( ) {
305
- this [ kCallback ] ( new PerformanceObserverEntryList ( this . takeRecords ( ) ) ,
306
- this ) ;
302
+ this . #callback ( new PerformanceObserverEntryList ( this . takeRecords ( ) ) ,
303
+ this ) ;
307
304
}
308
305
309
306
[ kInspect ] ( depth , options ) {
@@ -317,8 +314,8 @@ class PerformanceObserver {
317
314
return `PerformanceObserver ${ inspect ( {
318
315
connected : kObservers . has ( this ) ,
319
316
pending : kPending . has ( this ) ,
320
- entryTypes : ArrayFrom ( this [ kEntryTypes ] ) ,
321
- buffer : this [ kBuffer ] ,
317
+ entryTypes : ArrayFrom ( this . #entryTypes ) ,
318
+ buffer : this . #buffer ,
322
319
} , opts ) } `;
323
320
}
324
321
}
0 commit comments