Minsky
dummy-addon.cc File Reference
#include <napi.h>
#include <exception>
#include <iostream>
Include dependency graph for dummy-addon.cc:

Go to the source code of this file.

Functions

Value RESTCall (const Napi::CallbackInfo &info)
 
Object Init (Env env, Object exports)
 

Function Documentation

◆ Init()

Object Init ( Env  env,
Object  exports 
)

Definition at line 55 of file dummy-addon.cc.

References RESTCall().

55  {
56  std::cout << "Init"<<std::endl;
57  exports.Set(String::New(env, "call"), Function::New(env, RESTCall));
58  return exports;
59 }
Value RESTCall(const Napi::CallbackInfo &info)
Definition: dummy-addon.cc:29
Here is the call graph for this function:

◆ RESTCall()

Value RESTCall ( const Napi::CallbackInfo &  info)

Definition at line 29 of file dummy-addon.cc.

Referenced by Init().

30 {
31  Env env = info.Env();
32  if (info.Length() < 1)
33  {
34  Napi::TypeError::New(env, "Needs to be call(endpoint[, arguments])").ThrowAsJavaScriptException();
35  return env.Null();
36  }
37 
38  try
39  {
40  return info[0];
41  }
42  catch (const std::exception& ex)
43  {
44  // throw C++ exception as Javascript exception
45  Napi::Error::New(env, ex.what()).ThrowAsJavaScriptException();
46  return env.Null();
47  }
48  catch (...)
49  {
50  Napi::Error::New(env, "unknown exception caught").ThrowAsJavaScriptException();
51  return env.Null();
52  }
53 }
Here is the caller graph for this function: