dukpy
dukpy copied to clipboard
Math.trunc not supported by evaljs
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
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.
You must be using some old version. I wrote a test and it succeeds on master.
https://github.com/amol-/dukpy/pull/63
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.