@@ -33,6 +33,10 @@ Value HasPropertyWithCStyleString(const CallbackInfo& info);
33
33
Value HasPropertyWithCppStyleString (const CallbackInfo& info);
34
34
35
35
static bool testValue = true ;
36
+ // Used to test void* Data() integrity
37
+ struct UserDataHolder {
38
+ int32_t value;
39
+ };
36
40
37
41
Value TestGetter (const CallbackInfo& info) {
38
42
return Boolean::New (info.Env (), testValue);
@@ -42,6 +46,16 @@ void TestSetter(const CallbackInfo& info) {
42
46
testValue = info[0 ].As <Boolean>();
43
47
}
44
48
49
+ Value TestGetterWithUserData (const CallbackInfo& info) {
50
+ const UserDataHolder* holder = reinterpret_cast <UserDataHolder*>(info.Data ());
51
+ return Number::New (info.Env (), holder->value );
52
+ }
53
+
54
+ void TestSetterWithUserData (const CallbackInfo& info) {
55
+ UserDataHolder* holder = reinterpret_cast <UserDataHolder*>(info.Data ());
56
+ holder->value = info[0 ].As <Number>().Int32Value ();
57
+ }
58
+
45
59
Value TestFunction (const CallbackInfo& info) {
46
60
return Boolean::New (info.Env (), true );
47
61
}
@@ -58,11 +72,15 @@ void DefineProperties(const CallbackInfo& info) {
58
72
Env env = info.Env ();
59
73
60
74
Boolean trueValue = Boolean::New (env, true );
75
+ UserDataHolder* holder = new UserDataHolder ();
76
+ holder->value = 1234 ;
61
77
62
78
if (nameType.Utf8Value () == " literal" ) {
63
79
obj.DefineProperties ({
64
80
PropertyDescriptor::Accessor (env, obj, " readonlyAccessor" , TestGetter),
65
81
PropertyDescriptor::Accessor (env, obj, " readwriteAccessor" , TestGetter, TestSetter),
82
+ PropertyDescriptor::Accessor (env, obj, " readonlyAccessorWithUserData" , TestGetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast <void *>(holder)),
83
+ PropertyDescriptor::Accessor (env, obj, " readwriteAccessorWithUserData" , TestGetterWithUserData, TestSetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast <void *>(holder)),
66
84
PropertyDescriptor::Value (" readonlyValue" , trueValue),
67
85
PropertyDescriptor::Value (" readwriteValue" , trueValue, napi_writable),
68
86
PropertyDescriptor::Value (" enumerableValue" , trueValue, napi_enumerable),
@@ -76,6 +94,8 @@ void DefineProperties(const CallbackInfo& info) {
76
94
// work around the issue.
77
95
std::string str1 (" readonlyAccessor" );
78
96
std::string str2 (" readwriteAccessor" );
97
+ std::string str1a (" readonlyAccessorWithUserData" );
98
+ std::string str2a (" readwriteAccessorWithUserData" );
79
99
std::string str3 (" readonlyValue" );
80
100
std::string str4 (" readwriteValue" );
81
101
std::string str5 (" enumerableValue" );
@@ -85,6 +105,8 @@ void DefineProperties(const CallbackInfo& info) {
85
105
obj.DefineProperties ({
86
106
PropertyDescriptor::Accessor (env, obj, str1, TestGetter),
87
107
PropertyDescriptor::Accessor (env, obj, str2, TestGetter, TestSetter),
108
+ PropertyDescriptor::Accessor (env, obj, str1a, TestGetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast <void *>(holder)),
109
+ PropertyDescriptor::Accessor (env, obj, str2a, TestGetterWithUserData, TestSetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast <void *>(holder)),
88
110
PropertyDescriptor::Value (str3, trueValue),
89
111
PropertyDescriptor::Value (str4, trueValue, napi_writable),
90
112
PropertyDescriptor::Value (str5, trueValue, napi_enumerable),
@@ -97,6 +119,10 @@ void DefineProperties(const CallbackInfo& info) {
97
119
Napi::String::New (env, " readonlyAccessor" ), TestGetter),
98
120
PropertyDescriptor::Accessor (env, obj,
99
121
Napi::String::New (env, " readwriteAccessor" ), TestGetter, TestSetter),
122
+ PropertyDescriptor::Accessor (env, obj,
123
+ Napi::String::New (env, " readonlyAccessorWithUserData" ), TestGetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast <void *>(holder)),
124
+ PropertyDescriptor::Accessor (env, obj,
125
+ Napi::String::New (env, " readwriteAccessorWithUserData" ), TestGetterWithUserData, TestSetterWithUserData, napi_property_attributes::napi_default, reinterpret_cast <void *>(holder)),
100
126
PropertyDescriptor::Value (
101
127
Napi::String::New (env, " readonlyValue" ), trueValue),
102
128
PropertyDescriptor::Value (
0 commit comments