How do I use instanceOf operator in native?

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.

How do I use instanceOf operator in native?

Postby mpgopala » Tue Mar 03, 2015 9:51 am

How do I use a feature similar to instanceOf operator in JS in native CEF? Here is what I am trying to achieve.

JS
Code: Select all
var A = function() {}
var a = new A();
isIntanceOf(a, A);


C++
Code: Select all
//Only the relevant parts of code is shown here...
bool MyHandler::Execute(...)
{
    if(name.compare("isInstanceOf") == 0)
    {
        CefRefPtr<CefV8Value> obj = arguments[0];
        CefRefPtr<CefV8Value> fn = arguments[1];
        bool instance = isInstanceOf(obj, fn); // How do I implement this?
        retval = CefV8Value::CreateBool(instance);
        return true;
    }
}


Thanks in advance for your help.
mpgopala
Newbie
 
Posts: 4
Joined: Tue Mar 03, 2015 9:42 am

Re: How do I use instanceOf operator in native?

Postby magreenblatt » Tue Mar 03, 2015 1:13 pm

instanceof is a JavaScript operator so you would need to execute it in JavaScript using CefV8Context::Eval(). The operands would need to be stored as variables in the context. For example, the following untested pseudocode:

Code: Select all
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
context->SetValue("_arg0", arguments[0], ...);
context->SetValue("_arg1", arguments[1], ...);

CefRefPtr<CefV8Value> result;
context->Eval("_arg0 instanceof _arg1", result, ...);
magreenblatt
Site Admin
 
Posts: 12404
Joined: Fri May 29, 2009 6:57 pm

Re: How do I use instanceOf operator in native?

Postby mpgopala » Tue Mar 10, 2015 10:02 am

Thanks, Let me try this out.
mpgopala
Newbie
 
Posts: 4
Joined: Tue Mar 03, 2015 9:42 am


Return to Support Forum

Who is online

Users browsing this forum: richardmgoodin and 43 guests