Page 1 of 1

Errors implementing CefV8Value

PostPosted: Wed Sep 04, 2019 6:18 am
by CephaluS
Hi all,

I'm on the early stages to create a CEF-based piece of software that already loads HTML and performs ExecuteJavaScript() and implements JS Extensions.

Now I want to implement accessors for my JS objects and I've created a class in a .cpp file with same exact code defined in CEF JS documentation:

Code: Select all
class MyV8Accessor : public CefV8Accessor {
public:
  MyV8Accessor() {}

  virtual bool Get(const CefString& name,
                   const CefRefPtr<CefV8Value> object,
                   CefRefPtr<CefV8Value>& retval,
                   CefString& exception) OVERRIDE {
    if (name == "myval") {
      // Return the value.
      retval = CefV8Value::CreateString(myval_);
      return true;
    }

    // Value does not exist.
    return false;
  }

  virtual bool Set(const CefString& name,
                   const CefRefPtr<CefV8Value> object,
                   const CefRefPtr<CefV8Value> value,
                   CefString& exception) OVERRIDE {
    if (name == "myval") {
      if (value.IsString()) {
        // Store the value.
        myval_ = value.GetStringValue();
      } else {
        // Throw an exception.
        exception = "Invalid value type";
      }
      return true;
    }

    // Value does not exist.
    return false;
  }

  // Variable used for storing the value.
  CefString myval_;

  // Provide the reference counting implementation for this class.
  IMPLEMENT_REFCOUNTING(MyV8Accessor);
};


I've prepended this code with #include "include/cef_v8.h".

I'm having two compiling errors (GCC). It seems CefV8Value cannot reach its member functions:

Code: Select all
CefAccesor.cpp:28:17: error: 'CefRefPtr<CefV8Value>' {aka 'const class scoped_refptr<CefV8Value>'} has no member named 'IsString'
   28 |       if (value.IsString()) {
      |                 ^~~~~~~~
CefAccesor.cpp:30:24: error: 'CefRefPtr<CefV8Value>' {aka 'const class scoped_refptr<CefV8Value>'} has no member named 'GetStringValue'
   30 |         myval_ = value.GetStringValue();
      |


I'm know I'm missing some obvious stuff I'm be able to solve.
Thanks for your help in advance.

Re: Errors implementing CefV8Value

PostPosted: Wed Sep 04, 2019 6:31 am
by amaitland
You are using the incorrect syntax(operator), see https://github.com/chromiumembedded/cef ... est.cc#L40 for an example.

You need to use an arrow operator as it's a pointer.

Re: Errors implementing CefV8Value

PostPosted: Wed Sep 04, 2019 6:41 am
by CephaluS
Thank you, amaitland.

I took for granted the code examples in the official documentation compiles right away I don't even bothered checking that code. I'm a bit ashamed not spotting myself this obvious issue... :oops:

Re: Errors implementing CefV8Value

PostPosted: Wed Sep 04, 2019 9:35 am
by magreenblatt
CephaluS wrote:I took for granted the code examples in the official documentation compiles right away I don't even bothered checking that code.

Sorry about that. I've fixed the JavaScriptIntegration Wiki examples.

Re: Errors implementing CefV8Value

PostPosted: Wed Sep 04, 2019 10:41 am
by CephaluS
Marshall, thank you for your efforts and for your amazing work on CEF.