@@ -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,8 @@ 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' , entryTypes , 'options.entryTypes can not set with options.type together' ) ;
211
220
212
221
switch ( this [ kType ] ) {
213
222
case undefined :
@@ -216,11 +225,11 @@ class PerformanceObserver {
216
225
break ;
217
226
case kTypeSingle :
218
227
if ( entryTypes !== undefined )
219
- throw new ERR_INVALID_ARG_VALUE ( 'options.entryTypes ', entryTypes ) ;
228
+ throw lazyDOMException ( 'PerformanceObserver can not change to multiple observations ', 'InvalidModificationError' ) ;
220
229
break ;
221
230
case kTypeMultiple :
222
231
if ( type !== undefined )
223
- throw new ERR_INVALID_ARG_VALUE ( 'options.type ', type ) ;
232
+ throw lazyDOMException ( 'PerformanceObserver can not change to single observation ', 'InvalidModificationError' ) ;
224
233
break ;
225
234
}
226
235
@@ -271,7 +280,7 @@ class PerformanceObserver {
271
280
takeRecords ( ) {
272
281
const list = this [ kBuffer ] ;
273
282
this [ kBuffer ] = [ ] ;
274
- return new PerformanceObserverEntryList ( list ) ;
283
+ return list ;
275
284
}
276
285
277
286
static get supportedEntryTypes ( ) {
@@ -287,7 +296,7 @@ class PerformanceObserver {
287
296
queuePending ( ) ;
288
297
}
289
298
290
- [ kDispatch ] ( ) { this [ kCallback ] ( this . takeRecords ( ) , this ) ; }
299
+ [ kDispatch ] ( ) { this [ kCallback ] ( new PerformanceObserverEntryList ( this . takeRecords ( ) ) , this ) ; }
291
300
292
301
[ kInspect ] ( depth , options ) {
293
302
if ( depth < 0 ) return this ;
@@ -367,6 +376,7 @@ function clearEntriesFromBuffer(type, name) {
367
376
368
377
let head = null ;
369
378
let tail = null ;
379
+ let count = 0 ;
370
380
for ( let entry = buffer . head ; entry !== null ; entry = entry [ kBufferNext ] ) {
371
381
if ( entry . name !== name ) {
372
382
head = head ?? entry ;
@@ -377,9 +387,11 @@ function clearEntriesFromBuffer(type, name) {
377
387
continue ;
378
388
}
379
389
tail [ kBufferNext ] = entry [ kBufferNext ] ;
390
+ count ++ ;
380
391
}
381
392
buffer . head = head ;
382
393
buffer . tail = tail ;
394
+ buffer . count = count ;
383
395
}
384
396
385
397
function filterBufferMapByNameAndType ( name , type ) {
@@ -469,6 +481,7 @@ function resetBuffer(buffer) {
469
481
470
482
module . exports = {
471
483
PerformanceObserver,
484
+ PerformanceObserverEntryList,
472
485
enqueue,
473
486
hasObserver,
474
487
clearEntriesFromBuffer,
0 commit comments