@@ -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,8 @@ 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' , entryTypes , 'options.entryTypes can not set with options.type together' ) ;
211220
212221 switch ( this [ kType ] ) {
213222 case undefined :
@@ -216,11 +225,11 @@ class PerformanceObserver {
216225 break ;
217226 case kTypeSingle :
218227 if ( entryTypes !== undefined )
219- throw new ERR_INVALID_ARG_VALUE ( 'options.entryTypes ', entryTypes ) ;
228+ throw lazyDOMException ( 'PerformanceObserver can not change to multiple observations ', 'InvalidModificationError' ) ;
220229 break ;
221230 case kTypeMultiple :
222231 if ( type !== undefined )
223- throw new ERR_INVALID_ARG_VALUE ( 'options.type ', type ) ;
232+ throw lazyDOMException ( 'PerformanceObserver can not change to single observation ', 'InvalidModificationError' ) ;
224233 break ;
225234 }
226235
@@ -271,7 +280,7 @@ class PerformanceObserver {
271280 takeRecords ( ) {
272281 const list = this [ kBuffer ] ;
273282 this [ kBuffer ] = [ ] ;
274- return new PerformanceObserverEntryList ( list ) ;
283+ return list ;
275284 }
276285
277286 static get supportedEntryTypes ( ) {
@@ -287,7 +296,7 @@ class PerformanceObserver {
287296 queuePending ( ) ;
288297 }
289298
290- [ kDispatch ] ( ) { this [ kCallback ] ( this . takeRecords ( ) , this ) ; }
299+ [ kDispatch ] ( ) { this [ kCallback ] ( new PerformanceObserverEntryList ( this . takeRecords ( ) ) , this ) ; }
291300
292301 [ kInspect ] ( depth , options ) {
293302 if ( depth < 0 ) return this ;
@@ -367,6 +376,7 @@ function clearEntriesFromBuffer(type, name) {
367376
368377 let head = null ;
369378 let tail = null ;
379+ let count = 0 ;
370380 for ( let entry = buffer . head ; entry !== null ; entry = entry [ kBufferNext ] ) {
371381 if ( entry . name !== name ) {
372382 head = head ?? entry ;
@@ -377,9 +387,11 @@ function clearEntriesFromBuffer(type, name) {
377387 continue ;
378388 }
379389 tail [ kBufferNext ] = entry [ kBufferNext ] ;
390+ count ++ ;
380391 }
381392 buffer . head = head ;
382393 buffer . tail = tail ;
394+ buffer . count = count ;
383395}
384396
385397function filterBufferMapByNameAndType ( name , type ) {
@@ -469,6 +481,7 @@ function resetBuffer(buffer) {
469481
470482module . exports = {
471483 PerformanceObserver,
484+ PerformanceObserverEntryList,
472485 enqueue,
473486 hasObserver,
474487 clearEntriesFromBuffer,
0 commit comments