| 95 | } |
| 96 | |
| 97 | function flushTimeoutHandlers() { |
| 98 | // Copy the array. In case setTimeout/clearTimeout is invoked in the callback. |
| 99 | const savedTimeoutHandlers = timeoutHandlers.slice(); |
| 100 | for (let i = 0; i < savedTimeoutHandlers.length; i++) { |
| 101 | const handler = savedTimeoutHandlers[i]; |
| 102 | if (handler.frame === frameIdx) { |
| 103 | // Need find index again. In case setTimeout/clearTimeout is invoked in the callback. |
| 104 | const idx = timeoutHandlers.indexOf(handler); |
| 105 | timeoutHandlers.splice(idx, 1); |
| 106 | try { |
| 107 | handler.callback(); |
| 108 | } |
| 109 | catch (e) { |
| 110 | // Catch error to avoid following tasks. |
| 111 | __VRT_LOG_ERRORS__(e.toString()); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | window.setInterval = function (cb, interval) { |
| 118 | const intervalFrame = Math.ceil(Math.max(interval || 0, 1) / FIXED_FRAME_TIME); |