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.
- package/.clang-format +111 -0
- package/.github/workflows/ci.yml +55 -0
- package/.github/workflows/linter.yml +24 -0
- package/.github/workflows/stale.yml +18 -0
- package/.travis.yml +1 -5
- package/CHANGELOG.md +237 -23
- package/README.md +101 -31
- package/appveyor.yml +3 -14
- package/benchmark/README.md +47 -0
- package/benchmark/binding.gyp +25 -0
- package/benchmark/function_args.cc +217 -0
- package/benchmark/function_args.js +60 -0
- package/benchmark/index.js +34 -0
- package/benchmark/property_descriptor.cc +91 -0
- package/benchmark/property_descriptor.js +37 -0
- package/common.gypi +21 -0
- package/doc/addon.md +157 -0
- package/doc/array.md +81 -0
- package/doc/array_buffer.md +20 -0
- package/doc/async_context.md +1 -1
- package/doc/async_worker.md +34 -5
- package/doc/{async_progress_worker.md → async_worker_variants.md} +236 -23
- package/doc/bigint.md +7 -2
- package/doc/boolean.md +5 -1
- package/doc/buffer.md +4 -0
- package/doc/checker-tool.md +1 -1
- package/doc/class_property_descriptor.md +3 -3
- package/doc/creating_a_release.md +6 -6
- package/doc/dataview.md +4 -0
- package/doc/date.md +2 -2
- package/doc/env.md +69 -0
- package/doc/error.md +5 -0
- package/doc/escapable_handle_scope.md +1 -1
- package/doc/external.md +4 -0
- package/doc/function.md +111 -3
- package/doc/function_reference.md +1 -1
- package/doc/handle_scope.md +1 -1
- package/doc/hierarchy.md +91 -0
- package/doc/instance_wrap.md +408 -0
- package/doc/name.md +29 -0
- package/doc/number.md +1 -1
- package/doc/object.md +44 -1
- package/doc/object_lifetime_management.md +2 -2
- package/doc/object_reference.md +1 -1
- package/doc/object_wrap.md +220 -216
- package/doc/prebuild_tools.md +2 -2
- package/doc/promises.md +5 -0
- package/doc/property_descriptor.md +67 -12
- package/doc/setup.md +1 -2
- package/doc/string.md +5 -1
- package/doc/symbol.md +5 -1
- package/doc/threadsafe.md +121 -0
- package/doc/threadsafe_function.md +16 -46
- package/doc/typed_array.md +4 -0
- package/doc/typed_array_of.md +4 -0
- package/doc/typed_threadsafe_function.md +307 -0
- package/doc/value.md +166 -104
- package/doc/version_management.md +2 -2
- package/except.gypi +16 -0
- package/index.js +7 -41
- package/napi-inl.h +1685 -464
- package/napi.h +606 -141
- package/node_api.gyp +9 -0
- package/noexcept.gypi +16 -0
- package/{src/nothing.c → nothing.c} +0 -0
- package/package-support.json +21 -0
- package/package.json +106 -2
- package/tools/README.md +12 -6
- package/tools/clang-format.js +47 -0
- package/tools/conversion.js +4 -8
- package/doc/Doxyfile +0 -2450
- package/doc/basic_types.md +0 -423
- package/doc/working_with_javascript_values.md +0 -14
- 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/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
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::
|
|
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
|
|
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
|
|
72
|
+
// do something with newValue
|
|
73
73
|
};
|
|
74
74
|
```
|
|
75
75
|
|