Skip to content

Commit

Permalink
fix(shared): Fix BigInts not being parsed properly
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Feb 15, 2024
1 parent c24bead commit 05d9152
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions server/src/classes/Metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void ValueSetter(js::PropertyContext& ctx)
if(!ctx.CheckExtraInternalFieldValue()) return;
alt::Metric* metric = ctx.GetExtraInternalFieldValue<alt::Metric>();

uint32_t value;
uint64_t value;
if(!ctx.GetValue(value)) return;

metric->SetValue(value);
Expand All @@ -65,7 +65,7 @@ static void Add(js::FunctionContext& ctx)
if(!ctx.CheckExtraInternalFieldValue()) return;
alt::Metric* metric = ctx.GetExtraInternalFieldValue<alt::Metric>();

uint32_t value;
uint64_t value;
if(!ctx.GetArg(0, value)) return;

metric->Add(value);
Expand Down
26 changes: 20 additions & 6 deletions shared/src/helpers/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,26 @@ namespace js
else if constexpr(std::is_same_v<T, int64_t> || std::is_same_v<T, uint64_t>)
{
constexpr bool isSigned = std::is_same_v<T, int64_t>;
v8::Local<v8::BigInt> bigInt;
v8::MaybeLocal<v8::BigInt> maybeBigInt = val->ToBigInt(v8::Isolate::GetCurrent()->GetEnteredOrMicrotaskContext());
if(!maybeBigInt.ToLocal(&bigInt)) return std::nullopt;
if constexpr(isSigned) return bigInt->Int64Value();
else
return bigInt->Uint64Value();

if (val->IsBigInt())
{
v8::Local<v8::BigInt> bigInt;
v8::MaybeLocal<v8::BigInt> maybeBigInt = val->ToBigInt(v8::Isolate::GetCurrent()->GetEnteredOrMicrotaskContext());
if(!maybeBigInt.ToLocal(&bigInt)) return std::nullopt;

if constexpr(isSigned)
return bigInt->Int64Value();
else
return bigInt->Uint64Value();
}

using Type = std::conditional_t<isSigned, int32_t, uint32_t>;
const auto _val = CppValue<Type>(val);

if (_val.has_value())
{
return static_cast<T>(_val.value());
}
}
else if constexpr(std::is_integral_v<T> || std::is_floating_point_v<T> || std::is_enum_v<T>)
{
Expand Down

0 comments on commit 05d9152

Please sign in to comment.