reactiverse / es4x

🚀 fast JavaScript 4 Eclipse Vert.x
https://reactiverse.io/es4x/
Apache License 2.0
881 stars 75 forks source link

Type coercion problem in global setTimer #576

Closed chefhoobajoob closed 2 years ago

chefhoobajoob commented 2 years ago

Some js libraries making use of the setTimer function on es4x are sometimes generating exceptions with this message:

invokeMember (setTimer) on io.vertx.core.impl.VertxImpl@2c930868 failed due to: Cannot convert 'NaN'(language: Java, type: java.lang.Double) to Java type 'long': Invalid or lossy primitive coercion

Looks like there might be a type handling issue in the es4x implementation

pmlopes commented 2 years ago

In the polyfill we're coercing the argument to number with Number(value) which can return NaN. We should either use the function isNaN() or do an extra verification against x !== x

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN

Do not confuse with Number.isNaN()