Page 1 of 1

TCefv8ValueRef.NewFunction returns nil

Posted: Wed Mar 21, 2018 11:47 am
by Albus
Hi, in my code I'm recieving a ProcessMessage in the main process (comming from a subprocess). Now I'm trying to create a ICefv8Value Function with TCefv8ValueRef.NewFunction('name', Self). But it returns nil.
This error occures only in multi process mode. If I run my app in single process mode, everything works fine.

Re: TCefv8ValueRef.NewFunction returns nil

Posted: Wed Mar 21, 2018 3:53 pm
by Albus
I just found out that TCefv8ValueRef is generaly not working in my main process if I use the multi process mode. Every attemp to create a Cefv8Value fails with nil.

Re: TCefv8ValueRef.NewFunction returns nil

Posted: Thu Mar 22, 2018 7:22 am
by Albus
Ok, now I have a problem. Even the subprocess can't create a Cefv8Value. How is this possible?

Re: TCefv8ValueRef.NewFunction returns nil

Posted: Thu Mar 22, 2018 8:06 am
by salvadordf
Here is the original source code where CEF3 defines all v8 related classes :
https://github.com/chromiumembedded/cef ... _v8_capi.h

As you can see in CEF4Delphi code, all "TCefv8ValueRef.New..." class functions call CEF3 functions like : cef_v8value_create_int, cef_v8value_create_object, cef_v8value_create_string, etc.

For example, cef_v8value_create_object has these comments in CEF3 code :

Code: Select all

///
// Create a new cef_v8value_t object of type object with optional accessor
// and/or interceptor. This function should only be called from within the scope
// of a cef_render_process_handler_t, cef_v8handler_t or cef_v8accessor_t
// callback, or in combination with calling enter() and exit() on a stored
// cef_v8context_t reference.
///
This is what the CEF API say about CefV8Value :
http://magpcss.org/ceforum/apidocs3/pro ... Value.html
Class representing a V8 value handle. V8 handles can only be accessed from the thread on which they are created. Valid threads for creating a V8 handle include the render process main thread (TID_RENDERER) and WebWorker threads. A task runner for posting tasks on the associated thread can be retrieved via the CefV8Context::GetTaskRunner() method.

Re: TCefv8ValueRef.NewFunction returns nil

Posted: Thu Mar 22, 2018 8:08 am
by salvadordf
I just found this on stackoverflow :
https://stackoverflow.com/questions/988 ... utefunctio

Re: TCefv8ValueRef.NewFunction returns nil

Posted: Thu Mar 22, 2018 8:43 am
by Albus
Thank you. I tried the solution with entering a v8context manually, but this also doesn't worked, because browser.MainFrame.Getv8Context (inside the ProcessMessageReceived in the main process) returns nil.
Therefore I worked around this and created my own implementation of the ICefv8Value Interface (with just the most needed functions). This works currently fine, however this is not really a clean solution.