Skip to content

Commit

Permalink
A bug fix - the undefined behavior of idleCallbacks's timeRemaining.
Browse files Browse the repository at this point in the history
Summary:
## Changelog:

[Android] [Fixed] - Fix a bug that returns a random number from callback argument `timeRemaining` of `idleCallbacks` registered by `requestIdleCallbacks`.

`global.performance.now()` returns a time from an unknown origin, while `frameTime` is epoch time. Thus, `global.performance.now() - frameTime` is just a random number rather than an elapsed time from the frame start time.

As a simple solution, I would suggest to use `Date.now()`.
Its resolution is lower than `frameTime` due to the security issue in JavaScript VM. So, it loses some precision, but, at least, it is not wrong.

Reviewed By: javache

Differential Revision: D40941461

fbshipit-source-id: b0094e181b97a844d133a9268fe48cd8c8fadfda
  • Loading branch information
mir597 authored and facebook-github-bot committed Nov 3, 2022
1 parent 890805d commit d9ab5e8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/Core/Timers/JSTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ const JSTimers = {

callIdleCallbacks: function (frameTime: number) {
if (
FRAME_DURATION - (global.performance.now() - frameTime) <
FRAME_DURATION - (Date.now() - frameTime) <
IDLE_CALLBACK_FRAME_DEADLINE
) {
return;
Expand Down

0 comments on commit d9ab5e8

Please sign in to comment.