@@ -190,6 +190,7 @@ export class Wrapper {
190190 } ;
191191 selfTraceLink = '' ;
192192 #traceForDebug: string | null = null ;
193+ #traceForBypass: string | null = null ;
193194 #callstackType: EWrapperCallstackType = EWrapperCallstackType . FULL ;
194195
195196 constructor ( ) {
@@ -230,6 +231,18 @@ export class Wrapper {
230231 this . #traceForDebug = traceId ;
231232 }
232233
234+ #shouldDebug( traceId : string ) {
235+ return this . #traceForDebug === traceId ;
236+ }
237+
238+ setTraceForBypass ( traceId : string | null ) {
239+ this . #traceForBypass = traceId ;
240+ }
241+
242+ #shouldBypass( traceId : string ) {
243+ return this . #traceForBypass === traceId ;
244+ }
245+
233246 setCallstackType ( type : EWrapperCallstackType ) {
234247 this . #callstackType = type ;
235248 }
@@ -393,7 +406,7 @@ export class Wrapper {
393406 updateTimersSelfTime (
394407 map : Map < string , TSetTimerHistory > ,
395408 traceId : string ,
396- selfTime : number
409+ selfTime : number | null
397410 ) {
398411 const record = map . get ( traceId ) ;
399412
@@ -437,7 +450,7 @@ export class Wrapper {
437450 this . onlineAnimationFrameLookup . set ( handler , callstack . traceId ) ;
438451 }
439452
440- rafFired ( handler : number , traceId : string , selfTime : number ) {
453+ rafFired ( handler : number , traceId : string , selfTime : number | null ) {
441454 const rafRecord = this . rafHistory . get ( traceId ) ;
442455 if ( ! rafRecord ) {
443456 return ;
@@ -492,7 +505,7 @@ export class Wrapper {
492505 handler : number ,
493506 traceId : string ,
494507 deadline : IdleDeadline ,
495- selfTime : number
508+ selfTime : number | null
496509 ) {
497510 const ricRecord = this . ricHistory . get ( traceId ) ;
498511 if ( ! ricRecord ) {
@@ -680,16 +693,17 @@ export class Wrapper {
680693 this . callCounter . requestIdleCallback ++ ;
681694 const handler = this . native . requestIdleCallback ( ( deadline ) => {
682695 const start = performance . now ( ) ;
683- if ( this . #traceForDebug === callstack . traceId ) {
696+ let selfTime = null ;
697+
698+ if ( this . #shouldDebug( callstack . traceId ) ) {
684699 debugger ;
685700 }
686- fn ( deadline ) ;
687- this . ricFired (
688- handler ,
689- callstack . traceId ,
690- deadline ,
691- performance . now ( ) - start
692- ) ;
701+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
702+ fn ( deadline ) ;
703+ selfTime = performance . now ( ) - start ;
704+ }
705+
706+ this . ricFired ( handler , callstack . traceId , deadline , selfTime ) ;
693707 } , options ) ;
694708 this . updateRicHistory ( handler , delay , callstack ) ;
695709
@@ -707,10 +721,12 @@ export class Wrapper {
707721
708722 this . updateCicHistory ( handler , callstack ) ;
709723 this . callCounter . cancelIdleCallback ++ ;
710- if ( this . #traceForDebug === callstack . traceId ) {
724+ if ( this . #shouldDebug ( callstack . traceId ) ) {
711725 debugger ;
712726 }
713- this . native . cancelIdleCallback ( handler ) ;
727+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
728+ this . native . cancelIdleCallback ( handler ) ;
729+ }
714730 } . bind ( this ) ;
715731 }
716732
@@ -725,11 +741,17 @@ export class Wrapper {
725741 this . callCounter . requestAnimationFrame ++ ;
726742 const handler = this . native . requestAnimationFrame ( ( ...args ) => {
727743 const start = performance . now ( ) ;
728- if ( this . #traceForDebug === callstack . traceId ) {
744+ let selfTime = null ;
745+
746+ if ( this . #shouldDebug( callstack . traceId ) ) {
729747 debugger ;
730748 }
731- fn ( ...args ) ;
732- this . rafFired ( handler , callstack . traceId , performance . now ( ) - start ) ;
749+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
750+ fn ( ...args ) ;
751+ selfTime = performance . now ( ) - start ;
752+ }
753+
754+ this . rafFired ( handler , callstack . traceId , selfTime ) ;
733755 } ) ;
734756 this . updateRafHistory ( handler , callstack ) ;
735757
@@ -747,30 +769,34 @@ export class Wrapper {
747769
748770 this . updateCafHistory ( handler , callstack ) ;
749771 this . callCounter . cancelAnimationFrame ++ ;
750- if ( this . #traceForDebug === callstack . traceId ) {
772+ if ( this . #shouldDebug ( callstack . traceId ) ) {
751773 debugger ;
752774 }
753- this . native . cancelAnimationFrame ( handler ) ;
775+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
776+ this . native . cancelAnimationFrame ( handler ) ;
777+ }
754778 } . bind ( this ) ;
755779 }
756780
757781 wrapEval ( ) {
758782 window . eval = function WrappedLessEval ( this : Wrapper , code : string ) {
783+ const err = new Error ( TRACE_ERROR_MESSAGE ) ;
784+ const callstack = this . createCallstack ( err , code ) ;
759785 let rv : unknown ;
760786 let throwError = null ;
761787 let usesLocalScope = false ;
762788 let selfTime = null ;
763- const err = new Error ( TRACE_ERROR_MESSAGE ) ;
764- const callstack = this . createCallstack ( err , code ) ;
765789
766790 try {
767791 this . callCounter . eval ++ ;
768792 const start = performance . now ( ) ;
769- if ( this . #traceForDebug === callstack . traceId ) {
793+ if ( this . #shouldDebug ( callstack . traceId ) ) {
770794 debugger ;
771795 }
772- rv = this . native . eval ( code ) ;
773- selfTime = performance . now ( ) - start ;
796+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
797+ rv = this . native . eval ( code ) ;
798+ selfTime = performance . now ( ) - start ;
799+ }
774800 } catch ( error : unknown ) {
775801 if ( error instanceof Error && 'ReferenceError' === error . name ) {
776802 // most likely a side effect of `eval` reassigning
@@ -807,25 +833,33 @@ export class Wrapper {
807833 const handler = this . native . setTimeout (
808834 ( ...params : any [ ] ) => {
809835 const start = performance . now ( ) ;
836+ let selfTime = null ;
837+
810838 if ( isEval ) {
811839 this . callCounter . eval ++ ;
812- if ( this . #traceForDebug === callstack . traceId ) {
840+ if ( this . #shouldDebug ( callstack . traceId ) ) {
813841 debugger ;
814842 }
815- // see https://developer.mozilla.org/docs/Web/API/setTimeout#code
816- this . native . eval ( code ) ;
843+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
844+ // see https://developer.mozilla.org/docs/Web/API/setTimeout#code
845+ this . native . eval ( code ) ;
846+ selfTime = performance . now ( ) - start ;
847+ }
817848 } else {
818- if ( this . #traceForDebug === callstack . traceId ) {
849+ if ( this . #shouldDebug ( callstack . traceId ) ) {
819850 debugger ;
820851 }
821- code ( ...params ) ;
852+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
853+ code ( ...params ) ;
854+ selfTime = performance . now ( ) - start ;
855+ }
822856 }
823- const stop = performance . now ( ) - start ;
824- this . timerOffline ( handler , null , stop ) ;
857+
858+ this . timerOffline ( handler , null , selfTime ) ;
825859 this . updateTimersSelfTime (
826860 this . setTimeoutHistory ,
827861 callstack . traceId ,
828- stop
862+ selfTime
829863 ) ;
830864 } ,
831865 delay ,
@@ -873,10 +907,12 @@ export class Wrapper {
873907 }
874908
875909 this . callCounter . clearTimeout ++ ;
876- if ( this . #traceForDebug === callstack . traceId ) {
910+ if ( this . #shouldDebug ( callstack . traceId ) ) {
877911 debugger ;
878912 }
879- this . native . clearTimeout ( handler ) ;
913+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
914+ this . native . clearTimeout ( handler ) ;
915+ }
880916 } . bind ( this ) ;
881917 }
882918
@@ -895,23 +931,32 @@ export class Wrapper {
895931 const handler = this . native . setInterval (
896932 ( ...params : any [ ] ) => {
897933 const start = performance . now ( ) ;
934+ let selfTime = null ;
935+
898936 if ( isEval ) {
899937 this . callCounter . eval ++ ;
900- if ( this . #traceForDebug === callstack . traceId ) {
938+ if ( this . #shouldDebug ( callstack . traceId ) ) {
901939 debugger ;
902940 }
903- // see https://developer.mozilla.org/docs/Web/API/setInterval
904- this . native . eval ( code ) ;
941+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
942+ // see https://developer.mozilla.org/docs/Web/API/setInterval
943+ this . native . eval ( code ) ;
944+ selfTime = performance . now ( ) - start ;
945+ }
905946 } else {
906- if ( this . #traceForDebug === callstack . traceId ) {
947+ if ( this . #shouldDebug ( callstack . traceId ) ) {
907948 debugger ;
908949 }
909- code ( ...params ) ;
950+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
951+ code ( ...params ) ;
952+ selfTime = performance . now ( ) - start ;
953+ }
910954 }
955+
911956 this . updateTimersSelfTime (
912957 this . setIntervalHistory ,
913958 callstack . traceId ,
914- performance . now ( ) - start
959+ selfTime
915960 ) ;
916961 } ,
917962 delay ,
@@ -959,10 +1004,12 @@ export class Wrapper {
9591004 }
9601005
9611006 this . callCounter . clearInterval ++ ;
962- if ( this . #traceForDebug === callstack . traceId ) {
1007+ if ( this . #shouldDebug ( callstack . traceId ) ) {
9631008 debugger ;
9641009 }
965- this . native . clearInterval ( handler ) ;
1010+ if ( ! this . #shouldBypass( callstack . traceId ) ) {
1011+ this . native . clearInterval ( handler ) ;
1012+ }
9661013 } . bind ( this ) ;
9671014 }
9681015
0 commit comments