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
|
# Env
Class `Napi::Env` inherits from class [`Napi::BasicEnv`][].
The data structure containing the environment in which the request is being run.
The `Napi::Env` object is usually created and passed by the Node.js runtime or
node-addon-api infrastructure.
The `Napi::Env` object represents an environment that has a superset of APIs
when compared to `Napi::BasicEnv` and therefore _cannot_ be used in basic
finalizers. See [Finalization][] for more details.
## Methods
### Constructor
```cpp
Napi::Env::Env(napi_env env);
```
- `[in] env`: The `napi_env` environment from which to construct the `Napi::Env` object.
### napi_env
```cpp
operator napi_env() const;
```
Returns the `napi_env` opaque data structure representing the environment.
### Global
```cpp
Napi::Object Napi::Env::Global() const;
```
Returns the `Napi::Object` representing the environment's JavaScript Global Object.
### Undefined
```cpp
Napi::Value Napi::Env::Undefined() const;
```
Returns the `Napi::Value` representing the environment's JavaScript Undefined Object.
### Null
```cpp
Napi::Value Napi::Env::Null() const;
```
Returns the `Napi::Value` representing the environment's JavaScript Null Object.
### IsExceptionPending
```cpp
bool Napi::Env::IsExceptionPending() const;
```
Returns a `bool` indicating if an exception is pending in the environment.
### GetAndClearPendingException
```cpp
Napi::Error Napi::Env::GetAndClearPendingException() const;
```
Returns an `Napi::Error` object representing the environment's pending exception, if any.
### RunScript
```cpp
Napi::Value Napi::Env::RunScript(____ script) const;
```
- `[in] script`: A string containing JavaScript code to execute.
Runs JavaScript code contained in a string and returns its result.
The `script` can be any of the following types:
- [`Napi::String`](string.md)
- `const char *`
- `const std::string &`
[`Napi::BasicEnv`]: ./basic_env.md
[Finalization]: ./finalization.md
|