Skip to content

Commit e04304c

Browse files
committed
fixup
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 769be84 commit e04304c

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/ffi/data.cc

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ bool GetValidatedSize(Environment* env,
3636
const char* label,
3737
size_t* out) {
3838
if (!value->IsNumber()) {
39-
env->ThrowTypeError(
40-
(std::string("The ") + label + " must be a number").c_str());
39+
THROW_ERR_INVALID_ARG_VALUE(
40+
env, (std::string("The ") + label + " must be a number").c_str());
4141
return false;
4242
}
4343

4444
double length = value.As<Number>()->Value();
4545
if (!std::isfinite(length) || length < 0 || std::floor(length) != length) {
46-
env->ThrowTypeError(
46+
THROW_ERR_INVALID_ARG_VALUE(
47+
env,
4748
(std::string("The ") + label + " must be a non-negative integer")
4849
.c_str());
4950
return false;
@@ -64,15 +65,16 @@ bool GetValidatedPointerAddress(Environment* env,
6465
const char* label,
6566
uintptr_t* out) {
6667
if (!value->IsBigInt()) {
67-
env->ThrowTypeError(
68-
(std::string("The ") + label + " must be a bigint").c_str());
68+
THROW_ERR_INVALID_ARG_VALUE(
69+
env, (std::string("The ") + label + " must be a bigint").c_str());
6970
return false;
7071
}
7172

7273
bool lossless;
7374
uint64_t address = value.As<BigInt>()->Uint64Value(&lossless);
7475
if (!lossless) {
75-
env->ThrowTypeError(
76+
THROW_ERR_INVALID_ARG_VALUE(
77+
env,
7678
(std::string("The ") + label + " must be a non-negative bigint")
7779
.c_str());
7880
return false;
@@ -97,14 +99,16 @@ bool GetValidatedSignedInt(Environment* env,
9799
const char* type_name,
98100
int64_t* out) {
99101
if (!value->IsNumber()) {
100-
env->ThrowTypeError((std::string("Value must be an ") + type_name).c_str());
102+
THROW_ERR_INVALID_ARG_VALUE(
103+
env, (std::string("Value must be an ") + type_name).c_str());
101104
return false;
102105
}
103106

104107
double number = value.As<Number>()->Value();
105108
if (!std::isfinite(number) || std::floor(number) != number || number < min ||
106109
number > max) {
107-
env->ThrowTypeError((std::string("Value must be an ") + type_name).c_str());
110+
THROW_ERR_INVALID_ARG_VALUE(
111+
env, (std::string("Value must be an ") + type_name).c_str());
108112
return false;
109113
}
110114

@@ -118,14 +122,16 @@ bool GetValidatedUnsignedInt(Environment* env,
118122
const char* type_name,
119123
uint64_t* out) {
120124
if (!value->IsNumber()) {
121-
env->ThrowTypeError((std::string("Value must be a ") + type_name).c_str());
125+
THROW_ERR_INVALID_ARG_VALUE(
126+
env, (std::string("Value must be a ") + type_name).c_str());
122127
return false;
123128
}
124129

125130
double number = value.As<Number>()->Value();
126131
if (!std::isfinite(number) || std::floor(number) != number || number < 0 ||
127132
number > static_cast<double>(max)) {
128-
env->ThrowTypeError((std::string("Value must be a ") + type_name).c_str());
133+
THROW_ERR_INVALID_ARG_VALUE(
134+
env, (std::string("Value must be a ") + type_name).c_str());
129135
return false;
130136
}
131137

@@ -223,7 +229,7 @@ bool GetValidatedPointerValueAndOffset(Environment* env,
223229
}
224230

225231
if (args.Length() < 2 || args[1]->IsUndefined()) {
226-
env->ThrowTypeError("Expected an offset argument");
232+
THROW_ERR_INVALID_ARG_VALUE(env, "Expected an offset argument");
227233
return false;
228234
}
229235

@@ -241,7 +247,7 @@ bool GetValidatedPointerValueAndOffset(Environment* env,
241247
}
242248

243249
if (args.Length() < 3 || args[2]->IsUndefined()) {
244-
env->ThrowTypeError("Expected a value argument");
250+
THROW_ERR_INVALID_ARG_VALUE(env, "Expected a value argument");
245251
return false;
246252
}
247253

@@ -362,7 +368,7 @@ void SetValue(const FunctionCallbackInfo<Value>& args) {
362368
bool lossless;
363369
converted = static_cast<T>(value.As<BigInt>()->Int64Value(&lossless));
364370
if (!lossless) {
365-
env->ThrowTypeError("Value must be an int64");
371+
THROW_ERR_INVALID_ARG_VALUE(env, "Value must be an int64");
366372
return;
367373
}
368374
} else if (value->IsNumber()) {
@@ -377,15 +383,15 @@ void SetValue(const FunctionCallbackInfo<Value>& args) {
377383
}
378384
converted = static_cast<T>(validated);
379385
} else {
380-
env->ThrowTypeError("Value must be a bigint or a number");
386+
THROW_ERR_INVALID_ARG_VALUE(env, "Value must be a bigint or a number");
381387
return;
382388
}
383389
} else if constexpr (std::is_same_v<T, uint64_t>) {
384390
if (value->IsBigInt()) {
385391
bool lossless;
386392
converted = static_cast<T>(value.As<BigInt>()->Uint64Value(&lossless));
387393
if (!lossless) {
388-
env->ThrowTypeError("Value must be a uint64");
394+
THROW_ERR_INVALID_ARG_VALUE(env, "Value must be a uint64");
389395
return;
390396
}
391397
} else if (value->IsNumber()) {
@@ -399,15 +405,15 @@ void SetValue(const FunctionCallbackInfo<Value>& args) {
399405
}
400406
converted = static_cast<T>(validated);
401407
} else {
402-
env->ThrowTypeError("Value must be a bigint or a number");
408+
THROW_ERR_INVALID_ARG_VALUE(env, "Value must be a bigint or a number");
403409
return;
404410
}
405411
} else if constexpr (std::is_same_v<T, float> || std::is_same_v<T, double>) {
406412
MaybeLocal<Number> number = value->ToNumber(context);
407413
Local<Number> number_local;
408414

409415
if (!number.ToLocal(&number_local)) {
410-
env->ThrowTypeError("Value must be a number");
416+
THROW_ERR_INVALID_ARG_VALUE(env, "Value must be a number");
411417
return;
412418
}
413419

0 commit comments

Comments
 (0)