MCPcopy Index your code
hub / github.com/nodejs/node-addon-api / OnCalledAsFunction

Method OnCalledAsFunction

test/objectwrap_function.cc:10–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8 : Napi::ObjectWrap<FunctionTest>(info) {}
9
10 static Napi::Value OnCalledAsFunction(const Napi::CallbackInfo& info) {
11 // If called with a "true" argument, throw an exeption to test the handling.
12 if (!info[0].IsUndefined() && MaybeUnwrap(info[0].ToBoolean())) {
13 NAPI_THROW(Napi::Error::New(info.Env(), "an exception"), Napi::Value());
14 }
15 // Otherwise, act as a factory.
16 std::vector<napi_value> args;
17 for (size_t i = 0; i < info.Length(); i++) args.push_back(info[i]);
18 return MaybeUnwrap(GetConstructor(info.Env()).New(args));
19 }
20
21 static void Initialize(Napi::Env env, Napi::Object exports) {
22 const char* name = "FunctionTest";

Callers

nothing calls this directly

Calls 5

MaybeUnwrapFunction · 0.85
EnvMethod · 0.80
LengthMethod · 0.80
NewMethod · 0.80
ValueClass · 0.50

Tested by

no test coverage detected