本文整理汇总了Python中PyV8.JSContext方法的典型用法代码示例。如果您正苦于以下问题:Python PyV8.JSContext方法的具体用法?Python PyV8.JSContext怎么用?Python PyV8.JSContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyV8
的用法示例。
在下文中一共展示了PyV8.JSContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _exec_
# 需要导入模块: import PyV8 [as 别名]
# 或者: from PyV8 import JSContext [as 别名]
def _exec_(self, source):
source = '''\
(function() {{
{0};
{1};
}})()'''.format(
encode_unicode_codepoints(self._source),
encode_unicode_codepoints(source)
)
source = str(source)
# backward compatibility
with contextlib.nested(PyV8.JSContext(), PyV8.JSEngine()) as (ctxt, engine):
js_errors = (PyV8.JSError, IndexError, ReferenceError, SyntaxError, TypeError)
try:
script = engine.compile(source)
except js_errors as e:
raise exceptions.RuntimeError(e)
try:
value = script.run()
except js_errors as e:
raise exceptions.ProgramError(e)
return self.convert(value)
示例2: exec_
# 需要导入模块: import PyV8 [as 别名]
# 或者: from PyV8 import JSContext [as 别名]
def exec_(self, source):
source = '''\
(function() {{
{0};
{1};
}})()'''.format(
encode_unicode_codepoints(self._source),
encode_unicode_codepoints(source)
)
source = str(source)
import PyV8
import contextlib
#backward compatibility
with contextlib.nested(PyV8.JSContext(), PyV8.JSEngine()) as (ctxt, engine):
js_errors = (PyV8.JSError, IndexError, ReferenceError, SyntaxError, TypeError)
try:
script = engine.compile(source)
except js_errors as e:
raise RuntimeError(e)
try:
value = script.run()
except js_errors as e:
raise ProgramError(e)
return self.convert(value)
示例3: eval_pyv8
# 需要导入模块: import PyV8 [as 别名]
# 或者: from PyV8 import JSContext [as 别名]
def eval_pyv8(self, script):
rt = PyV8.JSContext()
rt.enter()
return rt.eval(script)
示例4: get_ctx
# 需要导入模块: import PyV8 [as 别名]
# 或者: from PyV8 import JSContext [as 别名]
def get_ctx():
if not hasattr(get_ctx, 'ctx'):
ctx = PyV8.JSContext()
ctx.enter()
get_ctx.ctx = ctx
return get_ctx.ctx
示例5: executeJS
# 需要导入模块: import PyV8 [as 别名]
# 或者: from PyV8 import JSContext [as 别名]
def executeJS(js_func_string, arg):
ctxt = PyV8.JSContext()
ctxt.enter()
func = ctxt.eval("({js})".format(js=js_func_string))
return func(arg)