Skip to content

Commit 9560377

Browse files
committed
see what happen if || 0 is replaced with a function call
1 parent e1ad53e commit 9560377

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/compiler/jsexecute.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ runtimeFunctions.retire = `const retire = () => {
223223
thread.target.runtime.sequencer.retireThread(thread);
224224
}`;
225225

226+
runtimeFunctions.NaNToZero = `const NaNToZero = value => {
227+
if (isNaN(value)) return 0;
228+
return value;
229+
}`;
230+
226231
/**
227232
* Scratch cast to boolean.
228233
* Similar to Cast.toBoolean()

src/compiler/jsgen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ class JSGenerator {
185185
return `(+${this.descendInput(node.target.toType(InputType.BOOLEAN))})`;
186186
}
187187
if (node.target.isAlwaysType(InputType.NUMBER_OR_NAN)) {
188-
return `(${this.descendInput(node.target)} || 0)`;
188+
return `NaNToZero(${this.descendInput(node.target)})`;
189189
}
190-
return `(+${this.descendInput(node.target)} || 0)`;
190+
return `NaNToZero(+${this.descendInput(node.target)})`;
191191
case InputOpcode.CAST_NUMBER_OR_NAN:
192192
return `(+${this.descendInput(node.target)})`;
193193
case InputOpcode.CAST_NUMBER_INDEX:

0 commit comments

Comments
 (0)