node-addon-api 3.0.1 → 3.0.2
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/CHANGELOG.md +45 -0
- package/README.md +28 -23
- package/appveyor.yml +3 -14
- package/benchmark/function_args.cc +64 -0
- package/benchmark/function_args.js +15 -7
- package/benchmark/property_descriptor.cc +31 -0
- package/benchmark/property_descriptor.js +12 -4
- package/common.gypi +1 -1
- package/doc/addon.md +157 -0
- package/doc/array.md +81 -0
- package/doc/array_buffer.md +4 -0
- package/doc/bigint.md +4 -0
- package/doc/boolean.md +4 -0
- package/doc/buffer.md +4 -0
- package/doc/dataview.md +4 -0
- package/doc/date.md +2 -2
- package/doc/error.md +5 -0
- package/doc/external.md +4 -0
- package/doc/function.md +1 -0
- package/doc/hierarchy.md +91 -0
- package/doc/instance_wrap.md +408 -0
- package/doc/name.md +29 -0
- package/doc/object.md +6 -2
- package/doc/object_wrap.md +120 -410
- package/doc/promises.md +5 -0
- package/doc/setup.md +1 -1
- package/doc/string.md +4 -0
- package/doc/symbol.md +4 -0
- package/doc/typed_array.md +4 -0
- package/doc/typed_array_of.md +4 -0
- package/doc/value.md +166 -104
- package/index.js +4 -3
- package/napi-inl.h +539 -461
- package/napi.h +134 -119
- package/package.json +15 -1
- package/tools/conversion.js +4 -4
- package/doc/basic_types.md +0 -423
- package/doc/working_with_javascript_values.md +0 -14
package/doc/promises.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Promise
|
|
2
2
|
|
|
3
|
+
Class `Napi::Promise` inherits from class [`Napi::Object`][].
|
|
4
|
+
|
|
3
5
|
The `Napi::Promise` class, along with its `Napi::Promise::Deferred` class, implement the ability to create, resolve, and reject Promise objects.
|
|
4
6
|
|
|
5
7
|
The basic approach is to create a `Napi::Promise::Deferred` object and return to your caller the value returned by the `Napi::Promise::Deferred::Promise` method. For example:
|
|
@@ -72,3 +74,6 @@ void Napi::Promise::Deferred::Reject(napi_value value) const;
|
|
|
72
74
|
Rejects the Promise object held by the `Napi::Promise::Deferred` object.
|
|
73
75
|
|
|
74
76
|
* `[in] value`: The N-API primitive value with which to reject the `Napi::Promise`.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
[`Napi::Object`]: ./object.md
|
package/doc/setup.md
CHANGED
|
@@ -26,7 +26,7 @@ To use **N-API** in a native module:
|
|
|
26
26
|
2. Reference this package's include directory and gyp file in `binding.gyp`:
|
|
27
27
|
|
|
28
28
|
```gyp
|
|
29
|
-
'include_dirs': ["
|
|
29
|
+
'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"],
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
3. Decide whether the package will enable C++ exceptions in the N-API wrapper.
|
package/doc/string.md
CHANGED
package/doc/symbol.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Symbol
|
|
2
2
|
|
|
3
|
+
Class `Napi::Symbol` inherits from class [`Napi::Name`][].
|
|
4
|
+
|
|
3
5
|
## Methods
|
|
4
6
|
|
|
5
7
|
### Constructor
|
|
@@ -42,3 +44,5 @@ static Napi::Symbol Napi::Symbol::WellKnown(napi_env env, const std::string& nam
|
|
|
42
44
|
|
|
43
45
|
Returns a `Napi::Symbol` representing a well-known `Symbol` from the
|
|
44
46
|
`Symbol` registry.
|
|
47
|
+
|
|
48
|
+
[`Napi::Name`]: ./name.md
|
package/doc/typed_array.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# TypedArray
|
|
2
2
|
|
|
3
|
+
Class `Napi::TypedArray` inherits from class [`Napi::Object`][].
|
|
4
|
+
|
|
3
5
|
The `Napi::TypedArray` class corresponds to the
|
|
4
6
|
[JavaScript `TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
|
|
5
7
|
class.
|
|
@@ -72,3 +74,5 @@ size_t Napi::TypedArray::ByteLength() const;
|
|
|
72
74
|
```
|
|
73
75
|
|
|
74
76
|
Returns the length of the array, in bytes.
|
|
77
|
+
|
|
78
|
+
[`Napi::Object`]: ./object.md
|
package/doc/typed_array_of.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# TypedArrayOf
|
|
2
2
|
|
|
3
|
+
Class `Napi::TypedArrayOf<T>` inherits from class [`Napi::TypedArray`][].
|
|
4
|
+
|
|
3
5
|
The `Napi::TypedArrayOf` class corresponds to the various
|
|
4
6
|
[JavaScript `TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
|
|
5
7
|
classes.
|
|
@@ -131,3 +133,5 @@ const T* Napi::TypedArrayOf::Data() const
|
|
|
131
133
|
|
|
132
134
|
Returns a pointer into the backing `Napi::ArrayBuffer` which is offset to point to the
|
|
133
135
|
start of the array.
|
|
136
|
+
|
|
137
|
+
[`Napi::TypedArray`]: ./typed_array.md
|
package/doc/value.md
CHANGED
|
@@ -1,27 +1,13 @@
|
|
|
1
1
|
# Value
|
|
2
2
|
|
|
3
|
-
`Napi::Value` is the C++ manifestation of a JavaScript value.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- [`Napi::Array`](basic_types.md#array)
|
|
10
|
-
- [`Napi::ArrayBuffer`](array_buffer.md)
|
|
11
|
-
- [`Napi::Boolean`](boolean.md)
|
|
12
|
-
- [`Napi::Buffer`](buffer.md)
|
|
13
|
-
- [`Napi::Date`](date.md)
|
|
14
|
-
- [`Napi::External`](external.md)
|
|
15
|
-
- [`Napi::Function`](function.md)
|
|
16
|
-
- [`Napi::Name`](name.md)
|
|
17
|
-
- [`Napi::Number`](number.md)
|
|
18
|
-
- [`Napi::Object`](object.md)
|
|
19
|
-
- [`Napi::String`](string.md)
|
|
20
|
-
- [`Napi::Symbol`](symbol.md)
|
|
21
|
-
- [`Napi::TypedArray`](typed_array.md)
|
|
22
|
-
- [`Napi::TypedArrayOf`](typed_array_of.md)
|
|
3
|
+
`Napi::Value` is the C++ manifestation of a JavaScript value. It is the base
|
|
4
|
+
class upon which other JavaScript values such as `Napi::Number`,
|
|
5
|
+
`Napi::Boolean`, `Napi::String`, and `Napi::Object` are based. It represents a
|
|
6
|
+
JavaScript value of an unknown type. It is a thin wrapper around the N-API
|
|
7
|
+
datatype `napi_value`. Methods on this class can be used to check the JavaScript
|
|
8
|
+
type of the underlying N-API `napi_value` and also to convert to C++ types.
|
|
23
9
|
|
|
24
|
-
##
|
|
10
|
+
## Constructors
|
|
25
11
|
|
|
26
12
|
### Empty Constructor
|
|
27
13
|
|
|
@@ -37,9 +23,10 @@ Creates a new *empty* `Napi::Value` instance.
|
|
|
37
23
|
Napi::Value::Value(napi_env env, napi_value value);
|
|
38
24
|
```
|
|
39
25
|
|
|
40
|
-
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Value`
|
|
41
|
-
|
|
42
|
-
- `[in] value`: The C++ primitive from which to instantiate the `Napi::Value`.
|
|
26
|
+
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Value`
|
|
27
|
+
object.
|
|
28
|
+
- `[in] value`: The C++ primitive from which to instantiate the `Napi::Value`.
|
|
29
|
+
value` may be any of:
|
|
43
30
|
- `bool`
|
|
44
31
|
- Any integer type
|
|
45
32
|
- Any floating point type
|
|
@@ -50,38 +37,25 @@ Napi::Value::Value(napi_env env, napi_value value);
|
|
|
50
37
|
- `Napi::Value`
|
|
51
38
|
- `napi_value`
|
|
52
39
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
```cpp
|
|
56
|
-
template <typename T> static Napi::Value Napi::Value::From(napi_env env, const T& value);
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
- `[in] env`: The `napi_env` environment in which to create the `Napi::Value` object.
|
|
60
|
-
|
|
61
|
-
- `[in] value`: The N-API primitive value from which to create the `Napi::Value` object.
|
|
62
|
-
|
|
63
|
-
Returns a `Napi::Value` object from an N-API primitive value.
|
|
40
|
+
## Operators
|
|
64
41
|
|
|
65
42
|
### operator napi_value
|
|
66
43
|
|
|
67
44
|
```cpp
|
|
68
|
-
operator napi_value() const;
|
|
45
|
+
Napi::Value::operator napi_value() const;
|
|
69
46
|
```
|
|
70
47
|
|
|
71
|
-
Returns
|
|
72
|
-
|
|
73
|
-
Returns `nullptr` if this `Napi::Value` is *empty*.
|
|
48
|
+
Returns the underlying N-API `napi_value`. If the instance is _empty_, this
|
|
49
|
+
returns `nullptr`.
|
|
74
50
|
|
|
75
51
|
### operator ==
|
|
76
52
|
|
|
77
53
|
```cpp
|
|
78
|
-
|
|
79
54
|
bool Napi::Value::operator ==(const Napi::Value& other) const;
|
|
80
55
|
```
|
|
81
56
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
Returns a `bool` indicating if this `Napi::Value` strictly equals another `Napi::Value`.
|
|
57
|
+
Returns `true` if this value strictly equals another value, or `false`
|
|
58
|
+
otherwise.
|
|
85
59
|
|
|
86
60
|
### operator !=
|
|
87
61
|
|
|
@@ -89,18 +63,22 @@ Returns a `bool` indicating if this `Napi::Value` strictly equals another `Napi:
|
|
|
89
63
|
bool Napi::Value::operator !=(const Napi::Value& other) const;
|
|
90
64
|
```
|
|
91
65
|
|
|
92
|
-
|
|
66
|
+
Returns `false` if this value strictly equals another value, or `true`
|
|
67
|
+
otherwise.
|
|
93
68
|
|
|
94
|
-
|
|
69
|
+
## Methods
|
|
95
70
|
|
|
96
|
-
###
|
|
71
|
+
### As
|
|
97
72
|
|
|
98
73
|
```cpp
|
|
99
|
-
|
|
74
|
+
template <typename T> T Napi::Value::As() const;
|
|
100
75
|
```
|
|
101
|
-
- `[in] other`: The `Napi::Value` object to be compared.
|
|
102
76
|
|
|
103
|
-
|
|
77
|
+
Casts to another type of `Napi::Value`, when the actual type is known or
|
|
78
|
+
assumed.
|
|
79
|
+
|
|
80
|
+
This conversion does not coerce the type. Calling any methods inappropriate for
|
|
81
|
+
the actual value type will throw `Napi::Error`.
|
|
104
82
|
|
|
105
83
|
### Env
|
|
106
84
|
|
|
@@ -108,100 +86,141 @@ Returns a `bool` indicating if this `Napi::Value` strictly equals another `Napi:
|
|
|
108
86
|
Napi::Env Napi::Value::Env() const;
|
|
109
87
|
```
|
|
110
88
|
|
|
111
|
-
Returns the `Napi::Env` environment this value is associated with.
|
|
89
|
+
Returns the `Napi::Env` environment this value is associated with. See
|
|
90
|
+
[`Napi::Env`](env.md) for more details about environments.
|
|
112
91
|
|
|
113
|
-
###
|
|
92
|
+
### From
|
|
114
93
|
|
|
115
94
|
```cpp
|
|
116
|
-
|
|
95
|
+
template <typename T>
|
|
96
|
+
static Napi::Value Napi::Value::From(napi_env env, const T& value);
|
|
117
97
|
```
|
|
118
98
|
|
|
119
|
-
|
|
99
|
+
- `[in] env`: The `napi_env` environment in which to create the `Napi::Value`
|
|
100
|
+
object.
|
|
101
|
+
- `[in] value`: The N-API primitive value from which to create the `Napi::Value`
|
|
102
|
+
object.
|
|
120
103
|
|
|
121
|
-
|
|
122
|
-
Note an empty `Napi::Value` is distinct from JavaScript `null` or `undefined`, which are valid values.
|
|
104
|
+
Returns a `Napi::Value` object from an N-API primitive value.
|
|
123
105
|
|
|
124
|
-
|
|
106
|
+
This method is used to convert from a C++ type to a JavaScript value.
|
|
107
|
+
Here, `value` may be any of:
|
|
108
|
+
- `bool` - returns a `Napi::Boolean`.
|
|
109
|
+
- Any integer type - returns a `Napi::Number`.
|
|
110
|
+
- Any floating point type - returns a `Napi::Number`.
|
|
111
|
+
- `const char*` (encoded using UTF-8, null-terminated) - returns a
|
|
112
|
+
`Napi::String`.
|
|
113
|
+
- `const char16_t*` (encoded using UTF-16-LE, null-terminated) - returns a
|
|
114
|
+
`Napi::String`.
|
|
115
|
+
- `std::string` (encoded using UTF-8) - returns a `Napi::String`.
|
|
116
|
+
- `std::u16string` - returns a `Napi::String`.
|
|
117
|
+
- `Napi::Value` - returns a `Napi::Value`.
|
|
118
|
+
- `Napi_value` - returns a `Napi::Value`.
|
|
125
119
|
|
|
126
|
-
###
|
|
120
|
+
### IsArray
|
|
127
121
|
|
|
128
122
|
```cpp
|
|
129
|
-
|
|
123
|
+
bool Napi::Value::IsArray() const;
|
|
130
124
|
```
|
|
131
125
|
|
|
132
|
-
Returns
|
|
126
|
+
Returns `true` if the underlying value is a JavaScript `Napi::Array` or `false`
|
|
127
|
+
otherwise.
|
|
133
128
|
|
|
134
|
-
###
|
|
129
|
+
### IsArrayBuffer
|
|
135
130
|
|
|
136
131
|
```cpp
|
|
137
|
-
bool Napi::Value::
|
|
132
|
+
bool Napi::Value::IsArrayBuffer() const;
|
|
138
133
|
```
|
|
139
134
|
|
|
140
|
-
Returns
|
|
135
|
+
Returns `true` if the underlying value is a JavaScript `Napi::ArrayBuffer` or
|
|
136
|
+
`false` otherwise.
|
|
141
137
|
|
|
142
|
-
###
|
|
138
|
+
### IsBoolean
|
|
143
139
|
|
|
144
140
|
```cpp
|
|
145
|
-
bool Napi::Value::
|
|
141
|
+
bool Napi::Value::IsBoolean() const;
|
|
146
142
|
```
|
|
147
143
|
|
|
148
|
-
Returns
|
|
144
|
+
Returns `true` if the underlying value is a JavaScript `true` or JavaScript
|
|
145
|
+
`false`, or `false` if the value is not a `Napi::Boolean` value in JavaScript.
|
|
149
146
|
|
|
150
|
-
###
|
|
147
|
+
### IsBuffer
|
|
151
148
|
|
|
152
149
|
```cpp
|
|
153
|
-
bool Napi::Value::
|
|
150
|
+
bool Napi::Value::IsBuffer() const;
|
|
154
151
|
```
|
|
155
152
|
|
|
156
|
-
Returns
|
|
153
|
+
Returns `true` if the underlying value is a Node.js `Napi::Buffer` or `false`
|
|
154
|
+
otherwise.
|
|
157
155
|
|
|
158
|
-
###
|
|
156
|
+
### IsDataView
|
|
157
|
+
```cpp
|
|
158
|
+
bool Napi::Value::IsDataView() const;
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Returns `true` if the underlying value is a JavaScript `Napi::DataView` or
|
|
162
|
+
`false` otherwise.
|
|
163
|
+
|
|
164
|
+
### IsDate
|
|
159
165
|
|
|
160
166
|
```cpp
|
|
161
|
-
bool Napi::Value::
|
|
167
|
+
bool Napi::Value::IsDate() const;
|
|
162
168
|
```
|
|
163
169
|
|
|
164
|
-
Returns
|
|
170
|
+
Returns `true` if the underlying value is a JavaScript `Date` or `false`
|
|
171
|
+
otherwise.
|
|
165
172
|
|
|
166
|
-
###
|
|
173
|
+
### IsEmpty
|
|
167
174
|
|
|
168
175
|
```cpp
|
|
169
|
-
bool Napi::Value::
|
|
176
|
+
bool Napi::Value::IsEmpty() const;
|
|
170
177
|
```
|
|
171
178
|
|
|
172
|
-
Returns
|
|
179
|
+
Returns `true` if the value is uninitialized.
|
|
173
180
|
|
|
174
|
-
|
|
181
|
+
An empty `Napi::Value` is invalid, and most attempts to perform an operation on
|
|
182
|
+
an empty `Napi::Value` will result in an exception. An empty `Napi::Value` is
|
|
183
|
+
distinct from JavaScript `null` or `undefined`, which are valid values.
|
|
184
|
+
|
|
185
|
+
When C++ exceptions are disabled at compile time, a method with a `Napi::Value`
|
|
186
|
+
return type may return an empty `Napi::Value` to indicate a pending exception.
|
|
187
|
+
Thus, when C++ exceptions are not being used, callers should check the result of
|
|
188
|
+
`Env::IsExceptionPending` before attempting to use the value.
|
|
175
189
|
|
|
190
|
+
### IsExternal
|
|
176
191
|
```cpp
|
|
177
|
-
bool Napi::Value::
|
|
192
|
+
bool Napi::Value::IsExternal() const;
|
|
178
193
|
```
|
|
179
194
|
|
|
180
|
-
Returns
|
|
195
|
+
Returns `true` if the underlying value is a N-API external object or `false`
|
|
196
|
+
otherwise.
|
|
181
197
|
|
|
182
|
-
###
|
|
198
|
+
### IsFunction
|
|
183
199
|
|
|
184
200
|
```cpp
|
|
185
|
-
bool Napi::Value::
|
|
201
|
+
bool Napi::Value::IsFunction() const;
|
|
186
202
|
```
|
|
187
203
|
|
|
188
|
-
Returns
|
|
204
|
+
Returns `true` if the underlying value is a JavaScript `Napi::Function` or
|
|
205
|
+
`false` otherwise.
|
|
189
206
|
|
|
190
|
-
###
|
|
207
|
+
### IsNull
|
|
191
208
|
|
|
192
209
|
```cpp
|
|
193
|
-
bool Napi::Value::
|
|
210
|
+
bool Napi::Value::IsNull() const;
|
|
194
211
|
```
|
|
195
212
|
|
|
196
|
-
Returns
|
|
213
|
+
Returns `true` if the underlying value is a JavaScript `null` or `false`
|
|
214
|
+
otherwise.
|
|
197
215
|
|
|
198
|
-
###
|
|
216
|
+
### IsNumber
|
|
199
217
|
|
|
200
218
|
```cpp
|
|
201
|
-
bool Napi::Value::
|
|
219
|
+
bool Napi::Value::IsNumber() const;
|
|
202
220
|
```
|
|
203
221
|
|
|
204
|
-
Returns
|
|
222
|
+
Returns `true` if the underlying value is a JavaScript `Napi::Number` or `false`
|
|
223
|
+
otherwise.
|
|
205
224
|
|
|
206
225
|
### IsObject
|
|
207
226
|
|
|
@@ -209,41 +228,63 @@ Returns a `bool` indicating if this `Napi::Value` is a JavaScript typed array.
|
|
|
209
228
|
bool Napi::Value::IsObject() const;
|
|
210
229
|
```
|
|
211
230
|
|
|
212
|
-
Returns
|
|
231
|
+
Returns `true` if the underlying value is a JavaScript `Napi::Object` or `false`
|
|
232
|
+
otherwise.
|
|
213
233
|
|
|
214
|
-
###
|
|
234
|
+
### IsPromise
|
|
215
235
|
|
|
216
236
|
```cpp
|
|
217
|
-
bool Napi::Value::
|
|
237
|
+
bool Napi::Value::IsPromise() const;
|
|
218
238
|
```
|
|
219
239
|
|
|
220
|
-
Returns
|
|
240
|
+
Returns `true` if the underlying value is a JavaScript `Napi::Promise` or
|
|
241
|
+
`false` otherwise.
|
|
221
242
|
|
|
222
|
-
###
|
|
243
|
+
### IsString
|
|
223
244
|
|
|
224
245
|
```cpp
|
|
225
|
-
bool Napi::Value::
|
|
246
|
+
bool Napi::Value::IsString() const;
|
|
226
247
|
```
|
|
227
248
|
|
|
228
|
-
Returns
|
|
249
|
+
Returns `true` if the underlying value is a JavaScript `Napi::String` or `false`
|
|
250
|
+
otherwise.
|
|
229
251
|
|
|
230
|
-
###
|
|
252
|
+
### IsSymbol
|
|
231
253
|
|
|
232
254
|
```cpp
|
|
233
|
-
bool Napi::Value::
|
|
255
|
+
bool Napi::Value::IsSymbol() const;
|
|
234
256
|
```
|
|
235
257
|
|
|
236
|
-
Returns
|
|
258
|
+
Returns `true` if the underlying value is a JavaScript `Napi::Symbol` or `false`
|
|
259
|
+
otherwise.
|
|
237
260
|
|
|
238
|
-
###
|
|
261
|
+
### IsTypedArray
|
|
239
262
|
|
|
240
263
|
```cpp
|
|
241
|
-
|
|
264
|
+
bool Napi::Value::IsTypedArray() const;
|
|
242
265
|
```
|
|
243
266
|
|
|
244
|
-
|
|
267
|
+
Returns `true` if the underlying value is a JavaScript `Napi::TypedArray` or
|
|
268
|
+
`false` otherwise.
|
|
245
269
|
|
|
246
|
-
|
|
270
|
+
### IsUndefined
|
|
271
|
+
|
|
272
|
+
```cpp
|
|
273
|
+
bool Napi::Value::IsUndefined() const;
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Returns `true` if the underlying value is a JavaScript `undefined` or `false`
|
|
277
|
+
otherwise.
|
|
278
|
+
|
|
279
|
+
### StrictEquals
|
|
280
|
+
|
|
281
|
+
```cpp
|
|
282
|
+
bool Napi::Value::StrictEquals(const Napi::Value& other) const;
|
|
283
|
+
```
|
|
284
|
+
- `[in] other`: The `Napi::Value` object to be compared.
|
|
285
|
+
|
|
286
|
+
Returns a `bool` indicating if this `Napi::Value` strictly equals another
|
|
287
|
+
`Napi::Value`.
|
|
247
288
|
|
|
248
289
|
### ToBoolean
|
|
249
290
|
|
|
@@ -251,7 +292,12 @@ This conversion does not coerce the type. Calling any methods inappropriate for
|
|
|
251
292
|
Napi::Boolean Napi::Value::ToBoolean() const;
|
|
252
293
|
```
|
|
253
294
|
|
|
254
|
-
Returns
|
|
295
|
+
Returns a `Napi::Boolean` representing the `Napi::Value`.
|
|
296
|
+
|
|
297
|
+
This is a wrapper around `napi_coerce_to_boolean`. This will throw a JavaScript
|
|
298
|
+
exception if the coercion fails. If C++ exceptions are not being used, callers
|
|
299
|
+
should check the result of `Env::IsExceptionPending` before attempting to use
|
|
300
|
+
the returned value.
|
|
255
301
|
|
|
256
302
|
### ToNumber
|
|
257
303
|
|
|
@@ -261,6 +307,14 @@ Napi::Number Napi::Value::ToNumber() const;
|
|
|
261
307
|
|
|
262
308
|
Returns the `Napi::Value` coerced to a JavaScript number.
|
|
263
309
|
|
|
310
|
+
### ToObject
|
|
311
|
+
|
|
312
|
+
```cpp
|
|
313
|
+
Napi::Object Napi::Value::ToObject() const;
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Returns the `Napi::Value` coerced to a JavaScript object.
|
|
317
|
+
|
|
264
318
|
### ToString
|
|
265
319
|
|
|
266
320
|
```cpp
|
|
@@ -269,10 +323,18 @@ Napi::String Napi::Value::ToString() const;
|
|
|
269
323
|
|
|
270
324
|
Returns the `Napi::Value` coerced to a JavaScript string.
|
|
271
325
|
|
|
272
|
-
###
|
|
326
|
+
### Type
|
|
273
327
|
|
|
274
328
|
```cpp
|
|
275
|
-
|
|
329
|
+
napi_valuetype Napi::Value::Type() const;
|
|
276
330
|
```
|
|
277
331
|
|
|
278
|
-
Returns the `
|
|
332
|
+
Returns the `napi_valuetype` type of the `Napi::Value`.
|
|
333
|
+
|
|
334
|
+
[`Napi::Boolean`]: ./boolean.md
|
|
335
|
+
[`Napi::BigInt`]: ./bigint.md
|
|
336
|
+
[`Napi::Date`]: ./date.md
|
|
337
|
+
[`Napi::External`]: ./external.md
|
|
338
|
+
[`Napi::Name`]: ./name.md
|
|
339
|
+
[`Napi::Number`]: ./number.md
|
|
340
|
+
[`Napi::Object`]: ./object.md
|
package/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const include_dir = path.relative('.', __dirname);
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
|
-
include:
|
|
7
|
-
|
|
6
|
+
include: `"${__dirname}"`, // deprecated, can be removed as part of 4.0.0
|
|
7
|
+
include_dir,
|
|
8
|
+
gyp: path.join(include_dir, 'node_api.gyp:nothing'),
|
|
8
9
|
isNodeApiBuiltin: true,
|
|
9
10
|
needsFlag: false
|
|
10
11
|
};
|