node-addon-api 2.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/.clang-format +111 -0
  2. package/.github/workflows/ci.yml +55 -0
  3. package/.github/workflows/linter.yml +24 -0
  4. package/.github/workflows/stale.yml +18 -0
  5. package/.travis.yml +1 -5
  6. package/CHANGELOG.md +237 -23
  7. package/README.md +101 -31
  8. package/appveyor.yml +3 -14
  9. package/benchmark/README.md +47 -0
  10. package/benchmark/binding.gyp +25 -0
  11. package/benchmark/function_args.cc +217 -0
  12. package/benchmark/function_args.js +60 -0
  13. package/benchmark/index.js +34 -0
  14. package/benchmark/property_descriptor.cc +91 -0
  15. package/benchmark/property_descriptor.js +37 -0
  16. package/common.gypi +21 -0
  17. package/doc/addon.md +157 -0
  18. package/doc/array.md +81 -0
  19. package/doc/array_buffer.md +20 -0
  20. package/doc/async_context.md +1 -1
  21. package/doc/async_worker.md +34 -5
  22. package/doc/{async_progress_worker.md → async_worker_variants.md} +236 -23
  23. package/doc/bigint.md +7 -2
  24. package/doc/boolean.md +5 -1
  25. package/doc/buffer.md +4 -0
  26. package/doc/checker-tool.md +1 -1
  27. package/doc/class_property_descriptor.md +3 -3
  28. package/doc/creating_a_release.md +6 -6
  29. package/doc/dataview.md +4 -0
  30. package/doc/date.md +2 -2
  31. package/doc/env.md +69 -0
  32. package/doc/error.md +5 -0
  33. package/doc/escapable_handle_scope.md +1 -1
  34. package/doc/external.md +4 -0
  35. package/doc/function.md +111 -3
  36. package/doc/function_reference.md +1 -1
  37. package/doc/handle_scope.md +1 -1
  38. package/doc/hierarchy.md +91 -0
  39. package/doc/instance_wrap.md +408 -0
  40. package/doc/name.md +29 -0
  41. package/doc/number.md +1 -1
  42. package/doc/object.md +44 -1
  43. package/doc/object_lifetime_management.md +2 -2
  44. package/doc/object_reference.md +1 -1
  45. package/doc/object_wrap.md +220 -216
  46. package/doc/prebuild_tools.md +2 -2
  47. package/doc/promises.md +5 -0
  48. package/doc/property_descriptor.md +67 -12
  49. package/doc/setup.md +1 -2
  50. package/doc/string.md +5 -1
  51. package/doc/symbol.md +5 -1
  52. package/doc/threadsafe.md +121 -0
  53. package/doc/threadsafe_function.md +16 -46
  54. package/doc/typed_array.md +4 -0
  55. package/doc/typed_array_of.md +4 -0
  56. package/doc/typed_threadsafe_function.md +307 -0
  57. package/doc/value.md +166 -104
  58. package/doc/version_management.md +2 -2
  59. package/except.gypi +16 -0
  60. package/index.js +7 -41
  61. package/napi-inl.h +1685 -464
  62. package/napi.h +606 -141
  63. package/node_api.gyp +9 -0
  64. package/noexcept.gypi +16 -0
  65. package/{src/nothing.c → nothing.c} +0 -0
  66. package/package-support.json +21 -0
  67. package/package.json +106 -2
  68. package/tools/README.md +12 -6
  69. package/tools/clang-format.js +47 -0
  70. package/tools/conversion.js +4 -8
  71. package/doc/Doxyfile +0 -2450
  72. package/doc/basic_types.md +0 -423
  73. package/doc/working_with_javascript_values.md +0 -14
  74. package/external-napi/node_api.h +0 -7
  75. package/src/node_api.cc +0 -3655
  76. package/src/node_api.gyp +0 -21
  77. package/src/node_api.h +0 -588
  78. package/src/node_api_types.h +0 -115
  79. package/src/node_internals.cc +0 -142
  80. package/src/node_internals.h +0 -157
  81. package/src/util-inl.h +0 -38
  82. package/src/util.h +0 -7
package/doc/function.md CHANGED
@@ -11,6 +11,10 @@ functions that were created in JavaScript and passed to the native add-on.
11
11
  The `Napi::Function` class inherits its behavior from the `Napi::Object` class (for more info
12
12
  see: [`Napi::Object`](object.md)).
13
13
 
14
+ > For callbacks that will be called with asynchronous events from a
15
+ > non-JavaScript thread, please refer to [`Napi::ThreadSafeFunction`][] for more
16
+ > examples.
17
+
14
18
  ## Example
15
19
 
16
20
  ```cpp
@@ -25,7 +29,8 @@ Value Fn(const CallbackInfo& info) {
25
29
  }
26
30
 
27
31
  Object Init(Env env, Object exports) {
28
- exports.Set(String::New(env, "fn"), Function::New(env, Fn));
32
+ exports.Set(String::New(env, "fn"), Function::New<Fn>(env));
33
+ return exports;
29
34
  }
30
35
 
31
36
  NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
@@ -47,6 +52,27 @@ and in general in situations which don't have an existing JavaScript function on
47
52
  the stack. The `Call` method is used when there is already a JavaScript function
48
53
  on the stack (for example when running a native method called from JavaScript).
49
54
 
55
+ ## Type definitions
56
+
57
+ ### Napi::Function::VoidCallback
58
+
59
+ This is the type describing a callback returning `void` that will be invoked
60
+ from JavaScript.
61
+
62
+ ```cpp
63
+ typedef void (*VoidCallback)(const Napi::CallbackInfo& info);
64
+ ```
65
+
66
+ ### Napi::Function::Callback
67
+
68
+ This is the type describing a callback returning a value that will be invoked
69
+ from JavaScript.
70
+
71
+
72
+ ```cpp
73
+ typedef Value (*Callback)(const Napi::CallbackInfo& info);
74
+ ```
75
+
50
76
  ## Methods
51
77
 
52
78
  ### Constructor
@@ -74,6 +100,86 @@ Returns a non-empty `Napi::Function` instance.
74
100
 
75
101
  Creates an instance of a `Napi::Function` object.
76
102
 
103
+ ```cpp
104
+ template <Napi::VoidCallback cb>
105
+ static Napi::Function New(napi_env env,
106
+ const char* utf8name = nullptr,
107
+ void* data = nullptr);
108
+ ```
109
+
110
+ - `[template] cb`: The native function to invoke when the JavaScript function is
111
+ invoked.
112
+ - `[in] env`: The `napi_env` environment in which to construct the `Napi::Function` object.
113
+ - `[in] utf8name`: Null-terminated string to be used as the name of the function.
114
+ - `[in] data`: User-provided data context. This will be passed back into the
115
+ function when invoked later.
116
+
117
+ Returns an instance of a `Napi::Function` object.
118
+
119
+ ### New
120
+
121
+ Creates an instance of a `Napi::Function` object.
122
+
123
+ ```cpp
124
+ template <Napi::Callback cb>
125
+ static Napi::Function New(napi_env env,
126
+ const char* utf8name = nullptr,
127
+ void* data = nullptr);
128
+ ```
129
+
130
+ - `[template] cb`: The native function to invoke when the JavaScript function is
131
+ invoked.
132
+ - `[in] env`: The `napi_env` environment in which to construct the `Napi::Function` object.
133
+ - `[in] utf8name`: Null-terminated string to be used as the name of the function.
134
+ - `[in] data`: User-provided data context. This will be passed back into the
135
+ function when invoked later.
136
+
137
+ Returns an instance of a `Napi::Function` object.
138
+
139
+ ### New
140
+
141
+ Creates an instance of a `Napi::Function` object.
142
+
143
+ ```cpp
144
+ template <Napi::VoidCallback cb>
145
+ static Napi::Function New(napi_env env,
146
+ const std::string& utf8name,
147
+ void* data = nullptr);
148
+ ```
149
+
150
+ - `[template] cb`: The native function to invoke when the JavaScript function is
151
+ invoked.
152
+ - `[in] env`: The `napi_env` environment in which to construct the `Napi::Function` object.
153
+ - `[in] utf8name`: String to be used as the name of the function.
154
+ - `[in] data`: User-provided data context. This will be passed back into the
155
+ function when invoked later.
156
+
157
+ Returns an instance of a `Napi::Function` object.
158
+
159
+ ### New
160
+
161
+ Creates an instance of a `Napi::Function` object.
162
+
163
+ ```cpp
164
+ template <Napi::Callback cb>
165
+ static Napi::Function New(napi_env env,
166
+ const std::string& utf8name,
167
+ void* data = nullptr);
168
+ ```
169
+
170
+ - `[template] cb`: The native function to invoke when the JavaScript function is
171
+ invoked.
172
+ - `[in] env`: The `napi_env` environment in which to construct the `Napi::Function` object.
173
+ - `[in] utf8name`: String to be used as the name of the function.
174
+ - `[in] data`: User-provided data context. This will be passed back into the
175
+ function when invoked later.
176
+
177
+ Returns an instance of a `Napi::Function` object.
178
+
179
+ ### New
180
+
181
+ Creates an instance of a `Napi::Function` object.
182
+
77
183
  ```cpp
78
184
  template <typename Callable>
79
185
  static Napi::Function Napi::Function::New(napi_env env, Callable cb, const char* utf8name = nullptr, void* data = nullptr);
@@ -112,7 +218,7 @@ Napi::Object Napi::Function::New(const std::initializer_list<napi_value>& args)
112
218
  ```
113
219
 
114
220
  - `[in] args`: Initializer list of JavaScript values as `napi_value` representing
115
- the arguments of the contructor function.
221
+ the arguments of the constructor function.
116
222
 
117
223
  Returns a new JavaScript object.
118
224
 
@@ -139,7 +245,7 @@ object.
139
245
  Napi::Object Napi::Function::New(size_t argc, const napi_value* args) const;
140
246
  ```
141
247
 
142
- - `[in] argc`: The number of the arguments passed to the contructor function.
248
+ - `[in] argc`: The number of the arguments passed to the constructor function.
143
249
  - `[in] args`: Array of JavaScript values as `napi_value` representing the
144
250
  arguments of the constructor function.
145
251
 
@@ -292,3 +398,5 @@ Napi::Value Napi::Function::operator ()(const std::initializer_list<napi_value>&
292
398
  - `[in] args`: Initializer list of JavaScript values as `napi_value`.
293
399
 
294
400
  Returns a `Napi::Value` representing the JavaScript value returned by the function.
401
+
402
+ [`Napi::ThreadSafeFunction`]: ./threadsafe_function.md
@@ -73,7 +73,7 @@ Napi::Object Napi::FunctionReference::New(const std::initializer_list<napi_value
73
73
  ```
74
74
 
75
75
  - `[in] args`: Initializer list of JavaScript values as `napi_value` representing
76
- the arguments of the contructor function.
76
+ the arguments of the constructor function.
77
77
 
78
78
  Returns a new JavaScript object.
79
79
 
@@ -54,7 +54,7 @@ Napi::HandleScope::~HandleScope();
54
54
 
55
55
  Deletes the `Napi::HandleScope` instance and allows any objects/handles created
56
56
  in the scope to be collected by the garbage collector. There is no
57
- guarantee as to when the gargbage collector will do this.
57
+ guarantee as to when the garbage collector will do this.
58
58
 
59
59
  ### Env
60
60
 
@@ -0,0 +1,91 @@
1
+ # Full Class Hierarchy
2
+
3
+ | Class | Parent Class(es) |
4
+ |---|---|
5
+ | [`Napi::Addon`][] | [`Napi::InstanceWrap`][] |
6
+ | [`Napi::Array`][] | [`Napi::Object`][] |
7
+ | [`Napi::ArrayBuffer`][] | [`Napi::Object`][] |
8
+ | [`Napi::AsyncContext`][] | |
9
+ | [`Napi::AsyncProgressQueueWorker`][] | `Napi::AsyncProgressWorkerBase` |
10
+ | [`Napi::AsyncProgressWorker`][] | `Napi::AsyncProgressWorkerBase` |
11
+ | [`Napi::AsyncWorker`][] | |
12
+ | [`Napi::BigInt`][] | [`Napi::Value`][] |
13
+ | [`Napi::Boolean`][] | [`Napi::Value`][] |
14
+ | [`Napi::Buffer`][] | [`Napi::Uint8Array`][] |
15
+ | [`Napi::CallbackInfo`][] | |
16
+ | [`Napi::CallbackScope`][] | |
17
+ | [`Napi::ClassPropertyDescriptor`][] | |
18
+ | [`Napi::DataView`][] | [`Napi::Object`][] |
19
+ | [`Napi::Date`][] | [`Napi::Value`][] |
20
+ | [`Napi::Env`][] | |
21
+ | [`Napi::Error`][] | [`Napi::ObjectReference`][], [`std::exception`][] |
22
+ | [`Napi::EscapableHandleScope`][] | |
23
+ | [`Napi::External`][] | [`Napi::Value`][] |
24
+ | [`Napi::Function`][] | [`Napi::Object`][] |
25
+ | [`Napi::FunctionReference`][] | [`Napi::Reference<Napi::Function>`][] |
26
+ | [`Napi::HandleScope`][] | |
27
+ | [`Napi::InstanceWrap`][] | |
28
+ | [`Napi::MemoryManagement`][] | |
29
+ | [`Napi::Name`][] | [`Napi::Value`][] |
30
+ | [`Napi::Number`][] | [`Napi::Value`][] |
31
+ | [`Napi::Object`][] | [`Napi::Value`][] |
32
+ | [`Napi::ObjectReference`][] | [`Napi::Reference<Napi::Object>`][] |
33
+ | [`Napi::ObjectWrap`][] | [`Napi::InstanceWrap`][], [`Napi::Reference<Napi::Object>`][] |
34
+ | [`Napi::Promise`][] | [`Napi::Object`][] |
35
+ | [`Napi::PropertyDescriptor`][] | |
36
+ | [`Napi::RangeError`][] | [`Napi::Error`][] |
37
+ | [`Napi::Reference`] | |
38
+ | [`Napi::String`][] | [`Napi::Name`][] |
39
+ | [`Napi::Symbol`][] | [`Napi::Name`][] |
40
+ | [`Napi::ThreadSafeFunction`][] | |
41
+ | [`Napi::TypeError`][] | [`Napi::Error`][] |
42
+ | [`Napi::TypedArray`][] | [`Napi::Object`][] |
43
+ | [`Napi::TypedArrayOf`][] | [`Napi::TypedArray`][] |
44
+ | [`Napi::Value`][] | |
45
+ | [`Napi::VersionManagement`][] | |
46
+
47
+ [`Napi::Addon`]: ./addon.md
48
+ [`Napi::Array`]: ./array.md
49
+ [`Napi::ArrayBuffer`]: ./array_buffer.md
50
+ [`Napi::AsyncContext`]: ./async_context.md
51
+ [`Napi::AsyncProgressQueueWorker`]: ./async_worker_variants.md#asyncprogressqueueworker
52
+ [`Napi::AsyncProgressWorker`]: ./async_worker_variants.md#asyncprogressworker
53
+ [`Napi::AsyncWorker`]: ./async_worker.md
54
+ [`Napi::BigInt`]: ./bigint.md
55
+ [`Napi::Boolean`]: ./boolean.md
56
+ [`Napi::Buffer`]: ./buffer.md
57
+ [`Napi::CallbackInfo`]: ./callbackinfo.md
58
+ [`Napi::CallbackScope`]: ./callback_scope.md
59
+ [`Napi::ClassPropertyDescriptor`]: ./class_property_descriptor.md
60
+ [`Napi::DataView`]: ./dataview.md
61
+ [`Napi::Date`]: ./date.md
62
+ [`Napi::Env`]: ./env.md
63
+ [`Napi::Error`]: ./error.md
64
+ [`Napi::EscapableHandleScope`]: ./escapable_handle_scope.md
65
+ [`Napi::External`]: ./external.md
66
+ [`Napi::Function`]: ./function.md
67
+ [`Napi::FunctionReference`]: ./function_reference.md
68
+ [`Napi::HandleScope`]: ./handle_scope.md
69
+ [`Napi::InstanceWrap`]: ./instance_wrap.md
70
+ [`Napi::MemoryManagement`]: ./memory_management.md
71
+ [`Napi::Name`]: ./name.md
72
+ [`Napi::Number`]: ./number.md
73
+ [`Napi::Object`]: ./object.md
74
+ [`Napi::ObjectReference`]: ./object_reference.md
75
+ [`Napi::ObjectWrap`]: ./object_wrap.md
76
+ [`Napi::Promise`]: ./promise.md
77
+ [`Napi::PropertyDescriptor`]: ./property_descriptor.md
78
+ [`Napi::RangeError`]: ./range_error.md
79
+ [`Napi::Reference`]: ./reference.md
80
+ [`Napi::Reference<Napi::Function>`]: ./reference.md
81
+ [`Napi::Reference<Napi::Object>`]: ./reference.md
82
+ [`Napi::String`]: ./string.md
83
+ [`Napi::Symbol`]: ./symbol.md
84
+ [`Napi::ThreadSafeFunction`]: ./thread_safe_function.md
85
+ [`Napi::TypeError`]: ./type_error.md
86
+ [`Napi::TypedArray`]: ./typed_array.md
87
+ [`Napi::TypedArrayOf`]: ./typed_array_of.md
88
+ [`Napi::Uint8Array`]: ./typed_array_of.md
89
+ [`Napi::Value`]: ./value.md
90
+ [`Napi::VersionManagement`]: ./version_management.md
91
+ [`std::exception`]: https://cplusplus.com/reference/exception/exception/
@@ -0,0 +1,408 @@
1
+ # InstanceWrap<T>
2
+
3
+ This class serves as the base class for [`Napi::ObjectWrap<T>`][] and
4
+ [`Napi::Addon<T>`][].
5
+
6
+ In the case of [`Napi::Addon<T>`][] it provides the
7
+ methods for exposing functions to JavaScript on instances of an add-on.
8
+
9
+ As a base class for [`Napi::ObjectWrap<T>`][] it provides the methods for
10
+ exposing instance methods of JavaScript objects instantiated from the JavaScript
11
+ class corresponding to the subclass of [`Napi::ObjectWrap<T>`][].
12
+
13
+ ## Methods
14
+
15
+ ### InstanceMethod
16
+
17
+ Creates a property descriptor that represents a method exposed on JavaScript
18
+ instances of this class.
19
+
20
+ ```cpp
21
+ template <typename T>
22
+ static Napi::ClassPropertyDescriptor<T>
23
+ Napi::InstanceWrap<T>::InstanceMethod(const char* utf8name,
24
+ InstanceVoidMethodCallback method,
25
+ napi_property_attributes attributes = napi_default,
26
+ void* data = nullptr);
27
+ ```
28
+
29
+ - `[in] utf8name`: Null-terminated string that represents the name of the method
30
+ provided by instances of the class.
31
+ - `[in] method`: The native function that represents a method provided by the
32
+ add-on.
33
+ - `[in] attributes`: The attributes associated with the property. One or more of
34
+ `napi_property_attributes`.
35
+ - `[in] data`: User-provided data passed into the method when it is invoked.
36
+
37
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
38
+ provided by instances of the class. The method must be of the form
39
+
40
+ ```cpp
41
+ void MethodName(const Napi::CallbackInfo& info);
42
+ ```
43
+
44
+ ### InstanceMethod
45
+
46
+ Creates a property descriptor that represents a method exposed on JavaScript
47
+ instances of this class.
48
+
49
+ ```cpp
50
+ template <typename T>
51
+ static Napi::ClassPropertyDescriptor<T>
52
+ Napi::InstanceWrap<T>::InstanceMethod(const char* utf8name,
53
+ InstanceMethodCallback method,
54
+ napi_property_attributes attributes = napi_default,
55
+ void* data = nullptr);
56
+ ```
57
+
58
+ - `[in] utf8name`: Null-terminated string that represents the name of the method
59
+ provided by instances of the class.
60
+ - `[in] method`: The native function that represents a method provided by the
61
+ add-on.
62
+ - `[in] attributes`: The attributes associated with the property. One or more of
63
+ `napi_property_attributes`.
64
+ - `[in] data`: User-provided data passed into the method when it is invoked.
65
+
66
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
67
+ provided by instances of the class. The method must be of the form
68
+
69
+ ```cpp
70
+ Napi::Value MethodName(const Napi::CallbackInfo& info);
71
+ ```
72
+
73
+ ### InstanceMethod
74
+
75
+ Creates a property descriptor that represents a method exposed on JavaScript
76
+ instances of this class.
77
+
78
+ ```cpp
79
+ template <typename T>
80
+ static Napi::ClassPropertyDescriptor<T>
81
+ Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
82
+ InstanceVoidMethodCallback method,
83
+ napi_property_attributes attributes = napi_default,
84
+ void* data = nullptr);
85
+ ```
86
+
87
+ - `[in] name`: JavaScript symbol that represents the name of the method provided
88
+ by instances of the class.
89
+ - `[in] method`: The native function that represents a method provided by the
90
+ add-on.
91
+ - `[in] attributes`: The attributes associated with the property. One or more of
92
+ `napi_property_attributes`.
93
+ - `[in] data`: User-provided data passed into the method when it is invoked.
94
+
95
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
96
+ provided by instances of the class. The method must be of the form
97
+
98
+ ```cpp
99
+ void MethodName(const Napi::CallbackInfo& info);
100
+ ```
101
+
102
+ ### InstanceMethod
103
+
104
+ Creates a property descriptor that represents a method exposed on JavaScript
105
+ instances of this class.
106
+
107
+ ```cpp
108
+ template <typename T>
109
+ static Napi::ClassPropertyDescriptor<T>
110
+ Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
111
+ InstanceMethodCallback method,
112
+ napi_property_attributes attributes = napi_default,
113
+ void* data = nullptr);
114
+ ```
115
+
116
+ - `[in] name`: JavaScript symbol that represents the name of the method provided
117
+ by instances of the class.
118
+ - `[in] method`: The native function that represents a method provided by the
119
+ add-on.
120
+ - `[in] attributes`: The attributes associated with the property. One or more of
121
+ `napi_property_attributes`.
122
+ - `[in] data`: User-provided data passed into the method when it is invoked.
123
+
124
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
125
+ provided by instances of the class. The method must be of the form
126
+
127
+ ```cpp
128
+ Napi::Value MethodName(const Napi::CallbackInfo& info);
129
+ ```
130
+
131
+ ### InstanceMethod
132
+
133
+ Creates a property descriptor that represents a method exposed on JavaScript
134
+ instances of this class.
135
+
136
+ ```cpp
137
+ <template typename T>
138
+ template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
139
+ static Napi::ClassPropertyDescriptor<T>
140
+ Napi::InstanceWrap::InstanceMethod(const char* utf8name,
141
+ napi_property_attributes attributes = napi_default,
142
+ void* data = nullptr);
143
+ ```
144
+
145
+ - `[in] method`: The native function that represents a method provided by the
146
+ add-on.
147
+ - `[in] utf8name`: Null-terminated string that represents the name of the method
148
+ provided by instances of the class.
149
+ - `[in] attributes`: The attributes associated with the property. One or more of
150
+ `napi_property_attributes`.
151
+ - `[in] data`: User-provided data passed into the method when it is invoked.
152
+
153
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
154
+ provided by instances of the class. The method must be of the form
155
+
156
+ ```cpp
157
+ void MethodName(const Napi::CallbackInfo& info);
158
+ ```
159
+
160
+ ### InstanceMethod
161
+
162
+ Creates a property descriptor that represents a method exposed on JavaScript
163
+ instances of this class.
164
+
165
+ ```cpp
166
+ template <typename T>
167
+ template <typename InstanceWrap<T>::InstanceMethodCallback method>
168
+ static Napi::ClassPropertyDescriptor<T>
169
+ Napi::InstanceWrap<T>::InstanceMethod(const char* utf8name,
170
+ napi_property_attributes attributes = napi_default,
171
+ void* data = nullptr);
172
+ ```
173
+
174
+ - `[in] method`: The native function that represents a method provided by the
175
+ add-on.
176
+ - `[in] utf8name`: Null-terminated string that represents the name of the method
177
+ provided by instances of the class.
178
+ - `[in] attributes`: The attributes associated with the property. One or more of
179
+ `napi_property_attributes`.
180
+ - `[in] data`: User-provided data passed into the method when it is invoked.
181
+
182
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
183
+ provided by instances of the class. The method must be of the form
184
+
185
+ ```cpp
186
+ Napi::Value MethodName(const Napi::CallbackInfo& info);
187
+ ```
188
+
189
+ ### InstanceMethod
190
+
191
+ Creates a property descriptor that represents a method exposed on JavaScript
192
+ instances of this class.
193
+
194
+ ```cpp
195
+ template <typename T>
196
+ template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
197
+ static Napi::ClassPropertyDescriptor<T>
198
+ Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
199
+ napi_property_attributes attributes = napi_default,
200
+ void* data = nullptr);
201
+ ```
202
+
203
+ - `[in] method`: The native function that represents a method provided by the
204
+ add-on.
205
+ - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
206
+ instance method for the class.
207
+ - `[in] attributes`: The attributes associated with the property. One or more of
208
+ `napi_property_attributes`.
209
+ - `[in] data`: User-provided data passed into the method when it is invoked.
210
+
211
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
212
+ provided by instances of the class. The method must be of the form
213
+
214
+ ```cpp
215
+ void MethodName(const Napi::CallbackInfo& info);
216
+ ```
217
+
218
+ ### InstanceMethod
219
+
220
+ Creates a property descriptor that represents a method exposed on JavaScript
221
+ instances of this class.
222
+
223
+ ```cpp
224
+ template <typename T>
225
+ template <InstanceWrap<T>::InstanceMethodCallback method>
226
+ static Napi::ClassPropertyDescriptor<T>
227
+ Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
228
+ napi_property_attributes attributes = napi_default,
229
+ void* data = nullptr);
230
+ ```
231
+
232
+ - `[in] method`: The native function that represents a method provided by the
233
+ add-on.
234
+ - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
235
+ instance method for the class.
236
+ - `[in] attributes`: The attributes associated with the property. One or more of
237
+ `napi_property_attributes`.
238
+ - `[in] data`: User-provided data passed into the method when it is invoked.
239
+
240
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
241
+ provided by instances of the class. The method must be of the form
242
+
243
+ ```cpp
244
+ Napi::Value MethodName(const Napi::CallbackInfo& info);
245
+ ```
246
+
247
+ ### InstanceAccessor
248
+
249
+ Creates a property descriptor that represents a property exposed on JavaScript
250
+ instances of this class.
251
+
252
+ ```cpp
253
+ template <typename T>
254
+ static Napi::ClassPropertyDescriptor<T>
255
+ Napi::InstanceWrap<T>::InstanceAccessor(const char* utf8name,
256
+ InstanceGetterCallback getter,
257
+ InstanceSetterCallback setter,
258
+ napi_property_attributes attributes = napi_default,
259
+ void* data = nullptr);
260
+ ```
261
+
262
+ - `[in] utf8name`: Null-terminated string that represents the name of the method
263
+ provided by instances of the class.
264
+ - `[in] getter`: The native function to call when a get access to the property
265
+ is performed.
266
+ - `[in] setter`: The native function to call when a set access to the property
267
+ is performed.
268
+ - `[in] attributes`: The attributes associated with the property. One or more of
269
+ `napi_property_attributes`.
270
+ - `[in] data`: User-provided data passed into the getter or the setter when it
271
+ is invoked.
272
+
273
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
274
+ accessor property provided by instances of the class.
275
+
276
+ ### InstanceAccessor
277
+
278
+ Creates a property descriptor that represents a property exposed on JavaScript
279
+ instances of this class.
280
+
281
+ ```cpp
282
+ template <typename T>
283
+ static Napi::ClassPropertyDescriptor<T>
284
+ Napi::InstanceWrap<T>::InstanceAccessor(Symbol name,
285
+ InstanceGetterCallback getter,
286
+ InstanceSetterCallback setter,
287
+ napi_property_attributes attributes = napi_default,
288
+ void* data = nullptr);
289
+ ```
290
+
291
+ - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
292
+ instance accessor.
293
+ - `[in] getter`: The native function to call when a get access to the property of
294
+ a JavaScript class is performed.
295
+ - `[in] setter`: The native function to call when a set access to the property of
296
+ a JavaScript class is performed.
297
+ - `[in] attributes`: The attributes associated with the property. One or more of
298
+ `napi_property_attributes`.
299
+ - `[in] data`: User-provided data passed into the getter or the setter when it
300
+ is invoked.
301
+
302
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
303
+ accessor property provided instances of the class.
304
+
305
+ ### InstanceAccessor
306
+
307
+ Creates a property descriptor that represents a property exposed on JavaScript
308
+ instances of this class.
309
+
310
+ ```cpp
311
+ template <typename T>
312
+ template <typename InstanceWrap<T>::InstanceGetterCallback getter,
313
+ typename InstanceWrap<T>::InstanceSetterCallback setter=nullptr>
314
+ static Napi::ClassPropertyDescriptor<T>
315
+ Napi::InstanceWrap<T>::InstanceAccessor(const char* utf8name,
316
+ napi_property_attributes attributes = napi_default,
317
+ void* data = nullptr);
318
+ ```
319
+
320
+ - `[in] getter`: The native function to call when a get access to the property of
321
+ a JavaScript class is performed.
322
+ - `[in] setter`: The native function to call when a set access to the property of
323
+ a JavaScript class is performed.
324
+ - `[in] utf8name`: Null-terminated string that represents the name of the method
325
+ provided by instances of the class.
326
+ - `[in] attributes`: The attributes associated with the property. One or more of
327
+ `napi_property_attributes`.
328
+ - `[in] data`: User-provided data passed into the getter or the setter when it
329
+ is invoked.
330
+
331
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
332
+ accessor property provided by instances of the class.
333
+
334
+ ### InstanceAccessor
335
+
336
+ Creates a property descriptor that represents a property exposed on JavaScript
337
+ instances of this class.
338
+
339
+ ```cpp
340
+ template <typename T>
341
+ template <typename InstanceWrap<T>::InstanceGetterCallback getter,
342
+ typename InstanceWrap<T>::InstanceSetterCallback setter=nullptr>
343
+ static Napi::ClassPropertyDescriptor<T>
344
+ Napi::InstanceWrap<T>::InstanceAccessor(Symbol name,
345
+ napi_property_attributes attributes = napi_default,
346
+ void* data = nullptr);
347
+ ```
348
+
349
+ - `[in] getter`: The native function to call when a get access to the property of
350
+ a JavaScript class is performed.
351
+ - `[in] setter`: The native function to call when a set access to the property of
352
+ a JavaScript class is performed.
353
+ - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
354
+ instance accessor.
355
+ - `[in] attributes`: The attributes associated with the property. One or more of
356
+ `napi_property_attributes`.
357
+ - `[in] data`: User-provided data passed into the getter or the setter when it
358
+ is invoked.
359
+
360
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
361
+ accessor property provided by instances of the class.
362
+
363
+ ### InstanceValue
364
+
365
+ Creates property descriptor that represents a value exposed on JavaScript
366
+ instances of this class.
367
+
368
+ ```cpp
369
+ template <typename T>
370
+ static Napi::ClassPropertyDescriptor<T>
371
+ Napi::InstanceWrap<T>::InstanceValue(const char* utf8name,
372
+ Napi::Value value,
373
+ napi_property_attributes attributes = napi_default);
374
+ ```
375
+
376
+ - `[in] utf8name`: Null-terminated string that represents the name of the
377
+ property.
378
+ - `[in] value`: The value that's retrieved by a get access of the property.
379
+ - `[in] attributes`: The attributes associated with the property. One or more of
380
+ `napi_property_attributes`.
381
+
382
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
383
+ value property of an add-on.
384
+
385
+ ### InstanceValue
386
+
387
+ Creates property descriptor that represents a value exposed on JavaScript
388
+ instances of this class.
389
+
390
+ ```cpp
391
+ template <typename T>
392
+ static Napi::ClassPropertyDescriptor<T>
393
+ Napi::InstanceWrap<T>::InstanceValue(Symbol name,
394
+ Napi::Value value,
395
+ napi_property_attributes attributes = napi_default);
396
+ ```
397
+
398
+ - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
399
+ name of the property.
400
+ - `[in] value`: The value that's retrieved by a get access of the property.
401
+ - `[in] attributes`: The attributes associated with the property. One or more of
402
+ `napi_property_attributes`.
403
+
404
+ Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
405
+ value property of an add-on.
406
+
407
+ [`Napi::Addon<T>`]: ./addon.md
408
+ [`Napi::ObjectWrap<T>`]: ./object_wrap.md