本文整理匯總了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)