@kungfu-tech/libnode-win32-x64 0.0.0-bootstrap.0 → 22.22.3-kf.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 (343) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +3 -0
  3. package/dist/node/include/acorn_version.h +6 -0
  4. package/dist/node/include/aliased_buffer-inl.h +244 -0
  5. package/dist/node/include/aliased_buffer.h +206 -0
  6. package/dist/node/include/aliased_struct-inl.h +54 -0
  7. package/dist/node/include/aliased_struct.h +63 -0
  8. package/dist/node/include/amaro_version.h +6 -0
  9. package/dist/node/include/async_context_frame.h +33 -0
  10. package/dist/node/include/async_wrap-inl.h +96 -0
  11. package/dist/node/include/async_wrap.h +243 -0
  12. package/dist/node/include/base_object-inl.h +335 -0
  13. package/dist/node/include/base_object.h +342 -0
  14. package/dist/node/include/base_object_types.h +74 -0
  15. package/dist/node/include/blob_serializer_deserializer-inl.h +385 -0
  16. package/dist/node/include/blob_serializer_deserializer.h +132 -0
  17. package/dist/node/include/callback_queue-inl.h +97 -0
  18. package/dist/node/include/callback_queue.h +79 -0
  19. package/dist/node/include/cares_wrap.h +447 -0
  20. package/dist/node/include/cjs_module_lexer_version.h +6 -0
  21. package/dist/node/include/cleanup_queue-inl.h +36 -0
  22. package/dist/node/include/cleanup_queue.h +79 -0
  23. package/dist/node/include/compile_cache.h +104 -0
  24. package/dist/node/include/connect_wrap.h +26 -0
  25. package/dist/node/include/connection_wrap.h +30 -0
  26. package/dist/node/include/cppgc/allocation.h +310 -0
  27. package/dist/node/include/cppgc/common.h +28 -0
  28. package/dist/node/include/cppgc/cross-thread-persistent.h +466 -0
  29. package/dist/node/include/cppgc/custom-space.h +97 -0
  30. package/dist/node/include/cppgc/default-platform.h +67 -0
  31. package/dist/node/include/cppgc/ephemeron-pair.h +30 -0
  32. package/dist/node/include/cppgc/explicit-management.h +100 -0
  33. package/dist/node/include/cppgc/garbage-collected.h +106 -0
  34. package/dist/node/include/cppgc/heap-consistency.h +309 -0
  35. package/dist/node/include/cppgc/heap-handle.h +48 -0
  36. package/dist/node/include/cppgc/heap-state.h +82 -0
  37. package/dist/node/include/cppgc/heap-statistics.h +120 -0
  38. package/dist/node/include/cppgc/heap.h +202 -0
  39. package/dist/node/include/cppgc/internal/api-constants.h +87 -0
  40. package/dist/node/include/cppgc/internal/atomic-entry-flag.h +48 -0
  41. package/dist/node/include/cppgc/internal/base-page-handle.h +45 -0
  42. package/dist/node/include/cppgc/internal/caged-heap-local-data.h +121 -0
  43. package/dist/node/include/cppgc/internal/caged-heap.h +68 -0
  44. package/dist/node/include/cppgc/internal/compiler-specific.h +38 -0
  45. package/dist/node/include/cppgc/internal/finalizer-trait.h +93 -0
  46. package/dist/node/include/cppgc/internal/gc-info.h +148 -0
  47. package/dist/node/include/cppgc/internal/logging.h +50 -0
  48. package/dist/node/include/cppgc/internal/member-storage.h +256 -0
  49. package/dist/node/include/cppgc/internal/name-trait.h +137 -0
  50. package/dist/node/include/cppgc/internal/persistent-node.h +214 -0
  51. package/dist/node/include/cppgc/internal/pointer-policies.h +243 -0
  52. package/dist/node/include/cppgc/internal/write-barrier.h +487 -0
  53. package/dist/node/include/cppgc/liveness-broker.h +78 -0
  54. package/dist/node/include/cppgc/macros.h +35 -0
  55. package/dist/node/include/cppgc/member.h +629 -0
  56. package/dist/node/include/cppgc/name-provider.h +65 -0
  57. package/dist/node/include/cppgc/object-size-trait.h +58 -0
  58. package/dist/node/include/cppgc/persistent.h +377 -0
  59. package/dist/node/include/cppgc/platform.h +163 -0
  60. package/dist/node/include/cppgc/prefinalizer.h +75 -0
  61. package/dist/node/include/cppgc/process-heap-statistics.h +36 -0
  62. package/dist/node/include/cppgc/sentinel-pointer.h +39 -0
  63. package/dist/node/include/cppgc/source-location.h +16 -0
  64. package/dist/node/include/cppgc/testing.h +106 -0
  65. package/dist/node/include/cppgc/trace-trait.h +128 -0
  66. package/dist/node/include/cppgc/type-traits.h +271 -0
  67. package/dist/node/include/cppgc/visitor.h +504 -0
  68. package/dist/node/include/crypto/crypto_aes.h +88 -0
  69. package/dist/node/include/crypto/crypto_bio.h +193 -0
  70. package/dist/node/include/crypto/crypto_cipher.h +293 -0
  71. package/dist/node/include/crypto/crypto_clienthello-inl.h +90 -0
  72. package/dist/node/include/crypto/crypto_clienthello.h +131 -0
  73. package/dist/node/include/crypto/crypto_common.h +64 -0
  74. package/dist/node/include/crypto/crypto_context.h +171 -0
  75. package/dist/node/include/crypto/crypto_dh.h +126 -0
  76. package/dist/node/include/crypto/crypto_dsa.h +52 -0
  77. package/dist/node/include/crypto/crypto_ec.h +164 -0
  78. package/dist/node/include/crypto/crypto_hash.h +91 -0
  79. package/dist/node/include/crypto/crypto_hkdf.h +61 -0
  80. package/dist/node/include/crypto/crypto_hmac.h +92 -0
  81. package/dist/node/include/crypto/crypto_keygen.h +299 -0
  82. package/dist/node/include/crypto/crypto_keys.h +392 -0
  83. package/dist/node/include/crypto/crypto_pbkdf2.h +74 -0
  84. package/dist/node/include/crypto/crypto_random.h +124 -0
  85. package/dist/node/include/crypto/crypto_rsa.h +136 -0
  86. package/dist/node/include/crypto/crypto_scrypt.h +85 -0
  87. package/dist/node/include/crypto/crypto_sig.h +165 -0
  88. package/dist/node/include/crypto/crypto_spkac.h +21 -0
  89. package/dist/node/include/crypto/crypto_timing.h +20 -0
  90. package/dist/node/include/crypto/crypto_tls.h +305 -0
  91. package/dist/node/include/crypto/crypto_util.h +725 -0
  92. package/dist/node/include/crypto/crypto_x509.h +140 -0
  93. package/dist/node/include/dataqueue/queue.h +306 -0
  94. package/dist/node/include/debug_utils-inl.h +278 -0
  95. package/dist/node/include/debug_utils.h +196 -0
  96. package/dist/node/include/diagnosticfilename-inl.h +33 -0
  97. package/dist/node/include/embedded_data.h +17 -0
  98. package/dist/node/include/encoding_binding.h +61 -0
  99. package/dist/node/include/env-inl.h +984 -0
  100. package/dist/node/include/env.h +1287 -0
  101. package/dist/node/include/env_properties.h +540 -0
  102. package/dist/node/include/handle_wrap.h +123 -0
  103. package/dist/node/include/histogram-inl.h +107 -0
  104. package/dist/node/include/histogram.h +279 -0
  105. package/dist/node/include/inspector/io_agent.h +30 -0
  106. package/dist/node/include/inspector/main_thread_interface.h +116 -0
  107. package/dist/node/include/inspector/network_agent.h +94 -0
  108. package/dist/node/include/inspector/network_inspector.h +45 -0
  109. package/dist/node/include/inspector/network_requests_buffer.h +195 -0
  110. package/dist/node/include/inspector/network_resource_manager.h +29 -0
  111. package/dist/node/include/inspector/node_json.h +24 -0
  112. package/dist/node/include/inspector/node_string.h +101 -0
  113. package/dist/node/include/inspector/protocol_helper.h +27 -0
  114. package/dist/node/include/inspector/runtime_agent.h +41 -0
  115. package/dist/node/include/inspector/target_agent.h +75 -0
  116. package/dist/node/include/inspector/tracing_agent.h +43 -0
  117. package/dist/node/include/inspector/worker_agent.h +40 -0
  118. package/dist/node/include/inspector/worker_inspector.h +124 -0
  119. package/dist/node/include/inspector_agent.h +165 -0
  120. package/dist/node/include/inspector_io.h +78 -0
  121. package/dist/node/include/inspector_profiler.h +149 -0
  122. package/dist/node/include/inspector_socket.h +60 -0
  123. package/dist/node/include/inspector_socket_server.h +110 -0
  124. package/dist/node/include/js_native_api.h +607 -0
  125. package/dist/node/include/js_native_api_types.h +226 -0
  126. package/dist/node/include/js_native_api_v8.h +485 -0
  127. package/dist/node/include/js_native_api_v8_internals.h +45 -0
  128. package/dist/node/include/js_stream.h +52 -0
  129. package/dist/node/include/json_utils.h +172 -0
  130. package/dist/node/include/large_pages/node_large_page.h +34 -0
  131. package/dist/node/include/libplatform/libplatform-export.h +29 -0
  132. package/dist/node/include/libplatform/libplatform.h +112 -0
  133. package/dist/node/include/libplatform/v8-tracing.h +333 -0
  134. package/dist/node/include/memory_tracker-inl.h +359 -0
  135. package/dist/node/include/memory_tracker.h +289 -0
  136. package/dist/node/include/module_wrap.h +216 -0
  137. package/dist/node/include/node.h +1593 -0
  138. package/dist/node/include/node_api.h +265 -0
  139. package/dist/node/include/node_api_internals.h +48 -0
  140. package/dist/node/include/node_api_types.h +56 -0
  141. package/dist/node/include/node_binding.h +161 -0
  142. package/dist/node/include/node_blob.h +159 -0
  143. package/dist/node/include/node_bob-inl.h +36 -0
  144. package/dist/node/include/node_bob.h +107 -0
  145. package/dist/node/include/node_buffer.h +92 -0
  146. package/dist/node/include/node_builtins.h +220 -0
  147. package/dist/node/include/node_config_file.h +46 -0
  148. package/dist/node/include/node_constants.h +82 -0
  149. package/dist/node/include/node_context_data.h +168 -0
  150. package/dist/node/include/node_contextify.h +204 -0
  151. package/dist/node/include/node_crypto.h +56 -0
  152. package/dist/node/include/node_debug.h +30 -0
  153. package/dist/node/include/node_dir.h +52 -0
  154. package/dist/node/include/node_dotenv.h +45 -0
  155. package/dist/node/include/node_errors.h +380 -0
  156. package/dist/node/include/node_exit_code.h +54 -0
  157. package/dist/node/include/node_external_reference.h +165 -0
  158. package/dist/node/include/node_file-inl.h +406 -0
  159. package/dist/node/include/node_file.h +537 -0
  160. package/dist/node/include/node_http2.h +1177 -0
  161. package/dist/node/include/node_http2_state.h +159 -0
  162. package/dist/node/include/node_http_common-inl.h +202 -0
  163. package/dist/node/include/node_http_common.h +535 -0
  164. package/dist/node/include/node_i18n.h +132 -0
  165. package/dist/node/include/node_internals.h +483 -0
  166. package/dist/node/include/node_main_instance.h +67 -0
  167. package/dist/node/include/node_mem-inl.h +113 -0
  168. package/dist/node/include/node_mem.h +45 -0
  169. package/dist/node/include/node_messaging.h +389 -0
  170. package/dist/node/include/node_metadata.h +164 -0
  171. package/dist/node/include/node_modules.h +91 -0
  172. package/dist/node/include/node_mutex.h +323 -0
  173. package/dist/node/include/node_object_wrap.h +132 -0
  174. package/dist/node/include/node_options-inl.h +490 -0
  175. package/dist/node/include/node_options.h +615 -0
  176. package/dist/node/include/node_perf.h +166 -0
  177. package/dist/node/include/node_perf_common.h +102 -0
  178. package/dist/node/include/node_platform.h +238 -0
  179. package/dist/node/include/node_process-inl.h +26 -0
  180. package/dist/node/include/node_process.h +112 -0
  181. package/dist/node/include/node_realm-inl.h +151 -0
  182. package/dist/node/include/node_realm.h +183 -0
  183. package/dist/node/include/node_report.h +43 -0
  184. package/dist/node/include/node_revert.h +82 -0
  185. package/dist/node/include/node_root_certs.h +3520 -0
  186. package/dist/node/include/node_sea.h +74 -0
  187. package/dist/node/include/node_shadow_realm.h +46 -0
  188. package/dist/node/include/node_snapshot_builder.h +57 -0
  189. package/dist/node/include/node_snapshotable.h +174 -0
  190. package/dist/node/include/node_sockaddr-inl.h +257 -0
  191. package/dist/node/include/node_sockaddr.h +394 -0
  192. package/dist/node/include/node_sqlite.h +270 -0
  193. package/dist/node/include/node_stat_watcher.h +73 -0
  194. package/dist/node/include/node_task_runner.h +92 -0
  195. package/dist/node/include/node_threadsafe_cow-inl.h +54 -0
  196. package/dist/node/include/node_threadsafe_cow.h +105 -0
  197. package/dist/node/include/node_union_bytes.h +81 -0
  198. package/dist/node/include/node_url.h +96 -0
  199. package/dist/node/include/node_v8.h +77 -0
  200. package/dist/node/include/node_v8_platform-inl.h +185 -0
  201. package/dist/node/include/node_version.h +110 -0
  202. package/dist/node/include/node_wasi.h +184 -0
  203. package/dist/node/include/node_wasm_web_api.h +55 -0
  204. package/dist/node/include/node_watchdog.h +154 -0
  205. package/dist/node/include/node_webstorage.h +60 -0
  206. package/dist/node/include/node_worker.h +158 -0
  207. package/dist/node/include/path.h +33 -0
  208. package/dist/node/include/permission/addon_permission.h +31 -0
  209. package/dist/node/include/permission/child_process_permission.h +31 -0
  210. package/dist/node/include/permission/fs_permission.h +167 -0
  211. package/dist/node/include/permission/inspector_permission.h +31 -0
  212. package/dist/node/include/permission/permission.h +138 -0
  213. package/dist/node/include/permission/permission_base.h +65 -0
  214. package/dist/node/include/permission/wasi_permission.h +31 -0
  215. package/dist/node/include/permission/worker_permission.h +31 -0
  216. package/dist/node/include/pipe_wrap.h +80 -0
  217. package/dist/node/include/quic/application.h +159 -0
  218. package/dist/node/include/quic/bindingdata.h +272 -0
  219. package/dist/node/include/quic/cid.h +127 -0
  220. package/dist/node/include/quic/data.h +148 -0
  221. package/dist/node/include/quic/defs.h +245 -0
  222. package/dist/node/include/quic/endpoint.h +458 -0
  223. package/dist/node/include/quic/http3.h +15 -0
  224. package/dist/node/include/quic/logstream.h +81 -0
  225. package/dist/node/include/quic/packet.h +152 -0
  226. package/dist/node/include/quic/preferredaddress.h +72 -0
  227. package/dist/node/include/quic/session.h +443 -0
  228. package/dist/node/include/quic/sessionticket.h +108 -0
  229. package/dist/node/include/quic/streams.h +232 -0
  230. package/dist/node/include/quic/tlscontext.h +227 -0
  231. package/dist/node/include/quic/tokens.h +256 -0
  232. package/dist/node/include/quic/transportparams.h +165 -0
  233. package/dist/node/include/req_wrap-inl.h +171 -0
  234. package/dist/node/include/req_wrap.h +77 -0
  235. package/dist/node/include/spawn_sync.h +243 -0
  236. package/dist/node/include/stream_base-inl.h +173 -0
  237. package/dist/node/include/stream_base.h +478 -0
  238. package/dist/node/include/stream_pipe.h +76 -0
  239. package/dist/node/include/stream_wrap.h +132 -0
  240. package/dist/node/include/string_bytes.h +113 -0
  241. package/dist/node/include/string_decoder-inl.h +31 -0
  242. package/dist/node/include/string_decoder.h +49 -0
  243. package/dist/node/include/tcp_wrap.h +105 -0
  244. package/dist/node/include/threadpoolwork-inl.h +70 -0
  245. package/dist/node/include/timer_wrap-inl.h +32 -0
  246. package/dist/node/include/timer_wrap.h +85 -0
  247. package/dist/node/include/timers.h +70 -0
  248. package/dist/node/include/tracing/agent.h +195 -0
  249. package/dist/node/include/tracing/node_trace_buffer.h +83 -0
  250. package/dist/node/include/tracing/node_trace_writer.h +75 -0
  251. package/dist/node/include/tracing/trace_event.h +722 -0
  252. package/dist/node/include/tracing/trace_event_common.h +1109 -0
  253. package/dist/node/include/tracing/traced_value.h +129 -0
  254. package/dist/node/include/tty_wrap.h +65 -0
  255. package/dist/node/include/udp_wrap.h +230 -0
  256. package/dist/node/include/undici_version.h +6 -0
  257. package/dist/node/include/util-inl.h +700 -0
  258. package/dist/node/include/util.h +1021 -0
  259. package/dist/node/include/uv/aix.h +32 -0
  260. package/dist/node/include/uv/bsd.h +34 -0
  261. package/dist/node/include/uv/darwin.h +61 -0
  262. package/dist/node/include/uv/errno.h +483 -0
  263. package/dist/node/include/uv/linux.h +34 -0
  264. package/dist/node/include/uv/os390.h +33 -0
  265. package/dist/node/include/uv/posix.h +31 -0
  266. package/dist/node/include/uv/sunos.h +44 -0
  267. package/dist/node/include/uv/threadpool.h +37 -0
  268. package/dist/node/include/uv/tree.h +521 -0
  269. package/dist/node/include/uv/unix.h +512 -0
  270. package/dist/node/include/uv/version.h +43 -0
  271. package/dist/node/include/uv/win.h +698 -0
  272. package/dist/node/include/uv.h +1990 -0
  273. package/dist/node/include/v8-array-buffer.h +525 -0
  274. package/dist/node/include/v8-callbacks.h +462 -0
  275. package/dist/node/include/v8-container.h +183 -0
  276. package/dist/node/include/v8-context.h +485 -0
  277. package/dist/node/include/v8-cppgc.h +245 -0
  278. package/dist/node/include/v8-data.h +80 -0
  279. package/dist/node/include/v8-date.h +48 -0
  280. package/dist/node/include/v8-debug.h +168 -0
  281. package/dist/node/include/v8-embedder-heap.h +82 -0
  282. package/dist/node/include/v8-embedder-state-scope.h +52 -0
  283. package/dist/node/include/v8-exception.h +223 -0
  284. package/dist/node/include/v8-extension.h +62 -0
  285. package/dist/node/include/v8-external.h +37 -0
  286. package/dist/node/include/v8-fast-api-calls.h +984 -0
  287. package/dist/node/include/v8-forward.h +82 -0
  288. package/dist/node/include/v8-function-callback.h +607 -0
  289. package/dist/node/include/v8-function.h +140 -0
  290. package/dist/node/include/v8-handle-base.h +137 -0
  291. package/dist/node/include/v8-initialization.h +289 -0
  292. package/dist/node/include/v8-inspector-protocol.h +13 -0
  293. package/dist/node/include/v8-inspector.h +419 -0
  294. package/dist/node/include/v8-internal.h +1397 -0
  295. package/dist/node/include/v8-isolate.h +1767 -0
  296. package/dist/node/include/v8-json.h +47 -0
  297. package/dist/node/include/v8-local-handle.h +758 -0
  298. package/dist/node/include/v8-locker.h +138 -0
  299. package/dist/node/include/v8-maybe.h +160 -0
  300. package/dist/node/include/v8-memory-span.h +198 -0
  301. package/dist/node/include/v8-message.h +233 -0
  302. package/dist/node/include/v8-metrics.h +264 -0
  303. package/dist/node/include/v8-microtask-queue.h +157 -0
  304. package/dist/node/include/v8-microtask.h +28 -0
  305. package/dist/node/include/v8-object.h +824 -0
  306. package/dist/node/include/v8-persistent-handle.h +582 -0
  307. package/dist/node/include/v8-platform.h +1358 -0
  308. package/dist/node/include/v8-primitive-object.h +118 -0
  309. package/dist/node/include/v8-primitive.h +877 -0
  310. package/dist/node/include/v8-profiler.h +1302 -0
  311. package/dist/node/include/v8-promise.h +174 -0
  312. package/dist/node/include/v8-proxy.h +50 -0
  313. package/dist/node/include/v8-regexp.h +106 -0
  314. package/dist/node/include/v8-script.h +904 -0
  315. package/dist/node/include/v8-snapshot.h +266 -0
  316. package/dist/node/include/v8-source-location.h +92 -0
  317. package/dist/node/include/v8-statistics.h +238 -0
  318. package/dist/node/include/v8-template.h +1297 -0
  319. package/dist/node/include/v8-traced-handle.h +432 -0
  320. package/dist/node/include/v8-typed-array.h +390 -0
  321. package/dist/node/include/v8-unwinder-state.h +31 -0
  322. package/dist/node/include/v8-unwinder.h +132 -0
  323. package/dist/node/include/v8-util.h +665 -0
  324. package/dist/node/include/v8-value-serializer-version.h +24 -0
  325. package/dist/node/include/v8-value-serializer.h +316 -0
  326. package/dist/node/include/v8-value.h +655 -0
  327. package/dist/node/include/v8-version-string.h +38 -0
  328. package/dist/node/include/v8-version.h +20 -0
  329. package/dist/node/include/v8-wasm-trap-handler-posix.h +31 -0
  330. package/dist/node/include/v8-wasm-trap-handler-win.h +28 -0
  331. package/dist/node/include/v8-wasm.h +201 -0
  332. package/dist/node/include/v8-weak-callback-info.h +80 -0
  333. package/dist/node/include/v8.h +88 -0
  334. package/dist/node/include/v8config.h +981 -0
  335. package/dist/node/include/zlib_version.h +6 -0
  336. package/dist/node/libnode.dll +0 -0
  337. package/dist/node/libnode.lib +0 -0
  338. package/dist/node/libnodebuildinfo.json +10 -0
  339. package/dist/node/link_node.lib +0 -0
  340. package/dist/node/link_node.node +0 -0
  341. package/index.js +5 -0
  342. package/libnode.release.json +8 -0
  343. package/package.json +29 -1
@@ -0,0 +1,700 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ #ifndef SRC_UTIL_INL_H_
23
+ #define SRC_UTIL_INL_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include <cmath>
28
+ #include <cstring>
29
+ #include <locale>
30
+ #include "node_revert.h"
31
+ #include "util.h"
32
+
33
+ #ifdef _WIN32
34
+ #include <regex> // NOLINT(build/c++11)
35
+ #endif // _WIN32
36
+
37
+ #define CHAR_TEST(bits, name, expr) \
38
+ template <typename T> \
39
+ bool name(const T ch) { \
40
+ static_assert(sizeof(ch) >= (bits) / 8, \
41
+ "Character must be wider than " #bits " bits"); \
42
+ return (expr); \
43
+ }
44
+
45
+ namespace node {
46
+
47
+ template <typename T>
48
+ ListNode<T>::ListNode() : prev_(this), next_(this) {}
49
+
50
+ template <typename T>
51
+ ListNode<T>::~ListNode() {
52
+ Remove();
53
+ }
54
+
55
+ template <typename T>
56
+ void ListNode<T>::Remove() {
57
+ prev_->next_ = next_;
58
+ next_->prev_ = prev_;
59
+ prev_ = this;
60
+ next_ = this;
61
+ }
62
+
63
+ template <typename T>
64
+ bool ListNode<T>::IsEmpty() const {
65
+ return prev_ == this;
66
+ }
67
+
68
+ template <typename T, ListNode<T> (T::*M)>
69
+ ListHead<T, M>::Iterator::Iterator(ListNode<T>* node) : node_(node) {}
70
+
71
+ template <typename T, ListNode<T> (T::*M)>
72
+ T* ListHead<T, M>::Iterator::operator*() const {
73
+ return ContainerOf(M, node_);
74
+ }
75
+
76
+ template <typename T, ListNode<T> (T::*M)>
77
+ const typename ListHead<T, M>::Iterator&
78
+ ListHead<T, M>::Iterator::operator++() {
79
+ node_ = node_->next_;
80
+ return *this;
81
+ }
82
+
83
+ template <typename T, ListNode<T> (T::*M)>
84
+ bool ListHead<T, M>::Iterator::operator!=(const Iterator& that) const {
85
+ return node_ != that.node_;
86
+ }
87
+
88
+ template <typename T, ListNode<T> (T::*M)>
89
+ ListHead<T, M>::~ListHead() {
90
+ while (IsEmpty() == false)
91
+ head_.next_->Remove();
92
+ }
93
+
94
+ template <typename T, ListNode<T> (T::*M)>
95
+ void ListHead<T, M>::PushBack(T* element) {
96
+ ListNode<T>* that = &(element->*M);
97
+ head_.prev_->next_ = that;
98
+ that->prev_ = head_.prev_;
99
+ that->next_ = &head_;
100
+ head_.prev_ = that;
101
+ }
102
+
103
+ template <typename T, ListNode<T> (T::*M)>
104
+ void ListHead<T, M>::PushFront(T* element) {
105
+ ListNode<T>* that = &(element->*M);
106
+ head_.next_->prev_ = that;
107
+ that->prev_ = &head_;
108
+ that->next_ = head_.next_;
109
+ head_.next_ = that;
110
+ }
111
+
112
+ template <typename T, ListNode<T> (T::*M)>
113
+ bool ListHead<T, M>::IsEmpty() const {
114
+ return head_.IsEmpty();
115
+ }
116
+
117
+ template <typename T, ListNode<T> (T::*M)>
118
+ T* ListHead<T, M>::PopFront() {
119
+ if (IsEmpty())
120
+ return nullptr;
121
+ ListNode<T>* node = head_.next_;
122
+ node->Remove();
123
+ return ContainerOf(M, node);
124
+ }
125
+
126
+ template <typename T, ListNode<T> (T::*M)>
127
+ typename ListHead<T, M>::Iterator ListHead<T, M>::begin() const {
128
+ return Iterator(head_.next_);
129
+ }
130
+
131
+ template <typename T, ListNode<T> (T::*M)>
132
+ typename ListHead<T, M>::Iterator ListHead<T, M>::end() const {
133
+ return Iterator(const_cast<ListNode<T>*>(&head_));
134
+ }
135
+
136
+ template <typename Inner, typename Outer>
137
+ constexpr uintptr_t OffsetOf(Inner Outer::*field) {
138
+ return reinterpret_cast<uintptr_t>(&(static_cast<Outer*>(nullptr)->*field));
139
+ }
140
+
141
+ template <typename Inner, typename Outer>
142
+ ContainerOfHelper<Inner, Outer>::ContainerOfHelper(Inner Outer::*field,
143
+ Inner* pointer)
144
+ : pointer_(
145
+ reinterpret_cast<Outer*>(
146
+ reinterpret_cast<uintptr_t>(pointer) - OffsetOf(field))) {}
147
+
148
+ template <typename Inner, typename Outer>
149
+ template <typename TypeName>
150
+ ContainerOfHelper<Inner, Outer>::operator TypeName*() const {
151
+ return static_cast<TypeName*>(pointer_);
152
+ }
153
+
154
+ template <typename Inner, typename Outer>
155
+ constexpr ContainerOfHelper<Inner, Outer> ContainerOf(Inner Outer::*field,
156
+ Inner* pointer) {
157
+ return ContainerOfHelper<Inner, Outer>(field, pointer);
158
+ }
159
+
160
+ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
161
+ const char* data,
162
+ int length,
163
+ v8::NewStringType type) {
164
+ return v8::String::NewFromOneByte(
165
+ isolate, reinterpret_cast<const uint8_t*>(data), type, length)
166
+ .ToLocalChecked();
167
+ }
168
+
169
+ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
170
+ const signed char* data,
171
+ int length,
172
+ v8::NewStringType type) {
173
+ return v8::String::NewFromOneByte(
174
+ isolate, reinterpret_cast<const uint8_t*>(data), type, length)
175
+ .ToLocalChecked();
176
+ }
177
+
178
+ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
179
+ const unsigned char* data,
180
+ int length,
181
+ v8::NewStringType type) {
182
+ return v8::String::NewFromOneByte(isolate, data, type, length)
183
+ .ToLocalChecked();
184
+ }
185
+
186
+ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
187
+ std::string_view str,
188
+ v8::NewStringType type) {
189
+ return OneByteString(isolate, str.data(), str.size(), type);
190
+ }
191
+
192
+ char ToLower(char c) {
193
+ return std::tolower(c, std::locale::classic());
194
+ }
195
+
196
+ template <typename T>
197
+ std::string ToLower(const T& in) {
198
+ auto it = std::cbegin(in);
199
+ auto end = std::cend(in);
200
+ std::string out(std::distance(it, end), 0);
201
+ size_t i;
202
+ for (i = 0; it != end; ++it, ++i) out[i] = ToLower(*it);
203
+ DCHECK_EQ(i, out.size());
204
+ return out;
205
+ }
206
+
207
+ char ToUpper(char c) {
208
+ return std::toupper(c, std::locale::classic());
209
+ }
210
+
211
+ template <typename T>
212
+ std::string ToUpper(const T& in) {
213
+ auto it = std::cbegin(in);
214
+ auto end = std::cend(in);
215
+ std::string out(std::distance(it, end), 0);
216
+ size_t i;
217
+ for (i = 0; it != end; ++it, ++i) out[i] = ToUpper(*it);
218
+ DCHECK_EQ(i, out.size());
219
+ return out;
220
+ }
221
+
222
+ bool StringEqualNoCase(const char* a, const char* b) {
223
+ while (ToLower(*a) == ToLower(*b++)) {
224
+ if (*a++ == '\0')
225
+ return true;
226
+ }
227
+ return false;
228
+ }
229
+
230
+ bool StringEqualNoCaseN(const char* a, const char* b, size_t length) {
231
+ for (size_t i = 0; i < length; i++) {
232
+ if (ToLower(a[i]) != ToLower(b[i]))
233
+ return false;
234
+ if (a[i] == '\0')
235
+ return true;
236
+ }
237
+ return true;
238
+ }
239
+
240
+ template <typename T>
241
+ inline T MultiplyWithOverflowCheck(T a, T b) {
242
+ auto ret = a * b;
243
+ if (a != 0)
244
+ CHECK_EQ(b, ret / a);
245
+
246
+ return ret;
247
+ }
248
+
249
+ // These should be used in our code as opposed to the native
250
+ // versions as they abstract out some platform and or
251
+ // compiler version specific functionality.
252
+ // malloc(0) and realloc(ptr, 0) have implementation-defined behavior in
253
+ // that the standard allows them to either return a unique pointer or a
254
+ // nullptr for zero-sized allocation requests. Normalize by always using
255
+ // a nullptr.
256
+ template <typename T>
257
+ T* UncheckedRealloc(T* pointer, size_t n) {
258
+ size_t full_size = MultiplyWithOverflowCheck(sizeof(T), n);
259
+
260
+ if (full_size == 0) {
261
+ free(pointer);
262
+ return nullptr;
263
+ }
264
+
265
+ void* allocated = realloc(pointer, full_size);
266
+
267
+ if (allocated == nullptr) [[unlikely]] {
268
+ // Tell V8 that memory is low and retry.
269
+ LowMemoryNotification();
270
+ allocated = realloc(pointer, full_size);
271
+ }
272
+
273
+ return static_cast<T*>(allocated);
274
+ }
275
+
276
+ // As per spec realloc behaves like malloc if passed nullptr.
277
+ template <typename T>
278
+ inline T* UncheckedMalloc(size_t n) {
279
+ return UncheckedRealloc<T>(nullptr, n);
280
+ }
281
+
282
+ template <typename T>
283
+ inline T* UncheckedCalloc(size_t n) {
284
+ if (MultiplyWithOverflowCheck(sizeof(T), n) == 0) return nullptr;
285
+ return static_cast<T*>(calloc(n, sizeof(T)));
286
+ }
287
+
288
+ template <typename T>
289
+ inline T* Realloc(T* pointer, size_t n) {
290
+ T* ret = UncheckedRealloc(pointer, n);
291
+ CHECK_IMPLIES(n > 0, ret != nullptr);
292
+ return ret;
293
+ }
294
+
295
+ template <typename T>
296
+ inline T* Malloc(size_t n) {
297
+ T* ret = UncheckedMalloc<T>(n);
298
+ CHECK_IMPLIES(n > 0, ret != nullptr);
299
+ return ret;
300
+ }
301
+
302
+ template <typename T>
303
+ inline T* Calloc(size_t n) {
304
+ T* ret = UncheckedCalloc<T>(n);
305
+ CHECK_IMPLIES(n > 0, ret != nullptr);
306
+ return ret;
307
+ }
308
+
309
+ // Shortcuts for char*.
310
+ inline char* Malloc(size_t n) { return Malloc<char>(n); }
311
+ inline char* Calloc(size_t n) { return Calloc<char>(n); }
312
+ inline char* UncheckedMalloc(size_t n) { return UncheckedMalloc<char>(n); }
313
+ inline char* UncheckedCalloc(size_t n) { return UncheckedCalloc<char>(n); }
314
+
315
+ // This is a helper in the .cc file so including util-inl.h doesn't include more
316
+ // headers than we really need to.
317
+ void ThrowErrStringTooLong(v8::Isolate* isolate);
318
+
319
+ struct ArrayIterationData {
320
+ std::vector<v8::Global<v8::Value>>* out;
321
+ v8::Isolate* isolate = nullptr;
322
+ };
323
+
324
+ inline v8::Array::CallbackResult PushItemToVector(uint32_t index,
325
+ v8::Local<v8::Value> element,
326
+ void* data) {
327
+ auto vec = static_cast<ArrayIterationData*>(data)->out;
328
+ auto isolate = static_cast<ArrayIterationData*>(data)->isolate;
329
+ vec->push_back(v8::Global<v8::Value>(isolate, element));
330
+ return v8::Array::CallbackResult::kContinue;
331
+ }
332
+
333
+ v8::Maybe<void> FromV8Array(v8::Local<v8::Context> context,
334
+ v8::Local<v8::Array> js_array,
335
+ std::vector<v8::Global<v8::Value>>* out) {
336
+ uint32_t count = js_array->Length();
337
+ out->reserve(count);
338
+ ArrayIterationData data{out, context->GetIsolate()};
339
+ return js_array->Iterate(context, PushItemToVector, &data);
340
+ }
341
+
342
+ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
343
+ std::string_view str,
344
+ v8::Isolate* isolate) {
345
+ if (isolate == nullptr) isolate = context->GetIsolate();
346
+ if (str.size() >= static_cast<size_t>(v8::String::kMaxLength)) [[unlikely]] {
347
+ // V8 only has a TODO comment about adding an exception when the maximum
348
+ // string size is exceeded.
349
+ ThrowErrStringTooLong(isolate);
350
+ return v8::MaybeLocal<v8::Value>();
351
+ }
352
+
353
+ return v8::String::NewFromUtf8(
354
+ isolate, str.data(), v8::NewStringType::kNormal, str.size())
355
+ .FromMaybe(v8::Local<v8::String>());
356
+ }
357
+
358
+ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
359
+ v8_inspector::StringView str,
360
+ v8::Isolate* isolate) {
361
+ if (isolate == nullptr) isolate = context->GetIsolate();
362
+ if (str.length() >= static_cast<size_t>(v8::String::kMaxLength))
363
+ [[unlikely]] {
364
+ // V8 only has a TODO comment about adding an exception when the maximum
365
+ // string size is exceeded.
366
+ ThrowErrStringTooLong(isolate);
367
+ return v8::MaybeLocal<v8::Value>();
368
+ }
369
+
370
+ if (str.is8Bit()) {
371
+ return v8::String::NewFromOneByte(isolate,
372
+ str.characters8(),
373
+ v8::NewStringType::kNormal,
374
+ str.length())
375
+ .FromMaybe(v8::Local<v8::String>());
376
+ }
377
+ return v8::String::NewFromTwoByte(isolate,
378
+ str.characters16(),
379
+ v8::NewStringType::kNormal,
380
+ str.length())
381
+ .FromMaybe(v8::Local<v8::String>());
382
+ }
383
+
384
+ template <typename T>
385
+ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
386
+ const std::vector<T>& vec,
387
+ v8::Isolate* isolate) {
388
+ if (isolate == nullptr) isolate = context->GetIsolate();
389
+ v8::EscapableHandleScope handle_scope(isolate);
390
+
391
+ MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
392
+ arr.SetLength(vec.size());
393
+ for (size_t i = 0; i < vec.size(); ++i) {
394
+ if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i]))
395
+ return v8::MaybeLocal<v8::Value>();
396
+ }
397
+
398
+ return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
399
+ }
400
+
401
+ template <typename T>
402
+ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
403
+ const std::set<T>& set,
404
+ v8::Isolate* isolate) {
405
+ if (isolate == nullptr) isolate = context->GetIsolate();
406
+ v8::Local<v8::Set> set_js = v8::Set::New(isolate);
407
+ v8::HandleScope handle_scope(isolate);
408
+
409
+ for (const T& entry : set) {
410
+ v8::Local<v8::Value> value;
411
+ if (!ToV8Value(context, entry, isolate).ToLocal(&value))
412
+ return {};
413
+ if (set_js->Add(context, value).IsEmpty())
414
+ return {};
415
+ }
416
+
417
+ return set_js;
418
+ }
419
+
420
+ template <typename T, typename U>
421
+ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
422
+ const std::unordered_map<T, U>& map,
423
+ v8::Isolate* isolate) {
424
+ if (isolate == nullptr) isolate = context->GetIsolate();
425
+ v8::EscapableHandleScope handle_scope(isolate);
426
+
427
+ v8::Local<v8::Map> ret = v8::Map::New(isolate);
428
+ for (const auto& item : map) {
429
+ v8::Local<v8::Value> first, second;
430
+ if (!ToV8Value(context, item.first, isolate).ToLocal(&first) ||
431
+ !ToV8Value(context, item.second, isolate).ToLocal(&second) ||
432
+ ret->Set(context, first, second).IsEmpty()) {
433
+ return v8::MaybeLocal<v8::Value>();
434
+ }
435
+ }
436
+
437
+ return handle_scope.Escape(ret);
438
+ }
439
+
440
+ template <typename T>
441
+ v8::Local<v8::Value> ConvertNumberToV8Value(v8::Isolate* isolate,
442
+ const T& number) {
443
+ using Limits = std::numeric_limits<T>;
444
+ // Choose Uint32, Int32, or Double depending on range checks.
445
+ // These checks should all collapse at compile time.
446
+ if (static_cast<uint32_t>(Limits::max()) <=
447
+ std::numeric_limits<uint32_t>::max() &&
448
+ static_cast<uint32_t>(Limits::min()) >=
449
+ std::numeric_limits<uint32_t>::min() && Limits::is_exact) {
450
+ return v8::Integer::NewFromUnsigned(isolate, static_cast<uint32_t>(number));
451
+ }
452
+
453
+ if (static_cast<int32_t>(Limits::max()) <=
454
+ std::numeric_limits<int32_t>::max() &&
455
+ static_cast<int32_t>(Limits::min()) >=
456
+ std::numeric_limits<int32_t>::min() && Limits::is_exact) {
457
+ return v8::Integer::New(isolate, static_cast<int32_t>(number));
458
+ }
459
+
460
+ return v8::Number::New(isolate, static_cast<double>(number));
461
+ }
462
+
463
+ template <typename T, typename>
464
+ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
465
+ const T& number,
466
+ v8::Isolate* isolate) {
467
+ if (isolate == nullptr) isolate = context->GetIsolate();
468
+ return ConvertNumberToV8Value(isolate, number);
469
+ }
470
+
471
+ template <typename T>
472
+ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
473
+ const std::vector<T>& vec,
474
+ v8::Isolate* isolate) {
475
+ static_assert(
476
+ std::is_same_v<T, bool> || std::is_integral_v<T> ||
477
+ std::is_floating_point_v<T>,
478
+ "Only primitive types (bool, integral, floating-point) are supported.");
479
+
480
+ if (isolate == nullptr) isolate = context->GetIsolate();
481
+ v8::EscapableHandleScope handle_scope(isolate);
482
+
483
+ v8::LocalVector<v8::Value> elements(isolate);
484
+ elements.reserve(vec.size());
485
+
486
+ for (const auto& value : vec) {
487
+ if constexpr (std::is_same_v<T, bool>) {
488
+ elements.emplace_back(v8::Boolean::New(isolate, value));
489
+ } else {
490
+ v8::Local<v8::Value> v = ConvertNumberToV8Value(isolate, value);
491
+ elements.emplace_back(v);
492
+ }
493
+ }
494
+
495
+ v8::Local<v8::Array> arr =
496
+ v8::Array::New(isolate, elements.data(), elements.size());
497
+ return handle_scope.Escape(arr);
498
+ }
499
+
500
+ SlicedArguments::SlicedArguments(
501
+ const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
502
+ const size_t length = static_cast<size_t>(args.Length());
503
+ if (start >= length) return;
504
+ const size_t size = length - start;
505
+
506
+ AllocateSufficientStorage(size);
507
+ for (size_t i = 0; i < size; ++i)
508
+ (*this)[i] = args[i + start];
509
+ }
510
+
511
+ template <typename T, size_t kStackStorageSize>
512
+ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
513
+ size_t storage) {
514
+ CHECK(!IsInvalidated());
515
+ if (storage > capacity()) {
516
+ bool was_allocated = IsAllocated();
517
+ T* allocated_ptr = was_allocated ? buf_ : nullptr;
518
+ buf_ = Realloc(allocated_ptr, storage);
519
+ capacity_ = storage;
520
+ if (!was_allocated && length_ > 0)
521
+ memcpy(buf_, buf_st_, length_ * sizeof(buf_[0]));
522
+ }
523
+
524
+ length_ = storage;
525
+ }
526
+
527
+ template <typename T, size_t S>
528
+ ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
529
+ v8::Local<v8::Value> value) {
530
+ DCHECK(value->IsArrayBufferView() || value->IsSharedArrayBuffer() ||
531
+ value->IsArrayBuffer());
532
+ ReadValue(value);
533
+ }
534
+
535
+ template <typename T, size_t S>
536
+ ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
537
+ v8::Local<v8::Object> value) {
538
+ CHECK(value->IsArrayBufferView());
539
+ Read(value.As<v8::ArrayBufferView>());
540
+ }
541
+
542
+ template <typename T, size_t S>
543
+ ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
544
+ v8::Local<v8::ArrayBufferView> abv) {
545
+ Read(abv);
546
+ }
547
+
548
+ template <typename T, size_t S>
549
+ void ArrayBufferViewContents<T, S>::Read(v8::Local<v8::ArrayBufferView> abv) {
550
+ static_assert(sizeof(T) == 1, "Only supports one-byte data at the moment");
551
+ length_ = abv->ByteLength();
552
+ if (length_ > sizeof(stack_storage_) || abv->HasBuffer()) {
553
+ data_ = static_cast<T*>(abv->Buffer()->Data()) + abv->ByteOffset();
554
+ } else {
555
+ abv->CopyContents(stack_storage_, sizeof(stack_storage_));
556
+ data_ = stack_storage_;
557
+ }
558
+ }
559
+
560
+ template <typename T, size_t S>
561
+ void ArrayBufferViewContents<T, S>::ReadValue(v8::Local<v8::Value> buf) {
562
+ static_assert(sizeof(T) == 1, "Only supports one-byte data at the moment");
563
+ DCHECK(buf->IsArrayBufferView() || buf->IsSharedArrayBuffer() ||
564
+ buf->IsArrayBuffer());
565
+
566
+ if (buf->IsArrayBufferView()) {
567
+ Read(buf.As<v8::ArrayBufferView>());
568
+ } else if (buf->IsArrayBuffer()) {
569
+ auto ab = buf.As<v8::ArrayBuffer>();
570
+ length_ = ab->ByteLength();
571
+ data_ = static_cast<T*>(ab->Data());
572
+ was_detached_ = ab->WasDetached();
573
+ } else {
574
+ CHECK(buf->IsSharedArrayBuffer());
575
+ auto sab = buf.As<v8::SharedArrayBuffer>();
576
+ length_ = sab->ByteLength();
577
+ data_ = static_cast<T*>(sab->Data());
578
+ }
579
+ }
580
+
581
+ // ECMA-262, 15th edition, 21.1.2.5. Number.isSafeInteger
582
+ inline bool IsSafeJsInt(v8::Local<v8::Value> v) {
583
+ if (!v->IsNumber()) return false;
584
+ double v_d = v.As<v8::Number>()->Value();
585
+ if (std::isnan(v_d)) return false;
586
+ if (std::isinf(v_d)) return false;
587
+ if (std::trunc(v_d) != v_d) return false; // not int
588
+ if (std::abs(v_d) <= static_cast<double>(kMaxSafeJsInteger)) return true;
589
+ return false;
590
+ }
591
+
592
+ constexpr size_t FastStringKey::HashImpl(std::string_view str) {
593
+ // Low-quality hash (djb2), but just fine for current use cases.
594
+ size_t h = 5381;
595
+ for (const char c : str) {
596
+ h = h * 33 + c;
597
+ }
598
+ return h;
599
+ }
600
+
601
+ constexpr size_t FastStringKey::Hash::operator()(
602
+ const FastStringKey& key) const {
603
+ return key.cached_hash_;
604
+ }
605
+
606
+ constexpr bool FastStringKey::operator==(const FastStringKey& other) const {
607
+ return name_ == other.name_;
608
+ }
609
+
610
+ consteval FastStringKey::FastStringKey(std::string_view name)
611
+ : FastStringKey(name, 0) {}
612
+
613
+ constexpr FastStringKey FastStringKey::AllowDynamic(std::string_view name) {
614
+ return FastStringKey(name, 0);
615
+ }
616
+
617
+ constexpr FastStringKey::FastStringKey(std::string_view name, int dummy)
618
+ : name_(name), cached_hash_(HashImpl(name)) {}
619
+
620
+ constexpr std::string_view FastStringKey::as_string_view() const {
621
+ return name_;
622
+ }
623
+
624
+ // Converts a V8 numeric value to a corresponding C++ primitive or enum type.
625
+ template <typename T,
626
+ bool loose = false,
627
+ typename = std::enable_if_t<std::numeric_limits<T>::is_specialized ||
628
+ std::is_enum_v<T>>>
629
+ T FromV8Value(v8::Local<v8::Value> value) {
630
+ if constexpr (std::is_enum_v<T>) {
631
+ using Underlying = std::underlying_type_t<T>;
632
+ return static_cast<T>(FromV8Value<Underlying, loose>(value));
633
+ } else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>) {
634
+ static_assert(
635
+ std::numeric_limits<T>::max() <= std::numeric_limits<uint32_t>::max() &&
636
+ std::numeric_limits<T>::min() >=
637
+ std::numeric_limits<uint32_t>::min(),
638
+ "Type is out of unsigned integer range");
639
+ if constexpr (!loose) {
640
+ CHECK(value->IsUint32());
641
+ } else {
642
+ CHECK(value->IsNumber());
643
+ }
644
+ return static_cast<T>(value.As<v8::Uint32>()->Value());
645
+ } else if constexpr (std::is_integral_v<T> && std::is_signed_v<T>) {
646
+ static_assert(
647
+ std::numeric_limits<T>::max() <= std::numeric_limits<int32_t>::max() &&
648
+ std::numeric_limits<T>::min() >=
649
+ std::numeric_limits<int32_t>::min(),
650
+ "Type is out of signed integer range");
651
+ if constexpr (!loose) {
652
+ CHECK(value->IsInt32());
653
+ } else {
654
+ CHECK(value->IsNumber());
655
+ }
656
+ return static_cast<T>(value.As<v8::Int32>()->Value());
657
+ } else {
658
+ static_assert(std::is_floating_point_v<T>,
659
+ "Type must be arithmetic or enum.");
660
+ CHECK(value->IsNumber());
661
+ return static_cast<T>(value.As<v8::Number>()->Value());
662
+ }
663
+ }
664
+
665
+ #ifdef _WIN32
666
+ inline bool IsWindowsBatchFile(const char* filename) {
667
+ std::string file_with_extension = filename;
668
+ // Regex to match the last extension part after the last dot, ignoring
669
+ // trailing spaces and dots
670
+ std::regex extension_regex(R"(\.([a-zA-Z0-9]+)\s*[\.\s]*$)");
671
+ std::smatch match;
672
+ std::string extension;
673
+
674
+ if (std::regex_search(file_with_extension, match, extension_regex)) {
675
+ extension = ToLower(match[1].str());
676
+ }
677
+
678
+ return !extension.empty() && (extension == "cmd" || extension == "bat");
679
+ }
680
+
681
+ inline std::wstring ConvertToWideString(const std::string& str,
682
+ UINT code_page) {
683
+ int size_needed = MultiByteToWideChar(
684
+ code_page, 0, &str[0], static_cast<int>(str.size()), nullptr, 0);
685
+ std::wstring wstrTo(size_needed, 0);
686
+ MultiByteToWideChar(code_page,
687
+ 0,
688
+ &str[0],
689
+ static_cast<int>(str.size()),
690
+ &wstrTo[0],
691
+ size_needed);
692
+ return wstrTo;
693
+ }
694
+ #endif // _WIN32
695
+
696
+ } // namespace node
697
+
698
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
699
+
700
+ #endif // SRC_UTIL_INL_H_