[jsinterp] Fix bitwise operations (#15985)

Authored by: bashonly
This commit is contained in:
bashonly
2026-02-17 23:10:18 +00:00
committed by GitHub
parent abade83f8d
commit 62574f5763
3 changed files with 62 additions and 36 deletions
+9 -1
View File
@@ -18,6 +18,14 @@ from .utils import (
)
def int_to_int32(n):
"""Converts an integer to a signed 32-bit integer"""
n &= 0xFFFFFFFF
if n & 0x80000000:
return n - 0x100000000
return n
def _js_bit_op(op):
def zeroise(x):
if x in (None, JS_Undefined):
@@ -28,7 +36,7 @@ def _js_bit_op(op):
return int(float(x))
def wrapped(a, b):
return op(zeroise(a), zeroise(b)) & 0xffffffff
return int_to_int32(op(int_to_int32(zeroise(a)), int_to_int32(zeroise(b))))
return wrapped