Skip to content

Commit

Permalink
Avoid creating BigInt implicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed May 1, 2024
1 parent 7944943 commit 2cc3e23
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,6 @@ struct Type<int64_t> {
}
};

template<>
struct Type<uint64_t> {
static constexpr const char* name = "BigInt";
static inline napi_status ToNode(napi_env env,
uint64_t value,
napi_value* result) {
return napi_create_bigint_uint64(env, value, result);
}
static inline std::optional<uint64_t> FromNode(napi_env env,
napi_value value) {
uint64_t result;
bool lossless;
if (napi_get_value_bigint_uint64(env, value, &result, &lossless) == napi_ok)
return result;
return std::nullopt;
}
};

#if defined(__APPLE__)
template<>
struct Type<size_t> {
Expand Down Expand Up @@ -254,6 +236,23 @@ struct Type<double> {
}
};

template<>
struct Type<uint64_t> {
static constexpr const char* name = "Integer";
static inline napi_status ToNode(napi_env env,
uint64_t value,
napi_value* result) {
return Type<double>::ToNode(env, static_cast<double>(value), result);
}
static inline std::optional<uint64_t> FromNode(napi_env env,
napi_value value) {
auto result = Type<double>::FromNode(env, value);
if (!result)
return std::nullopt;
return static_cast<uint64_t>(*result);
}
};

template<>
struct Type<bool> {
static constexpr const char* name = "Boolean";
Expand Down

0 comments on commit 2cc3e23

Please sign in to comment.