|
| 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 | +``` |
0 commit comments