Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Jun 14, 2024
1 parent 0a5713d commit f6d6af0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
9 changes: 6 additions & 3 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "napi.h"

#include <algorithm>
#include <cstdarg>
#include <cstring>
#if NAPI_HAS_THREADS
#include <mutex>
Expand Down Expand Up @@ -340,11 +341,13 @@ struct AccessorCallbackData {
};

// Debugging-purpose C++-style variant of sprintf().
template <typename... Args>
inline std::string SPrintF(const char* format, Args&&... args) {
inline std::string StringFormat(const char* format, ...) {
char buf[256];
int ret = snprintf(buf, 256, format, args...);
va_list args;
va_start(args, format);
int ret = vsnprintf(buf, sizeof(buf), format, args);
NAPI_CHECK(ret >= 0, "SPrintF", "Malformed format");
va_end(args);
return buf;
}

Expand Down
17 changes: 10 additions & 7 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,20 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t),
#define NAPI_INTERNAL_CHECK(expr, location, ...) \
do { \
if (!(expr)) { \
std::string msg = Napi::details::SPrintF(__VA_ARGS__); \
Napi::Error::Fatal(location " " #expr, msg.c_str()); \
std::string msg = Napi::details::StringFormat(__VA_ARGS__); \
Napi::Error::Fatal(location, msg.c_str()); \
} \
} while (0)

#define NAPI_INTERNAL_CHECK_EQ(actual, expected, value_format, location) \
NAPI_INTERNAL_CHECK((actual) == (expected), \
location, \
"Expected " #actual " to be equal to " #expected \
", but got " value_format ".", \
actual)
do { \
auto actual_value = (actual); \
NAPI_INTERNAL_CHECK(actual_value == (expected), \
location, \
"Expected " #actual " to be equal to " #expected \
", but got " value_format ".", \
actual_value); \
} while (0)

#define NAPI_FATAL_IF_FAILED(status, location, message) \
NAPI_CHECK((status) == napi_ok, location, message)
Expand Down

0 comments on commit f6d6af0

Please sign in to comment.