@encharm/cws 4.5.3 → 4.6.0

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 (288) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/CLAUDE.md +81 -0
  3. package/README.md +10 -3
  4. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  5. package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  7. package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
  8. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  9. package/dist/bindings/cws_linux_arm64_node127.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node137.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node147.node +0 -0
  12. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  13. package/dist/bindings/cws_linux_x64_node127.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node147.node +0 -0
  16. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  17. package/dist/bindings/cws_win32_x64_node127.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node137.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node147.node +0 -0
  20. package/package.json +1 -1
  21. package/src/Addon.cpp +2 -1
  22. package/src/Addon.h +70 -14
  23. package/src/Hub.h +1 -0
  24. package/src/Networking.h +11 -0
  25. package/src/Socket.h +201 -6
  26. package/src/WebSocket.cpp +4 -1
  27. package/src/cSNode.cpp +2 -0
  28. package/src/cSNode.h +4 -0
  29. package/src/headers/26/acorn_version.h +6 -0
  30. package/src/headers/26/aliased_buffer-inl.h +264 -0
  31. package/src/headers/26/aliased_buffer.h +205 -0
  32. package/src/headers/26/aliased_struct-inl.h +143 -0
  33. package/src/headers/26/aliased_struct.h +248 -0
  34. package/src/headers/26/amaro_version.h +6 -0
  35. package/src/headers/26/async_context_frame.h +33 -0
  36. package/src/headers/26/async_wrap-inl.h +123 -0
  37. package/src/headers/26/async_wrap.h +254 -0
  38. package/src/headers/26/base_object-inl.h +333 -0
  39. package/src/headers/26/base_object.h +339 -0
  40. package/src/headers/26/base_object_types.h +76 -0
  41. package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
  42. package/src/headers/26/blob_serializer_deserializer.h +142 -0
  43. package/src/headers/26/builtin_info.h +57 -0
  44. package/src/headers/26/callback_queue-inl.h +97 -0
  45. package/src/headers/26/callback_queue.h +79 -0
  46. package/src/headers/26/cares_wrap.h +475 -0
  47. package/src/headers/26/cleanup_queue-inl.h +36 -0
  48. package/src/headers/26/cleanup_queue.h +79 -0
  49. package/src/headers/26/compile_cache.h +134 -0
  50. package/src/headers/26/connect_wrap.h +26 -0
  51. package/src/headers/26/connection_wrap.h +30 -0
  52. package/src/headers/26/cppgc_helpers-inl.h +69 -0
  53. package/src/headers/26/cppgc_helpers.h +162 -0
  54. package/src/headers/26/crypto/crypto_aes.h +107 -0
  55. package/src/headers/26/crypto/crypto_argon2.h +88 -0
  56. package/src/headers/26/crypto/crypto_bio.h +193 -0
  57. package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
  58. package/src/headers/26/crypto/crypto_cipher.h +291 -0
  59. package/src/headers/26/crypto/crypto_common.h +48 -0
  60. package/src/headers/26/crypto/crypto_context.h +219 -0
  61. package/src/headers/26/crypto/crypto_dh.h +104 -0
  62. package/src/headers/26/crypto/crypto_dsa.h +50 -0
  63. package/src/headers/26/crypto/crypto_ec.h +102 -0
  64. package/src/headers/26/crypto/crypto_hash.h +157 -0
  65. package/src/headers/26/crypto/crypto_hkdf.h +62 -0
  66. package/src/headers/26/crypto/crypto_hmac.h +92 -0
  67. package/src/headers/26/crypto/crypto_kem.h +131 -0
  68. package/src/headers/26/crypto/crypto_keygen.h +382 -0
  69. package/src/headers/26/crypto/crypto_keys.h +366 -0
  70. package/src/headers/26/crypto/crypto_kmac.h +79 -0
  71. package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
  72. package/src/headers/26/crypto/crypto_pqc.h +39 -0
  73. package/src/headers/26/crypto/crypto_random.h +127 -0
  74. package/src/headers/26/crypto/crypto_rsa.h +108 -0
  75. package/src/headers/26/crypto/crypto_scrypt.h +85 -0
  76. package/src/headers/26/crypto/crypto_sig.h +159 -0
  77. package/src/headers/26/crypto/crypto_spkac.h +21 -0
  78. package/src/headers/26/crypto/crypto_timing.h +20 -0
  79. package/src/headers/26/crypto/crypto_tls.h +342 -0
  80. package/src/headers/26/crypto/crypto_turboshake.h +105 -0
  81. package/src/headers/26/crypto/crypto_util.h +775 -0
  82. package/src/headers/26/crypto/crypto_x509.h +140 -0
  83. package/src/headers/26/dataqueue/queue.h +311 -0
  84. package/src/headers/26/debug_utils-inl.h +291 -0
  85. package/src/headers/26/debug_utils.h +200 -0
  86. package/src/headers/26/diagnosticfilename-inl.h +33 -0
  87. package/src/headers/26/embedded_data.h +17 -0
  88. package/src/headers/26/encoding_binding.h +59 -0
  89. package/src/headers/26/env-inl.h +956 -0
  90. package/src/headers/26/env.h +1294 -0
  91. package/src/headers/26/env_properties.h +562 -0
  92. package/src/headers/26/ffi/data.h +30 -0
  93. package/src/headers/26/ffi/fast.h +96 -0
  94. package/src/headers/26/ffi/jit_memory.h +26 -0
  95. package/src/headers/26/ffi/types.h +99 -0
  96. package/src/headers/26/handle_wrap.h +123 -0
  97. package/src/headers/26/histogram-inl.h +211 -0
  98. package/src/headers/26/histogram.h +474 -0
  99. package/src/headers/26/inspector/dom_storage_agent.h +68 -0
  100. package/src/headers/26/inspector/inspector_object_utils.h +38 -0
  101. package/src/headers/26/inspector/io_agent.h +30 -0
  102. package/src/headers/26/inspector/main_thread_interface.h +116 -0
  103. package/src/headers/26/inspector/network_agent.h +110 -0
  104. package/src/headers/26/inspector/network_inspector.h +45 -0
  105. package/src/headers/26/inspector/network_requests_buffer.h +195 -0
  106. package/src/headers/26/inspector/network_resource_manager.h +29 -0
  107. package/src/headers/26/inspector/node_json.h +24 -0
  108. package/src/headers/26/inspector/node_string.h +101 -0
  109. package/src/headers/26/inspector/notification_emitter.h +38 -0
  110. package/src/headers/26/inspector/protocol_helper.h +27 -0
  111. package/src/headers/26/inspector/runtime_agent.h +41 -0
  112. package/src/headers/26/inspector/storage_agent.h +33 -0
  113. package/src/headers/26/inspector/target_agent.h +59 -0
  114. package/src/headers/26/inspector/target_manager.h +70 -0
  115. package/src/headers/26/inspector/tracing_agent.h +43 -0
  116. package/src/headers/26/inspector/worker_agent.h +40 -0
  117. package/src/headers/26/inspector/worker_inspector.h +124 -0
  118. package/src/headers/26/inspector_agent.h +168 -0
  119. package/src/headers/26/inspector_io.h +78 -0
  120. package/src/headers/26/inspector_profiler.h +149 -0
  121. package/src/headers/26/inspector_socket.h +60 -0
  122. package/src/headers/26/inspector_socket_server.h +110 -0
  123. package/src/headers/26/js_native_api.h +634 -0
  124. package/src/headers/26/js_native_api_types.h +244 -0
  125. package/src/headers/26/js_native_api_v8.h +485 -0
  126. package/src/headers/26/js_native_api_v8_internals.h +45 -0
  127. package/src/headers/26/js_stream.h +57 -0
  128. package/src/headers/26/json_utils.h +172 -0
  129. package/src/headers/26/large_pages/node_large_page.h +34 -0
  130. package/src/headers/26/lru_cache-inl.h +69 -0
  131. package/src/headers/26/memory_tracker-inl.h +461 -0
  132. package/src/headers/26/memory_tracker.h +341 -0
  133. package/src/headers/26/module_wrap.h +231 -0
  134. package/src/headers/26/ncrypto.h +2008 -0
  135. package/src/headers/26/node.h +1693 -0
  136. package/src/headers/26/node_api.h +265 -0
  137. package/src/headers/26/node_api_internals.h +48 -0
  138. package/src/headers/26/node_api_types.h +58 -0
  139. package/src/headers/26/node_binding.h +170 -0
  140. package/src/headers/26/node_blob.h +160 -0
  141. package/src/headers/26/node_bob-inl.h +36 -0
  142. package/src/headers/26/node_bob.h +107 -0
  143. package/src/headers/26/node_buffer.h +92 -0
  144. package/src/headers/26/node_builtins.h +239 -0
  145. package/src/headers/26/node_concepts.h +46 -0
  146. package/src/headers/26/node_config_file.h +77 -0
  147. package/src/headers/26/node_constants.h +82 -0
  148. package/src/headers/26/node_context_data.h +171 -0
  149. package/src/headers/26/node_contextify.h +261 -0
  150. package/src/headers/26/node_crypto.h +66 -0
  151. package/src/headers/26/node_debug.h +30 -0
  152. package/src/headers/26/node_diagnostics_channel.h +121 -0
  153. package/src/headers/26/node_dir.h +52 -0
  154. package/src/headers/26/node_dotenv.h +45 -0
  155. package/src/headers/26/node_errors.h +378 -0
  156. package/src/headers/26/node_exit_code.h +54 -0
  157. package/src/headers/26/node_external_reference.h +171 -0
  158. package/src/headers/26/node_ffi.h +212 -0
  159. package/src/headers/26/node_file-inl.h +421 -0
  160. package/src/headers/26/node_file.h +561 -0
  161. package/src/headers/26/node_file_utils.h +39 -0
  162. package/src/headers/26/node_hash.h +212 -0
  163. package/src/headers/26/node_http2.h +1202 -0
  164. package/src/headers/26/node_http2_state.h +159 -0
  165. package/src/headers/26/node_http_common-inl.h +199 -0
  166. package/src/headers/26/node_http_common.h +535 -0
  167. package/src/headers/26/node_i18n.h +132 -0
  168. package/src/headers/26/node_internals.h +485 -0
  169. package/src/headers/26/node_locks.h +184 -0
  170. package/src/headers/26/node_main_instance.h +67 -0
  171. package/src/headers/26/node_mem-inl.h +113 -0
  172. package/src/headers/26/node_mem.h +45 -0
  173. package/src/headers/26/node_messaging.h +389 -0
  174. package/src/headers/26/node_metadata.h +172 -0
  175. package/src/headers/26/node_modules.h +102 -0
  176. package/src/headers/26/node_mutex.h +323 -0
  177. package/src/headers/26/node_object_wrap.h +145 -0
  178. package/src/headers/26/node_options-inl.h +524 -0
  179. package/src/headers/26/node_options.h +710 -0
  180. package/src/headers/26/node_perf.h +167 -0
  181. package/src/headers/26/node_perf_common.h +103 -0
  182. package/src/headers/26/node_platform.h +290 -0
  183. package/src/headers/26/node_process-inl.h +26 -0
  184. package/src/headers/26/node_process.h +112 -0
  185. package/src/headers/26/node_profiling.h +38 -0
  186. package/src/headers/26/node_realm-inl.h +156 -0
  187. package/src/headers/26/node_realm.h +236 -0
  188. package/src/headers/26/node_report.h +43 -0
  189. package/src/headers/26/node_revert.h +82 -0
  190. package/src/headers/26/node_root_certs.h +2937 -0
  191. package/src/headers/26/node_sea.h +101 -0
  192. package/src/headers/26/node_shadow_realm.h +46 -0
  193. package/src/headers/26/node_snapshot_builder.h +57 -0
  194. package/src/headers/26/node_snapshotable.h +167 -0
  195. package/src/headers/26/node_sockaddr-inl.h +248 -0
  196. package/src/headers/26/node_sockaddr.h +459 -0
  197. package/src/headers/26/node_sqlite.h +607 -0
  198. package/src/headers/26/node_stat_watcher.h +73 -0
  199. package/src/headers/26/node_task_runner.h +92 -0
  200. package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
  201. package/src/headers/26/node_threadsafe_cow.h +105 -0
  202. package/src/headers/26/node_union_bytes.h +81 -0
  203. package/src/headers/26/node_url.h +101 -0
  204. package/src/headers/26/node_url_pattern.h +118 -0
  205. package/src/headers/26/node_v8.h +78 -0
  206. package/src/headers/26/node_v8_embedder.h +26 -0
  207. package/src/headers/26/node_v8_platform-inl.h +96 -0
  208. package/src/headers/26/node_version.h +116 -0
  209. package/src/headers/26/node_wasi.h +184 -0
  210. package/src/headers/26/node_wasm_web_api.h +55 -0
  211. package/src/headers/26/node_watchdog.h +164 -0
  212. package/src/headers/26/node_webstorage.h +62 -0
  213. package/src/headers/26/node_worker.h +162 -0
  214. package/src/headers/26/path.h +36 -0
  215. package/src/headers/26/permission/boolean_permission.h +50 -0
  216. package/src/headers/26/permission/fs_permission.h +192 -0
  217. package/src/headers/26/permission/permission.h +155 -0
  218. package/src/headers/26/permission/permission_base.h +79 -0
  219. package/src/headers/26/pipe_wrap.h +80 -0
  220. package/src/headers/26/quic/application.h +279 -0
  221. package/src/headers/26/quic/arena.h +373 -0
  222. package/src/headers/26/quic/bindingdata.h +440 -0
  223. package/src/headers/26/quic/cid.h +127 -0
  224. package/src/headers/26/quic/data.h +358 -0
  225. package/src/headers/26/quic/defs.h +417 -0
  226. package/src/headers/26/quic/endpoint.h +519 -0
  227. package/src/headers/26/quic/guard.h +5 -0
  228. package/src/headers/26/quic/http3.h +25 -0
  229. package/src/headers/26/quic/packet.h +166 -0
  230. package/src/headers/26/quic/preferredaddress.h +72 -0
  231. package/src/headers/26/quic/session.h +770 -0
  232. package/src/headers/26/quic/session_manager.h +107 -0
  233. package/src/headers/26/quic/sessionticket.h +110 -0
  234. package/src/headers/26/quic/streams.h +518 -0
  235. package/src/headers/26/quic/tlscontext.h +353 -0
  236. package/src/headers/26/quic/tokens.h +263 -0
  237. package/src/headers/26/quic/transportparams.h +184 -0
  238. package/src/headers/26/req_wrap-inl.h +175 -0
  239. package/src/headers/26/req_wrap.h +79 -0
  240. package/src/headers/26/spawn_sync.h +243 -0
  241. package/src/headers/26/stream_base-inl.h +170 -0
  242. package/src/headers/26/stream_base.h +487 -0
  243. package/src/headers/26/stream_pipe.h +76 -0
  244. package/src/headers/26/stream_wrap.h +137 -0
  245. package/src/headers/26/string_bytes.h +114 -0
  246. package/src/headers/26/string_decoder-inl.h +31 -0
  247. package/src/headers/26/string_decoder.h +49 -0
  248. package/src/headers/26/tcp_wrap.h +138 -0
  249. package/src/headers/26/threadpoolwork-inl.h +70 -0
  250. package/src/headers/26/timer_wrap-inl.h +32 -0
  251. package/src/headers/26/timer_wrap.h +87 -0
  252. package/src/headers/26/timers.h +70 -0
  253. package/src/headers/26/tracing/agent.h +125 -0
  254. package/src/headers/26/tracing/agent_legacy.h +146 -0
  255. package/src/headers/26/tracing/agent_perfetto.h +145 -0
  256. package/src/headers/26/tracing/node_trace_buffer.h +91 -0
  257. package/src/headers/26/tracing/node_trace_writer.h +79 -0
  258. package/src/headers/26/tracing/trace_event.h +27 -0
  259. package/src/headers/26/tracing/trace_event_helper.h +40 -0
  260. package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
  261. package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
  262. package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
  263. package/src/headers/26/tracing/traced_value.h +167 -0
  264. package/src/headers/26/tty_wrap.h +65 -0
  265. package/src/headers/26/udp_wrap.h +231 -0
  266. package/src/headers/26/undici_version.h +6 -0
  267. package/src/headers/26/util-inl.h +788 -0
  268. package/src/headers/26/util.h +1207 -0
  269. package/src/headers/26/v8-cpp-heap-external.h +56 -0
  270. package/src/headers/26/v8-external-memory-accounter.h +60 -0
  271. package/src/headers/26/v8-fast-api-calls.h +784 -0
  272. package/src/headers/26/v8-inspector-protocol.h +13 -0
  273. package/src/headers/26/v8-inspector.h +458 -0
  274. package/src/headers/26/v8-metrics.h +273 -0
  275. package/src/headers/26/v8-trace-categories.h +28 -0
  276. package/src/headers/26/v8-unwinder-state.h +30 -0
  277. package/src/headers/26/v8-util.h +549 -0
  278. package/src/headers/26/v8-value-serializer-version.h +24 -0
  279. package/src/headers/26/v8-version-string.h +38 -0
  280. package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
  281. package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
  282. package/src/headers/26/zlib_version.h +6 -0
  283. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +0 -20
  284. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
  285. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +0 -931
  286. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +0 -20
  287. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
  288. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +0 -931
@@ -0,0 +1,291 @@
1
+ #ifndef SRC_DEBUG_UTILS_INL_H_
2
+ #define SRC_DEBUG_UTILS_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "debug_utils.h"
7
+ #include "env.h"
8
+ #include "util-inl.h"
9
+
10
+ #include <type_traits>
11
+
12
+ namespace node {
13
+
14
+ template <typename T>
15
+ concept StringViewConvertible = requires(T a) {
16
+ {
17
+ a.ToStringView()
18
+ } -> std::convertible_to<std::string_view>;
19
+ };
20
+ template <typename T>
21
+ concept StringConvertible = requires(T a) {
22
+ {
23
+ a.ToString()
24
+ } -> std::convertible_to<std::string>;
25
+ };
26
+ // For std::filesystem::path and similar types
27
+ template <typename T>
28
+ concept StringConvertibleFSPathLike = requires(T a) {
29
+ {
30
+ a.string()
31
+ } -> std::convertible_to<std::string>;
32
+ };
33
+
34
+ struct ToStringHelper {
35
+ template <typename T>
36
+ requires(StringConvertible<T>) && (!StringViewConvertible<T>)
37
+ static std::string Convert(const T& value) {
38
+ return value.ToString();
39
+ }
40
+ template <typename T>
41
+ requires(StringConvertibleFSPathLike<T>) && (!StringViewConvertible<T>) &&
42
+ (!StringConvertible<T>)
43
+ static std::string Convert(const T& value) {
44
+ return value.string();
45
+ }
46
+ template <typename T>
47
+ requires StringViewConvertible<T>
48
+ static std::string_view Convert(const T& value) {
49
+ return value.ToStringView();
50
+ }
51
+
52
+ template <NumericOrEnum T>
53
+ static std::string Convert(const T& value) {
54
+ return std::to_string(value);
55
+ }
56
+ static std::string_view Convert(const char* value) {
57
+ return value != nullptr ? value : "(null)";
58
+ }
59
+ static std::string Convert(const std::string& value) { return value; }
60
+ static std::string_view Convert(std::string_view value) { return value; }
61
+ static std::string Convert(bool value) { return value ? "true" : "false"; }
62
+
63
+ static std::string Convert(v8::Local<v8::Value> value) {
64
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
65
+ if (value->IsString()) {
66
+ Utf8Value utf8_value(isolate, value);
67
+ return SPrintF("\"%s\"", utf8_value.ToString());
68
+ }
69
+ v8::MaybeLocal<v8::String> maybe_detail =
70
+ value->ToDetailString(isolate->GetCurrentContext());
71
+ v8::Local<v8::String> detail;
72
+ if (!maybe_detail.ToLocal(&detail)) {
73
+ // This will only occur when terminating. No exception is expected
74
+ // with `ToDetailString`.
75
+ return "<Unable to stringify v8::Value>";
76
+ }
77
+ Utf8Value utf8_value(isolate, detail);
78
+ return utf8_value.ToString();
79
+ }
80
+
81
+ template <unsigned BASE_BITS, std::integral T>
82
+ static std::string BaseConvert(const T& value) {
83
+ auto v = static_cast<uint64_t>(value);
84
+ char ret[3 * sizeof(T)];
85
+ char* ptr = ret + 3 * sizeof(T) - 1;
86
+ *ptr = '\0';
87
+ const char* digits = "0123456789abcdef";
88
+ do {
89
+ unsigned digit = v & ((1 << BASE_BITS) - 1);
90
+ *--ptr = (BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
91
+ } while ((v >>= BASE_BITS) != 0);
92
+ return ptr;
93
+ }
94
+ template <unsigned BASE_BITS, typename T>
95
+ requires(!std::integral<T>)
96
+ static auto BaseConvert(T&& value) {
97
+ return Convert(std::forward<T>(value));
98
+ }
99
+ };
100
+
101
+ template <typename T>
102
+ auto ToStringOrStringView(const T& value) {
103
+ return ToStringHelper::Convert(value);
104
+ }
105
+
106
+ template <typename T>
107
+ std::string ToString(const T& value) {
108
+ return std::string(ToStringOrStringView(value));
109
+ }
110
+
111
+ template <unsigned BASE_BITS, typename T>
112
+ auto ToBaseString(const T& value) {
113
+ return ToStringHelper::BaseConvert<BASE_BITS>(value);
114
+ }
115
+
116
+ inline std::string SPrintFImpl(std::string_view format) {
117
+ auto offset = format.find('%');
118
+ if (offset == std::string_view::npos) return std::string(format);
119
+ CHECK_LT(offset + 1, format.size());
120
+ CHECK_EQ(format[offset + 1],
121
+ '%'); // Only '%%' allowed when there are no arguments.
122
+
123
+ return std::string(format.substr(0, offset + 1)) +
124
+ SPrintFImpl(format.substr(offset + 2));
125
+ }
126
+
127
+ template <typename Arg, typename... Args>
128
+ std::string COLD_NOINLINE SPrintFImpl( // NOLINT(runtime/string)
129
+ std::string_view format,
130
+ Arg&& arg,
131
+ Args&&... args) {
132
+ auto offset = format.find('%');
133
+ CHECK_NE(offset, std::string_view::npos); // If you hit this, you passed in
134
+ // too many arguments.
135
+ std::string ret(format.substr(0, offset));
136
+ // Ignore long / size_t modifiers
137
+ while (++offset < format.size() &&
138
+ (format[offset] == 'l' || format[offset] == 'z')) {
139
+ }
140
+ switch (offset == format.size() ? '\0' : format[offset]) {
141
+ case '%': {
142
+ return ret + '%' +
143
+ SPrintFImpl(format.substr(offset + 1),
144
+ std::forward<Arg>(arg),
145
+ std::forward<Args>(args)...);
146
+ }
147
+ default: {
148
+ return ret + '%' +
149
+ SPrintFImpl(format.substr(offset),
150
+ std::forward<Arg>(arg),
151
+ std::forward<Args>(args)...);
152
+ }
153
+ case 'd':
154
+ case 'i':
155
+ case 'u':
156
+ case 's':
157
+ ret += ToStringOrStringView(arg);
158
+ break;
159
+ case 'o':
160
+ ret += ToBaseString<3>(arg);
161
+ break;
162
+ case 'x':
163
+ ret += ToBaseString<4>(arg);
164
+ break;
165
+ case 'X':
166
+ ret += node::ToUpper(ToBaseString<4>(arg));
167
+ break;
168
+ case 'p': {
169
+ CHECK(std::is_pointer_v<typename std::remove_reference_t<Arg>>);
170
+ char out[20];
171
+ int n = snprintf(
172
+ out, sizeof(out), "%p", *reinterpret_cast<const void* const*>(&arg));
173
+ CHECK_GE(n, 0);
174
+ ret += out;
175
+ break;
176
+ }
177
+ }
178
+ return ret +
179
+ SPrintFImpl(format.substr(offset + 1), std::forward<Args>(args)...);
180
+ }
181
+
182
+ template <typename... Args>
183
+ std::string COLD_NOINLINE SPrintF( // NOLINT(runtime/string)
184
+ std::string_view format,
185
+ Args&&... args) {
186
+ return SPrintFImpl(format, std::forward<Args>(args)...);
187
+ }
188
+
189
+ template <typename... Args>
190
+ void COLD_NOINLINE FPrintF(FILE* file,
191
+ std::string_view format,
192
+ Args&&... args) {
193
+ FWrite(file, SPrintF(format, std::forward<Args>(args)...));
194
+ }
195
+
196
+ template <typename... Args>
197
+ inline void FORCE_INLINE Debug(EnabledDebugList* list,
198
+ DebugCategory cat,
199
+ const char* format,
200
+ Args&&... args) {
201
+ if (!list->enabled(cat)) [[unlikely]]
202
+ return;
203
+ FPrintF(stderr, format, std::forward<Args>(args)...);
204
+ }
205
+
206
+ inline void FORCE_INLINE Debug(EnabledDebugList* list,
207
+ DebugCategory cat,
208
+ const char* message) {
209
+ if (!list->enabled(cat)) [[unlikely]]
210
+ return;
211
+ FPrintF(stderr, "%s", message);
212
+ }
213
+
214
+ template <typename... Args>
215
+ inline void FORCE_INLINE
216
+ Debug(Environment* env, DebugCategory cat, const char* format, Args&&... args) {
217
+ Debug(env->enabled_debug_list(), cat, format, std::forward<Args>(args)...);
218
+ }
219
+
220
+ inline void FORCE_INLINE Debug(Environment* env,
221
+ DebugCategory cat,
222
+ const char* message) {
223
+ Debug(env->enabled_debug_list(), cat, message);
224
+ }
225
+
226
+ template <typename... Args>
227
+ inline void Debug(Environment* env,
228
+ DebugCategory cat,
229
+ const std::string& format,
230
+ Args&&... args) {
231
+ Debug(env->enabled_debug_list(),
232
+ cat,
233
+ format.c_str(),
234
+ std::forward<Args>(args)...);
235
+ }
236
+
237
+ // Used internally by the 'real' Debug(AsyncWrap*, ...) functions below, so that
238
+ // the FORCE_INLINE flag on them doesn't apply to the contents of this function
239
+ // as well.
240
+ // We apply COLD_NOINLINE to tell the compiler that it's not worth optimizing
241
+ // this function for speed and it should rather focus on keeping it out of
242
+ // hot code paths. In particular, we want to keep the string concatenating code
243
+ // out of the function containing the original `Debug()` call.
244
+ template <typename... Args>
245
+ void COLD_NOINLINE UnconditionalAsyncWrapDebug(AsyncWrap* async_wrap,
246
+ const char* format,
247
+ Args&&... args) {
248
+ Debug(async_wrap->env(),
249
+ static_cast<DebugCategory>(async_wrap->provider_type()),
250
+ async_wrap->diagnostic_name() + " " + format + "\n",
251
+ std::forward<Args>(args)...);
252
+ }
253
+
254
+ template <typename... Args>
255
+ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
256
+ const char* format,
257
+ Args&&... args) {
258
+ DCHECK_NOT_NULL(async_wrap);
259
+ if (auto cat = static_cast<DebugCategory>(async_wrap->provider_type());
260
+ !async_wrap->env()->enabled_debug_list()->enabled(cat)) [[unlikely]] {
261
+ return;
262
+ }
263
+ UnconditionalAsyncWrapDebug(async_wrap, format, std::forward<Args>(args)...);
264
+ }
265
+
266
+ template <typename... Args>
267
+ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
268
+ const std::string& format,
269
+ Args&&... args) {
270
+ Debug(async_wrap, format.c_str(), std::forward<Args>(args)...);
271
+ }
272
+
273
+ namespace per_process {
274
+
275
+ template <typename... Args>
276
+ inline void FORCE_INLINE Debug(DebugCategory cat,
277
+ const char* format,
278
+ Args&&... args) {
279
+ Debug(&enabled_debug_list, cat, format, std::forward<Args>(args)...);
280
+ }
281
+
282
+ inline void FORCE_INLINE Debug(DebugCategory cat, const char* message) {
283
+ Debug(&enabled_debug_list, cat, message);
284
+ }
285
+
286
+ } // namespace per_process
287
+ } // namespace node
288
+
289
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
290
+
291
+ #endif // SRC_DEBUG_UTILS_INL_H_
@@ -0,0 +1,200 @@
1
+ #ifndef SRC_DEBUG_UTILS_H_
2
+ #define SRC_DEBUG_UTILS_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "async_wrap.h"
7
+ #include "util.h"
8
+
9
+ #include <algorithm>
10
+ #include <sstream>
11
+ #include <string>
12
+
13
+ // Use FORCE_INLINE on functions that have a debug-category-enabled check first
14
+ // and then ideally only a single function call following it, to maintain
15
+ // performance for the common case (no debugging used).
16
+ #ifdef __GNUC__
17
+ #define FORCE_INLINE __attribute__((always_inline))
18
+ #define COLD_NOINLINE __attribute__((cold, noinline))
19
+ #else
20
+ #define FORCE_INLINE
21
+ #define COLD_NOINLINE
22
+ #endif
23
+
24
+ namespace node {
25
+ class Environment;
26
+
27
+ template <typename T>
28
+ inline std::string ToString(const T& value);
29
+ template <typename T>
30
+ inline auto ToStringOrStringView(const T& value);
31
+
32
+ // C++-style variant of sprintf()/fprintf() that:
33
+ // - Returns an std::string
34
+ // - Handles \0 bytes correctly
35
+ // - Supports %p and %s. %d, %i and %u are aliases for %s.
36
+ // - Accepts any class that has a ToString() method for stringification.
37
+ template <typename... Args>
38
+ inline std::string SPrintF(std::string_view format, Args&&... args);
39
+ template <typename... Args>
40
+ inline void FPrintF(FILE* file, std::string_view format, Args&&... args);
41
+ void NODE_EXTERN_PRIVATE FWrite(FILE* file, const std::string& str);
42
+
43
+ // Listing the AsyncWrap provider types first enables us to cast directly
44
+ // from a provider type to a debug category.
45
+ #define DEBUG_CATEGORY_NAMES(V) \
46
+ NODE_ASYNC_PROVIDER_TYPES(V) \
47
+ V(BOOTSTRAP) \
48
+ V(CRYPTO) \
49
+ V(COMPILE_CACHE) \
50
+ V(CONTEXTIFY) \
51
+ V(DIAGNOSTICS) \
52
+ V(HUGEPAGES) \
53
+ V(INSPECTOR_SERVER) \
54
+ V(INSPECTOR_CLIENT) \
55
+ V(INSPECTOR_PROFILER) \
56
+ V(CODE_CACHE) \
57
+ V(NGTCP2) \
58
+ V(NGHTTP3) \
59
+ V(SEA) \
60
+ V(WASI) \
61
+ V(MODULE) \
62
+ V(MKSNAPSHOT) \
63
+ V(SNAPSHOT_SERDES) \
64
+ V(PERFETTO) \
65
+ V(PERMISSION_MODEL) \
66
+ V(PLATFORM_MINIMAL) \
67
+ V(PLATFORM_VERBOSE) \
68
+ V(QUIC)
69
+
70
+ enum class DebugCategory : unsigned int {
71
+ #define V(name) name,
72
+ DEBUG_CATEGORY_NAMES(V)
73
+ #undef V
74
+ };
75
+
76
+ #define V(name) +1
77
+ constexpr unsigned int kDebugCategoryCount = DEBUG_CATEGORY_NAMES(V);
78
+ #undef V
79
+
80
+ class NODE_EXTERN_PRIVATE EnabledDebugList {
81
+ public:
82
+ bool FORCE_INLINE enabled(DebugCategory category) const {
83
+ DCHECK_LT(static_cast<unsigned int>(category), kDebugCategoryCount);
84
+ return enabled_[static_cast<unsigned int>(category)];
85
+ }
86
+
87
+ // Uses NODE_DEBUG_NATIVE to initialize the categories. env->env_vars()
88
+ // is parsed if it is not a nullptr, otherwise the system environment
89
+ // variables are parsed.
90
+ void Parse(Environment* env);
91
+
92
+ private:
93
+ // Enable all categories matching cats.
94
+ void Parse(const std::string& cats);
95
+ void set_enabled(DebugCategory category) {
96
+ DCHECK_LT(static_cast<unsigned int>(category), kDebugCategoryCount);
97
+ enabled_[static_cast<int>(category)] = true;
98
+ }
99
+
100
+ bool enabled_[kDebugCategoryCount] = {false};
101
+ };
102
+
103
+ template <typename... Args>
104
+ inline void FORCE_INLINE Debug(EnabledDebugList* list,
105
+ DebugCategory cat,
106
+ const char* format,
107
+ Args&&... args);
108
+
109
+ inline void FORCE_INLINE Debug(EnabledDebugList* list,
110
+ DebugCategory cat,
111
+ const char* message);
112
+
113
+ template <typename... Args>
114
+ inline void FORCE_INLINE
115
+ Debug(Environment* env, DebugCategory cat, const char* format, Args&&... args);
116
+
117
+ inline void FORCE_INLINE Debug(Environment* env,
118
+ DebugCategory cat,
119
+ const char* message);
120
+
121
+ template <typename... Args>
122
+ inline void Debug(Environment* env,
123
+ DebugCategory cat,
124
+ const std::string& format,
125
+ Args&&... args);
126
+
127
+ // Used internally by the 'real' Debug(AsyncWrap*, ...) functions below, so that
128
+ // the FORCE_INLINE flag on them doesn't apply to the contents of this function
129
+ // as well.
130
+ // We apply COLD_NOINLINE to tell the compiler that it's not worth optimizing
131
+ // this function for speed and it should rather focus on keeping it out of
132
+ // hot code paths. In particular, we want to keep the string concatenating code
133
+ // out of the function containing the original `Debug()` call.
134
+ template <typename... Args>
135
+ void COLD_NOINLINE UnconditionalAsyncWrapDebug(AsyncWrap* async_wrap,
136
+ const char* format,
137
+ Args&&... args);
138
+
139
+ template <typename... Args>
140
+ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
141
+ const char* format,
142
+ Args&&... args);
143
+
144
+ template <typename... Args>
145
+ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
146
+ const std::string& format,
147
+ Args&&... args);
148
+
149
+ // Debug helper for inspecting the currently running `node` executable.
150
+ class NativeSymbolDebuggingContext {
151
+ public:
152
+ static std::unique_ptr<NativeSymbolDebuggingContext> New();
153
+
154
+ class SymbolInfo {
155
+ public:
156
+ std::string name;
157
+ std::string filename;
158
+ size_t line = 0;
159
+ size_t dis = 0;
160
+
161
+ std::string Display() const;
162
+ };
163
+
164
+ NativeSymbolDebuggingContext() = default;
165
+ virtual ~NativeSymbolDebuggingContext() = default;
166
+
167
+ virtual SymbolInfo LookupSymbol(void* address) { return {}; }
168
+ virtual bool IsMapped(void* address) { return false; }
169
+ virtual int GetStackTrace(void** frames, int count) { return 0; }
170
+
171
+ NativeSymbolDebuggingContext(const NativeSymbolDebuggingContext&) = delete;
172
+ NativeSymbolDebuggingContext(NativeSymbolDebuggingContext&&) = delete;
173
+ NativeSymbolDebuggingContext operator=(NativeSymbolDebuggingContext&)
174
+ = delete;
175
+ NativeSymbolDebuggingContext operator=(NativeSymbolDebuggingContext&&)
176
+ = delete;
177
+ static std::vector<std::string> GetLoadedLibraries();
178
+ };
179
+
180
+ // Variant of `uv_loop_close` that tries to be as helpful as possible
181
+ // about giving information on currently existing handles, if there are any,
182
+ // but still aborts the process.
183
+ void CheckedUvLoopClose(uv_loop_t* loop);
184
+ void PrintLibuvHandleInformation(uv_loop_t* loop, FILE* stream);
185
+
186
+ namespace per_process {
187
+ extern NODE_EXTERN_PRIVATE EnabledDebugList enabled_debug_list;
188
+
189
+ template <typename... Args>
190
+ inline void FORCE_INLINE Debug(DebugCategory cat,
191
+ const char* format,
192
+ Args&&... args);
193
+
194
+ inline void FORCE_INLINE Debug(DebugCategory cat, const char* message);
195
+ } // namespace per_process
196
+ } // namespace node
197
+
198
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
199
+
200
+ #endif // SRC_DEBUG_UTILS_H_
@@ -0,0 +1,33 @@
1
+ #ifndef SRC_DIAGNOSTICFILENAME_INL_H_
2
+ #define SRC_DIAGNOSTICFILENAME_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node_internals.h"
7
+ namespace node {
8
+
9
+ class Environment;
10
+
11
+ inline DiagnosticFilename::DiagnosticFilename(
12
+ Environment* env,
13
+ const char* prefix,
14
+ const char* ext) :
15
+ filename_(MakeFilename(env->thread_id(), prefix, ext)) {
16
+ }
17
+
18
+ inline DiagnosticFilename::DiagnosticFilename(
19
+ uint64_t thread_id,
20
+ const char* prefix,
21
+ const char* ext) :
22
+ filename_(MakeFilename(thread_id, prefix, ext)) {
23
+ }
24
+
25
+ inline const char* DiagnosticFilename::operator*() const {
26
+ return filename_.c_str();
27
+ }
28
+
29
+ } // namespace node
30
+
31
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
32
+
33
+ #endif // SRC_DIAGNOSTICFILENAME_INL_H_
@@ -0,0 +1,17 @@
1
+ #ifndef SRC_EMBEDDED_DATA_H_
2
+ #define SRC_EMBEDDED_DATA_H_
3
+
4
+ #include <cinttypes>
5
+ #include <string>
6
+
7
+ // This file must not depend on node.h or other code that depends on
8
+ // the full Node.js implementation because it is used during the
9
+ // compilation of the Node.js implementation itself (especially js2c).
10
+
11
+ namespace node {
12
+
13
+ const std::string& GetOctalCode(uint8_t index);
14
+
15
+ } // namespace node
16
+
17
+ #endif // SRC_EMBEDDED_DATA_H_
@@ -0,0 +1,59 @@
1
+ #ifndef SRC_ENCODING_BINDING_H_
2
+ #define SRC_ENCODING_BINDING_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <cinttypes>
7
+ #include "aliased_buffer.h"
8
+ #include "node_snapshotable.h"
9
+ #include "v8-fast-api-calls.h"
10
+
11
+ namespace node {
12
+ class ExternalReferenceRegistry;
13
+
14
+ namespace encoding_binding {
15
+ class BindingData : public SnapshotableObject {
16
+ public:
17
+ struct InternalFieldInfo : public node::InternalFieldInfoBase {
18
+ AliasedBufferIndex encode_into_results_buffer;
19
+ };
20
+
21
+ BindingData(Realm* realm,
22
+ v8::Local<v8::Object> obj,
23
+ InternalFieldInfo* info = nullptr);
24
+ SERIALIZABLE_OBJECT_METHODS()
25
+ SET_BINDING_ID(encoding_binding_data)
26
+
27
+ void MemoryInfo(MemoryTracker* tracker) const override;
28
+ SET_SELF_SIZE(BindingData)
29
+ SET_MEMORY_INFO_NAME(BindingData)
30
+
31
+ static void EncodeInto(const v8::FunctionCallbackInfo<v8::Value>& args);
32
+ static void EncodeUtf8String(const v8::FunctionCallbackInfo<v8::Value>& args);
33
+ static void DecodeUTF8(const v8::FunctionCallbackInfo<v8::Value>& args);
34
+
35
+ static void ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args);
36
+ static void ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args);
37
+
38
+ static void CreatePerIsolateProperties(IsolateData* isolate_data,
39
+ v8::Local<v8::ObjectTemplate> target);
40
+ static void CreatePerContextProperties(v8::Local<v8::Object> target,
41
+ v8::Local<v8::Value> unused,
42
+ v8::Local<v8::Context> context,
43
+ void* priv);
44
+ static void RegisterTimerExternalReferences(
45
+ ExternalReferenceRegistry* registry);
46
+
47
+ private:
48
+ static constexpr size_t kEncodeIntoResultsLength = 2;
49
+ AliasedUint32Array encode_into_results_buffer_;
50
+ InternalFieldInfo* internal_field_info_ = nullptr;
51
+ };
52
+
53
+ } // namespace encoding_binding
54
+
55
+ } // namespace node
56
+
57
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
58
+
59
+ #endif // SRC_ENCODING_BINDING_H_