Skip to content

Commit

Permalink
fix(core): use window.performance for compatibility in JSDOM (fix vue…
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo committed Mar 14, 2019
1 parent 43115e0 commit b31d02a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/core/observer/scheduler.js
Expand Up @@ -47,16 +47,18 @@ let getNow: () => number = Date.now
// timestamp can either be hi-res (relative to page load) or low-res
// (relative to UNIX epoch), so in order to compare time we have to use the
// same timestamp type when saving the flush timestamp.
if (
inBrowser &&
window.performance &&
typeof performance.now === 'function' &&
document.createEvent('Event').timeStamp <= performance.now()
) {
// if the event timestamp is bigger than the hi-res timestamp
// (which is evaluated AFTER) it means the event is using a lo-res timestamp,
// and we need to use the lo-res version for event listeners as well.
getNow = () => performance.now()
if (inBrowser) {
const performance = window.performance
if (
performance &&
typeof performance.now === 'function' &&
document.createEvent('Event').timeStamp <= performance.now()
) {
// if the event timestamp is bigger than the hi-res timestamp
// (which is evaluated AFTER) it means the event is using a lo-res timestamp,
// and we need to use the lo-res version for event listeners as well.
getNow = () => performance.now()
}
}

/**
Expand Down

0 comments on commit b31d02a

Please sign in to comment.