Browse Source

fix(core): use window.performance for compatibility in JSDOM (#9700)

fix #9698
dev
GU Yiling 6 years ago
committed by Evan You
parent
commit
653c74e64e
  1. 6
      src/core/observer/scheduler.js

6
src/core/observer/scheduler.js

@ -47,9 +47,10 @@ let getNow: () => number = Date.now
// timestamp can either be hi-res (relative to page load) or low-res // 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 // (relative to UNIX epoch), so in order to compare time we have to use the
// same timestamp type when saving the flush timestamp. // same timestamp type when saving the flush timestamp.
if (inBrowser) {
const performance = window.performance
if ( if (
inBrowser && performance &&
window.performance &&
typeof performance.now === 'function' && typeof performance.now === 'function' &&
document.createEvent('Event').timeStamp <= performance.now() document.createEvent('Event').timeStamp <= performance.now()
) { ) {
@ -58,6 +59,7 @@ if (
// and we need to use the lo-res version for event listeners as well. // and we need to use the lo-res version for event listeners as well.
getNow = () => performance.now() getNow = () => performance.now()
} }
}
/** /**
* Flush both queues and run the watchers. * Flush both queues and run the watchers.

Loading…
Cancel
Save