# Copyright (c) 2012-2014 The CEF Python authors. All rights reserved.
# License: New BSD License.
# Website: http://code.google.com/p/cefpython/
cdef public cpp_bool V8FunctionHandler_Execute(
CefRefPtr[CefV8Context] v8Context,
int pythonCallbackId,
CefString& cefFuncName,
CefRefPtr[CefV8Value] cefObject, # receiver ('this' object) of the function.
CefV8ValueList& v8Arguments,
CefRefPtr[CefV8Value]& cefReturnValue,
CefString& cefException
) except * with gil:
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef JavascriptBindings javascriptBindings
cdef cpp_vector[CefRefPtr[CefV8Value]].iterator iterator
cdef CefRefPtr[CefV8Value] cefValue
cdef object pythonCallback
cdef list arguments
cdef str functionName
cdef object pyReturnValue
cdef object pyFunction
cdef str objectName
cdef str objectMethod
try:
if pythonCallbackId:
pythonCallback = GetPythonCallback(pythonCallbackId)
arguments = []
iterator = v8Arguments.begin()
while iterator != v8Arguments.end():
cefValue = deref(iterator)
arguments.append(V8ToPyValue(cefValue, v8Context))
preinc(iterator)
pyReturnValue = pythonCallback(*arguments)
# Can't use "arg = " for a referenced argument, bug in Cython,
# see comment in RequestHandler_OnProtocolExecution() for
# more details.
cefReturnValue.swap(PyToV8Value(pyReturnValue, v8Context))
return