Skip to content

Commit 653c74e

Browse files
Justineoyyx990803
authored andcommittedMar 15, 2019
fix(core): use window.performance for compatibility in JSDOM (#9700)
fix #9698
1 parent 43115e0 commit 653c74e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed
 

‎src/core/observer/scheduler.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ let getNow: () => number = Date.now
4747
// timestamp can either be hi-res (relative to page load) or low-res
4848
// (relative to UNIX epoch), so in order to compare time we have to use the
4949
// same timestamp type when saving the flush timestamp.
50-
if (
51-
inBrowser &&
52-
window.performance &&
53-
typeof performance.now === 'function' &&
54-
document.createEvent('Event').timeStamp <= performance.now()
55-
) {
56-
// if the event timestamp is bigger than the hi-res timestamp
57-
// (which is evaluated AFTER) it means the event is using a lo-res timestamp,
58-
// and we need to use the lo-res version for event listeners as well.
59-
getNow = () => performance.now()
50+
if (inBrowser) {
51+
const performance = window.performance
52+
if (
53+
performance &&
54+
typeof performance.now === 'function' &&
55+
document.createEvent('Event').timeStamp <= performance.now()
56+
) {
57+
// if the event timestamp is bigger than the hi-res timestamp
58+
// (which is evaluated AFTER) it means the event is using a lo-res timestamp,
59+
// and we need to use the lo-res version for event listeners as well.
60+
getNow = () => performance.now()
61+
}
6062
}
6163

6264
/**

0 commit comments

Comments
 (0)
Please sign in to comment.