@@ -64,6 +64,11 @@ Value TestFunction(const CallbackInfo& info) {
64
64
return Boolean::New (info.Env (), true );
65
65
}
66
66
67
+ Value TestFunctionWithUserData (const CallbackInfo& info) {
68
+ UserDataHolder* holder = reinterpret_cast <UserDataHolder*>(info.Data ());
69
+ return Number::New (info.Env (), holder->value );
70
+ }
71
+
67
72
Array GetPropertyNames (const CallbackInfo& info) {
68
73
Object obj = info[0 ].As <Object>();
69
74
Array arr = obj.GetPropertyNames ();
@@ -104,6 +109,7 @@ void DefineProperties(const CallbackInfo& info) {
104
109
PropertyDescriptor::Value (" enumerableValue" , trueValue, napi_enumerable),
105
110
PropertyDescriptor::Value (" configurableValue" , trueValue, napi_configurable),
106
111
PropertyDescriptor::Function (env, obj, " function" , TestFunction),
112
+ PropertyDescriptor::Function (env, obj, " functionWithUserData" , TestFunctionWithUserData, napi_property_attributes::napi_default, reinterpret_cast <void *>(holder)),
107
113
});
108
114
} else if (nameType.Utf8Value () == " string" ) {
109
115
// VS2013 has lifetime issues when passing temporary objects into the constructor of another
@@ -125,6 +131,7 @@ void DefineProperties(const CallbackInfo& info) {
125
131
std::string str5 (" enumerableValue" );
126
132
std::string str6 (" configurableValue" );
127
133
std::string str7 (" function" );
134
+ std::string str8 (" functionWithUserData" );
128
135
129
136
obj.DefineProperties ({
130
137
PropertyDescriptor::Accessor (env, obj, str1, TestGetter),
@@ -148,6 +155,7 @@ void DefineProperties(const CallbackInfo& info) {
148
155
PropertyDescriptor::Value (str5, trueValue, napi_enumerable),
149
156
PropertyDescriptor::Value (str6, trueValue, napi_configurable),
150
157
PropertyDescriptor::Function (env, obj, str7, TestFunction),
158
+ PropertyDescriptor::Function (env, obj, str8, TestFunctionWithUserData, napi_property_attributes::napi_default, reinterpret_cast <void *>(holder)),
151
159
});
152
160
} else if (nameType.Utf8Value () == " value" ) {
153
161
obj.DefineProperties ({
@@ -184,6 +192,8 @@ void DefineProperties(const CallbackInfo& info) {
184
192
Napi::String::New (env, " configurableValue" ), trueValue, napi_configurable),
185
193
PropertyDescriptor::Function (env, obj,
186
194
Napi::String::New (env, " function" ), TestFunction),
195
+ PropertyDescriptor::Function (env, obj,
196
+ Napi::String::New (env, " functionWithUserData" ), TestFunctionWithUserData, napi_property_attributes::napi_default, reinterpret_cast <void *>(holder)),
187
197
});
188
198
}
189
199
}
0 commit comments