Skip to content

Commit

Permalink
Fix return type and declaration of setter callback
Browse files Browse the repository at this point in the history
Return type should be void and second function argument of type Napi::Value should be present.
See typedef: https://github.com/nodejs/node-addon-api/blob/295e560f5554c87d0a9dde6b73942ebd85fddb9d/napi.h#L1623
  • Loading branch information
timrach authored Nov 5, 2019
1 parent 295e560 commit b3609d3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions doc/class_property_descriptor.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Example : public Napi::ObjectWrap<Example> {
static Napi::FunctionReference constructor;
double _value;
Napi::Value GetValue(const Napi::CallbackInfo &info);
Napi::Value SetValue(const Napi::CallbackInfo &info);
void SetValue(const Napi::CallbackInfo &info, const Napi::Value &value);
};

Napi::Object Example::Init(Napi::Env env, Napi::Object exports) {
Expand Down Expand Up @@ -52,12 +52,11 @@ Napi::Value Example::GetValue(const Napi::CallbackInfo &info) {
return Napi::Number::New(env, this->_value);
}

Napi::Value Example::SetValue(const Napi::CallbackInfo &info, const Napi::Value &value) {
void Example::SetValue(const Napi::CallbackInfo &info, const Napi::Value &value) {
Napi::Env env = info.Env();
// ...
Napi::Number arg = value.As<Napi::Number>();
this->_value = arg.DoubleValue();
return this->GetValue(info);
}

// Initialize native add-on
Expand Down

0 comments on commit b3609d3

Please sign in to comment.