snowfrogdev / macao

A general purpose game playing A.I. framework based on the Monte Carlo tree search algorithm.
MIT License
23 stars 4 forks source link

fix(util): `now()` causing runtime exception on Chrome #29

Closed mbarbin closed 9 months ago

mbarbin commented 2 years ago

When trying to execute macao on Chrome, I was getting a Type error: Illegal invocation traced to the execution of now().

I looked briefly on the web for info and found this which gave me the idea for the fix: https://coderedirect.com/questions/116205/uncaught-typeerror-illegal-invocation-in-javascript

Using an eta-expension and thus making the call in the context of performance seems to fix the issue for me.

I am not claiming this is a complete fix, adding there for your consideration. Please adapt as desired. Thanks!

mbarbin commented 2 years ago

In the debug console on chrome, the following shows how to reproduce the core of the issue:

> var i = performance.now
undefined
> i()
Uncaught TypeError: Illegal invocation at <anonymous>:1:1 (anonymous) @ VM1365:1
> var j = () => performance.now()
undefined
> j()
2076082.200000003