From d3bb9632be5f9d7e2dfd286a099fcac10a8234df Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Mon, 18 Dec 2023 23:13:44 -0600 Subject: [PATCH] Add a warning on Math.random() Fixes https://github.com/hackclub/blot/issues/161 --- astro/src/lib/run.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/astro/src/lib/run.ts b/astro/src/lib/run.ts index 86909be28..a914342c3 100644 --- a/astro/src/lib/run.ts +++ b/astro/src/lib/run.ts @@ -38,6 +38,18 @@ const hConsole = { warn: (...args: [any, ...any[]]) => baseLogger('warn', ...args) } +let DETECTED_RANDOM_USAGE = false +const patchedRandom = (() => { + if (!DETECTED_RANDOM_USAGE) { + hConsole.warn(`Math.random() called! This could cause issues if done unintentionally. + https://github.com/hackclub/blot/issues/161`) + DETECTED_RANDOM_USAGE = true + } + return Math.__proto__.unpatchedRandom() +}) +Math.__proto__.unpatchedRandom = Math.random +Math.random = patchedRandom + let intervals: number[] = [] let timeouts: number[] = [] const patchedInterval = (