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

Function DefineProperties

test/object/object_deprecated.cc:21–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21void DefineProperties(const CallbackInfo& info) {
22 Object obj = info[0].As<Object>();
23 String nameType = info[1].As<String>();
24 Env env = info.Env();
25
26 if (nameType.Utf8Value() == "literal") {
27 obj.DefineProperties({
28 PropertyDescriptor::Accessor("readonlyAccessor", TestGetter),
29 PropertyDescriptor::Accessor(
30 "readwriteAccessor", TestGetter, TestSetter),
31 PropertyDescriptor::Function("function", TestFunction),
32 });
33 } else if (nameType.Utf8Value() == "string") {
34 // VS2013 has lifetime issues when passing temporary objects into the
35 // constructor of another object. It generates code to destruct the object
36 // as soon as the constructor call returns. Since this isn't a common case
37 // for using std::string objects, I'm refactoring the test to work around
38 // the issue.
39 std::string str1("readonlyAccessor");
40 std::string str2("readwriteAccessor");
41 std::string str7("function");
42
43 obj.DefineProperties({
44 PropertyDescriptor::Accessor(str1, TestGetter),
45 PropertyDescriptor::Accessor(str2, TestGetter, TestSetter),
46 PropertyDescriptor::Function(str7, TestFunction),
47 });
48 } else if (nameType.Utf8Value() == "value") {
49 obj.DefineProperties({
50 PropertyDescriptor::Accessor(Napi::String::New(env, "readonlyAccessor"),
51 TestGetter),
52 PropertyDescriptor::Accessor(
53 Napi::String::New(env, "readwriteAccessor"),
54 TestGetter,
55 TestSetter),
56 PropertyDescriptor::Function(Napi::String::New(env, "function"),
57 TestFunction),
58 });
59 }
60}
61
62} // end of anonymous namespace
63

Callers

nothing calls this directly

Calls 3

FunctionClass · 0.85
EnvMethod · 0.80
DefinePropertiesMethod · 0.80

Tested by

no test coverage detected