node-addon-api 1.7.2 → 2.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 +4 -7
- package/CHANGELOG.md +54 -3
- package/README.md +6 -3
- package/doc/array_buffer.md +1 -1
- package/doc/async_context.md +10 -0
- package/doc/async_operations.md +1 -1
- package/doc/async_progress_worker.md +344 -0
- package/doc/async_worker.md +23 -22
- package/doc/basic_types.md +8 -0
- package/doc/class_property_descriptor.md +2 -3
- package/doc/cmake-js.md +58 -9
- package/doc/date.md +68 -0
- package/doc/object.md +34 -0
- package/doc/object_wrap.md +13 -2
- package/doc/prebuild_tools.md +1 -1
- package/doc/threadsafe_function.md +18 -1
- package/doc/value.md +9 -0
- package/napi-inl.h +346 -76
- package/napi.h +136 -18
- package/package.json +212 -47
- package/src/node_api.cc +3 -9
package/doc/async_worker.md
CHANGED
|
@@ -7,8 +7,8 @@ operation.
|
|
|
7
7
|
|
|
8
8
|
Once created, execution is requested by calling `Napi::AsyncWorker::Queue`. When
|
|
9
9
|
a thread is available for execution the `Napi::AsyncWorker::Execute` method will
|
|
10
|
-
be invoked.
|
|
11
|
-
`Napi::AsyncWorker::OnOK` or `Napi::AsyncWorker::OnError` will be invoked.
|
|
10
|
+
be invoked. Once `Napi::AsyncWorker::Execute` completes either
|
|
11
|
+
`Napi::AsyncWorker::OnOK` or `Napi::AsyncWorker::OnError` will be invoked. Once
|
|
12
12
|
the `Napi::AsyncWorker::OnOK` or `Napi::AsyncWorker::OnError` methods are
|
|
13
13
|
complete the `Napi::AsyncWorker` instance is destructed.
|
|
14
14
|
|
|
@@ -38,7 +38,7 @@ void Napi::AsyncWorker::Queue();
|
|
|
38
38
|
### Cancel
|
|
39
39
|
|
|
40
40
|
Cancels queued work if it has not yet been started. If it has already started
|
|
41
|
-
executing, it cannot be cancelled.
|
|
41
|
+
executing, it cannot be cancelled. If cancelled successfully neither
|
|
42
42
|
`OnOK` nor `OnError` will be called.
|
|
43
43
|
|
|
44
44
|
```cpp
|
|
@@ -90,14 +90,14 @@ void Napi::AsyncWorker::SetError(const std::string& error);
|
|
|
90
90
|
|
|
91
91
|
### Execute
|
|
92
92
|
|
|
93
|
-
This method is used to execute some tasks
|
|
93
|
+
This method is used to execute some tasks outside of the **event loop** on a libuv
|
|
94
94
|
worker thread. Subclasses must implement this method and the method is run on
|
|
95
|
-
a thread other than that running the main event loop.
|
|
95
|
+
a thread other than that running the main event loop. As the method is not
|
|
96
96
|
running on the main event loop, it must avoid calling any methods from node-addon-api
|
|
97
97
|
or running any code that might invoke JavaScript. Instead, once this method is
|
|
98
98
|
complete any interaction through node-addon-api with JavaScript should be implemented
|
|
99
|
-
in the `Napi::AsyncWorker::OnOK` method
|
|
100
|
-
invoked when the `Napi::AsyncWorker::Execute` method completes.
|
|
99
|
+
in the `Napi::AsyncWorker::OnOK` method and `Napi::AsyncWorker::OnError` which run
|
|
100
|
+
on the main thread and are invoked when the `Napi::AsyncWorker::Execute` method completes.
|
|
101
101
|
|
|
102
102
|
```cpp
|
|
103
103
|
virtual void Napi::AsyncWorker::Execute() = 0;
|
|
@@ -106,18 +106,19 @@ virtual void Napi::AsyncWorker::Execute() = 0;
|
|
|
106
106
|
### OnOK
|
|
107
107
|
|
|
108
108
|
This method is invoked when the computation in the `Execute` method ends.
|
|
109
|
-
The default implementation runs the Callback optionally provided when the
|
|
110
|
-
was created. The
|
|
111
|
-
|
|
109
|
+
The default implementation runs the `Callback` optionally provided when the
|
|
110
|
+
`AsyncWorker` class was created. The `Callback` will by default receive no
|
|
111
|
+
arguments. The arguments to the `Callback` can be provided by overriding the
|
|
112
|
+
`GetResult()` method.
|
|
112
113
|
|
|
113
114
|
```cpp
|
|
114
115
|
virtual void Napi::AsyncWorker::OnOK();
|
|
115
116
|
```
|
|
116
117
|
### GetResult
|
|
117
118
|
|
|
118
|
-
This method returns the arguments passed to the Callback invoked by the default
|
|
119
|
+
This method returns the arguments passed to the `Callback` invoked by the default
|
|
119
120
|
`OnOK()` implementation. The default implementation returns an empty vector,
|
|
120
|
-
providing no arguments to the Callback
|
|
121
|
+
providing no arguments to the `Callback`.
|
|
121
122
|
|
|
122
123
|
```cpp
|
|
123
124
|
virtual std::vector<napi_value> Napi::AsyncWorker::GetResult(Napi::Env env);
|
|
@@ -128,7 +129,7 @@ virtual std::vector<napi_value> Napi::AsyncWorker::GetResult(Napi::Env env);
|
|
|
128
129
|
This method is invoked after `Napi::AsyncWorker::Execute` completes if an error
|
|
129
130
|
occurs while `Napi::AsyncWorker::Execute` is running and C++ exceptions are
|
|
130
131
|
enabled or if an error was set through a call to `Napi::AsyncWorker::SetError`.
|
|
131
|
-
The default implementation calls the
|
|
132
|
+
The default implementation calls the `Callback` provided when the `Napi::AsyncWorker`
|
|
132
133
|
class was created, passing in the error as the first parameter.
|
|
133
134
|
|
|
134
135
|
```cpp
|
|
@@ -172,7 +173,7 @@ explicit Napi::AsyncWorker(const Napi::Function& callback, const char* resource_
|
|
|
172
173
|
|
|
173
174
|
- `[in] callback`: The function which will be called when an asynchronous
|
|
174
175
|
operations ends. The given function is called from the main event loop thread.
|
|
175
|
-
- `[in] resource_name`: Null-terminated
|
|
176
|
+
- `[in] resource_name`: Null-terminated string that represents the
|
|
176
177
|
identifier for the kind of resource that is being provided for diagnostic
|
|
177
178
|
information exposed by the async_hooks API.
|
|
178
179
|
|
|
@@ -189,7 +190,7 @@ explicit Napi::AsyncWorker(const Napi::Function& callback, const char* resource_
|
|
|
189
190
|
|
|
190
191
|
- `[in] callback`: The function which will be called when an asynchronous
|
|
191
192
|
operations ends. The given function is called from the main event loop thread.
|
|
192
|
-
- `[in] resource_name`:
|
|
193
|
+
- `[in] resource_name`: Null-terminated string that represents the
|
|
193
194
|
identifier for the kind of resource that is being provided for diagnostic
|
|
194
195
|
information exposed by the async_hooks API.
|
|
195
196
|
- `[in] resource`: Object associated with the asynchronous operation that
|
|
@@ -224,7 +225,7 @@ explicit Napi::AsyncWorker(const Napi::Object& receiver, const Napi::Function& c
|
|
|
224
225
|
- `[in] receiver`: The `this` object passed to the called function.
|
|
225
226
|
- `[in] callback`: The function which will be called when an asynchronous
|
|
226
227
|
operations ends. The given function is called from the main event loop thread.
|
|
227
|
-
- `[in] resource_name`:
|
|
228
|
+
- `[in] resource_name`: Null-terminated string that represents the
|
|
228
229
|
identifier for the kind of resource that is being provided for diagnostic
|
|
229
230
|
information exposed by the async_hooks API.
|
|
230
231
|
|
|
@@ -242,7 +243,7 @@ explicit Napi::AsyncWorker(const Napi::Object& receiver, const Napi::Function& c
|
|
|
242
243
|
- `[in] receiver`: The `this` object passed to the called function.
|
|
243
244
|
- `[in] callback`: The function which will be called when an asynchronous
|
|
244
245
|
operations ends. The given function is called from the main event loop thread.
|
|
245
|
-
- `[in] resource_name`:
|
|
246
|
+
- `[in] resource_name`: Null-terminated string that represents the
|
|
246
247
|
identifier for the kind of resource that is being provided for diagnostic
|
|
247
248
|
information exposed by the async_hooks API.
|
|
248
249
|
- `[in] resource`: Object associated with the asynchronous operation that
|
|
@@ -274,7 +275,7 @@ explicit Napi::AsyncWorker(Napi::Env env, const char* resource_name);
|
|
|
274
275
|
```
|
|
275
276
|
|
|
276
277
|
- `[in] env`: The environment in which to create the `Napi::AsyncWorker`.
|
|
277
|
-
- `[in] resource_name`: Null-terminated
|
|
278
|
+
- `[in] resource_name`: Null-terminated string that represents the
|
|
278
279
|
identifier for the kind of resource that is being provided for diagnostic
|
|
279
280
|
information exposed by the async_hooks API.
|
|
280
281
|
|
|
@@ -290,7 +291,7 @@ explicit Napi::AsyncWorker(Napi::Env env, const char* resource_name, const Napi:
|
|
|
290
291
|
```
|
|
291
292
|
|
|
292
293
|
- `[in] env`: The environment in which to create the `Napi::AsyncWorker`.
|
|
293
|
-
- `[in] resource_name`:
|
|
294
|
+
- `[in] resource_name`: Null-terminated string that represents the
|
|
294
295
|
identifier for the kind of resource that is being provided for diagnostic
|
|
295
296
|
information exposed by the async_hooks API.
|
|
296
297
|
- `[in] resource`: Object associated with the asynchronous operation that
|
|
@@ -333,7 +334,7 @@ function runs in the background out of the **event loop** thread and at the end
|
|
|
333
334
|
the `Napi::AsyncWorker::OnOK` or `Napi::AsyncWorker::OnError` function will be
|
|
334
335
|
called and are executed as part of the event loop.
|
|
335
336
|
|
|
336
|
-
The code below
|
|
337
|
+
The code below shows a basic example of `Napi::AsyncWorker` the implementation:
|
|
337
338
|
|
|
338
339
|
```cpp
|
|
339
340
|
#include<napi.h>
|
|
@@ -371,7 +372,7 @@ the work on the `Napi::AsyncWorker::Execute` method is done the
|
|
|
371
372
|
`Napi::AsyncWorker::OnOk` method is called and the results return back to
|
|
372
373
|
JavaScript invoking the stored callback with its associated environment.
|
|
373
374
|
|
|
374
|
-
The following code shows an example
|
|
375
|
+
The following code shows an example of how to create and use an `Napi::AsyncWorker`.
|
|
375
376
|
|
|
376
377
|
```cpp
|
|
377
378
|
#include<napi.h>
|
|
@@ -382,7 +383,7 @@ The following code shows an example on how to create and use an `Napi::AsyncWork
|
|
|
382
383
|
use namespace Napi;
|
|
383
384
|
|
|
384
385
|
Value Echo(const CallbackInfo& info) {
|
|
385
|
-
// You need to
|
|
386
|
+
// You need to validate the arguments here.
|
|
386
387
|
Function cb = info[1].As<Function>();
|
|
387
388
|
std::string in = info[0].As<String>();
|
|
388
389
|
EchoWorker* wk = new EchoWorker(cb, in);
|
package/doc/basic_types.md
CHANGED
|
@@ -257,6 +257,14 @@ bool Napi::Value::IsExternal() const;
|
|
|
257
257
|
Returns `true` if the underlying value is a N-API external object or `false`
|
|
258
258
|
otherwise.
|
|
259
259
|
|
|
260
|
+
#### IsDate
|
|
261
|
+
```cpp
|
|
262
|
+
bool Napi::Value::IsDate() const;
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Returns `true` if the underlying value is a JavaScript `Date` or `false`
|
|
266
|
+
otherwise.
|
|
267
|
+
|
|
260
268
|
#### ToBoolean
|
|
261
269
|
```cpp
|
|
262
270
|
Napi::Boolean Napi::Value::ToBoolean() const;
|
|
@@ -20,7 +20,7 @@ class Example : public Napi::ObjectWrap<Example> {
|
|
|
20
20
|
static Napi::FunctionReference constructor;
|
|
21
21
|
double _value;
|
|
22
22
|
Napi::Value GetValue(const Napi::CallbackInfo &info);
|
|
23
|
-
|
|
23
|
+
void SetValue(const Napi::CallbackInfo &info, const Napi::Value &value);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
Napi::Object Example::Init(Napi::Env env, Napi::Object exports) {
|
|
@@ -52,12 +52,11 @@ Napi::Value Example::GetValue(const Napi::CallbackInfo &info) {
|
|
|
52
52
|
return Napi::Number::New(env, this->_value);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
void Example::SetValue(const Napi::CallbackInfo &info, const Napi::Value &value) {
|
|
56
56
|
Napi::Env env = info.Env();
|
|
57
57
|
// ...
|
|
58
58
|
Napi::Number arg = value.As<Napi::Number>();
|
|
59
59
|
this->_value = arg.DoubleValue();
|
|
60
|
-
return this->GetValue(info);
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
// Initialize native add-on
|
package/doc/cmake-js.md
CHANGED
|
@@ -1,19 +1,68 @@
|
|
|
1
1
|
# CMake.js
|
|
2
2
|
|
|
3
|
-
**CMake.js** is a build tool that allow native addon
|
|
4
|
-
C++ code into executable form. It works like **[node-gyp](node-gyp.md)** but
|
|
5
|
-
instead of Google's **gyp**
|
|
3
|
+
[**CMake.js**](https://github.com/cmake-js/cmake-js) is a build tool that allow native addon developers to compile their
|
|
4
|
+
C or C++ code into executable form. It works like **[node-gyp](node-gyp.md)** but
|
|
5
|
+
instead of Google's [**gyp**](https://gyp.gsrc.io) tool it is based on the [**CMake**](https://cmake.org) build system.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Quick Start
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
### Install CMake
|
|
10
|
+
|
|
11
|
+
CMake.js requires that CMake be installed. Installers for a variety of platforms can be found on the [CMake website](https://cmake.org).
|
|
12
|
+
|
|
13
|
+
### Install CMake.js
|
|
14
|
+
|
|
15
|
+
For developers, CMake.js is typically installed as a global package:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g cmake-js
|
|
19
|
+
cmake-js --help
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> For *users* of your native addon, CMake.js should be configured as a dependency in your `package.json` as described in the [CMake.js documentation](https://github.com/cmake-js/cmake-js).
|
|
23
|
+
|
|
24
|
+
### CMakeLists.txt
|
|
25
|
+
|
|
26
|
+
Your project will require a `CMakeLists.txt` file. The [CMake.js README file](https://github.com/cmake-js/cmake-js#usage) shows what's necessary.
|
|
27
|
+
|
|
28
|
+
### NAPI_VERSION
|
|
29
|
+
|
|
30
|
+
When building N-API addons, it's crucial to specify the N-API version your code is designed to work with. With CMake.js, this information is specified in the `CMakeLists.txt` file:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
add_definitions(-DNAPI_VERSION=3)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Since N-API is ABI-stable, your N-API addon will work, without recompilation, with the N-API version you specify in `NAPI_VERSION` and all subsequent N-API versions.
|
|
37
|
+
|
|
38
|
+
In the absence of a need for features available only in a specific N-API version, version 3 is a good choice as it is the version of N-API that was active when N-API left experimental status.
|
|
39
|
+
|
|
40
|
+
### NAPI_EXPERIMENTAL
|
|
41
|
+
|
|
42
|
+
The following line in the `CMakeLists.txt` file will enable N-API experimental features if your code requires them:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
add_definitions(-DNAPI_EXPERIMENTAL)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### node-addon-api
|
|
49
|
+
|
|
50
|
+
If your N-API native add-on uses the optional [**node-addon-api**](https://github.com/nodejs/node-addon-api#node-addon-api-module) C++ wrapper, the `CMakeLists.txt` file requires additional configuration information as described on the [CMake.js README file](https://github.com/cmake-js/cmake-js#n-api-and-node-addon-api).
|
|
51
|
+
|
|
52
|
+
## Example
|
|
53
|
+
|
|
54
|
+
A working example of an N-API native addon built using CMake.js can be found on the [node-addon-examples repository](https://github.com/nodejs/node-addon-examples/tree/master/build_with_cmake#building-n-api-addons-using-cmakejs).
|
|
55
|
+
|
|
56
|
+
## **CMake** Reference
|
|
57
|
+
|
|
58
|
+
- [Installation](https://github.com/cmake-js/cmake-js#installation)
|
|
59
|
+
- [How to use](https://github.com/cmake-js/cmake-js#usage)
|
|
11
60
|
- [Using N-API and node-addon-api](https://github.com/cmake-js/cmake-js#n-api-and-node-addon-api)
|
|
12
|
-
- [Tutorials](https://
|
|
13
|
-
- [Use case in the works - ArrayFire.js](https://
|
|
61
|
+
- [Tutorials](https://github.com/cmake-js/cmake-js#tutorials)
|
|
62
|
+
- [Use case in the works - ArrayFire.js](https://github.com/cmake-js/cmake-js#use-case-in-the-works---arrayfirejs)
|
|
14
63
|
|
|
15
64
|
Sometimes finding the right settings is not easy so to accomplish at most
|
|
16
65
|
complicated task please refer to:
|
|
17
66
|
|
|
18
67
|
- [CMake documentation](https://cmake.org/)
|
|
19
|
-
- [CMake.js wiki](https://github.com/cmake-js/cmake-js/wiki)
|
|
68
|
+
- [CMake.js wiki](https://github.com/cmake-js/cmake-js/wiki)
|
package/doc/date.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Date
|
|
2
|
+
|
|
3
|
+
`Napi::Date` class is a representation of the JavaScript `Date` object. The
|
|
4
|
+
`Napi::Date` class inherits its behavior from `Napi::Value` class
|
|
5
|
+
(for more info see [`Napi::Value`](value.md))
|
|
6
|
+
|
|
7
|
+
## Methods
|
|
8
|
+
|
|
9
|
+
### Constructor
|
|
10
|
+
|
|
11
|
+
Creates a new _empty_ instance of a `Napi::Date` object.
|
|
12
|
+
|
|
13
|
+
```cpp
|
|
14
|
+
Napi::Date::Date();
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Creates a new _non-empty_ instance of a `Napi::Date` object.
|
|
18
|
+
|
|
19
|
+
```cpp
|
|
20
|
+
Napi::Date::Date(napi_env env, napi_value value);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- `[in] env`: The environment in which to construct the `Napi::Date` object.
|
|
24
|
+
- `[in] value`: The `napi_value` which is a handle for a JavaScript `Date`.
|
|
25
|
+
|
|
26
|
+
### New
|
|
27
|
+
|
|
28
|
+
Creates a new instance of a `Napi::Date` object.
|
|
29
|
+
|
|
30
|
+
```cpp
|
|
31
|
+
static Napi::Date Napi::Date::New(Napi::Env env, double value);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- `[in] env`: The environment in which to construct the `Napi::Date` object.
|
|
35
|
+
- `[in] value`: The time value the JavaScript `Date` will contain represented
|
|
36
|
+
as the number of milliseconds since 1 January 1970 00:00:00 UTC.
|
|
37
|
+
|
|
38
|
+
Returns a new instance of `Napi::Date` object.
|
|
39
|
+
|
|
40
|
+
### ValueOf
|
|
41
|
+
|
|
42
|
+
```cpp
|
|
43
|
+
double Napi::Date::ValueOf() const;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Returns the time value as `double` primitive represented as the number of
|
|
47
|
+
milliseconds since 1 January 1970 00:00:00 UTC.
|
|
48
|
+
|
|
49
|
+
## Operators
|
|
50
|
+
|
|
51
|
+
### operator double
|
|
52
|
+
|
|
53
|
+
Converts a `Napi::Date` value to a `double` primitive.
|
|
54
|
+
|
|
55
|
+
```cpp
|
|
56
|
+
Napi::Date::operator double() const;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Example
|
|
60
|
+
|
|
61
|
+
The following shows an example of casting a `Napi::Date` value to a `double`
|
|
62
|
+
primitive.
|
|
63
|
+
|
|
64
|
+
```cpp
|
|
65
|
+
double operatorVal = Napi::Date::New(Env(), 0); // Napi::Date to double
|
|
66
|
+
// or
|
|
67
|
+
auto instanceVal = info[0].As<Napi::Date>().ValueOf();
|
|
68
|
+
```
|
package/doc/object.md
CHANGED
|
@@ -137,6 +137,40 @@ Returns a `bool` that is true if the `Napi::Object` is an instance created by th
|
|
|
137
137
|
|
|
138
138
|
Note: This is equivalent to the JavaScript instanceof operator.
|
|
139
139
|
|
|
140
|
+
### AddFinalizer()
|
|
141
|
+
```cpp
|
|
142
|
+
template <typename Finalizer, typename T>
|
|
143
|
+
inline void AddFinalizer(Finalizer finalizeCallback, T* data);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
- `[in] finalizeCallback`: The function to call when the object is garbage-collected.
|
|
147
|
+
- `[in] data`: The data to associate with the object.
|
|
148
|
+
|
|
149
|
+
Associates `data` with the object, calling `finalizeCallback` when the object is garbage-collected. `finalizeCallback`
|
|
150
|
+
has the signature
|
|
151
|
+
```cpp
|
|
152
|
+
void finalizeCallback(Napi::Env env, T* data);
|
|
153
|
+
```
|
|
154
|
+
where `data` is the pointer that was passed into the call to `AddFinalizer()`.
|
|
155
|
+
|
|
156
|
+
### AddFinalizer()
|
|
157
|
+
```cpp
|
|
158
|
+
template <typename Finalizer, typename T, typename Hint>
|
|
159
|
+
inline void AddFinalizer(Finalizer finalizeCallback,
|
|
160
|
+
T* data,
|
|
161
|
+
Hint* finalizeHint);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
- `[in] data`: The data to associate with the object.
|
|
165
|
+
- `[in] finalizeCallback`: The function to call when the object is garbage-collected.
|
|
166
|
+
|
|
167
|
+
Associates `data` with the object, calling `finalizeCallback` when the object is garbage-collected. An additional hint
|
|
168
|
+
may be given. It will also be passed to `finalizeCallback`, which has the signature
|
|
169
|
+
```cpp
|
|
170
|
+
void finalizeCallback(Napi::Env env, T* data, Hint* hint);
|
|
171
|
+
```
|
|
172
|
+
where `data` and `hint` are the pointers that were passed into the call to `AddFinalizer()`.
|
|
173
|
+
|
|
140
174
|
### DefineProperty()
|
|
141
175
|
|
|
142
176
|
```cpp
|
package/doc/object_wrap.md
CHANGED
|
@@ -161,7 +161,7 @@ static Napi::Function Napi::ObjectWrap::DefineClass(Napi::Env env,
|
|
|
161
161
|
JavaScript constructor function.
|
|
162
162
|
* `[in] properties`: Initializer list of class property descriptor describing
|
|
163
163
|
static and instance properties and methods of the class.
|
|
164
|
-
See: [`Class
|
|
164
|
+
See: [`Class property and descriptor`](class_property_descriptor.md).
|
|
165
165
|
* `[in] data`: User-provided data passed to the constructor callback as `data`
|
|
166
166
|
property of the `Napi::CallbackInfo`.
|
|
167
167
|
|
|
@@ -184,12 +184,23 @@ static Napi::Function Napi::ObjectWrap::DefineClass(Napi::Env env,
|
|
|
184
184
|
JavaScript constructor function.
|
|
185
185
|
* `[in] properties`: Vector of class property descriptor describing static and
|
|
186
186
|
instance properties and methods of the class.
|
|
187
|
-
See: [`Class
|
|
187
|
+
See: [`Class property and descriptor`](class_property_descriptor.md).
|
|
188
188
|
* `[in] data`: User-provided data passed to the constructor callback as `data`
|
|
189
189
|
property of the `Napi::CallbackInfo`.
|
|
190
190
|
|
|
191
191
|
Returns a `Napi::Function` representing the constructor function for the class.
|
|
192
192
|
|
|
193
|
+
### Finalize
|
|
194
|
+
|
|
195
|
+
Provides an opportunity to run cleanup code that requires access to the `Napi::Env`
|
|
196
|
+
before the wrapped native object instance is freed. Override to implement.
|
|
197
|
+
|
|
198
|
+
```cpp
|
|
199
|
+
virtual void Finalize(Napi::Env env);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
- `[in] env`: `Napi::Env`.
|
|
203
|
+
|
|
193
204
|
### StaticMethod
|
|
194
205
|
|
|
195
206
|
Creates property descriptor that represents a static method of a JavaScript class.
|
package/doc/prebuild_tools.md
CHANGED
|
@@ -9,7 +9,7 @@ possible to ditribute the native add-on in pre-built form for different platform
|
|
|
9
9
|
and architectures. The prebuild tools help to create and distrubute the pre-built
|
|
10
10
|
form of a native add-on.
|
|
11
11
|
|
|
12
|
-
The following list report
|
|
12
|
+
The following list report known tools that are compatible with **N-API**:
|
|
13
13
|
|
|
14
14
|
- **[node-pre-gyp](https://www.npmjs.com/package/node-pre-gyp)**
|
|
15
15
|
- **[prebuild](https://www.npmjs.com/package/prebuild)**
|
|
@@ -58,7 +58,10 @@ Napi::ThreadSafeFunction::ThreadSafeFunction(napi_threadsafe_function tsfn);
|
|
|
58
58
|
- `tsfn`: The `napi_threadsafe_function` which is a handle for an existing
|
|
59
59
|
thread-safe function.
|
|
60
60
|
|
|
61
|
-
Returns a non-empty `Napi::ThreadSafeFunction` instance.
|
|
61
|
+
Returns a non-empty `Napi::ThreadSafeFunction` instance. When using this
|
|
62
|
+
constructor, only use the `Blocking(void*)` / `NonBlocking(void*)` overloads;
|
|
63
|
+
the `Callback` and templated `data*` overloads should _not_ be used. See below
|
|
64
|
+
for additional details.
|
|
62
65
|
|
|
63
66
|
### New
|
|
64
67
|
|
|
@@ -171,6 +174,9 @@ There are several overloaded implementations of `BlockingCall()` and
|
|
|
171
174
|
`NonBlockingCall()` for use with optional parameters: skip the optional
|
|
172
175
|
parameter for that specific overload.
|
|
173
176
|
|
|
177
|
+
**These specific function overloads should only be used on a `ThreadSafeFunction`
|
|
178
|
+
created via `ThreadSafeFunction::New`.**
|
|
179
|
+
|
|
174
180
|
```cpp
|
|
175
181
|
napi_status Napi::ThreadSafeFunction::BlockingCall(DataType* data, Callback callback) const
|
|
176
182
|
|
|
@@ -186,6 +192,17 @@ napi_status Napi::ThreadSafeFunction::NonBlockingCall(DataType* data, Callback c
|
|
|
186
192
|
necessary to call into JavaScript via `MakeCallback()` because N-API runs
|
|
187
193
|
`callback` in a context appropriate for callbacks.
|
|
188
194
|
|
|
195
|
+
**These specific function overloads should only be used on a `ThreadSafeFunction`
|
|
196
|
+
created via `ThreadSafeFunction(napi_threadsafe_function)`.**
|
|
197
|
+
|
|
198
|
+
```cpp
|
|
199
|
+
napi_status Napi::ThreadSafeFunction::BlockingCall(void* data) const
|
|
200
|
+
|
|
201
|
+
napi_status Napi::ThreadSafeFunction::NonBlockingCall(void* data) const
|
|
202
|
+
```
|
|
203
|
+
- `data`: Data to pass to `call_js_cb` specified when creating the thread-safe
|
|
204
|
+
function via `napi_create_threadsafe_function`.
|
|
205
|
+
|
|
189
206
|
Returns one of:
|
|
190
207
|
- `napi_ok`: The call was successfully added to the queue.
|
|
191
208
|
- `napi_queue_full`: The queue was full when trying to call in a non-blocking
|
package/doc/value.md
CHANGED
|
@@ -10,6 +10,7 @@ The following classes inherit, either directly or indirectly, from `Napi::Value`
|
|
|
10
10
|
- [`Napi::ArrayBuffer`](array_buffer.md)
|
|
11
11
|
- [`Napi::Boolean`](boolean.md)
|
|
12
12
|
- [`Napi::Buffer`](buffer.md)
|
|
13
|
+
- [`Napi::Date`](date.md)
|
|
13
14
|
- [`Napi::External`](external.md)
|
|
14
15
|
- [`Napi::Function`](function.md)
|
|
15
16
|
- [`Napi::Name`](name.md)
|
|
@@ -226,6 +227,14 @@ bool Napi::Value::IsBuffer() const;
|
|
|
226
227
|
|
|
227
228
|
Returns a `bool` indicating if this `Napi::Value` is a Node buffer.
|
|
228
229
|
|
|
230
|
+
### IsDate
|
|
231
|
+
|
|
232
|
+
```cpp
|
|
233
|
+
bool Napi::Value::IsDate() const;
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Returns a `bool` indicating if this `Napi::Value` is a JavaScript date.
|
|
237
|
+
|
|
229
238
|
### As
|
|
230
239
|
|
|
231
240
|
```cpp
|