node-addon-api 2.0.2 → 3.1.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.
Files changed (82) hide show
  1. package/.clang-format +111 -0
  2. package/.github/workflows/ci.yml +55 -0
  3. package/.github/workflows/linter.yml +24 -0
  4. package/.github/workflows/stale.yml +18 -0
  5. package/.travis.yml +1 -5
  6. package/CHANGELOG.md +237 -23
  7. package/README.md +101 -31
  8. package/appveyor.yml +3 -14
  9. package/benchmark/README.md +47 -0
  10. package/benchmark/binding.gyp +25 -0
  11. package/benchmark/function_args.cc +217 -0
  12. package/benchmark/function_args.js +60 -0
  13. package/benchmark/index.js +34 -0
  14. package/benchmark/property_descriptor.cc +91 -0
  15. package/benchmark/property_descriptor.js +37 -0
  16. package/common.gypi +21 -0
  17. package/doc/addon.md +157 -0
  18. package/doc/array.md +81 -0
  19. package/doc/array_buffer.md +20 -0
  20. package/doc/async_context.md +1 -1
  21. package/doc/async_worker.md +34 -5
  22. package/doc/{async_progress_worker.md → async_worker_variants.md} +236 -23
  23. package/doc/bigint.md +7 -2
  24. package/doc/boolean.md +5 -1
  25. package/doc/buffer.md +4 -0
  26. package/doc/checker-tool.md +1 -1
  27. package/doc/class_property_descriptor.md +3 -3
  28. package/doc/creating_a_release.md +6 -6
  29. package/doc/dataview.md +4 -0
  30. package/doc/date.md +2 -2
  31. package/doc/env.md +69 -0
  32. package/doc/error.md +5 -0
  33. package/doc/escapable_handle_scope.md +1 -1
  34. package/doc/external.md +4 -0
  35. package/doc/function.md +111 -3
  36. package/doc/function_reference.md +1 -1
  37. package/doc/handle_scope.md +1 -1
  38. package/doc/hierarchy.md +91 -0
  39. package/doc/instance_wrap.md +408 -0
  40. package/doc/name.md +29 -0
  41. package/doc/number.md +1 -1
  42. package/doc/object.md +44 -1
  43. package/doc/object_lifetime_management.md +2 -2
  44. package/doc/object_reference.md +1 -1
  45. package/doc/object_wrap.md +220 -216
  46. package/doc/prebuild_tools.md +2 -2
  47. package/doc/promises.md +5 -0
  48. package/doc/property_descriptor.md +67 -12
  49. package/doc/setup.md +1 -2
  50. package/doc/string.md +5 -1
  51. package/doc/symbol.md +5 -1
  52. package/doc/threadsafe.md +121 -0
  53. package/doc/threadsafe_function.md +16 -46
  54. package/doc/typed_array.md +4 -0
  55. package/doc/typed_array_of.md +4 -0
  56. package/doc/typed_threadsafe_function.md +307 -0
  57. package/doc/value.md +166 -104
  58. package/doc/version_management.md +2 -2
  59. package/except.gypi +16 -0
  60. package/index.js +7 -41
  61. package/napi-inl.h +1685 -464
  62. package/napi.h +606 -141
  63. package/node_api.gyp +9 -0
  64. package/noexcept.gypi +16 -0
  65. package/{src/nothing.c → nothing.c} +0 -0
  66. package/package-support.json +21 -0
  67. package/package.json +106 -2
  68. package/tools/README.md +12 -6
  69. package/tools/clang-format.js +47 -0
  70. package/tools/conversion.js +4 -8
  71. package/doc/Doxyfile +0 -2450
  72. package/doc/basic_types.md +0 -423
  73. package/doc/working_with_javascript_values.md +0 -14
  74. package/external-napi/node_api.h +0 -7
  75. package/src/node_api.cc +0 -3655
  76. package/src/node_api.gyp +0 -21
  77. package/src/node_api.h +0 -588
  78. package/src/node_api_types.h +0 -115
  79. package/src/node_internals.cc +0 -142
  80. package/src/node_internals.h +0 -157
  81. package/src/util-inl.h +0 -38
  82. package/src/util.h +0 -7
package/doc/name.md ADDED
@@ -0,0 +1,29 @@
1
+ # Name
2
+
3
+ Class `Napi::Name` inherits from class [`Napi::Value`][].
4
+
5
+ Names are JavaScript values that can be used as a property name. There are two
6
+ specialized types of names supported in Node.js Addon API [`Napi::String`](string.md)
7
+ and [`Napi::Symbol`](symbol.md).
8
+
9
+ ## Methods
10
+
11
+ ### Constructor
12
+ ```cpp
13
+ Napi::Name::Name();
14
+ ```
15
+
16
+ Returns an empty `Napi::Name`.
17
+
18
+ ```cpp
19
+ Napi::Name::Name(napi_env env, napi_value value);
20
+ ```
21
+ - `[in] env` - The environment in which to create the array.
22
+ - `[in] value` - The primitive to wrap.
23
+
24
+ Returns a `Napi::Name` created from the JavaScript primitive.
25
+
26
+ Note:
27
+ The value is not coerced to a string.
28
+
29
+ [`Napi::Value`]: ./value.md
package/doc/number.md CHANGED
@@ -16,7 +16,7 @@ Napi::Number();
16
16
 
17
17
  Returns a new _empty_ `Napi::Number` object.
18
18
 
19
- ### Contructor
19
+ ### Constructor
20
20
 
21
21
  Creates a new instance of a `Napi::Number` object.
22
22
 
package/doc/object.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Object
2
2
 
3
+ Class `Napi::Object` inherits from class [`Napi::Value`][].
4
+
3
5
  The `Napi::Object` class corresponds to a JavaScript object. It is extended by the following node-addon-api classes that you may use when working with more specific types:
4
6
 
5
- - [`Napi::Value`](value.md) and extends [`Napi::Array`](array.md)
7
+ - [`Napi::Array`](array.md)
6
8
  - [`Napi::ArrayBuffer`](array_buffer.md)
7
9
  - [`Napi::Buffer<T>`](buffer.md)
8
10
  - [`Napi::Function`](function.md)
@@ -101,6 +103,22 @@ While the value must be any of the following types:
101
103
  - `bool`
102
104
  - `double`
103
105
 
106
+ ### Delete()
107
+
108
+ ```cpp
109
+ bool Napi::Object::Delete(____ key);
110
+ ```
111
+ - `[in] key`: The name of the property to delete.
112
+
113
+ Deletes the property associated with the given key. Returns `true` if the property was deleted.
114
+
115
+ The `key` can be any of the following types:
116
+ - `napi_value`
117
+ - [`Napi::Value`](value.md)
118
+ - `const char *`
119
+ - `const std::string &`
120
+ - `uint32_t`
121
+
104
122
  ### Get()
105
123
 
106
124
  ```cpp
@@ -171,6 +189,29 @@ void finalizeCallback(Napi::Env env, T* data, Hint* hint);
171
189
  ```
172
190
  where `data` and `hint` are the pointers that were passed into the call to `AddFinalizer()`.
173
191
 
192
+ ### GetPropertyNames()
193
+ ```cpp
194
+ Napi::Array Napi::Object::GetPropertyNames() const;
195
+ ```
196
+
197
+ Returns the names of the enumerable properties of the object as a [`Napi::Array`](array.md) of strings.
198
+ The properties whose key is a `Symbol` will not be included.
199
+
200
+ ### HasOwnProperty()
201
+ ```cpp
202
+ bool Napi::Object::HasOwnProperty(____ key); const
203
+ ```
204
+ - `[in] key` The name of the property to check.
205
+
206
+ Returns a `bool` that is *true* if the object has an own property named `key` and *false* otherwise.
207
+
208
+ The key can be any of the following types:
209
+ - `napi_value`
210
+ - [`Napi::Value`](value.md)
211
+ - `const char*`
212
+ - `const std::string&`
213
+ - `uint32_t`
214
+
174
215
  ### DefineProperty()
175
216
 
176
217
  ```cpp
@@ -234,3 +275,5 @@ Napi::Value Napi::Object::operator[] (uint32_t index) const;
234
275
  - `[in] index`: Element index.
235
276
 
236
277
  Returns an indexed property or array element as a [`Napi::Value`](value.md).
278
+
279
+ [`Napi::Value`]: ./value.md
@@ -60,7 +60,7 @@ a native method must be deleted before returning from that method. Since
60
60
  deletion, however, care must be taken to create the scope in the right
61
61
  place such that you achieve the desired lifetime.
62
62
 
63
- Taking the earlier example, creating a `Napi::HandleScope` in the innner loop
63
+ Taking the earlier example, creating a `Napi::HandleScope` in the inner loop
64
64
  would ensure that at most a single new value is held alive throughout the
65
65
  execution of the loop:
66
66
 
@@ -69,7 +69,7 @@ for (int i = 0; i < LOOP_MAX; i++) {
69
69
  Napi::HandleScope scope(info.Env());
70
70
  std::string name = std::string("inner-scope") + std::to_string(i);
71
71
  Napi::Value newValue = Napi::String::New(info.Env(), name.c_str());
72
- // do something with neValue
72
+ // do something with newValue
73
73
  };
74
74
  ```
75
75
 
@@ -8,7 +8,7 @@ For more general information on references, please consult [`Napi::Reference`](r
8
8
  ```cpp
9
9
  #include <napi.h>
10
10
 
11
- using namescape Napi;
11
+ using namespace Napi;
12
12
 
13
13
  void Init(Env env) {
14
14