File: callbackinfo.md

package info (click to toggle)
node-addon-api 8.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: cpp: 15,431; javascript: 5,631; ansic: 157; makefile: 7
file content (97 lines) | stat: -rw-r--r-- 2,547 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# CallbackInfo

The object representing the components of the JavaScript request being made.

The `Napi::CallbackInfo` object is usually created and passed by the Node.js runtime or node-addon-api infrastructure.

The `Napi::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.

The `SetData` and `Data` methods are used to set and retrieve the data pointer contained in the `Napi::CallbackInfo` object.

## Methods

### Constructor

```cpp
Napi::CallbackInfo::CallbackInfo(napi_env env, napi_callback_info info);
```

- `[in] env`: The `napi_env` environment in which to construct the `Napi::CallbackInfo` object.
- `[in] info`: The `napi_callback_info` data structure from which to construct the `Napi::CallbackInfo` object.

### Env

```cpp
Napi::Env Napi::CallbackInfo::Env() const;
```

Returns the `Env` object in which the request is being made.

### NewTarget

```cpp
Napi::Value Napi::CallbackInfo::NewTarget() const;
```

Returns the `new.target` value of the constructor call. If the function that was invoked (and for which the `Napi::NCallbackInfo` was passed) is not a constructor call, a call to `IsEmpty()` on the returned value returns true.

### IsConstructCall

```cpp
bool Napi::CallbackInfo::IsConstructCall() const;
```

Returns a `bool` indicating if the function that was invoked (and for which the `Napi::CallbackInfo` was passed) is a constructor call.

### Length

```cpp
size_t Napi::CallbackInfo::Length() const;
```

Returns the number of arguments passed in the `Napi::CallbackInfo` object.

### operator []

```cpp
const Napi::Value operator [](size_t index) const;
```

- `[in] index`: The zero-based index of the requested argument.

Returns a `Napi::Value` object containing the requested argument.

### This

```cpp
Napi::Value Napi::CallbackInfo::This() const;
```

Returns the JavaScript `this` value for the call

### Data

```cpp
void* Napi::CallbackInfo::Data() const;
```

Returns the data pointer for the callback.

### SetData

```cpp
void Napi::CallbackInfo::SetData(void* data);
```

- `[in] data`: The new data pointer to associate with this `Napi::CallbackInfo` object.

Returns `void`.

### Not documented here

```cpp
Napi::CallbackInfo::~CallbackInfo();
// Disallow copying to prevent multiple free of _dynamicArgs
Napi::CallbackInfo::CallbackInfo(CallbackInfo const &) = delete;
void Napi::CallbackInfo::operator=(CallbackInfo const &) = delete;
```