node-addon-api 3.0.1 → 3.2.1

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 (74) hide show
  1. package/CHANGELOG.md +217 -0
  2. package/README.md +104 -60
  3. package/common.gypi +1 -1
  4. package/index.js +4 -3
  5. package/napi-inl.deprecated.h +8 -8
  6. package/napi-inl.h +1206 -540
  7. package/napi.h +821 -522
  8. package/package-support.json +21 -0
  9. package/package.json +80 -4
  10. package/tools/README.md +8 -2
  11. package/tools/clang-format.js +67 -0
  12. package/tools/conversion.js +4 -4
  13. package/.editorconfig +0 -8
  14. package/.travis.yml +0 -59
  15. package/CODE_OF_CONDUCT.md +0 -4
  16. package/CONTRIBUTING.md +0 -66
  17. package/appveyor.yml +0 -48
  18. package/benchmark/README.md +0 -47
  19. package/benchmark/binding.gyp +0 -25
  20. package/benchmark/function_args.cc +0 -153
  21. package/benchmark/function_args.js +0 -52
  22. package/benchmark/index.js +0 -34
  23. package/benchmark/property_descriptor.cc +0 -60
  24. package/benchmark/property_descriptor.js +0 -29
  25. package/doc/Doxyfile +0 -2450
  26. package/doc/array_buffer.md +0 -129
  27. package/doc/async_context.md +0 -86
  28. package/doc/async_operations.md +0 -31
  29. package/doc/async_worker.md +0 -427
  30. package/doc/async_worker_variants.md +0 -456
  31. package/doc/basic_types.md +0 -423
  32. package/doc/bigint.md +0 -93
  33. package/doc/boolean.md +0 -64
  34. package/doc/buffer.md +0 -140
  35. package/doc/callback_scope.md +0 -54
  36. package/doc/callbackinfo.md +0 -97
  37. package/doc/checker-tool.md +0 -32
  38. package/doc/class_property_descriptor.md +0 -117
  39. package/doc/cmake-js.md +0 -68
  40. package/doc/conversion-tool.md +0 -28
  41. package/doc/creating_a_release.md +0 -62
  42. package/doc/dataview.md +0 -244
  43. package/doc/date.md +0 -68
  44. package/doc/env.md +0 -132
  45. package/doc/error.md +0 -115
  46. package/doc/error_handling.md +0 -186
  47. package/doc/escapable_handle_scope.md +0 -82
  48. package/doc/external.md +0 -59
  49. package/doc/function.md +0 -401
  50. package/doc/function_reference.md +0 -238
  51. package/doc/generator.md +0 -13
  52. package/doc/handle_scope.md +0 -65
  53. package/doc/memory_management.md +0 -27
  54. package/doc/node-gyp.md +0 -82
  55. package/doc/number.md +0 -163
  56. package/doc/object.md +0 -275
  57. package/doc/object_lifetime_management.md +0 -83
  58. package/doc/object_reference.md +0 -117
  59. package/doc/object_wrap.md +0 -851
  60. package/doc/prebuild_tools.md +0 -16
  61. package/doc/promises.md +0 -74
  62. package/doc/property_descriptor.md +0 -286
  63. package/doc/range_error.md +0 -59
  64. package/doc/reference.md +0 -111
  65. package/doc/setup.md +0 -81
  66. package/doc/string.md +0 -89
  67. package/doc/symbol.md +0 -44
  68. package/doc/threadsafe_function.md +0 -320
  69. package/doc/type_error.md +0 -59
  70. package/doc/typed_array.md +0 -74
  71. package/doc/typed_array_of.md +0 -133
  72. package/doc/value.md +0 -278
  73. package/doc/version_management.md +0 -43
  74. package/doc/working_with_javascript_values.md +0 -14
@@ -1,851 +0,0 @@
1
- # Object Wrap
2
-
3
- The `Napi::ObjectWrap` class is used to bind the lifetime of C++ code to a
4
- JavaScript object. Once bound, each time an instance of the JavaScript object
5
- is created, an instance of the C++ class will also be created. When a method
6
- is called on the JavaScript object which is defined as an InstanceMethod, the
7
- corresponding C++ method on the wrapped C++ class will be invoked.
8
-
9
- In order to create a wrapper it's necessary to extend the
10
- `Napi::ObjectWrap`class which contains all the plumbing to connect JavaScript code
11
- with a C++ object. Classes extending `Napi::ObjectWrap` can be instantiated from
12
- JavaScript using the **new** operator, and their methods can be directly invoked
13
- from JavaScript. The **wrap** word refers to a way of grouping methods and state
14
- of the class because it will be necessary write custom code to bridge each of
15
- your C++ class methods.
16
-
17
- ## Example
18
-
19
- ```cpp
20
- #include <napi.h>
21
-
22
- class Example : public Napi::ObjectWrap<Example> {
23
- public:
24
- static Napi::Object Init(Napi::Env env, Napi::Object exports);
25
- Example(const Napi::CallbackInfo& info);
26
- static Napi::Value CreateNewItem(const Napi::CallbackInfo& info);
27
-
28
- private:
29
- double _value;
30
- Napi::Value GetValue(const Napi::CallbackInfo& info);
31
- Napi::Value SetValue(const Napi::CallbackInfo& info);
32
- };
33
-
34
- Napi::Object Example::Init(Napi::Env env, Napi::Object exports) {
35
- // This method is used to hook the accessor and method callbacks
36
- Napi::Function func = DefineClass(env, "Example", {
37
- InstanceMethod<&Example::GetValue>("GetValue"),
38
- InstanceMethod<&Example::SetValue>("SetValue"),
39
- StaticMethod<&Example::CreateNewItem>("CreateNewItem"),
40
- });
41
-
42
- Napi::FunctionReference* constructor = new Napi::FunctionReference();
43
-
44
- // Create a peristent reference to the class constructor. This will allow
45
- // a function called on a class prototype and a function
46
- // called on instance of a class to be distinguished from each other.
47
- *constructor = Napi::Persistent(func);
48
- exports.Set("Example", func);
49
-
50
- // Store the constructor as the add-on instance data. This will allow this
51
- // add-on to support multiple instances of itself running on multiple worker
52
- // threads, as well as multiple instances of itself running in different
53
- // contexts on the same thread.
54
- //
55
- // By default, the value set on the environment here will be destroyed when
56
- // the add-on is unloaded using the `delete` operator, but it is also
57
- // possible to supply a custom deleter.
58
- env.SetInstanceData<Napi::FunctionReference>(constructor);
59
-
60
- return exports;
61
- }
62
-
63
- Example::Example(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Example>(info) {
64
- Napi::Env env = info.Env();
65
- // ...
66
- Napi::Number value = info[0].As<Napi::Number>();
67
- this->_value = value.DoubleValue();
68
- }
69
-
70
- Napi::Value Example::GetValue(const Napi::CallbackInfo& info){
71
- Napi::Env env = info.Env();
72
- return Napi::Number::New(env, this->_value);
73
- }
74
-
75
- Napi::Value Example::SetValue(const Napi::CallbackInfo& info){
76
- Napi::Env env = info.Env();
77
- // ...
78
- Napi::Number value = info[0].As<Napi::Number>();
79
- this->_value = value.DoubleValue();
80
- return this->GetValue(info);
81
- }
82
-
83
- // Initialize native add-on
84
- Napi::Object Init (Napi::Env env, Napi::Object exports) {
85
- Example::Init(env, exports);
86
- return exports;
87
- }
88
-
89
- // Create a new item using the constructor stored during Init.
90
- Napi::Value Example::CreateNewItem(const Napi::CallbackInfo& info) {
91
- // Retrieve the instance data we stored during `Init()`. We only stored the
92
- // constructor there, so we retrieve it here to create a new instance of the
93
- // JS class the constructor represents.
94
- Napi::FunctionReference* constructor =
95
- info.Env().GetInstanceData<Napi::FunctionReference>();
96
- return constructor->New({ Napi::Number::New(info.Env(), 42) });
97
- }
98
-
99
- // Register and initialize native add-on
100
- NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
101
- ```
102
-
103
- The above code can be used from JavaScript as follows:
104
-
105
- ```js
106
- 'use strict'
107
-
108
- const { Example } = require('bindings')('addon')
109
-
110
- const example = new Example(11)
111
- console.log(example.GetValue())
112
- // It prints 11
113
- example.SetValue(19)
114
- console.log(example.GetValue());
115
- // It prints 19
116
- ```
117
-
118
- At initialization time, the `Napi::ObjectWrap::DefineClass()` method must be used
119
- to hook up the accessor and method callbacks. It takes a list of property
120
- descriptors, which can be constructed via the various static methods on the base
121
- class.
122
-
123
- When JavaScript code invokes the constructor, the constructor callback will create
124
- a new C++ instance and "wrap" it into the newly created JavaScript object.
125
-
126
- When JavaScript code invokes a method or a property accessor on the class the
127
- corresponding C++ callback function will be executed.
128
-
129
- For a wrapped object it could be difficult to distinguish between a function called
130
- on a class prototype and a function called on instance of a class. Therefore it is
131
- good practice to save a persistent reference to the class constructor. This allows
132
- the two cases to be distinguished from each other by checking the this object
133
- against the class constructor.
134
-
135
- ## Methods
136
-
137
- ### Constructor
138
-
139
- Creates a new instance of a JavaScript object that wraps native instance.
140
-
141
- ```cpp
142
- Napi::ObjectWrap(const Napi::CallbackInfo& callbackInfo);
143
- ```
144
-
145
- - `[in] callbackInfo`: The object representing the components of the JavaScript
146
- request being made.
147
-
148
- ### Unwrap
149
-
150
- Retrieves a native instance wrapped in a JavaScript object.
151
-
152
- ```cpp
153
- static T* Napi::ObjectWrap::Unwrap(Napi::Object wrapper);
154
- ```
155
-
156
- * `[in] wrapper`: The JavaScript object that wraps the native instance.
157
-
158
- Returns a native instance wrapped in a JavaScript object. Given the
159
- Napi:Object, this allows a method to get a pointer to the wrapped
160
- C++ object and then reference fields, call methods, etc. within that class.
161
- In many cases calling Unwrap is not required, as methods can
162
- use the `this` field for ObjectWrap when running in a method on a
163
- class that extends ObjectWrap.
164
-
165
- ### DefineClass
166
-
167
- Defnines a JavaScript class with constructor, static and instance properties and
168
- methods.
169
-
170
- ```cpp
171
- static Napi::Function Napi::ObjectWrap::DefineClass(Napi::Env env,
172
- const char* utf8name,
173
- const std::initializer_list<PropertyDescriptor>& properties,
174
- void* data = nullptr);
175
- ```
176
-
177
- * `[in] env`: The environment in which to construct a JavaScript class.
178
- * `[in] utf8name`: Null-terminated string that represents the name of the
179
- JavaScript constructor function.
180
- * `[in] properties`: Initializer list of class property descriptor describing
181
- static and instance properties and methods of the class.
182
- See: [`Class property and descriptor`](class_property_descriptor.md).
183
- * `[in] data`: User-provided data passed to the constructor callback as `data`
184
- property of the `Napi::CallbackInfo`.
185
-
186
- Returns a `Napi::Function` representing the constructor function for the class.
187
-
188
- ### DefineClass
189
-
190
- Defnines a JavaScript class with constructor, static and instance properties and
191
- methods.
192
-
193
- ```cpp
194
- static Napi::Function Napi::ObjectWrap::DefineClass(Napi::Env env,
195
- const char* utf8name,
196
- const std::vector<PropertyDescriptor>& properties,
197
- void* data = nullptr);
198
- ```
199
-
200
- * `[in] env`: The environment in which to construct a JavaScript class.
201
- * `[in] utf8name`: Null-terminated string that represents the name of the
202
- JavaScript constructor function.
203
- * `[in] properties`: Vector of class property descriptor describing static and
204
- instance properties and methods of the class.
205
- See: [`Class property and descriptor`](class_property_descriptor.md).
206
- * `[in] data`: User-provided data passed to the constructor callback as `data`
207
- property of the `Napi::CallbackInfo`.
208
-
209
- Returns a `Napi::Function` representing the constructor function for the class.
210
-
211
- ### Finalize
212
-
213
- Provides an opportunity to run cleanup code that requires access to the `Napi::Env`
214
- before the wrapped native object instance is freed. Override to implement.
215
-
216
- ```cpp
217
- virtual void Finalize(Napi::Env env);
218
- ```
219
-
220
- - `[in] env`: `Napi::Env`.
221
-
222
- ### StaticMethod
223
-
224
- Creates property descriptor that represents a static method of a JavaScript class.
225
-
226
- ```cpp
227
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(const char* utf8name,
228
- StaticVoidMethodCallback method,
229
- napi_property_attributes attributes = napi_default,
230
- void* data = nullptr);
231
- ```
232
-
233
- - `[in] utf8name`: Null-terminated string that represents the name of a static
234
- method for the class.
235
- - `[in] method`: The native function that represents a static method of a
236
- JavaScript class.
237
- - `[in] attributes`: The attributes associated with a particular property.
238
- One or more of `napi_property_attributes`.
239
- - `[in] data`: User-provided data passed into method when it is invoked.
240
-
241
- Returns `Napi::PropertyDescriptor` object that represents the static method of a
242
- JavaScript class.
243
-
244
- ### StaticMethod
245
-
246
- Creates property descriptor that represents a static method of a JavaScript class.
247
-
248
- ```cpp
249
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(const char* utf8name,
250
- StaticMethodCallback method,
251
- napi_property_attributes attributes = napi_default,
252
- void* data = nullptr);
253
- ```
254
-
255
- - `[in] utf8name`: Null-terminated string that represents the name of a static
256
- method for the class.
257
- - `[in] method`: The native function that represents a static method of a
258
- JavaScript class.
259
- - `[in] attributes`: The attributes associated with a particular property.
260
- One or more of `napi_property_attributes`.
261
- - `[in] data`: User-provided data passed into method when it is invoked.
262
-
263
- Returns `Napi::PropertyDescriptor` object that represents a static method of a
264
- JavaScript class.
265
-
266
- ### StaticMethod
267
-
268
- Creates property descriptor that represents a static method of a JavaScript class.
269
-
270
- ```cpp
271
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
272
- StaticVoidMethodCallback method,
273
- napi_property_attributes attributes = napi_default,
274
- void* data = nullptr);
275
- ```
276
-
277
- - `[in] name`: Napi:Symbol that represents the name of a static
278
- method for the class.
279
- - `[in] method`: The native function that represents a static method of a
280
- JavaScript class.
281
- - `[in] attributes`: The attributes associated with a particular property.
282
- One or more of `napi_property_attributes`.
283
- - `[in] data`: User-provided data passed into method when it is invoked.
284
-
285
- Returns `Napi::PropertyDescriptor` object that represents the static method of a
286
- JavaScript class.
287
-
288
- ### StaticMethod
289
-
290
- Creates property descriptor that represents a static method of a JavaScript class.
291
-
292
- ```cpp
293
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
294
- StaticMethodCallback method,
295
- napi_property_attributes attributes = napi_default,
296
- void* data = nullptr);
297
- ```
298
-
299
- method for the class.
300
- - `[in] name`: Napi:Symbol that represents the name of a static.
301
- - `[in] method`: The native function that represents a static method of a
302
- JavaScript class.
303
- - `[in] attributes`: The attributes associated with a particular property.
304
- One or more of `napi_property_attributes`.
305
- - `[in] data`: User-provided data passed into method when it is invoked.
306
-
307
- Returns `Napi::PropertyDescriptor` object that represents a static method of a
308
- JavaScript class.
309
-
310
- ### StaticMethod
311
-
312
- Creates property descriptor that represents a static method of a JavaScript class.
313
-
314
- ```cpp
315
- template <StaticVoidMethodCallback method>
316
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(const char* utf8name,
317
- napi_property_attributes attributes = napi_default,
318
- void* data = nullptr);
319
- ```
320
-
321
- - `[in] method`: The native function that represents a static method of a
322
- JavaScript class. This function returns nothing.
323
- - `[in] utf8name`: Null-terminated string that represents the name of a static
324
- method for the class.
325
- - `[in] attributes`: The attributes associated with a particular property.
326
- One or more of `napi_property_attributes`.
327
- - `[in] data`: User-provided data passed into method when it is invoked.
328
-
329
- Returns `Napi::PropertyDescriptor` object that represents the static method of a
330
- JavaScript class.
331
-
332
- ### StaticMethod
333
-
334
- Creates property descriptor that represents a static method of a JavaScript class.
335
-
336
- ```cpp
337
- template <StaticMethodCallback method>
338
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(const char* utf8name,
339
- napi_property_attributes attributes = napi_default,
340
- void* data = nullptr);
341
- ```
342
-
343
- - `[in] method`: The native function that represents a static method of a
344
- JavaScript class.
345
- - `[in] utf8name`: Null-terminated string that represents the name of a static
346
- method for the class.
347
- - `[in] attributes`: The attributes associated with a particular property.
348
- One or more of `napi_property_attributes`.
349
- - `[in] data`: User-provided data passed into method when it is invoked.
350
-
351
- Returns `Napi::PropertyDescriptor` object that represents a static method of a
352
- JavaScript class.
353
-
354
- ### StaticMethod
355
-
356
- Creates property descriptor that represents a static method of a JavaScript class.
357
-
358
- ```cpp
359
- template <StaticVoidMethodCallback method>
360
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
361
- napi_property_attributes attributes = napi_default,
362
- void* data = nullptr);
363
- ```
364
-
365
- - `[in] method`: The native function that represents a static method of a
366
- JavaScript class.
367
- - `[in] name`: Napi:Symbol that represents the name of a static
368
- method for the class.
369
- - `[in] attributes`: The attributes associated with a particular property.
370
- One or more of `napi_property_attributes`.
371
- - `[in] data`: User-provided data passed into method when it is invoked.
372
-
373
- Returns `Napi::PropertyDescriptor` object that represents the static method of a
374
- JavaScript class.
375
-
376
- ### StaticMethod
377
-
378
- Creates property descriptor that represents a static method of a JavaScript class.
379
-
380
- ```cpp
381
- template <StaticMethodCallback method>
382
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
383
- napi_property_attributes attributes = napi_default,
384
- void* data = nullptr);
385
- ```
386
-
387
- - `[in] method`: The native function that represents a static method of a
388
- JavaScript class.
389
- - `[in] name`: Napi:Symbol that represents the name of a static.
390
- - `[in] attributes`: The attributes associated with a particular property.
391
- One or more of `napi_property_attributes`.
392
- - `[in] data`: User-provided data passed into method when it is invoked.
393
-
394
- Returns `Napi::PropertyDescriptor` object that represents a static method of a
395
- JavaScript class.
396
-
397
- ### StaticAccessor
398
-
399
- Creates property descriptor that represents a static accessor property of a
400
- JavaScript class.
401
-
402
- ```cpp
403
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(const char* utf8name,
404
- StaticGetterCallback getter,
405
- StaticSetterCallback setter,
406
- napi_property_attributes attributes = napi_default,
407
- void* data = nullptr);
408
- ```
409
-
410
- - `[in] utf8name`: Null-terminated string that represents the name of a static
411
- accessor property for the class.
412
- - `[in] getter`: The native function to call when a get access to the property of
413
- a JavaScript class is performed.
414
- - `[in] setter`: The native function to call when a set access to the property of
415
- a JavaScript class is performed.
416
- - `[in] attributes`: The attributes associated with a particular property.
417
- One or more of `napi_property_attributes`.
418
- - `[in] data`: User-provided data passed into getter or setter when
419
- is invoked.
420
-
421
- Returns `Napi::PropertyDescriptor` object that represents a static accessor
422
- property of a JavaScript class.
423
-
424
- ### StaticAccessor
425
-
426
- Creates property descriptor that represents a static accessor property of a
427
- JavaScript class.
428
-
429
- ```cpp
430
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(Symbol name,
431
- StaticGetterCallback getter,
432
- StaticSetterCallback setter,
433
- napi_property_attributes attributes = napi_default,
434
- void* data = nullptr);
435
- ```
436
-
437
- - `[in] name`: Napi:Symbol that represents the name of a static accessor.
438
- - `[in] getter`: The native function to call when a get access to the property of
439
- a JavaScript class is performed.
440
- - `[in] setter`: The native function to call when a set access to the property of
441
- a JavaScript class is performed.
442
- - `[in] attributes`: The attributes associated with a particular property.
443
- One or more of `napi_property_attributes`.
444
- - `[in] data`: User-provided data passed into getter or setter when
445
- is invoked.
446
-
447
- Returns `Napi::PropertyDescriptor` object that represents a static accessor
448
- property of a JavaScript class.
449
-
450
- ### StaticAccessor
451
-
452
- Creates property descriptor that represents a static accessor property of a
453
- JavaScript class.
454
-
455
- ```cpp
456
- template <StaticGetterCallback getter, StaticSetterCallback setter=nullptr>
457
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(const char* utf8name,
458
- napi_property_attributes attributes = napi_default,
459
- void* data = nullptr);
460
- ```
461
-
462
- - `[in] getter`: The native function to call when a get access to the property of
463
- a JavaScript class is performed.
464
- - `[in] setter`: The native function to call when a set access to the property of
465
- a JavaScript class is performed.
466
- - `[in] utf8name`: Null-terminated string that represents the name of a static
467
- accessor property for the class.
468
- - `[in] attributes`: The attributes associated with a particular property.
469
- One or more of `napi_property_attributes`.
470
- - `[in] data`: User-provided data passed into getter or setter when
471
- is invoked.
472
-
473
- Returns `Napi::PropertyDescriptor` object that represents a static accessor
474
- property of a JavaScript class.
475
-
476
- ### StaticAccessor
477
-
478
- Creates property descriptor that represents a static accessor property of a
479
- JavaScript class.
480
-
481
- ```cpp
482
- template <StaticGetterCallback getter, StaticSetterCallback setter=nullptr>
483
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(Symbol name,
484
- napi_property_attributes attributes = napi_default,
485
- void* data = nullptr);
486
- ```
487
-
488
- - `[in] getter`: The native function to call when a get access to the property of
489
- a JavaScript class is performed.
490
- - `[in] setter`: The native function to call when a set access to the property of
491
- a JavaScript class is performed.
492
- - `[in] name`: Napi:Symbol that represents the name of a static accessor.
493
- - `[in] attributes`: The attributes associated with a particular property.
494
- One or more of `napi_property_attributes`.
495
- - `[in] data`: User-provided data passed into getter or setter when
496
- is invoked.
497
-
498
- Returns `Napi::PropertyDescriptor` object that represents a static accessor
499
- property of a JavaScript class.
500
-
501
- ### InstanceMethod
502
-
503
- Creates property descriptor that represents an instance method of a JavaScript class.
504
-
505
- ```cpp
506
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(const char* utf8name,
507
- InstanceVoidMethodCallback method,
508
- napi_property_attributes attributes = napi_default,
509
- void* data = nullptr);
510
- ```
511
-
512
- - `[in] utf8name`: Null-terminated string that represents the name of an instance
513
- method for the class.
514
- - `[in] method`: The native function that represents an instance method of a
515
- JavaScript class.
516
- - `[in] attributes`: The attributes associated with a particular property.
517
- One or more of `napi_property_attributes`.
518
- - `[in] data`: User-provided data passed into method when it is invoked.
519
-
520
- Returns `Napi::PropertyDescriptor` object that represents an instance method of a
521
- JavaScript class.
522
-
523
- ### InstanceMethod
524
-
525
- Creates property descriptor that represents an instance method of a JavaScript class.
526
-
527
- ```cpp
528
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(const char* utf8name,
529
- InstanceMethodCallback method,
530
- napi_property_attributes attributes = napi_default,
531
- void* data = nullptr);
532
- ```
533
-
534
- - `[in] utf8name`: Null-terminated string that represents the name of an instance
535
- method for the class.
536
- - `[in] method`: The native function that represents an instance method of a
537
- JavaScript class.
538
- - `[in] attributes`: The attributes associated with a particular property.
539
- One or more of `napi_property_attributes`.
540
- - `[in] data`: User-provided data passed into method when it is invoked.
541
-
542
- Returns `Napi::PropertyDescriptor` object that represents an instance method of a
543
- JavaScript class.
544
-
545
- ### InstanceMethod
546
-
547
- Creates property descriptor that represents an instance method of a JavaScript class.
548
-
549
- ```cpp
550
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(Napi::Symbol name,
551
- InstanceVoidMethodCallback method,
552
- napi_property_attributes attributes = napi_default,
553
- void* data = nullptr);
554
- ```
555
-
556
- - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
557
- instance method for the class.
558
- - `[in] method`: The native function that represents an instance method of a
559
- JavaScript class.
560
- - `[in] attributes`: The attributes associated with a particular property.
561
- One or more of `napi_property_attributes`.
562
- - `[in] data`: User-provided data passed into method when it is invoked.
563
-
564
- Returns `Napi::PropertyDescriptor` object that represents an instance method of a
565
- JavaScript class.
566
-
567
- ### InstanceMethod
568
-
569
- Creates property descriptor that represents an instance method of a JavaScript class.
570
-
571
- ```cpp
572
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(Napi::Symbol name,
573
- InstanceMethodCallback method,
574
- napi_property_attributes attributes = napi_default,
575
- void* data = nullptr);
576
- ```
577
-
578
- - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
579
- instance method for the class.
580
- - `[in] method`: The native function that represents an instance method of a
581
- JavaScript class.
582
- - `[in] attributes`: The attributes associated with a particular property.
583
- One or more of `napi_property_attributes`.
584
- - `[in] data`: User-provided data passed into method when it is invoked.
585
-
586
- Returns `Napi::PropertyDescriptor` object that represents an instance method of a
587
- JavaScript class.
588
-
589
- ### InstanceMethod
590
-
591
- Creates property descriptor that represents an instance method of a JavaScript class.
592
-
593
- ```cpp
594
- template <InstanceVoidMethodCallback method>
595
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(const char* utf8name,
596
- napi_property_attributes attributes = napi_default,
597
- void* data = nullptr);
598
- ```
599
-
600
- - `[in] method`: The native function that represents an instance method of a
601
- JavaScript class.
602
- - `[in] utf8name`: Null-terminated string that represents the name of an instance
603
- method for the class.
604
- - `[in] attributes`: The attributes associated with a particular property.
605
- One or more of `napi_property_attributes`.
606
- - `[in] data`: User-provided data passed into method when it is invoked.
607
-
608
- Returns `Napi::PropertyDescriptor` object that represents an instance method of a
609
- JavaScript class.
610
-
611
- ### InstanceMethod
612
-
613
- Creates property descriptor that represents an instance method of a JavaScript class.
614
-
615
- ```cpp
616
- template <InstanceMethodCallback method>
617
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(const char* utf8name,
618
- napi_property_attributes attributes = napi_default,
619
- void* data = nullptr);
620
- ```
621
-
622
- - `[in] method`: The native function that represents an instance method of a
623
- JavaScript class.
624
- - `[in] utf8name`: Null-terminated string that represents the name of an instance
625
- method for the class.
626
- - `[in] attributes`: The attributes associated with a particular property.
627
- One or more of `napi_property_attributes`.
628
- - `[in] data`: User-provided data passed into method when it is invoked.
629
-
630
- Returns `Napi::PropertyDescriptor` object that represents an instance method of a
631
- JavaScript class.
632
-
633
- ### InstanceMethod
634
-
635
- Creates property descriptor that represents an instance method of a JavaScript class.
636
-
637
- ```cpp
638
- template <InstanceVoidMethodCallback method>
639
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(Napi::Symbol name,
640
- napi_property_attributes attributes = napi_default,
641
- void* data = nullptr);
642
- ```
643
-
644
- - `[in] method`: The native function that represents an instance method of a
645
- JavaScript class.
646
- - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
647
- instance method for the class.
648
- - `[in] attributes`: The attributes associated with a particular property.
649
- One or more of `napi_property_attributes`.
650
- - `[in] data`: User-provided data passed into method when it is invoked.
651
-
652
- Returns `Napi::PropertyDescriptor` object that represents an instance method of a
653
- JavaScript class.
654
-
655
- ### InstanceMethod
656
-
657
- Creates property descriptor that represents an instance method of a JavaScript class.
658
-
659
- ```cpp
660
- template <InstanceMethodCallback method>
661
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(Napi::Symbol name,
662
- napi_property_attributes attributes = napi_default,
663
- void* data = nullptr);
664
- ```
665
-
666
- - `[in] method`: The native function that represents an instance method of a
667
- JavaScript class.
668
- - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
669
- instance method for the class.
670
- - `[in] attributes`: The attributes associated with a particular property.
671
- One or more of `napi_property_attributes`.
672
- - `[in] data`: User-provided data passed into method when it is invoked.
673
-
674
- Returns `Napi::PropertyDescriptor` object that represents an instance method of a
675
- JavaScript class.
676
-
677
- ### InstanceAccessor
678
-
679
- Creates property descriptor that represents an instance accessor property of a
680
- JavaScript class.
681
-
682
- ```cpp
683
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceAccessor(const char* utf8name,
684
- InstanceGetterCallback getter,
685
- InstanceSetterCallback setter,
686
- napi_property_attributes attributes = napi_default,
687
- void* data = nullptr);
688
- ```
689
-
690
- - `[in] utf8name`: Null-terminated string that represents the name of an instance
691
- accessor property for the class.
692
- - `[in] getter`: The native function to call when a get access to the property of
693
- a JavaScript class is performed.
694
- - `[in] setter`: The native function to call when a set access to the property of
695
- a JavaScript class is performed.
696
- - `[in] attributes`: The attributes associated with the particular property.
697
- One or more of `napi_property_attributes`.
698
- - `[in] data`: User-provided data passed into getter or setter when this is invoked.
699
-
700
- Returns `Napi::PropertyDescriptor` object that represents an instance accessor
701
- property of a JavaScript class.
702
-
703
- ### InstanceAccessor
704
-
705
- Creates property descriptor that represents an instance accessor property of a
706
- JavaScript class.
707
-
708
- ```cpp
709
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceAccessor(Symbol name,
710
- InstanceGetterCallback getter,
711
- InstanceSetterCallback setter,
712
- napi_property_attributes attributes = napi_default,
713
- void* data = nullptr);
714
- ```
715
-
716
- - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
717
- instance accessor.
718
- - `[in] getter`: The native function to call when a get access to the property of
719
- a JavaScript class is performed.
720
- - `[in] setter`: The native function to call when a set access to the property of
721
- a JavaScript class is performed.
722
- - `[in] attributes`: The attributes associated with the particular property.
723
- One or more of `napi_property_attributes`.
724
- - `[in] data`: User-provided data passed into getter or setter when this is invoked.
725
-
726
- Returns `Napi::PropertyDescriptor` object that represents an instance accessor
727
- property of a JavaScript class.
728
-
729
- ### InstanceAccessor
730
-
731
- Creates property descriptor that represents an instance accessor property of a
732
- JavaScript class.
733
-
734
- ```cpp
735
- template <InstanceGetterCallback getter, InstanceSetterCallback setter=nullptr>
736
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceAccessor(const char* utf8name,
737
- napi_property_attributes attributes = napi_default,
738
- void* data = nullptr);
739
- ```
740
-
741
- - `[in] getter`: The native function to call when a get access to the property of
742
- a JavaScript class is performed.
743
- - `[in] setter`: The native function to call when a set access to the property of
744
- a JavaScript class is performed.
745
- - `[in] utf8name`: Null-terminated string that represents the name of an instance
746
- accessor property for the class.
747
- - `[in] attributes`: The attributes associated with the particular property.
748
- One or more of `napi_property_attributes`.
749
- - `[in] data`: User-provided data passed into getter or setter when this is invoked.
750
-
751
- Returns `Napi::PropertyDescriptor` object that represents an instance accessor
752
- property of a JavaScript class.
753
-
754
- ### InstanceAccessor
755
-
756
- Creates property descriptor that represents an instance accessor property of a
757
- JavaScript class.
758
-
759
- ```cpp
760
- template <InstanceGetterCallback getter, InstanceSetterCallback setter=nullptr>
761
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceAccessor(Symbol name,
762
- napi_property_attributes attributes = napi_default,
763
- void* data = nullptr);
764
- ```
765
-
766
- - `[in] getter`: The native function to call when a get access to the property of
767
- a JavaScript class is performed.
768
- - `[in] setter`: The native function to call when a set access to the property of
769
- a JavaScript class is performed.
770
- - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
771
- instance accessor.
772
- - `[in] attributes`: The attributes associated with the particular property.
773
- One or more of `napi_property_attributes`.
774
- - `[in] data`: User-provided data passed into getter or setter when this is invoked.
775
-
776
- Returns `Napi::PropertyDescriptor` object that represents an instance accessor
777
- property of a JavaScript class.
778
-
779
- ### StaticValue
780
-
781
- Creates property descriptor that represents an static value property of a
782
- JavaScript class.
783
- ```cpp
784
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticValue(const char* utf8name,
785
- Napi::Value value,
786
- napi_property_attributes attributes = napi_default);
787
- ```
788
-
789
- - `[in] utf8name`: Null-terminated string that represents the name of the static
790
- property.
791
- - `[in] value`: The value that's retrieved by a get access of the property.
792
- - `[in] attributes`: The attributes to be associated with the property in addition
793
- to the napi_static attribute. One or more of `napi_property_attributes`.
794
-
795
- Returns `Napi::PropertyDescriptor` object that represents an static value
796
- property of a JavaScript class
797
-
798
- ### StaticValue
799
-
800
- Creates property descriptor that represents an static value property of a
801
- JavaScript class.
802
- ```cpp
803
- static Napi::PropertyDescriptor Napi::ObjectWrap::StaticValue(Symbol name,
804
- Napi::Value value,
805
- napi_property_attributes attributes = napi_default);
806
- ```
807
-
808
- - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
809
- name of the static property.
810
- - `[in] value`: The value that's retrieved by a get access of the property.
811
- - `[in] attributes`: The attributes to be associated with the property in addition
812
- to the napi_static attribute. One or more of `napi_property_attributes`.
813
-
814
- Returns `Napi::PropertyDescriptor` object that represents an static value
815
- property of a JavaScript class
816
-
817
- ### InstanceValue
818
-
819
- Creates property descriptor that represents an instance value property of a
820
- JavaScript class.
821
- ```cpp
822
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceValue(const char* utf8name,
823
- Napi::Value value,
824
- napi_property_attributes attributes = napi_default);
825
- ```
826
-
827
- - `[in] utf8name`: Null-terminated string that represents the name of the property.
828
- - `[in] value`: The value that's retrieved by a get access of the property.
829
- - `[in] attributes`: The attributes to be associated with the property.
830
- One or more of `napi_property_attributes`.
831
-
832
- Returns `Napi::PropertyDescriptor` object that represents an instance value
833
- property of a JavaScript class.
834
-
835
- ### InstanceValue
836
-
837
- Creates property descriptor that represents an instance value property of a
838
- JavaScript class.
839
- ```cpp
840
- static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceValue(Symbol name,
841
- Napi::Value value,
842
- napi_property_attributes attributes = napi_default);
843
- ```
844
-
845
- - `[in] name`: The `Napi::Symbol` object whose value is used to identify the
846
- name of the property.
847
- - `[in] value`: The value that's retrieved by a get access of the property.
848
- - `[in] attributes`: The attributes to be associated with the property.
849
- One or more of `napi_property_attributes`.
850
-
851
- Returns `Napi::PropertyDescriptor` object that represents an instance value