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/boolean.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Boolean
|
|
2
2
|
|
|
3
|
+
Class `Napi::Boolean` inherits from class [`Napi::Value`][].
|
|
4
|
+
|
|
3
5
|
`Napi::Boolean` class is a representation of the JavaScript `Boolean` object. The
|
|
4
6
|
`Napi::Boolean` class inherits its behavior from the `Napi::Value` class
|
|
5
7
|
(for more info see: [`Napi::Value`](value.md)).
|
|
@@ -62,3 +64,5 @@ Napi::Boolean::operator bool() const;
|
|
|
62
64
|
```
|
|
63
65
|
|
|
64
66
|
Returns the boolean primitive type of the corresponding `Napi::Boolean` object.
|
|
67
|
+
|
|
68
|
+
[`Napi::Value`]: ./value.md
|
package/doc/buffer.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Buffer
|
|
2
2
|
|
|
3
|
+
Class `Napi::Buffer` inherits from class [`Napi::Uint8Array`][].
|
|
4
|
+
|
|
3
5
|
The `Napi::Buffer` class creates a projection of raw data that can be consumed by
|
|
4
6
|
script.
|
|
5
7
|
|
|
@@ -138,3 +140,5 @@ size_t Napi::Buffer::Length() const;
|
|
|
138
140
|
```
|
|
139
141
|
|
|
140
142
|
Returns the number of `T` elements in the external data.
|
|
143
|
+
|
|
144
|
+
[`Napi::Uint8Array`]: ./typed_array_of.md
|
package/doc/dataview.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# DataView
|
|
2
2
|
|
|
3
|
+
Class `Napi::DataView` inherits from class [`Napi::Object`][].
|
|
4
|
+
|
|
3
5
|
The `Napi::DataView` class corresponds to the
|
|
4
6
|
[JavaScript `DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
|
|
5
7
|
class.
|
|
@@ -242,3 +244,5 @@ void Napi::DataView::SetUint32(size_t byteOffset, uint32_t value) const;
|
|
|
242
244
|
|
|
243
245
|
- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
|
|
244
246
|
- `[in] value`: The value to set.
|
|
247
|
+
|
|
248
|
+
[`Napi::Object`]: ./object.md
|
package/doc/date.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Date
|
|
2
2
|
|
|
3
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))
|
|
4
|
+
`Napi::Date` class inherits its behavior from the `Napi::Value` class
|
|
5
|
+
(for more info see [`Napi::Value`](value.md)).
|
|
6
6
|
|
|
7
7
|
## Methods
|
|
8
8
|
|
package/doc/error.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Error
|
|
2
2
|
|
|
3
|
+
Class `Napi::Error` inherits from class [`Napi::ObjectReference`][] and class [`std::exception`][].
|
|
4
|
+
|
|
3
5
|
The `Napi::Error` class is a representation of the JavaScript `Error` object that is thrown
|
|
4
6
|
when runtime errors occur. The Error object can also be used as a base object for
|
|
5
7
|
user-defined exceptions.
|
|
@@ -113,3 +115,6 @@ const char* Napi::Error::what() const NAPI_NOEXCEPT override;
|
|
|
113
115
|
|
|
114
116
|
Returns a pointer to a null-terminated string that is used to identify the
|
|
115
117
|
exception. This method can be used only if the exception mechanism is enabled.
|
|
118
|
+
|
|
119
|
+
[`Napi::ObjectReference`]: ./object_reference.md
|
|
120
|
+
[`std::exception`]: http://cplusplus.com/reference/exception/exception/
|
package/doc/external.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# External (template)
|
|
2
2
|
|
|
3
|
+
Class `Napi::External<T>` inherits from class [`Napi::Value`][].
|
|
4
|
+
|
|
3
5
|
The `Napi::External` template class implements the ability to create a `Napi::Value` object with arbitrary C++ data. It is the user's responsibility to manage the memory for the arbitrary C++ data.
|
|
4
6
|
|
|
5
7
|
`Napi::External` objects can be created with an optional Finalizer function and optional Hint value. The Finalizer function, if specified, is called when your `Napi::External` object is released by Node's garbage collector. It gives your code the opportunity to free any dynamically created data. If you specify a Hint value, it is passed to your Finalizer function.
|
|
@@ -57,3 +59,5 @@ T* Napi::External::Data() const;
|
|
|
57
59
|
```
|
|
58
60
|
|
|
59
61
|
Returns a pointer to the arbitrary C++ data held by the `Napi::External` object.
|
|
62
|
+
|
|
63
|
+
[`Napi::Value`]: ./value.md
|
package/doc/function.md
CHANGED
package/doc/hierarchy.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Full Class Hierarchy
|
|
2
|
+
|
|
3
|
+
| Class | Parent Class(es) |
|
|
4
|
+
|---|---|
|
|
5
|
+
| [`Napi::Addon`][] | [`Napi::InstanceWrap`][] |
|
|
6
|
+
| [`Napi::Array`][] | [`Napi::Object`][] |
|
|
7
|
+
| [`Napi::ArrayBuffer`][] | [`Napi::Object`][] |
|
|
8
|
+
| [`Napi::AsyncContext`][] | |
|
|
9
|
+
| [`Napi::AsyncProgressQueueWorker`][] | `Napi::AsyncProgressWorkerBase` |
|
|
10
|
+
| [`Napi::AsyncProgressWorker`][] | `Napi::AsyncProgressWorkerBase` |
|
|
11
|
+
| [`Napi::AsyncWorker`][] | |
|
|
12
|
+
| [`Napi::BigInt`][] | [`Napi::Value`][] |
|
|
13
|
+
| [`Napi::Boolean`][] | [`Napi::Value`][] |
|
|
14
|
+
| [`Napi::Buffer`][] | [`Napi::Uint8Array`][] |
|
|
15
|
+
| [`Napi::CallbackInfo`][] | |
|
|
16
|
+
| [`Napi::CallbackScope`][] | |
|
|
17
|
+
| [`Napi::ClassPropertyDescriptor`][] | |
|
|
18
|
+
| [`Napi::DataView`][] | [`Napi::Object`][] |
|
|
19
|
+
| [`Napi::Date`][] | [`Napi::Value`][] |
|
|
20
|
+
| [`Napi::Env`][] | |
|
|
21
|
+
| [`Napi::Error`][] | [`Napi::ObjectReference`][], [`std::exception`][] |
|
|
22
|
+
| [`Napi::EscapableHandleScope`][] | |
|
|
23
|
+
| [`Napi::External`][] | [`Napi::Value`][] |
|
|
24
|
+
| [`Napi::Function`][] | [`Napi::Object`][] |
|
|
25
|
+
| [`Napi::FunctionReference`][] | [`Napi::Reference<Napi::Function>`][] |
|
|
26
|
+
| [`Napi::HandleScope`][] | |
|
|
27
|
+
| [`Napi::InstanceWrap`][] | |
|
|
28
|
+
| [`Napi::MemoryManagement`][] | |
|
|
29
|
+
| [`Napi::Name`][] | [`Napi::Value`][] |
|
|
30
|
+
| [`Napi::Number`][] | [`Napi::Value`][] |
|
|
31
|
+
| [`Napi::Object`][] | [`Napi::Value`][] |
|
|
32
|
+
| [`Napi::ObjectReference`][] | [`Napi::Reference<Napi::Object>`][] |
|
|
33
|
+
| [`Napi::ObjectWrap`][] | [`Napi::InstanceWrap`][], [`Napi::Reference<Napi::Object>`][] |
|
|
34
|
+
| [`Napi::Promise`][] | [`Napi::Object`][] |
|
|
35
|
+
| [`Napi::PropertyDescriptor`][] | |
|
|
36
|
+
| [`Napi::RangeError`][] | [`Napi::Error`][] |
|
|
37
|
+
| [`Napi::Reference`] | |
|
|
38
|
+
| [`Napi::String`][] | [`Napi::Name`][] |
|
|
39
|
+
| [`Napi::Symbol`][] | [`Napi::Name`][] |
|
|
40
|
+
| [`Napi::ThreadSafeFunction`][] | |
|
|
41
|
+
| [`Napi::TypeError`][] | [`Napi::Error`][] |
|
|
42
|
+
| [`Napi::TypedArray`][] | [`Napi::Object`][] |
|
|
43
|
+
| [`Napi::TypedArrayOf`][] | [`Napi::TypedArray`][] |
|
|
44
|
+
| [`Napi::Value`][] | |
|
|
45
|
+
| [`Napi::VersionManagement`][] | |
|
|
46
|
+
|
|
47
|
+
[`Napi::Addon`]: ./addon.md
|
|
48
|
+
[`Napi::Array`]: ./array.md
|
|
49
|
+
[`Napi::ArrayBuffer`]: ./array_buffer.md
|
|
50
|
+
[`Napi::AsyncContext`]: ./async_context.md
|
|
51
|
+
[`Napi::AsyncProgressQueueWorker`]: ./async_worker_variants.md#asyncprogressqueueworker
|
|
52
|
+
[`Napi::AsyncProgressWorker`]: ./async_worker_variants.md#asyncprogressworker
|
|
53
|
+
[`Napi::AsyncWorker`]: ./async_worker.md
|
|
54
|
+
[`Napi::BigInt`]: ./bigint.md
|
|
55
|
+
[`Napi::Boolean`]: ./boolean.md
|
|
56
|
+
[`Napi::Buffer`]: ./buffer.md
|
|
57
|
+
[`Napi::CallbackInfo`]: ./callbackinfo.md
|
|
58
|
+
[`Napi::CallbackScope`]: ./callback_scope.md
|
|
59
|
+
[`Napi::ClassPropertyDescriptor`]: ./class_property_descriptor.md
|
|
60
|
+
[`Napi::DataView`]: ./dataview.md
|
|
61
|
+
[`Napi::Date`]: ./date.md
|
|
62
|
+
[`Napi::Env`]: ./env.md
|
|
63
|
+
[`Napi::Error`]: ./error.md
|
|
64
|
+
[`Napi::EscapableHandleScope`]: ./escapable_handle_scope.md
|
|
65
|
+
[`Napi::External`]: ./external.md
|
|
66
|
+
[`Napi::Function`]: ./function.md
|
|
67
|
+
[`Napi::FunctionReference`]: ./function_reference.md
|
|
68
|
+
[`Napi::HandleScope`]: ./handle_scope.md
|
|
69
|
+
[`Napi::InstanceWrap`]: ./instance_wrap.md
|
|
70
|
+
[`Napi::MemoryManagement`]: ./memory_management.md
|
|
71
|
+
[`Napi::Name`]: ./name.md
|
|
72
|
+
[`Napi::Number`]: ./number.md
|
|
73
|
+
[`Napi::Object`]: ./object.md
|
|
74
|
+
[`Napi::ObjectReference`]: ./object_reference.md
|
|
75
|
+
[`Napi::ObjectWrap`]: ./object_wrap.md
|
|
76
|
+
[`Napi::Promise`]: ./promise.md
|
|
77
|
+
[`Napi::PropertyDescriptor`]: ./property_descriptor.md
|
|
78
|
+
[`Napi::RangeError`]: ./range_error.md
|
|
79
|
+
[`Napi::Reference`]: ./reference.md
|
|
80
|
+
[`Napi::Reference<Napi::Function>`]: ./reference.md
|
|
81
|
+
[`Napi::Reference<Napi::Object>`]: ./reference.md
|
|
82
|
+
[`Napi::String`]: ./string.md
|
|
83
|
+
[`Napi::Symbol`]: ./symbol.md
|
|
84
|
+
[`Napi::ThreadSafeFunction`]: ./thread_safe_function.md
|
|
85
|
+
[`Napi::TypeError`]: ./type_error.md
|
|
86
|
+
[`Napi::TypedArray`]: ./typed_array.md
|
|
87
|
+
[`Napi::TypedArrayOf`]: ./typed_array_of.md
|
|
88
|
+
[`Napi::Uint8Array`]: ./typed_array_of.md
|
|
89
|
+
[`Napi::Value`]: ./value.md
|
|
90
|
+
[`Napi::VersionManagement`]: ./version_management.md
|
|
91
|
+
[`std::exception`]: http://cplusplus.com/reference/exception/exception/
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
# InstanceWrap<T>
|
|
2
|
+
|
|
3
|
+
This class serves as the base class for [`Napi::ObjectWrap<T>`][] and
|
|
4
|
+
[`Napi::Addon<T>`][].
|
|
5
|
+
|
|
6
|
+
In the case of [`Napi::Addon<T>`][] it provides the
|
|
7
|
+
methods for exposing functions to JavaScript on instances of an add-on.
|
|
8
|
+
|
|
9
|
+
As a base class for [`Napi::ObjectWrap<T>`][] it provides the methods for
|
|
10
|
+
exposing instance methods of JavaScript objects instantiated from the JavaScript
|
|
11
|
+
class corresponding to the subclass of [`Napi::ObjectWrap<T>`][].
|
|
12
|
+
|
|
13
|
+
## Methods
|
|
14
|
+
|
|
15
|
+
### InstanceMethod
|
|
16
|
+
|
|
17
|
+
Creates a property descriptor that represents a method exposed on JavaScript
|
|
18
|
+
instances of this class.
|
|
19
|
+
|
|
20
|
+
```cpp
|
|
21
|
+
template <typename T>
|
|
22
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
23
|
+
Napi::InstanceWrap<T>::InstanceMethod(const char* utf8name,
|
|
24
|
+
InstanceVoidMethodCallback method,
|
|
25
|
+
napi_property_attributes attributes = napi_default,
|
|
26
|
+
void* data = nullptr);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- `[in] utf8name`: Null-terminated string that represents the name of the method
|
|
30
|
+
provided by instances of the class.
|
|
31
|
+
- `[in] method`: The native function that represents a method provided by the
|
|
32
|
+
add-on.
|
|
33
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
34
|
+
`napi_property_attributes`.
|
|
35
|
+
- `[in] data`: User-provided data passed into the method when it is invoked.
|
|
36
|
+
|
|
37
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
|
|
38
|
+
provided by instances of the class. The method must be of the form
|
|
39
|
+
|
|
40
|
+
```cpp
|
|
41
|
+
void MethodName(const Napi::CallbackInfo& info);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### InstanceMethod
|
|
45
|
+
|
|
46
|
+
Creates a property descriptor that represents a method exposed on JavaScript
|
|
47
|
+
instances of this class.
|
|
48
|
+
|
|
49
|
+
```cpp
|
|
50
|
+
template <typename T>
|
|
51
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
52
|
+
Napi::InstanceWrap<T>::InstanceMethod(const char* utf8name,
|
|
53
|
+
InstanceMethodCallback method,
|
|
54
|
+
napi_property_attributes attributes = napi_default,
|
|
55
|
+
void* data = nullptr);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- `[in] utf8name`: Null-terminated string that represents the name of the method
|
|
59
|
+
provided by instances of the class.
|
|
60
|
+
- `[in] method`: The native function that represents a method provided by the
|
|
61
|
+
add-on.
|
|
62
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
63
|
+
`napi_property_attributes`.
|
|
64
|
+
- `[in] data`: User-provided data passed into the method when it is invoked.
|
|
65
|
+
|
|
66
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
|
|
67
|
+
provided by instances of the class. The method must be of the form
|
|
68
|
+
|
|
69
|
+
```cpp
|
|
70
|
+
Napi::Value MethodName(const Napi::CallbackInfo& info);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### InstanceMethod
|
|
74
|
+
|
|
75
|
+
Creates a property descriptor that represents a method exposed on JavaScript
|
|
76
|
+
instances of this class.
|
|
77
|
+
|
|
78
|
+
```cpp
|
|
79
|
+
template <typename T>
|
|
80
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
81
|
+
Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
|
|
82
|
+
InstanceVoidMethodCallback method,
|
|
83
|
+
napi_property_attributes attributes = napi_default,
|
|
84
|
+
void* data = nullptr);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- `[in] name`: JavaScript symbol that represents the name of the method provided
|
|
88
|
+
by instances of the class.
|
|
89
|
+
- `[in] method`: The native function that represents a method provided by the
|
|
90
|
+
add-on.
|
|
91
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
92
|
+
`napi_property_attributes`.
|
|
93
|
+
- `[in] data`: User-provided data passed into the method when it is invoked.
|
|
94
|
+
|
|
95
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
|
|
96
|
+
provided by instances of the class. The method must be of the form
|
|
97
|
+
|
|
98
|
+
```cpp
|
|
99
|
+
void MethodName(const Napi::CallbackInfo& info);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### InstanceMethod
|
|
103
|
+
|
|
104
|
+
Creates a property descriptor that represents a method exposed on JavaScript
|
|
105
|
+
instances of this class.
|
|
106
|
+
|
|
107
|
+
```cpp
|
|
108
|
+
template <typename T>
|
|
109
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
110
|
+
Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
|
|
111
|
+
InstanceMethodCallback method,
|
|
112
|
+
napi_property_attributes attributes = napi_default,
|
|
113
|
+
void* data = nullptr);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
- `[in] name`: JavaScript symbol that represents the name of the method provided
|
|
117
|
+
by instances of the class.
|
|
118
|
+
- `[in] method`: The native function that represents a method provided by the
|
|
119
|
+
add-on.
|
|
120
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
121
|
+
`napi_property_attributes`.
|
|
122
|
+
- `[in] data`: User-provided data passed into the method when it is invoked.
|
|
123
|
+
|
|
124
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
|
|
125
|
+
provided by instances of the class. The method must be of the form
|
|
126
|
+
|
|
127
|
+
```cpp
|
|
128
|
+
Napi::Value MethodName(const Napi::CallbackInfo& info);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### InstanceMethod
|
|
132
|
+
|
|
133
|
+
Creates a property descriptor that represents a method exposed on JavaScript
|
|
134
|
+
instances of this class.
|
|
135
|
+
|
|
136
|
+
```cpp
|
|
137
|
+
<template typename T>
|
|
138
|
+
template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
|
|
139
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
140
|
+
Napi::InstanceWrap::InstanceMethod(const char* utf8name,
|
|
141
|
+
napi_property_attributes attributes = napi_default,
|
|
142
|
+
void* data = nullptr);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- `[in] method`: The native function that represents a method provided by the
|
|
146
|
+
add-on.
|
|
147
|
+
- `[in] utf8name`: Null-terminated string that represents the name of the method
|
|
148
|
+
provided by instances of the class.
|
|
149
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
150
|
+
`napi_property_attributes`.
|
|
151
|
+
- `[in] data`: User-provided data passed into the method when it is invoked.
|
|
152
|
+
|
|
153
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
|
|
154
|
+
provided by instances of the class. The method must be of the form
|
|
155
|
+
|
|
156
|
+
```cpp
|
|
157
|
+
void MethodName(const Napi::CallbackInfo& info);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### InstanceMethod
|
|
161
|
+
|
|
162
|
+
Creates a property descriptor that represents a method exposed on JavaScript
|
|
163
|
+
instances of this class.
|
|
164
|
+
|
|
165
|
+
```cpp
|
|
166
|
+
template <typename T>
|
|
167
|
+
template <typename InstanceWrap<T>::InstanceMethodCallback method>
|
|
168
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
169
|
+
Napi::InstanceWrap<T>::InstanceMethod(const char* utf8name,
|
|
170
|
+
napi_property_attributes attributes = napi_default,
|
|
171
|
+
void* data = nullptr);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
- `[in] method`: The native function that represents a method provided by the
|
|
175
|
+
add-on.
|
|
176
|
+
- `[in] utf8name`: Null-terminated string that represents the name of the method
|
|
177
|
+
provided by instances of the class.
|
|
178
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
179
|
+
`napi_property_attributes`.
|
|
180
|
+
- `[in] data`: User-provided data passed into the method when it is invoked.
|
|
181
|
+
|
|
182
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
|
|
183
|
+
provided by instances of the class. The method must be of the form
|
|
184
|
+
|
|
185
|
+
```cpp
|
|
186
|
+
Napi::Value MethodName(const Napi::CallbackInfo& info);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### InstanceMethod
|
|
190
|
+
|
|
191
|
+
Creates a property descriptor that represents a method exposed on JavaScript
|
|
192
|
+
instances of this class.
|
|
193
|
+
|
|
194
|
+
```cpp
|
|
195
|
+
template <typename T>
|
|
196
|
+
template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
|
|
197
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
198
|
+
Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
|
|
199
|
+
napi_property_attributes attributes = napi_default,
|
|
200
|
+
void* data = nullptr);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
- `[in] method`: The native function that represents a method provided by the
|
|
204
|
+
add-on.
|
|
205
|
+
- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
|
|
206
|
+
instance method for the class.
|
|
207
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
208
|
+
`napi_property_attributes`.
|
|
209
|
+
- `[in] data`: User-provided data passed into the method when it is invoked.
|
|
210
|
+
|
|
211
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
|
|
212
|
+
provided by instances of the class. The method must be of the form
|
|
213
|
+
|
|
214
|
+
```cpp
|
|
215
|
+
void MethodName(const Napi::CallbackInfo& info);
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### InstanceMethod
|
|
219
|
+
|
|
220
|
+
Creates a property descriptor that represents a method exposed on JavaScript
|
|
221
|
+
instances of this class.
|
|
222
|
+
|
|
223
|
+
```cpp
|
|
224
|
+
template <typename T>
|
|
225
|
+
template <InstanceWrap<T>::InstanceMethodCallback method>
|
|
226
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
227
|
+
Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
|
|
228
|
+
napi_property_attributes attributes = napi_default,
|
|
229
|
+
void* data = nullptr);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- `[in] method`: The native function that represents a method provided by the
|
|
233
|
+
add-on.
|
|
234
|
+
- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
|
|
235
|
+
instance method for the class.
|
|
236
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
237
|
+
`napi_property_attributes`.
|
|
238
|
+
- `[in] data`: User-provided data passed into the method when it is invoked.
|
|
239
|
+
|
|
240
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
|
|
241
|
+
provided by instances of the class. The method must be of the form
|
|
242
|
+
|
|
243
|
+
```cpp
|
|
244
|
+
Napi::Value MethodName(const Napi::CallbackInfo& info);
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### InstanceAccessor
|
|
248
|
+
|
|
249
|
+
Creates a property descriptor that represents a property exposed on JavaScript
|
|
250
|
+
instances of this class.
|
|
251
|
+
|
|
252
|
+
```cpp
|
|
253
|
+
template <typename T>
|
|
254
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
255
|
+
Napi::InstanceWrap<T>::InstanceAccessor(const char* utf8name,
|
|
256
|
+
InstanceGetterCallback getter,
|
|
257
|
+
InstanceSetterCallback setter,
|
|
258
|
+
napi_property_attributes attributes = napi_default,
|
|
259
|
+
void* data = nullptr);
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
- `[in] utf8name`: Null-terminated string that represents the name of the method
|
|
263
|
+
provided by instances of the class.
|
|
264
|
+
- `[in] getter`: The native function to call when a get access to the property
|
|
265
|
+
is performed.
|
|
266
|
+
- `[in] setter`: The native function to call when a set access to the property
|
|
267
|
+
is performed.
|
|
268
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
269
|
+
`napi_property_attributes`.
|
|
270
|
+
- `[in] data`: User-provided data passed into the getter or the setter when it
|
|
271
|
+
is invoked.
|
|
272
|
+
|
|
273
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
|
|
274
|
+
accessor property provided by instances of the class.
|
|
275
|
+
|
|
276
|
+
### InstanceAccessor
|
|
277
|
+
|
|
278
|
+
Creates a property descriptor that represents a property exposed on JavaScript
|
|
279
|
+
instances of this class.
|
|
280
|
+
|
|
281
|
+
```cpp
|
|
282
|
+
template <typename T>
|
|
283
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
284
|
+
Napi::InstanceWrap<T>::InstanceAccessor(Symbol name,
|
|
285
|
+
InstanceGetterCallback getter,
|
|
286
|
+
InstanceSetterCallback setter,
|
|
287
|
+
napi_property_attributes attributes = napi_default,
|
|
288
|
+
void* data = nullptr);
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
|
|
292
|
+
instance accessor.
|
|
293
|
+
- `[in] getter`: The native function to call when a get access to the property of
|
|
294
|
+
a JavaScript class is performed.
|
|
295
|
+
- `[in] setter`: The native function to call when a set access to the property of
|
|
296
|
+
a JavaScript class is performed.
|
|
297
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
298
|
+
`napi_property_attributes`.
|
|
299
|
+
- `[in] data`: User-provided data passed into the getter or the setter when it
|
|
300
|
+
is invoked.
|
|
301
|
+
|
|
302
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
|
|
303
|
+
accessor property provided instances of the class.
|
|
304
|
+
|
|
305
|
+
### InstanceAccessor
|
|
306
|
+
|
|
307
|
+
Creates a property descriptor that represents a property exposed on JavaScript
|
|
308
|
+
instances of this class.
|
|
309
|
+
|
|
310
|
+
```cpp
|
|
311
|
+
template <typename T>
|
|
312
|
+
template <typename InstanceWrap<T>::InstanceGetterCallback getter,
|
|
313
|
+
typename InstanceWrap<T>::InstanceSetterCallback setter=nullptr>
|
|
314
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
315
|
+
Napi::InstanceWrap<T>::InstanceAccessor(const char* utf8name,
|
|
316
|
+
napi_property_attributes attributes = napi_default,
|
|
317
|
+
void* data = nullptr);
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
- `[in] getter`: The native function to call when a get access to the property of
|
|
321
|
+
a JavaScript class is performed.
|
|
322
|
+
- `[in] setter`: The native function to call when a set access to the property of
|
|
323
|
+
a JavaScript class is performed.
|
|
324
|
+
- `[in] utf8name`: Null-terminated string that represents the name of the method
|
|
325
|
+
provided by instances of the class.
|
|
326
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
327
|
+
`napi_property_attributes`.
|
|
328
|
+
- `[in] data`: User-provided data passed into the getter or the setter when it
|
|
329
|
+
is invoked.
|
|
330
|
+
|
|
331
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
|
|
332
|
+
accessor property provided by instances of the class.
|
|
333
|
+
|
|
334
|
+
### InstanceAccessor
|
|
335
|
+
|
|
336
|
+
Creates a property descriptor that represents a property exposed on JavaScript
|
|
337
|
+
instances of this class.
|
|
338
|
+
|
|
339
|
+
```cpp
|
|
340
|
+
template <typename T>
|
|
341
|
+
template <typename InstanceWrap<T>::InstanceGetterCallback getter,
|
|
342
|
+
typename InstanceWrap<T>::InstanceSetterCallback setter=nullptr>
|
|
343
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
344
|
+
Napi::InstanceWrap<T>::InstanceAccessor(Symbol name,
|
|
345
|
+
napi_property_attributes attributes = napi_default,
|
|
346
|
+
void* data = nullptr);
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
- `[in] getter`: The native function to call when a get access to the property of
|
|
350
|
+
a JavaScript class is performed.
|
|
351
|
+
- `[in] setter`: The native function to call when a set access to the property of
|
|
352
|
+
a JavaScript class is performed.
|
|
353
|
+
- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
|
|
354
|
+
instance accessor.
|
|
355
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
356
|
+
`napi_property_attributes`.
|
|
357
|
+
- `[in] data`: User-provided data passed into the getter or the setter when it
|
|
358
|
+
is invoked.
|
|
359
|
+
|
|
360
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
|
|
361
|
+
accessor property provided by instances of the class.
|
|
362
|
+
|
|
363
|
+
### InstanceValue
|
|
364
|
+
|
|
365
|
+
Creates property descriptor that represents a value exposed on JavaScript
|
|
366
|
+
instances of this class.
|
|
367
|
+
|
|
368
|
+
```cpp
|
|
369
|
+
template <typename T>
|
|
370
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
371
|
+
Napi::InstanceWrap<T>::InstanceValue(const char* utf8name,
|
|
372
|
+
Napi::Value value,
|
|
373
|
+
napi_property_attributes attributes = napi_default);
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
- `[in] utf8name`: Null-terminated string that represents the name of the
|
|
377
|
+
property.
|
|
378
|
+
- `[in] value`: The value that's retrieved by a get access of the property.
|
|
379
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
380
|
+
`napi_property_attributes`.
|
|
381
|
+
|
|
382
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
|
|
383
|
+
value property of an add-on.
|
|
384
|
+
|
|
385
|
+
### InstanceValue
|
|
386
|
+
|
|
387
|
+
Creates property descriptor that represents a value exposed on JavaScript
|
|
388
|
+
instances of this class.
|
|
389
|
+
|
|
390
|
+
```cpp
|
|
391
|
+
template <typename T>
|
|
392
|
+
static Napi::ClassPropertyDescriptor<T>
|
|
393
|
+
Napi::InstanceWrap<T>::InstanceValue(Symbol name,
|
|
394
|
+
Napi::Value value,
|
|
395
|
+
napi_property_attributes attributes = napi_default);
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
|
|
399
|
+
name of the property.
|
|
400
|
+
- `[in] value`: The value that's retrieved by a get access of the property.
|
|
401
|
+
- `[in] attributes`: The attributes associated with the property. One or more of
|
|
402
|
+
`napi_property_attributes`.
|
|
403
|
+
|
|
404
|
+
Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
|
|
405
|
+
value property of an add-on.
|
|
406
|
+
|
|
407
|
+
[`Napi::Addon<T>`]: ./addon.md
|
|
408
|
+
[`Napi::ObjectWrap<T>`]: ./object_wrap.md
|
package/doc/name.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Name
|
|
2
|
+
|
|
3
|
+
Class `Napi::Name` inherits from class [`Napi::Value`][].
|
|
4
|
+
|
|
5
|
+
Names are JavaScript values that can be used as a property name. There are two
|
|
6
|
+
specialized types of names supported in Node.js Addon API [`Napi::String`](string.md)
|
|
7
|
+
and [`Napi::Symbol`](symbol.md).
|
|
8
|
+
|
|
9
|
+
## Methods
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
```cpp
|
|
13
|
+
Napi::Name::Name();
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Returns an empty `Napi::Name`.
|
|
17
|
+
|
|
18
|
+
```cpp
|
|
19
|
+
Napi::Name::Name(napi_env env, napi_value value);
|
|
20
|
+
```
|
|
21
|
+
- `[in] env` - The environment in which to create the array.
|
|
22
|
+
- `[in] value` - The primitive to wrap.
|
|
23
|
+
|
|
24
|
+
Returns a `Napi::Name` created from the JavaScript primitive.
|
|
25
|
+
|
|
26
|
+
Note:
|
|
27
|
+
The value is not coerced to a string.
|
|
28
|
+
|
|
29
|
+
[`Napi::Value`]: ./value.md
|
package/doc/object.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# Object
|
|
2
2
|
|
|
3
|
+
Class `Napi::Object` inherits from class [`Napi::Value`][].
|
|
4
|
+
|
|
3
5
|
The `Napi::Object` class corresponds to a JavaScript object. It is extended by the following node-addon-api classes that you may use when working with more specific types:
|
|
4
6
|
|
|
5
|
-
- [`Napi::
|
|
7
|
+
- [`Napi::Array`](array.md)
|
|
6
8
|
- [`Napi::ArrayBuffer`](array_buffer.md)
|
|
7
9
|
- [`Napi::Buffer<T>`](buffer.md)
|
|
8
10
|
- [`Napi::Function`](function.md)
|
|
@@ -192,7 +194,7 @@ where `data` and `hint` are the pointers that were passed into the call to `AddF
|
|
|
192
194
|
Napi::Array Napi::Object::GetPropertyNames() const;
|
|
193
195
|
```
|
|
194
196
|
|
|
195
|
-
Returns the names of the enumerable properties of the object as a [`Napi::Array`](
|
|
197
|
+
Returns the names of the enumerable properties of the object as a [`Napi::Array`](array.md) of strings.
|
|
196
198
|
The properties whose key is a `Symbol` will not be included.
|
|
197
199
|
|
|
198
200
|
### HasOwnProperty()
|
|
@@ -273,3 +275,5 @@ Napi::Value Napi::Object::operator[] (uint32_t index) const;
|
|
|
273
275
|
- `[in] index`: Element index.
|
|
274
276
|
|
|
275
277
|
Returns an indexed property or array element as a [`Napi::Value`](value.md).
|
|
278
|
+
|
|
279
|
+
[`Napi::Value`]: ./value.md
|