Skip to content

Commit 0db6709

Browse files
authoredJun 20, 2023
fix: compat with frozen Math (#3527)
1 parent 150cfaa commit 0db6709

File tree

2 files changed

+0
-8
lines changed

2 files changed

+0
-8
lines changed
 

‎packages/browser/src/client/rpc.ts

-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@ import type {
44
import type { VitestClient } from '@vitest/ws-client'
55

66
const { get } = Reflect
7-
const safeRandom = Math.random
87

98
function withSafeTimers(getTimers: typeof getSafeTimers, fn: () => void) {
109
const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getTimers()
1110

1211
const currentSetTimeout = globalThis.setTimeout
1312
const currentClearTimeout = globalThis.clearTimeout
14-
const currentRandom = globalThis.Math.random
1513
const currentNextTick = globalThis.process.nextTick
1614
const currentSetImmediate = globalThis.setImmediate
1715
const currentClearImmediate = globalThis.clearImmediate
1816

1917
try {
2018
globalThis.setTimeout = setTimeout
2119
globalThis.clearTimeout = clearTimeout
22-
globalThis.Math.random = safeRandom
2320
globalThis.process.nextTick = nextTick
2421
globalThis.setImmediate = setImmediate
2522
globalThis.clearImmediate = clearImmediate
@@ -30,7 +27,6 @@ function withSafeTimers(getTimers: typeof getSafeTimers, fn: () => void) {
3027
finally {
3128
globalThis.setTimeout = currentSetTimeout
3229
globalThis.clearTimeout = currentClearTimeout
33-
globalThis.Math.random = currentRandom
3430
globalThis.setImmediate = currentSetImmediate
3531
globalThis.clearImmediate = currentClearImmediate
3632
nextTick(() => {

‎packages/vitest/src/runtime/rpc.ts

-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@ import {
44
import { getWorkerState } from '../utils/global'
55

66
const { get } = Reflect
7-
const safeRandom = Math.random
87

98
function withSafeTimers(fn: () => void) {
109
const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers()
1110

1211
const currentSetTimeout = globalThis.setTimeout
1312
const currentClearTimeout = globalThis.clearTimeout
14-
const currentRandom = globalThis.Math.random
1513
const currentNextTick = globalThis.process.nextTick
1614
const currentSetImmediate = globalThis.setImmediate
1715
const currentClearImmediate = globalThis.clearImmediate
1816

1917
try {
2018
globalThis.setTimeout = setTimeout
2119
globalThis.clearTimeout = clearTimeout
22-
globalThis.Math.random = safeRandom
2320
globalThis.process.nextTick = nextTick
2421
globalThis.setImmediate = setImmediate
2522
globalThis.clearImmediate = clearImmediate
@@ -30,7 +27,6 @@ function withSafeTimers(fn: () => void) {
3027
finally {
3128
globalThis.setTimeout = currentSetTimeout
3229
globalThis.clearTimeout = currentClearTimeout
33-
globalThis.Math.random = currentRandom
3430
globalThis.setImmediate = currentSetImmediate
3531
globalThis.clearImmediate = currentClearImmediate
3632
nextTick(() => {

0 commit comments

Comments
 (0)
Please sign in to comment.