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

Function RefMoveAssignTests

test/reference.cc:8–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6static Reference<Buffer<uint8_t>> weak;
7
8static void RefMoveAssignTests(const Napi::CallbackInfo& info) {
9 Napi::Object obj = Napi::Object::New(info.Env());
10 obj.Set("tPro", "tTEST");
11 Napi::Reference<Napi::Object> ref = Napi::Reference<Napi::Object>::New(obj);
12 ref.SuppressDestruct();
13
14 napi_ref obj_ref = static_cast<napi_ref>(ref);
15 Napi::Reference<Napi::Object> existingRef =
16 Napi::Reference<Napi::Object>(info.Env(), obj_ref);
17 assert(ref == existingRef);
18 assert(!(ref != existingRef));
19
20 std::string val =
21 MaybeUnwrap(existingRef.Value().Get("tPro")).As<Napi::String>();
22 assert(val == "tTEST");
23 // ------------------------------------------------------------ //
24 Napi::Reference<Napi::Object> copyMoveRef = std::move(existingRef);
25 assert(copyMoveRef == ref);
26
27 Napi::Reference<Napi::Object> copyAssignRef;
28 copyAssignRef = std::move(copyMoveRef);
29 assert(copyAssignRef == ref);
30}
31
32static void ReferenceRefTests(const Napi::CallbackInfo& info) {
33 Napi::Object obj = Napi::Object::New(info.Env());

Callers

nothing calls this directly

Calls 6

MaybeUnwrapFunction · 0.85
EnvMethod · 0.80
SetMethod · 0.80
SuppressDestructMethod · 0.80
GetMethod · 0.80
ValueMethod · 0.80

Tested by

no test coverage detected