-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: return Maybe<> on pending exception when cpp exception disabled
- Loading branch information
1 parent
60348d1
commit 9684123
Showing
32 changed files
with
1,237 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Maybe (template) | ||
|
||
Class `Napi::Maybe<T>` represents an maybe empty value: every `Maybe` is either | ||
`Just` and contains a value, or `Nothing`, and does not. `Maybe` types are very | ||
common in node-addon-api code, as they represent the function may throw a | ||
JavaScript exception and cause the program unable to evaluation any JavaScript | ||
code until the exception is been handled. | ||
|
||
Typically, the value wrapped in `Napi::Maybe<T>` is [`Napi::Value`] and its | ||
subclasses. | ||
|
||
## Methods | ||
|
||
### IsNothing | ||
|
||
```cpp | ||
template <typename T> | ||
bool Napi::Maybe::IsNothing() const; | ||
``` | ||
|
||
Returns if the `Maybe` is `Nothing` and does not contain a value. | ||
|
||
### IsJust | ||
|
||
```cpp | ||
template <typename T> | ||
bool Napi::Maybe::IsJust() const; | ||
``` | ||
|
||
Returns if the `Maybe` is `Just` and contains a value. | ||
|
||
### Check | ||
|
||
```cpp | ||
template <typename T> | ||
void Napi::Maybe::Check() const; | ||
``` | ||
|
||
Short-hand for `Maybe::Unwrap()`, which doesn't return a value. Could be used | ||
where the actual value of the Maybe is not needed like `Object::Set`. | ||
If this Maybe is nothing (empty), node-addon-api will crash the | ||
process. | ||
|
||
### Unwrap | ||
|
||
```cpp | ||
template <typename T> | ||
T Napi::Maybe::Unwrap() const; | ||
``` | ||
|
||
Return the value of type `T` contained in the Maybe. If this Maybe is | ||
nothing (empty), node-addon-api will crash the process. | ||
|
||
### UnwrapOr | ||
|
||
```cpp | ||
template <typename T> | ||
T Napi::Maybe::UnwrapOr(const T& default_value) const; | ||
``` | ||
Return the value of type T contained in the Maybe, or using a default | ||
value if this Maybe is nothing (empty). | ||
### UnwrapTo | ||
```cpp | ||
template <typename T> | ||
bool Napi::Maybe::UnwrapTo() const; | ||
``` | ||
|
||
Converts this Maybe to a value of type `T` in the `out`. If this Maybe is | ||
nothing (empty), `false` is returned and `out is left untouched. | ||
|
||
[`Napi::Value`]: ./value.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.