33 */
44let timeoutHandler ;
55const timeoutCallbacks = { } ;
6+ // this is needed to keep a strong reference to the callback
7+ // currently fixes a race condition in V8 with the android runtime implementation of WeakRef
8+ // there are fixes in the android runtime that will remove the need for this
9+ const timeoutCallbacksCb = { } ;
610let timerId = 0 ;
711
812function createHandlerAndGetId ( ) : number {
@@ -29,12 +33,14 @@ export function setTimeout(callback: Function, milliseconds = 0, ...args): numbe
2933
3034 if ( timeoutCallbacks [ id ] ) {
3135 delete timeoutCallbacks [ id ] ;
36+ delete timeoutCallbacksCb [ id ] ;
3237 }
3338 } ,
3439 } ) ;
3540
3641 if ( ! timeoutCallbacks [ id ] ) {
3742 timeoutCallbacks [ id ] = runnable ;
43+ timeoutCallbacksCb [ id ] = callback ;
3844 }
3945
4046 timeoutHandler . postDelayed ( runnable , long ( milliseconds ) ) ;
@@ -47,6 +53,7 @@ export function clearTimeout(id: number): void {
4753 if ( timeoutCallbacks [ index ] ) {
4854 timeoutHandler . removeCallbacks ( timeoutCallbacks [ index ] ) ;
4955 delete timeoutCallbacks [ index ] ;
56+ delete timeoutCallbacksCb [ index ] ;
5057 }
5158}
5259
@@ -74,6 +81,7 @@ export function setInterval(callback: Function, milliseconds = 0, ...args): numb
7481
7582 if ( ! timeoutCallbacks [ id ] ) {
7683 timeoutCallbacks [ id ] = runnable ;
84+ timeoutCallbacksCb [ id ] = callback ;
7785 }
7886
7987 timeoutHandler . postDelayed ( runnable , long ( nextCallMs ( ) ) ) ;
0 commit comments