dukpy icon indicating copy to clipboard operation
dukpy copied to clipboard

Math.trunc not supported by evaljs

Open ypiguet-epfl opened this issue 2 years ago • 4 comments

In dukpy.evaljs, the math function Math.trunc raises the exception _dukpy.JSRuntimeError: TypeError: undefined not callable. Other math functions, such as Math.floor, work.

To reproduce in Python 3 (tested in 3.6.9):

>>> import dukpy
>>> print(dukpy.evaljs("Math.trunc(2.3)"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xxx/.local/lib/python3.6/site-packages/dukpy/evaljs.py", line 134, in evaljs
    return JSInterpreter().evaljs(code, **kwargs)
  File "/home/xxx/.local/lib/python3.6/site-packages/dukpy/evaljs.py", line 57, in evaljs
    res = _dukpy.eval_string(self, jscode, jsvars)
_dukpy.JSRuntimeError: TypeError: undefined not callable
        duk_js_call.c:776
        eval src/pyduktape.c:1 preventsyield
>>> print(dukpy.evaljs("Math.floor(2.3)"))
2

ypiguet-epfl avatar Jul 06 '22 09:07 ypiguet-epfl

I'd recommend adding PRs with xfailing tests for such cases so there's an acceptance test in the tree whenever somebody gets around to fixing it.

webknjaz avatar Jul 07 '22 09:07 webknjaz

You must be using some old version. I wrote a test and it succeeds on master.

webknjaz avatar Jul 07 '22 10:07 webknjaz

https://github.com/amol-/dukpy/pull/63

webknjaz avatar Jul 07 '22 10:07 webknjaz

I had installed the default version for pip:

$ python3 -m pip install --force-reinstall dukpy
Collecting dukpy
  Using cached https://files.pythonhosted.org/packages/92/a5/4bae803eb58ea342f18d73a42f8510ca4e0cc095856a32b8feca23d6445e/dukpy-0.2.3-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: dukpy
Successfully installed dukpy-0.2.3

With the current version on github, installing with

$ python3 -m pip install --force-reinstall git+https://github.com/amol-/dukpy/

you're right, it works. Thank you very much.

ypiguet-epfl avatar Jul 07 '22 11:07 ypiguet-epfl