node-addon-api 3.0.1 → 3.0.2
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.
- package/CHANGELOG.md +45 -0
- package/README.md +28 -23
- package/appveyor.yml +3 -14
- package/benchmark/function_args.cc +64 -0
- package/benchmark/function_args.js +15 -7
- package/benchmark/property_descriptor.cc +31 -0
- package/benchmark/property_descriptor.js +12 -4
- package/common.gypi +1 -1
- package/doc/addon.md +157 -0
- package/doc/array.md +81 -0
- package/doc/array_buffer.md +4 -0
- package/doc/bigint.md +4 -0
- package/doc/boolean.md +4 -0
- package/doc/buffer.md +4 -0
- package/doc/dataview.md +4 -0
- package/doc/date.md +2 -2
- package/doc/error.md +5 -0
- package/doc/external.md +4 -0
- package/doc/function.md +1 -0
- package/doc/hierarchy.md +91 -0
- package/doc/instance_wrap.md +408 -0
- package/doc/name.md +29 -0
- package/doc/object.md +6 -2
- package/doc/object_wrap.md +120 -410
- package/doc/promises.md +5 -0
- package/doc/setup.md +1 -1
- package/doc/string.md +4 -0
- package/doc/symbol.md +4 -0
- package/doc/typed_array.md +4 -0
- package/doc/typed_array_of.md +4 -0
- package/doc/value.md +166 -104
- package/index.js +4 -3
- package/napi-inl.h +539 -461
- package/napi.h +134 -119
- package/package.json +15 -1
- package/tools/conversion.js +4 -4
- package/doc/basic_types.md +0 -423
- package/doc/working_with_javascript_values.md +0 -14
package/doc/object_wrap.md
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# Object Wrap
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Class `Napi::ObjectWrap<T>` inherits from class [`Napi::InstanceWrap<T>`][].
|
|
4
|
+
|
|
5
|
+
The `Napi::ObjectWrap<T>` class is used to bind the lifetime of C++ code to a
|
|
4
6
|
JavaScript object. Once bound, each time an instance of the JavaScript object
|
|
5
7
|
is created, an instance of the C++ class will also be created. When a method
|
|
6
8
|
is called on the JavaScript object which is defined as an InstanceMethod, the
|
|
7
9
|
corresponding C++ method on the wrapped C++ class will be invoked.
|
|
8
10
|
|
|
9
11
|
In order to create a wrapper it's necessary to extend the
|
|
10
|
-
`Napi::ObjectWrap
|
|
11
|
-
with a C++ object. Classes extending `Napi::ObjectWrap` can be
|
|
12
|
-
JavaScript using the **new** operator, and their methods can
|
|
13
|
-
from JavaScript. The **wrap** word refers to a way of
|
|
14
|
-
of the class because it will be necessary write
|
|
15
|
-
your C++ class methods.
|
|
12
|
+
`Napi::ObjectWrap<T>` class which contains all the plumbing to connect
|
|
13
|
+
JavaScript code with a C++ object. Classes extending `Napi::ObjectWrap` can be
|
|
14
|
+
instantiated from JavaScript using the **new** operator, and their methods can
|
|
15
|
+
be directly invoked from JavaScript. The **wrap** word refers to a way of
|
|
16
|
+
grouping methods and state of the class because it will be necessary write
|
|
17
|
+
custom code to bridge each of your C++ class methods.
|
|
16
18
|
|
|
17
19
|
## Example
|
|
18
20
|
|
|
@@ -60,11 +62,12 @@ Napi::Object Example::Init(Napi::Env env, Napi::Object exports) {
|
|
|
60
62
|
return exports;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
Example::Example(const Napi::CallbackInfo& info) :
|
|
64
|
-
Napi::
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
Example::Example(const Napi::CallbackInfo& info) :
|
|
66
|
+
Napi::ObjectWrap<Example>(info) {
|
|
67
|
+
Napi::Env env = info.Env();
|
|
68
|
+
// ...
|
|
69
|
+
Napi::Number value = info[0].As<Napi::Number>();
|
|
70
|
+
this->_value = value.DoubleValue();
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
Napi::Value Example::GetValue(const Napi::CallbackInfo& info){
|
|
@@ -115,22 +118,23 @@ console.log(example.GetValue());
|
|
|
115
118
|
// It prints 19
|
|
116
119
|
```
|
|
117
120
|
|
|
118
|
-
At initialization time, the `Napi::ObjectWrap::DefineClass()` method must be
|
|
119
|
-
to hook up the accessor and method callbacks. It takes a list of property
|
|
121
|
+
At initialization time, the `Napi::ObjectWrap::DefineClass()` method must be
|
|
122
|
+
used to hook up the accessor and method callbacks. It takes a list of property
|
|
120
123
|
descriptors, which can be constructed via the various static methods on the base
|
|
121
124
|
class.
|
|
122
125
|
|
|
123
|
-
When JavaScript code invokes the constructor, the constructor callback will
|
|
124
|
-
a new C++ instance and "wrap" it into the newly created JavaScript
|
|
126
|
+
When JavaScript code invokes the constructor, the constructor callback will
|
|
127
|
+
create a new C++ instance and "wrap" it into the newly created JavaScript
|
|
128
|
+
object.
|
|
125
129
|
|
|
126
130
|
When JavaScript code invokes a method or a property accessor on the class the
|
|
127
131
|
corresponding C++ callback function will be executed.
|
|
128
132
|
|
|
129
|
-
For a wrapped object it could be difficult to distinguish between a function
|
|
130
|
-
on a class prototype and a function called on instance of a class.
|
|
131
|
-
good practice to save a persistent reference to the class
|
|
132
|
-
the two cases to be distinguished from each other by
|
|
133
|
-
against the class constructor.
|
|
133
|
+
For a wrapped object it could be difficult to distinguish between a function
|
|
134
|
+
called on a class prototype and a function called on instance of a class.
|
|
135
|
+
Therefore it is good practice to save a persistent reference to the class
|
|
136
|
+
constructor. This allows the two cases to be distinguished from each other by
|
|
137
|
+
checking the this object against the class constructor.
|
|
134
138
|
|
|
135
139
|
## Methods
|
|
136
140
|
|
|
@@ -169,9 +173,9 @@ methods.
|
|
|
169
173
|
|
|
170
174
|
```cpp
|
|
171
175
|
static Napi::Function Napi::ObjectWrap::DefineClass(Napi::Env env,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
176
|
+
const char* utf8name,
|
|
177
|
+
const std::initializer_list<PropertyDescriptor>& properties,
|
|
178
|
+
void* data = nullptr);
|
|
175
179
|
```
|
|
176
180
|
|
|
177
181
|
* `[in] env`: The environment in which to construct a JavaScript class.
|
|
@@ -210,8 +214,9 @@ Returns a `Napi::Function` representing the constructor function for the class.
|
|
|
210
214
|
|
|
211
215
|
### Finalize
|
|
212
216
|
|
|
213
|
-
Provides an opportunity to run cleanup code that requires access to the
|
|
214
|
-
before the wrapped native object instance is freed. Override to
|
|
217
|
+
Provides an opportunity to run cleanup code that requires access to the
|
|
218
|
+
`Napi::Env` before the wrapped native object instance is freed. Override to
|
|
219
|
+
implement.
|
|
215
220
|
|
|
216
221
|
```cpp
|
|
217
222
|
virtual void Finalize(Napi::Env env);
|
|
@@ -221,13 +226,15 @@ virtual void Finalize(Napi::Env env);
|
|
|
221
226
|
|
|
222
227
|
### StaticMethod
|
|
223
228
|
|
|
224
|
-
Creates property descriptor that represents a static method of a JavaScript
|
|
229
|
+
Creates property descriptor that represents a static method of a JavaScript
|
|
230
|
+
class.
|
|
225
231
|
|
|
226
232
|
```cpp
|
|
227
|
-
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(
|
|
234
|
+
const char* utf8name,
|
|
235
|
+
StaticVoidMethodCallback method,
|
|
236
|
+
napi_property_attributes attributes = napi_default,
|
|
237
|
+
void* data = nullptr);
|
|
231
238
|
```
|
|
232
239
|
|
|
233
240
|
- `[in] utf8name`: Null-terminated string that represents the name of a static
|
|
@@ -243,13 +250,15 @@ JavaScript class.
|
|
|
243
250
|
|
|
244
251
|
### StaticMethod
|
|
245
252
|
|
|
246
|
-
Creates property descriptor that represents a static method of a JavaScript
|
|
253
|
+
Creates property descriptor that represents a static method of a JavaScript
|
|
254
|
+
class.
|
|
247
255
|
|
|
248
256
|
```cpp
|
|
249
|
-
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
257
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(
|
|
258
|
+
const char* utf8name,
|
|
259
|
+
StaticMethodCallback method,
|
|
260
|
+
napi_property_attributes attributes = napi_default,
|
|
261
|
+
void* data = nullptr);
|
|
253
262
|
```
|
|
254
263
|
|
|
255
264
|
- `[in] utf8name`: Null-terminated string that represents the name of a static
|
|
@@ -265,13 +274,14 @@ JavaScript class.
|
|
|
265
274
|
|
|
266
275
|
### StaticMethod
|
|
267
276
|
|
|
268
|
-
Creates property descriptor that represents a static method of a JavaScript
|
|
277
|
+
Creates property descriptor that represents a static method of a JavaScript
|
|
278
|
+
class.
|
|
269
279
|
|
|
270
280
|
```cpp
|
|
271
281
|
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
282
|
+
StaticVoidMethodCallback method,
|
|
283
|
+
napi_property_attributes attributes = napi_default,
|
|
284
|
+
void* data = nullptr);
|
|
275
285
|
```
|
|
276
286
|
|
|
277
287
|
- `[in] name`: Napi:Symbol that represents the name of a static
|
|
@@ -287,13 +297,14 @@ JavaScript class.
|
|
|
287
297
|
|
|
288
298
|
### StaticMethod
|
|
289
299
|
|
|
290
|
-
Creates property descriptor that represents a static method of a JavaScript
|
|
300
|
+
Creates property descriptor that represents a static method of a JavaScript
|
|
301
|
+
class.
|
|
291
302
|
|
|
292
303
|
```cpp
|
|
293
304
|
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
305
|
+
StaticMethodCallback method,
|
|
306
|
+
napi_property_attributes attributes = napi_default,
|
|
307
|
+
void* data = nullptr);
|
|
297
308
|
```
|
|
298
309
|
|
|
299
310
|
method for the class.
|
|
@@ -309,13 +320,15 @@ JavaScript class.
|
|
|
309
320
|
|
|
310
321
|
### StaticMethod
|
|
311
322
|
|
|
312
|
-
Creates property descriptor that represents a static method of a JavaScript
|
|
323
|
+
Creates property descriptor that represents a static method of a JavaScript
|
|
324
|
+
class.
|
|
313
325
|
|
|
314
326
|
```cpp
|
|
315
327
|
template <StaticVoidMethodCallback method>
|
|
316
|
-
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(
|
|
317
|
-
|
|
318
|
-
|
|
328
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(
|
|
329
|
+
const char* utf8name,
|
|
330
|
+
napi_property_attributes attributes = napi_default,
|
|
331
|
+
void* data = nullptr);
|
|
319
332
|
```
|
|
320
333
|
|
|
321
334
|
- `[in] method`: The native function that represents a static method of a
|
|
@@ -331,13 +344,15 @@ JavaScript class.
|
|
|
331
344
|
|
|
332
345
|
### StaticMethod
|
|
333
346
|
|
|
334
|
-
Creates property descriptor that represents a static method of a JavaScript
|
|
347
|
+
Creates property descriptor that represents a static method of a JavaScript
|
|
348
|
+
class.
|
|
335
349
|
|
|
336
350
|
```cpp
|
|
337
351
|
template <StaticMethodCallback method>
|
|
338
|
-
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(
|
|
339
|
-
|
|
340
|
-
|
|
352
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(
|
|
353
|
+
const char* utf8name,
|
|
354
|
+
napi_property_attributes attributes = napi_default,
|
|
355
|
+
void* data = nullptr);
|
|
341
356
|
```
|
|
342
357
|
|
|
343
358
|
- `[in] method`: The native function that represents a static method of a
|
|
@@ -353,13 +368,14 @@ JavaScript class.
|
|
|
353
368
|
|
|
354
369
|
### StaticMethod
|
|
355
370
|
|
|
356
|
-
Creates property descriptor that represents a static method of a JavaScript
|
|
371
|
+
Creates property descriptor that represents a static method of a JavaScript
|
|
372
|
+
class.
|
|
357
373
|
|
|
358
374
|
```cpp
|
|
359
375
|
template <StaticVoidMethodCallback method>
|
|
360
376
|
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
|
|
361
|
-
|
|
362
|
-
|
|
377
|
+
napi_property_attributes attributes = napi_default,
|
|
378
|
+
void* data = nullptr);
|
|
363
379
|
```
|
|
364
380
|
|
|
365
381
|
- `[in] method`: The native function that represents a static method of a
|
|
@@ -375,13 +391,14 @@ JavaScript class.
|
|
|
375
391
|
|
|
376
392
|
### StaticMethod
|
|
377
393
|
|
|
378
|
-
Creates property descriptor that represents a static method of a JavaScript
|
|
394
|
+
Creates property descriptor that represents a static method of a JavaScript
|
|
395
|
+
class.
|
|
379
396
|
|
|
380
397
|
```cpp
|
|
381
398
|
template <StaticMethodCallback method>
|
|
382
399
|
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
|
|
383
|
-
|
|
384
|
-
|
|
400
|
+
napi_property_attributes attributes = napi_default,
|
|
401
|
+
void* data = nullptr);
|
|
385
402
|
```
|
|
386
403
|
|
|
387
404
|
- `[in] method`: The native function that represents a static method of a
|
|
@@ -400,19 +417,20 @@ Creates property descriptor that represents a static accessor property of a
|
|
|
400
417
|
JavaScript class.
|
|
401
418
|
|
|
402
419
|
```cpp
|
|
403
|
-
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
420
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(
|
|
421
|
+
const char* utf8name,
|
|
422
|
+
StaticGetterCallback getter,
|
|
423
|
+
StaticSetterCallback setter,
|
|
424
|
+
napi_property_attributes attributes = napi_default,
|
|
425
|
+
void* data = nullptr);
|
|
408
426
|
```
|
|
409
427
|
|
|
410
428
|
- `[in] utf8name`: Null-terminated string that represents the name of a static
|
|
411
429
|
accessor property for the class.
|
|
412
|
-
- `[in] getter`: The native function to call when a get access to the property
|
|
413
|
-
a JavaScript class is performed.
|
|
414
|
-
- `[in] setter`: The native function to call when a set access to the property
|
|
415
|
-
a JavaScript class is performed.
|
|
430
|
+
- `[in] getter`: The native function to call when a get access to the property
|
|
431
|
+
of a JavaScript class is performed.
|
|
432
|
+
- `[in] setter`: The native function to call when a set access to the property
|
|
433
|
+
of a JavaScript class is performed.
|
|
416
434
|
- `[in] attributes`: The attributes associated with a particular property.
|
|
417
435
|
One or more of `napi_property_attributes`.
|
|
418
436
|
- `[in] data`: User-provided data passed into getter or setter when
|
|
@@ -428,17 +446,17 @@ JavaScript class.
|
|
|
428
446
|
|
|
429
447
|
```cpp
|
|
430
448
|
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(Symbol name,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
449
|
+
StaticGetterCallback getter,
|
|
450
|
+
StaticSetterCallback setter,
|
|
451
|
+
napi_property_attributes attributes = napi_default,
|
|
452
|
+
void* data = nullptr);
|
|
435
453
|
```
|
|
436
454
|
|
|
437
455
|
- `[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
|
|
439
|
-
a JavaScript class is performed.
|
|
440
|
-
- `[in] setter`: The native function to call when a set access to the property
|
|
441
|
-
a JavaScript class is performed.
|
|
456
|
+
- `[in] getter`: The native function to call when a get access to the property
|
|
457
|
+
of a JavaScript class is performed.
|
|
458
|
+
- `[in] setter`: The native function to call when a set access to the property
|
|
459
|
+
of a JavaScript class is performed.
|
|
442
460
|
- `[in] attributes`: The attributes associated with a particular property.
|
|
443
461
|
One or more of `napi_property_attributes`.
|
|
444
462
|
- `[in] data`: User-provided data passed into getter or setter when
|
|
@@ -454,15 +472,16 @@ JavaScript class.
|
|
|
454
472
|
|
|
455
473
|
```cpp
|
|
456
474
|
template <StaticGetterCallback getter, StaticSetterCallback setter=nullptr>
|
|
457
|
-
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(
|
|
458
|
-
|
|
459
|
-
|
|
475
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(
|
|
476
|
+
const char* utf8name,
|
|
477
|
+
napi_property_attributes attributes = napi_default,
|
|
478
|
+
void* data = nullptr);
|
|
460
479
|
```
|
|
461
480
|
|
|
462
|
-
- `[in] getter`: The native function to call when a get access to the property
|
|
463
|
-
a JavaScript class is performed.
|
|
464
|
-
- `[in] setter`: The native function to call when a set access to the property
|
|
465
|
-
a JavaScript class is performed.
|
|
481
|
+
- `[in] getter`: The native function to call when a get access to the property
|
|
482
|
+
of a JavaScript class is performed.
|
|
483
|
+
- `[in] setter`: The native function to call when a set access to the property
|
|
484
|
+
of a JavaScript class is performed.
|
|
466
485
|
- `[in] utf8name`: Null-terminated string that represents the name of a static
|
|
467
486
|
accessor property for the class.
|
|
468
487
|
- `[in] attributes`: The attributes associated with a particular property.
|
|
@@ -481,14 +500,14 @@ JavaScript class.
|
|
|
481
500
|
```cpp
|
|
482
501
|
template <StaticGetterCallback getter, StaticSetterCallback setter=nullptr>
|
|
483
502
|
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(Symbol name,
|
|
484
|
-
|
|
485
|
-
|
|
503
|
+
napi_property_attributes attributes = napi_default,
|
|
504
|
+
void* data = nullptr);
|
|
486
505
|
```
|
|
487
506
|
|
|
488
|
-
- `[in] getter`: The native function to call when a get access to the property
|
|
489
|
-
a JavaScript class is performed.
|
|
490
|
-
- `[in] setter`: The native function to call when a set access to the property
|
|
491
|
-
a JavaScript class is performed.
|
|
507
|
+
- `[in] getter`: The native function to call when a get access to the property
|
|
508
|
+
of a JavaScript class is performed.
|
|
509
|
+
- `[in] setter`: The native function to call when a set access to the property
|
|
510
|
+
of a JavaScript class is performed.
|
|
492
511
|
- `[in] name`: Napi:Symbol that represents the name of a static accessor.
|
|
493
512
|
- `[in] attributes`: The attributes associated with a particular property.
|
|
494
513
|
One or more of `napi_property_attributes`.
|
|
@@ -498,299 +517,23 @@ is invoked.
|
|
|
498
517
|
Returns `Napi::PropertyDescriptor` object that represents a static accessor
|
|
499
518
|
property of a JavaScript class.
|
|
500
519
|
|
|
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
520
|
### StaticValue
|
|
780
521
|
|
|
781
522
|
Creates property descriptor that represents an static value property of a
|
|
782
523
|
JavaScript class.
|
|
783
524
|
```cpp
|
|
784
|
-
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticValue(
|
|
785
|
-
|
|
786
|
-
|
|
525
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticValue(
|
|
526
|
+
const char* utf8name,
|
|
527
|
+
Napi::Value value,
|
|
528
|
+
napi_property_attributes attributes = napi_default);
|
|
787
529
|
```
|
|
788
530
|
|
|
789
531
|
- `[in] utf8name`: Null-terminated string that represents the name of the static
|
|
790
532
|
property.
|
|
791
533
|
- `[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
|
|
793
|
-
to the napi_static attribute. One or more of
|
|
534
|
+
- `[in] attributes`: The attributes to be associated with the property in
|
|
535
|
+
addition to the napi_static attribute. One or more of
|
|
536
|
+
`napi_property_attributes`.
|
|
794
537
|
|
|
795
538
|
Returns `Napi::PropertyDescriptor` object that represents an static value
|
|
796
539
|
property of a JavaScript class
|
|
@@ -801,51 +544,18 @@ Creates property descriptor that represents an static value property of a
|
|
|
801
544
|
JavaScript class.
|
|
802
545
|
```cpp
|
|
803
546
|
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticValue(Symbol name,
|
|
804
|
-
|
|
805
|
-
|
|
547
|
+
Napi::Value value,
|
|
548
|
+
napi_property_attributes attributes = napi_default);
|
|
806
549
|
```
|
|
807
550
|
|
|
808
551
|
- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
|
|
809
552
|
name of the static property.
|
|
810
553
|
- `[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
|
|
812
|
-
to the napi_static attribute. One or more of
|
|
554
|
+
- `[in] attributes`: The attributes to be associated with the property in
|
|
555
|
+
addition to the napi_static attribute. One or more of
|
|
556
|
+
`napi_property_attributes`.
|
|
813
557
|
|
|
814
558
|
Returns `Napi::PropertyDescriptor` object that represents an static value
|
|
815
559
|
property of a JavaScript class
|
|
816
560
|
|
|
817
|
-
|
|
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
|
|
561
|
+
[`Napi::InstanceWrap<T>`]: ./instance_wrap.md
|