From 0db670989ba477357874eedcd1104083234d4e3e Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 20 Jun 2023 05:31:02 -0700 Subject: [PATCH] fix: compat with frozen Math (#3527) --- packages/browser/src/client/rpc.ts | 4 ---- packages/vitest/src/runtime/rpc.ts | 4 ---- 2 files changed, 8 deletions(-) diff --git a/packages/browser/src/client/rpc.ts b/packages/browser/src/client/rpc.ts index 69daa0e56218..831d770062d9 100644 --- a/packages/browser/src/client/rpc.ts +++ b/packages/browser/src/client/rpc.ts @@ -4,14 +4,12 @@ import type { import type { VitestClient } from '@vitest/ws-client' const { get } = Reflect -const safeRandom = Math.random function withSafeTimers(getTimers: typeof getSafeTimers, fn: () => void) { const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getTimers() const currentSetTimeout = globalThis.setTimeout const currentClearTimeout = globalThis.clearTimeout - const currentRandom = globalThis.Math.random const currentNextTick = globalThis.process.nextTick const currentSetImmediate = globalThis.setImmediate const currentClearImmediate = globalThis.clearImmediate @@ -19,7 +17,6 @@ function withSafeTimers(getTimers: typeof getSafeTimers, fn: () => void) { try { globalThis.setTimeout = setTimeout globalThis.clearTimeout = clearTimeout - globalThis.Math.random = safeRandom globalThis.process.nextTick = nextTick globalThis.setImmediate = setImmediate globalThis.clearImmediate = clearImmediate @@ -30,7 +27,6 @@ function withSafeTimers(getTimers: typeof getSafeTimers, fn: () => void) { finally { globalThis.setTimeout = currentSetTimeout globalThis.clearTimeout = currentClearTimeout - globalThis.Math.random = currentRandom globalThis.setImmediate = currentSetImmediate globalThis.clearImmediate = currentClearImmediate nextTick(() => { diff --git a/packages/vitest/src/runtime/rpc.ts b/packages/vitest/src/runtime/rpc.ts index 1e2b6084db27..87db7476545a 100644 --- a/packages/vitest/src/runtime/rpc.ts +++ b/packages/vitest/src/runtime/rpc.ts @@ -4,14 +4,12 @@ import { import { getWorkerState } from '../utils/global' const { get } = Reflect -const safeRandom = Math.random function withSafeTimers(fn: () => void) { const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers() const currentSetTimeout = globalThis.setTimeout const currentClearTimeout = globalThis.clearTimeout - const currentRandom = globalThis.Math.random const currentNextTick = globalThis.process.nextTick const currentSetImmediate = globalThis.setImmediate const currentClearImmediate = globalThis.clearImmediate @@ -19,7 +17,6 @@ function withSafeTimers(fn: () => void) { try { globalThis.setTimeout = setTimeout globalThis.clearTimeout = clearTimeout - globalThis.Math.random = safeRandom globalThis.process.nextTick = nextTick globalThis.setImmediate = setImmediate globalThis.clearImmediate = clearImmediate @@ -30,7 +27,6 @@ function withSafeTimers(fn: () => void) { finally { globalThis.setTimeout = currentSetTimeout globalThis.clearTimeout = currentClearTimeout - globalThis.Math.random = currentRandom globalThis.setImmediate = currentSetImmediate globalThis.clearImmediate = currentClearImmediate nextTick(() => {