@@ -61,13 +61,9 @@ const {
6161
6262const { inspect } = require ( 'util' ) ;
6363
64- const kBuffer = Symbol ( 'kBuffer' ) ;
65- const kCallback = Symbol ( 'kCallback' ) ;
6664const kDispatch = Symbol ( 'kDispatch' ) ;
67- const kEntryTypes = Symbol ( 'kEntryTypes' ) ;
6865const kMaybeBuffer = Symbol ( 'kMaybeBuffer' ) ;
6966const kDeprecatedFields = Symbol ( 'kDeprecatedFields' ) ;
70- const kType = Symbol ( 'kType' ) ;
7167
7268const kDeprecationMessage =
7369 'Custom PerformanceEntry accessors are deprecated. ' +
@@ -151,32 +147,34 @@ function maybeIncrementObserverCount(type) {
151147}
152148
153149class PerformanceObserverEntryList {
150+ #buffer = [ ] ;
151+
154152 constructor ( entries ) {
155- this [ kBuffer ] = ArrayPrototypeSort ( entries , ( first , second ) => {
153+ this . #buffer = ArrayPrototypeSort ( entries , ( first , second ) => {
156154 return first . startTime - second . startTime ;
157155 } ) ;
158156 }
159157
160158 getEntries ( ) {
161- return ArrayPrototypeSlice ( this [ kBuffer ] ) ;
159+ return ArrayPrototypeSlice ( this . #buffer ) ;
162160 }
163161
164162 getEntriesByType ( type ) {
165163 type = `${ type } ` ;
166164 return ArrayPrototypeFilter (
167- this [ kBuffer ] ,
165+ this . #buffer ,
168166 ( entry ) => entry . entryType === type ) ;
169167 }
170168
171169 getEntriesByName ( name , type ) {
172170 name = `${ name } ` ;
173171 if ( type != null /** not nullish */ ) {
174172 return ArrayPrototypeFilter (
175- this [ kBuffer ] ,
173+ this . #buffer ,
176174 ( entry ) => entry . name === name && entry . entryType === type ) ;
177175 }
178176 return ArrayPrototypeFilter (
179- this [ kBuffer ] ,
177+ this . #buffer ,
180178 ( entry ) => entry . name === name ) ;
181179 }
182180
@@ -188,20 +186,19 @@ class PerformanceObserverEntryList {
188186 depth : options . depth == null ? null : options . depth - 1
189187 } ;
190188
191- return `PerformanceObserverEntryList ${ inspect ( this [ kBuffer ] , opts ) } ` ;
189+ return `PerformanceObserverEntryList ${ inspect ( this . #buffer , opts ) } ` ;
192190 }
193191}
194192
195193class PerformanceObserver {
194+ #buffer = [ ] ;
195+ #entryTypes = new SafeSet ( ) ;
196+ #type;
197+ #callback;
198+
196199 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 ;
203200 validateFunction ( callback , 'callback' ) ;
204- this [ kCallback ] = callback ;
201+ this . #callback = callback ;
205202 }
206203
207204 observe ( options = { } ) {
@@ -219,10 +216,10 @@ class PerformanceObserver {
219216 'options.entryTypes can not set with ' +
220217 'options.type together' ) ;
221218
222- switch ( this [ kType ] ) {
219+ switch ( this . #type ) {
223220 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 ;
226223 break ;
227224 case kTypeSingle :
228225 if ( entryTypes !== undefined )
@@ -238,53 +235,53 @@ class PerformanceObserver {
238235 break ;
239236 }
240237
241- if ( this [ kType ] === kTypeMultiple ) {
238+ if ( this . #type === kTypeMultiple ) {
242239 if ( ! ArrayIsArray ( entryTypes ) ) {
243240 throw new ERR_INVALID_ARG_TYPE (
244241 'options.entryTypes' ,
245242 'string[]' ,
246243 entryTypes ) ;
247244 }
248- maybeDecrementObserverCounts ( this [ kEntryTypes ] ) ;
249- this [ kEntryTypes ] . clear ( ) ;
245+ maybeDecrementObserverCounts ( this . #entryTypes ) ;
246+ this . #entryTypes . clear ( ) ;
250247 for ( let n = 0 ; n < entryTypes . length ; n ++ ) {
251248 if ( ArrayPrototypeIncludes ( kSupportedEntryTypes , entryTypes [ n ] ) ) {
252- this [ kEntryTypes ] . add ( entryTypes [ n ] ) ;
249+ this . #entryTypes . add ( entryTypes [ n ] ) ;
253250 maybeIncrementObserverCount ( entryTypes [ n ] ) ;
254251 }
255252 }
256253 } else {
257254 if ( ! ArrayPrototypeIncludes ( kSupportedEntryTypes , type ) )
258255 return ;
259- this [ kEntryTypes ] . add ( type ) ;
256+ this . #entryTypes . add ( type ) ;
260257 maybeIncrementObserverCount ( type ) ;
261258 if ( buffered ) {
262259 const entries = filterBufferMapByNameAndType ( undefined , type ) ;
263- ArrayPrototypePushApply ( this [ kBuffer ] , entries ) ;
260+ ArrayPrototypePushApply ( this . #buffer , entries ) ;
264261 kPending . add ( this ) ;
265262 if ( kPending . size )
266263 queuePending ( ) ;
267264 }
268265 }
269266
270- if ( this [ kEntryTypes ] . size )
267+ if ( this . #entryTypes . size )
271268 kObservers . add ( this ) ;
272269 else
273270 this . disconnect ( ) ;
274271 }
275272
276273 disconnect ( ) {
277- maybeDecrementObserverCounts ( this [ kEntryTypes ] ) ;
274+ maybeDecrementObserverCounts ( this . #entryTypes ) ;
278275 kObservers . delete ( this ) ;
279276 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 ;
283280 }
284281
285282 takeRecords ( ) {
286- const list = this [ kBuffer ] ;
287- this [ kBuffer ] = [ ] ;
283+ const list = this . #buffer ;
284+ this . #buffer = [ ] ;
288285 return list ;
289286 }
290287
@@ -293,17 +290,17 @@ class PerformanceObserver {
293290 }
294291
295292 [ kMaybeBuffer ] ( entry ) {
296- if ( ! this [ kEntryTypes ] . has ( entry . entryType ) )
293+ if ( ! this . #entryTypes . has ( entry . entryType ) )
297294 return ;
298- ArrayPrototypePush ( this [ kBuffer ] , entry ) ;
295+ ArrayPrototypePush ( this . #buffer , entry ) ;
299296 kPending . add ( this ) ;
300297 if ( kPending . size )
301298 queuePending ( ) ;
302299 }
303300
304301 [ kDispatch ] ( ) {
305- this [ kCallback ] ( new PerformanceObserverEntryList ( this . takeRecords ( ) ) ,
306- this ) ;
302+ this . #callback ( new PerformanceObserverEntryList ( this . takeRecords ( ) ) ,
303+ this ) ;
307304 }
308305
309306 [ kInspect ] ( depth , options ) {
@@ -317,8 +314,8 @@ class PerformanceObserver {
317314 return `PerformanceObserver ${ inspect ( {
318315 connected : kObservers . has ( this ) ,
319316 pending : kPending . has ( this ) ,
320- entryTypes : ArrayFrom ( this [ kEntryTypes ] ) ,
321- buffer : this [ kBuffer ] ,
317+ entryTypes : ArrayFrom ( this . #entryTypes ) ,
318+ buffer : this . #buffer ,
322319 } , opts ) } `;
323320 }
324321}
0 commit comments