Skip to content

Commit

Permalink
Check for win.performance before using it (#6316)
Browse files Browse the repository at this point in the history
* git diff HEAD~1

* check performance

* also check for performance.now

* nit
  • Loading branch information
zhouyx committed Nov 23, 2016
1 parent c60cb40 commit 1bb8712
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/intersection-observer-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const DEFAULT_THRESHOLD =
[0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4,
0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1];

const INIT_TIME = Date.now();

/**
* A function to get the element's current IntersectionObserverEntry
* regardless of the intersetion ratio. Only available when element is not
Expand Down Expand Up @@ -411,7 +413,8 @@ function calculateChangeEntry(
}

return /** @type {!IntersectionObserverEntry} */ ({
time: performance.now(),
time: (typeof performance !== 'undefined' && performance.now) ?
performance.now() : Date.now() - INIT_TIME,
rootBounds: rootBounds && DomRectFromLayoutRect(rootBounds),
boundingClientRect: DomRectFromLayoutRect(boundingClientRect),
intersectionRect: DomRectFromLayoutRect(intersection),
Expand Down

0 comments on commit 1bb8712

Please sign in to comment.