MCPcopy Create free account
hub / github.com/nodejs/node-addon-api / FuncRefObject

Class FuncRefObject

test/function_reference.cc:6–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4using namespace Napi;
5
6class FuncRefObject : public Napi::ObjectWrap<FuncRefObject> {
7 public:
8 FuncRefObject(const Napi::CallbackInfo& info)
9 : Napi::ObjectWrap<FuncRefObject>(info) {
10 Napi::Env env = info.Env();
11 int argLen = info.Length();
12 if (argLen <= 0 || !info[0].IsNumber()) {
13 Napi::TypeError::New(env, "First param should be a number")
14 .ThrowAsJavaScriptException();
15 return;
16 }
17 Napi::Number value = info[0].As<Napi::Number>();
18 this->_value = value.Int32Value();
19 }
20
21 Napi::Value GetValue(const Napi::CallbackInfo& info) {
22 int value = this->_value;
23 return Napi::Number::New(info.Env(), value);
24 }
25
26 private:
27 int _value;
28};
29
30namespace {
31

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected