From 627dbf3c37ab64e33ad4431c6b569f6a36dd1723 Mon Sep 17 00:00:00 2001 From: Kevin Eady <8634912+KevinEady@users.noreply.github.com> Date: Mon, 21 Jun 2021 23:47:57 +0200 Subject: [PATCH] doc: update examples for context sensitivity Fixes: https://github.com/nodejs/node-addon-api/issues/1011 PR-URL: https://github.com/nodejs/node-addon-api/pull/1013 Reviewed-By: Michael Dawson Reviewed-By: Chengzhong Wu --- doc/class_property_descriptor.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/doc/class_property_descriptor.md b/doc/class_property_descriptor.md index a0ac0d38f..e5035c126 100644 --- a/doc/class_property_descriptor.md +++ b/doc/class_property_descriptor.md @@ -17,7 +17,6 @@ class Example : public Napi::ObjectWrap { Example(const Napi::CallbackInfo &info); private: - static Napi::FunctionReference constructor; double _value; Napi::Value GetValue(const Napi::CallbackInfo &info); void SetValue(const Napi::CallbackInfo &info, const Napi::Value &value); @@ -31,8 +30,9 @@ Napi::Object Example::Init(Napi::Env env, Napi::Object exports) { InstanceAccessor<&Example::GetValue>("readOnlyProp") }); - constructor = Napi::Persistent(func); - constructor.SuppressDestruct(); + Napi::FunctionReference *constructor = new Napi::FunctionReference(); + *constructor = Napi::Persistent(func); + env.SetInstanceData(constructor); exports.Set("Example", func); return exports; @@ -45,8 +45,6 @@ Example::Example(const Napi::CallbackInfo &info) : Napi::ObjectWrap(inf this->_value = value.DoubleValue(); } -Napi::FunctionReference Example::constructor; - Napi::Value Example::GetValue(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); return Napi::Number::New(env, this->_value);