node-addon-api 4.3.0 → 5.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/README.md +3 -3
- package/napi-inl.h +111 -61
- package/napi.h +79 -59
- package/package.json +22 -6
- package/tools/clang-format.js +4 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ git branch -u origin/main main
|
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
# **node-addon-api module**
|
|
13
|
-
This module contains
|
|
13
|
+
This module contains **header-only C++ wrapper classes** which simplify
|
|
14
14
|
the use of the C based [Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html)
|
|
15
15
|
provided by Node.js when using C++. It provides a C++ object model
|
|
16
16
|
and exception handling semantics with low overhead.
|
|
@@ -70,7 +70,7 @@ and node-addon-api.
|
|
|
70
70
|
- **[Contributors](#contributors)**
|
|
71
71
|
- **[License](#license)**
|
|
72
72
|
|
|
73
|
-
## **Current version:
|
|
73
|
+
## **Current version: 5.0.0**
|
|
74
74
|
|
|
75
75
|
(See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
|
|
76
76
|
|
|
@@ -83,7 +83,7 @@ This allows addons built with it to run with Node.js versions which support the
|
|
|
83
83
|
**However** the node-addon-api support model is to support only the active LTS Node.js versions. This means that
|
|
84
84
|
every year there will be a new major which drops support for the Node.js LTS version which has gone out of service.
|
|
85
85
|
|
|
86
|
-
The oldest Node.js version supported by the current version of node-addon-api is Node.js
|
|
86
|
+
The oldest Node.js version supported by the current version of node-addon-api is Node.js 14.x.
|
|
87
87
|
|
|
88
88
|
## Setup
|
|
89
89
|
- [Installation and usage](doc/setup.md)
|
package/napi-inl.h
CHANGED
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
namespace Napi {
|
|
20
20
|
|
|
21
|
+
#ifdef NAPI_CPP_CUSTOM_NAMESPACE
|
|
22
|
+
namespace NAPI_CPP_CUSTOM_NAMESPACE {
|
|
23
|
+
#endif
|
|
24
|
+
|
|
21
25
|
// Helpers to handle functions exposed from C++.
|
|
22
26
|
namespace details {
|
|
23
27
|
|
|
@@ -483,7 +487,7 @@ inline bool Env::IsExceptionPending() const {
|
|
|
483
487
|
return result;
|
|
484
488
|
}
|
|
485
489
|
|
|
486
|
-
inline Error Env::GetAndClearPendingException() {
|
|
490
|
+
inline Error Env::GetAndClearPendingException() const {
|
|
487
491
|
napi_value value;
|
|
488
492
|
napi_status status = napi_get_and_clear_last_exception(_env, &value);
|
|
489
493
|
if (status != napi_ok) {
|
|
@@ -493,16 +497,16 @@ inline Error Env::GetAndClearPendingException() {
|
|
|
493
497
|
return Error(_env, value);
|
|
494
498
|
}
|
|
495
499
|
|
|
496
|
-
inline MaybeOrValue<Value> Env::RunScript(const char* utf8script) {
|
|
500
|
+
inline MaybeOrValue<Value> Env::RunScript(const char* utf8script) const {
|
|
497
501
|
String script = String::New(_env, utf8script);
|
|
498
502
|
return RunScript(script);
|
|
499
503
|
}
|
|
500
504
|
|
|
501
|
-
inline MaybeOrValue<Value> Env::RunScript(const std::string& utf8script) {
|
|
505
|
+
inline MaybeOrValue<Value> Env::RunScript(const std::string& utf8script) const {
|
|
502
506
|
return RunScript(utf8script.c_str());
|
|
503
507
|
}
|
|
504
508
|
|
|
505
|
-
inline MaybeOrValue<Value> Env::RunScript(String script) {
|
|
509
|
+
inline MaybeOrValue<Value> Env::RunScript(String script) const {
|
|
506
510
|
napi_value result;
|
|
507
511
|
napi_status status = napi_run_script(_env, script, &result);
|
|
508
512
|
NAPI_RETURN_OR_THROW_IF_FAILED(
|
|
@@ -531,7 +535,7 @@ void Env::CleanupHook<Hook, Arg>::WrapperWithArg(void* data) NAPI_NOEXCEPT {
|
|
|
531
535
|
|
|
532
536
|
#if NAPI_VERSION > 5
|
|
533
537
|
template <typename T, Env::Finalizer<T> fini>
|
|
534
|
-
inline void Env::SetInstanceData(T* data) {
|
|
538
|
+
inline void Env::SetInstanceData(T* data) const {
|
|
535
539
|
napi_status status =
|
|
536
540
|
napi_set_instance_data(_env, data, [](napi_env env, void* data, void*) {
|
|
537
541
|
fini(env, static_cast<T*>(data));
|
|
@@ -542,7 +546,7 @@ inline void Env::SetInstanceData(T* data) {
|
|
|
542
546
|
template <typename DataType,
|
|
543
547
|
typename HintType,
|
|
544
548
|
Napi::Env::FinalizerWithHint<DataType, HintType> fini>
|
|
545
|
-
inline void Env::SetInstanceData(DataType* data, HintType* hint) {
|
|
549
|
+
inline void Env::SetInstanceData(DataType* data, HintType* hint) const {
|
|
546
550
|
napi_status status =
|
|
547
551
|
napi_set_instance_data(_env, data,
|
|
548
552
|
[](napi_env env, void* data, void* hint) {
|
|
@@ -552,7 +556,7 @@ inline void Env::SetInstanceData(DataType* data, HintType* hint) {
|
|
|
552
556
|
}
|
|
553
557
|
|
|
554
558
|
template <typename T>
|
|
555
|
-
inline T* Env::GetInstanceData() {
|
|
559
|
+
inline T* Env::GetInstanceData() const {
|
|
556
560
|
void* data = nullptr;
|
|
557
561
|
|
|
558
562
|
napi_status status = napi_get_instance_data(_env, &data);
|
|
@@ -1294,22 +1298,20 @@ inline Object::Object() : Value() {
|
|
|
1294
1298
|
inline Object::Object(napi_env env, napi_value value) : Value(env, value) {
|
|
1295
1299
|
}
|
|
1296
1300
|
|
|
1297
|
-
inline Object::PropertyLValue<std::string> Object::operator
|
|
1301
|
+
inline Object::PropertyLValue<std::string> Object::operator[](
|
|
1302
|
+
const char* utf8name) {
|
|
1298
1303
|
return PropertyLValue<std::string>(*this, utf8name);
|
|
1299
1304
|
}
|
|
1300
1305
|
|
|
1301
|
-
inline Object::PropertyLValue<std::string> Object::operator
|
|
1306
|
+
inline Object::PropertyLValue<std::string> Object::operator[](
|
|
1307
|
+
const std::string& utf8name) {
|
|
1302
1308
|
return PropertyLValue<std::string>(*this, utf8name);
|
|
1303
1309
|
}
|
|
1304
1310
|
|
|
1305
|
-
inline Object::PropertyLValue<uint32_t> Object::operator
|
|
1311
|
+
inline Object::PropertyLValue<uint32_t> Object::operator[](uint32_t index) {
|
|
1306
1312
|
return PropertyLValue<uint32_t>(*this, index);
|
|
1307
1313
|
}
|
|
1308
1314
|
|
|
1309
|
-
inline Object::PropertyLValue<Value> Object::operator[](Value index) {
|
|
1310
|
-
return PropertyLValue<Value>(*this, index);
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
1315
|
inline Object::PropertyLValue<Value> Object::operator[](Value index) const {
|
|
1314
1316
|
return PropertyLValue<Value>(*this, index);
|
|
1315
1317
|
}
|
|
@@ -1396,14 +1398,15 @@ inline MaybeOrValue<Value> Object::Get(const std::string& utf8name) const {
|
|
|
1396
1398
|
}
|
|
1397
1399
|
|
|
1398
1400
|
template <typename ValueType>
|
|
1399
|
-
inline MaybeOrValue<bool> Object::Set(napi_value key,
|
|
1401
|
+
inline MaybeOrValue<bool> Object::Set(napi_value key,
|
|
1402
|
+
const ValueType& value) const {
|
|
1400
1403
|
napi_status status =
|
|
1401
1404
|
napi_set_property(_env, _value, key, Value::From(_env, value));
|
|
1402
1405
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
1403
1406
|
}
|
|
1404
1407
|
|
|
1405
1408
|
template <typename ValueType>
|
|
1406
|
-
inline MaybeOrValue<bool> Object::Set(Value key, const ValueType& value) {
|
|
1409
|
+
inline MaybeOrValue<bool> Object::Set(Value key, const ValueType& value) const {
|
|
1407
1410
|
napi_status status =
|
|
1408
1411
|
napi_set_property(_env, _value, key, Value::From(_env, value));
|
|
1409
1412
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
@@ -1411,7 +1414,7 @@ inline MaybeOrValue<bool> Object::Set(Value key, const ValueType& value) {
|
|
|
1411
1414
|
|
|
1412
1415
|
template <typename ValueType>
|
|
1413
1416
|
inline MaybeOrValue<bool> Object::Set(const char* utf8name,
|
|
1414
|
-
const ValueType& value) {
|
|
1417
|
+
const ValueType& value) const {
|
|
1415
1418
|
napi_status status =
|
|
1416
1419
|
napi_set_named_property(_env, _value, utf8name, Value::From(_env, value));
|
|
1417
1420
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
@@ -1419,27 +1422,27 @@ inline MaybeOrValue<bool> Object::Set(const char* utf8name,
|
|
|
1419
1422
|
|
|
1420
1423
|
template <typename ValueType>
|
|
1421
1424
|
inline MaybeOrValue<bool> Object::Set(const std::string& utf8name,
|
|
1422
|
-
const ValueType& value) {
|
|
1425
|
+
const ValueType& value) const {
|
|
1423
1426
|
return Set(utf8name.c_str(), value);
|
|
1424
1427
|
}
|
|
1425
1428
|
|
|
1426
|
-
inline MaybeOrValue<bool> Object::Delete(napi_value key) {
|
|
1429
|
+
inline MaybeOrValue<bool> Object::Delete(napi_value key) const {
|
|
1427
1430
|
bool result;
|
|
1428
1431
|
napi_status status = napi_delete_property(_env, _value, key, &result);
|
|
1429
1432
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, result, bool);
|
|
1430
1433
|
}
|
|
1431
1434
|
|
|
1432
|
-
inline MaybeOrValue<bool> Object::Delete(Value key) {
|
|
1435
|
+
inline MaybeOrValue<bool> Object::Delete(Value key) const {
|
|
1433
1436
|
bool result;
|
|
1434
1437
|
napi_status status = napi_delete_property(_env, _value, key, &result);
|
|
1435
1438
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, result, bool);
|
|
1436
1439
|
}
|
|
1437
1440
|
|
|
1438
|
-
inline MaybeOrValue<bool> Object::Delete(const char* utf8name) {
|
|
1441
|
+
inline MaybeOrValue<bool> Object::Delete(const char* utf8name) const {
|
|
1439
1442
|
return Delete(String::New(_env, utf8name));
|
|
1440
1443
|
}
|
|
1441
1444
|
|
|
1442
|
-
inline MaybeOrValue<bool> Object::Delete(const std::string& utf8name) {
|
|
1445
|
+
inline MaybeOrValue<bool> Object::Delete(const std::string& utf8name) const {
|
|
1443
1446
|
return Delete(String::New(_env, utf8name));
|
|
1444
1447
|
}
|
|
1445
1448
|
|
|
@@ -1456,13 +1459,14 @@ inline MaybeOrValue<Value> Object::Get(uint32_t index) const {
|
|
|
1456
1459
|
}
|
|
1457
1460
|
|
|
1458
1461
|
template <typename ValueType>
|
|
1459
|
-
inline MaybeOrValue<bool> Object::Set(uint32_t index,
|
|
1462
|
+
inline MaybeOrValue<bool> Object::Set(uint32_t index,
|
|
1463
|
+
const ValueType& value) const {
|
|
1460
1464
|
napi_status status =
|
|
1461
1465
|
napi_set_element(_env, _value, index, Value::From(_env, value));
|
|
1462
1466
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
1463
1467
|
}
|
|
1464
1468
|
|
|
1465
|
-
inline MaybeOrValue<bool> Object::Delete(uint32_t index) {
|
|
1469
|
+
inline MaybeOrValue<bool> Object::Delete(uint32_t index) const {
|
|
1466
1470
|
bool result;
|
|
1467
1471
|
napi_status status = napi_delete_element(_env, _value, index, &result);
|
|
1468
1472
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, result, bool);
|
|
@@ -1475,21 +1479,21 @@ inline MaybeOrValue<Array> Object::GetPropertyNames() const {
|
|
|
1475
1479
|
}
|
|
1476
1480
|
|
|
1477
1481
|
inline MaybeOrValue<bool> Object::DefineProperty(
|
|
1478
|
-
const PropertyDescriptor& property) {
|
|
1482
|
+
const PropertyDescriptor& property) const {
|
|
1479
1483
|
napi_status status = napi_define_properties(_env, _value, 1,
|
|
1480
1484
|
reinterpret_cast<const napi_property_descriptor*>(&property));
|
|
1481
1485
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
1482
1486
|
}
|
|
1483
1487
|
|
|
1484
1488
|
inline MaybeOrValue<bool> Object::DefineProperties(
|
|
1485
|
-
const std::initializer_list<PropertyDescriptor>& properties) {
|
|
1489
|
+
const std::initializer_list<PropertyDescriptor>& properties) const {
|
|
1486
1490
|
napi_status status = napi_define_properties(_env, _value, properties.size(),
|
|
1487
1491
|
reinterpret_cast<const napi_property_descriptor*>(properties.begin()));
|
|
1488
1492
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
1489
1493
|
}
|
|
1490
1494
|
|
|
1491
1495
|
inline MaybeOrValue<bool> Object::DefineProperties(
|
|
1492
|
-
const std::vector<PropertyDescriptor>& properties) {
|
|
1496
|
+
const std::vector<PropertyDescriptor>& properties) const {
|
|
1493
1497
|
napi_status status = napi_define_properties(_env, _value, properties.size(),
|
|
1494
1498
|
reinterpret_cast<const napi_property_descriptor*>(properties.data()));
|
|
1495
1499
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
@@ -1503,7 +1507,7 @@ inline MaybeOrValue<bool> Object::InstanceOf(
|
|
|
1503
1507
|
}
|
|
1504
1508
|
|
|
1505
1509
|
template <typename Finalizer, typename T>
|
|
1506
|
-
inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data) {
|
|
1510
|
+
inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data) const {
|
|
1507
1511
|
details::FinalizeData<T, Finalizer>* finalizeData =
|
|
1508
1512
|
new details::FinalizeData<T, Finalizer>(
|
|
1509
1513
|
{std::move(finalizeCallback), nullptr});
|
|
@@ -1522,7 +1526,7 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data) {
|
|
|
1522
1526
|
template <typename Finalizer, typename T, typename Hint>
|
|
1523
1527
|
inline void Object::AddFinalizer(Finalizer finalizeCallback,
|
|
1524
1528
|
T* data,
|
|
1525
|
-
Hint* finalizeHint) {
|
|
1529
|
+
Hint* finalizeHint) const {
|
|
1526
1530
|
details::FinalizeData<T, Finalizer, Hint>* finalizeData =
|
|
1527
1531
|
new details::FinalizeData<T, Finalizer, Hint>(
|
|
1528
1532
|
{std::move(finalizeCallback), finalizeHint});
|
|
@@ -1616,12 +1620,12 @@ Object::iterator::operator*() {
|
|
|
1616
1620
|
#endif // NAPI_CPP_EXCEPTIONS
|
|
1617
1621
|
|
|
1618
1622
|
#if NAPI_VERSION >= 8
|
|
1619
|
-
inline MaybeOrValue<bool> Object::Freeze() {
|
|
1623
|
+
inline MaybeOrValue<bool> Object::Freeze() const {
|
|
1620
1624
|
napi_status status = napi_object_freeze(_env, _value);
|
|
1621
1625
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
1622
1626
|
}
|
|
1623
1627
|
|
|
1624
|
-
inline MaybeOrValue<bool> Object::Seal() {
|
|
1628
|
+
inline MaybeOrValue<bool> Object::Seal() const {
|
|
1625
1629
|
napi_status status = napi_object_seal(_env, _value);
|
|
1626
1630
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
1627
1631
|
}
|
|
@@ -2287,6 +2291,11 @@ inline MaybeOrValue<Value> Function::Call(
|
|
|
2287
2291
|
return Call(Env().Undefined(), args);
|
|
2288
2292
|
}
|
|
2289
2293
|
|
|
2294
|
+
inline MaybeOrValue<Value> Function::Call(
|
|
2295
|
+
const std::vector<Value>& args) const {
|
|
2296
|
+
return Call(Env().Undefined(), args);
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2290
2299
|
inline MaybeOrValue<Value> Function::Call(size_t argc,
|
|
2291
2300
|
const napi_value* args) const {
|
|
2292
2301
|
return Call(Env().Undefined(), argc, args);
|
|
@@ -2302,6 +2311,27 @@ inline MaybeOrValue<Value> Function::Call(
|
|
|
2302
2311
|
return Call(recv, args.size(), args.data());
|
|
2303
2312
|
}
|
|
2304
2313
|
|
|
2314
|
+
inline MaybeOrValue<Value> Function::Call(
|
|
2315
|
+
napi_value recv, const std::vector<Value>& args) const {
|
|
2316
|
+
const size_t argc = args.size();
|
|
2317
|
+
const size_t stackArgsCount = 6;
|
|
2318
|
+
napi_value stackArgs[stackArgsCount];
|
|
2319
|
+
std::vector<napi_value> heapArgs;
|
|
2320
|
+
napi_value* argv;
|
|
2321
|
+
if (argc <= stackArgsCount) {
|
|
2322
|
+
argv = stackArgs;
|
|
2323
|
+
} else {
|
|
2324
|
+
heapArgs.resize(argc);
|
|
2325
|
+
argv = heapArgs.data();
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
for (size_t index = 0; index < argc; index++) {
|
|
2329
|
+
argv[index] = static_cast<napi_value>(args[index]);
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
return Call(recv, argc, argv);
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2305
2335
|
inline MaybeOrValue<Value> Function::Call(napi_value recv,
|
|
2306
2336
|
size_t argc,
|
|
2307
2337
|
const napi_value* args) const {
|
|
@@ -2607,8 +2637,8 @@ inline Error::Error(napi_env env, napi_value value) : ObjectReference(env, nullp
|
|
|
2607
2637
|
|
|
2608
2638
|
// property flag that we attach to show the error object is wrapped
|
|
2609
2639
|
napi_property_descriptor wrapObjFlag = {
|
|
2610
|
-
ERROR_WRAP_VALUE, // Unique GUID identifier since Symbol isn't a
|
|
2611
|
-
|
|
2640
|
+
ERROR_WRAP_VALUE(), // Unique GUID identifier since Symbol isn't a
|
|
2641
|
+
// viable option
|
|
2612
2642
|
nullptr,
|
|
2613
2643
|
nullptr,
|
|
2614
2644
|
nullptr,
|
|
@@ -2648,15 +2678,17 @@ inline Object Error::Value() const {
|
|
|
2648
2678
|
// We are checking if the object is wrapped
|
|
2649
2679
|
bool isWrappedObject = false;
|
|
2650
2680
|
|
|
2651
|
-
status = napi_has_property(
|
|
2652
|
-
|
|
2681
|
+
status = napi_has_property(_env,
|
|
2682
|
+
refValue,
|
|
2683
|
+
String::From(_env, ERROR_WRAP_VALUE()),
|
|
2684
|
+
&isWrappedObject);
|
|
2653
2685
|
|
|
2654
2686
|
// Don't care about status
|
|
2655
2687
|
if (isWrappedObject) {
|
|
2656
2688
|
napi_value unwrappedValue;
|
|
2657
2689
|
status = napi_get_property(_env,
|
|
2658
2690
|
refValue,
|
|
2659
|
-
String::From(_env, ERROR_WRAP_VALUE),
|
|
2691
|
+
String::From(_env, ERROR_WRAP_VALUE()),
|
|
2660
2692
|
&unwrappedValue);
|
|
2661
2693
|
NAPI_THROW_IF_FAILED(_env, status, Object());
|
|
2662
2694
|
|
|
@@ -2772,6 +2804,10 @@ inline const char* Error::what() const NAPI_NOEXCEPT {
|
|
|
2772
2804
|
|
|
2773
2805
|
#endif // NAPI_CPP_EXCEPTIONS
|
|
2774
2806
|
|
|
2807
|
+
inline const char* Error::ERROR_WRAP_VALUE() NAPI_NOEXCEPT {
|
|
2808
|
+
return "4bda9e7e-4913-4dbc-95de-891cbf66598e-errorVal";
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2775
2811
|
template <typename TError>
|
|
2776
2812
|
inline TError Error::New(napi_env env,
|
|
2777
2813
|
const char* message,
|
|
@@ -2930,7 +2966,7 @@ inline T Reference<T>::Value() const {
|
|
|
2930
2966
|
}
|
|
2931
2967
|
|
|
2932
2968
|
template <typename T>
|
|
2933
|
-
inline uint32_t Reference<T>::Ref() {
|
|
2969
|
+
inline uint32_t Reference<T>::Ref() const {
|
|
2934
2970
|
uint32_t result;
|
|
2935
2971
|
napi_status status = napi_reference_ref(_env, _ref, &result);
|
|
2936
2972
|
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
@@ -2938,7 +2974,7 @@ inline uint32_t Reference<T>::Ref() {
|
|
|
2938
2974
|
}
|
|
2939
2975
|
|
|
2940
2976
|
template <typename T>
|
|
2941
|
-
inline uint32_t Reference<T>::Unref() {
|
|
2977
|
+
inline uint32_t Reference<T>::Unref() const {
|
|
2942
2978
|
uint32_t result;
|
|
2943
2979
|
napi_status status = napi_reference_unref(_env, _ref, &result);
|
|
2944
2980
|
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
@@ -3064,61 +3100,61 @@ inline MaybeOrValue<Napi::Value> ObjectReference::Get(
|
|
|
3064
3100
|
}
|
|
3065
3101
|
|
|
3066
3102
|
inline MaybeOrValue<bool> ObjectReference::Set(const char* utf8name,
|
|
3067
|
-
napi_value value) {
|
|
3103
|
+
napi_value value) const {
|
|
3068
3104
|
HandleScope scope(_env);
|
|
3069
3105
|
return Value().Set(utf8name, value);
|
|
3070
3106
|
}
|
|
3071
3107
|
|
|
3072
3108
|
inline MaybeOrValue<bool> ObjectReference::Set(const char* utf8name,
|
|
3073
|
-
Napi::Value value) {
|
|
3109
|
+
Napi::Value value) const {
|
|
3074
3110
|
HandleScope scope(_env);
|
|
3075
3111
|
return Value().Set(utf8name, value);
|
|
3076
3112
|
}
|
|
3077
3113
|
|
|
3078
3114
|
inline MaybeOrValue<bool> ObjectReference::Set(const char* utf8name,
|
|
3079
|
-
const char* utf8value) {
|
|
3115
|
+
const char* utf8value) const {
|
|
3080
3116
|
HandleScope scope(_env);
|
|
3081
3117
|
return Value().Set(utf8name, utf8value);
|
|
3082
3118
|
}
|
|
3083
3119
|
|
|
3084
3120
|
inline MaybeOrValue<bool> ObjectReference::Set(const char* utf8name,
|
|
3085
|
-
bool boolValue) {
|
|
3121
|
+
bool boolValue) const {
|
|
3086
3122
|
HandleScope scope(_env);
|
|
3087
3123
|
return Value().Set(utf8name, boolValue);
|
|
3088
3124
|
}
|
|
3089
3125
|
|
|
3090
3126
|
inline MaybeOrValue<bool> ObjectReference::Set(const char* utf8name,
|
|
3091
|
-
double numberValue) {
|
|
3127
|
+
double numberValue) const {
|
|
3092
3128
|
HandleScope scope(_env);
|
|
3093
3129
|
return Value().Set(utf8name, numberValue);
|
|
3094
3130
|
}
|
|
3095
3131
|
|
|
3096
3132
|
inline MaybeOrValue<bool> ObjectReference::Set(const std::string& utf8name,
|
|
3097
|
-
napi_value value) {
|
|
3133
|
+
napi_value value) const {
|
|
3098
3134
|
HandleScope scope(_env);
|
|
3099
3135
|
return Value().Set(utf8name, value);
|
|
3100
3136
|
}
|
|
3101
3137
|
|
|
3102
3138
|
inline MaybeOrValue<bool> ObjectReference::Set(const std::string& utf8name,
|
|
3103
|
-
Napi::Value value) {
|
|
3139
|
+
Napi::Value value) const {
|
|
3104
3140
|
HandleScope scope(_env);
|
|
3105
3141
|
return Value().Set(utf8name, value);
|
|
3106
3142
|
}
|
|
3107
3143
|
|
|
3108
3144
|
inline MaybeOrValue<bool> ObjectReference::Set(const std::string& utf8name,
|
|
3109
|
-
std::string& utf8value) {
|
|
3145
|
+
std::string& utf8value) const {
|
|
3110
3146
|
HandleScope scope(_env);
|
|
3111
3147
|
return Value().Set(utf8name, utf8value);
|
|
3112
3148
|
}
|
|
3113
3149
|
|
|
3114
3150
|
inline MaybeOrValue<bool> ObjectReference::Set(const std::string& utf8name,
|
|
3115
|
-
bool boolValue) {
|
|
3151
|
+
bool boolValue) const {
|
|
3116
3152
|
HandleScope scope(_env);
|
|
3117
3153
|
return Value().Set(utf8name, boolValue);
|
|
3118
3154
|
}
|
|
3119
3155
|
|
|
3120
3156
|
inline MaybeOrValue<bool> ObjectReference::Set(const std::string& utf8name,
|
|
3121
|
-
double numberValue) {
|
|
3157
|
+
double numberValue) const {
|
|
3122
3158
|
HandleScope scope(_env);
|
|
3123
3159
|
return Value().Set(utf8name, numberValue);
|
|
3124
3160
|
}
|
|
@@ -3140,36 +3176,37 @@ inline MaybeOrValue<Napi::Value> ObjectReference::Get(uint32_t index) const {
|
|
|
3140
3176
|
}
|
|
3141
3177
|
|
|
3142
3178
|
inline MaybeOrValue<bool> ObjectReference::Set(uint32_t index,
|
|
3143
|
-
napi_value value) {
|
|
3179
|
+
napi_value value) const {
|
|
3144
3180
|
HandleScope scope(_env);
|
|
3145
3181
|
return Value().Set(index, value);
|
|
3146
3182
|
}
|
|
3147
3183
|
|
|
3148
3184
|
inline MaybeOrValue<bool> ObjectReference::Set(uint32_t index,
|
|
3149
|
-
Napi::Value value) {
|
|
3185
|
+
Napi::Value value) const {
|
|
3150
3186
|
HandleScope scope(_env);
|
|
3151
3187
|
return Value().Set(index, value);
|
|
3152
3188
|
}
|
|
3153
3189
|
|
|
3154
3190
|
inline MaybeOrValue<bool> ObjectReference::Set(uint32_t index,
|
|
3155
|
-
const char* utf8value) {
|
|
3191
|
+
const char* utf8value) const {
|
|
3156
3192
|
HandleScope scope(_env);
|
|
3157
3193
|
return Value().Set(index, utf8value);
|
|
3158
3194
|
}
|
|
3159
3195
|
|
|
3160
|
-
inline MaybeOrValue<bool> ObjectReference::Set(
|
|
3161
|
-
|
|
3196
|
+
inline MaybeOrValue<bool> ObjectReference::Set(
|
|
3197
|
+
uint32_t index, const std::string& utf8value) const {
|
|
3162
3198
|
HandleScope scope(_env);
|
|
3163
3199
|
return Value().Set(index, utf8value);
|
|
3164
3200
|
}
|
|
3165
3201
|
|
|
3166
|
-
inline MaybeOrValue<bool> ObjectReference::Set(uint32_t index,
|
|
3202
|
+
inline MaybeOrValue<bool> ObjectReference::Set(uint32_t index,
|
|
3203
|
+
bool boolValue) const {
|
|
3167
3204
|
HandleScope scope(_env);
|
|
3168
3205
|
return Value().Set(index, boolValue);
|
|
3169
3206
|
}
|
|
3170
3207
|
|
|
3171
3208
|
inline MaybeOrValue<bool> ObjectReference::Set(uint32_t index,
|
|
3172
|
-
double numberValue) {
|
|
3209
|
+
double numberValue) const {
|
|
3173
3210
|
HandleScope scope(_env);
|
|
3174
3211
|
return Value().Set(index, numberValue);
|
|
3175
3212
|
}
|
|
@@ -4451,6 +4488,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(Symbol name,
|
|
|
4451
4488
|
return desc;
|
|
4452
4489
|
}
|
|
4453
4490
|
|
|
4491
|
+
template <typename T>
|
|
4492
|
+
inline Value ObjectWrap<T>::OnCalledAsFunction(
|
|
4493
|
+
const Napi::CallbackInfo& callbackInfo) {
|
|
4494
|
+
NAPI_THROW(
|
|
4495
|
+
TypeError::New(callbackInfo.Env(),
|
|
4496
|
+
"Class constructors cannot be invoked without 'new'"),
|
|
4497
|
+
Napi::Value());
|
|
4498
|
+
}
|
|
4499
|
+
|
|
4454
4500
|
template <typename T>
|
|
4455
4501
|
inline void ObjectWrap<T>::Finalize(Napi::Env /*env*/) {}
|
|
4456
4502
|
|
|
@@ -4464,8 +4510,8 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
|
|
|
4464
4510
|
|
|
4465
4511
|
bool isConstructCall = (new_target != nullptr);
|
|
4466
4512
|
if (!isConstructCall) {
|
|
4467
|
-
|
|
4468
|
-
|
|
4513
|
+
return details::WrapCallback(
|
|
4514
|
+
[&] { return T::OnCalledAsFunction(CallbackInfo(env, info)); });
|
|
4469
4515
|
}
|
|
4470
4516
|
|
|
4471
4517
|
napi_value wrapper = details::WrapCallback([&] {
|
|
@@ -5323,7 +5369,7 @@ template <typename ContextType,
|
|
|
5323
5369
|
typename DataType,
|
|
5324
5370
|
void (*CallJs)(Napi::Env, Napi::Function, ContextType*, DataType*)>
|
|
5325
5371
|
inline napi_status
|
|
5326
|
-
TypedThreadSafeFunction<ContextType, DataType, CallJs>::Release() {
|
|
5372
|
+
TypedThreadSafeFunction<ContextType, DataType, CallJs>::Release() const {
|
|
5327
5373
|
return napi_release_threadsafe_function(_tsfn, napi_tsfn_release);
|
|
5328
5374
|
}
|
|
5329
5375
|
|
|
@@ -5331,7 +5377,7 @@ template <typename ContextType,
|
|
|
5331
5377
|
typename DataType,
|
|
5332
5378
|
void (*CallJs)(Napi::Env, Napi::Function, ContextType*, DataType*)>
|
|
5333
5379
|
inline napi_status
|
|
5334
|
-
TypedThreadSafeFunction<ContextType, DataType, CallJs>::Abort() {
|
|
5380
|
+
TypedThreadSafeFunction<ContextType, DataType, CallJs>::Abort() const {
|
|
5335
5381
|
return napi_release_threadsafe_function(_tsfn, napi_tsfn_abort);
|
|
5336
5382
|
}
|
|
5337
5383
|
|
|
@@ -5661,11 +5707,11 @@ inline napi_status ThreadSafeFunction::Acquire() const {
|
|
|
5661
5707
|
return napi_acquire_threadsafe_function(_tsfn);
|
|
5662
5708
|
}
|
|
5663
5709
|
|
|
5664
|
-
inline napi_status ThreadSafeFunction::Release() {
|
|
5710
|
+
inline napi_status ThreadSafeFunction::Release() const {
|
|
5665
5711
|
return napi_release_threadsafe_function(_tsfn, napi_tsfn_release);
|
|
5666
5712
|
}
|
|
5667
5713
|
|
|
5668
|
-
inline napi_status ThreadSafeFunction::Abort() {
|
|
5714
|
+
inline napi_status ThreadSafeFunction::Abort() const {
|
|
5669
5715
|
return napi_release_threadsafe_function(_tsfn, napi_tsfn_abort);
|
|
5670
5716
|
}
|
|
5671
5717
|
|
|
@@ -6204,6 +6250,10 @@ bool Env::CleanupHook<Hook, Arg>::IsEmpty() const {
|
|
|
6204
6250
|
}
|
|
6205
6251
|
#endif // NAPI_VERSION > 2
|
|
6206
6252
|
|
|
6253
|
+
#ifdef NAPI_CPP_CUSTOM_NAMESPACE
|
|
6254
|
+
} // namespace NAPI_CPP_CUSTOM_NAMESPACE
|
|
6255
|
+
#endif
|
|
6256
|
+
|
|
6207
6257
|
} // namespace Napi
|
|
6208
6258
|
|
|
6209
6259
|
#endif // SRC_NAPI_INL_H_
|
package/napi.h
CHANGED
|
@@ -140,6 +140,18 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), "Size mismatch between char16
|
|
|
140
140
|
////////////////////////////////////////////////////////////////////////////////
|
|
141
141
|
namespace Napi {
|
|
142
142
|
|
|
143
|
+
#ifdef NAPI_CPP_CUSTOM_NAMESPACE
|
|
144
|
+
// NAPI_CPP_CUSTOM_NAMESPACE can be #define'd per-addon to avoid symbol
|
|
145
|
+
// conflicts between different instances of node-addon-api
|
|
146
|
+
|
|
147
|
+
// First dummy definition of the namespace to make sure that Napi::(name) still
|
|
148
|
+
// refers to the right things inside this file.
|
|
149
|
+
namespace NAPI_CPP_CUSTOM_NAMESPACE {}
|
|
150
|
+
using namespace NAPI_CPP_CUSTOM_NAMESPACE;
|
|
151
|
+
|
|
152
|
+
namespace NAPI_CPP_CUSTOM_NAMESPACE {
|
|
153
|
+
#endif
|
|
154
|
+
|
|
143
155
|
// Forward declarations
|
|
144
156
|
class Env;
|
|
145
157
|
class Value;
|
|
@@ -286,11 +298,11 @@ namespace Napi {
|
|
|
286
298
|
Value Null() const;
|
|
287
299
|
|
|
288
300
|
bool IsExceptionPending() const;
|
|
289
|
-
Error GetAndClearPendingException();
|
|
301
|
+
Error GetAndClearPendingException() const;
|
|
290
302
|
|
|
291
|
-
MaybeOrValue<Value> RunScript(const char* utf8script);
|
|
292
|
-
MaybeOrValue<Value> RunScript(const std::string& utf8script);
|
|
293
|
-
MaybeOrValue<Value> RunScript(String script);
|
|
303
|
+
MaybeOrValue<Value> RunScript(const char* utf8script) const;
|
|
304
|
+
MaybeOrValue<Value> RunScript(const std::string& utf8script) const;
|
|
305
|
+
MaybeOrValue<Value> RunScript(String script) const;
|
|
294
306
|
|
|
295
307
|
#if NAPI_VERSION > 2
|
|
296
308
|
template <typename Hook>
|
|
@@ -301,19 +313,20 @@ namespace Napi {
|
|
|
301
313
|
#endif // NAPI_VERSION > 2
|
|
302
314
|
|
|
303
315
|
#if NAPI_VERSION > 5
|
|
304
|
-
template <typename T>
|
|
316
|
+
template <typename T>
|
|
317
|
+
T* GetInstanceData() const;
|
|
305
318
|
|
|
306
319
|
template <typename T> using Finalizer = void (*)(Env, T*);
|
|
307
320
|
template <typename T, Finalizer<T> fini = Env::DefaultFini<T>>
|
|
308
|
-
void SetInstanceData(T* data);
|
|
321
|
+
void SetInstanceData(T* data) const;
|
|
309
322
|
|
|
310
323
|
template <typename DataType, typename HintType>
|
|
311
324
|
using FinalizerWithHint = void (*)(Env, DataType*, HintType*);
|
|
312
325
|
template <typename DataType,
|
|
313
326
|
typename HintType,
|
|
314
327
|
FinalizerWithHint<DataType, HintType> fini =
|
|
315
|
-
|
|
316
|
-
void SetInstanceData(DataType* data, HintType* hint);
|
|
328
|
+
Env::DefaultFiniWithHint<DataType, HintType>>
|
|
329
|
+
void SetInstanceData(DataType* data, HintType* hint) const;
|
|
317
330
|
#endif // NAPI_VERSION > 5
|
|
318
331
|
|
|
319
332
|
private:
|
|
@@ -727,22 +740,18 @@ namespace Napi {
|
|
|
727
740
|
napi_value value); ///< Wraps a Node-API value primitive.
|
|
728
741
|
|
|
729
742
|
/// Gets or sets a named property.
|
|
730
|
-
PropertyLValue<std::string> operator
|
|
731
|
-
|
|
743
|
+
PropertyLValue<std::string> operator[](
|
|
744
|
+
const char* utf8name ///< UTF-8 encoded null-terminated property name
|
|
732
745
|
);
|
|
733
746
|
|
|
734
747
|
/// Gets or sets a named property.
|
|
735
|
-
PropertyLValue<std::string> operator
|
|
736
|
-
|
|
748
|
+
PropertyLValue<std::string> operator[](
|
|
749
|
+
const std::string& utf8name ///< UTF-8 encoded property name
|
|
737
750
|
);
|
|
738
751
|
|
|
739
752
|
/// Gets or sets an indexed property or array element.
|
|
740
|
-
PropertyLValue<uint32_t> operator
|
|
741
|
-
|
|
742
|
-
);
|
|
743
|
-
|
|
744
|
-
/// Gets or sets an indexed property or array element.
|
|
745
|
-
PropertyLValue<Value> operator[](Value index /// Property / element index
|
|
753
|
+
PropertyLValue<uint32_t> operator[](
|
|
754
|
+
uint32_t index /// Property / element index
|
|
746
755
|
);
|
|
747
756
|
|
|
748
757
|
/// Gets or sets an indexed property or array element.
|
|
@@ -822,44 +831,44 @@ namespace Napi {
|
|
|
822
831
|
template <typename ValueType>
|
|
823
832
|
MaybeOrValue<bool> Set(napi_value key, ///< Property key primitive
|
|
824
833
|
const ValueType& value ///< Property value primitive
|
|
825
|
-
);
|
|
834
|
+
) const;
|
|
826
835
|
|
|
827
836
|
/// Sets a property.
|
|
828
837
|
template <typename ValueType>
|
|
829
838
|
MaybeOrValue<bool> Set(Value key, ///< Property key
|
|
830
839
|
const ValueType& value ///< Property value
|
|
831
|
-
);
|
|
840
|
+
) const;
|
|
832
841
|
|
|
833
842
|
/// Sets a named property.
|
|
834
843
|
template <typename ValueType>
|
|
835
844
|
MaybeOrValue<bool> Set(
|
|
836
845
|
const char* utf8name, ///< UTF-8 encoded null-terminated property name
|
|
837
|
-
const ValueType& value);
|
|
846
|
+
const ValueType& value) const;
|
|
838
847
|
|
|
839
848
|
/// Sets a named property.
|
|
840
849
|
template <typename ValueType>
|
|
841
850
|
MaybeOrValue<bool> Set(
|
|
842
851
|
const std::string& utf8name, ///< UTF-8 encoded property name
|
|
843
852
|
const ValueType& value ///< Property value primitive
|
|
844
|
-
);
|
|
853
|
+
) const;
|
|
845
854
|
|
|
846
855
|
/// Delete property.
|
|
847
856
|
MaybeOrValue<bool> Delete(napi_value key ///< Property key primitive
|
|
848
|
-
);
|
|
857
|
+
) const;
|
|
849
858
|
|
|
850
859
|
/// Delete property.
|
|
851
860
|
MaybeOrValue<bool> Delete(Value key ///< Property key
|
|
852
|
-
);
|
|
861
|
+
) const;
|
|
853
862
|
|
|
854
863
|
/// Delete property.
|
|
855
864
|
MaybeOrValue<bool> Delete(
|
|
856
865
|
const char* utf8name ///< UTF-8 encoded null-terminated property name
|
|
857
|
-
);
|
|
866
|
+
) const;
|
|
858
867
|
|
|
859
868
|
/// Delete property.
|
|
860
869
|
MaybeOrValue<bool> Delete(
|
|
861
870
|
const std::string& utf8name ///< UTF-8 encoded property name
|
|
862
|
-
);
|
|
871
|
+
) const;
|
|
863
872
|
|
|
864
873
|
/// Checks whether an indexed property is present.
|
|
865
874
|
MaybeOrValue<bool> Has(uint32_t index ///< Property / element index
|
|
@@ -873,11 +882,11 @@ namespace Napi {
|
|
|
873
882
|
template <typename ValueType>
|
|
874
883
|
MaybeOrValue<bool> Set(uint32_t index, ///< Property / element index
|
|
875
884
|
const ValueType& value ///< Property value primitive
|
|
876
|
-
);
|
|
885
|
+
) const;
|
|
877
886
|
|
|
878
887
|
/// Deletes an indexed property or array element.
|
|
879
888
|
MaybeOrValue<bool> Delete(uint32_t index ///< Property / element index
|
|
880
|
-
);
|
|
889
|
+
) const;
|
|
881
890
|
|
|
882
891
|
/// This operation can fail in case of Proxy.[[OwnPropertyKeys]] and
|
|
883
892
|
/// Proxy.[[GetOwnProperty]] calling into JavaScript. See:
|
|
@@ -895,7 +904,7 @@ namespace Napi {
|
|
|
895
904
|
MaybeOrValue<bool> DefineProperty(
|
|
896
905
|
const PropertyDescriptor&
|
|
897
906
|
property ///< Descriptor for the property to be defined
|
|
898
|
-
);
|
|
907
|
+
) const;
|
|
899
908
|
|
|
900
909
|
/// Defines properties on the object.
|
|
901
910
|
///
|
|
@@ -905,7 +914,7 @@ namespace Napi {
|
|
|
905
914
|
MaybeOrValue<bool> DefineProperties(
|
|
906
915
|
const std::initializer_list<PropertyDescriptor>& properties
|
|
907
916
|
///< List of descriptors for the properties to be defined
|
|
908
|
-
);
|
|
917
|
+
) const;
|
|
909
918
|
|
|
910
919
|
/// Defines properties on the object.
|
|
911
920
|
///
|
|
@@ -915,7 +924,7 @@ namespace Napi {
|
|
|
915
924
|
MaybeOrValue<bool> DefineProperties(
|
|
916
925
|
const std::vector<PropertyDescriptor>& properties
|
|
917
926
|
///< Vector of descriptors for the properties to be defined
|
|
918
|
-
);
|
|
927
|
+
) const;
|
|
919
928
|
|
|
920
929
|
/// Checks if an object is an instance created by a constructor function.
|
|
921
930
|
///
|
|
@@ -930,12 +939,12 @@ namespace Napi {
|
|
|
930
939
|
) const;
|
|
931
940
|
|
|
932
941
|
template <typename Finalizer, typename T>
|
|
933
|
-
inline void AddFinalizer(Finalizer finalizeCallback, T* data);
|
|
942
|
+
inline void AddFinalizer(Finalizer finalizeCallback, T* data) const;
|
|
934
943
|
|
|
935
944
|
template <typename Finalizer, typename T, typename Hint>
|
|
936
945
|
inline void AddFinalizer(Finalizer finalizeCallback,
|
|
937
946
|
T* data,
|
|
938
|
-
Hint* finalizeHint);
|
|
947
|
+
Hint* finalizeHint) const;
|
|
939
948
|
|
|
940
949
|
#ifdef NAPI_CPP_EXCEPTIONS
|
|
941
950
|
class const_iterator;
|
|
@@ -956,12 +965,12 @@ namespace Napi {
|
|
|
956
965
|
/// JavaScript.
|
|
957
966
|
/// See
|
|
958
967
|
/// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof
|
|
959
|
-
MaybeOrValue<bool> Freeze();
|
|
968
|
+
MaybeOrValue<bool> Freeze() const;
|
|
960
969
|
/// This operation can fail in case of Proxy.[[GetPrototypeOf]] calling into
|
|
961
970
|
/// JavaScript.
|
|
962
971
|
/// See
|
|
963
972
|
/// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof
|
|
964
|
-
MaybeOrValue<bool> Seal();
|
|
973
|
+
MaybeOrValue<bool> Seal() const;
|
|
965
974
|
#endif // NAPI_VERSION >= 8
|
|
966
975
|
};
|
|
967
976
|
|
|
@@ -1350,11 +1359,14 @@ namespace Napi {
|
|
|
1350
1359
|
MaybeOrValue<Value> Call(
|
|
1351
1360
|
const std::initializer_list<napi_value>& args) const;
|
|
1352
1361
|
MaybeOrValue<Value> Call(const std::vector<napi_value>& args) const;
|
|
1362
|
+
MaybeOrValue<Value> Call(const std::vector<Value>& args) const;
|
|
1353
1363
|
MaybeOrValue<Value> Call(size_t argc, const napi_value* args) const;
|
|
1354
1364
|
MaybeOrValue<Value> Call(
|
|
1355
1365
|
napi_value recv, const std::initializer_list<napi_value>& args) const;
|
|
1356
1366
|
MaybeOrValue<Value> Call(napi_value recv,
|
|
1357
1367
|
const std::vector<napi_value>& args) const;
|
|
1368
|
+
MaybeOrValue<Value> Call(napi_value recv,
|
|
1369
|
+
const std::vector<Value>& args) const;
|
|
1358
1370
|
MaybeOrValue<Value> Call(napi_value recv,
|
|
1359
1371
|
size_t argc,
|
|
1360
1372
|
const napi_value* args) const;
|
|
@@ -1462,8 +1474,8 @@ namespace Napi {
|
|
|
1462
1474
|
// within a HandleScope so that the value handle gets cleaned up efficiently.
|
|
1463
1475
|
T Value() const;
|
|
1464
1476
|
|
|
1465
|
-
uint32_t Ref();
|
|
1466
|
-
uint32_t Unref();
|
|
1477
|
+
uint32_t Ref() const;
|
|
1478
|
+
uint32_t Unref() const;
|
|
1467
1479
|
void Reset();
|
|
1468
1480
|
void Reset(const T& value, uint32_t refcount = 0);
|
|
1469
1481
|
|
|
@@ -1500,24 +1512,27 @@ namespace Napi {
|
|
|
1500
1512
|
|
|
1501
1513
|
MaybeOrValue<Napi::Value> Get(const char* utf8name) const;
|
|
1502
1514
|
MaybeOrValue<Napi::Value> Get(const std::string& utf8name) const;
|
|
1503
|
-
MaybeOrValue<bool> Set(const char* utf8name, napi_value value);
|
|
1504
|
-
MaybeOrValue<bool> Set(const char* utf8name, Napi::Value value);
|
|
1505
|
-
MaybeOrValue<bool> Set(const char* utf8name, const char* utf8value);
|
|
1506
|
-
MaybeOrValue<bool> Set(const char* utf8name, bool boolValue);
|
|
1507
|
-
MaybeOrValue<bool> Set(const char* utf8name, double numberValue);
|
|
1508
|
-
MaybeOrValue<bool> Set(const std::string& utf8name, napi_value value);
|
|
1509
|
-
MaybeOrValue<bool> Set(const std::string& utf8name,
|
|
1510
|
-
|
|
1511
|
-
MaybeOrValue<bool> Set(const std::string& utf8name,
|
|
1512
|
-
|
|
1515
|
+
MaybeOrValue<bool> Set(const char* utf8name, napi_value value) const;
|
|
1516
|
+
MaybeOrValue<bool> Set(const char* utf8name, Napi::Value value) const;
|
|
1517
|
+
MaybeOrValue<bool> Set(const char* utf8name, const char* utf8value) const;
|
|
1518
|
+
MaybeOrValue<bool> Set(const char* utf8name, bool boolValue) const;
|
|
1519
|
+
MaybeOrValue<bool> Set(const char* utf8name, double numberValue) const;
|
|
1520
|
+
MaybeOrValue<bool> Set(const std::string& utf8name, napi_value value) const;
|
|
1521
|
+
MaybeOrValue<bool> Set(const std::string& utf8name,
|
|
1522
|
+
Napi::Value value) const;
|
|
1523
|
+
MaybeOrValue<bool> Set(const std::string& utf8name,
|
|
1524
|
+
std::string& utf8value) const;
|
|
1525
|
+
MaybeOrValue<bool> Set(const std::string& utf8name, bool boolValue) const;
|
|
1526
|
+
MaybeOrValue<bool> Set(const std::string& utf8name,
|
|
1527
|
+
double numberValue) const;
|
|
1513
1528
|
|
|
1514
1529
|
MaybeOrValue<Napi::Value> Get(uint32_t index) const;
|
|
1515
|
-
MaybeOrValue<bool> Set(uint32_t index, const napi_value value);
|
|
1516
|
-
MaybeOrValue<bool> Set(uint32_t index, const Napi::Value value);
|
|
1517
|
-
MaybeOrValue<bool> Set(uint32_t index, const char* utf8value);
|
|
1518
|
-
MaybeOrValue<bool> Set(uint32_t index, const std::string& utf8value);
|
|
1519
|
-
MaybeOrValue<bool> Set(uint32_t index, bool boolValue);
|
|
1520
|
-
MaybeOrValue<bool> Set(uint32_t index, double numberValue);
|
|
1530
|
+
MaybeOrValue<bool> Set(uint32_t index, const napi_value value) const;
|
|
1531
|
+
MaybeOrValue<bool> Set(uint32_t index, const Napi::Value value) const;
|
|
1532
|
+
MaybeOrValue<bool> Set(uint32_t index, const char* utf8value) const;
|
|
1533
|
+
MaybeOrValue<bool> Set(uint32_t index, const std::string& utf8value) const;
|
|
1534
|
+
MaybeOrValue<bool> Set(uint32_t index, bool boolValue) const;
|
|
1535
|
+
MaybeOrValue<bool> Set(uint32_t index, double numberValue) const;
|
|
1521
1536
|
|
|
1522
1537
|
protected:
|
|
1523
1538
|
ObjectReference(const ObjectReference&);
|
|
@@ -1720,8 +1735,7 @@ namespace Napi {
|
|
|
1720
1735
|
/// !endcond
|
|
1721
1736
|
|
|
1722
1737
|
private:
|
|
1723
|
-
const char* ERROR_WRAP_VALUE
|
|
1724
|
-
"4bda9e7e-4913-4dbc-95de-891cbf66598e-errorVal";
|
|
1738
|
+
static inline const char* ERROR_WRAP_VALUE() NAPI_NOEXCEPT;
|
|
1725
1739
|
mutable std::string _message;
|
|
1726
1740
|
};
|
|
1727
1741
|
|
|
@@ -2199,6 +2213,8 @@ namespace Napi {
|
|
|
2199
2213
|
static PropertyDescriptor StaticValue(Symbol name,
|
|
2200
2214
|
Napi::Value value,
|
|
2201
2215
|
napi_property_attributes attributes = napi_default);
|
|
2216
|
+
static Napi::Value OnCalledAsFunction(
|
|
2217
|
+
const Napi::CallbackInfo& callbackInfo);
|
|
2202
2218
|
virtual void Finalize(Napi::Env env);
|
|
2203
2219
|
|
|
2204
2220
|
private:
|
|
@@ -2553,10 +2569,10 @@ namespace Napi {
|
|
|
2553
2569
|
napi_status Acquire() const;
|
|
2554
2570
|
|
|
2555
2571
|
// This API may be called from any thread.
|
|
2556
|
-
napi_status Release();
|
|
2572
|
+
napi_status Release() const;
|
|
2557
2573
|
|
|
2558
2574
|
// This API may be called from any thread.
|
|
2559
|
-
napi_status Abort();
|
|
2575
|
+
napi_status Abort() const;
|
|
2560
2576
|
|
|
2561
2577
|
struct ConvertibleContext
|
|
2562
2578
|
{
|
|
@@ -2752,10 +2768,10 @@ namespace Napi {
|
|
|
2752
2768
|
napi_status Acquire() const;
|
|
2753
2769
|
|
|
2754
2770
|
// This API may be called from any thread.
|
|
2755
|
-
napi_status Release();
|
|
2771
|
+
napi_status Release() const;
|
|
2756
2772
|
|
|
2757
2773
|
// This API may be called from any thread.
|
|
2758
|
-
napi_status Abort();
|
|
2774
|
+
napi_status Abort() const;
|
|
2759
2775
|
|
|
2760
2776
|
// This API may be called from any thread.
|
|
2761
2777
|
ContextType* GetContext() const;
|
|
@@ -2975,6 +2991,10 @@ namespace Napi {
|
|
|
2975
2991
|
};
|
|
2976
2992
|
#endif // NAPI_VERSION > 5
|
|
2977
2993
|
|
|
2994
|
+
#ifdef NAPI_CPP_CUSTOM_NAMESPACE
|
|
2995
|
+
} // namespace NAPI_CPP_CUSTOM_NAMESPACE
|
|
2996
|
+
#endif
|
|
2997
|
+
|
|
2978
2998
|
} // namespace Napi
|
|
2979
2999
|
|
|
2980
3000
|
// Inline implementations of all the above class methods are included here.
|
package/package.json
CHANGED
|
@@ -95,14 +95,18 @@
|
|
|
95
95
|
"name": "Doni Rubiagatra",
|
|
96
96
|
"url": "https://github.com/rubiagatra"
|
|
97
97
|
},
|
|
98
|
-
{
|
|
99
|
-
"name": "Ferdinand Holzer",
|
|
100
|
-
"url": "https://github.com/fholzer"
|
|
101
|
-
},
|
|
102
98
|
{
|
|
103
99
|
"name": "Eric Bickle",
|
|
104
100
|
"url": "https://github.com/ebickle"
|
|
105
101
|
},
|
|
102
|
+
{
|
|
103
|
+
"name": "extremeheat",
|
|
104
|
+
"url": "https://github.com/extremeheat"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "Ferdinand Holzer",
|
|
108
|
+
"url": "https://github.com/fholzer"
|
|
109
|
+
},
|
|
106
110
|
{
|
|
107
111
|
"name": "Gabriel Schulhof",
|
|
108
112
|
"url": "https://github.com/gabrielschulhof"
|
|
@@ -267,6 +271,10 @@
|
|
|
267
271
|
"name": "Philipp Renoth",
|
|
268
272
|
"url": "https://github.com/DaAitch"
|
|
269
273
|
},
|
|
274
|
+
{
|
|
275
|
+
"name": "rgerd",
|
|
276
|
+
"url": "https://github.com/rgerd"
|
|
277
|
+
},
|
|
270
278
|
{
|
|
271
279
|
"name": "Rolf Timmermans",
|
|
272
280
|
"url": "https://github.com/rolftimmermans"
|
|
@@ -319,11 +327,19 @@
|
|
|
319
327
|
"name": "Vlad Velmisov",
|
|
320
328
|
"url": "https://github.com/Velmisov"
|
|
321
329
|
},
|
|
330
|
+
{
|
|
331
|
+
"name": "Vladimir Morozov",
|
|
332
|
+
"url": "https://github.com/vmoroz"
|
|
333
|
+
|
|
334
|
+
},
|
|
322
335
|
{
|
|
323
336
|
"name": "WenheLI",
|
|
324
337
|
"url": "https://github.com/WenheLI"
|
|
325
338
|
},
|
|
326
|
-
|
|
339
|
+
{
|
|
340
|
+
"name": "Xuguang Mei",
|
|
341
|
+
"url": "https://github.com/meixg"
|
|
342
|
+
},
|
|
327
343
|
{
|
|
328
344
|
"name": "Yohei Kishimoto",
|
|
329
345
|
"url": "https://github.com/morokosi"
|
|
@@ -394,6 +410,6 @@
|
|
|
394
410
|
"lint:fix": "node tools/clang-format --fix && node tools/eslint-format --fix"
|
|
395
411
|
},
|
|
396
412
|
"pre-commit": "lint",
|
|
397
|
-
"version": "
|
|
413
|
+
"version": "5.0.0",
|
|
398
414
|
"support": true
|
|
399
415
|
}
|
package/tools/clang-format.js
CHANGED
|
@@ -20,7 +20,10 @@ function main (args) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const clangFormatPath = path.dirname(require.resolve('clang-format'));
|
|
23
|
-
const
|
|
23
|
+
const binary = process.platform === 'win32'
|
|
24
|
+
? 'node_modules\\.bin\\clang-format.cmd'
|
|
25
|
+
: 'node_modules/.bin/clang-format';
|
|
26
|
+
const options = ['--binary=' + binary, '--style=file'];
|
|
24
27
|
if (fix) {
|
|
25
28
|
options.push(FORMAT_START);
|
|
26
29
|
} else {
|