koffi 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/build/2.5.1/koffi_darwin_arm64/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_darwin_x64/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_freebsd_x64/koffi.node +0 -0
- package/build/2.5.1/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/2.5.1/koffi_linux_arm64/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_linux_ia32/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_linux_x64/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_openbsd_x64/koffi.node +0 -0
- package/build/2.5.1/koffi_win32_arm64/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_win32_ia32/koffi.node +0 -0
- package/build/{2.5.0 → 2.5.1}/koffi_win32_x64/koffi.node +0 -0
- package/package.json +2 -2
- package/src/core/libcc/brotli.cc +1 -1
- package/src/core/libcc/libcc.cc +53 -65
- package/src/core/libcc/libcc.hh +67 -28
- package/src/core/libcc/miniz.cc +2 -2
- package/src/koffi/CMakeLists.txt +1 -5
- package/src/koffi/src/abi_arm32.cc +35 -35
- package/src/koffi/src/abi_arm64.cc +34 -34
- package/src/koffi/src/abi_riscv64.cc +29 -29
- package/src/koffi/src/abi_x64_sysv.cc +29 -28
- package/src/koffi/src/abi_x64_win.cc +23 -23
- package/src/koffi/src/abi_x86.cc +27 -27
- package/src/koffi/src/call.cc +62 -69
- package/src/koffi/src/call.hh +2 -2
- package/src/koffi/src/ffi.cc +24 -24
- package/src/koffi/src/ffi.hh +4 -4
- package/src/koffi/src/parser.cc +1 -1
- package/src/koffi/src/trampolines/prototypes.inc +1 -1
- package/src/koffi/src/util.cc +7 -7
- package/src/koffi/src/util.hh +1 -1
- package/src/koffi/src/win32.hh +4 -4
- package/build/2.5.0/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.5.0/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/2.5.0/koffi_linux_arm64/koffi.node +0 -0
- package/build/2.5.0/koffi_win32_arm64/koffi.node +0 -0
- package/build/2.5.0/koffi_win32_x64/koffi.pdb +0 -0
- /package/build/{2.5.0 → 2.5.1}/koffi_win32_arm64/koffi.exp +0 -0
- /package/build/{2.5.0 → 2.5.1}/koffi_win32_arm64/koffi.lib +0 -0
- /package/build/{2.5.0 → 2.5.1}/koffi_win32_ia32/koffi.exp +0 -0
- /package/build/{2.5.0 → 2.5.1}/koffi_win32_ia32/koffi.lib +0 -0
- /package/build/{2.5.0 → 2.5.1}/koffi_win32_x64/koffi.exp +0 -0
- /package/build/{2.5.0 → 2.5.1}/koffi_win32_x64/koffi.lib +0 -0
|
@@ -226,11 +226,11 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
226
226
|
// registers just before the stack (so behind the vector ones).
|
|
227
227
|
// In the armv7hf calling convention, some arguments can end up
|
|
228
228
|
// partially in GPR, partially in the stack.
|
|
229
|
-
if (
|
|
229
|
+
if (!AllocStack(func->args_size, 16, &args_ptr)) [[unlikely]]
|
|
230
230
|
return false;
|
|
231
|
-
if (
|
|
231
|
+
if (!AllocStack(4 * 4, 8, &gpr_ptr)) [[unlikely]]
|
|
232
232
|
return false;
|
|
233
|
-
if (
|
|
233
|
+
if (!AllocStack(8 * 8, 8, &vec_ptr)) [[unlikely]]
|
|
234
234
|
return false;
|
|
235
235
|
if (func->ret.use_memory) {
|
|
236
236
|
return_ptr = AllocHeap(func->ret.type->size, 16);
|
|
@@ -239,7 +239,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
239
239
|
|
|
240
240
|
#define PUSH_INTEGER_32(CType) \
|
|
241
241
|
do { \
|
|
242
|
-
if (
|
|
242
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
243
243
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
244
244
|
return false; \
|
|
245
245
|
} \
|
|
@@ -249,7 +249,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
249
249
|
} while (false)
|
|
250
250
|
#define PUSH_INTEGER_32_SWAP(CType) \
|
|
251
251
|
do { \
|
|
252
|
-
if (
|
|
252
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
253
253
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
254
254
|
return false; \
|
|
255
255
|
} \
|
|
@@ -259,14 +259,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
259
259
|
} while (false)
|
|
260
260
|
#define PUSH_INTEGER_64(CType) \
|
|
261
261
|
do { \
|
|
262
|
-
if (
|
|
262
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
263
263
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
264
264
|
return false; \
|
|
265
265
|
} \
|
|
266
266
|
\
|
|
267
267
|
CType v = GetNumber<CType>(value); \
|
|
268
268
|
\
|
|
269
|
-
if (
|
|
269
|
+
if (param.gpr_count) [[likely]] { \
|
|
270
270
|
gpr_ptr = AlignUp(gpr_ptr, 8); \
|
|
271
271
|
*(uint64_t *)gpr_ptr = (uint64_t)v; \
|
|
272
272
|
gpr_ptr += param.gpr_count; \
|
|
@@ -278,14 +278,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
278
278
|
} while (false)
|
|
279
279
|
#define PUSH_INTEGER_64_SWAP(CType) \
|
|
280
280
|
do { \
|
|
281
|
-
if (
|
|
281
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
282
282
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
283
283
|
return false; \
|
|
284
284
|
} \
|
|
285
285
|
\
|
|
286
286
|
CType v = GetNumber<CType>(value); \
|
|
287
287
|
\
|
|
288
|
-
if (
|
|
288
|
+
if (param.gpr_count) [[likely]] { \
|
|
289
289
|
gpr_ptr = AlignUp(gpr_ptr, 8); \
|
|
290
290
|
*(uint64_t *)gpr_ptr = (uint64_t)ReverseBytes(v); \
|
|
291
291
|
gpr_ptr += param.gpr_count; \
|
|
@@ -307,7 +307,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
307
307
|
case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
|
|
308
308
|
|
|
309
309
|
case PrimitiveKind::Bool: {
|
|
310
|
-
if (
|
|
310
|
+
if (!value.IsBoolean()) [[unlikely]] {
|
|
311
311
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
|
|
312
312
|
return false;
|
|
313
313
|
}
|
|
@@ -331,28 +331,28 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
331
331
|
case PrimitiveKind::UInt64S: { PUSH_INTEGER_64_SWAP(uint64_t); } break;
|
|
332
332
|
case PrimitiveKind::String: {
|
|
333
333
|
const char *str;
|
|
334
|
-
if (
|
|
334
|
+
if (!PushString(value, param.directions, &str)) [[unlikely]]
|
|
335
335
|
return false;
|
|
336
336
|
|
|
337
337
|
*(const char **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str;
|
|
338
338
|
} break;
|
|
339
339
|
case PrimitiveKind::String16: {
|
|
340
340
|
const char16_t *str16;
|
|
341
|
-
if (
|
|
341
|
+
if (!PushString16(value, param.directions, &str16)) [[unlikely]]
|
|
342
342
|
return false;
|
|
343
343
|
|
|
344
344
|
*(const char16_t **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str16;
|
|
345
345
|
} break;
|
|
346
346
|
case PrimitiveKind::Pointer: {
|
|
347
347
|
void *ptr;
|
|
348
|
-
if (
|
|
348
|
+
if (!PushPointer(value, param.type, param.directions, &ptr)) [[unlikely]]
|
|
349
349
|
return false;
|
|
350
350
|
|
|
351
351
|
*(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
|
|
352
352
|
} break;
|
|
353
353
|
case PrimitiveKind::Record:
|
|
354
354
|
case PrimitiveKind::Union: {
|
|
355
|
-
if (
|
|
355
|
+
if (!IsObject(value)) [[unlikely]] {
|
|
356
356
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
|
|
357
357
|
return false;
|
|
358
358
|
}
|
|
@@ -385,14 +385,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
385
385
|
} break;
|
|
386
386
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
387
387
|
case PrimitiveKind::Float32: {
|
|
388
|
-
if (
|
|
388
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
|
|
389
389
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
|
|
390
390
|
return false;
|
|
391
391
|
}
|
|
392
392
|
|
|
393
393
|
float f = GetNumber<float>(value);
|
|
394
394
|
|
|
395
|
-
if (
|
|
395
|
+
if (param.vec_count) [[likely]] {
|
|
396
396
|
*(float *)(vec_ptr++) = f;
|
|
397
397
|
} else if (param.gpr_count) {
|
|
398
398
|
*(float *)(gpr_ptr++) = f;
|
|
@@ -401,14 +401,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
401
401
|
}
|
|
402
402
|
} break;
|
|
403
403
|
case PrimitiveKind::Float64: {
|
|
404
|
-
if (
|
|
404
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
|
|
405
405
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
|
|
406
406
|
return false;
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
double d = GetNumber<double>(value);
|
|
410
410
|
|
|
411
|
-
if (
|
|
411
|
+
if (param.vec_count) [[likely]] {
|
|
412
412
|
*(double *)vec_ptr = d;
|
|
413
413
|
vec_ptr += 2;
|
|
414
414
|
} else if (param.gpr_count) {
|
|
@@ -428,7 +428,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
428
428
|
Napi::Function func = value.As<Napi::Function>();
|
|
429
429
|
|
|
430
430
|
ptr = ReserveTrampoline(param.type->ref.proto, func);
|
|
431
|
-
if (
|
|
431
|
+
if (!ptr) [[unlikely]]
|
|
432
432
|
return false;
|
|
433
433
|
} else if (CheckValueTag(instance, value, param.type->ref.marker)) {
|
|
434
434
|
ptr = value.As<Napi::External<void>>().Data();
|
|
@@ -566,7 +566,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
|
|
|
566
566
|
|
|
567
567
|
void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async, BackRegisters *out_reg)
|
|
568
568
|
{
|
|
569
|
-
if (
|
|
569
|
+
if (env.IsExceptionPending()) [[unlikely]]
|
|
570
570
|
return;
|
|
571
571
|
|
|
572
572
|
const TrampolineInfo &trampoline = shared.trampolines[idx];
|
|
@@ -583,7 +583,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
583
583
|
|
|
584
584
|
RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
|
|
585
585
|
|
|
586
|
-
if (
|
|
586
|
+
if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
|
|
587
587
|
ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
|
|
588
588
|
return;
|
|
589
589
|
}
|
|
@@ -789,7 +789,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
789
789
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
790
790
|
case PrimitiveKind::Float32: {
|
|
791
791
|
float f;
|
|
792
|
-
if (
|
|
792
|
+
if (param.vec_count) [[likely]] {
|
|
793
793
|
f = *(float *)(vec_ptr++);
|
|
794
794
|
} else if (param.gpr_count) {
|
|
795
795
|
f = *(float *)(gpr_ptr++);
|
|
@@ -802,7 +802,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
802
802
|
} break;
|
|
803
803
|
case PrimitiveKind::Float64: {
|
|
804
804
|
double d;
|
|
805
|
-
if (
|
|
805
|
+
if (param.vec_count) [[likely]] {
|
|
806
806
|
d = *(double *)vec_ptr;
|
|
807
807
|
vec_ptr += 2;
|
|
808
808
|
} else if (param.gpr_count) {
|
|
@@ -835,12 +835,12 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
835
835
|
}
|
|
836
836
|
Napi::Value value(env, ret);
|
|
837
837
|
|
|
838
|
-
if (
|
|
838
|
+
if (env.IsExceptionPending()) [[unlikely]]
|
|
839
839
|
return;
|
|
840
840
|
|
|
841
841
|
#define RETURN_INTEGER_32(CType) \
|
|
842
842
|
do { \
|
|
843
|
-
if (
|
|
843
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
844
844
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
845
845
|
return; \
|
|
846
846
|
} \
|
|
@@ -850,7 +850,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
850
850
|
} while (false)
|
|
851
851
|
#define RETURN_INTEGER_32_SWAP(CType) \
|
|
852
852
|
do { \
|
|
853
|
-
if (
|
|
853
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
854
854
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
855
855
|
return; \
|
|
856
856
|
} \
|
|
@@ -860,7 +860,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
860
860
|
} while (false)
|
|
861
861
|
#define RETURN_INTEGER_64(CType) \
|
|
862
862
|
do { \
|
|
863
|
-
if (
|
|
863
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
864
864
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
865
865
|
return; \
|
|
866
866
|
} \
|
|
@@ -872,7 +872,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
872
872
|
} while (false)
|
|
873
873
|
#define RETURN_INTEGER_64_SWAP(CType) \
|
|
874
874
|
do { \
|
|
875
|
-
if (
|
|
875
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
876
876
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
877
877
|
return; \
|
|
878
878
|
} \
|
|
@@ -887,7 +887,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
887
887
|
switch (type->primitive) {
|
|
888
888
|
case PrimitiveKind::Void: {} break;
|
|
889
889
|
case PrimitiveKind::Bool: {
|
|
890
|
-
if (
|
|
890
|
+
if (!value.IsBoolean()) [[unlikely]] {
|
|
891
891
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
|
|
892
892
|
return;
|
|
893
893
|
}
|
|
@@ -911,14 +911,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
911
911
|
case PrimitiveKind::UInt64S: { RETURN_INTEGER_64_SWAP(uint64_t); } break;
|
|
912
912
|
case PrimitiveKind::String: {
|
|
913
913
|
const char *str;
|
|
914
|
-
if (
|
|
914
|
+
if (!PushString(value, 1, &str)) [[unlikely]]
|
|
915
915
|
return;
|
|
916
916
|
|
|
917
917
|
out_reg->r0 = (uint32_t)str;
|
|
918
918
|
} break;
|
|
919
919
|
case PrimitiveKind::String16: {
|
|
920
920
|
const char16_t *str16;
|
|
921
|
-
if (
|
|
921
|
+
if (!PushString16(value, 1, &str16)) [[unlikely]]
|
|
922
922
|
return;
|
|
923
923
|
|
|
924
924
|
out_reg->r0 = (uint32_t)str16;
|
|
@@ -947,7 +947,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
947
947
|
} break;
|
|
948
948
|
case PrimitiveKind::Record:
|
|
949
949
|
case PrimitiveKind::Union: {
|
|
950
|
-
if (
|
|
950
|
+
if (!IsObject(value)) [[unlikely]] {
|
|
951
951
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
|
|
952
952
|
return;
|
|
953
953
|
}
|
|
@@ -966,7 +966,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
966
966
|
} break;
|
|
967
967
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
968
968
|
case PrimitiveKind::Float32: {
|
|
969
|
-
if (
|
|
969
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
|
|
970
970
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
|
|
971
971
|
return;
|
|
972
972
|
}
|
|
@@ -979,7 +979,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
979
979
|
#endif
|
|
980
980
|
} break;
|
|
981
981
|
case PrimitiveKind::Float64: {
|
|
982
|
-
if (
|
|
982
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
|
|
983
983
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
|
|
984
984
|
return;
|
|
985
985
|
}
|
|
@@ -998,7 +998,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
998
998
|
Napi::Function func2 = value.As<Napi::Function>();
|
|
999
999
|
|
|
1000
1000
|
ptr = ReserveTrampoline(type->ref.proto, func2);
|
|
1001
|
-
if (
|
|
1001
|
+
if (!ptr) [[unlikely]]
|
|
1002
1002
|
return;
|
|
1003
1003
|
} else if (CheckValueTag(instance, value, type->ref.marker)) {
|
|
1004
1004
|
ptr = value.As<Napi::External<void>>().Data();
|
|
@@ -271,11 +271,11 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
271
271
|
uint64_t *vec_ptr = nullptr;
|
|
272
272
|
|
|
273
273
|
// Return through registers unless it's too big
|
|
274
|
-
if (
|
|
274
|
+
if (!AllocStack(func->args_size, 16, &args_ptr)) [[unlikely]]
|
|
275
275
|
return false;
|
|
276
|
-
if (
|
|
276
|
+
if (!AllocStack(8 * 8, 8, &vec_ptr)) [[unlikely]]
|
|
277
277
|
return false;
|
|
278
|
-
if (
|
|
278
|
+
if (!AllocStack(9 * 8, 8, &gpr_ptr)) [[unlikely]]
|
|
279
279
|
return false;
|
|
280
280
|
if (func->ret.use_memory) {
|
|
281
281
|
return_ptr = AllocHeap(func->ret.type->size, 16);
|
|
@@ -297,14 +297,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
297
297
|
#ifdef __APPLE__
|
|
298
298
|
#define PUSH_INTEGER(CType) \
|
|
299
299
|
do { \
|
|
300
|
-
if (
|
|
300
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
301
301
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
302
302
|
return false; \
|
|
303
303
|
} \
|
|
304
304
|
\
|
|
305
305
|
CType v = GetNumber<CType>(value); \
|
|
306
306
|
\
|
|
307
|
-
if (
|
|
307
|
+
if (param.gpr_count) [[likely]] { \
|
|
308
308
|
*(gpr_ptr++) = (uint64_t)v; \
|
|
309
309
|
} else { \
|
|
310
310
|
args_ptr = AlignUp(args_ptr, param.type->align); \
|
|
@@ -314,14 +314,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
314
314
|
} while (false)
|
|
315
315
|
#define PUSH_INTEGER_SWAP(CType) \
|
|
316
316
|
do { \
|
|
317
|
-
if (
|
|
317
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
318
318
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
319
319
|
return false; \
|
|
320
320
|
} \
|
|
321
321
|
\
|
|
322
322
|
CType v = GetNumber<CType>(value); \
|
|
323
323
|
\
|
|
324
|
-
if (
|
|
324
|
+
if (param.gpr_count) [[likely]] { \
|
|
325
325
|
*(gpr_ptr++) = (uint64_t)ReverseBytes(v); \
|
|
326
326
|
} else { \
|
|
327
327
|
args_ptr = AlignUp(args_ptr, param.type->align); \
|
|
@@ -332,7 +332,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
332
332
|
#else
|
|
333
333
|
#define PUSH_INTEGER(CType) \
|
|
334
334
|
do { \
|
|
335
|
-
if (
|
|
335
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
336
336
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
337
337
|
return false; \
|
|
338
338
|
} \
|
|
@@ -342,7 +342,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
342
342
|
} while (false)
|
|
343
343
|
#define PUSH_INTEGER_SWAP(CType) \
|
|
344
344
|
do { \
|
|
345
|
-
if (
|
|
345
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
346
346
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
347
347
|
return false; \
|
|
348
348
|
} \
|
|
@@ -363,7 +363,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
363
363
|
case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
|
|
364
364
|
|
|
365
365
|
case PrimitiveKind::Bool: {
|
|
366
|
-
if (
|
|
366
|
+
if (!value.IsBoolean()) [[unlikely]] {
|
|
367
367
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
|
|
368
368
|
return false;
|
|
369
369
|
}
|
|
@@ -371,7 +371,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
371
371
|
bool b = value.As<Napi::Boolean>();
|
|
372
372
|
|
|
373
373
|
#ifdef __APPLE__
|
|
374
|
-
if (
|
|
374
|
+
if (param.gpr_count) [[likely]] {
|
|
375
375
|
*(gpr_ptr++) = (uint64_t)b;
|
|
376
376
|
} else {
|
|
377
377
|
*(uint8_t *)args_ptr = b;
|
|
@@ -397,7 +397,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
397
397
|
case PrimitiveKind::UInt64S: { PUSH_INTEGER_SWAP(uint64_t); } break;
|
|
398
398
|
case PrimitiveKind::String: {
|
|
399
399
|
const char *str;
|
|
400
|
-
if (
|
|
400
|
+
if (!PushString(value, param.directions, &str)) [[unlikely]]
|
|
401
401
|
return false;
|
|
402
402
|
|
|
403
403
|
#ifdef __APPLE__
|
|
@@ -407,7 +407,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
407
407
|
} break;
|
|
408
408
|
case PrimitiveKind::String16: {
|
|
409
409
|
const char16_t *str16;
|
|
410
|
-
if (
|
|
410
|
+
if (!PushString16(value, param.directions, &str16)) [[unlikely]]
|
|
411
411
|
return false;
|
|
412
412
|
|
|
413
413
|
#ifdef __APPLE__
|
|
@@ -417,7 +417,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
417
417
|
} break;
|
|
418
418
|
case PrimitiveKind::Pointer: {
|
|
419
419
|
void *ptr;
|
|
420
|
-
if (
|
|
420
|
+
if (!PushPointer(value, param.type, param.directions, &ptr)) [[unlikely]]
|
|
421
421
|
return false;
|
|
422
422
|
|
|
423
423
|
#ifdef __APPLE__
|
|
@@ -427,7 +427,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
427
427
|
} break;
|
|
428
428
|
case PrimitiveKind::Record:
|
|
429
429
|
case PrimitiveKind::Union: {
|
|
430
|
-
if (
|
|
430
|
+
if (!IsObject(value)) [[unlikely]] {
|
|
431
431
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
|
|
432
432
|
return false;
|
|
433
433
|
}
|
|
@@ -478,14 +478,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
478
478
|
} break;
|
|
479
479
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
480
480
|
case PrimitiveKind::Float32: {
|
|
481
|
-
if (
|
|
481
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
|
|
482
482
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
|
|
483
483
|
return false;
|
|
484
484
|
}
|
|
485
485
|
|
|
486
486
|
float f = GetNumber<float>(value);
|
|
487
487
|
|
|
488
|
-
if (
|
|
488
|
+
if (param.vec_count) [[likely]] {
|
|
489
489
|
memset((uint8_t *)vec_ptr + 4, 0, 4);
|
|
490
490
|
*(float *)(vec_ptr++) = f;
|
|
491
491
|
#ifdef _WIN32
|
|
@@ -505,14 +505,14 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
505
505
|
}
|
|
506
506
|
} break;
|
|
507
507
|
case PrimitiveKind::Float64: {
|
|
508
|
-
if (
|
|
508
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
|
|
509
509
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
|
|
510
510
|
return false;
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
double d = GetNumber<double>(value);
|
|
514
514
|
|
|
515
|
-
if (
|
|
515
|
+
if (param.vec_count) [[likely]] {
|
|
516
516
|
*(double *)(vec_ptr++) = d;
|
|
517
517
|
#ifdef _WIN32
|
|
518
518
|
} else if (param.gpr_count) {
|
|
@@ -532,7 +532,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
|
|
|
532
532
|
Napi::Function func = value.As<Napi::Function>();
|
|
533
533
|
|
|
534
534
|
ptr = ReserveTrampoline(param.type->ref.proto, func);
|
|
535
|
-
if (
|
|
535
|
+
if (!ptr) [[unlikely]]
|
|
536
536
|
return false;
|
|
537
537
|
} else if (CheckValueTag(instance, value, param.type->ref.marker)) {
|
|
538
538
|
ptr = value.As<Napi::External<void>>().Data();
|
|
@@ -707,7 +707,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
|
|
|
707
707
|
|
|
708
708
|
void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async, BackRegisters *out_reg)
|
|
709
709
|
{
|
|
710
|
-
if (
|
|
710
|
+
if (env.IsExceptionPending()) [[unlikely]]
|
|
711
711
|
return;
|
|
712
712
|
|
|
713
713
|
#ifdef _WIN32
|
|
@@ -741,7 +741,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
741
741
|
|
|
742
742
|
RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
|
|
743
743
|
|
|
744
|
-
if (
|
|
744
|
+
if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
|
|
745
745
|
ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
|
|
746
746
|
return;
|
|
747
747
|
}
|
|
@@ -1092,7 +1092,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1092
1092
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
1093
1093
|
case PrimitiveKind::Float32: {
|
|
1094
1094
|
float f;
|
|
1095
|
-
if (
|
|
1095
|
+
if (param.vec_count) [[likely]] {
|
|
1096
1096
|
f = *(float *)(vec_ptr++);
|
|
1097
1097
|
#ifdef _WIN32
|
|
1098
1098
|
} else if (param.gpr_count) {
|
|
@@ -1113,7 +1113,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1113
1113
|
} break;
|
|
1114
1114
|
case PrimitiveKind::Float64: {
|
|
1115
1115
|
double d;
|
|
1116
|
-
if (
|
|
1116
|
+
if (param.vec_count) [[likely]] {
|
|
1117
1117
|
d = *(double *)(vec_ptr++);
|
|
1118
1118
|
#ifdef _WIN32
|
|
1119
1119
|
} else if (param.gpr_count) {
|
|
@@ -1147,12 +1147,12 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1147
1147
|
}
|
|
1148
1148
|
Napi::Value value(env, ret);
|
|
1149
1149
|
|
|
1150
|
-
if (
|
|
1150
|
+
if (env.IsExceptionPending()) [[unlikely]]
|
|
1151
1151
|
return;
|
|
1152
1152
|
|
|
1153
1153
|
#define RETURN_INTEGER(CType) \
|
|
1154
1154
|
do { \
|
|
1155
|
-
if (
|
|
1155
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
1156
1156
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
1157
1157
|
return; \
|
|
1158
1158
|
} \
|
|
@@ -1162,7 +1162,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1162
1162
|
} while (false)
|
|
1163
1163
|
#define RETURN_INTEGER_SWAP(CType) \
|
|
1164
1164
|
do { \
|
|
1165
|
-
if (
|
|
1165
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
|
|
1166
1166
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
|
|
1167
1167
|
return; \
|
|
1168
1168
|
} \
|
|
@@ -1175,7 +1175,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1175
1175
|
switch (type->primitive) {
|
|
1176
1176
|
case PrimitiveKind::Void: {} break;
|
|
1177
1177
|
case PrimitiveKind::Bool: {
|
|
1178
|
-
if (
|
|
1178
|
+
if (!value.IsBoolean()) [[unlikely]] {
|
|
1179
1179
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
|
|
1180
1180
|
return;
|
|
1181
1181
|
}
|
|
@@ -1199,14 +1199,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1199
1199
|
case PrimitiveKind::UInt64S: { RETURN_INTEGER_SWAP(uint64_t); } break;
|
|
1200
1200
|
case PrimitiveKind::String: {
|
|
1201
1201
|
const char *str;
|
|
1202
|
-
if (
|
|
1202
|
+
if (!PushString(value, 1, &str)) [[unlikely]]
|
|
1203
1203
|
return;
|
|
1204
1204
|
|
|
1205
1205
|
out_reg->x0 = (uint64_t)str;
|
|
1206
1206
|
} break;
|
|
1207
1207
|
case PrimitiveKind::String16: {
|
|
1208
1208
|
const char16_t *str16;
|
|
1209
|
-
if (
|
|
1209
|
+
if (!PushString16(value, 1, &str16)) [[unlikely]]
|
|
1210
1210
|
return;
|
|
1211
1211
|
|
|
1212
1212
|
out_reg->x0 = (uint64_t)str16;
|
|
@@ -1235,7 +1235,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1235
1235
|
} break;
|
|
1236
1236
|
case PrimitiveKind::Record:
|
|
1237
1237
|
case PrimitiveKind::Union: {
|
|
1238
|
-
if (
|
|
1238
|
+
if (!IsObject(value)) [[unlikely]] {
|
|
1239
1239
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
|
|
1240
1240
|
return;
|
|
1241
1241
|
}
|
|
@@ -1257,7 +1257,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1257
1257
|
} break;
|
|
1258
1258
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
1259
1259
|
case PrimitiveKind::Float32: {
|
|
1260
|
-
if (
|
|
1260
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
|
|
1261
1261
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
|
|
1262
1262
|
return;
|
|
1263
1263
|
}
|
|
@@ -1268,7 +1268,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1268
1268
|
memcpy(&out_reg->d0, &f, 4);
|
|
1269
1269
|
} break;
|
|
1270
1270
|
case PrimitiveKind::Float64: {
|
|
1271
|
-
if (
|
|
1271
|
+
if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
|
|
1272
1272
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
|
|
1273
1273
|
return;
|
|
1274
1274
|
}
|
|
@@ -1283,7 +1283,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool async,
|
|
|
1283
1283
|
Napi::Function func2 = value.As<Napi::Function>();
|
|
1284
1284
|
|
|
1285
1285
|
ptr = ReserveTrampoline(type->ref.proto, func2);
|
|
1286
|
-
if (
|
|
1286
|
+
if (!ptr) [[unlikely]]
|
|
1287
1287
|
return;
|
|
1288
1288
|
} else if (CheckValueTag(instance, value, type->ref.marker)) {
|
|
1289
1289
|
ptr = value.As<Napi::External<void>>().Data();
|