Errors implementing CefV8Value

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.

Errors implementing CefV8Value

Postby CephaluS » Wed Sep 04, 2019 6:18 am

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.
CephaluS
Techie
 
Posts: 21
Joined: Sun Jan 06, 2019 5:22 pm

Re: Errors implementing CefV8Value

Postby amaitland » Wed Sep 04, 2019 6:31 am

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.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Errors implementing CefV8Value

Postby CephaluS » Wed Sep 04, 2019 6:41 am

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:
CephaluS
Techie
 
Posts: 21
Joined: Sun Jan 06, 2019 5:22 pm

Re: Errors implementing CefV8Value

Postby magreenblatt » Wed Sep 04, 2019 9:35 am

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.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Errors implementing CefV8Value

Postby CephaluS » Wed Sep 04, 2019 10:41 am

Marshall, thank you for your efforts and for your amazing work on CEF.
CephaluS
Techie
 
Posts: 21
Joined: Sun Jan 06, 2019 5:22 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 40 guests