koffi 2.1.0-beta.1 → 2.1.0-beta.2

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.
Files changed (99) hide show
  1. package/CMakeLists.txt +1 -1
  2. package/ChangeLog.md +17 -0
  3. package/build/qemu/2.1.0-beta.2/koffi_darwin_arm64.tar.gz +0 -0
  4. package/build/qemu/2.1.0-beta.2/koffi_darwin_x64.tar.gz +0 -0
  5. package/build/qemu/2.1.0-beta.2/koffi_freebsd_arm64.tar.gz +0 -0
  6. package/build/qemu/2.1.0-beta.2/koffi_freebsd_ia32.tar.gz +0 -0
  7. package/build/qemu/2.1.0-beta.2/koffi_freebsd_x64.tar.gz +0 -0
  8. package/build/qemu/2.1.0-beta.2/koffi_linux_arm32hf.tar.gz +0 -0
  9. package/build/qemu/2.1.0-beta.2/koffi_linux_arm64.tar.gz +0 -0
  10. package/build/qemu/2.1.0-beta.2/koffi_linux_ia32.tar.gz +0 -0
  11. package/build/qemu/2.1.0-beta.2/koffi_linux_riscv64hf64.tar.gz +0 -0
  12. package/build/qemu/2.1.0-beta.2/koffi_linux_x64.tar.gz +0 -0
  13. package/build/qemu/2.1.0-beta.2/koffi_openbsd_ia32.tar.gz +0 -0
  14. package/build/qemu/2.1.0-beta.2/koffi_openbsd_x64.tar.gz +0 -0
  15. package/build/qemu/2.1.0-beta.2/koffi_win32_arm64.tar.gz +0 -0
  16. package/build/qemu/2.1.0-beta.2/koffi_win32_ia32.tar.gz +0 -0
  17. package/build/qemu/2.1.0-beta.2/koffi_win32_x64.tar.gz +0 -0
  18. package/doc/functions.md +67 -1
  19. package/doc/templates/badges.html +1 -2
  20. package/doc/types.md +100 -147
  21. package/package.json +1 -1
  22. package/src/abi_arm32.cc +166 -2
  23. package/src/abi_arm64.cc +195 -2
  24. package/src/abi_riscv64.cc +106 -2
  25. package/src/abi_x64_sysv.cc +113 -3
  26. package/src/abi_x64_win.cc +112 -2
  27. package/src/abi_x86.cc +155 -4
  28. package/src/call.cc +199 -0
  29. package/src/ffi.cc +50 -18
  30. package/src/ffi.hh +12 -0
  31. package/build/qemu/2.1.0-beta.1/koffi_darwin_arm64.tar.gz +0 -0
  32. package/build/qemu/2.1.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
  33. package/build/qemu/2.1.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
  34. package/build/qemu/2.1.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
  35. package/build/qemu/2.1.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
  36. package/build/qemu/2.1.0-beta.1/koffi_linux_arm32hf.tar.gz +0 -0
  37. package/build/qemu/2.1.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
  38. package/build/qemu/2.1.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
  39. package/build/qemu/2.1.0-beta.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  40. package/build/qemu/2.1.0-beta.1/koffi_linux_x64.tar.gz +0 -0
  41. package/build/qemu/2.1.0-beta.1/koffi_openbsd_ia32.tar.gz +0 -0
  42. package/build/qemu/2.1.0-beta.1/koffi_openbsd_x64.tar.gz +0 -0
  43. package/build/qemu/2.1.0-beta.1/koffi_win32_arm64.tar.gz +0 -0
  44. package/build/qemu/2.1.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
  45. package/build/qemu/2.1.0-beta.1/koffi_win32_x64.tar.gz +0 -0
  46. package/doc/dist/html/.buildinfo +0 -4
  47. package/doc/dist/html/_sources/benchmarks.md.txt +0 -137
  48. package/doc/dist/html/_sources/changes.md.txt +0 -161
  49. package/doc/dist/html/_sources/contribute.md.txt +0 -127
  50. package/doc/dist/html/_sources/functions.md.txt +0 -355
  51. package/doc/dist/html/_sources/index.rst.txt +0 -39
  52. package/doc/dist/html/_sources/memory.md.txt +0 -32
  53. package/doc/dist/html/_sources/platforms.md.txt +0 -31
  54. package/doc/dist/html/_sources/start.md.txt +0 -100
  55. package/doc/dist/html/_sources/types.md.txt +0 -588
  56. package/doc/dist/html/_static/_sphinx_javascript_frameworks_compat.js +0 -134
  57. package/doc/dist/html/_static/basic.css +0 -932
  58. package/doc/dist/html/_static/bench_linux.png +0 -0
  59. package/doc/dist/html/_static/bench_windows.png +0 -0
  60. package/doc/dist/html/_static/custom.css +0 -22
  61. package/doc/dist/html/_static/debug.css +0 -69
  62. package/doc/dist/html/_static/doctools.js +0 -264
  63. package/doc/dist/html/_static/documentation_options.js +0 -14
  64. package/doc/dist/html/_static/file.png +0 -0
  65. package/doc/dist/html/_static/jquery-3.6.0.js +0 -10881
  66. package/doc/dist/html/_static/jquery.js +0 -2
  67. package/doc/dist/html/_static/language_data.js +0 -199
  68. package/doc/dist/html/_static/minus.png +0 -0
  69. package/doc/dist/html/_static/perf_linux_20220623.png +0 -0
  70. package/doc/dist/html/_static/perf_linux_20220623_2.png +0 -0
  71. package/doc/dist/html/_static/perf_windows_20220623.png +0 -0
  72. package/doc/dist/html/_static/perf_windows_20220623_2.png +0 -0
  73. package/doc/dist/html/_static/plus.png +0 -0
  74. package/doc/dist/html/_static/pygments.css +0 -252
  75. package/doc/dist/html/_static/scripts/furo-extensions.js +0 -0
  76. package/doc/dist/html/_static/scripts/furo.js +0 -3
  77. package/doc/dist/html/_static/scripts/furo.js.LICENSE.txt +0 -7
  78. package/doc/dist/html/_static/scripts/furo.js.map +0 -1
  79. package/doc/dist/html/_static/searchtools.js +0 -531
  80. package/doc/dist/html/_static/skeleton.css +0 -296
  81. package/doc/dist/html/_static/styles/furo-extensions.css +0 -2
  82. package/doc/dist/html/_static/styles/furo-extensions.css.map +0 -1
  83. package/doc/dist/html/_static/styles/furo.css +0 -2
  84. package/doc/dist/html/_static/styles/furo.css.map +0 -1
  85. package/doc/dist/html/_static/underscore-1.13.1.js +0 -2042
  86. package/doc/dist/html/_static/underscore.js +0 -6
  87. package/doc/dist/html/benchmarks.html +0 -572
  88. package/doc/dist/html/changes.html +0 -668
  89. package/doc/dist/html/contribute.html +0 -404
  90. package/doc/dist/html/functions.html +0 -657
  91. package/doc/dist/html/genindex.html +0 -254
  92. package/doc/dist/html/index.html +0 -360
  93. package/doc/dist/html/memory.html +0 -347
  94. package/doc/dist/html/objects.inv +0 -0
  95. package/doc/dist/html/platforms.html +0 -372
  96. package/doc/dist/html/search.html +0 -262
  97. package/doc/dist/html/searchindex.js +0 -1
  98. package/doc/dist/html/start.html +0 -385
  99. package/doc/dist/html/types.html +0 -1097
package/src/abi_x86.cc CHANGED
@@ -229,6 +229,17 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
229
229
  int32_t v = CopyNumber<int32_t>(value);
230
230
  *(int32_t *)((param.fast ? fast_ptr : args_ptr)++) = v;
231
231
  } break;
232
+ case PrimitiveKind::Int16S:
233
+ case PrimitiveKind::UInt16S:
234
+ case PrimitiveKind::Int32S: {
235
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
236
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
237
+ return false;
238
+ }
239
+
240
+ int32_t v = CopyNumber<int32_t>(value);
241
+ *(int32_t *)((param.fast ? fast_ptr : args_ptr)++) = ReverseBytes(v);
242
+ } break;
232
243
  case PrimitiveKind::UInt32: {
233
244
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
234
245
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
@@ -238,6 +249,15 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
238
249
  uint32_t v = CopyNumber<uint32_t>(value);
239
250
  *((param.fast ? fast_ptr : args_ptr)++) = v;
240
251
  } break;
252
+ case PrimitiveKind::UInt32S: {
253
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
254
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
255
+ return false;
256
+ }
257
+
258
+ uint32_t v = CopyNumber<uint32_t>(value);
259
+ *((param.fast ? fast_ptr : args_ptr)++) = ReverseBytes(v);
260
+ } break;
241
261
  case PrimitiveKind::Int64: {
242
262
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
243
263
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
@@ -248,6 +268,16 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
248
268
  *(int64_t *)args_ptr = v;
249
269
  args_ptr += 2;
250
270
  } break;
271
+ case PrimitiveKind::Int64S: {
272
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
273
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
274
+ return false;
275
+ }
276
+
277
+ int64_t v = CopyNumber<int64_t>(value);
278
+ *(int64_t *)args_ptr = ReverseBytes(v);
279
+ args_ptr += 2;
280
+ } break;
251
281
  case PrimitiveKind::UInt64: {
252
282
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
253
283
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
@@ -258,6 +288,16 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
258
288
  *(uint64_t *)args_ptr = v;
259
289
  args_ptr += 2;
260
290
  } break;
291
+ case PrimitiveKind::UInt64S: {
292
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
293
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
294
+ return false;
295
+ }
296
+
297
+ uint64_t v = CopyNumber<uint64_t>(value);
298
+ *(uint64_t *)args_ptr = ReverseBytes(v);
299
+ args_ptr += 2;
300
+ } break;
261
301
  case PrimitiveKind::String: {
262
302
  const char *str;
263
303
  if (RG_LIKELY(value.IsString())) {
@@ -382,11 +422,17 @@ void CallData::Execute()
382
422
  case PrimitiveKind::Int8:
383
423
  case PrimitiveKind::UInt8:
384
424
  case PrimitiveKind::Int16:
425
+ case PrimitiveKind::Int16S:
385
426
  case PrimitiveKind::UInt16:
427
+ case PrimitiveKind::UInt16S:
386
428
  case PrimitiveKind::Int32:
429
+ case PrimitiveKind::Int32S:
387
430
  case PrimitiveKind::UInt32:
431
+ case PrimitiveKind::UInt32S:
388
432
  case PrimitiveKind::Int64:
433
+ case PrimitiveKind::Int64S:
389
434
  case PrimitiveKind::UInt64:
435
+ case PrimitiveKind::UInt64S:
390
436
  case PrimitiveKind::String:
391
437
  case PrimitiveKind::String16:
392
438
  case PrimitiveKind::Pointer:
@@ -418,11 +464,17 @@ Napi::Value CallData::Complete()
418
464
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
419
465
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
420
466
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
467
+ case PrimitiveKind::Int16S: return Napi::Number::New(env, (double)ReverseBytes(result.i16));
421
468
  case PrimitiveKind::UInt16: return Napi::Number::New(env, (double)result.u16);
469
+ case PrimitiveKind::UInt16S: return Napi::Number::New(env, (double)ReverseBytes(result.u16));
422
470
  case PrimitiveKind::Int32: return Napi::Number::New(env, (double)result.i32);
471
+ case PrimitiveKind::Int32S: return Napi::Number::New(env, (double)ReverseBytes(result.i32));
423
472
  case PrimitiveKind::UInt32: return Napi::Number::New(env, (double)result.u32);
473
+ case PrimitiveKind::UInt32S: return Napi::Number::New(env, (double)ReverseBytes(result.u32));
424
474
  case PrimitiveKind::Int64: return NewBigInt(env, result.i64);
475
+ case PrimitiveKind::Int64S: return NewBigInt(env, ReverseBytes(result.i64));
425
476
  case PrimitiveKind::UInt64: return NewBigInt(env, result.u64);
477
+ case PrimitiveKind::UInt64S: return NewBigInt(env, ReverseBytes(result.u64));
426
478
  case PrimitiveKind::String: return result.ptr ? Napi::String::New(env, (const char *)result.ptr) : env.Null();
427
479
  case PrimitiveKind::String16: return result.ptr ? Napi::String::New(env, (const char16_t *)result.ptr) : env.Null();
428
480
  case PrimitiveKind::Pointer:
@@ -524,24 +576,52 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
524
576
  Napi::Value arg = Napi::Number::New(env, d);
525
577
  arguments.Append(arg);
526
578
  } break;
579
+ case PrimitiveKind::Int16S: {
580
+ int16_t v = *(int16_t *)(args_ptr++);
581
+ double d = (double)ReverseBytes(v);
582
+
583
+ Napi::Value arg = Napi::Number::New(env, d);
584
+ arguments.Append(arg);
585
+ } break;
527
586
  case PrimitiveKind::UInt16: {
528
587
  double d = (double)*(uint16_t *)(args_ptr++);
529
588
 
530
589
  Napi::Value arg = Napi::Number::New(env, d);
531
590
  arguments.Append(arg);
532
591
  } break;
592
+ case PrimitiveKind::UInt16S: {
593
+ uint16_t v = *(uint16_t *)(args_ptr++);
594
+ double d = (double)ReverseBytes(v);
595
+
596
+ Napi::Value arg = Napi::Number::New(env, d);
597
+ arguments.Append(arg);
598
+ } break;
533
599
  case PrimitiveKind::Int32: {
534
600
  double d = (double)*(int32_t *)(args_ptr++);
535
601
 
536
602
  Napi::Value arg = Napi::Number::New(env, d);
537
603
  arguments.Append(arg);
538
604
  } break;
605
+ case PrimitiveKind::Int32S: {
606
+ int32_t v = *(int32_t *)(args_ptr++);
607
+ double d = (double)ReverseBytes(v);
608
+
609
+ Napi::Value arg = Napi::Number::New(env, d);
610
+ arguments.Append(arg);
611
+ } break;
539
612
  case PrimitiveKind::UInt32: {
540
613
  double d = (double)*(uint32_t *)(args_ptr++);
541
614
 
542
615
  Napi::Value arg = Napi::Number::New(env, d);
543
616
  arguments.Append(arg);
544
617
  } break;
618
+ case PrimitiveKind::UInt32S: {
619
+ uint32_t v = *(uint32_t *)(args_ptr++);
620
+ double d = (double)ReverseBytes(v);
621
+
622
+ Napi::Value arg = Napi::Number::New(env, d);
623
+ arguments.Append(arg);
624
+ } break;
545
625
  case PrimitiveKind::Int64: {
546
626
  int64_t v = *(int64_t *)args_ptr;
547
627
  args_ptr += 2;
@@ -549,6 +629,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
549
629
  Napi::Value arg = NewBigInt(env, v);
550
630
  arguments.Append(arg);
551
631
  } break;
632
+ case PrimitiveKind::Int64S: {
633
+ int64_t v = *(int64_t *)args_ptr;
634
+ args_ptr += 2;
635
+
636
+ Napi::Value arg = NewBigInt(env, ReverseBytes(v));
637
+ arguments.Append(arg);
638
+ } break;
552
639
  case PrimitiveKind::UInt64: {
553
640
  uint64_t v = *(uint64_t *)args_ptr;
554
641
  args_ptr += 2;
@@ -556,6 +643,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
556
643
  Napi::Value arg = NewBigInt(env, v);
557
644
  arguments.Append(arg);
558
645
  } break;
646
+ case PrimitiveKind::UInt64S: {
647
+ uint64_t v = *(uint64_t *)args_ptr;
648
+ args_ptr += 2;
649
+
650
+ Napi::Value arg = NewBigInt(env, ReverseBytes(v));
651
+ arguments.Append(arg);
652
+ } break;
559
653
  case PrimitiveKind::String: {
560
654
  const char *str = *(const char **)(args_ptr++);
561
655
 
@@ -647,8 +741,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
647
741
  case PrimitiveKind::UInt8:
648
742
  case PrimitiveKind::Int16:
649
743
  case PrimitiveKind::UInt16:
650
- case PrimitiveKind::Int32:
651
- case PrimitiveKind::UInt32: {
744
+ case PrimitiveKind::Int32: {
652
745
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
653
746
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
654
747
  return;
@@ -657,8 +750,36 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
657
750
  int32_t v = CopyNumber<int32_t>(value);
658
751
  out_reg->eax = (uint32_t)v;
659
752
  } break;
660
- case PrimitiveKind::Int64:
661
- case PrimitiveKind::UInt64: {
753
+ case PrimitiveKind::Int16S:
754
+ case PrimitiveKind::UInt16S:
755
+ case PrimitiveKind::Int32S: {
756
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
757
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
758
+ return;
759
+ }
760
+
761
+ int32_t v = CopyNumber<int32_t>(value);
762
+ out_reg->eax = (uint32_t)ReverseBytes(v);
763
+ } break;
764
+ case PrimitiveKind::UInt32: {
765
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
766
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
767
+ return;
768
+ }
769
+
770
+ uint32_t v = CopyNumber<uint32_t>(value);
771
+ out_reg->eax = v;
772
+ } break;
773
+ case PrimitiveKind::UInt32S: {
774
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
775
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
776
+ return;
777
+ }
778
+
779
+ uint32_t v = CopyNumber<uint32_t>(value);
780
+ out_reg->eax = ReverseBytes(v);
781
+ } break;
782
+ case PrimitiveKind::Int64: {
662
783
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
663
784
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
664
785
  return;
@@ -668,6 +789,36 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
668
789
  out_reg->eax = (uint32_t)(v & 0xFFFFFFFFul);
669
790
  out_reg->edx = (uint32_t)(v << 32);
670
791
  } break;
792
+ case PrimitiveKind::Int64S: {
793
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
794
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
795
+ return;
796
+ }
797
+
798
+ int64_t v = ReverseBytes(CopyNumber<int64_t>(value));
799
+ out_reg->eax = (uint32_t)(v & 0xFFFFFFFFul);
800
+ out_reg->edx = (uint32_t)(v << 32);
801
+ } break;
802
+ case PrimitiveKind::UInt64: {
803
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
804
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
805
+ return;
806
+ }
807
+
808
+ uint64_t v = CopyNumber<uint64_t>(value);
809
+ out_reg->eax = (uint32_t)(v & 0xFFFFFFFFul);
810
+ out_reg->edx = (uint32_t)(v << 32);
811
+ } break;
812
+ case PrimitiveKind::UInt64S: {
813
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
814
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
815
+ return;
816
+ }
817
+
818
+ uint64_t v = ReverseBytes(CopyNumber<uint64_t>(value));
819
+ out_reg->eax = (uint32_t)(v & 0xFFFFFFFFul);
820
+ out_reg->edx = (uint32_t)(v << 32);
821
+ } break;
671
822
  case PrimitiveKind::String: {
672
823
  const char *str;
673
824
  if (RG_LIKELY(value.IsString())) {
package/src/call.cc CHANGED
@@ -178,6 +178,15 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
178
178
  int16_t v = CopyNumber<int16_t>(value);
179
179
  *(int16_t *)dest = v;
180
180
  } break;
181
+ case PrimitiveKind::Int16S: {
182
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
183
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
184
+ return false;
185
+ }
186
+
187
+ int16_t v = CopyNumber<int16_t>(value);
188
+ *(int16_t *)dest = ReverseBytes(v);
189
+ } break;
181
190
  case PrimitiveKind::UInt16: {
182
191
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
183
192
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
@@ -187,6 +196,15 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
187
196
  uint16_t v = CopyNumber<uint16_t>(value);
188
197
  *(uint16_t *)dest = v;
189
198
  } break;
199
+ case PrimitiveKind::UInt16S: {
200
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
201
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
202
+ return false;
203
+ }
204
+
205
+ uint16_t v = CopyNumber<uint16_t>(value);
206
+ *(uint16_t *)dest = ReverseBytes(v);
207
+ } break;
190
208
  case PrimitiveKind::Int32: {
191
209
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
192
210
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
@@ -196,6 +214,15 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
196
214
  int32_t v = CopyNumber<int32_t>(value);
197
215
  *(int32_t *)dest = v;
198
216
  } break;
217
+ case PrimitiveKind::Int32S: {
218
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
219
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
220
+ return false;
221
+ }
222
+
223
+ int32_t v = CopyNumber<int32_t>(value);
224
+ *(int32_t *)dest = ReverseBytes(v);
225
+ } break;
199
226
  case PrimitiveKind::UInt32: {
200
227
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
201
228
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
@@ -205,6 +232,15 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
205
232
  uint32_t v = CopyNumber<uint32_t>(value);
206
233
  *(uint32_t *)dest = v;
207
234
  } break;
235
+ case PrimitiveKind::UInt32S: {
236
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
237
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
238
+ return false;
239
+ }
240
+
241
+ uint32_t v = CopyNumber<uint32_t>(value);
242
+ *(uint32_t *)dest = ReverseBytes(v);
243
+ } break;
208
244
  case PrimitiveKind::Int64: {
209
245
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
210
246
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
@@ -214,6 +250,15 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
214
250
  int64_t v = CopyNumber<int64_t>(value);
215
251
  *(int64_t *)dest = v;
216
252
  } break;
253
+ case PrimitiveKind::Int64S: {
254
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
255
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
256
+ return false;
257
+ }
258
+
259
+ int64_t v = CopyNumber<int64_t>(value);
260
+ *(int64_t *)dest = ReverseBytes(v);
261
+ } break;
217
262
  case PrimitiveKind::UInt64: {
218
263
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
219
264
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
@@ -223,6 +268,15 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
223
268
  uint64_t v = CopyNumber<uint64_t>(value);
224
269
  *(uint64_t *)dest = v;
225
270
  } break;
271
+ case PrimitiveKind::UInt64S: {
272
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
273
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
274
+ return false;
275
+ }
276
+
277
+ uint64_t v = CopyNumber<uint64_t>(value);
278
+ *(uint64_t *)dest = ReverseBytes(v);
279
+ } break;
226
280
  case PrimitiveKind::String: {
227
281
  const char *str;
228
282
  if (RG_LIKELY(value.IsString())) {
@@ -402,36 +456,72 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
402
456
  *(int16_t *)dest = v;
403
457
  });
404
458
  } break;
459
+ case PrimitiveKind::Int16S: {
460
+ PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
461
+ int16_t v = CopyNumber<int16_t>(value);
462
+ *(int16_t *)dest = ReverseBytes(v);
463
+ });
464
+ } break;
405
465
  case PrimitiveKind::UInt16: {
406
466
  PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
407
467
  uint16_t v = CopyNumber<uint16_t>(value);
408
468
  *(uint16_t *)dest = v;
409
469
  });
410
470
  } break;
471
+ case PrimitiveKind::UInt16S: {
472
+ PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
473
+ uint16_t v = CopyNumber<uint16_t>(value);
474
+ *(uint16_t *)dest = ReverseBytes(v);
475
+ });
476
+ } break;
411
477
  case PrimitiveKind::Int32: {
412
478
  PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
413
479
  int32_t v = CopyNumber<int32_t>(value);
414
480
  *(int32_t *)dest = v;
415
481
  });
416
482
  } break;
483
+ case PrimitiveKind::Int32S: {
484
+ PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
485
+ int32_t v = CopyNumber<int32_t>(value);
486
+ *(int32_t *)dest = ReverseBytes(v);
487
+ });
488
+ } break;
417
489
  case PrimitiveKind::UInt32: {
418
490
  PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
419
491
  uint32_t v = CopyNumber<uint32_t>(value);
420
492
  *(uint32_t *)dest = v;
421
493
  });
422
494
  } break;
495
+ case PrimitiveKind::UInt32S: {
496
+ PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
497
+ uint32_t v = CopyNumber<uint32_t>(value);
498
+ *(uint32_t *)dest = ReverseBytes(v);
499
+ });
500
+ } break;
423
501
  case PrimitiveKind::Int64: {
424
502
  PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
425
503
  int64_t v = CopyNumber<int64_t>(value);
426
504
  *(int64_t *)dest = v;
427
505
  });
428
506
  } break;
507
+ case PrimitiveKind::Int64S: {
508
+ PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
509
+ int64_t v = CopyNumber<int64_t>(value);
510
+ *(int64_t *)dest = ReverseBytes(v);
511
+ });
512
+ } break;
429
513
  case PrimitiveKind::UInt64: {
430
514
  PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
431
515
  uint64_t v = CopyNumber<uint64_t>(value);
432
516
  *(uint64_t *)dest = v;
433
517
  });
434
518
  } break;
519
+ case PrimitiveKind::UInt64S: {
520
+ PUSH_ARRAY(value.IsNumber() || value.IsBigInt(), "number", {
521
+ uint64_t v = CopyNumber<uint64_t>(value);
522
+ *(uint64_t *)dest = ReverseBytes(v);
523
+ });
524
+ } break;
435
525
  case PrimitiveKind::String: {
436
526
  PUSH_ARRAY(value.IsString() || IsNullOrUndefined(value), "string", {
437
527
  if (!IsNullOrUndefined(value)) {
@@ -819,26 +909,58 @@ void CallData::PopObject(Napi::Object obj, const uint8_t *origin, const TypeInfo
819
909
  double d = (double)*(int16_t *)src;
820
910
  obj.Set(member.name, Napi::Number::New(env, d));
821
911
  } break;
912
+ case PrimitiveKind::Int16S: {
913
+ int16_t v = *(int16_t *)src;
914
+ double d = (double)ReverseBytes(v);
915
+
916
+ obj.Set(member.name, Napi::Number::New(env, d));
917
+ } break;
822
918
  case PrimitiveKind::UInt16: {
823
919
  double d = (double)*(uint16_t *)src;
824
920
  obj.Set(member.name, Napi::Number::New(env, d));
825
921
  } break;
922
+ case PrimitiveKind::UInt16S: {
923
+ uint16_t v = *(uint16_t *)src;
924
+ double d = (double)ReverseBytes(v);
925
+
926
+ obj.Set(member.name, Napi::Number::New(env, d));
927
+ } break;
826
928
  case PrimitiveKind::Int32: {
827
929
  double d = (double)*(int32_t *)src;
828
930
  obj.Set(member.name, Napi::Number::New(env, d));
829
931
  } break;
932
+ case PrimitiveKind::Int32S: {
933
+ int32_t v = *(int32_t *)src;
934
+ double d = (double)ReverseBytes(v);
935
+
936
+ obj.Set(member.name, Napi::Number::New(env, d));
937
+ } break;
830
938
  case PrimitiveKind::UInt32: {
831
939
  double d = (double)*(uint32_t *)src;
832
940
  obj.Set(member.name, Napi::Number::New(env, d));
833
941
  } break;
942
+ case PrimitiveKind::UInt32S: {
943
+ uint32_t v = *(uint32_t *)src;
944
+ double d = (double)ReverseBytes(v);
945
+
946
+ obj.Set(member.name, Napi::Number::New(env, d));
947
+ } break;
834
948
  case PrimitiveKind::Int64: {
835
949
  int64_t v = *(int64_t *)src;
836
950
  obj.Set(member.name, NewBigInt(env, v));
837
951
  } break;
952
+ case PrimitiveKind::Int64S: {
953
+ int64_t v = ReverseBytes(*(int64_t *)src);
954
+ obj.Set(member.name, NewBigInt(env, v));
955
+ } break;
838
956
  case PrimitiveKind::UInt64: {
839
957
  uint64_t v = *(uint64_t *)src;
840
958
  obj.Set(member.name, NewBigInt(env, v));
841
959
  } break;
960
+ case PrimitiveKind::UInt64S: {
961
+ uint64_t v = ReverseBytes(*(uint64_t *)src);
962
+ obj.Set(member.name, NewBigInt(env, v));
963
+ } break;
842
964
  case PrimitiveKind::String: {
843
965
  const char *str = *(const char **)src;
844
966
  obj.Set(member.name, str ? Napi::String::New(env, str) : env.Null());
@@ -939,6 +1061,14 @@ void CallData::PopNormalArray(Napi::Array array, const uint8_t *origin, const Ty
939
1061
  array.Set(i, Napi::Number::New(env, d)); \
940
1062
  }); \
941
1063
  } while (false)
1064
+ #define POP_NUMBER_ARRAY_SWAP(CType) \
1065
+ do { \
1066
+ POP_ARRAY({ \
1067
+ CType v = *(CType *)src; \
1068
+ double d = (double)ReverseBytes(v); \
1069
+ array.Set(i, Napi::Number::New(env, d)); \
1070
+ }); \
1071
+ } while (false)
942
1072
 
943
1073
  switch (ref->primitive) {
944
1074
  case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
@@ -952,21 +1082,37 @@ void CallData::PopNormalArray(Napi::Array array, const uint8_t *origin, const Ty
952
1082
  case PrimitiveKind::Int8: { POP_NUMBER_ARRAY(int8_t); } break;
953
1083
  case PrimitiveKind::UInt8: { POP_NUMBER_ARRAY(uint8_t); } break;
954
1084
  case PrimitiveKind::Int16: { POP_NUMBER_ARRAY(int16_t); } break;
1085
+ case PrimitiveKind::Int16S: { POP_NUMBER_ARRAY_SWAP(int16_t); } break;
955
1086
  case PrimitiveKind::UInt16: { POP_NUMBER_ARRAY(uint16_t); } break;
1087
+ case PrimitiveKind::UInt16S: { POP_NUMBER_ARRAY_SWAP(uint16_t); } break;
956
1088
  case PrimitiveKind::Int32: { POP_NUMBER_ARRAY(int32_t); } break;
1089
+ case PrimitiveKind::Int32S: { POP_NUMBER_ARRAY_SWAP(int32_t); } break;
957
1090
  case PrimitiveKind::UInt32: { POP_NUMBER_ARRAY(uint32_t); } break;
1091
+ case PrimitiveKind::UInt32S: { POP_NUMBER_ARRAY_SWAP(uint32_t); } break;
958
1092
  case PrimitiveKind::Int64: {
959
1093
  POP_ARRAY({
960
1094
  int64_t v = *(int64_t *)src;
961
1095
  array.Set(i, NewBigInt(env, v));
962
1096
  });
963
1097
  } break;
1098
+ case PrimitiveKind::Int64S: {
1099
+ POP_ARRAY({
1100
+ int64_t v = ReverseBytes(*(int64_t *)src);
1101
+ array.Set(i, NewBigInt(env, v));
1102
+ });
1103
+ } break;
964
1104
  case PrimitiveKind::UInt64: {
965
1105
  POP_ARRAY({
966
1106
  uint64_t v = *(uint64_t *)src;
967
1107
  array.Set(i, NewBigInt(env, v));
968
1108
  });
969
1109
  } break;
1110
+ case PrimitiveKind::UInt64S: {
1111
+ POP_ARRAY({
1112
+ uint64_t v = ReverseBytes(*(uint64_t *)src);
1113
+ array.Set(i, NewBigInt(env, v));
1114
+ });
1115
+ } break;
970
1116
  case PrimitiveKind::String: {
971
1117
  POP_ARRAY({
972
1118
  const char *str = *(const char **)src;
@@ -1024,6 +1170,7 @@ void CallData::PopNormalArray(Napi::Array array, const uint8_t *origin, const Ty
1024
1170
  case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1025
1171
  }
1026
1172
 
1173
+ #undef POP_NUMBER_ARRAY_SWAP
1027
1174
  #undef POP_NUMBER_ARRAY
1028
1175
  #undef POP_ARRAY
1029
1176
  }
@@ -1054,6 +1201,26 @@ void CallData::PopTypedArray(Napi::TypedArray array, const uint8_t *origin, cons
1054
1201
  } else {
1055
1202
  memcpy_safe(buf, origin, (size_t)array.ByteLength());
1056
1203
  }
1204
+
1205
+ #define SWAP(CType) \
1206
+ do { \
1207
+ CType *data = (CType *)buf; \
1208
+ Size len = (Size)array.ElementLength(); \
1209
+ \
1210
+ for (Size i = 0; i < len; i++) { \
1211
+ data[i] = ReverseBytes(data[i]); \
1212
+ } \
1213
+ } while (false)
1214
+
1215
+ if (ref->primitive == PrimitiveKind::Int16S || ref->primitive == PrimitiveKind::UInt16S) {
1216
+ SWAP(uint16_t);
1217
+ } else if (ref->primitive == PrimitiveKind::Int32S || ref->primitive == PrimitiveKind::UInt32S) {
1218
+ SWAP(uint32_t);
1219
+ } else if (ref->primitive == PrimitiveKind::Int64S || ref->primitive == PrimitiveKind::UInt64S) {
1220
+ SWAP(uint64_t);
1221
+ }
1222
+
1223
+ #undef SWAP
1057
1224
  }
1058
1225
 
1059
1226
  Napi::Value CallData::PopArray(const uint8_t *origin, const TypeInfo *type, int16_t realign)
@@ -1094,6 +1261,21 @@ Napi::Value CallData::PopArray(const uint8_t *origin, const TypeInfo *type, int1
1094
1261
  return array; \
1095
1262
  } \
1096
1263
  } while (false)
1264
+ #define POP_NUMBER_ARRAY_SWAP(TypedArrayType, CType) \
1265
+ do { \
1266
+ if (type->hint == TypeInfo::ArrayHint::Array) { \
1267
+ POP_ARRAY({ \
1268
+ CType v = *(CType *)src; \
1269
+ double d = (double)ReverseBytes(v); \
1270
+ array.Set(i, Napi::Number::New(env, d)); \
1271
+ }); \
1272
+ } else { \
1273
+ Napi::TypedArrayType array = Napi::TypedArrayType::New(env, len); \
1274
+ PopTypedArray(array, origin, type->ref.type, realign); \
1275
+ \
1276
+ return array; \
1277
+ } \
1278
+ } while (false)
1097
1279
 
1098
1280
  switch (type->ref.type->primitive) {
1099
1281
  case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
@@ -1131,21 +1313,37 @@ Napi::Value CallData::PopArray(const uint8_t *origin, const TypeInfo *type, int1
1131
1313
 
1132
1314
  POP_NUMBER_ARRAY(Int16Array, int16_t);
1133
1315
  } break;
1316
+ case PrimitiveKind::Int16S: { POP_NUMBER_ARRAY_SWAP(Int16Array, int16_t); } break;
1134
1317
  case PrimitiveKind::UInt16: { POP_NUMBER_ARRAY(Uint16Array, uint16_t); } break;
1318
+ case PrimitiveKind::UInt16S: { POP_NUMBER_ARRAY_SWAP(Uint16Array, uint16_t); } break;
1135
1319
  case PrimitiveKind::Int32: { POP_NUMBER_ARRAY(Int32Array, int32_t); } break;
1320
+ case PrimitiveKind::Int32S: { POP_NUMBER_ARRAY_SWAP(Int32Array, int32_t); } break;
1136
1321
  case PrimitiveKind::UInt32: { POP_NUMBER_ARRAY(Uint32Array, uint32_t); } break;
1322
+ case PrimitiveKind::UInt32S: { POP_NUMBER_ARRAY_SWAP(Uint32Array, uint32_t); } break;
1137
1323
  case PrimitiveKind::Int64: {
1138
1324
  POP_ARRAY({
1139
1325
  int64_t v = *(int64_t *)src;
1140
1326
  array.Set(i, NewBigInt(env, v));
1141
1327
  });
1142
1328
  } break;
1329
+ case PrimitiveKind::Int64S: {
1330
+ POP_ARRAY({
1331
+ int64_t v = ReverseBytes(*(int64_t *)src);
1332
+ array.Set(i, NewBigInt(env, v));
1333
+ });
1334
+ } break;
1143
1335
  case PrimitiveKind::UInt64: {
1144
1336
  POP_ARRAY({
1145
1337
  uint64_t v = *(uint64_t *)src;
1146
1338
  array.Set(i, NewBigInt(env, v));
1147
1339
  });
1148
1340
  } break;
1341
+ case PrimitiveKind::UInt64S: {
1342
+ POP_ARRAY({
1343
+ uint64_t v = ReverseBytes(*(uint64_t *)src);
1344
+ array.Set(i, NewBigInt(env, v));
1345
+ });
1346
+ } break;
1149
1347
  case PrimitiveKind::String: {
1150
1348
  POP_ARRAY({
1151
1349
  const char *str = *(const char **)src;
@@ -1191,6 +1389,7 @@ Napi::Value CallData::PopArray(const uint8_t *origin, const TypeInfo *type, int1
1191
1389
  case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1192
1390
  }
1193
1391
 
1392
+ #undef POP_NUMBER_ARRAY_SWAP
1194
1393
  #undef POP_NUMBER_ARRAY
1195
1394
  #undef POP_ARRAY
1196
1395