Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

TCefv8ValueRef.NewFunction returns nil

Post Reply
Albus

TCefv8ValueRef.NewFunction returns nil

Post 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.
Albus

Re: TCefv8ValueRef.NewFunction returns nil

Post 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.
Albus

Re: TCefv8ValueRef.NewFunction returns nil

Post by Albus »

Ok, now I have a problem. Even the subprocess can't create a Cefv8Value. How is this possible?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TCefv8ValueRef.NewFunction returns nil

Post 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.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TCefv8ValueRef.NewFunction returns nil

Post by salvadordf »

I just found this on stackoverflow :
https://stackoverflow.com/questions/988 ... utefunctio
Albus

Re: TCefv8ValueRef.NewFunction returns nil

Post 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.
Post Reply