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

Function SetWithTempString

test/object_reference.cc:34–48  ·  view source on GitHub ↗

Test that Set() with std::string key and value accepts temporaries (rvalues). This verifies that the parameter is `const std::string&` rather than `std::string&`.

Source from the content-addressed store, hash-verified

32// This verifies that the parameter is `const std::string&` rather than
33// `std::string&`.
34void SetWithTempString(const Napi::CallbackInfo& info) {
35 Env env = info.Env();
36 HandleScope scope(env);
37
38 Napi::ObjectReference ref = Persistent(Object::New(env));
39 ref.SuppressDestruct();
40
41 ref.Set(std::string("tempKey"), std::string("tempValue"));
42 ref.Set(std::string("anotherKey"), info[0].As<Napi::String>().Utf8Value());
43
44 assert(MaybeUnwrap(ref.Get("tempKey")).As<Napi::String>().Utf8Value() ==
45 "tempValue");
46 assert(MaybeUnwrap(ref.Get("anotherKey")).As<Napi::String>().Utf8Value() ==
47 info[0].As<Napi::String>().Utf8Value());
48}
49
50void MoveOperatorsTest(const Napi::CallbackInfo& info) {
51 Napi::ObjectReference existingRef;

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected