koffi 2.12.0 → 2.12.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 (188) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.txt +2 -2
  3. package/README.md +8 -8
  4. package/build/koffi/darwin_arm64/koffi.node +0 -0
  5. package/build/koffi/darwin_x64/koffi.node +0 -0
  6. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  7. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  8. package/build/koffi/freebsd_x64/koffi.node +0 -0
  9. package/build/koffi/linux_arm64/koffi.node +0 -0
  10. package/build/koffi/linux_armhf/koffi.node +0 -0
  11. package/build/koffi/linux_ia32/koffi.node +0 -0
  12. package/build/koffi/linux_loong64/koffi.node +0 -0
  13. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  14. package/build/koffi/linux_x64/koffi.node +0 -0
  15. package/build/koffi/musl_arm64/koffi.node +0 -0
  16. package/build/koffi/musl_x64/koffi.node +0 -0
  17. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  18. package/build/koffi/openbsd_x64/koffi.node +0 -0
  19. package/build/koffi/win32_arm64/koffi.exp +0 -0
  20. package/build/koffi/win32_arm64/koffi.node +0 -0
  21. package/build/koffi/win32_ia32/koffi.exp +0 -0
  22. package/build/koffi/win32_ia32/koffi.node +0 -0
  23. package/build/koffi/win32_x64/koffi.exp +0 -0
  24. package/build/koffi/win32_x64/koffi.node +0 -0
  25. package/doc/assets.ini +3 -3
  26. package/doc/develop.sh +4 -3
  27. package/doc/pages/platforms.md +1 -1
  28. package/doc/static/highlight.js +1 -1
  29. package/doc/static/koffi.css +3 -2
  30. package/doc/static/print.css +1 -1
  31. package/doc/templates/code.html +5 -5
  32. package/doc/templates/page.html +4 -4
  33. package/index.d.ts +2 -2
  34. package/index.js +25 -25
  35. package/indirect.js +25 -5
  36. package/package.json +2 -2
  37. package/src/cnoke/LICENSE.txt +2 -2
  38. package/src/cnoke/README.md +2 -0
  39. package/src/cnoke/assets/FindCNoke.cmake +12 -2
  40. package/src/cnoke/assets/win_delay_hook.c +4 -4
  41. package/src/cnoke/cnoke.js +4 -2
  42. package/src/cnoke/package.json +1 -1
  43. package/src/cnoke/src/builder.js +11 -14
  44. package/src/cnoke/src/index.js +2 -2
  45. package/src/cnoke/src/tools.js +34 -2
  46. package/src/core/{libcc/libcc.cc → base/base.cc} +3092 -1674
  47. package/src/core/{libcc/libcc.hh → base/base.hh} +3059 -2432
  48. package/src/core/{libcc → base}/mimetypes.inc +42 -4
  49. package/src/core/{libcc → base}/mimetypes_gen.py +3 -3
  50. package/src/core/unicode/generate.py +124 -0
  51. package/src/core/unicode/xid.cc +52 -0
  52. package/src/core/unicode/xid.hh +29 -0
  53. package/src/core/unicode/xid.inc +465 -0
  54. package/src/koffi/CMakeLists.txt +8 -5
  55. package/src/koffi/cmake/raylib.cmake +6 -2
  56. package/src/koffi/cmake/{sqlite.cmake → sqlite3.cmake} +3 -3
  57. package/src/koffi/examples/electron-forge/forge.config.js +23 -3
  58. package/src/koffi/examples/electron-forge/package.json +18 -16
  59. package/src/koffi/src/abi_arm32.cc +8 -21
  60. package/src/koffi/src/abi_arm32_asm.S +2 -2
  61. package/src/koffi/src/abi_arm64.cc +46 -59
  62. package/src/koffi/src/abi_arm64_asm.S +4 -4
  63. package/src/koffi/src/abi_arm64_asm.asm +2 -2
  64. package/src/koffi/src/abi_loong64_asm.S +2 -2
  65. package/src/koffi/src/abi_riscv64.cc +6 -19
  66. package/src/koffi/src/abi_riscv64_asm.S +2 -2
  67. package/src/koffi/src/abi_x64_sysv.cc +4 -17
  68. package/src/koffi/src/abi_x64_sysv_asm.S +5 -5
  69. package/src/koffi/src/abi_x64_win.cc +4 -17
  70. package/src/koffi/src/abi_x64_win_asm.asm +2 -2
  71. package/src/koffi/src/abi_x86.cc +9 -22
  72. package/src/koffi/src/abi_x86_asm.S +2 -2
  73. package/src/koffi/src/abi_x86_asm.asm +2 -2
  74. package/src/koffi/src/call.cc +49 -42
  75. package/src/koffi/src/call.hh +9 -8
  76. package/src/koffi/src/errno.inc +152 -152
  77. package/src/koffi/src/ffi.cc +45 -39
  78. package/src/koffi/src/ffi.hh +6 -6
  79. package/src/koffi/src/init.js +1 -1
  80. package/src/koffi/src/parser.cc +6 -5
  81. package/src/koffi/src/parser.hh +3 -3
  82. package/src/koffi/src/trampolines/armasm.inc +2 -2
  83. package/src/koffi/src/trampolines/gnu.inc +2 -2
  84. package/src/koffi/src/trampolines/masm32.inc +2 -2
  85. package/src/koffi/src/trampolines/masm64.inc +2 -2
  86. package/src/koffi/src/trampolines/prototypes.inc +2 -2
  87. package/src/koffi/src/util.cc +9 -9
  88. package/src/koffi/src/util.hh +3 -3
  89. package/src/koffi/src/win32.cc +5 -5
  90. package/src/koffi/src/win32.hh +9 -9
  91. package/vendor/node-addon-api/CHANGELOG.md +97 -2
  92. package/vendor/node-addon-api/CONTRIBUTING.md +117 -7
  93. package/vendor/node-addon-api/README.md +25 -249
  94. package/vendor/node-addon-api/common.gypi +1 -0
  95. package/vendor/node-addon-api/doc/README.md +145 -0
  96. package/vendor/node-addon-api/doc/array_buffer.md +15 -15
  97. package/vendor/node-addon-api/doc/basic_env.md +200 -0
  98. package/vendor/node-addon-api/doc/buffer.md +24 -26
  99. package/vendor/node-addon-api/doc/cmake-js.md +19 -0
  100. package/vendor/node-addon-api/doc/{creating_a_release.md → contributing/creating_a_release.md} +16 -4
  101. package/vendor/node-addon-api/doc/env.md +11 -131
  102. package/vendor/node-addon-api/doc/error_handling.md +12 -0
  103. package/vendor/node-addon-api/doc/external.md +13 -4
  104. package/vendor/node-addon-api/doc/finalization.md +153 -0
  105. package/vendor/node-addon-api/doc/memory_management.md +1 -1
  106. package/vendor/node-addon-api/doc/object_wrap.md +19 -3
  107. package/vendor/node-addon-api/doc/promises.md +51 -0
  108. package/vendor/node-addon-api/doc/setup.md +29 -6
  109. package/vendor/node-addon-api/doc/value.md +13 -0
  110. package/vendor/node-addon-api/doc/version_management.md +2 -2
  111. package/vendor/node-addon-api/eslint.config.js +5 -0
  112. package/vendor/node-addon-api/index.js +2 -0
  113. package/vendor/node-addon-api/napi-inl.h +592 -166
  114. package/vendor/node-addon-api/napi.h +167 -59
  115. package/vendor/node-addon-api/node_addon_api.gyp +10 -0
  116. package/vendor/node-addon-api/noexcept.gypi +1 -1
  117. package/vendor/node-addon-api/package.json +10 -13
  118. package/vendor/node-addon-api/release-please-config.json +15 -0
  119. package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +2 -1
  120. package/vendor/node-addon-api/test/array_buffer.js +1 -1
  121. package/vendor/node-addon-api/test/async_context.js +2 -2
  122. package/vendor/node-addon-api/test/async_progress_queue_worker.js +3 -3
  123. package/vendor/node-addon-api/test/async_progress_worker.js +3 -3
  124. package/vendor/node-addon-api/test/async_worker.cc +15 -13
  125. package/vendor/node-addon-api/test/async_worker.js +5 -5
  126. package/vendor/node-addon-api/test/basic_types/value.cc +6 -0
  127. package/vendor/node-addon-api/test/basic_types/value.js +17 -0
  128. package/vendor/node-addon-api/test/binding.cc +8 -0
  129. package/vendor/node-addon-api/test/binding.gyp +23 -1
  130. package/vendor/node-addon-api/test/buffer.js +1 -2
  131. package/vendor/node-addon-api/test/common/index.js +1 -1
  132. package/vendor/node-addon-api/test/except_all.cc +22 -0
  133. package/vendor/node-addon-api/test/except_all.js +14 -0
  134. package/vendor/node-addon-api/test/exports.js +19 -0
  135. package/vendor/node-addon-api/test/finalizer_order.cc +152 -0
  136. package/vendor/node-addon-api/test/finalizer_order.js +98 -0
  137. package/vendor/node-addon-api/test/function.js +2 -2
  138. package/vendor/node-addon-api/test/function_reference.js +2 -2
  139. package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +4 -4
  140. package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +4 -4
  141. package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +3 -3
  142. package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +5 -5
  143. package/vendor/node-addon-api/test/name.cc +10 -8
  144. package/vendor/node-addon-api/test/object/delete_property.cc +5 -5
  145. package/vendor/node-addon-api/test/object/get_property.cc +5 -5
  146. package/vendor/node-addon-api/test/object/has_own_property.cc +4 -4
  147. package/vendor/node-addon-api/test/object/has_property.cc +5 -5
  148. package/vendor/node-addon-api/test/object/object.cc +1 -1
  149. package/vendor/node-addon-api/test/object/set_property.cc +5 -5
  150. package/vendor/node-addon-api/test/object/subscript_operator.cc +3 -3
  151. package/vendor/node-addon-api/test/object_reference.cc +18 -18
  152. package/vendor/node-addon-api/test/promise.cc +75 -0
  153. package/vendor/node-addon-api/test/promise.js +23 -0
  154. package/vendor/node-addon-api/test/require_basic_finalizers/index.js +38 -0
  155. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/addon.cc +12 -0
  156. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/binding.gyp +48 -0
  157. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/index.js +3 -0
  158. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/package.json +11 -0
  159. package/vendor/node-addon-api/test/run_script.cc +1 -1
  160. package/vendor/node-addon-api/test/type_taggable.cc +1 -1
  161. package/vendor/node-addon-api/test/type_taggable.js +3 -4
  162. package/vendor/node-addon-api/test/typedarray.cc +28 -24
  163. package/vendor/node-addon-api/tools/conversion.js +1 -1
  164. package/vendor/node-api-headers/CHANGELOG.md +29 -0
  165. package/vendor/node-api-headers/CREATING_A_RELEASE.md +12 -2
  166. package/vendor/node-api-headers/def/js_native_api.def +6 -1
  167. package/vendor/node-api-headers/def/node_api.def +7 -1
  168. package/vendor/node-api-headers/include/js_native_api.h +56 -24
  169. package/vendor/node-api-headers/include/js_native_api_types.h +27 -0
  170. package/vendor/node-api-headers/include/node_api.h +38 -29
  171. package/vendor/node-api-headers/lib/parse-utils.js +92 -0
  172. package/vendor/node-api-headers/package.json +7 -7
  173. package/vendor/node-api-headers/release-please-config.json +12 -0
  174. package/vendor/node-api-headers/scripts/update-headers.js +63 -12
  175. package/vendor/node-api-headers/scripts/write-symbols.js +1 -1
  176. package/vendor/node-api-headers/symbols.js +17 -1
  177. package/vendor/node-api-headers/test/parse-utils.js +21 -0
  178. package/doc/flat/flat.css +0 -27
  179. package/doc/flat/normal.css +0 -429
  180. package/doc/flat/print.css +0 -29
  181. package/doc/flat/reset.css +0 -41
  182. package/doc/flat/small.css +0 -104
  183. package/doc/flat/static.js +0 -161
  184. package/src/core/libcc/brotli.cc +0 -186
  185. package/src/core/libcc/lz4.cc +0 -197
  186. package/src/core/libcc/miniz.cc +0 -353
  187. package/vendor/node-addon-api/tools/eslint-format.js +0 -79
  188. /package/vendor/node-api-headers/{scripts → lib}/clang-utils.js +0 -0
@@ -1,11 +1,11 @@
1
1
  #ifndef SRC_NODE_API_H_
2
2
  #define SRC_NODE_API_H_
3
3
 
4
- #ifdef BUILDING_NODE_EXTENSION
4
+ #if defined(BUILDING_NODE_EXTENSION) && !defined(NAPI_EXTERN)
5
5
  #ifdef _WIN32
6
6
  // Building native addon against node
7
7
  #define NAPI_EXTERN __declspec(dllimport)
8
- #elif defined(__wasm32__)
8
+ #elif defined(__wasm__)
9
9
  #define NAPI_EXTERN __attribute__((__import_module__("napi")))
10
10
  #endif
11
11
  #endif
@@ -17,8 +17,13 @@ struct uv_loop_s; // Forward declaration.
17
17
  #ifdef _WIN32
18
18
  #define NAPI_MODULE_EXPORT __declspec(dllexport)
19
19
  #else
20
+ #ifdef __EMSCRIPTEN__
21
+ #define NAPI_MODULE_EXPORT \
22
+ __attribute__((visibility("default"))) __attribute__((used))
23
+ #else
20
24
  #define NAPI_MODULE_EXPORT __attribute__((visibility("default")))
21
25
  #endif
26
+ #endif
22
27
 
23
28
  #if defined(__GNUC__)
24
29
  #define NAPI_NO_RETURN __attribute__((noreturn))
@@ -30,7 +35,7 @@ struct uv_loop_s; // Forward declaration.
30
35
 
31
36
  typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
32
37
  napi_value exports);
33
- typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)();
38
+ typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);
34
39
 
35
40
  // Used by deprecated registration method napi_module_register.
36
41
  typedef struct napi_module {
@@ -49,7 +54,7 @@ typedef struct napi_module {
49
54
  NAPI_MODULE_INITIALIZER_X_HELPER(base, version)
50
55
  #define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version
51
56
 
52
- #ifdef __wasm32__
57
+ #ifdef __wasm__
53
58
  #define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v
54
59
  #else
55
60
  #define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v
@@ -66,7 +71,7 @@ typedef struct napi_module {
66
71
 
67
72
  #define NAPI_MODULE_INIT() \
68
73
  EXTERN_C_START \
69
- NAPI_MODULE_EXPORT int32_t NODE_API_MODULE_GET_API_VERSION() { \
74
+ NAPI_MODULE_EXPORT int32_t NODE_API_MODULE_GET_API_VERSION(void) { \
70
75
  return NAPI_VERSION; \
71
76
  } \
72
77
  NAPI_MODULE_EXPORT napi_value NAPI_MODULE_INITIALIZER(napi_env env, \
@@ -85,9 +90,6 @@ EXTERN_C_START
85
90
 
86
91
  // Deprecated. Replaced by symbol-based registration defined by NAPI_MODULE
87
92
  // and NAPI_MODULE_INIT macros.
88
- #if defined(__cplusplus) && __cplusplus >= 201402L
89
- [[deprecated]]
90
- #endif
91
93
  NAPI_EXTERN void NAPI_CDECL
92
94
  napi_module_register(napi_module* mod);
93
95
 
@@ -126,10 +128,21 @@ NAPI_EXTERN napi_status NAPI_CDECL
126
128
  napi_create_external_buffer(napi_env env,
127
129
  size_t length,
128
130
  void* data,
129
- napi_finalize finalize_cb,
131
+ node_api_basic_finalize finalize_cb,
130
132
  void* finalize_hint,
131
133
  napi_value* result);
132
134
  #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
135
+
136
+ #if NAPI_VERSION >= 10
137
+
138
+ NAPI_EXTERN napi_status NAPI_CDECL
139
+ node_api_create_buffer_from_arraybuffer(napi_env env,
140
+ napi_value arraybuffer,
141
+ size_t byte_offset,
142
+ size_t byte_length,
143
+ napi_value* result);
144
+ #endif // NAPI_VERSION >= 10
145
+
133
146
  NAPI_EXTERN napi_status NAPI_CDECL napi_create_buffer_copy(napi_env env,
134
147
  size_t length,
135
148
  const void* data,
@@ -143,7 +156,6 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_buffer_info(napi_env env,
143
156
  void** data,
144
157
  size_t* length);
145
158
 
146
- #ifndef __wasm32__
147
159
  // Methods to manage simple async operations
148
160
  NAPI_EXTERN napi_status NAPI_CDECL
149
161
  napi_create_async_work(napi_env env,
@@ -155,21 +167,20 @@ napi_create_async_work(napi_env env,
155
167
  napi_async_work* result);
156
168
  NAPI_EXTERN napi_status NAPI_CDECL napi_delete_async_work(napi_env env,
157
169
  napi_async_work work);
158
- NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(napi_env env,
170
+ NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(node_api_basic_env env,
159
171
  napi_async_work work);
160
- NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(napi_env env,
161
- napi_async_work work);
162
- #endif // __wasm32__
172
+ NAPI_EXTERN napi_status NAPI_CDECL
173
+ napi_cancel_async_work(node_api_basic_env env, napi_async_work work);
163
174
 
164
175
  // version management
165
- NAPI_EXTERN napi_status NAPI_CDECL
166
- napi_get_node_version(napi_env env, const napi_node_version** version);
176
+ NAPI_EXTERN napi_status NAPI_CDECL napi_get_node_version(
177
+ node_api_basic_env env, const napi_node_version** version);
167
178
 
168
179
  #if NAPI_VERSION >= 2
169
180
 
170
181
  // Return the current libuv event loop for a given environment
171
182
  NAPI_EXTERN napi_status NAPI_CDECL
172
- napi_get_uv_event_loop(napi_env env, struct uv_loop_s** loop);
183
+ napi_get_uv_event_loop(node_api_basic_env env, struct uv_loop_s** loop);
173
184
 
174
185
  #endif // NAPI_VERSION >= 2
175
186
 
@@ -178,11 +189,11 @@ napi_get_uv_event_loop(napi_env env, struct uv_loop_s** loop);
178
189
  NAPI_EXTERN napi_status NAPI_CDECL napi_fatal_exception(napi_env env,
179
190
  napi_value err);
180
191
 
181
- NAPI_EXTERN napi_status NAPI_CDECL
182
- napi_add_env_cleanup_hook(napi_env env, napi_cleanup_hook fun, void* arg);
192
+ NAPI_EXTERN napi_status NAPI_CDECL napi_add_env_cleanup_hook(
193
+ node_api_basic_env env, napi_cleanup_hook fun, void* arg);
183
194
 
184
- NAPI_EXTERN napi_status NAPI_CDECL
185
- napi_remove_env_cleanup_hook(napi_env env, napi_cleanup_hook fun, void* arg);
195
+ NAPI_EXTERN napi_status NAPI_CDECL napi_remove_env_cleanup_hook(
196
+ node_api_basic_env env, napi_cleanup_hook fun, void* arg);
186
197
 
187
198
  NAPI_EXTERN napi_status NAPI_CDECL
188
199
  napi_open_callback_scope(napi_env env,
@@ -197,7 +208,6 @@ napi_close_callback_scope(napi_env env, napi_callback_scope scope);
197
208
 
198
209
  #if NAPI_VERSION >= 4
199
210
 
200
- #ifndef __wasm32__
201
211
  // Calling into JS from other threads
202
212
  NAPI_EXTERN napi_status NAPI_CDECL
203
213
  napi_create_threadsafe_function(napi_env env,
@@ -226,19 +236,18 @@ napi_acquire_threadsafe_function(napi_threadsafe_function func);
226
236
  NAPI_EXTERN napi_status NAPI_CDECL napi_release_threadsafe_function(
227
237
  napi_threadsafe_function func, napi_threadsafe_function_release_mode mode);
228
238
 
229
- NAPI_EXTERN napi_status NAPI_CDECL
230
- napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);
239
+ NAPI_EXTERN napi_status NAPI_CDECL napi_unref_threadsafe_function(
240
+ node_api_basic_env env, napi_threadsafe_function func);
231
241
 
232
- NAPI_EXTERN napi_status NAPI_CDECL
233
- napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
234
- #endif // __wasm32__
242
+ NAPI_EXTERN napi_status NAPI_CDECL napi_ref_threadsafe_function(
243
+ node_api_basic_env env, napi_threadsafe_function func);
235
244
 
236
245
  #endif // NAPI_VERSION >= 4
237
246
 
238
247
  #if NAPI_VERSION >= 8
239
248
 
240
249
  NAPI_EXTERN napi_status NAPI_CDECL
241
- napi_add_async_cleanup_hook(napi_env env,
250
+ napi_add_async_cleanup_hook(node_api_basic_env env,
242
251
  napi_async_cleanup_hook hook,
243
252
  void* arg,
244
253
  napi_async_cleanup_hook_handle* remove_handle);
@@ -251,7 +260,7 @@ napi_remove_async_cleanup_hook(napi_async_cleanup_hook_handle remove_handle);
251
260
  #if NAPI_VERSION >= 9
252
261
 
253
262
  NAPI_EXTERN napi_status NAPI_CDECL
254
- node_api_get_module_file_name(napi_env env, const char** result);
263
+ node_api_get_module_file_name(node_api_basic_env env, const char** result);
255
264
 
256
265
  #endif // NAPI_VERSION >= 9
257
266
 
@@ -0,0 +1,92 @@
1
+ const parser = require("acorn");
2
+
3
+ /**
4
+ * @param {string} text Code to evaluate
5
+ * @returns {boolean | undefined} The result of the evaluation, `undefined` if
6
+ * parsing failed or the result is unknown.
7
+ */
8
+ function evaluate(text) {
9
+ try {
10
+ const ast = parser.parse(text, { ecmaVersion: 2020 });
11
+
12
+ const expressionStatement = ast.body[0];
13
+
14
+ if (expressionStatement.type !== "ExpressionStatement") {
15
+ throw new Error("Expected an ExpressionStatement");
16
+ }
17
+
18
+ return visitExpression(expressionStatement.expression);
19
+ } catch {
20
+ // Return an unknown result if parsing failed
21
+ return undefined;
22
+ }
23
+ }
24
+
25
+ /**
26
+ * @param {import("acorn").Expression} node
27
+ */
28
+ const visitExpression = (node) => {
29
+ if (node.type === "LogicalExpression") {
30
+ return visitLogicalExpression(node);
31
+ } else if (node.type === "UnaryExpression") {
32
+ return visitUnaryExpression(node);
33
+ } else if (node.type === "CallExpression") {
34
+ return visitCallExpression(node);
35
+ } else {
36
+ throw new Error(`Unknown node type: ${node.type} ${JSON.stringify(node)}`);
37
+ }
38
+ };
39
+
40
+ /**
41
+ * @param {import("acorn").LogicalExpression} node
42
+ */
43
+ const visitLogicalExpression = (node) => {
44
+ const left = visitExpression(node.left);
45
+ const right = visitExpression(node.right);
46
+
47
+ if (node.operator === "&&") {
48
+ // We can shortcircuit regardless of `unknown` if either are false.
49
+ if (left === false || right === false) {
50
+ return false;
51
+ } else if (left === undefined || right === undefined) {
52
+ return undefined;
53
+ } else {
54
+ return left && right;
55
+ }
56
+ } else if (node.operator === "||") {
57
+ if (left === undefined || right === undefined) {
58
+ return undefined;
59
+ } else {
60
+ return left || right;
61
+ }
62
+ }
63
+ };
64
+
65
+ /**
66
+ * @param {import("acorn").UnaryExpression} node
67
+ */
68
+ const visitUnaryExpression = (node) => {
69
+ const argument = visitExpression(node.argument);
70
+ if (typeof argument === 'boolean') {
71
+ return !argument;
72
+ }
73
+ };
74
+
75
+ /**
76
+ * @param {import("acorn").CallExpression} node
77
+ */
78
+ const visitCallExpression = (node) => {
79
+ const isDefinedExperimentalCall =
80
+ // is `defined(arg)` call
81
+ node.callee.type === 'Identifier' && node.callee.name === 'defined' && node.arguments.length == 1
82
+ // and that arg is `NAPI_EXPERIMENTAL`
83
+ && node.arguments[0].type === 'Identifier' && node.arguments[0].name === 'NAPI_EXPERIMENTAL';
84
+
85
+ if (isDefinedExperimentalCall) {
86
+ return false;
87
+ }
88
+ };
89
+
90
+ module.exports = {
91
+ evaluate
92
+ };
@@ -33,17 +33,16 @@
33
33
  }
34
34
  ],
35
35
  "description": "Node-API headers",
36
- "dependencies": {},
37
- "devDependencies": {},
36
+ "devDependencies": {
37
+ "acorn": "^8.12.1"
38
+ },
38
39
  "directories": {},
39
40
  "gypfile": false,
40
41
  "homepage": "https://github.com/nodejs/node-api-headers",
41
- "keywords": [
42
- ],
42
+ "keywords": [],
43
43
  "license": "MIT",
44
44
  "main": "index.js",
45
45
  "name": "node-api-headers",
46
- "optionalDependencies": {},
47
46
  "readme": "README.md",
48
47
  "repository": {
49
48
  "type": "git",
@@ -52,8 +51,9 @@
52
51
  "scripts": {
53
52
  "update-headers": "node --no-warnings scripts/update-headers.js",
54
53
  "write-symbols": "node --no-warnings scripts/write-symbols.js",
55
- "write-win32-def": "node --no-warnings scripts/write-win32-def.js"
54
+ "write-win32-def": "node --no-warnings scripts/write-win32-def.js",
55
+ "test": "node test/parse-utils.js "
56
56
  },
57
- "version": "1.1.0",
57
+ "version": "1.5.0",
58
58
  "support": true
59
59
  }
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3
+ "release-type": "node",
4
+ "pull-request-title-pattern": "chore: release v${version}",
5
+ "bootstrap-sha": "9d78c7da25c5f90617600e23d2a8e7a23288f1ae",
6
+ "packages": {
7
+ ".": {
8
+ "include-component-in-tag": false,
9
+ "changelog-path": "CHANGELOG.md"
10
+ }
11
+ }
12
+ }
@@ -6,7 +6,8 @@ const { resolve } = require('path');
6
6
  const { parseArgs } = require('util')
7
7
  const { createInterface } = require('readline');
8
8
  const { inspect } = require('util');
9
- const { runClang } = require('./clang-utils');
9
+ const { runClang } = require('../lib/clang-utils');
10
+ const { evaluate } = require('../lib/parse-utils');
10
11
 
11
12
  /**
12
13
  * @returns {Promise<string>} Version string, eg. `'v19.6.0'`.
@@ -32,8 +33,11 @@ function removeExperimentals(stream, destination, verbose = false) {
32
33
  };
33
34
  const rl = createInterface(stream);
34
35
 
35
- /** @type {Array<'write' | 'ignore'>} */
36
- let mode = ['write'];
36
+ /** @type {Array<'write' | 'ignore' | 'preprocessor'>} */
37
+ const mode = ['write'];
38
+
39
+ /** @type {Array<string>} */
40
+ const preprocessor = [];
37
41
 
38
42
  /** @type {Array<string>} */
39
43
  const macroStack = [];
@@ -44,6 +48,22 @@ function removeExperimentals(stream, destination, verbose = false) {
44
48
  let lineNumber = 0;
45
49
  let toWrite = '';
46
50
 
51
+ const handlePreprocessor = (expression) => {
52
+ const result = evaluate(expression);
53
+
54
+ macroStack.push(expression);
55
+
56
+ if (result === false) {
57
+ debug(`Line ${lineNumber} Ignored '${expression}'`);
58
+ mode.push('ignore');
59
+ return false;
60
+ } else {
61
+ debug(`Line ${lineNumber} Pushed '${expression}'`);
62
+ mode.push('write');
63
+ return true;
64
+ }
65
+ };
66
+
47
67
  rl.on('line', function lineHandler(line) {
48
68
  ++lineNumber;
49
69
  if (matches = line.match(/^\s*#if(n)?def\s+([A-Za-z_][A-Za-z0-9_]*)/)) {
@@ -63,14 +83,23 @@ function removeExperimentals(stream, destination, verbose = false) {
63
83
  } else {
64
84
  mode.push('write');
65
85
  }
66
-
67
86
  }
68
87
  else if (matches = line.match(/^\s*#if\s+(.+)$/)) {
69
- const identifier = matches[1];
70
- macroStack.push(identifier);
71
- mode.push('write');
88
+ const expression = matches[1];
89
+ if (expression.endsWith('\\')) {
90
+ if (preprocessor.length) {
91
+ reject(new Error(`Unexpected preprocessor continuation on line ${lineNumber}`));
92
+ return;
93
+ }
94
+ preprocessor.push(expression.substring(0, expression.length - 1));
72
95
 
73
- debug(`Line ${lineNumber} Pushed ${identifier}`);
96
+ mode.push('preprocessor');
97
+ return;
98
+ } else {
99
+ if (!handlePreprocessor(expression)) {
100
+ return;
101
+ }
102
+ }
74
103
  }
75
104
  else if (line.match(/^#else(?:\s+|$)/)) {
76
105
  const identifier = macroStack[macroStack.length - 1];
@@ -83,7 +112,7 @@ function removeExperimentals(stream, destination, verbose = false) {
83
112
  return;
84
113
  }
85
114
 
86
- if (identifier === 'NAPI_EXPERIMENTAL') {
115
+ if (identifier.indexOf('NAPI_EXPERIMENTAL') > -1) {
87
116
  const lastMode = mode[mode.length - 1];
88
117
  mode[mode.length - 1] = (lastMode === 'ignore') ? 'write' : 'ignore';
89
118
  return;
@@ -98,9 +127,10 @@ function removeExperimentals(stream, destination, verbose = false) {
98
127
  if (!identifier) {
99
128
  rl.off('line', lineHandler);
100
129
  reject(new Error(`Macro stack is empty handling #endif on line ${lineNumber}`));
130
+ return;
101
131
  }
102
132
 
103
- if (identifier === 'NAPI_EXPERIMENTAL') {
133
+ if (identifier.indexOf('NAPI_EXPERIMENTAL') > -1) {
104
134
  return;
105
135
  }
106
136
  }
@@ -113,7 +143,28 @@ function removeExperimentals(stream, destination, verbose = false) {
113
143
 
114
144
  if (mode[mode.length - 1] === 'write') {
115
145
  toWrite += `${line}\n`;
146
+ } else if (mode[mode.length - 1] === 'preprocessor') {
147
+ if (!preprocessor) {
148
+ reject(new Error(`Preprocessor mode without preprocessor on line ${lineNumber}`));
149
+ return;
150
+ }
151
+
152
+ if (line.endsWith('\\')) {
153
+ preprocessor.push(line.substring(0, line.length - 1));
154
+ return;
155
+ }
156
+
157
+ preprocessor.push(line);
158
+
159
+ const expression = preprocessor.join('');
160
+ preprocessor.length = 0;
161
+ mode.pop();
162
+
163
+ if (!handlePreprocessor(expression)) {
164
+ return;
165
+ }
116
166
  }
167
+
117
168
  });
118
169
 
119
170
  rl.on('close', () => {
@@ -138,7 +189,7 @@ function removeExperimentals(stream, destination, verbose = false) {
138
189
  * @param {string} path Path for file to validate with clang.
139
190
  */
140
191
  async function validateSyntax(path) {
141
- try {
192
+ try {
142
193
  await runClang(['-fsyntax-only', path]);
143
194
  } catch (e) {
144
195
  throw new Error(`Syntax validation failed for ${path}: ${e}`);
@@ -160,7 +211,7 @@ async function main() {
160
211
  },
161
212
  });
162
213
 
163
- console.log(`Update headers from nodejs/node tag ${tag}`);
214
+ console.log(`feat: update headers from nodejs/node tag ${tag}`);
164
215
 
165
216
  const files = ['js_native_api_types.h', 'js_native_api.h', 'node_api_types.h', 'node_api.h'];
166
217
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { resolve: resolvePath } = require('path');
4
4
  const { writeFile } = require('fs/promises');
5
- const { runClang } = require('./clang-utils');
5
+ const { runClang } = require('../lib/clang-utils');
6
6
 
7
7
  /** @typedef {{ js_native_api_symbols: string[]; node_api_symbols: string[]; }} SymbolInfo */
8
8
 
@@ -228,6 +228,21 @@ const v9 = {
228
228
  ]
229
229
  }
230
230
 
231
+ const v10 = {
232
+ js_native_api_symbols: [
233
+ ...v9.js_native_api_symbols,
234
+ 'node_api_create_external_string_latin1',
235
+ 'node_api_create_external_string_utf16',
236
+ 'node_api_create_property_key_latin1',
237
+ 'node_api_create_property_key_utf16',
238
+ 'node_api_create_property_key_utf8'
239
+ ],
240
+ node_api_symbols: [
241
+ ...v9.node_api_symbols,
242
+ 'node_api_create_buffer_from_arraybuffer'
243
+ ]
244
+ }
245
+
231
246
  module.exports = {
232
247
  v1,
233
248
  v2,
@@ -237,5 +252,6 @@ module.exports = {
237
252
  v6,
238
253
  v7,
239
254
  v8,
240
- v9
255
+ v9,
256
+ v10
241
257
  }
@@ -0,0 +1,21 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert');
3
+ const { evaluate } = require("../lib/parse-utils");
4
+
5
+ /** @type {Array<[string, boolean | undefined]>} */
6
+ const testCases = [
7
+ [`defined(NAPI_EXPERIMENTAL)`, false],
8
+ [`!defined(NAPI_EXPERIMENTAL)`, true],
9
+ [`defined(NAPI_EXPERIMENTAL) || defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT)`, undefined],
10
+ [`defined(NAPI_EXPERIMENTAL) && defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT)`, false],
11
+ [`!defined(NAPI_EXPERIMENTAL) || (defined(NAPI_EXPERIMENTAL) && (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))`, true],
12
+ [`NAPI_VERSION >= 9`, undefined],
13
+ [`!defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900)`, undefined], // parser error on `defined __cplusplus`
14
+ ];
15
+
16
+ for (const [text, expected] of testCases) {
17
+ test(`${text} -> ${expected}`, (t) => {
18
+ const result = evaluate(text);
19
+ assert.strictEqual(result, expected);
20
+ });
21
+ }
package/doc/flat/flat.css DELETED
@@ -1,27 +0,0 @@
1
- /* Copyright (C) 2024 Niels Martignène <niels.martignene@protonmail.com>
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the “Software”), to deal in
5
- the Software without restriction, including without limitation the rights to use,
6
- copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- Software, and to permit persons to whom the Software is furnished to do so,
8
- subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- OTHER DEALINGS IN THE SOFTWARE. */
21
-
22
- @import url('../../../vendor/opensans/OpenSans.css');
23
- @import url('./reset.css');
24
-
25
- @import url('./normal.css');
26
- @import url('./small.css');
27
- @import url('./print.css');