Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for win.performance before using it #6316

Merged
merged 4 commits into from
Nov 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't pass presubmit as the Date.now() call can't be DCEd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presubmit is passing locally for me.
Well if I can't do this where should I get the init time? I can create one in IntersectionObserverPolyfill, but what about the export function #getIntersectionChangeEntry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's lint? Something will fail.

but what about the export function #getIntersectionChangeEntry

First call to calculateChangeEntry sets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing fails. Is it something with our test? Or do I still need to worry about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's because I'm only checking exports. While this won't be DCEd, it's fine as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!


/**
* 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