node-addon-api 2.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/.travis.yml +1 -4
- package/CHANGELOG.md +172 -10
- package/README.md +81 -30
- 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 +4 -0
- package/doc/async_worker.md +33 -4
- package/doc/{async_progress_worker.md → async_worker_variants.md} +115 -3
- package/doc/bigint.md +7 -2
- package/doc/boolean.md +4 -0
- package/doc/buffer.md +4 -0
- package/doc/class_property_descriptor.md +3 -3
- package/doc/creating_a_release.md +5 -5
- 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/external.md +4 -0
- package/doc/function.md +109 -1
- package/doc/hierarchy.md +91 -0
- package/doc/instance_wrap.md +408 -0
- package/doc/name.md +29 -0
- package/doc/object.md +44 -1
- package/doc/object_lifetime_management.md +1 -1
- package/doc/object_wrap.md +219 -215
- package/doc/promises.md +5 -0
- package/doc/property_descriptor.md +64 -9
- package/doc/setup.md +1 -2
- package/doc/string.md +5 -1
- package/doc/symbol.md +5 -1
- package/doc/typed_array.md +4 -0
- package/doc/typed_array_of.md +4 -0
- package/doc/value.md +166 -104
- package/except.gypi +16 -0
- package/index.js +7 -41
- package/napi-inl.h +1116 -400
- package/napi.h +414 -142
- package/node_api.gyp +9 -0
- package/noexcept.gypi +16 -0
- package/{src/nothing.c → nothing.c} +0 -0
- package/package.json +63 -1
- package/tools/README.md +4 -4
- package/tools/conversion.js +4 -8
- 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/node_api.gyp
ADDED
package/noexcept.gypi
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
|
|
3
|
+
'cflags': [ '-fno-exceptions' ],
|
|
4
|
+
'cflags_cc': [ '-fno-exceptions' ],
|
|
5
|
+
'msvs_settings': {
|
|
6
|
+
'VCCLCompilerTool': {
|
|
7
|
+
'ExceptionHandling': 0,
|
|
8
|
+
'EnablePREfast': 'true',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
'xcode_settings': {
|
|
12
|
+
'CLANG_CXX_LIBRARY': 'libc++',
|
|
13
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.7',
|
|
14
|
+
'GCC_ENABLE_CPP_EXCEPTIONS': 'NO',
|
|
15
|
+
},
|
|
16
|
+
}
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"name": "Alba Mendez",
|
|
12
12
|
"url": "https://github.com/jmendeth"
|
|
13
13
|
},
|
|
14
|
+
{
|
|
15
|
+
"name": "András Timár, Dr",
|
|
16
|
+
"url": "https://github.com/timarandras"
|
|
17
|
+
},
|
|
14
18
|
{
|
|
15
19
|
"name": "Andrew Petersen",
|
|
16
20
|
"url": "https://github.com/kirbysayshi"
|
|
@@ -31,6 +35,10 @@
|
|
|
31
35
|
"name": "Arunesh Chandra",
|
|
32
36
|
"url": "https://github.com/aruneshchandra"
|
|
33
37
|
},
|
|
38
|
+
{
|
|
39
|
+
"name": "Azlan Mukhtar",
|
|
40
|
+
"url": "https://github.com/azlan"
|
|
41
|
+
},
|
|
34
42
|
{
|
|
35
43
|
"name": "Ben Berman",
|
|
36
44
|
"url": "https://github.com/rivertam"
|
|
@@ -51,10 +59,18 @@
|
|
|
51
59
|
"name": "Cory Mickelson",
|
|
52
60
|
"url": "https://github.com/corymickelson"
|
|
53
61
|
},
|
|
62
|
+
{
|
|
63
|
+
"name": "Daniel Bevenius",
|
|
64
|
+
"url": "https://github.com/danbev"
|
|
65
|
+
},
|
|
54
66
|
{
|
|
55
67
|
"name": "David Halls",
|
|
56
68
|
"url": "https://github.com/davedoesdev"
|
|
57
69
|
},
|
|
70
|
+
{
|
|
71
|
+
"name": "Dmitry Ashkadov",
|
|
72
|
+
"url": "https://github.com/dmitryash"
|
|
73
|
+
},
|
|
58
74
|
{
|
|
59
75
|
"name": "Dongjin Na",
|
|
60
76
|
"url": "https://github.com/nadongguri"
|
|
@@ -67,6 +83,10 @@
|
|
|
67
83
|
"name": "Gabriel Schulhof",
|
|
68
84
|
"url": "https://github.com/gabrielschulhof"
|
|
69
85
|
},
|
|
86
|
+
{
|
|
87
|
+
"name": "Guenter Sandner",
|
|
88
|
+
"url": "https://github.com/gms1"
|
|
89
|
+
},
|
|
70
90
|
{
|
|
71
91
|
"name": "Gus Caplan",
|
|
72
92
|
"url": "https://github.com/devsnek"
|
|
@@ -75,6 +95,10 @@
|
|
|
75
95
|
"name": "Hitesh Kanwathirtha",
|
|
76
96
|
"url": "https://github.com/digitalinfinity"
|
|
77
97
|
},
|
|
98
|
+
{
|
|
99
|
+
"name": "ikokostya",
|
|
100
|
+
"url": "https://github.com/ikokostya"
|
|
101
|
+
},
|
|
78
102
|
{
|
|
79
103
|
"name": "Jake Barnes",
|
|
80
104
|
"url": "https://github.com/DuBistKomisch"
|
|
@@ -87,6 +111,10 @@
|
|
|
87
111
|
"name": "Jason Ginchereau",
|
|
88
112
|
"url": "https://github.com/jasongin"
|
|
89
113
|
},
|
|
114
|
+
{
|
|
115
|
+
"name": "Jeroen Janssen",
|
|
116
|
+
"url": "https://github.com/japj"
|
|
117
|
+
},
|
|
90
118
|
{
|
|
91
119
|
"name": "Jim Schlight",
|
|
92
120
|
"url": "https://github.com/jschlight"
|
|
@@ -99,10 +127,22 @@
|
|
|
99
127
|
"name": "joshgarde",
|
|
100
128
|
"url": "https://github.com/joshgarde"
|
|
101
129
|
},
|
|
130
|
+
{
|
|
131
|
+
"name": "Kasumi Hanazuki",
|
|
132
|
+
"url": "https://github.com/hanazuki"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"name": "Kelvin",
|
|
136
|
+
"url": "https://github.com/kelvinhammond"
|
|
137
|
+
},
|
|
102
138
|
{
|
|
103
139
|
"name": "Kevin Eady",
|
|
104
140
|
"url": "https://github.com/KevinEady"
|
|
105
141
|
},
|
|
142
|
+
{
|
|
143
|
+
"name": "Koki Nishihara",
|
|
144
|
+
"url": "https://github.com/Nishikoh"
|
|
145
|
+
},
|
|
106
146
|
{
|
|
107
147
|
"name": "Konstantin Tarkus",
|
|
108
148
|
"url": "https://github.com/koistya"
|
|
@@ -115,6 +155,10 @@
|
|
|
115
155
|
"name": "legendecas",
|
|
116
156
|
"url": "https://github.com/legendecas"
|
|
117
157
|
},
|
|
158
|
+
{
|
|
159
|
+
"name": "Lovell Fuller",
|
|
160
|
+
"url": "https://github.com/lovell"
|
|
161
|
+
},
|
|
118
162
|
{
|
|
119
163
|
"name": "Luciano Martorella",
|
|
120
164
|
"url": "https://github.com/lmartorella"
|
|
@@ -155,6 +199,10 @@
|
|
|
155
199
|
"name": "Nurbol Alpysbayev",
|
|
156
200
|
"url": "https://github.com/anurbol"
|
|
157
201
|
},
|
|
202
|
+
{
|
|
203
|
+
"name": "pacop",
|
|
204
|
+
"url": "https://github.com/pacop"
|
|
205
|
+
},
|
|
158
206
|
{
|
|
159
207
|
"name": "Philipp Renoth",
|
|
160
208
|
"url": "https://github.com/DaAitch"
|
|
@@ -199,17 +247,29 @@
|
|
|
199
247
|
"name": "Tux3",
|
|
200
248
|
"url": "https://github.com/tux3"
|
|
201
249
|
},
|
|
250
|
+
{
|
|
251
|
+
"name": "Vlad Velmisov",
|
|
252
|
+
"url": "https://github.com/Velmisov"
|
|
253
|
+
},
|
|
202
254
|
{
|
|
203
255
|
"name": "Yohei Kishimoto",
|
|
204
256
|
"url": "https://github.com/morokosi"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"name": "Yulong Wang",
|
|
260
|
+
"url": "https://github.com/fs-eire"
|
|
205
261
|
}
|
|
206
262
|
],
|
|
207
263
|
"dependencies": {},
|
|
208
264
|
"description": "Node.js API (N-API)",
|
|
209
265
|
"devDependencies": {
|
|
266
|
+
"benchmark": "^2.1.4",
|
|
267
|
+
"fs-extra": "^9.0.1",
|
|
268
|
+
"bindings": "^1.5.0",
|
|
210
269
|
"safe-buffer": "^5.1.1"
|
|
211
270
|
},
|
|
212
271
|
"directories": {},
|
|
272
|
+
"gypfile": false,
|
|
213
273
|
"homepage": "https://github.com/nodejs/node-addon-api",
|
|
214
274
|
"keywords": [
|
|
215
275
|
"n-api",
|
|
@@ -232,6 +292,8 @@
|
|
|
232
292
|
"url": "git://github.com/nodejs/node-addon-api.git"
|
|
233
293
|
},
|
|
234
294
|
"scripts": {
|
|
295
|
+
"prebenchmark": "node-gyp rebuild -C benchmark",
|
|
296
|
+
"benchmark": "node benchmark",
|
|
235
297
|
"pretest": "node-gyp rebuild -C test",
|
|
236
298
|
"test": "node test",
|
|
237
299
|
"predev": "node-gyp rebuild -C test --debug",
|
|
@@ -240,5 +302,5 @@
|
|
|
240
302
|
"dev:incremental": "node test",
|
|
241
303
|
"doc": "doxygen doc/Doxyfile"
|
|
242
304
|
},
|
|
243
|
-
"version": "
|
|
305
|
+
"version": "3.0.2"
|
|
244
306
|
}
|
package/tools/README.md
CHANGED
|
@@ -49,10 +49,10 @@ Napi::FunctionReference constructor;
|
|
|
49
49
|
void [ClassName]::Init(Napi::Env env, Napi::Object exports, Napi::Object module) {
|
|
50
50
|
Napi::HandleScope scope(env);
|
|
51
51
|
Napi::Function ctor = DefineClass(env, "Canvas", {
|
|
52
|
-
InstanceMethod
|
|
53
|
-
InstanceMethod
|
|
54
|
-
InstanceAccessor
|
|
55
|
-
StaticMethod
|
|
52
|
+
InstanceMethod<&[ClassName]::Func1>("Func1"),
|
|
53
|
+
InstanceMethod<&[ClassName]::Func2>("Func2"),
|
|
54
|
+
InstanceAccessor<&[ClassName]::ValueGetter>("Value"),
|
|
55
|
+
StaticMethod<&[ClassName]::StaticMethod>("MethodName"),
|
|
56
56
|
InstanceValue("Value", Napi::[Type]::New(env, value)),
|
|
57
57
|
});
|
|
58
58
|
|
package/tools/conversion.js
CHANGED
|
@@ -22,10 +22,8 @@ if (disable != "--disable" && dir != "--disable") {
|
|
|
22
22
|
[ /[ ]*"nan": *"[^"]+"(,|)[\n\r]/g, '' ]
|
|
23
23
|
],
|
|
24
24
|
'binding.gyp': [
|
|
25
|
-
[ /([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'
|
|
26
|
-
[ /([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "
|
|
27
|
-
[ /([ ]*)'dependencies': \[/g, '$1\'dependencies\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').gyp")\','],
|
|
28
|
-
[ /([ ]*)"dependencies": \[/g, '$1"dependencies": [\n$1 "<!(node -p \'require(\\\"node-addon-api\\\").gyp\')",'],
|
|
25
|
+
[ /([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').include_dir")\',' ],
|
|
26
|
+
[ /([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!(node -p \\"require(\'node-addon-api\').include_dir\\")",' ],
|
|
29
27
|
[ /[ ]*("|')<!\(node -e ("|'|\\"|\\')require\(("|'|\\"|\\')nan("|'|\\"|\\')\)("|'|\\"|\\')\)("|')(,|)[\r\n]/g, '' ],
|
|
30
28
|
[ /([ ]*)("|')target_name("|'): ("|')(.+?)("|'),/g, '$1$2target_name$2: $4$5$6,\n $2cflags!$2: [ $2-fno-exceptions$2 ],\n $2cflags_cc!$2: [ $2-fno-exceptions$2 ],\n $2xcode_settings$2: { $2GCC_ENABLE_CPP_EXCEPTIONS$2: $2YES$2,\n $2CLANG_CXX_LIBRARY$2: $2libc++$2,\n $2MACOSX_DEPLOYMENT_TARGET$2: $210.7$2,\n },\n $2msvs_settings$2: {\n $2VCCLCompilerTool$2: { $2ExceptionHandling$2: 1 },\n },' ],
|
|
31
29
|
]
|
|
@@ -37,10 +35,8 @@ if (disable != "--disable" && dir != "--disable") {
|
|
|
37
35
|
[ /[ ]*"nan": *"[^"]+"(,|)[\n\r]/g, '' ]
|
|
38
36
|
],
|
|
39
37
|
'binding.gyp': [
|
|
40
|
-
[ /([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'
|
|
41
|
-
[ /([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "
|
|
42
|
-
[ /([ ]*)'dependencies': \[/g, '$1\'dependencies\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').gyp")\','],
|
|
43
|
-
[ /([ ]*)"dependencies": \[/g, '$1"dependencies": [\n$1 "<!(node -p \'require(\\\"node-addon-api\\\").gyp\')",'],
|
|
38
|
+
[ /([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').include_dir")\',' ],
|
|
39
|
+
[ /([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!(node -p \'require(\\\"node-addon-api\\\").include_dir\')",' ],
|
|
44
40
|
[ /[ ]*("|')<!\(node -e ("|'|\\"|\\')require\(("|'|\\"|\\')nan("|'|\\"|\\')\)("|'|\\"|\\')\)("|')(,|)[\r\n]/g, '' ],
|
|
45
41
|
[ /([ ]*)("|')target_name("|'): ("|')(.+?)("|'),/g, '$1$2target_name$2: $4$5$6,\n $2cflags!$2: [ $2-fno-exceptions$2 ],\n $2cflags_cc!$2: [ $2-fno-exceptions$2 ],\n $2defines$2: [ $2NAPI_DISABLE_CPP_EXCEPTIONS$2 ],\n $2conditions$2: [\n [\'OS==\"win\"\', { $2defines$2: [ $2_HAS_EXCEPTIONS=1$2 ] }]\n ]' ],
|
|
46
42
|
]
|
package/doc/basic_types.md
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
# Basic Types
|
|
2
|
-
|
|
3
|
-
Node Addon API consists of a few fundamental data types. These allow a user of
|
|
4
|
-
the API to create, convert and introspect fundamental JavaScript types, and
|
|
5
|
-
interoperate with their C++ counterparts.
|
|
6
|
-
|
|
7
|
-
## Value
|
|
8
|
-
|
|
9
|
-
`Napi::Value` is the base class of Node Addon API's fundamental object type hierarchy.
|
|
10
|
-
It represents a JavaScript value of an unknown type. It is a thin wrapper around
|
|
11
|
-
the N-API datatype `napi_value`. Methods on this class can be used to check
|
|
12
|
-
the JavaScript type of the underlying N-API `napi_value` and also to convert to
|
|
13
|
-
C++ types.
|
|
14
|
-
|
|
15
|
-
### Constructor
|
|
16
|
-
|
|
17
|
-
```cpp
|
|
18
|
-
Napi::Value::Value();
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Used to create a Node Addon API `Napi::Value` that represents an **empty** value.
|
|
22
|
-
|
|
23
|
-
```cpp
|
|
24
|
-
Napi::Value::Value(napi_env env, napi_value value);
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
- `[in] env` - The `napi_env` environment in which to construct the `Napi::Value`
|
|
28
|
-
object.
|
|
29
|
-
- `[in] value` - The underlying JavaScript value that the `Napi::Value` instance
|
|
30
|
-
represents.
|
|
31
|
-
|
|
32
|
-
Returns a Node.js Addon API `Napi::Value` that represents the `napi_value` passed
|
|
33
|
-
in.
|
|
34
|
-
|
|
35
|
-
### Operators
|
|
36
|
-
|
|
37
|
-
#### operator napi_value
|
|
38
|
-
|
|
39
|
-
```cpp
|
|
40
|
-
Napi::Value::operator napi_value() const;
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Returns the underlying N-API `napi_value`. If the instance is _empty_, this
|
|
44
|
-
returns `nullptr`.
|
|
45
|
-
|
|
46
|
-
#### operator ==
|
|
47
|
-
|
|
48
|
-
```cpp
|
|
49
|
-
bool Napi::Value::operator ==(const Value& other) const;
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Returns `true` if this value strictly equals another value, or `false` otherwise.
|
|
53
|
-
|
|
54
|
-
#### operator !=
|
|
55
|
-
|
|
56
|
-
```cpp
|
|
57
|
-
bool Napi::Value::operator !=(const Value& other) const;
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Returns `false` if this value strictly equals another value, or `true` otherwise.
|
|
61
|
-
|
|
62
|
-
### Methods
|
|
63
|
-
|
|
64
|
-
#### From
|
|
65
|
-
```cpp
|
|
66
|
-
template <typename T>
|
|
67
|
-
static Napi::Value Napi::Value::From(napi_env env, const T& value);
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
- `[in] env` - The `napi_env` environment in which to construct the `Napi::Value` object.
|
|
71
|
-
- `[in] value` - The C++ type to represent in JavaScript.
|
|
72
|
-
|
|
73
|
-
Returns a `Napi::Value` representing the input C++ type in JavaScript.
|
|
74
|
-
|
|
75
|
-
This method is used to convert from a C++ type to a JavaScript value.
|
|
76
|
-
Here, `value` may be any of:
|
|
77
|
-
- `bool` - returns a `Napi::Boolean`.
|
|
78
|
-
- Any integer type - returns a `Napi::Number`.
|
|
79
|
-
- Any floating point type - returns a `Napi::Number`.
|
|
80
|
-
- `const char*` (encoded using UTF-8, null-terminated) - returns a `Napi::String`.
|
|
81
|
-
- `const char16_t*` (encoded using UTF-16-LE, null-terminated) - returns a `Napi::String`.
|
|
82
|
-
- `std::string` (encoded using UTF-8) - returns a `Napi::String`.
|
|
83
|
-
- `std::u16string` - returns a `Napi::String`.
|
|
84
|
-
- `napi::Value` - returns a `Napi::Value`.
|
|
85
|
-
- `napi_value` - returns a `Napi::Value`.
|
|
86
|
-
|
|
87
|
-
#### As
|
|
88
|
-
```cpp
|
|
89
|
-
template <typename T> T Napi::Value::As() const;
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Returns the `Napi::Value` cast to a desired C++ type.
|
|
93
|
-
|
|
94
|
-
Use this when the actual type is known or assumed.
|
|
95
|
-
|
|
96
|
-
Note:
|
|
97
|
-
This conversion does NOT coerce the type. Calling any methods inappropriate for
|
|
98
|
-
the actual value type will throw `Napi::Error`.
|
|
99
|
-
|
|
100
|
-
#### StrictEquals
|
|
101
|
-
```cpp
|
|
102
|
-
bool Napi::Value::StrictEquals(const Value& other) const;
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
- `[in] other` - The value to compare against.
|
|
106
|
-
|
|
107
|
-
Returns true if the other `Napi::Value` is strictly equal to this one.
|
|
108
|
-
|
|
109
|
-
#### Env
|
|
110
|
-
```cpp
|
|
111
|
-
Napi::Env Napi::Value::Env() const;
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Returns the environment that the value is associated with. See
|
|
115
|
-
[`Napi::Env`](env.md) for more details about environments.
|
|
116
|
-
|
|
117
|
-
#### IsEmpty
|
|
118
|
-
```cpp
|
|
119
|
-
bool Napi::Value::IsEmpty() const;
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Returns `true` if the value is uninitialized.
|
|
123
|
-
|
|
124
|
-
An empty value is invalid, and most attempts to perform an operation on an
|
|
125
|
-
empty value will result in an exception. An empty value is distinct from
|
|
126
|
-
JavaScript `null` or `undefined`, which are valid values.
|
|
127
|
-
|
|
128
|
-
When C++ exceptions are disabled at compile time, a method with a `Napi::Value`
|
|
129
|
-
return type may return an empty value to indicate a pending exception. If C++
|
|
130
|
-
exceptions are not being used, callers should check the result of
|
|
131
|
-
`Env::IsExceptionPending` before attempting to use the value.
|
|
132
|
-
|
|
133
|
-
#### Type
|
|
134
|
-
```cpp
|
|
135
|
-
napi_valuetype Napi::Value::Type() const;
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
Returns the underlying N-API `napi_valuetype` of the value.
|
|
139
|
-
|
|
140
|
-
#### IsUndefined
|
|
141
|
-
```cpp
|
|
142
|
-
bool Napi::Value::IsUndefined() const;
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
Returns `true` if the underlying value is a JavaScript `undefined` or `false`
|
|
146
|
-
otherwise.
|
|
147
|
-
|
|
148
|
-
#### IsNull
|
|
149
|
-
```cpp
|
|
150
|
-
bool Napi::Value::IsNull() const;
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
Returns `true` if the underlying value is a JavaScript `null` or `false`
|
|
154
|
-
otherwise.
|
|
155
|
-
|
|
156
|
-
#### IsBoolean
|
|
157
|
-
```cpp
|
|
158
|
-
bool Napi::Value::IsBoolean() const;
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Returns `true` if the underlying value is a JavaScript `true` or JavaScript
|
|
162
|
-
`false`, or `false` if the value is not a `Napi::Boolean` value in JavaScript.
|
|
163
|
-
|
|
164
|
-
#### IsNumber
|
|
165
|
-
```cpp
|
|
166
|
-
bool Napi::Value::IsNumber() const;
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
Returns `true` if the underlying value is a JavaScript `Napi::Number` or `false`
|
|
170
|
-
otherwise.
|
|
171
|
-
|
|
172
|
-
#### IsString
|
|
173
|
-
```cpp
|
|
174
|
-
bool Napi::Value::IsString() const;
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
Returns `true` if the underlying value is a JavaScript `Napi::String` or `false`
|
|
178
|
-
otherwise.
|
|
179
|
-
|
|
180
|
-
#### IsSymbol
|
|
181
|
-
```cpp
|
|
182
|
-
bool Napi::Value::IsSymbol() const;
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
Returns `true` if the underlying value is a JavaScript `Napi::Symbol` or `false`
|
|
186
|
-
otherwise.
|
|
187
|
-
|
|
188
|
-
#### IsArray
|
|
189
|
-
```cpp
|
|
190
|
-
bool Napi::Value::IsArray() const;
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
Returns `true` if the underlying value is a JavaScript `Napi::Array` or `false`
|
|
194
|
-
otherwise.
|
|
195
|
-
|
|
196
|
-
#### IsArrayBuffer
|
|
197
|
-
```cpp
|
|
198
|
-
bool Napi::Value::IsArrayBuffer() const;
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
Returns `true` if the underlying value is a JavaScript `Napi::ArrayBuffer` or `false`
|
|
202
|
-
otherwise.
|
|
203
|
-
|
|
204
|
-
#### IsTypedArray
|
|
205
|
-
```cpp
|
|
206
|
-
bool Napi::Value::IsTypedArray() const;
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
Returns `true` if the underlying value is a JavaScript `Napi::TypedArray` or `false`
|
|
210
|
-
otherwise.
|
|
211
|
-
|
|
212
|
-
#### IsObject
|
|
213
|
-
```cpp
|
|
214
|
-
bool Napi::Value::IsObject() const;
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
Returns `true` if the underlying value is a JavaScript `Napi::Object` or `false`
|
|
218
|
-
otherwise.
|
|
219
|
-
|
|
220
|
-
#### IsFunction
|
|
221
|
-
```cpp
|
|
222
|
-
bool Napi::Value::IsFunction() const;
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
Returns `true` if the underlying value is a JavaScript `Napi::Function` or `false`
|
|
226
|
-
otherwise.
|
|
227
|
-
|
|
228
|
-
#### IsPromise
|
|
229
|
-
```cpp
|
|
230
|
-
bool Napi::Value::IsPromise() const;
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
Returns `true` if the underlying value is a JavaScript `Napi::Promise` or `false`
|
|
234
|
-
otherwise.
|
|
235
|
-
|
|
236
|
-
#### IsDataView
|
|
237
|
-
```cpp
|
|
238
|
-
bool Napi::Value::IsDataView() const;
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
Returns `true` if the underlying value is a JavaScript `Napi::DataView` or `false`
|
|
242
|
-
otherwise.
|
|
243
|
-
|
|
244
|
-
#### IsBuffer
|
|
245
|
-
```cpp
|
|
246
|
-
bool Napi::Value::IsBuffer() const;
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
Returns `true` if the underlying value is a Node.js `Napi::Buffer` or `false`
|
|
250
|
-
otherwise.
|
|
251
|
-
|
|
252
|
-
#### IsExternal
|
|
253
|
-
```cpp
|
|
254
|
-
bool Napi::Value::IsExternal() const;
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
Returns `true` if the underlying value is a N-API external object or `false`
|
|
258
|
-
otherwise.
|
|
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
|
-
|
|
268
|
-
#### ToBoolean
|
|
269
|
-
```cpp
|
|
270
|
-
Napi::Boolean Napi::Value::ToBoolean() const;
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
Returns a `Napi::Boolean` representing the `Napi::Value`.
|
|
274
|
-
|
|
275
|
-
This is a wrapper around `napi_coerce_to_boolean`. This will throw a JavaScript
|
|
276
|
-
exception if the coercion fails. If C++ exceptions are not being used, callers
|
|
277
|
-
should check the result of `Env::IsExceptionPending` before attempting to use
|
|
278
|
-
the returned value.
|
|
279
|
-
|
|
280
|
-
#### ToNumber
|
|
281
|
-
```cpp
|
|
282
|
-
Napi::Number Napi::Value::ToNumber() const;
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
Returns a `Napi::Number` representing the `Napi::Value`.
|
|
286
|
-
|
|
287
|
-
Note:
|
|
288
|
-
This can cause script code to be executed according to JavaScript semantics.
|
|
289
|
-
This is a wrapper around `napi_coerce_to_number`. This will throw a JavaScript
|
|
290
|
-
exception if the coercion fails. If C++ exceptions are not being used, callers
|
|
291
|
-
should check the result of `Env::IsExceptionPending` before attempting to use
|
|
292
|
-
the returned value.
|
|
293
|
-
|
|
294
|
-
#### ToString
|
|
295
|
-
```cpp
|
|
296
|
-
Napi::String Napi::Value::ToString() const;
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
Returns a `Napi::String` representing the `Napi::Value`.
|
|
300
|
-
|
|
301
|
-
Note that this can cause script code to be executed according to JavaScript
|
|
302
|
-
semantics. This is a wrapper around `napi_coerce_to_string`. This will throw a
|
|
303
|
-
JavaScript exception if the coercion fails. If C++ exceptions are not being
|
|
304
|
-
used, callers should check the result of `Env::IsExceptionPending` before
|
|
305
|
-
attempting to use the returned value.
|
|
306
|
-
|
|
307
|
-
#### ToObject
|
|
308
|
-
```cpp
|
|
309
|
-
Napi::Object Napi::Value::ToObject() const;
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
Returns a `Napi::Object` representing the `Napi::Value`.
|
|
313
|
-
|
|
314
|
-
This is a wrapper around `napi_coerce_to_object`. This will throw a JavaScript
|
|
315
|
-
exception if the coercion fails. If C++ exceptions are not being used, callers
|
|
316
|
-
should check the result of `Env::IsExceptionPending` before attempting to use
|
|
317
|
-
the returned value.
|
|
318
|
-
|
|
319
|
-
## Name
|
|
320
|
-
|
|
321
|
-
Names are JavaScript values that can be used as a property name. There are two
|
|
322
|
-
specialized types of names supported in Node.js Addon API [`Napi::String`](string.md)
|
|
323
|
-
and [`Napi::Symbol`](symbol.md).
|
|
324
|
-
|
|
325
|
-
### Methods
|
|
326
|
-
|
|
327
|
-
#### Constructor
|
|
328
|
-
```cpp
|
|
329
|
-
Napi::Name::Name();
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
Returns an empty `Napi::Name`.
|
|
333
|
-
|
|
334
|
-
```cpp
|
|
335
|
-
Napi::Name::Name(napi_env env, napi_value value);
|
|
336
|
-
```
|
|
337
|
-
- `[in] env` - The environment in which to create the array.
|
|
338
|
-
- `[in] value` - The primitive to wrap.
|
|
339
|
-
|
|
340
|
-
Returns a `Napi::Name` created from the JavaScript primitive.
|
|
341
|
-
|
|
342
|
-
Note:
|
|
343
|
-
The value is not coerced to a string.
|
|
344
|
-
|
|
345
|
-
## Array
|
|
346
|
-
|
|
347
|
-
Arrays are native representations of JavaScript Arrays. `Napi::Array` is a wrapper
|
|
348
|
-
around `napi_value` representing a JavaScript Array.
|
|
349
|
-
|
|
350
|
-
[`Napi::TypedArray`][] and [`Napi::ArrayBuffer`][] correspond to JavaScript data
|
|
351
|
-
types such as [`Int32Array`][] and [`ArrayBuffer`][], respectively, that can be
|
|
352
|
-
used for transferring large amounts of data from JavaScript to the native side.
|
|
353
|
-
An example illustrating the use of a JavaScript-provided `ArrayBuffer` in native
|
|
354
|
-
code is available [here](https://github.com/nodejs/node-addon-examples/tree/master/array_buffer_to_native/node-addon-api).
|
|
355
|
-
|
|
356
|
-
### Constructor
|
|
357
|
-
```cpp
|
|
358
|
-
Napi::Array::Array();
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
Returns an empty array.
|
|
362
|
-
|
|
363
|
-
If an error occurs, a `Napi::Error` will be thrown. If C++ exceptions are not
|
|
364
|
-
being used, callers should check the result of `Env::IsExceptionPending` before
|
|
365
|
-
attempting to use the returned value.
|
|
366
|
-
|
|
367
|
-
```cpp
|
|
368
|
-
Napi::Array::Array(napi_env env, napi_value value);
|
|
369
|
-
```
|
|
370
|
-
- `[in] env` - The environment in which to create the array.
|
|
371
|
-
- `[in] value` - The primitive to wrap.
|
|
372
|
-
|
|
373
|
-
Returns a `Napi::Array` wrapping a `napi_value`.
|
|
374
|
-
|
|
375
|
-
If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not
|
|
376
|
-
being used, callers should check the result of `Env::IsExceptionPending` before
|
|
377
|
-
attempting to use the returned value.
|
|
378
|
-
|
|
379
|
-
### Methods
|
|
380
|
-
|
|
381
|
-
#### New
|
|
382
|
-
```cpp
|
|
383
|
-
static Napi::Array Napi::Array::New(napi_env env);
|
|
384
|
-
```
|
|
385
|
-
- `[in] env` - The environment in which to create the array.
|
|
386
|
-
|
|
387
|
-
Returns a new `Napi::Array`.
|
|
388
|
-
|
|
389
|
-
If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not
|
|
390
|
-
being used, callers should check the result of `Env::IsExceptionPending` before
|
|
391
|
-
attempting to use the returned value.
|
|
392
|
-
|
|
393
|
-
#### New
|
|
394
|
-
|
|
395
|
-
```cpp
|
|
396
|
-
static Napi::Array Napi::Array::New(napi_env env, size_t length);
|
|
397
|
-
```
|
|
398
|
-
- `[in] env` - The environment in which to create the array.
|
|
399
|
-
- `[in] length` - The length of the array.
|
|
400
|
-
|
|
401
|
-
Returns a new `Napi::Array` with the given length.
|
|
402
|
-
|
|
403
|
-
If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not
|
|
404
|
-
being used, callers should check the result of `Env::IsExceptionPending` before
|
|
405
|
-
attempting to use the returned value.
|
|
406
|
-
|
|
407
|
-
#### Length
|
|
408
|
-
```cpp
|
|
409
|
-
uint32_t Napi::Array::Length() const;
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
Returns the length of the array.
|
|
413
|
-
|
|
414
|
-
Note:
|
|
415
|
-
This can execute JavaScript code implicitly according to JavaScript semantics.
|
|
416
|
-
If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not
|
|
417
|
-
being used, callers should check the result of `Env::IsExceptionPending` before
|
|
418
|
-
attempting to use the returned value.
|
|
419
|
-
|
|
420
|
-
[`Napi::TypedArray`]: ./typed_array.md
|
|
421
|
-
[`Napi::ArrayBuffer`]: ./array_buffer.md
|
|
422
|
-
[`Int32Array`]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
|
|
423
|
-
[`ArrayBuffer`]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Working with JavaScript Values
|
|
2
|
-
|
|
3
|
-
`node-addon-api` provides a set of classes that allow to create and manage
|
|
4
|
-
JavaScript object:
|
|
5
|
-
|
|
6
|
-
- [Function](function.md)
|
|
7
|
-
- [FunctionReference](function_reference.md)
|
|
8
|
-
- [ObjectWrap](object_wrap.md)
|
|
9
|
-
- [ClassPropertyDescriptor](class_property_descriptor.md)
|
|
10
|
-
- [Buffer](buffer.md)
|
|
11
|
-
- [ArrayBuffer](array_buffer.md)
|
|
12
|
-
- [TypedArray](typed_array.md)
|
|
13
|
-
- [TypedArrayOf](typed_array_of.md)
|
|
14
|
-
- [DataView](dataview.md)
|