Skip to content

Commit

Permalink
Implement requestAnimationFrame using performance.now
Browse files Browse the repository at this point in the history
Shouldn't make a practical difference as w3c-hr-time uses browser-process-hrtime (thus no change in lockfile), but it simplifies things a tiny bit.
  • Loading branch information
SimenB authored and domenic committed Apr 1, 2018
1 parent dc672a2 commit c520198
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
12 changes: 3 additions & 9 deletions lib/jsdom/browser/Window.js
Expand Up @@ -30,10 +30,6 @@ const { matchesDontThrow } = require("../living/helpers/selectors");
const SessionHistory = require("../living/window/SessionHistory");
const { contextifyWindow } = require("./documentfeatures.js");

// Browserify's process implementation doesn't have hrtime, and this package is small so not much of a burden for
// Node.js users.
const hrtime = require("browser-process-hrtime");

const GlobalEventHandlersImpl = require("../living/nodes/GlobalEventHandlers-impl").implementation;
const WindowEventHandlersImpl = require("../living/nodes/WindowEventHandlers-impl").implementation;

Expand All @@ -56,8 +52,7 @@ function Window(options) {
EventTarget.setup(this);

const rawPerformance = new RawPerformance();
const windowInitialized = hrtime();

const windowInitialized = rawPerformance.now();

const window = this;

Expand Down Expand Up @@ -255,8 +250,7 @@ function Window(options) {

if (this._pretendToBeVisual) {
this.requestAnimationFrame = fn => {
const hr = hrtime(windowInitialized);
const hrInMicro = hr[0] * 1e3 + hr[1] / 1e6;
const timestamp = rawPerformance.now() - windowInitialized;
const fps = 1000 / 60;

return startTimer(
Expand All @@ -267,7 +261,7 @@ function Window(options) {
fn,
fps,
animationFrameCallbacks,
[hrInMicro]
[timestamp]
);
};
this.cancelAnimationFrame = stopTimer.bind(this, animationFrameCallbacks);
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -23,7 +23,6 @@
"acorn": "^5.3.0",
"acorn-globals": "^4.1.0",
"array-equal": "^1.0.0",
"browser-process-hrtime": "^0.1.2",
"cssom": ">= 0.3.2 < 0.4.0",
"cssstyle": ">= 0.2.37 < 0.3.0",
"data-urls": "^1.0.0",
Expand Down

0 comments on commit c520198

Please sign in to comment.