- Code: Select all
void ClientApp::OnWebKitInitialized()
{
std::string app_code =
"var app;"
"if (!app)"
" app = {};"
"(function() {"
" app.MyJsFunction = function() {"
" native function MyJsFunction();"
" return MyJsFunction();"
" };"
"})();;";
CefRegisterExtension( "v8/app", app_code, new ClientV8ExtensionHandler(this) );
}
- Code: Select all
bool ClientV8ExtensionHandler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, const CefV8ValueList &arguments, CefRefPtr<CefV8Value> &retval, CefString &exception)
{
if (name == "MyJsFunction") {
//CefRefPtr<CefV8Value> obj = CefV8Value::CreateArray(0);
CefRefPtr<CefV8Value> obj = CefV8Value::CreateObject(NULL, NULL);
//CefRefPtr<CefV8Value> obj = CefV8Value::CreateUndefined();
retval = obj;
return true;
}
return false;
}
All of this 3 examples - CefV8Value::CreateArray(0), CefV8Value::CreateObject(NULL, NULL), CefV8Value::CreateUndefined() - crashes the program if in my JS i will call "var a = window.app.MyJsFunction()". I understand the thing about v8 context and about Enter() and Exit() methods. But inside ClientV8ExtensionHandler::Execute we are already in context right? What is possibly am I doing wrong? Thanks.