Problem with v8 create zero size array or NULL object

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Problem with v8 create zero size array or NULL object

Postby payalord » Sun Mar 18, 2018 12:34 am

Hi, i have problem when creating zero size array or null object inside "ClientV8ExtensionHandler::Execute" function. For example:

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.
payalord
Techie
 
Posts: 21
Joined: Sun Jan 07, 2018 8:21 am

Re: Problem with v8 create zero size array or NULL object

Postby payalord » Sun Mar 18, 2018 12:40 am

What I'm trying to achieve is that MyJsFunction will return or empty array similar like when we do in JS: "var a = [];" or empty object: "var a = {};" for example. So MyJsFunction must return or this "[]" or this "{}".
payalord
Techie
 
Posts: 21
Joined: Sun Jan 07, 2018 8:21 am

Re: Problem with v8 create zero size array or NULL object

Postby payalord » Mon Mar 19, 2018 3:21 am

I found the problem. It is not CEF related. That was my own problem in the code on another place. Now everything works fine. And program not crashes.
payalord
Techie
 
Posts: 21
Joined: Sun Jan 07, 2018 8:21 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 20 guests