node-addon-api 2.0.2 → 3.0.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.
- package/.travis.yml +1 -4
- package/CHANGELOG.md +88 -30
- package/README.md +53 -7
- package/benchmark/README.md +47 -0
- package/benchmark/binding.gyp +25 -0
- package/benchmark/function_args.cc +153 -0
- package/benchmark/function_args.js +52 -0
- package/benchmark/index.js +34 -0
- package/benchmark/property_descriptor.cc +60 -0
- package/benchmark/property_descriptor.js +29 -0
- package/common.gypi +21 -0
- package/doc/async_worker.md +33 -4
- package/doc/{async_progress_worker.md → async_worker_variants.md} +115 -3
- package/doc/bigint.md +2 -1
- package/doc/class_property_descriptor.md +3 -3
- package/doc/creating_a_release.md +5 -5
- package/doc/env.md +14 -0
- package/doc/function.md +108 -1
- package/doc/object.md +40 -1
- package/doc/object_lifetime_management.md +1 -1
- package/doc/object_wrap.md +278 -2
- package/doc/property_descriptor.md +64 -9
- package/doc/setup.md +0 -1
- package/doc/string.md +1 -1
- package/doc/symbol.md +1 -1
- package/doc/value.md +1 -1
- package/except.gypi +16 -0
- package/index.js +5 -42
- package/napi-inl.h +727 -141
- package/napi.h +338 -83
- package/node_api.gyp +9 -0
- package/noexcept.gypi +16 -0
- package/{src/nothing.c → nothing.c} +0 -0
- package/package.json +33 -1
- package/tools/README.md +4 -4
- package/tools/conversion.js +0 -4
- package/external-napi/node_api.h +0 -7
- package/src/node_api.cc +0 -3655
- package/src/node_api.gyp +0 -21
- package/src/node_api.h +0 -588
- package/src/node_api_types.h +0 -115
- package/src/node_internals.cc +0 -142
- package/src/node_internals.h +0 -157
- package/src/util-inl.h +0 -38
- package/src/util.h +0 -7
package/doc/object_wrap.md
CHANGED
|
@@ -34,8 +34,8 @@ class Example : public Napi::ObjectWrap<Example> {
|
|
|
34
34
|
Napi::Object Example::Init(Napi::Env env, Napi::Object exports) {
|
|
35
35
|
// This method is used to hook the accessor and method callbacks
|
|
36
36
|
Napi::Function func = DefineClass(env, "Example", {
|
|
37
|
-
InstanceMethod("GetValue"
|
|
38
|
-
InstanceMethod("SetValue"
|
|
37
|
+
InstanceMethod<&Example::GetValue>("GetValue"),
|
|
38
|
+
InstanceMethod<&Example::SetValue>("SetValue")
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
// Create a peristent reference to the class constructor. This will allow
|
|
@@ -289,6 +289,93 @@ One or more of `napi_property_attributes`.
|
|
|
289
289
|
Returns `Napi::PropertyDescriptor` object that represents a static method of a
|
|
290
290
|
JavaScript class.
|
|
291
291
|
|
|
292
|
+
### StaticMethod
|
|
293
|
+
|
|
294
|
+
Creates property descriptor that represents a static method of a JavaScript class.
|
|
295
|
+
|
|
296
|
+
```cpp
|
|
297
|
+
template <StaticVoidMethodCallback method>
|
|
298
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(const char* utf8name,
|
|
299
|
+
napi_property_attributes attributes = napi_default,
|
|
300
|
+
void* data = nullptr);
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
- `[in] method`: The native function that represents a static method of a
|
|
304
|
+
JavaScript class. This function returns nothing.
|
|
305
|
+
- `[in] utf8name`: Null-terminated string that represents the name of a static
|
|
306
|
+
method for the class.
|
|
307
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
308
|
+
One or more of `napi_property_attributes`.
|
|
309
|
+
- `[in] data`: User-provided data passed into method when it is invoked.
|
|
310
|
+
|
|
311
|
+
Returns `Napi::PropertyDescriptor` object that represents the static method of a
|
|
312
|
+
JavaScript class.
|
|
313
|
+
|
|
314
|
+
### StaticMethod
|
|
315
|
+
|
|
316
|
+
Creates property descriptor that represents a static method of a JavaScript class.
|
|
317
|
+
|
|
318
|
+
```cpp
|
|
319
|
+
template <StaticMethodCallback method>
|
|
320
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(const char* utf8name,
|
|
321
|
+
napi_property_attributes attributes = napi_default,
|
|
322
|
+
void* data = nullptr);
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
- `[in] method`: The native function that represents a static method of a
|
|
326
|
+
JavaScript class.
|
|
327
|
+
- `[in] utf8name`: Null-terminated string that represents the name of a static
|
|
328
|
+
method for the class.
|
|
329
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
330
|
+
One or more of `napi_property_attributes`.
|
|
331
|
+
- `[in] data`: User-provided data passed into method when it is invoked.
|
|
332
|
+
|
|
333
|
+
Returns `Napi::PropertyDescriptor` object that represents a static method of a
|
|
334
|
+
JavaScript class.
|
|
335
|
+
|
|
336
|
+
### StaticMethod
|
|
337
|
+
|
|
338
|
+
Creates property descriptor that represents a static method of a JavaScript class.
|
|
339
|
+
|
|
340
|
+
```cpp
|
|
341
|
+
template <StaticVoidMethodCallback method>
|
|
342
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
|
|
343
|
+
napi_property_attributes attributes = napi_default,
|
|
344
|
+
void* data = nullptr);
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
- `[in] method`: The native function that represents a static method of a
|
|
348
|
+
JavaScript class.
|
|
349
|
+
- `[in] name`: Napi:Symbol that represents the name of a static
|
|
350
|
+
method for the class.
|
|
351
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
352
|
+
One or more of `napi_property_attributes`.
|
|
353
|
+
- `[in] data`: User-provided data passed into method when it is invoked.
|
|
354
|
+
|
|
355
|
+
Returns `Napi::PropertyDescriptor` object that represents the static method of a
|
|
356
|
+
JavaScript class.
|
|
357
|
+
|
|
358
|
+
### StaticMethod
|
|
359
|
+
|
|
360
|
+
Creates property descriptor that represents a static method of a JavaScript class.
|
|
361
|
+
|
|
362
|
+
```cpp
|
|
363
|
+
template <StaticMethodCallback method>
|
|
364
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticMethod(Symbol name,
|
|
365
|
+
napi_property_attributes attributes = napi_default,
|
|
366
|
+
void* data = nullptr);
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
- `[in] method`: The native function that represents a static method of a
|
|
370
|
+
JavaScript class.
|
|
371
|
+
- `[in] name`: Napi:Symbol that represents the name of a static.
|
|
372
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
373
|
+
One or more of `napi_property_attributes`.
|
|
374
|
+
- `[in] data`: User-provided data passed into method when it is invoked.
|
|
375
|
+
|
|
376
|
+
Returns `Napi::PropertyDescriptor` object that represents a static method of a
|
|
377
|
+
JavaScript class.
|
|
378
|
+
|
|
292
379
|
### StaticAccessor
|
|
293
380
|
|
|
294
381
|
Creates property descriptor that represents a static accessor property of a
|
|
@@ -342,6 +429,57 @@ is invoked.
|
|
|
342
429
|
Returns `Napi::PropertyDescriptor` object that represents a static accessor
|
|
343
430
|
property of a JavaScript class.
|
|
344
431
|
|
|
432
|
+
### StaticAccessor
|
|
433
|
+
|
|
434
|
+
Creates property descriptor that represents a static accessor property of a
|
|
435
|
+
JavaScript class.
|
|
436
|
+
|
|
437
|
+
```cpp
|
|
438
|
+
template <StaticGetterCallback getter, StaticSetterCallback setter=nullptr>
|
|
439
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(const char* utf8name,
|
|
440
|
+
napi_property_attributes attributes = napi_default,
|
|
441
|
+
void* data = nullptr);
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
- `[in] getter`: The native function to call when a get access to the property of
|
|
445
|
+
a JavaScript class is performed.
|
|
446
|
+
- `[in] setter`: The native function to call when a set access to the property of
|
|
447
|
+
a JavaScript class is performed.
|
|
448
|
+
- `[in] utf8name`: Null-terminated string that represents the name of a static
|
|
449
|
+
accessor property for the class.
|
|
450
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
451
|
+
One or more of `napi_property_attributes`.
|
|
452
|
+
- `[in] data`: User-provided data passed into getter or setter when
|
|
453
|
+
is invoked.
|
|
454
|
+
|
|
455
|
+
Returns `Napi::PropertyDescriptor` object that represents a static accessor
|
|
456
|
+
property of a JavaScript class.
|
|
457
|
+
|
|
458
|
+
### StaticAccessor
|
|
459
|
+
|
|
460
|
+
Creates property descriptor that represents a static accessor property of a
|
|
461
|
+
JavaScript class.
|
|
462
|
+
|
|
463
|
+
```cpp
|
|
464
|
+
template <StaticGetterCallback getter, StaticSetterCallback setter=nullptr>
|
|
465
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::StaticAccessor(Symbol name,
|
|
466
|
+
napi_property_attributes attributes = napi_default,
|
|
467
|
+
void* data = nullptr);
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
- `[in] getter`: The native function to call when a get access to the property of
|
|
471
|
+
a JavaScript class is performed.
|
|
472
|
+
- `[in] setter`: The native function to call when a set access to the property of
|
|
473
|
+
a JavaScript class is performed.
|
|
474
|
+
- `[in] name`: Napi:Symbol that represents the name of a static accessor.
|
|
475
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
476
|
+
One or more of `napi_property_attributes`.
|
|
477
|
+
- `[in] data`: User-provided data passed into getter or setter when
|
|
478
|
+
is invoked.
|
|
479
|
+
|
|
480
|
+
Returns `Napi::PropertyDescriptor` object that represents a static accessor
|
|
481
|
+
property of a JavaScript class.
|
|
482
|
+
|
|
345
483
|
### InstanceMethod
|
|
346
484
|
|
|
347
485
|
Creates property descriptor that represents an instance method of a JavaScript class.
|
|
@@ -430,6 +568,94 @@ One or more of `napi_property_attributes`.
|
|
|
430
568
|
Returns `Napi::PropertyDescriptor` object that represents an instance method of a
|
|
431
569
|
JavaScript class.
|
|
432
570
|
|
|
571
|
+
### InstanceMethod
|
|
572
|
+
|
|
573
|
+
Creates property descriptor that represents an instance method of a JavaScript class.
|
|
574
|
+
|
|
575
|
+
```cpp
|
|
576
|
+
template <InstanceVoidMethodCallback method>
|
|
577
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(const char* utf8name,
|
|
578
|
+
napi_property_attributes attributes = napi_default,
|
|
579
|
+
void* data = nullptr);
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
- `[in] method`: The native function that represents an instance method of a
|
|
583
|
+
JavaScript class.
|
|
584
|
+
- `[in] utf8name`: Null-terminated string that represents the name of an instance
|
|
585
|
+
method for the class.
|
|
586
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
587
|
+
One or more of `napi_property_attributes`.
|
|
588
|
+
- `[in] data`: User-provided data passed into method when it is invoked.
|
|
589
|
+
|
|
590
|
+
Returns `Napi::PropertyDescriptor` object that represents an instance method of a
|
|
591
|
+
JavaScript class.
|
|
592
|
+
|
|
593
|
+
### InstanceMethod
|
|
594
|
+
|
|
595
|
+
Creates property descriptor that represents an instance method of a JavaScript class.
|
|
596
|
+
|
|
597
|
+
```cpp
|
|
598
|
+
template <InstanceMethodCallback method>
|
|
599
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(const char* utf8name,
|
|
600
|
+
napi_property_attributes attributes = napi_default,
|
|
601
|
+
void* data = nullptr);
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
- `[in] method`: The native function that represents an instance method of a
|
|
605
|
+
JavaScript class.
|
|
606
|
+
- `[in] utf8name`: Null-terminated string that represents the name of an instance
|
|
607
|
+
method for the class.
|
|
608
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
609
|
+
One or more of `napi_property_attributes`.
|
|
610
|
+
- `[in] data`: User-provided data passed into method when it is invoked.
|
|
611
|
+
|
|
612
|
+
Returns `Napi::PropertyDescriptor` object that represents an instance method of a
|
|
613
|
+
JavaScript class.
|
|
614
|
+
|
|
615
|
+
### InstanceMethod
|
|
616
|
+
|
|
617
|
+
Creates property descriptor that represents an instance method of a JavaScript class.
|
|
618
|
+
|
|
619
|
+
```cpp
|
|
620
|
+
template <InstanceVoidMethodCallback method>
|
|
621
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(Napi::Symbol name,
|
|
622
|
+
napi_property_attributes attributes = napi_default,
|
|
623
|
+
void* data = nullptr);
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
- `[in] method`: The native function that represents an instance method of a
|
|
627
|
+
JavaScript class.
|
|
628
|
+
- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
|
|
629
|
+
instance method for the class.
|
|
630
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
631
|
+
One or more of `napi_property_attributes`.
|
|
632
|
+
- `[in] data`: User-provided data passed into method when it is invoked.
|
|
633
|
+
|
|
634
|
+
Returns `Napi::PropertyDescriptor` object that represents an instance method of a
|
|
635
|
+
JavaScript class.
|
|
636
|
+
|
|
637
|
+
### InstanceMethod
|
|
638
|
+
|
|
639
|
+
Creates property descriptor that represents an instance method of a JavaScript class.
|
|
640
|
+
|
|
641
|
+
```cpp
|
|
642
|
+
template <InstanceMethodCallback method>
|
|
643
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceMethod(Napi::Symbol name,
|
|
644
|
+
napi_property_attributes attributes = napi_default,
|
|
645
|
+
void* data = nullptr);
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
- `[in] method`: The native function that represents an instance method of a
|
|
649
|
+
JavaScript class.
|
|
650
|
+
- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
|
|
651
|
+
instance method for the class.
|
|
652
|
+
- `[in] attributes`: The attributes associated with a particular property.
|
|
653
|
+
One or more of `napi_property_attributes`.
|
|
654
|
+
- `[in] data`: User-provided data passed into method when it is invoked.
|
|
655
|
+
|
|
656
|
+
Returns `Napi::PropertyDescriptor` object that represents an instance method of a
|
|
657
|
+
JavaScript class.
|
|
658
|
+
|
|
433
659
|
### InstanceAccessor
|
|
434
660
|
|
|
435
661
|
Creates property descriptor that represents an instance accessor property of a
|
|
@@ -482,6 +708,56 @@ One or more of `napi_property_attributes`.
|
|
|
482
708
|
Returns `Napi::PropertyDescriptor` object that represents an instance accessor
|
|
483
709
|
property of a JavaScript class.
|
|
484
710
|
|
|
711
|
+
### InstanceAccessor
|
|
712
|
+
|
|
713
|
+
Creates property descriptor that represents an instance accessor property of a
|
|
714
|
+
JavaScript class.
|
|
715
|
+
|
|
716
|
+
```cpp
|
|
717
|
+
template <InstanceGetterCallback getter, InstanceSetterCallback setter=nullptr>
|
|
718
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceAccessor(const char* utf8name,
|
|
719
|
+
napi_property_attributes attributes = napi_default,
|
|
720
|
+
void* data = nullptr);
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
- `[in] getter`: The native function to call when a get access to the property of
|
|
724
|
+
a JavaScript class is performed.
|
|
725
|
+
- `[in] setter`: The native function to call when a set access to the property of
|
|
726
|
+
a JavaScript class is performed.
|
|
727
|
+
- `[in] utf8name`: Null-terminated string that represents the name of an instance
|
|
728
|
+
accessor property for the class.
|
|
729
|
+
- `[in] attributes`: The attributes associated with the particular property.
|
|
730
|
+
One or more of `napi_property_attributes`.
|
|
731
|
+
- `[in] data`: User-provided data passed into getter or setter when this is invoked.
|
|
732
|
+
|
|
733
|
+
Returns `Napi::PropertyDescriptor` object that represents an instance accessor
|
|
734
|
+
property of a JavaScript class.
|
|
735
|
+
|
|
736
|
+
### InstanceAccessor
|
|
737
|
+
|
|
738
|
+
Creates property descriptor that represents an instance accessor property of a
|
|
739
|
+
JavaScript class.
|
|
740
|
+
|
|
741
|
+
```cpp
|
|
742
|
+
template <InstanceGetterCallback getter, InstanceSetterCallback setter=nullptr>
|
|
743
|
+
static Napi::PropertyDescriptor Napi::ObjectWrap::InstanceAccessor(Symbol name,
|
|
744
|
+
napi_property_attributes attributes = napi_default,
|
|
745
|
+
void* data = nullptr);
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
- `[in] getter`: The native function to call when a get access to the property of
|
|
749
|
+
a JavaScript class is performed.
|
|
750
|
+
- `[in] setter`: The native function to call when a set access to the property of
|
|
751
|
+
a JavaScript class is performed.
|
|
752
|
+
- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
|
|
753
|
+
instance accessor.
|
|
754
|
+
- `[in] attributes`: The attributes associated with the particular property.
|
|
755
|
+
One or more of `napi_property_attributes`.
|
|
756
|
+
- `[in] data`: User-provided data passed into getter or setter when this is invoked.
|
|
757
|
+
|
|
758
|
+
Returns `Napi::PropertyDescriptor` object that represents an instance accessor
|
|
759
|
+
property of a JavaScript class.
|
|
760
|
+
|
|
485
761
|
### StaticValue
|
|
486
762
|
|
|
487
763
|
Creates property descriptor that represents an static value property of a
|
|
@@ -26,15 +26,9 @@ Void Init(Env env) {
|
|
|
26
26
|
Object obj = Object::New(env);
|
|
27
27
|
|
|
28
28
|
// Accessor
|
|
29
|
-
PropertyDescriptor pd1 = PropertyDescriptor::Accessor(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
TestGetter);
|
|
33
|
-
PropertyDescriptor pd2 = PropertyDescriptor::Accessor(env,
|
|
34
|
-
obj,
|
|
35
|
-
"pd2",
|
|
36
|
-
TestGetter,
|
|
37
|
-
TestSetter);
|
|
29
|
+
PropertyDescriptor pd1 = PropertyDescriptor::Accessor<TestGetter>("pd1");
|
|
30
|
+
PropertyDescriptor pd2 =
|
|
31
|
+
PropertyDescriptor::Accessor<TestGetter, TestSetter>("pd2");
|
|
38
32
|
// Function
|
|
39
33
|
PropertyDescriptor pd3 = PropertyDescriptor::Function(env,
|
|
40
34
|
"function",
|
|
@@ -51,6 +45,26 @@ Void Init(Env env) {
|
|
|
51
45
|
}
|
|
52
46
|
```
|
|
53
47
|
|
|
48
|
+
## Types
|
|
49
|
+
|
|
50
|
+
### PropertyDescriptor::GetterCallback
|
|
51
|
+
|
|
52
|
+
```cpp
|
|
53
|
+
typedef Napi::Value (*GetterCallback)(const Napi::CallbackInfo& info);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This is the signature of a getter function to be passed as a template parameter
|
|
57
|
+
to `PropertyDescriptor::Accessor`.
|
|
58
|
+
|
|
59
|
+
### PropertyDescriptor::SetterCallback
|
|
60
|
+
|
|
61
|
+
```cpp
|
|
62
|
+
typedef void (*SetterCallback)(const Napi::CallbackInfo& info);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This is the signature of a setter function to be passed as a template parameter
|
|
66
|
+
to `PropertyDescriptor::Accessor`.
|
|
67
|
+
|
|
54
68
|
## Methods
|
|
55
69
|
|
|
56
70
|
### Constructor
|
|
@@ -63,6 +77,47 @@ Napi::PropertyDescriptor::PropertyDescriptor (napi_property_descriptor desc);
|
|
|
63
77
|
|
|
64
78
|
### Accessor
|
|
65
79
|
|
|
80
|
+
```cpp
|
|
81
|
+
template <Napi::PropertyDescriptor::GetterCallback Getter>
|
|
82
|
+
static Napi::PropertyDescriptor Napi::PropertyDescriptor::Accessor (___ name,
|
|
83
|
+
napi_property_attributes attributes = napi_default,
|
|
84
|
+
void* data = nullptr);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
* `[template] Getter`: A getter function.
|
|
88
|
+
* `[in] attributes`: Potential attributes for the getter function.
|
|
89
|
+
* `[in] data`: A pointer to data of any type, default is a null pointer.
|
|
90
|
+
|
|
91
|
+
Returns a PropertyDescriptor that contains a read-only property.
|
|
92
|
+
|
|
93
|
+
The name of the property can be any of the following types:
|
|
94
|
+
- `const char*`
|
|
95
|
+
- `const std::string &`
|
|
96
|
+
- `napi_value value`
|
|
97
|
+
- `Napi::Name`
|
|
98
|
+
|
|
99
|
+
```cpp
|
|
100
|
+
template <
|
|
101
|
+
Napi::PropertyDescriptor::GetterCallback Getter,
|
|
102
|
+
Napi::PropertyDescriptor::SetterCallback Setter>
|
|
103
|
+
static Napi::PropertyDescriptor Napi::PropertyDescriptor::Accessor (___ name,
|
|
104
|
+
napi_property_attributes attributes = napi_default,
|
|
105
|
+
void* data = nullptr);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
* `[template] Getter`: A getter function.
|
|
109
|
+
* `[template] Setter`: A setter function.
|
|
110
|
+
* `[in] attributes`: Potential attributes for the getter function.
|
|
111
|
+
* `[in] data`: A pointer to data of any type, default is a null pointer.
|
|
112
|
+
|
|
113
|
+
Returns a PropertyDescriptor that contains a read-write property.
|
|
114
|
+
|
|
115
|
+
The name of the property can be any of the following types:
|
|
116
|
+
- `const char*`
|
|
117
|
+
- `const std::string &`
|
|
118
|
+
- `napi_value value`
|
|
119
|
+
- `Napi::Name`
|
|
120
|
+
|
|
66
121
|
```cpp
|
|
67
122
|
static Napi::PropertyDescriptor Napi::PropertyDescriptor::Accessor (___ name,
|
|
68
123
|
Getter getter,
|
package/doc/setup.md
CHANGED
|
@@ -27,7 +27,6 @@ To use **N-API** in a native module:
|
|
|
27
27
|
|
|
28
28
|
```gyp
|
|
29
29
|
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
|
|
30
|
-
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
|
|
31
30
|
```
|
|
32
31
|
|
|
33
32
|
3. Decide whether the package will enable C++ exceptions in the N-API wrapper.
|
package/doc/string.md
CHANGED
|
@@ -62,7 +62,7 @@ Napi::String::New(napi_env env, const char16_t* value, size_t length);
|
|
|
62
62
|
|
|
63
63
|
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Value` object.
|
|
64
64
|
- `[in] value`: The C++ primitive from which to instantiate the `Napi::Value`. `value` may be any of:
|
|
65
|
-
- `std::string&` - represents
|
|
65
|
+
- `std::string&` - represents a UTF8 string.
|
|
66
66
|
- `std::u16string&` - represents a UTF16-LE string.
|
|
67
67
|
- `const char*` - represents a UTF8 string.
|
|
68
68
|
- `const char16_t*` - represents a UTF16-LE string.
|
package/doc/symbol.md
CHANGED
|
@@ -23,7 +23,7 @@ Napi::Symbol::New(napi_env env, napi_value description);
|
|
|
23
23
|
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Symbol` object.
|
|
24
24
|
- `[in] value`: The C++ primitive which represents the description hint for the `Napi::Symbol`.
|
|
25
25
|
`description` may be any of:
|
|
26
|
-
- `std::string&` -
|
|
26
|
+
- `std::string&` - UTF8 string description.
|
|
27
27
|
- `const char*` - represents a UTF8 string description.
|
|
28
28
|
- `String` - Node addon API String description.
|
|
29
29
|
- `napi_value` - N-API `napi_value` description.
|
package/doc/value.md
CHANGED
|
@@ -6,7 +6,7 @@ Value is a the base class upon which other JavaScript values such as Number, Boo
|
|
|
6
6
|
|
|
7
7
|
The following classes inherit, either directly or indirectly, from `Napi::Value`:
|
|
8
8
|
|
|
9
|
-
- [`Napi::Array`](
|
|
9
|
+
- [`Napi::Array`](basic_types.md#array)
|
|
10
10
|
- [`Napi::ArrayBuffer`](array_buffer.md)
|
|
11
11
|
- [`Napi::Boolean`](boolean.md)
|
|
12
12
|
- [`Napi::Buffer`](buffer.md)
|
package/except.gypi
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
'defines': [ 'NAPI_CPP_EXCEPTIONS' ],
|
|
3
|
+
'cflags!': [ '-fno-exceptions' ],
|
|
4
|
+
'cflags_cc!': [ '-fno-exceptions' ],
|
|
5
|
+
'msvs_settings': {
|
|
6
|
+
'VCCLCompilerTool': {
|
|
7
|
+
'ExceptionHandling': 1,
|
|
8
|
+
'EnablePREfast': 'true',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
'xcode_settings': {
|
|
12
|
+
'CLANG_CXX_LIBRARY': 'libc++',
|
|
13
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.7',
|
|
14
|
+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
|
15
|
+
},
|
|
16
|
+
}
|
package/index.js
CHANGED
|
@@ -1,45 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var versionArray = process.version
|
|
4
|
-
.substr(1)
|
|
5
|
-
.replace(/-.*$/, '')
|
|
6
|
-
.split('.')
|
|
7
|
-
.map(function(item) {
|
|
8
|
-
return +item;
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
// TODO: Check if the main node semantic version is within multiple ranges,
|
|
12
|
-
// or detect presence of built-in N-API by some other mechanism TBD.
|
|
13
|
-
|
|
14
|
-
// We know which version of Node.js first shipped the incarnation of the API
|
|
15
|
-
// available in *this* package. So, if we find that the Node.js version is below
|
|
16
|
-
// that, we indicate that the API is missing from Node.js.
|
|
17
|
-
var isNodeApiBuiltin = (
|
|
18
|
-
versionArray[0] > 8 ||
|
|
19
|
-
(versionArray[0] == 8 && versionArray[1] >= 6) ||
|
|
20
|
-
(versionArray[0] == 6 && versionArray[1] >= 15) ||
|
|
21
|
-
(versionArray[0] == 6 && versionArray[1] >= 14 && versionArray[2] >= 2));
|
|
22
|
-
|
|
23
|
-
// The flag is not needed when the Node version is not 8, nor if the API is
|
|
24
|
-
// built-in, because we removed the flag at the same time as creating the final
|
|
25
|
-
// incarnation of the built-in API.
|
|
26
|
-
var needsFlag = (!isNodeApiBuiltin && versionArray[0] == 8);
|
|
27
|
-
|
|
28
|
-
var include = [__dirname];
|
|
29
|
-
var gyp = path.join(__dirname, 'src', 'node_api.gyp');
|
|
30
|
-
|
|
31
|
-
if (isNodeApiBuiltin) {
|
|
32
|
-
gyp += ':nothing';
|
|
33
|
-
} else {
|
|
34
|
-
gyp += ':node-api';
|
|
35
|
-
include.unshift(path.join(__dirname, 'external-napi'));
|
|
36
|
-
}
|
|
1
|
+
const path = require('path');
|
|
37
2
|
|
|
38
3
|
module.exports = {
|
|
39
|
-
include:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
isNodeApiBuiltin: isNodeApiBuiltin,
|
|
44
|
-
needsFlag: needsFlag
|
|
4
|
+
include: `"${__dirname}"`,
|
|
5
|
+
gyp: path.join(__dirname, 'node_api.gyp:nothing'),
|
|
6
|
+
isNodeApiBuiltin: true,
|
|
7
|
+
needsFlag: false
|
|
45
8
|
};
|