MiniRacer.execute failure
SeaHOH opened this issue · 3 comments
SeaHOH commented
Steps to reproduce
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from py_mini_racer import MiniRacer
>>> ctx = MiniRacer()
>>> ctx.eval('var a = 1')
>>>
>>> ctx.execute('var b = 1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "M:\site-packages\py_mini_racer\py_mini_racer.py", line 235, in execute
ret = self.eval(wrapped_expr, timeout=timeout, max_memory=max_memory)
File "M:\site-packages\py_mini_racer\py_mini_racer.py", line 221, in eval
return MiniRacerValue(self, res).to_python()
File "M:\site-packages\py_mini_racer\py_mini_racer.py", line 403, in to_python
self._raise_from_error()
File "M:\site-packages\py_mini_racer\py_mini_racer.py", line 391, in _raise_from_error
raise JSParseException(msg)
py_mini_racer.py_mini_racer.JSParseException: b'Unknown JavaScript error during parse'
>>>
>>> ctx.eval('''
... function foo() {
... return 1
... }
... foo()''')
1
>>>
>>> ctx.execute('''
... function bar() {
... return 1
... }
... bar()''')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "M:\site-packages\py_mini_racer\py_mini_racer.py", line 235, in execute
ret = self.eval(wrapped_expr, timeout=timeout, max_memory=max_memory)
File "M:\site-packages\py_mini_racer\py_mini_racer.py", line 221, in eval
return MiniRacerValue(self, res).to_python()
File "M:\site-packages\py_mini_racer\py_mini_racer.py", line 403, in to_python
self._raise_from_error()
File "M:\site-packages\py_mini_racer\py_mini_racer.py", line 391, in _raise_from_error
raise JSParseException(msg)
py_mini_racer.py_mini_racer.JSParseException: b'Unknown JavaScript error during parse'
>>>
Expected behavior
All expressions can be evaluated via MiniRacer.execute
as same as MiniRacer.eval
.
Actual behavior
Some expressions can not be evaluated via MiniRacer.execute
.
System configuration
PyMiniRacer version:
0.6.0 win_amd64
Python version:
3.10.1
SeaHOH commented
I had tried use eval
to instead of function
in source code of MiniRacer.execute
, it works. But new issue occurred, the scope has been limited.
SeaHOH commented
Hmm... is there it possible to add a function likes res = ext.mr_json_stringify(ctx, res)
, intead of the wrapped expression string?
SeaHOH commented
I have used esprima to avoid this issue.
SeaHOH/jsengine@5ebe633
SeaHOH/jsengine@d8eedd3