[英]PyV8 throw error into JavaScript/get current line number
I'm using PyV8 and I'd like to disallow assigning javascript objects to my python objects because of a current memory leak bug with PyV8 . 我正在使用PyV8,并且由于当前PyV8存在内存泄漏错误,因此我想禁止将javascript对象分配给python对象。 I came upwith this code:
我想到了以下代码:
def __setattr__(self, name, val):
if isinstance(val, (PyV8.JSFunction, PyV8.JSObject)):
raise ValueError("Can't put js objects on py values")
object.__setattr__(self, name, val)
However, the traceback I get when I do this is not very helpful: 但是,执行此操作时得到的追溯不是很有帮助:
Traceback (most recent call last):
File "pyv8-bug-186.py", line 142, in <module>
""")
File "pyv8-bug-186.py", line 75, in run_case
obj = ctxt.eval(js)
ValueError: Can't put js objects on py values
Particularly, it gives no information at all about which javascript file was running or what the line number was, etc. I see two potential solutions: 特别是,它根本不提供有关正在运行哪个javascript文件或行号等的信息。我看到了两种可能的解决方案:
How would I go about doing either? 我该怎么做?
Not sure if this is by design, but for now, raise TypeError()
from within Python causes a javascript exception to be raised and displayed (along with line and column numbers). 不知道这是否是设计
raise TypeError()
,但就目前而言,从Python内部raise TypeError()
会引发并显示javascript异常(以及行号和列号)。 Great success! 巨大的成功!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.