koffi 2.15.0 → 2.16.0-beta.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/build/koffi/darwin_arm64/koffi.node +0 -0
  3. package/build/koffi/darwin_x64/koffi.node +0 -0
  4. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  5. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  6. package/build/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm64/koffi.node +0 -0
  8. package/build/koffi/linux_armhf/koffi.node +0 -0
  9. package/build/koffi/linux_ia32/koffi.node +0 -0
  10. package/build/koffi/linux_loong64/koffi.node +0 -0
  11. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  12. package/build/koffi/linux_x64/koffi.node +0 -0
  13. package/build/koffi/musl_arm64/koffi.node +0 -0
  14. package/build/koffi/musl_x64/koffi.node +0 -0
  15. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  16. package/build/koffi/openbsd_x64/koffi.node +0 -0
  17. package/build/koffi/win32_arm64/koffi.node +0 -0
  18. package/build/koffi/win32_ia32/koffi.node +0 -0
  19. package/build/koffi/win32_x64/koffi.node +0 -0
  20. package/doc/pages/index.md +4 -2
  21. package/doc/pages/misc.md +2 -0
  22. package/doc/templates/code.html +1 -2
  23. package/doc/templates/page.html +1 -2
  24. package/index.d.ts +11 -9
  25. package/index.js +9 -9
  26. package/indirect.js +9 -9
  27. package/lib/native/base/base.cc +79 -44
  28. package/lib/native/base/base.hh +31 -33
  29. package/package.json +2 -2
  30. package/src/cnoke/assets/FindCNoke.cmake +16 -10
  31. package/src/cnoke/assets/win_delay_hook.c +4 -0
  32. package/src/cnoke/src/builder.js +49 -46
  33. package/src/koffi/CMakeLists.txt +18 -8
  34. package/src/koffi/src/abi_arm32.cc +222 -219
  35. package/src/koffi/src/abi_arm32_asm.S +1 -29
  36. package/src/koffi/src/abi_arm64.cc +257 -235
  37. package/src/koffi/src/abi_arm64_asm.S +1 -32
  38. package/src/koffi/src/abi_arm64_asm.asm +1 -23
  39. package/src/koffi/src/abi_loong64_asm.S +1 -25
  40. package/src/koffi/src/abi_riscv64.cc +220 -217
  41. package/src/koffi/src/abi_riscv64_asm.S +1 -25
  42. package/src/koffi/src/abi_x64_sysv.cc +196 -192
  43. package/src/koffi/src/abi_x64_sysv_asm.S +1 -31
  44. package/src/koffi/src/abi_x64_win.cc +188 -172
  45. package/src/koffi/src/abi_x64_win_asm.S +144 -0
  46. package/src/koffi/src/abi_x64_win_asm.asm +1 -21
  47. package/src/koffi/src/abi_x86.cc +224 -189
  48. package/src/koffi/src/abi_x86_asm.S +6 -25
  49. package/src/koffi/src/abi_x86_asm.asm +9 -22
  50. package/src/koffi/src/call.cc +246 -428
  51. package/src/koffi/src/call.hh +9 -8
  52. package/src/koffi/src/ffi.cc +142 -88
  53. package/src/koffi/src/ffi.hh +13 -59
  54. package/src/koffi/src/primitives.inc +39 -0
  55. package/src/koffi/src/trampolines/armasm.inc +0 -32770
  56. package/src/koffi/src/trampolines/gnu.inc +0 -24578
  57. package/src/koffi/src/trampolines/masm32.inc +0 -32770
  58. package/src/koffi/src/trampolines/masm64.inc +0 -32770
  59. package/src/koffi/src/trampolines/prototypes.inc +16385 -16385
  60. package/src/koffi/src/util.cc +155 -112
  61. package/src/koffi/src/util.hh +77 -40
  62. package/vendor/node-api-headers/CHANGELOG.md +22 -0
  63. package/vendor/node-api-headers/README.md +6 -17
  64. package/vendor/node-api-headers/include/js_native_api.h +3 -13
  65. package/vendor/node-api-headers/include/js_native_api_types.h +15 -0
  66. package/vendor/node-api-headers/include/node_api.h +0 -4
  67. package/vendor/node-api-headers/include/node_api_types.h +6 -0
  68. package/vendor/node-api-headers/package.json +1 -1
  69. package/vendor/node-api-headers/scripts/update-headers.js +6 -0
@@ -17,7 +17,7 @@ extern const napi_type_tag MagicUnionMarker;
17
17
  class MagicUnion: public Napi::ObjectWrap<MagicUnion> {
18
18
  const TypeInfo *type;
19
19
 
20
- napi_value active_symbol;
20
+ Napi::Reference<Napi::Symbol> active_symbol;
21
21
  Size active_idx = -1;
22
22
 
23
23
  HeapArray<uint8_t> raw;
@@ -98,63 +98,97 @@ static inline bool IsObject(Napi::Value value)
98
98
  return value.IsObject() && !IsNullOrUndefined(value) && !value.IsArray();
99
99
  }
100
100
 
101
- static inline bool IsRawBuffer(Napi::Value value)
102
- {
103
- return value.IsTypedArray() || value.IsArrayBuffer();
104
- }
105
-
106
- static inline Span<uint8_t> GetRawBuffer(Napi::Value value)
101
+ template <typename T>
102
+ bool TryNumber(Napi::Value value, T *out_value)
107
103
  {
108
- if (value.IsTypedArray()) {
109
- napi_typedarray_type type = napi_int8_array;
110
- size_t length = 0;
111
- void *ptr = nullptr;
104
+ // Assume number first
105
+ {
106
+ T v;
107
+ napi_status status;
108
+
109
+ if constexpr (std::is_same_v<T, double>) {
110
+ status = napi_get_value_double(value.Env(), value, &v);
111
+ } else if constexpr (std::is_same_v<T, float>) {
112
+ double d;
113
+ status = napi_get_value_double(value.Env(), value, &d);
114
+ v = (float)d;
115
+ } else {
116
+ int64_t i64;
117
+ status = napi_get_value_int64(value.Env(), value, &i64);
118
+ v = (T)i64;
119
+ }
112
120
 
113
- napi_get_typedarray_info(value.Env(), value, &type, &length, &ptr, nullptr, nullptr);
114
-
115
- switch (type) {
116
- case napi_int8_array: { length *= 1; } break;
117
- case napi_uint8_array: { length *= 1; } break;
118
- case napi_uint8_clamped_array: { length *= 1; } break;
119
- case napi_int16_array: { length *= 2; } break;
120
- case napi_uint16_array: { length *= 2; } break;
121
- case napi_int32_array: { length *= 4; } break;
122
- case napi_uint32_array: { length *= 4; } break;
123
- case napi_float32_array: { length *= 4; } break;
124
- case napi_float64_array: { length *= 8; } break;
125
- case napi_bigint64_array: { length *= 8; } break;
126
- case napi_biguint64_array: { length *= 8; } break;
121
+ if (status == napi_ok) [[likely]] {
122
+ *out_value = v;
123
+ return true;
127
124
  }
125
+ }
126
+
127
+ if (value.IsBigInt()) {
128
+ Napi::BigInt bigint = value.As<Napi::BigInt>();
129
+
130
+ bool lossless;
131
+ *out_value = (T)bigint.Uint64Value(&lossless);
132
+
133
+ return true;
134
+ }
135
+
136
+ return false;
137
+ }
128
138
 
129
- return MakeSpan((uint8_t *)ptr, (Size)length);
139
+ static inline bool TryPointer(Napi::Value value, void **out_ptr)
140
+ {
141
+ if (IsNullOrUndefined(value)) {
142
+ *out_ptr = nullptr;
143
+ return true;
144
+ } else if (uintptr_t ptr = 0; TryNumber(value, &ptr)) {
145
+ *out_ptr = (void *)ptr;
146
+ return true;
147
+ } else if (value.IsTypedArray()) {
148
+ napi_get_typedarray_info(value.Env(), value, nullptr, nullptr, out_ptr, nullptr, nullptr);
149
+ return true;
150
+ } else if (value.IsExternal()) {
151
+ Napi::External<void> external = value.As<Napi::External<void>>();
152
+
153
+ *out_ptr = (void *)external.Data();
154
+ return true;
130
155
  } else if (value.IsArrayBuffer()) {
131
156
  Napi::ArrayBuffer buffer = value.As<Napi::ArrayBuffer>();
132
157
 
133
- return MakeSpan((uint8_t *)buffer.Data(), (Size)buffer.ByteLength());
158
+ *out_ptr = (void *)buffer.Data();
159
+ return true;
134
160
  }
135
161
 
136
- K_UNREACHABLE();
162
+ return false;
137
163
  }
138
164
 
139
- int GetTypedArrayType(const TypeInfo *type);
140
-
141
- template <typename T>
142
- T GetNumber(Napi::Value value)
165
+ static inline bool TryBuffer(Napi::Value value, Span<uint8_t> *out_buffer)
143
166
  {
144
- K_ASSERT(value.IsNumber() || value.IsBigInt());
167
+ // Before somewhere around Node 20.12, napi_get_buffer_info() would assert/crash
168
+ // when used with something it did not support, instead of returning napi_invalid_arg.
169
+ // So we need to call napi_is_buffer(), at least for now.
145
170
 
146
- if (value.IsNumber()) [[likely]] {
147
- return (T)value.As<Napi::Number>().DoubleValue();
148
- } else if (value.IsBigInt()) {
149
- Napi::BigInt bigint = value.As<Napi::BigInt>();
171
+ if (value.IsBuffer()) {
172
+ void *ptr = nullptr;
173
+ size_t length = 0;
150
174
 
151
- bool lossless;
152
- return (T)bigint.Uint64Value(&lossless);
175
+ // Assume it works
176
+ napi_get_buffer_info(value.Env(), value, &ptr, &length);
177
+
178
+ *out_buffer = MakeSpan((uint8_t *)ptr, (Size)length);
179
+ return true;
180
+ } else if (value.IsArrayBuffer()) {
181
+ Napi::ArrayBuffer buffer = value.As<Napi::ArrayBuffer>();
182
+
183
+ *out_buffer = MakeSpan((uint8_t *)buffer.Data(), (Size)buffer.ByteLength());
184
+ return true;
153
185
  }
154
186
 
155
- K_UNREACHABLE();
187
+ return false;
156
188
  }
157
189
 
190
+ int GetTypedArrayType(const TypeInfo *type);
191
+
158
192
  template <typename T>
159
193
  Size NullTerminatedLength(const T *ptr)
160
194
  {
@@ -226,6 +260,9 @@ static inline Napi::Array GetOwnPropertyNames(Napi::Object obj)
226
260
 
227
261
  Napi::Function WrapFunction(Napi::Env env, const FunctionInfo *func);
228
262
 
263
+ Napi::Value WrapPointer(Napi::Env env, const TypeInfo *ref, void *ptr);
264
+ Napi::Value WrapCallback(Napi::Env env, const TypeInfo *ref, void *ptr);
265
+
229
266
  bool DetectCallConvention(Span<const char> name, CallConvention *out_convention);
230
267
 
231
268
  int AnalyseFlat(const TypeInfo *type, FunctionRef<void(const TypeInfo *type, int offset, int count)> func);
@@ -1,5 +1,27 @@
1
1
  # node-api-headers Changelog
2
2
 
3
+ ## [1.8.0](https://github.com/nodejs/node-api-headers/compare/v1.7.0...v1.8.0) (2026-01-23)
4
+
5
+
6
+ ### Features
7
+
8
+ * update headers from nodejs/node tag v25.4.0 ([#70](https://github.com/nodejs/node-api-headers/issues/70)) ([ebc02e1](https://github.com/nodejs/node-api-headers/commit/ebc02e18357a4d49f127f094c144371948b60c84))
9
+
10
+ ## [1.7.0](https://github.com/nodejs/node-api-headers/compare/v1.6.0...v1.7.0) (2025-11-28)
11
+
12
+
13
+ ### Features
14
+
15
+ * update headers from nodejs/node tag v25.1.0 ([#65](https://github.com/nodejs/node-api-headers/issues/65)) ([f90f754](https://github.com/nodejs/node-api-headers/commit/f90f75459375cb4725914895aa418efefdde7af2))
16
+ * update headers from nodejs/node tag v25.2.1 ([#68](https://github.com/nodejs/node-api-headers/issues/68)) ([769031b](https://github.com/nodejs/node-api-headers/commit/769031b208acd820bf3f2c3b2cf9f8b4b2e2bd83))
17
+
18
+ ## [1.6.0](https://github.com/nodejs/node-api-headers/compare/v1.5.0...v1.6.0) (2025-09-26)
19
+
20
+
21
+ ### Features
22
+
23
+ * update headers from nodejs/node tag v24.9.0 ([#60](https://github.com/nodejs/node-api-headers/issues/60)) ([5963ef9](https://github.com/nodejs/node-api-headers/commit/5963ef9937c8f6bd8f33cb45c50f70bd9cbc0ffd))
24
+
3
25
  ## [1.5.0](https://github.com/nodejs/node-api-headers/compare/v1.4.0...v1.5.0) (2025-01-09)
4
26
 
5
27
 
@@ -9,10 +9,6 @@
9
9
  - **[Team](#team)**
10
10
  - **[License](#license)**
11
11
 
12
- ## Current Node-API version: 9
13
-
14
- (See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
15
-
16
12
  <a name="introduction"></a>
17
13
 
18
14
  ## Introduction
@@ -45,8 +41,8 @@ npm i node-api-headers
45
41
 
46
42
  ## Versions
47
43
 
48
- Node-API C headers are backward-compatible. Its version (e.g. `8`) is released
49
- separately from the Node.js version stream (e.g. `19.8.1`) and changes are
44
+ Node-API C headers are backward-compatible. Its version (e.g. `8`) is released
45
+ separately from the Node.js version stream (e.g. `19.8.1`) and changes are
50
46
  backported to active Node.js LTS lines (e.g. `16.x` and `18.x`).
51
47
 
52
48
  This package publishes semver-minor versions with new Node-API C headers changes.
@@ -57,6 +53,7 @@ JS API breaking changes are published with new semver-major versions.
57
53
  ## API
58
54
 
59
55
  The module exports two properties `include_dir` and `symbols`.
56
+
60
57
  ### `include_dir`
61
58
 
62
59
  This property is a string that represents the include path for the Node-API
@@ -89,18 +86,10 @@ grouped by version and api types.
89
86
 
90
87
  ## Team members
91
88
 
92
- ### Active
93
- | Name | GitHub Link |
94
- | ------------------- | ----------------------------------------------------- |
95
- | Anna Henningsen | [addaleax](https://github.com/addaleax) |
96
- | Chengzhong Wu | [legendecas](https://github.com/legendecas) |
97
- | Gabriel Schulhof | [gabrielschulhof](https://github.com/gabrielschulhof) |
98
- | Hitesh Kanwathirtha | [digitalinfinity](https://github.com/digitalinfinity) |
99
- | Jim Schlight | [jschlight](https://github.com/jschlight) |
100
- | Michael Dawson | [mhdawson](https://github.com/mhdawson) |
101
- | Kevin Eady | [KevinEady](https://github.com/KevinEady)
102
- | Nicola Del Gobbo | [NickNaso](https://github.com/NickNaso) |
89
+ The project is maintained by the [Node-API team members](https://github.com/nodejs/abi-stable-node/?tab=readme-ov-file#project-participants).
103
90
 
104
91
  <a name="license"></a>
105
92
 
93
+ ## License
94
+
106
95
  Licensed under [MIT](./LICENSE.md)
@@ -5,18 +5,6 @@
5
5
  #include <stdbool.h> // NOLINT(modernize-deprecated-headers)
6
6
  #include <stddef.h> // NOLINT(modernize-deprecated-headers)
7
7
 
8
- // Use INT_MAX, this should only be consumed by the pre-processor anyway.
9
- #define NAPI_VERSION_EXPERIMENTAL 2147483647
10
- #ifndef NAPI_VERSION
11
- // The baseline version for N-API.
12
- // The NAPI_VERSION controls which version will be used by default when
13
- // compilling a native addon. If the addon developer specifically wants to use
14
- // functions available in a new version of N-API that is not yet ported in all
15
- // LTS versions, they can set NAPI_VERSION knowing that they have specifically
16
- // depended on that version.
17
- #define NAPI_VERSION 8
18
- #endif
19
-
20
8
  #include "js_native_api_types.h"
21
9
 
22
10
  // If you need __declspec(dllimport), either include <node_api.h> instead, or
@@ -62,6 +50,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_boolean(napi_env env,
62
50
  // Methods to create Primitive types/Objects
63
51
  NAPI_EXTERN napi_status NAPI_CDECL napi_create_object(napi_env env,
64
52
  napi_value* result);
53
+
65
54
  NAPI_EXTERN napi_status NAPI_CDECL napi_create_array(napi_env env,
66
55
  napi_value* result);
67
56
  NAPI_EXTERN napi_status NAPI_CDECL
@@ -348,7 +337,7 @@ napi_create_reference(napi_env env,
348
337
 
349
338
  // Deletes a reference. The referenced value is released, and may
350
339
  // be GC'd unless there are other references to it.
351
- NAPI_EXTERN napi_status NAPI_CDECL napi_delete_reference(napi_env env,
340
+ NAPI_EXTERN napi_status NAPI_CDECL napi_delete_reference(node_api_basic_env env,
352
341
  napi_ref ref);
353
342
 
354
343
  // Increments the reference count, optionally returning the resulting count.
@@ -470,6 +459,7 @@ napi_get_dataview_info(napi_env env,
470
459
  napi_value* arraybuffer,
471
460
  size_t* byte_offset);
472
461
 
462
+
473
463
  // version management
474
464
  NAPI_EXTERN napi_status NAPI_CDECL napi_get_version(node_api_basic_env env,
475
465
  uint32_t* result);
@@ -1,6 +1,19 @@
1
1
  #ifndef SRC_JS_NATIVE_API_TYPES_H_
2
2
  #define SRC_JS_NATIVE_API_TYPES_H_
3
3
 
4
+ // Use INT_MAX, this should only be consumed by the pre-processor anyway.
5
+ #define NAPI_VERSION_EXPERIMENTAL 2147483647
6
+ #ifndef NAPI_VERSION
7
+ // The baseline version for N-API.
8
+ // The NAPI_VERSION controls which version will be used by default when
9
+ // compilling a native addon. If the addon developer specifically wants to use
10
+ // functions available in a new version of N-API that is not yet ported in all
11
+ // LTS versions, they can set NAPI_VERSION knowing that they have specifically
12
+ // depended on that version.
13
+ #define NAPI_VERSION 8
14
+ #endif
15
+
16
+
4
17
  // This file needs to be compatible with C compilers.
5
18
  // This is a public include file, and these includes have essentially
6
19
  // became part of it's API.
@@ -98,6 +111,8 @@ typedef enum {
98
111
  napi_float64_array,
99
112
  napi_bigint64_array,
100
113
  napi_biguint64_array,
114
+ #define NODE_API_HAS_FLOAT16_ARRAY
115
+ napi_float16_array,
101
116
  } napi_typedarray_type;
102
117
 
103
118
  typedef enum {
@@ -33,10 +33,6 @@ struct uv_loop_s; // Forward declaration.
33
33
  #define NAPI_NO_RETURN
34
34
  #endif
35
35
 
36
- typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
37
- napi_value exports);
38
- typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);
39
-
40
36
  // Used by deprecated registration method napi_module_register.
41
37
  typedef struct napi_module {
42
38
  int nm_version;
@@ -3,6 +3,12 @@
3
3
 
4
4
  #include "js_native_api_types.h"
5
5
 
6
+ typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
7
+ napi_value exports);
8
+ // False positive: https://github.com/cpplint/cpplint/issues/409
9
+ // NOLINTNEXTLINE (readability/casting)
10
+ typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);
11
+
6
12
  typedef struct napi_callback_scope__* napi_callback_scope;
7
13
  typedef struct napi_async_context__* napi_async_context;
8
14
  typedef struct napi_async_work__* napi_async_work;
@@ -54,6 +54,6 @@
54
54
  "write-win32-def": "node --no-warnings scripts/write-win32-def.js",
55
55
  "test": "node test/parse-utils.js "
56
56
  },
57
- "version": "1.5.0",
57
+ "version": "1.8.0",
58
58
  "support": true
59
59
  }
@@ -71,6 +71,12 @@ function removeExperimentals(stream, destination, verbose = false) {
71
71
  const identifier = matches[2];
72
72
  macroStack.push(identifier);
73
73
 
74
+ if (mode.length && mode[mode.length - 1] === 'ignore') {
75
+ debug(`Line ${lineNumber} Continued-Ignored ${identifier}`);
76
+ mode.push('ignore');
77
+ return;
78
+ }
79
+
74
80
  debug(`Line ${lineNumber} Pushed ${identifier}`);
75
81
 
76
82
  if (identifier === 'NAPI_EXPERIMENTAL') {