Skip to content

Commit

Permalink
Merge pull request #215 from hackclub/add-warning-on-math-random
Browse files Browse the repository at this point in the history
Add a warning on Math.random()
  • Loading branch information
leomcelroy authored Dec 19, 2023
2 parents 1e5d619 + d3bb963 commit 12aae33
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions astro/src/lib/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

1 comment on commit 12aae33

@vercel
Copy link

@vercel vercel bot commented on 12aae33 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blot – ./astro

blot-git-main.hackclub.dev
blot.hackclub.dev

Please sign in to comment.