node-addon-api 3.0.1 → 3.2.1

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 (74) hide show
  1. package/CHANGELOG.md +217 -0
  2. package/README.md +104 -60
  3. package/common.gypi +1 -1
  4. package/index.js +4 -3
  5. package/napi-inl.deprecated.h +8 -8
  6. package/napi-inl.h +1206 -540
  7. package/napi.h +821 -522
  8. package/package-support.json +21 -0
  9. package/package.json +80 -4
  10. package/tools/README.md +8 -2
  11. package/tools/clang-format.js +67 -0
  12. package/tools/conversion.js +4 -4
  13. package/.editorconfig +0 -8
  14. package/.travis.yml +0 -59
  15. package/CODE_OF_CONDUCT.md +0 -4
  16. package/CONTRIBUTING.md +0 -66
  17. package/appveyor.yml +0 -48
  18. package/benchmark/README.md +0 -47
  19. package/benchmark/binding.gyp +0 -25
  20. package/benchmark/function_args.cc +0 -153
  21. package/benchmark/function_args.js +0 -52
  22. package/benchmark/index.js +0 -34
  23. package/benchmark/property_descriptor.cc +0 -60
  24. package/benchmark/property_descriptor.js +0 -29
  25. package/doc/Doxyfile +0 -2450
  26. package/doc/array_buffer.md +0 -129
  27. package/doc/async_context.md +0 -86
  28. package/doc/async_operations.md +0 -31
  29. package/doc/async_worker.md +0 -427
  30. package/doc/async_worker_variants.md +0 -456
  31. package/doc/basic_types.md +0 -423
  32. package/doc/bigint.md +0 -93
  33. package/doc/boolean.md +0 -64
  34. package/doc/buffer.md +0 -140
  35. package/doc/callback_scope.md +0 -54
  36. package/doc/callbackinfo.md +0 -97
  37. package/doc/checker-tool.md +0 -32
  38. package/doc/class_property_descriptor.md +0 -117
  39. package/doc/cmake-js.md +0 -68
  40. package/doc/conversion-tool.md +0 -28
  41. package/doc/creating_a_release.md +0 -62
  42. package/doc/dataview.md +0 -244
  43. package/doc/date.md +0 -68
  44. package/doc/env.md +0 -132
  45. package/doc/error.md +0 -115
  46. package/doc/error_handling.md +0 -186
  47. package/doc/escapable_handle_scope.md +0 -82
  48. package/doc/external.md +0 -59
  49. package/doc/function.md +0 -401
  50. package/doc/function_reference.md +0 -238
  51. package/doc/generator.md +0 -13
  52. package/doc/handle_scope.md +0 -65
  53. package/doc/memory_management.md +0 -27
  54. package/doc/node-gyp.md +0 -82
  55. package/doc/number.md +0 -163
  56. package/doc/object.md +0 -275
  57. package/doc/object_lifetime_management.md +0 -83
  58. package/doc/object_reference.md +0 -117
  59. package/doc/object_wrap.md +0 -851
  60. package/doc/prebuild_tools.md +0 -16
  61. package/doc/promises.md +0 -74
  62. package/doc/property_descriptor.md +0 -286
  63. package/doc/range_error.md +0 -59
  64. package/doc/reference.md +0 -111
  65. package/doc/setup.md +0 -81
  66. package/doc/string.md +0 -89
  67. package/doc/symbol.md +0 -44
  68. package/doc/threadsafe_function.md +0 -320
  69. package/doc/type_error.md +0 -59
  70. package/doc/typed_array.md +0 -74
  71. package/doc/typed_array_of.md +0 -133
  72. package/doc/value.md +0 -278
  73. package/doc/version_management.md +0 -43
  74. package/doc/working_with_javascript_values.md +0 -14
package/doc/string.md DELETED
@@ -1,89 +0,0 @@
1
- # String
2
-
3
- ## Constructor
4
-
5
- ```cpp
6
- Napi::String::String();
7
- ```
8
-
9
- Returns a new **empty** `Napi::String` instance.
10
-
11
- If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not
12
- being used, callers should check the result of `Env::IsExceptionPending` before
13
- attempting to use the returned value.
14
-
15
- ```cpp
16
- Napi::String::String(napi_env env, napi_value value); ///< Wraps a N-API value primitive.
17
- ```
18
- - `[in] env` - The environment in which to create the string.
19
- - `[in] value` - The primitive to wrap.
20
-
21
- Returns a `Napi::String` wrapping a `napi_value`.
22
-
23
- If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not
24
- being used, callers should check the result of `Env::IsExceptionPending` before
25
- attempting to use the returned value.
26
-
27
- ## Operators
28
-
29
- ### operator std::string
30
-
31
- ```cpp
32
- Napi::String::operator std::string() const;
33
- ```
34
-
35
- Returns a UTF-8 encoded C++ string.
36
-
37
- ### operator std::u16string
38
- ```cpp
39
- Napi::String::operator std::u16string() const;
40
- ```
41
-
42
- Returns a UTF-16 encoded C++ string.
43
-
44
- ## Methods
45
-
46
- ### New
47
- ```cpp
48
- Napi::String::New();
49
- ```
50
-
51
- Returns a new empty `Napi::String`.
52
-
53
- ### New
54
- ```cpp
55
- Napi::String::New(napi_env env, const std::string& value);
56
- Napi::String::New(napi_env env, const std::u16::string& value);
57
- Napi::String::New(napi_env env, const char* value);
58
- Napi::String::New(napi_env env, const char16_t* value);
59
- Napi::String::New(napi_env env, const char* value, size_t length);
60
- Napi::String::New(napi_env env, const char16_t* value, size_t length);
61
- ```
62
-
63
- - `[in] env`: The `napi_env` environment in which to construct the `Napi::Value` object.
64
- - `[in] value`: The C++ primitive from which to instantiate the `Napi::Value`. `value` may be any of:
65
- - `std::string&` - represents a UTF8 string.
66
- - `std::u16string&` - represents a UTF16-LE string.
67
- - `const char*` - represents a UTF8 string.
68
- - `const char16_t*` - represents a UTF16-LE string.
69
- - `[in] length`: The length of the string (not necessarily null-terminated) in code units.
70
-
71
- Returns a new `Napi::String` that represents the passed in C++ string.
72
-
73
- If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not
74
- being used, callers should check the result of `Env::IsExceptionPending` before
75
- attempting to use the returned value.
76
-
77
- ### Utf8Value
78
- ```cpp
79
- std::string Napi::String::Utf8Value() const;
80
- ```
81
-
82
- Returns a UTF-8 encoded C++ string.
83
-
84
- ### Utf16Value
85
- ```cpp
86
- std::u16string Napi::String::Utf16Value() const;
87
- ```
88
-
89
- Returns a UTF-16 encoded C++ string.
package/doc/symbol.md DELETED
@@ -1,44 +0,0 @@
1
- # Symbol
2
-
3
- ## Methods
4
-
5
- ### Constructor
6
-
7
- Instantiates a new `Napi::Symbol` value.
8
-
9
- ```cpp
10
- Napi::Symbol::Symbol();
11
- ```
12
-
13
- Returns a new empty `Napi::Symbol`.
14
-
15
- ### New
16
- ```cpp
17
- Napi::Symbol::New(napi_env env, const std::string& description);
18
- Napi::Symbol::New(napi_env env, const char* description);
19
- Napi::Symbol::New(napi_env env, Napi::String description);
20
- Napi::Symbol::New(napi_env env, napi_value description);
21
- ```
22
-
23
- - `[in] env`: The `napi_env` environment in which to construct the `Napi::Symbol` object.
24
- - `[in] value`: The C++ primitive which represents the description hint for the `Napi::Symbol`.
25
- `description` may be any of:
26
- - `std::string&` - UTF8 string description.
27
- - `const char*` - represents a UTF8 string description.
28
- - `String` - Node addon API String description.
29
- - `napi_value` - N-API `napi_value` description.
30
-
31
- If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not
32
- being used, callers should check the result of `Napi::Env::IsExceptionPending` before
33
- attempting to use the returned value.
34
-
35
- ### Utf8Value
36
- ```cpp
37
- static Napi::Symbol Napi::Symbol::WellKnown(napi_env env, const std::string& name);
38
- ```
39
-
40
- - `[in] env`: The `napi_env` environment in which to construct the `Napi::Symbol` object.
41
- - `[in] name`: The C++ string representing the `Napi::Symbol` to retrieve.
42
-
43
- Returns a `Napi::Symbol` representing a well-known `Symbol` from the
44
- `Symbol` registry.
@@ -1,320 +0,0 @@
1
- # ThreadSafeFunction
2
-
3
- JavaScript functions can normally only be called from a native addon's main
4
- thread. If an addon creates additional threads, then node-addon-api functions
5
- that require a `Napi::Env`, `Napi::Value`, or `Napi::Reference` must not be
6
- called from those threads.
7
-
8
- When an addon has additional threads and JavaScript functions need to be invoked
9
- based on the processing completed by those threads, those threads must
10
- communicate with the addon's main thread so that the main thread can invoke the
11
- JavaScript function on their behalf. The thread-safe function APIs provide an
12
- easy way to do this.
13
-
14
- These APIs provide the type `Napi::ThreadSafeFunction` as well as APIs to
15
- create, destroy, and call objects of this type.
16
- `Napi::ThreadSafeFunction::New()` creates a persistent reference that holds a
17
- JavaScript function which can be called from multiple threads. The calls happen
18
- asynchronously. This means that values with which the JavaScript callback is to
19
- be called will be placed in a queue, and, for each value in the queue, a call
20
- will eventually be made to the JavaScript function.
21
-
22
- `Napi::ThreadSafeFunction` objects are destroyed when every thread which uses
23
- the object has called `Release()` or has received a return status of
24
- `napi_closing` in response to a call to `BlockingCall()` or `NonBlockingCall()`.
25
- The queue is emptied before the `Napi::ThreadSafeFunction` is destroyed. It is
26
- important that `Release()` be the last API call made in conjunction with a given
27
- `Napi::ThreadSafeFunction`, because after the call completes, there is no
28
- guarantee that the `Napi::ThreadSafeFunction` is still allocated. For the same
29
- reason it is also important that no more use be made of a thread-safe function
30
- after receiving a return value of `napi_closing` in response to a call to
31
- `BlockingCall()` or `NonBlockingCall()`. Data associated with the
32
- `Napi::ThreadSafeFunction` can be freed in its `Finalizer` callback which was
33
- passed to `ThreadSafeFunction::New()`.
34
-
35
- Once the number of threads making use of a `Napi::ThreadSafeFunction` reaches
36
- zero, no further threads can start making use of it by calling `Acquire()`. In
37
- fact, all subsequent API calls associated with it, except `Release()`, will
38
- return an error value of `napi_closing`.
39
-
40
- ## Methods
41
-
42
- ### Constructor
43
-
44
- Creates a new empty instance of `Napi::ThreadSafeFunction`.
45
-
46
- ```cpp
47
- Napi::Function::ThreadSafeFunction();
48
- ```
49
-
50
- ### Constructor
51
-
52
- Creates a new instance of the `Napi::ThreadSafeFunction` object.
53
-
54
- ```cpp
55
- Napi::ThreadSafeFunction::ThreadSafeFunction(napi_threadsafe_function tsfn);
56
- ```
57
-
58
- - `tsfn`: The `napi_threadsafe_function` which is a handle for an existing
59
- thread-safe function.
60
-
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.
65
-
66
- ### New
67
-
68
- Creates a new instance of the `Napi::ThreadSafeFunction` object. The `New`
69
- function has several overloads for the various optional parameters: skip the
70
- optional parameter for that specific overload.
71
-
72
- ```cpp
73
- New(napi_env env,
74
- const Function& callback,
75
- const Object& resource,
76
- ResourceString resourceName,
77
- size_t maxQueueSize,
78
- size_t initialThreadCount,
79
- ContextType* context,
80
- Finalizer finalizeCallback,
81
- FinalizerDataType* data);
82
- ```
83
-
84
- - `env`: The `napi_env` environment in which to construct the
85
- `Napi::ThreadSafeFunction` object.
86
- - `callback`: The `Function` to call from another thread.
87
- - `[optional] resource`: An object associated with the async work that will be
88
- passed to possible async_hooks init hooks.
89
- - `resourceName`: A JavaScript string to provide an identifier for the kind of
90
- resource that is being provided for diagnostic information exposed by the
91
- async_hooks API.
92
- - `maxQueueSize`: Maximum size of the queue. `0` for no limit.
93
- - `initialThreadCount`: The initial number of threads, including the main
94
- thread, which will be making use of this function.
95
- - `[optional] context`: Data to attach to the resulting `ThreadSafeFunction`.
96
- - `[optional] finalizeCallback`: Function to call when the `ThreadSafeFunction`
97
- is being destroyed. This callback will be invoked on the main thread when the
98
- thread-safe function is about to be destroyed. It receives the context and the
99
- finalize data given during construction (if given), and provides an
100
- opportunity for cleaning up after the threads e.g. by calling
101
- `uv_thread_join()`. It is important that, aside from the main loop thread,
102
- there be no threads left using the thread-safe function after the finalize
103
- callback completes. Must implement `void operator()(Env env, DataType* data,
104
- Context* hint)`, skipping `data` or `hint` if they are not provided.
105
- Can be retreived via `GetContext()`.
106
- - `[optional] data`: Data to be passed to `finalizeCallback`.
107
-
108
- Returns a non-empty `Napi::ThreadSafeFunction` instance.
109
-
110
- ### Acquire
111
-
112
- Add a thread to this thread-safe function object, indicating that a new thread
113
- will start making use of the thread-safe function.
114
-
115
- ```cpp
116
- napi_status Napi::ThreadSafeFunction::Acquire()
117
- ```
118
-
119
- Returns one of:
120
- - `napi_ok`: The thread has successfully acquired the thread-safe function
121
- for its use.
122
- - `napi_closing`: The thread-safe function has been marked as closing via a
123
- previous call to `Abort()`.
124
-
125
- ### Release
126
-
127
- Indicate that an existing thread will stop making use of the thread-safe
128
- function. A thread should call this API when it stops making use of this
129
- thread-safe function. Using any thread-safe APIs after having called this API
130
- has undefined results in the current thread, as it may have been destroyed.
131
-
132
- ```cpp
133
- napi_status Napi::ThreadSafeFunction::Release()
134
- ```
135
-
136
- Returns one of:
137
- - `napi_ok`: The thread-safe function has been successfully released.
138
- - `napi_invalid_arg`: The thread-safe function's thread-count is zero.
139
- - `napi_generic_failure`: A generic error occurred when attemping to release
140
- the thread-safe function.
141
-
142
- ### Abort
143
-
144
- "Abort" the thread-safe function. This will cause all subsequent APIs associated
145
- with the thread-safe function except `Release()` to return `napi_closing` even
146
- before its reference count reaches zero. In particular, `BlockingCall` and
147
- `NonBlockingCall()` will return `napi_closing`, thus informing the threads that
148
- it is no longer possible to make asynchronous calls to the thread-safe function.
149
- This can be used as a criterion for terminating the thread. Upon receiving a
150
- return value of `napi_closing` from a thread-safe function call a thread must
151
- make no further use of the thread-safe function because it is no longer
152
- guaranteed to be allocated.
153
-
154
- ```cpp
155
- napi_status Napi::ThreadSafeFunction::Abort()
156
- ```
157
-
158
- Returns one of:
159
- - `napi_ok`: The thread-safe function has been successfully aborted.
160
- - `napi_invalid_arg`: The thread-safe function's thread-count is zero.
161
- - `napi_generic_failure`: A generic error occurred when attemping to abort
162
- the thread-safe function.
163
-
164
- ### BlockingCall / NonBlockingCall
165
-
166
- Calls the Javascript function in either a blocking or non-blocking fashion.
167
- - `BlockingCall()`: the API blocks until space becomes available in the queue.
168
- Will never block if the thread-safe function was created with a maximum queue
169
- size of `0`.
170
- - `NonBlockingCall()`: will return `napi_queue_full` if the queue was full,
171
- preventing data from being successfully added to the queue.
172
-
173
- There are several overloaded implementations of `BlockingCall()` and
174
- `NonBlockingCall()` for use with optional parameters: skip the optional
175
- parameter for that specific overload.
176
-
177
- **These specific function overloads should only be used on a `ThreadSafeFunction`
178
- created via `ThreadSafeFunction::New`.**
179
-
180
- ```cpp
181
- napi_status Napi::ThreadSafeFunction::BlockingCall(DataType* data, Callback callback) const
182
-
183
- napi_status Napi::ThreadSafeFunction::NonBlockingCall(DataType* data, Callback callback) const
184
- ```
185
-
186
- - `[optional] data`: Data to pass to `callback`.
187
- - `[optional] callback`: C++ function that is invoked on the main thread. The
188
- callback receives the `ThreadSafeFunction`'s JavaScript callback function to
189
- call as an `Napi::Function` in its parameters and the `DataType*` data pointer
190
- (if provided). Must implement `void operator()(Napi::Env env, Function
191
- jsCallback, DataType* data)`, skipping `data` if not provided. It is not
192
- necessary to call into JavaScript via `MakeCallback()` because N-API runs
193
- `callback` in a context appropriate for callbacks.
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
-
206
- Returns one of:
207
- - `napi_ok`: The call was successfully added to the queue.
208
- - `napi_queue_full`: The queue was full when trying to call in a non-blocking
209
- method.
210
- - `napi_closing`: The thread-safe function is aborted and cannot accept more
211
- calls.
212
- - `napi_invalid_arg`: The thread-safe function is closed.
213
- - `napi_generic_failure`: A generic error occurred when attemping to add to the
214
- queue.
215
-
216
- ## Example
217
-
218
- ```cpp
219
- #include <chrono>
220
- #include <thread>
221
- #include <napi.h>
222
-
223
- using namespace Napi;
224
-
225
- std::thread nativeThread;
226
- ThreadSafeFunction tsfn;
227
-
228
- Value Start( const CallbackInfo& info )
229
- {
230
- Napi::Env env = info.Env();
231
-
232
- if ( info.Length() < 2 )
233
- {
234
- throw TypeError::New( env, "Expected two arguments" );
235
- }
236
- else if ( !info[0].IsFunction() )
237
- {
238
- throw TypeError::New( env, "Expected first arg to be function" );
239
- }
240
- else if ( !info[1].IsNumber() )
241
- {
242
- throw TypeError::New( env, "Expected second arg to be number" );
243
- }
244
-
245
- int count = info[1].As<Number>().Int32Value();
246
-
247
- // Create a ThreadSafeFunction
248
- tsfn = ThreadSafeFunction::New(
249
- env,
250
- info[0].As<Function>(), // JavaScript function called asynchronously
251
- "Resource Name", // Name
252
- 0, // Unlimited queue
253
- 1, // Only one thread will use this initially
254
- []( Napi::Env ) { // Finalizer used to clean threads up
255
- nativeThread.join();
256
- } );
257
-
258
- // Create a native thread
259
- nativeThread = std::thread( [count] {
260
- auto callback = []( Napi::Env env, Function jsCallback, int* value ) {
261
- // Transform native data into JS data, passing it to the provided
262
- // `jsCallback` -- the TSFN's JavaScript function.
263
- jsCallback.Call( {Number::New( env, *value )} );
264
-
265
- // We're finished with the data.
266
- delete value;
267
- };
268
-
269
- for ( int i = 0; i < count; i++ )
270
- {
271
- // Create new data
272
- int* value = new int( clock() );
273
-
274
- // Perform a blocking call
275
- napi_status status = tsfn.BlockingCall( value, callback );
276
- if ( status != napi_ok )
277
- {
278
- // Handle error
279
- break;
280
- }
281
-
282
- std::this_thread::sleep_for( std::chrono::seconds( 1 ) );
283
- }
284
-
285
- // Release the thread-safe function
286
- tsfn.Release();
287
- } );
288
-
289
- return Boolean::New(env, true);
290
- }
291
-
292
- Napi::Object Init( Napi::Env env, Object exports )
293
- {
294
- exports.Set( "start", Function::New( env, Start ) );
295
- return exports;
296
- }
297
-
298
- NODE_API_MODULE( clock, Init )
299
- ```
300
-
301
- The above code can be used from JavaScript as follows:
302
-
303
- ```js
304
- const { start } = require('bindings')('clock');
305
-
306
- start(function () {
307
- console.log("JavaScript callback called with arguments", Array.from(arguments));
308
- }, 5);
309
- ```
310
-
311
- When executed, the output will show the value of `clock()` five times at one
312
- second intervals:
313
-
314
- ```
315
- JavaScript callback called with arguments [ 84745 ]
316
- JavaScript callback called with arguments [ 103211 ]
317
- JavaScript callback called with arguments [ 104516 ]
318
- JavaScript callback called with arguments [ 105104 ]
319
- JavaScript callback called with arguments [ 105691 ]
320
- ```
package/doc/type_error.md DELETED
@@ -1,59 +0,0 @@
1
- # TypeError
2
-
3
- The `Napi::TypeError` class is a representation of the JavaScript `TypeError` that is
4
- thrown when an operand or argument passed to a function is incompatible with the
5
- type expected by the operator or function.
6
-
7
- The `Napi::TypeError` class inherits its behaviors from the `Napi::Error` class (for more info
8
- see: [`Napi::Error`](error.md)).
9
-
10
- For more details about error handling refer to the section titled [Error handling](error_handling.md).
11
-
12
- ## Methods
13
-
14
- ### New
15
-
16
- Creates a new instance of the `Napi::TypeError` object.
17
-
18
- ```cpp
19
- Napi::TypeError::New(Napi:Env env, const char* message);
20
- ```
21
-
22
- - `[in] Env`: The environment in which to construct the `Napi::TypeError` object.
23
- - `[in] message`: Null-terminated string to be used as the message for the `Napi::TypeError`.
24
-
25
- Returns an instance of a `Napi::TypeError` object.
26
-
27
- ### New
28
-
29
- Creates a new instance of a `Napi::TypeError` object.
30
-
31
- ```cpp
32
- Napi::TypeError::New(Napi:Env env, const std::string& message);
33
- ```
34
-
35
- - `[in] Env`: The environment in which to construct the `Napi::TypeError` object.
36
- - `[in] message`: Reference string to be used as the message for the `Napi::TypeError`.
37
-
38
- Returns an instance of a `Napi::TypeError` object.
39
-
40
- ### Constructor
41
-
42
- Creates a new empty instance of a `Napi::TypeError`.
43
-
44
- ```cpp
45
- Napi::TypeError::TypeError();
46
- ```
47
-
48
- ### Constructor
49
-
50
- Initializes a `Napi::TypeError` instance from an existing JavaScript error object.
51
-
52
- ```cpp
53
- Napi::TypeError::TypeError(napi_env env, napi_value value);
54
- ```
55
-
56
- - `[in] Env`: The environment in which to construct the `Napi::TypeError` object.
57
- - `[in] value`: The `Napi::Error` reference to wrap.
58
-
59
- Returns an instance of a `Napi::TypeError` object.
@@ -1,74 +0,0 @@
1
- # TypedArray
2
-
3
- The `Napi::TypedArray` class corresponds to the
4
- [JavaScript `TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
5
- class.
6
-
7
- ## Methods
8
-
9
- ### Constructor
10
-
11
- Initializes an empty instance of the `Napi::TypedArray` class.
12
-
13
- ```cpp
14
- Napi::TypedArray::TypedArray();
15
- ```
16
-
17
- ### Constructor
18
-
19
- Initializes a wrapper instance of an existing `Napi::TypedArray` instance.
20
-
21
- ```cpp
22
- Napi::TypedArray::TypedArray(napi_env env, napi_value value);
23
- ```
24
-
25
- - `[in] env`: The environment in which to create the `Napi::TypedArray` instance.
26
- - `[in] value`: The `Napi::TypedArray` reference to wrap.
27
-
28
- ### TypedArrayType
29
-
30
- ```cpp
31
- napi_typedarray_type Napi::TypedArray::TypedArrayType() const;
32
- ```
33
-
34
- Returns the type of this instance.
35
-
36
- ### ArrayBuffer
37
-
38
- ```cpp
39
- Napi::ArrayBuffer Napi::TypedArray::ArrayBuffer() const;
40
- ```
41
-
42
- Returns the backing array buffer.
43
-
44
- ### ElementSize
45
-
46
- ```cpp
47
- uint8_t Napi::TypedArray::ElementSize() const;
48
- ```
49
-
50
- Returns the size of one element, in bytes.
51
-
52
- ### ElementLength
53
-
54
- ```cpp
55
- size_t Napi::TypedArray::ElementLength() const;
56
- ```
57
-
58
- Returns the number of elements.
59
-
60
- ### ByteOffset
61
-
62
- ```cpp
63
- size_t Napi::TypedArray::ByteOffset() const;
64
- ```
65
-
66
- Returns the offset into the `Napi::ArrayBuffer` where the array starts, in bytes.
67
-
68
- ### ByteLength
69
-
70
- ```cpp
71
- size_t Napi::TypedArray::ByteLength() const;
72
- ```
73
-
74
- Returns the length of the array, in bytes.