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

Function NormalJsCallback

test/maybe/check.cc:35–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35void NormalJsCallback(const CallbackInfo& info) {
36 Napi::Function fn = info[0].As<Function>();
37 uint32_t magic_number = info[1].As<Number>().Uint32Value();
38
39 Maybe<Value> ret = fn.Call({});
40
41 assert(ret.IsNothing() == false);
42 assert(ret.IsJust() == true);
43
44 Napi::Value unwrappedValue = ret.Unwrap();
45 assert(unwrappedValue.IsNumber() == true);
46
47 assert(unwrappedValue.As<Number>().Uint32Value() == magic_number);
48
49 unwrappedValue =
50 ret.UnwrapOr(Napi::Number::New(info.Env(), magic_number - 1));
51 assert(unwrappedValue.As<Number>().Uint32Value() == magic_number);
52
53 Napi::Value placeHolder = Napi::Number::New(info.Env(), magic_number - 1);
54 assert(ret.UnwrapTo(&placeHolder) == true);
55 assert(placeHolder.As<Number>().Uint32Value() == magic_number);
56}
57
58} // end anonymous namespace
59

Callers

nothing calls this directly

Calls 7

CallMethod · 0.80
IsNothingMethod · 0.80
IsJustMethod · 0.80
UnwrapMethod · 0.80
UnwrapOrMethod · 0.80
EnvMethod · 0.80
UnwrapToMethod · 0.80

Tested by

no test coverage detected