(beforeTick: number)
| 353 | } |
| 354 | |
| 355 | private async _callFirstTimer(beforeTick: number): Promise<{ timerFound: boolean, error?: Error }> { |
| 356 | const timer = this._takeFirstTimer(beforeTick); |
| 357 | if (!timer) |
| 358 | return { timerFound: false }; |
| 359 | |
| 360 | this._duringTick = true; |
| 361 | try { |
| 362 | if (typeof timer.func !== 'function') { |
| 363 | let error: Error | undefined; |
| 364 | try { |
| 365 | // Using global this is not correct here, |
| 366 | // but it is already broken since the eval scope is different from the one |
| 367 | // on the original call site. |
| 368 | // eslint-disable-next-line no-restricted-globals |
| 369 | (() => { globalThis.eval(timer.func); })(); |
| 370 | } catch (e) { |
| 371 | error = e; |
| 372 | } |
| 373 | await new Promise<void>(f => this._embedder.setTimeout(f)); |
| 374 | return { timerFound: true, error }; |
| 375 | } |
| 376 | |
| 377 | let args = timer.args; |
| 378 | if (timer.type === TimerType.AnimationFrame) |
| 379 | args = [this._now.ticks]; |
| 380 | else if (timer.type === TimerType.IdleCallback) |
| 381 | args = [{ didTimeout: false, timeRemaining: () => 0 }]; |
| 382 | |
| 383 | let error: Error | undefined; |
| 384 | try { |
| 385 | timer.func.apply(null, args); |
| 386 | } catch (e) { |
| 387 | error = e; |
| 388 | } |
| 389 | await new Promise<void>(f => this._embedder.setTimeout(f)); |
| 390 | return { timerFound: true, error }; |
| 391 | } finally { |
| 392 | this._duringTick = false; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | getTimeToNextFrame() { |
| 397 | // When `window.requestAnimationFrame` is the first call in the page, |
no test coverage detected