@@ -53,6 +53,7 @@ const {
5353const {
5454 customInspectSymbol : kInspect ,
5555 deprecate,
56+ lazyDOMException,
5657} = require ( 'internal/util' ) ;
5758
5859const {
@@ -106,9 +107,10 @@ function queuePending() {
106107 isPending = true ;
107108 setImmediate ( ( ) => {
108109 isPending = false ;
109- for ( const pending of kPending )
110- pending [ kDispatch ] ( ) ;
110+ const pendings = ArrayFrom ( kPending . values ( ) ) ;
111111 kPending . clear ( ) ;
112+ for ( const pending of pendings )
113+ pending [ kDispatch ] ( ) ;
112114 } ) ;
113115}
114116
@@ -168,8 +170,13 @@ class PerformanceObserverEntryList {
168170 ( entry ) => entry . entryType === type ) ;
169171 }
170172
171- getEntriesByName ( name ) {
173+ getEntriesByName ( name , type ) {
172174 name = `${ name } ` ;
175+ if ( type != null /** not nullish */ ) {
176+ return ArrayPrototypeFilter (
177+ this [ kBuffer ] ,
178+ ( entry ) => entry . name === name && entry . entryType === type ) ;
179+ }
173180 return ArrayPrototypeFilter (
174181 this [ kBuffer ] ,
175182 ( entry ) => entry . name === name ) ;
@@ -208,6 +215,11 @@ class PerformanceObserver {
208215 } = { ...options } ;
209216 if ( entryTypes === undefined && type === undefined )
210217 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' ) ;
211223
212224 switch ( this [ kType ] ) {
213225 case undefined :
@@ -216,11 +228,15 @@ class PerformanceObserver {
216228 break ;
217229 case kTypeSingle :
218230 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' ) ;
220234 break ;
221235 case kTypeMultiple :
222236 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' ) ;
224240 break ;
225241 }
226242
@@ -271,7 +287,7 @@ class PerformanceObserver {
271287 takeRecords ( ) {
272288 const list = this [ kBuffer ] ;
273289 this [ kBuffer ] = [ ] ;
274- return new PerformanceObserverEntryList ( list ) ;
290+ return list ;
275291 }
276292
277293 static get supportedEntryTypes ( ) {
@@ -287,7 +303,10 @@ class PerformanceObserver {
287303 queuePending ( ) ;
288304 }
289305
290- [ kDispatch ] ( ) { this [ kCallback ] ( this . takeRecords ( ) , this ) ; }
306+ [ kDispatch ] ( ) {
307+ this [ kCallback ] ( new PerformanceObserverEntryList ( this . takeRecords ( ) ) ,
308+ this ) ;
309+ }
291310
292311 [ kInspect ] ( depth , options ) {
293312 if ( depth < 0 ) return this ;
@@ -367,6 +386,7 @@ function clearEntriesFromBuffer(type, name) {
367386
368387 let head = null ;
369388 let tail = null ;
389+ let count = 0 ;
370390 for ( let entry = buffer . head ; entry !== null ; entry = entry [ kBufferNext ] ) {
371391 if ( entry . name !== name ) {
372392 head = head ?? entry ;
@@ -377,9 +397,11 @@ function clearEntriesFromBuffer(type, name) {
377397 continue ;
378398 }
379399 tail [ kBufferNext ] = entry [ kBufferNext ] ;
400+ count ++ ;
380401 }
381402 buffer . head = head ;
382403 buffer . tail = tail ;
404+ buffer . count = count ;
383405}
384406
385407function filterBufferMapByNameAndType ( name , type ) {
@@ -469,6 +491,7 @@ function resetBuffer(buffer) {
469491
470492module . exports = {
471493 PerformanceObserver,
494+ PerformanceObserverEntryList,
472495 enqueue,
473496 hasObserver,
474497 clearEntriesFromBuffer,
0 commit comments