@@ -53,6 +53,7 @@ const {
53
53
const {
54
54
customInspectSymbol : kInspect ,
55
55
deprecate,
56
+ lazyDOMException,
56
57
} = require ( 'internal/util' ) ;
57
58
58
59
const {
@@ -106,9 +107,10 @@ function queuePending() {
106
107
isPending = true ;
107
108
setImmediate ( ( ) => {
108
109
isPending = false ;
109
- for ( const pending of kPending )
110
- pending [ kDispatch ] ( ) ;
110
+ const pendings = ArrayFrom ( kPending . values ( ) ) ;
111
111
kPending . clear ( ) ;
112
+ for ( const pending of pendings )
113
+ pending [ kDispatch ] ( ) ;
112
114
} ) ;
113
115
}
114
116
@@ -168,8 +170,13 @@ class PerformanceObserverEntryList {
168
170
( entry ) => entry . entryType === type ) ;
169
171
}
170
172
171
- getEntriesByName ( name ) {
173
+ getEntriesByName ( name , type ) {
172
174
name = `${ name } ` ;
175
+ if ( type != null /** not nullish */ ) {
176
+ return ArrayPrototypeFilter (
177
+ this [ kBuffer ] ,
178
+ ( entry ) => entry . name === name && entry . entryType === type ) ;
179
+ }
173
180
return ArrayPrototypeFilter (
174
181
this [ kBuffer ] ,
175
182
( entry ) => entry . name === name ) ;
@@ -208,6 +215,11 @@ class PerformanceObserver {
208
215
} = { ...options } ;
209
216
if ( entryTypes === undefined && type === undefined )
210
217
throw new ERR_MISSING_ARGS ( 'options.entryTypes' , 'options.type' ) ;
218
+ if ( entryTypes != null && type != null )
219
+ throw new ERR_INVALID_ARG_VALUE ( 'options.entryTypes' ,
220
+ entryTypes ,
221
+ 'options.entryTypes can not set with ' +
222
+ 'options.type together' ) ;
211
223
212
224
switch ( this [ kType ] ) {
213
225
case undefined :
@@ -216,11 +228,15 @@ class PerformanceObserver {
216
228
break ;
217
229
case kTypeSingle :
218
230
if ( entryTypes !== undefined )
219
- throw new ERR_INVALID_ARG_VALUE ( 'options.entryTypes' , entryTypes ) ;
231
+ throw lazyDOMException (
232
+ 'PerformanceObserver can not change to multiple observations' ,
233
+ 'InvalidModificationError' ) ;
220
234
break ;
221
235
case kTypeMultiple :
222
236
if ( type !== undefined )
223
- throw new ERR_INVALID_ARG_VALUE ( 'options.type' , type ) ;
237
+ throw lazyDOMException (
238
+ 'PerformanceObserver can not change to single observation' ,
239
+ 'InvalidModificationError' ) ;
224
240
break ;
225
241
}
226
242
@@ -271,7 +287,7 @@ class PerformanceObserver {
271
287
takeRecords ( ) {
272
288
const list = this [ kBuffer ] ;
273
289
this [ kBuffer ] = [ ] ;
274
- return new PerformanceObserverEntryList ( list ) ;
290
+ return list ;
275
291
}
276
292
277
293
static get supportedEntryTypes ( ) {
@@ -287,7 +303,10 @@ class PerformanceObserver {
287
303
queuePending ( ) ;
288
304
}
289
305
290
- [ kDispatch ] ( ) { this [ kCallback ] ( this . takeRecords ( ) , this ) ; }
306
+ [ kDispatch ] ( ) {
307
+ this [ kCallback ] ( new PerformanceObserverEntryList ( this . takeRecords ( ) ) ,
308
+ this ) ;
309
+ }
291
310
292
311
[ kInspect ] ( depth , options ) {
293
312
if ( depth < 0 ) return this ;
@@ -367,6 +386,7 @@ function clearEntriesFromBuffer(type, name) {
367
386
368
387
let head = null ;
369
388
let tail = null ;
389
+ let count = 0 ;
370
390
for ( let entry = buffer . head ; entry !== null ; entry = entry [ kBufferNext ] ) {
371
391
if ( entry . name !== name ) {
372
392
head = head ?? entry ;
@@ -377,9 +397,11 @@ function clearEntriesFromBuffer(type, name) {
377
397
continue ;
378
398
}
379
399
tail [ kBufferNext ] = entry [ kBufferNext ] ;
400
+ count ++ ;
380
401
}
381
402
buffer . head = head ;
382
403
buffer . tail = tail ;
404
+ buffer . count = count ;
383
405
}
384
406
385
407
function filterBufferMapByNameAndType ( name , type ) {
@@ -469,6 +491,7 @@ function resetBuffer(buffer) {
469
491
470
492
module . exports = {
471
493
PerformanceObserver,
494
+ PerformanceObserverEntryList,
472
495
enqueue,
473
496
hasObserver,
474
497
clearEntriesFromBuffer,
0 commit comments