| 102 | } |
| 103 | |
| 104 | void DefineProperties(const CallbackInfo& info) { |
| 105 | Object obj = info[0].As<Object>(); |
| 106 | String nameType = info[1].As<String>(); |
| 107 | Env env = info.Env(); |
| 108 | |
| 109 | Boolean trueValue = Boolean::New(env, true); |
| 110 | UserDataHolder* holder = new UserDataHolder(); |
| 111 | holder->value = 1234; |
| 112 | |
| 113 | if (nameType.Utf8Value() == "literal") { |
| 114 | obj.DefineProperties({ |
| 115 | PropertyDescriptor::Accessor(env, obj, "readonlyAccessor", TestGetter), |
| 116 | PropertyDescriptor::Accessor( |
| 117 | env, obj, "readwriteAccessor", TestGetter, TestSetter), |
| 118 | PropertyDescriptor::Accessor(env, |
| 119 | obj, |
| 120 | "readonlyAccessorWithUserData", |
| 121 | TestGetterWithUserData, |
| 122 | napi_property_attributes::napi_default, |
| 123 | reinterpret_cast<void*>(holder)), |
| 124 | PropertyDescriptor::Accessor(env, |
| 125 | obj, |
| 126 | "readwriteAccessorWithUserData", |
| 127 | TestGetterWithUserData, |
| 128 | TestSetterWithUserData, |
| 129 | napi_property_attributes::napi_default, |
| 130 | reinterpret_cast<void*>(holder)), |
| 131 | |
| 132 | PropertyDescriptor::Accessor<TestGetter>("readonlyAccessorT"), |
| 133 | PropertyDescriptor::Accessor<TestGetter, TestSetter>( |
| 134 | "readwriteAccessorT"), |
| 135 | PropertyDescriptor::Accessor<TestGetterWithUserData>( |
| 136 | "readonlyAccessorWithUserDataT", |
| 137 | napi_property_attributes::napi_default, |
| 138 | reinterpret_cast<void*>(holder)), |
| 139 | PropertyDescriptor::Accessor<TestGetterWithUserData, |
| 140 | TestSetterWithUserData>( |
| 141 | "readwriteAccessorWithUserDataT", |
| 142 | napi_property_attributes::napi_default, |
| 143 | reinterpret_cast<void*>(holder)), |
| 144 | |
| 145 | PropertyDescriptor::Value("readonlyValue", trueValue), |
| 146 | PropertyDescriptor::Value("readwriteValue", trueValue, napi_writable), |
| 147 | PropertyDescriptor::Value( |
| 148 | "enumerableValue", trueValue, napi_enumerable), |
| 149 | PropertyDescriptor::Value( |
| 150 | "configurableValue", trueValue, napi_configurable), |
| 151 | PropertyDescriptor::Function(env, obj, "function", TestFunction), |
| 152 | PropertyDescriptor::Function(env, |
| 153 | obj, |
| 154 | "functionWithUserData", |
| 155 | TestFunctionWithUserData, |
| 156 | napi_property_attributes::napi_default, |
| 157 | reinterpret_cast<void*>(holder)), |
| 158 | }); |
| 159 | } else if (nameType.Utf8Value() == "string") { |
| 160 | // VS2013 has lifetime issues when passing temporary objects into the |
| 161 | // constructor of another object. It generates code to destruct the object |