From 3c89a9445a3fb6894493a1c67251b7a71fcf66a9 Mon Sep 17 00:00:00 2001 From: Kenvin Davies Date: Wed, 16 Oct 2019 20:52:52 +0200 Subject: [PATCH] src: add Env() to AsyncContext PR-URL: https://github.com/nodejs/node-addon-api/pull/568 Reviewed-By: NickNaso Reviewed-By: Michael Dawson Reviewed-By: Anna Henningsen --- doc/async_context.md | 10 ++++++++++ napi-inl.h | 4 ++++ napi.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/doc/async_context.md b/doc/async_context.md index 48de9c4..8e1f481 100644 --- a/doc/async_context.md +++ b/doc/async_context.md @@ -45,6 +45,16 @@ The `Napi::AsyncContext` to be destroyed. virtual Napi::AsyncContext::~AsyncContext(); ``` +### Env + +Requests the environment in which the async context has been initially created. + +```cpp +Napi::Env Env() const; +``` + +Returns the `Napi::Env` environment in which the async context has been created. + ## Operator ```cpp diff --git a/napi-inl.h b/napi-inl.h index 2718199..2313dd2 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -3589,6 +3589,10 @@ inline AsyncContext::operator napi_async_context() const { return _context; } +inline Napi::Env AsyncContext::Env() const { + return Napi::Env(_env); +} + //////////////////////////////////////////////////////////////////////////////// // AsyncWorker class //////////////////////////////////////////////////////////////////////////////// diff --git a/napi.h b/napi.h index 05b2914..510c196 100644 --- a/napi.h +++ b/napi.h @@ -1784,6 +1784,8 @@ namespace Napi { operator napi_async_context() const; + Napi::Env Env() const; + private: napi_env _env; napi_async_context _context;