You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/object_wrappers.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,6 +54,18 @@ class ObjectWrap {
54
54
55
55
See the Node documentation on [Wrapping C++ Objects](https://nodejs.org/api/addons.html#addons_wrapping_c_objects) for more details.
56
56
57
+
### This vs. Holder
58
+
59
+
When calling `Unwrap`, it is important that the argument is indeed some JavaScript object which got wrapped by a `Wrap` call for this class or any derived class.
60
+
The `Signature` installed by [`Nan::SetPrototypeMethod()`](methods.md#api_nan_set_prototype_method) does ensure that `info.Holder()` is just such an instance.
61
+
In Node 0.12 and later, `info.This()` will also be of such a type, since otherwise the invocation will get rejected.
62
+
However, in Node 0.10 and before it was possible to invoke a method on a JavaScript object which just had the extension type in its prototype chain.
63
+
In such a situation, calling `Unwrap` on `info.This()` will likely lead to a failed assertion causing a crash, but could lead to even more serious corruption.
64
+
65
+
On the other hand, calling `Unwrap` in an [accessor](methods.md#api_nan_set_accessor) should not use `Holder()` if the accessor is defined on the prototype.
66
+
So either define your accessors on the instance template,
67
+
or use `This()` after verifying that it is indeed a valid object.
68
+
57
69
### Examples
58
70
59
71
#### Basic
@@ -93,12 +105,12 @@ class MyObject : public Nan::ObjectWrap {
0 commit comments