Skip to content

Commit 7ecab46

Browse files
jschlightmhdawson
authored andcommitted
doc: Initial documetation for Basic Types.
PR-URL: #165 Reviewed-By: Michael Dawson <[email protected]>
1 parent 0c4c70a commit 7ecab46

File tree

4 files changed

+495
-0
lines changed

4 files changed

+495
-0
lines changed

doc/callbackinfo.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
**WORK IN PROGRESS, NOT YET COMPLETE**
2+
3+
# CallbackInfo
4+
5+
The object representing the components of the JavaScript request being made.
6+
7+
The CallbackInfo object is usually created and passed by the Node.js runtime or node-addon-api infrastructure.
8+
9+
The CallbackInfo object contains the arguments passed by the caller. The number of arguments is returned by the `Length` method. Each individual argument can be accessed using the `operator[]` method.
10+
11+
The `SetData` and `Data` methods are used to set and retrieve the data pointer contained in the CallbackInfo object.
12+
13+
## Methods
14+
15+
### Constructor
16+
17+
```cpp
18+
CallbackInfo(napi_env env, napi_callback_info info);
19+
```
20+
21+
- `[in] env`: The `napi_env` environment in which to construct the `CallbackInfo` object.
22+
- `[in] info`: The `napi_callback_info` data structure from which to construct the `CallbackInfo` object.
23+
24+
### Env
25+
26+
```cpp
27+
Napi::Env Env() const;
28+
```
29+
30+
Returns the `Env` object in which the request is being made.
31+
32+
### NewTarget
33+
34+
```cpp
35+
Value NewTarget() const;
36+
```
37+
38+
Returns the `new.target` value of the constructor call. If the function that was invoked (and for which the CallbackInfo was passed) is not a constructor call, a call to `IsEmpty()` on the returned value returns true.
39+
40+
### IsConstructCall
41+
42+
```cpp
43+
bool IsConstructCall() const;
44+
```
45+
46+
Returns a `bool` indicating if the function that was invoked (and for which the CallbackInfo was passed) is a constructor call.
47+
48+
49+
### Length
50+
51+
```cpp
52+
size_t Length() const;
53+
```
54+
55+
Returns the number of arguments passed in the Callabckinfo object.
56+
57+
### operator []
58+
59+
```cpp
60+
const Value operator [](size_t index) const;
61+
```
62+
63+
- `[in] index`: The zero-based index of the requested argument.
64+
65+
Returns a `Value` object containing the requested argument.
66+
67+
### This
68+
69+
```cpp
70+
Value This() const;
71+
```
72+
73+
Returns the JavaScript `this` value for the call
74+
75+
### Data
76+
77+
```cpp
78+
void* Data() const;
79+
```
80+
81+
Returns the data pointer for the callback.
82+
83+
### SetData
84+
85+
```cpp
86+
void SetData(void* data);
87+
```
88+
89+
- `[in] data`: The new data pointer to associate with this CallbackInfo object.
90+
91+
Returns `void`.
92+
93+
### Not documented here
94+
95+
```cpp
96+
~CallbackInfo();
97+
// Disallow copying to prevent multiple free of _dynamicArgs
98+
CallbackInfo(CallbackInfo const &) = delete;
99+
void operator=(CallbackInfo const &) = delete;
100+
```

doc/env.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
**WORK IN PROGRESS, NOT YET COMPLETE**
2+
3+
# Env
4+
5+
The opaque data structure containing the environment in which the request is being run.
6+
7+
The Env object is usually created and passed by the Node.js runtime or node-addon-api infrastructure.
8+
9+
## Methods
10+
11+
### Constructor
12+
13+
```cpp
14+
Env(napi_env env);
15+
```
16+
17+
- `[in] env`: The `napi_env` environment from which to construct the `Env` object.
18+
19+
### napi_env
20+
21+
```cpp
22+
operator napi_env() const;
23+
```
24+
25+
Returns the `napi_env` opaque data structure representing the environment.
26+
27+
### Global
28+
29+
```cpp
30+
Object Global() const;
31+
```
32+
33+
Returns the `Object` representing the environment's JavaScript Global Object.
34+
35+
### Undefined
36+
37+
```cpp
38+
Value Undefined() const;
39+
```
40+
41+
Returns the `Value` representing the environment's JavaScript Undefined Object.
42+
43+
### Null
44+
45+
```cpp
46+
Value Null() const;
47+
```
48+
49+
Returns the `Value` representing the environment's JavaScript Null Object.
50+
51+
### IsExceptionPending
52+
53+
```cpp
54+
bool IsExceptionPending() const;
55+
```
56+
57+
Returns a `bool` indicating if an exception is pending in the environment.
58+
59+
### GetAndClearPendingException
60+
61+
```cpp
62+
Error GetAndClearPendingException();
63+
```
64+
65+
Returns an `Error` object representing the environment's pending exception, if any.

doc/external.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
**WORK IN PROGRESS, NOT YET COMPLETE**
2+
3+
# External (template)
4+
5+
The External template class implements the ability to create a Value object with arbitrary C++ data. It is the user's responsibility to manage the memory for the arbitrary C++ data.
6+
7+
External objects can be created with an optional Finalizer function and optional Hint value. The Finalizer function, if specified, is called when your 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.
8+
9+
## Methods
10+
11+
### New
12+
13+
```cpp
14+
template <typename T>
15+
static External New(napi_env env, T* data);
16+
```
17+
18+
- `[in] env`: The `napi_env` environment in which to construct the External object.
19+
- `[in] data`: The arbitrary C++ data to be held by the External object.
20+
21+
Returns the created `External<T>` object.
22+
23+
### New
24+
25+
```cpp
26+
template <typename T>
27+
static External New(napi_env env,
28+
T* data,
29+
Finalizer finalizeCallback);
30+
```
31+
32+
- `[in] env`: The `napi_env` environment in which to construct the External object.
33+
- `[in] data`: The arbitrary C++ data to be held by the External object.
34+
- `[in] finalizeCallback`: A function called when the External object is released by the garbage collector accepting a T* and returning void.
35+
36+
Returns the created `External<T>` object.
37+
38+
### New
39+
40+
```cpp
41+
template <typename T>
42+
static External New(napi_env env,
43+
T* data,
44+
Finalizer finalizeCallback,
45+
Hint* finalizeHint);
46+
```
47+
48+
- `[in] env`: The `napi_env` environment in which to construct the External object.
49+
- `[in] data`: The arbitrary C++ data to be held by the External object.
50+
- `[in] finalizeCallback`: A function called when the External object is released by the garbage collector accepting T* and Hint* parameters and returning void.
51+
- `[in] finalizeHint`: A hint value passed to the `finalizeCallback` function.
52+
53+
Returns the created `External<T>` object.
54+
55+
### Data
56+
57+
```cpp
58+
T* Data() const;
59+
```
60+
61+
Returns a pointer to the arbitrary C++ data held by the External object.

0 commit comments

Comments
 (0)