Skip to content

Commit cb42808

Browse files
committed
Use Number.isNaN instead
1 parent ec8ba63 commit cb42808

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/compiler/jsexecute.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,11 @@ runtimeFunctions.retire = `const retire = () => {
226226
/**
227227
* Converts NaN to zero. Used to match Scratch's string-to-number.
228228
* Unlike (x || 0), -0 stays as -0 and is not converted to 0.
229-
* This function is written in this specific way to make it easy for browsers to inline.
230-
* We've found that calling isNaN() causes slowdowns in Firefox, so instead we utilize the
231-
* fact that NaN is the only JavaScript value that does not equal itself.
229+
* This function needs to be written such that it's very easy for browsers to inline it.
232230
* @param {number} value A number. Might be NaN.
233231
* @returns {number} A number. Never NaN.
234232
*/
235-
runtimeFunctions.toNotNaN = `const toNotNaN = value => value === value ? value : 0`;
233+
runtimeFunctions.toNotNaN = `const toNotNaN = value => Number.isNaN(value) ? 0 : value`;
236234

237235
/**
238236
* Scratch cast to boolean.

0 commit comments

Comments
 (0)