From b31d02abf3d6ff1e6227a0f63971188655cdaf80 Mon Sep 17 00:00:00 2001 From: Justineo Date: Thu, 14 Mar 2019 23:19:19 +0800 Subject: [PATCH] fix(core): use window.performance for compatibility in JSDOM (fix #9698) --- src/core/observer/scheduler.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/core/observer/scheduler.js b/src/core/observer/scheduler.js index b0583ed12bd..20170cc006d 100644 --- a/src/core/observer/scheduler.js +++ b/src/core/observer/scheduler.js @@ -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() + } } /**