From b21cfa96102c81eaa12b54783b4ccdb4ea1855bf Mon Sep 17 00:00:00 2001 From: Marly Fleitas Date: Thu, 31 Mar 2022 22:38:41 +0200 Subject: [PATCH] doc: clarify ObjectWrap weak ref behavior (#1155) Refs: https://github.com/nodejs/node/pull/42461 We currently defer finalizer callbacks until the loop is idle. Warn users that the weak reference on ObjectWraps isn't guaranteed to be valid just because the object hasn't been finalized (destructed) yet. --- doc/object_wrap.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/object_wrap.md b/doc/object_wrap.md index 0b9dacd..4354664 100644 --- a/doc/object_wrap.md +++ b/doc/object_wrap.md @@ -16,6 +16,10 @@ be directly invoked from JavaScript. The **wrap** word refers to a way of grouping methods and state of the class because it will be necessary write custom code to bridge each of your C++ class methods. +**Caution:** When the JavaScript object is garbage collected, the call to the +C++ destructor may be deferred until a later time. Within that period, +`Value()` will return an empty value. + ## Example ```cpp