[jsinterp] Handle NaN in bitwise operators

Closes #6131
This commit is contained in:
pukkandan
2023-05-20 02:57:59 +05:30
parent f7f7a877bf
commit 1d7656184c
3 changed files with 20 additions and 1 deletions

View File

@@ -20,7 +20,12 @@ from .utils import (
def _js_bit_op(op):
def zeroise(x):
return 0 if x in (None, JS_Undefined) else x
if x in (None, JS_Undefined):
return 0
with contextlib.suppress(TypeError):
if math.isnan(x): # NB: NaN cannot be checked by membership
return 0
return x
def wrapped(a, b):
return op(zeroise(a), zeroise(b)) & 0xffffffff