Call a JS function from C++ node addon with v8.

93 views
Skip to first unread message

Philippe Richard

unread,
Jul 7, 2021, 2:25:02 PM7/7/21
to v8-users
Hi, 

I am trying to create a C++ function that will be able to call a JS function.

I am using node-gyp with v8 but and I'm not familiar with Napi and I have very basic understanding of the local / context / isolate. 

Although, I have already a working exemple of JS calling a C function. 

void CallCFunctionWithJS(const FunctionCallbackInfo<Value>& args) {

    Isolate* isolate = args.GetIsolate();
     function();

  args.GetReturnValue().Set(String::NewFromUtf8(isolate, "exit"));
}


The problem is : I try to achieve the opposite. 


void CallJSFunctionWithC(void)
{
  ??? console.log();   ???
}


Is there an easy way to create a function that will allow me to do this. 

If not, how can I send Async notification to my JS code when I receive a change of value in C. Thanks alot.




Philippe Richard

unread,
Jul 7, 2021, 2:27:01 PM7/7/21
to v8-users

My node version is v12.18.2
Reply all
Reply to author
Forward
0 new messages