koffi 0.9.30 → 0.9.33
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/package.json +1 -1
- package/src/call.hh +2 -1
- package/src/call_arm32.cc +27 -15
- package/src/call_arm64.cc +4 -9
- package/src/call_x64_sysv.cc +4 -9
- package/src/call_x64_sysv_fwd.S +13 -3
- package/src/call_x64_win.cc +4 -9
- package/src/call_x86.cc +18 -16
- package/src/ffi.cc +93 -46
- package/src/ffi.hh +11 -6
- package/src/util.cc +35 -1
- package/src/util.hh +2 -0
- package/test/tests/misc.c +62 -1
- package/test/tests/misc.js +49 -1
- package/vendor/node-addon-api/CHANGELOG.md +57 -0
- package/vendor/node-addon-api/README.md +3 -3
- package/vendor/node-addon-api/doc/array_buffer.md +2 -2
- package/vendor/node-addon-api/doc/buffer.md +2 -2
- package/vendor/node-addon-api/doc/class_property_descriptor.md +13 -5
- package/vendor/node-addon-api/doc/env.md +5 -5
- package/vendor/node-addon-api/doc/object.md +12 -33
- package/vendor/node-addon-api/doc/object_reference.md +1 -1
- package/vendor/node-addon-api/doc/object_wrap.md +27 -0
- package/vendor/node-addon-api/doc/reference.md +2 -2
- package/vendor/node-addon-api/doc/threadsafe_function.md +3 -3
- package/vendor/node-addon-api/doc/typed_threadsafe_function.md +2 -2
- package/vendor/node-addon-api/napi-inl.h +111 -61
- package/vendor/node-addon-api/napi.h +79 -59
- package/vendor/node-addon-api/package.json +22 -6
- package/vendor/node-addon-api/test/async_context.cc +15 -0
- package/vendor/node-addon-api/test/async_context.js +69 -33
- package/vendor/node-addon-api/test/binding.cc +2 -0
- package/vendor/node-addon-api/test/binding.gyp +7 -0
- package/vendor/node-addon-api/test/common/index.js +23 -22
- package/vendor/node-addon-api/test/common/test_helper.h +10 -0
- package/vendor/node-addon-api/test/error_terminating_environment.js +1 -0
- package/vendor/node-addon-api/test/function.cc +29 -0
- package/vendor/node-addon-api/test/function.js +35 -23
- package/vendor/node-addon-api/test/index.js +40 -17
- package/vendor/node-addon-api/test/object/object.cc +2 -0
- package/vendor/node-addon-api/test/object/set_property.cc +8 -0
- package/vendor/node-addon-api/test/object/set_property.js +6 -5
- package/vendor/node-addon-api/test/object/subscript_operator.cc +19 -3
- package/vendor/node-addon-api/test/objectwrap_function.cc +45 -0
- package/vendor/node-addon-api/test/objectwrap_function.js +22 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +1 -1
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +2 -2
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +1 -1
- package/vendor/node-addon-api/tools/clang-format.js +4 -1
- package/vendor/node-addon-api/unit-test/README.md +28 -0
- package/vendor/node-addon-api/unit-test/binding-file-template.js +39 -0
- package/vendor/node-addon-api/unit-test/binding.gyp +72 -0
- package/vendor/node-addon-api/unit-test/exceptions.js +32 -0
- package/vendor/node-addon-api/unit-test/generate-binding-cc.js +61 -0
- package/vendor/node-addon-api/unit-test/injectTestParams.js +101 -0
- package/vendor/node-addon-api/unit-test/listOfTestModules.js +88 -0
- package/vendor/node-addon-api/unit-test/matchModules.js +65 -0
- package/vendor/node-addon-api/unit-test/setup.js +13 -0
- package/vendor/node-addon-api/unit-test/spawnTask.js +26 -0
- package/vendor/node-addon-api/unit-test/test.js +30 -0
|
@@ -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.
|
|
@@ -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
|
}
|
|
@@ -12,10 +12,25 @@ static void MakeCallback(const CallbackInfo& info) {
|
|
|
12
12
|
Object::New(info.Env()), std::initializer_list<napi_value>{}, context);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
static void MakeCallbackNoResource(const CallbackInfo& info) {
|
|
16
|
+
Function callback = info[0].As<Function>();
|
|
17
|
+
AsyncContext context(info.Env(), "async_context_no_res_test");
|
|
18
|
+
callback.MakeCallback(
|
|
19
|
+
Object::New(info.Env()), std::initializer_list<napi_value>{}, context);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static Boolean AssertAsyncContextReturnCorrectEnv(const CallbackInfo& info) {
|
|
23
|
+
AsyncContext context(info.Env(), "empty_context_test");
|
|
24
|
+
return Boolean::New(info.Env(), context.Env() == info.Env());
|
|
25
|
+
}
|
|
15
26
|
} // end anonymous namespace
|
|
16
27
|
|
|
17
28
|
Object InitAsyncContext(Env env) {
|
|
18
29
|
Object exports = Object::New(env);
|
|
19
30
|
exports["makeCallback"] = Function::New(env, MakeCallback);
|
|
31
|
+
exports["makeCallbackNoResource"] =
|
|
32
|
+
Function::New(env, MakeCallbackNoResource);
|
|
33
|
+
exports["asyncCxtReturnCorrectEnv"] =
|
|
34
|
+
Function::New(env, AssertAsyncContextReturnCorrectEnv);
|
|
20
35
|
return exports;
|
|
21
36
|
}
|
|
@@ -5,12 +5,12 @@ const common = require('./common');
|
|
|
5
5
|
|
|
6
6
|
// we only check async hooks on 8.x an higher were
|
|
7
7
|
// they are closer to working properly
|
|
8
|
-
const nodeVersion = process.versions.node.split('.')[0]
|
|
9
|
-
let
|
|
10
|
-
function checkAsyncHooks() {
|
|
8
|
+
const nodeVersion = process.versions.node.split('.')[0];
|
|
9
|
+
let asyncHooks;
|
|
10
|
+
function checkAsyncHooks () {
|
|
11
11
|
if (nodeVersion >= 8) {
|
|
12
|
-
if (
|
|
13
|
-
|
|
12
|
+
if (asyncHooks === undefined) {
|
|
13
|
+
asyncHooks = require('async_hooks');
|
|
14
14
|
}
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
@@ -19,7 +19,7 @@ function checkAsyncHooks() {
|
|
|
19
19
|
|
|
20
20
|
module.exports = common.runTest(test);
|
|
21
21
|
|
|
22
|
-
function installAsyncHooksForTest() {
|
|
22
|
+
function installAsyncHooksForTest (resName) {
|
|
23
23
|
return new Promise((resolve, reject) => {
|
|
24
24
|
let id;
|
|
25
25
|
const events = [];
|
|
@@ -27,60 +27,96 @@ function installAsyncHooksForTest() {
|
|
|
27
27
|
* TODO(legendecas): investigate why resolving & disabling hooks in
|
|
28
28
|
* destroy callback causing crash with case 'callbackscope.js'.
|
|
29
29
|
*/
|
|
30
|
-
let hook;
|
|
31
30
|
let destroyed = false;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
clearInterval(interval);
|
|
36
|
-
resolve(events);
|
|
37
|
-
}
|
|
38
|
-
}, 10);
|
|
39
|
-
|
|
40
|
-
hook = async_hooks.createHook({
|
|
41
|
-
init(asyncId, type, triggerAsyncId, resource) {
|
|
42
|
-
if (id === undefined && type === 'async_context_test') {
|
|
31
|
+
const hook = asyncHooks.createHook({
|
|
32
|
+
init (asyncId, type, triggerAsyncId, resource) {
|
|
33
|
+
if (id === undefined && type === resName) {
|
|
43
34
|
id = asyncId;
|
|
44
35
|
events.push({ eventName: 'init', type, triggerAsyncId, resource });
|
|
45
36
|
}
|
|
46
37
|
},
|
|
47
|
-
before(asyncId) {
|
|
38
|
+
before (asyncId) {
|
|
48
39
|
if (asyncId === id) {
|
|
49
40
|
events.push({ eventName: 'before' });
|
|
50
41
|
}
|
|
51
42
|
},
|
|
52
|
-
after(asyncId) {
|
|
43
|
+
after (asyncId) {
|
|
53
44
|
if (asyncId === id) {
|
|
54
45
|
events.push({ eventName: 'after' });
|
|
55
46
|
}
|
|
56
47
|
},
|
|
57
|
-
destroy(asyncId) {
|
|
48
|
+
destroy (asyncId) {
|
|
58
49
|
if (asyncId === id) {
|
|
59
50
|
events.push({ eventName: 'destroy' });
|
|
60
51
|
destroyed = true;
|
|
61
52
|
}
|
|
62
53
|
}
|
|
63
54
|
}).enable();
|
|
55
|
+
|
|
56
|
+
const interval = setInterval(() => {
|
|
57
|
+
if (destroyed) {
|
|
58
|
+
hook.disable();
|
|
59
|
+
clearInterval(interval);
|
|
60
|
+
resolve(events);
|
|
61
|
+
}
|
|
62
|
+
}, 10);
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const triggerAsyncId = async_hooks.executionAsyncId();
|
|
74
|
-
binding.asynccontext.makeCallback(common.mustCall(), { foo: 'foo' });
|
|
75
|
-
return hooks.then(actual => {
|
|
66
|
+
async function makeCallbackWithResource (binding) {
|
|
67
|
+
const hooks = installAsyncHooksForTest('async_context_test');
|
|
68
|
+
const triggerAsyncId = asyncHooks.executionAsyncId();
|
|
69
|
+
await new Promise((resolve, reject) => {
|
|
70
|
+
binding.asynccontext.makeCallback(common.mustCall(), { foo: 'foo' });
|
|
71
|
+
hooks.then(actual => {
|
|
76
72
|
assert.deepStrictEqual(actual, [
|
|
77
|
-
{
|
|
73
|
+
{
|
|
74
|
+
eventName: 'init',
|
|
78
75
|
type: 'async_context_test',
|
|
79
76
|
triggerAsyncId: triggerAsyncId,
|
|
80
|
-
resource: { foo: 'foo' }
|
|
77
|
+
resource: { foo: 'foo' }
|
|
78
|
+
},
|
|
79
|
+
{ eventName: 'before' },
|
|
80
|
+
{ eventName: 'after' },
|
|
81
|
+
{ eventName: 'destroy' }
|
|
82
|
+
]);
|
|
83
|
+
}).catch(common.mustNotCall());
|
|
84
|
+
resolve();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function makeCallbackWithoutResource (binding) {
|
|
89
|
+
const hooks = installAsyncHooksForTest('async_context_no_res_test');
|
|
90
|
+
const triggerAsyncId = asyncHooks.executionAsyncId();
|
|
91
|
+
await new Promise((resolve, reject) => {
|
|
92
|
+
binding.asynccontext.makeCallbackNoResource(common.mustCall());
|
|
93
|
+
hooks.then(actual => {
|
|
94
|
+
assert.deepStrictEqual(actual, [
|
|
95
|
+
{
|
|
96
|
+
eventName: 'init',
|
|
97
|
+
type: 'async_context_no_res_test',
|
|
98
|
+
triggerAsyncId: triggerAsyncId,
|
|
99
|
+
resource: { }
|
|
100
|
+
},
|
|
81
101
|
{ eventName: 'before' },
|
|
82
102
|
{ eventName: 'after' },
|
|
83
103
|
{ eventName: 'destroy' }
|
|
84
104
|
]);
|
|
85
|
-
|
|
105
|
+
}).catch(common.mustNotCall());
|
|
106
|
+
resolve();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function assertAsyncContextReturnsCorrectEnv (binding) {
|
|
111
|
+
assert.strictEqual(binding.asynccontext.asyncCxtReturnCorrectEnv(), true);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function test (binding) {
|
|
115
|
+
if (!checkAsyncHooks()) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
await makeCallbackWithResource(binding);
|
|
120
|
+
await makeCallbackWithoutResource(binding);
|
|
121
|
+
assertAsyncContextReturnsCorrectEnv(binding);
|
|
86
122
|
}
|
|
@@ -65,6 +65,7 @@ Object InitTypedArray(Env env);
|
|
|
65
65
|
Object InitGlobalObject(Env env);
|
|
66
66
|
Object InitObjectWrap(Env env);
|
|
67
67
|
Object InitObjectWrapConstructorException(Env env);
|
|
68
|
+
Object InitObjectWrapFunction(Env env);
|
|
68
69
|
Object InitObjectWrapRemoveWrap(Env env);
|
|
69
70
|
Object InitObjectWrapMultipleInheritance(Env env);
|
|
70
71
|
Object InitObjectReference(Env env);
|
|
@@ -152,6 +153,7 @@ Object Init(Env env, Object exports) {
|
|
|
152
153
|
exports.Set("objectwrap", InitObjectWrap(env));
|
|
153
154
|
exports.Set("objectwrapConstructorException",
|
|
154
155
|
InitObjectWrapConstructorException(env));
|
|
156
|
+
exports.Set("objectwrap_function", InitObjectWrapFunction(env));
|
|
155
157
|
exports.Set("objectwrap_removewrap", InitObjectWrapRemoveWrap(env));
|
|
156
158
|
exports.Set("objectwrap_multiple_inheritance", InitObjectWrapMultipleInheritance(env));
|
|
157
159
|
exports.Set("objectreference", InitObjectReference(env));
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
'typedarray.cc',
|
|
67
67
|
'objectwrap.cc',
|
|
68
68
|
'objectwrap_constructor_exception.cc',
|
|
69
|
+
'objectwrap_function.cc',
|
|
69
70
|
'objectwrap_removewrap.cc',
|
|
70
71
|
'objectwrap_multiple_inheritance.cc',
|
|
71
72
|
'object_reference.cc',
|
|
@@ -113,5 +114,11 @@
|
|
|
113
114
|
'sources': ['>@(build_sources_swallowexcept)'],
|
|
114
115
|
'defines': ['NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS']
|
|
115
116
|
},
|
|
117
|
+
{
|
|
118
|
+
'target_name': 'binding_custom_namespace',
|
|
119
|
+
'includes': ['../noexcept.gypi'],
|
|
120
|
+
'sources': ['>@(build_sources)'],
|
|
121
|
+
'defines': ['NAPI_CPP_CUSTOM_NAMESPACE=cstm']
|
|
122
|
+
},
|
|
116
123
|
],
|
|
117
124
|
}
|