@@ -30,15 +30,26 @@ const eventToInitiatorMap = new Map<Types.Events.Event, Types.Events.Event>();
3030// multiple events, hence why the value for this map is an array.
3131const initiatorToEventsMap = new Map < Types . Events . Event , Types . Events . Event [ ] > ( ) ;
3232
33+ // Note: we are keeping the parsing of the following async JS schedulers
34+ // for backwards compatibility only. They are targeted to be removed
35+ // completely by M134. See more details at crbug.com/383974422
36+ // TODO(andoli): remove manual parsing of async JS schedulers.
37+ const requestAnimationFrameEventsById : Map < number , Types . Events . RequestAnimationFrame > = new Map ( ) ;
38+ const timerInstallEventsById : Map < number , Types . Events . TimerInstall > = new Map ( ) ;
39+ const requestIdleCallbackEventsById : Map < number , Types . Events . RequestIdleCallback > = new Map ( ) ;
40+
3341const webSocketCreateEventsById : Map < number , Types . Events . WebSocketCreate > = new Map ( ) ;
3442const schedulePostTaskCallbackEventsById : Map < number , Types . Events . SchedulePostTaskCallback > = new Map ( ) ;
3543
3644export function reset ( ) : void {
3745 lastScheduleStyleRecalcByFrame . clear ( ) ;
3846 lastInvalidationEventForFrame . clear ( ) ;
3947 lastUpdateLayoutTreeByFrame . clear ( ) ;
48+ timerInstallEventsById . clear ( ) ;
4049 eventToInitiatorMap . clear ( ) ;
4150 initiatorToEventsMap . clear ( ) ;
51+ requestAnimationFrameEventsById . clear ( ) ;
52+ requestIdleCallbackEventsById . clear ( ) ;
4253 webSocketCreateEventsById . clear ( ) ;
4354 schedulePostTaskCallbackEventsById . clear ( ) ;
4455}
@@ -117,6 +128,36 @@ export function handleEvent(event: Types.Events.Event): void {
117128 }
118129 // Now clear the last invalidation for the frame: the last invalidation has been linked to a Layout event, so it cannot be the initiator for any future layouts.
119130 lastInvalidationEventForFrame . delete ( event . args . beginData . frame ) ;
131+ } else if ( Types . Events . isRequestAnimationFrame ( event ) ) {
132+ requestAnimationFrameEventsById . set ( event . args . data . id , event ) ;
133+ } else if ( Types . Events . isFireAnimationFrame ( event ) ) {
134+ // If we get a fire event, that means we should have had the
135+ // RequestAnimationFrame event by now. If so, we can set that as the
136+ // initiator for the fire event.
137+ const matchingRequestEvent = requestAnimationFrameEventsById . get ( event . args . data . id ) ;
138+ if ( matchingRequestEvent ) {
139+ storeInitiator ( {
140+ event,
141+ initiator : matchingRequestEvent ,
142+ } ) ;
143+ }
144+ } else if ( Types . Events . isTimerInstall ( event ) ) {
145+ timerInstallEventsById . set ( event . args . data . timerId , event ) ;
146+ } else if ( Types . Events . isTimerFire ( event ) ) {
147+ const matchingInstall = timerInstallEventsById . get ( event . args . data . timerId ) ;
148+ if ( matchingInstall ) {
149+ storeInitiator ( { event, initiator : matchingInstall } ) ;
150+ }
151+ } else if ( Types . Events . isRequestIdleCallback ( event ) ) {
152+ requestIdleCallbackEventsById . set ( event . args . data . id , event ) ;
153+ } else if ( Types . Events . isFireIdleCallback ( event ) ) {
154+ const matchingRequestEvent = requestIdleCallbackEventsById . get ( event . args . data . id ) ;
155+ if ( matchingRequestEvent ) {
156+ storeInitiator ( {
157+ event,
158+ initiator : matchingRequestEvent ,
159+ } ) ;
160+ }
120161 } else if ( Types . Events . isWebSocketCreate ( event ) ) {
121162 webSocketCreateEventsById . set ( event . args . data . identifier , event ) ;
122163 } else if ( Types . Events . isWebSocketInfo ( event ) || Types . Events . isWebSocketTransfer ( event ) ) {
0 commit comments