Skip to content

Commit

Permalink
fix: mark external memory and version APIs as basic (#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas authored Oct 25, 2024
1 parent 8b5b8b7 commit 78da4fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion doc/memory_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ more often than it would otherwise in an attempt to garbage collect the JavaScri
objects that keep the externally allocated memory alive.

```cpp
static int64_t Napi::MemoryManagement::AdjustExternalMemory(Napi::Env env, int64_t change_in_bytes);
static int64_t Napi::MemoryManagement::AdjustExternalMemory(Napi::BasicEnv env, int64_t change_in_bytes);
```
- `[in] env`: The environment in which the API is invoked under.
Expand Down
4 changes: 2 additions & 2 deletions doc/version_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ important to make decisions based on different versions of the system.
Retrieves the highest Node-API version supported by Node.js runtime.

```cpp
static uint32_t Napi::VersionManagement::GetNapiVersion(Env env);
static uint32_t Napi::VersionManagement::GetNapiVersion(Napi::BasicEnv env);
```
- `[in] env`: The environment in which the API is invoked under.
Expand All @@ -34,7 +34,7 @@ typedef struct {
````

```cpp
static const napi_node_version* Napi::VersionManagement::GetNodeVersion(Env env);
static const napi_node_version* Napi::VersionManagement::GetNodeVersion(Napi::BasicEnv env);
```
- `[in] env`: The environment in which the API is invoked under.
Expand Down
17 changes: 11 additions & 6 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6699,30 +6699,35 @@ inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(
// Memory Management class
////////////////////////////////////////////////////////////////////////////////

inline int64_t MemoryManagement::AdjustExternalMemory(Env env,
inline int64_t MemoryManagement::AdjustExternalMemory(BasicEnv env,
int64_t change_in_bytes) {
int64_t result;
napi_status status =
napi_adjust_external_memory(env, change_in_bytes, &result);
NAPI_THROW_IF_FAILED(env, status, 0);
NAPI_FATAL_IF_FAILED(status,
"MemoryManagement::AdjustExternalMemory",
"napi_adjust_external_memory");
return result;
}

////////////////////////////////////////////////////////////////////////////////
// Version Management class
////////////////////////////////////////////////////////////////////////////////

inline uint32_t VersionManagement::GetNapiVersion(Env env) {
inline uint32_t VersionManagement::GetNapiVersion(BasicEnv env) {
uint32_t result;
napi_status status = napi_get_version(env, &result);
NAPI_THROW_IF_FAILED(env, status, 0);
NAPI_FATAL_IF_FAILED(
status, "VersionManagement::GetNapiVersion", "napi_get_version");
return result;
}

inline const napi_node_version* VersionManagement::GetNodeVersion(Env env) {
inline const napi_node_version* VersionManagement::GetNodeVersion(
BasicEnv env) {
const napi_node_version* result;
napi_status status = napi_get_node_version(env, &result);
NAPI_THROW_IF_FAILED(env, status, 0);
NAPI_FATAL_IF_FAILED(
status, "VersionManagement::GetNodeVersion", "napi_get_node_version");
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3234,14 +3234,14 @@ class AsyncProgressQueueWorker
// Memory management.
class MemoryManagement {
public:
static int64_t AdjustExternalMemory(Env env, int64_t change_in_bytes);
static int64_t AdjustExternalMemory(BasicEnv env, int64_t change_in_bytes);
};

// Version management
class VersionManagement {
public:
static uint32_t GetNapiVersion(Env env);
static const napi_node_version* GetNodeVersion(Env env);
static uint32_t GetNapiVersion(BasicEnv env);
static const napi_node_version* GetNodeVersion(BasicEnv env);
};

#if NAPI_VERSION > 5
Expand Down

0 comments on commit 78da4fa

Please sign in to comment.