@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,76 @@
1
+ #ifndef SRC_BASE_OBJECT_TYPES_H_
2
+ #define SRC_BASE_OBJECT_TYPES_H_
3
+
4
+ #include <cinttypes>
5
+
6
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
7
+
8
+ namespace node {
9
+ // List of internalBinding() data wrappers. The first argument should match
10
+ // what the class passes to SET_BINDING_ID(), the second argument should match
11
+ // the C++ class name.
12
+ #define SERIALIZABLE_BINDING_TYPES(V) \
13
+ V(diagnostics_channel_binding_data, diagnostics_channel::BindingData) \
14
+ V(encoding_binding_data, encoding_binding::BindingData) \
15
+ V(fs_binding_data, fs::BindingData) \
16
+ V(mksnapshot_binding_data, mksnapshot::BindingData) \
17
+ V(v8_binding_data, v8_utils::BindingData) \
18
+ V(blob_binding_data, BlobBindingData) \
19
+ V(process_binding_data, process::BindingData) \
20
+ V(timers_binding_data, timers::BindingData) \
21
+ V(url_binding_data, url::BindingData) \
22
+ V(modules_binding_data, modules::BindingData)
23
+
24
+ #define UNSERIALIZABLE_BINDING_TYPES(V) \
25
+ V(http2_binding_data, http2::BindingData) \
26
+ V(http_parser_binding_data, http_parser::BindingData) \
27
+ V(quic_binding_data, quic::BindingData) \
28
+ V(sqlite_binding_data, sqlite::BindingData)
29
+
30
+ // List of (non-binding) BaseObjects that are serializable in the snapshot.
31
+ // The first argument should match what the type passes to
32
+ // SET_OBJECT_ID(), the second argument should match the C++ class
33
+ // name.
34
+ #define SERIALIZABLE_NON_BINDING_TYPES(V)
35
+
36
+ // Helper list of all binding data wrapper types.
37
+ #define BINDING_TYPES(V) \
38
+ SERIALIZABLE_BINDING_TYPES(V) \
39
+ UNSERIALIZABLE_BINDING_TYPES(V)
40
+
41
+ // Helper list of all BaseObjects that implement snapshot support.
42
+ #define SERIALIZABLE_OBJECT_TYPES(V) \
43
+ SERIALIZABLE_BINDING_TYPES(V) \
44
+ SERIALIZABLE_NON_BINDING_TYPES(V)
45
+
46
+ #define V(TypeId, NativeType) k_##TypeId,
47
+ enum class BindingDataType : uint8_t { BINDING_TYPES(V) kBindingDataTypeCount };
48
+ // Make sure that we put the bindings first so that we can also use the enums
49
+ // for the bindings as index to the binding data store.
50
+ enum class EmbedderObjectType : uint8_t {
51
+ BINDING_TYPES(V) SERIALIZABLE_NON_BINDING_TYPES(V)
52
+ // We do not need to know about all the unserializable non-binding types for
53
+ // now so we do not list them.
54
+ kEmbedderObjectTypeCount
55
+ };
56
+ #undef V
57
+
58
+ // For now, BaseObjects only need to call this when they implement snapshot
59
+ // support.
60
+ #define SET_OBJECT_ID(TypeId) \
61
+ static constexpr EmbedderObjectType type_int = EmbedderObjectType::k_##TypeId;
62
+
63
+ // Binding data should call this so that they can be looked up from the binding
64
+ // data store.
65
+ #define SET_BINDING_ID(TypeId) \
66
+ static constexpr BindingDataType binding_type_int = \
67
+ BindingDataType::k_##TypeId; \
68
+ SET_OBJECT_ID(TypeId) \
69
+ static_assert(static_cast<uint8_t>(type_int) == \
70
+ static_cast<uint8_t>(binding_type_int));
71
+
72
+ } // namespace node
73
+
74
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
75
+
76
+ #endif // SRC_BASE_OBJECT_TYPES_H_
@@ -0,0 +1,385 @@
1
+ #ifndef SRC_BLOB_SERIALIZER_DESERIALIZER_INL_H_
2
+ #define SRC_BLOB_SERIALIZER_DESERIALIZER_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "blob_serializer_deserializer.h"
7
+
8
+ #include <ostream>
9
+ #include <sstream>
10
+ #include <string>
11
+ #include <type_traits>
12
+ #include <utility>
13
+
14
+ #include "debug_utils-inl.h"
15
+
16
+ // This is related to the blob that is used in snapshots and single executable
17
+ // applications and has nothing to do with `node_blob.h`.
18
+
19
+ namespace node {
20
+
21
+ struct EnvSerializeInfo;
22
+ struct PropInfo;
23
+ struct RealmSerializeInfo;
24
+
25
+ namespace builtins {
26
+ struct CodeCacheInfo;
27
+ } // namespace builtins
28
+
29
+ // These operator<< overload declarations are needed because
30
+ // BlobSerializerDeserializer::ToStr() uses these.
31
+
32
+ std::ostream& operator<<(std::ostream& output,
33
+ const builtins::CodeCacheInfo& info);
34
+
35
+ std::ostream& operator<<(std::ostream& output,
36
+ const std::vector<builtins::CodeCacheInfo>& vec);
37
+
38
+ std::ostream& operator<<(std::ostream& output, const std::vector<uint8_t>& vec);
39
+
40
+ std::ostream& operator<<(std::ostream& output,
41
+ const std::vector<PropInfo>& vec);
42
+
43
+ std::ostream& operator<<(std::ostream& output, const PropInfo& info);
44
+
45
+ std::ostream& operator<<(std::ostream& output,
46
+ const std::vector<std::string>& vec);
47
+
48
+ std::ostream& operator<<(std::ostream& output, const RealmSerializeInfo& i);
49
+
50
+ std::ostream& operator<<(std::ostream& output, const EnvSerializeInfo& i);
51
+
52
+ template <typename... Args>
53
+ void BlobSerializerDeserializer::Debug(const char* format,
54
+ Args&&... args) const {
55
+ if (is_debug) {
56
+ FPrintF(stderr, format, std::forward<Args>(args)...);
57
+ }
58
+ }
59
+
60
+ template <typename T>
61
+ std::string BlobSerializerDeserializer::ToStr(const T& arg) const {
62
+ std::stringstream ss;
63
+ ss << arg;
64
+ return ss.str();
65
+ }
66
+
67
+ template <typename T>
68
+ std::string BlobSerializerDeserializer::GetName() const {
69
+ #define TYPE_LIST(V) \
70
+ V(builtins::CodeCacheInfo) \
71
+ V(PropInfo) \
72
+ V(std::string)
73
+
74
+ #define V(TypeName) \
75
+ if constexpr (std::is_same_v<T, TypeName>) { \
76
+ return #TypeName; \
77
+ } else // NOLINT(readability/braces)
78
+ TYPE_LIST(V)
79
+ #undef V
80
+
81
+ if constexpr (std::is_arithmetic_v<T>) {
82
+ return (std::is_unsigned_v<T> ? "uint"
83
+ : std::is_integral_v<T> ? "int"
84
+ : "float") +
85
+ std::to_string(sizeof(T) * 8) + "_t";
86
+ }
87
+ return "";
88
+ }
89
+
90
+ // Helper for reading numeric types.
91
+ template <typename Impl>
92
+ template <typename T>
93
+ requires std::is_arithmetic_v<T>
94
+ T BlobDeserializer<Impl>::ReadArithmetic() {
95
+ T result;
96
+ ReadArithmetic(&result, 1);
97
+ return result;
98
+ }
99
+
100
+ // Layout of vectors:
101
+ // [ 4/8 bytes ] count
102
+ // [ ... ] contents (count * size of individual elements)
103
+ template <typename Impl>
104
+ template <typename T>
105
+ std::vector<T> BlobDeserializer<Impl>::ReadVector() {
106
+ if (is_debug) {
107
+ std::string name = GetName<T>();
108
+ Debug("\nReadVector<%s>()(%d-byte)\n", name, sizeof(T));
109
+ }
110
+ size_t count = static_cast<size_t>(ReadArithmetic<size_t>());
111
+ if (count == 0) {
112
+ return std::vector<T>();
113
+ }
114
+ if (is_debug) {
115
+ Debug("Reading %d vector elements...\n", count);
116
+ }
117
+ std::vector<T> result;
118
+ if constexpr (std::is_arithmetic_v<T>) {
119
+ result = ReadArithmeticVector<T>(count);
120
+ } else {
121
+ result = ReadNonArithmeticVector<T>(count);
122
+ }
123
+ if (is_debug) {
124
+ std::string str = std::is_arithmetic_v<T> ? "" : ToStr(result);
125
+ std::string name = GetName<T>();
126
+ Debug("ReadVector<%s>() read %s\n", name, str);
127
+ }
128
+ return result;
129
+ }
130
+
131
+ template <typename Impl>
132
+ std::string BlobDeserializer<Impl>::ReadString() {
133
+ std::string_view view = ReadStringView(StringLogMode::kAddressAndContent);
134
+ return std::string(view);
135
+ }
136
+
137
+ template <typename Impl>
138
+ std::string_view BlobDeserializer<Impl>::ReadStringView(StringLogMode mode) {
139
+ size_t length = ReadArithmetic<size_t>();
140
+ Debug("ReadStringView(), length=%zu: ", length);
141
+
142
+ if (length == 0) {
143
+ Debug("ReadStringView() read an empty view\n");
144
+ return std::string_view();
145
+ }
146
+
147
+ std::string_view result(sink.data() + read_total, length);
148
+ Debug("%p, read %zu bytes", result.data(), result.size());
149
+ if (mode == StringLogMode::kAddressAndContent) {
150
+ Debug(", content:%s%s", length > 32 ? "\n" : " ", result);
151
+ }
152
+ Debug("\n");
153
+
154
+ read_total += length;
155
+ return result;
156
+ }
157
+
158
+ // Helper for reading an array of numeric types.
159
+ template <typename Impl>
160
+ template <typename T>
161
+ requires std::is_arithmetic_v<T>
162
+ void BlobDeserializer<Impl>::ReadArithmetic(T* out, size_t count) {
163
+ DCHECK_GT(count, 0); // Should not read contents for vectors of size 0.
164
+ if (is_debug) {
165
+ std::string name = GetName<T>();
166
+ Debug("Read<%s>()(%d-byte), count=%d: ", name, sizeof(T), count);
167
+ }
168
+
169
+ size_t size = sizeof(T) * count;
170
+ memcpy(out, sink.data() + read_total, size);
171
+
172
+ if (is_debug) {
173
+ std::string str =
174
+ "{ " + std::to_string(out[0]) + (count > 1 ? ", ... }" : " }");
175
+ Debug("%s, read %zu bytes\n", str, size);
176
+ }
177
+ read_total += size;
178
+ }
179
+
180
+ // Helper for reading numeric vectors.
181
+ template <typename Impl>
182
+ template <typename Number>
183
+ requires std::is_arithmetic_v<Number>
184
+ std::vector<Number> BlobDeserializer<Impl>::ReadArithmeticVector(size_t count) {
185
+ DCHECK_GT(count, 0); // Should not read contents for vectors of size 0.
186
+ std::vector<Number> result(count);
187
+ ReadArithmetic(result.data(), count);
188
+ return result;
189
+ }
190
+
191
+ // Helper for reading non-numeric vectors.
192
+ template <typename Impl>
193
+ template <typename T>
194
+ requires(!std::is_arithmetic_v<T>)
195
+ std::vector<T> BlobDeserializer<Impl>::ReadNonArithmeticVector(size_t count) {
196
+ DCHECK_GT(count, 0); // Should not read contents for vectors of size 0.
197
+ std::vector<T> result;
198
+ result.reserve(count);
199
+ bool original_is_debug = is_debug;
200
+ is_debug = original_is_debug && !std::is_same_v<T, std::string>;
201
+ for (size_t i = 0; i < count; ++i) {
202
+ if (is_debug) {
203
+ Debug("\n[%d] ", i);
204
+ }
205
+ result.push_back(ReadElement<T>());
206
+ }
207
+ is_debug = original_is_debug;
208
+
209
+ return result;
210
+ }
211
+
212
+ template <typename Impl>
213
+ template <typename T>
214
+ T BlobDeserializer<Impl>::ReadElement() {
215
+ if constexpr (std::is_arithmetic_v<T>) {
216
+ return ReadArithmetic<T>();
217
+ } else if constexpr (std::is_same_v<T, std::string>) {
218
+ return ReadString();
219
+ } else {
220
+ return impl()->template Read<T>();
221
+ }
222
+ }
223
+
224
+ // Helper for writing numeric types.
225
+ template <typename Impl>
226
+ template <typename T>
227
+ requires std::is_arithmetic_v<T>
228
+ size_t BlobSerializer<Impl>::WriteArithmetic(const T& data) {
229
+ return WriteArithmetic(&data, 1);
230
+ }
231
+
232
+ // Layout of vectors:
233
+ // [ 4/8 bytes ] count
234
+ // [ ... ] contents (count * size of individual elements)
235
+ template <typename Impl>
236
+ template <typename T>
237
+ size_t BlobSerializer<Impl>::WriteVector(const std::vector<T>& data) {
238
+ if (is_debug) {
239
+ std::string str = std::is_arithmetic_v<T> ? "" : ToStr(data);
240
+ std::string name = GetName<T>();
241
+ Debug("\nAt 0x%x: WriteVector<%s>() (%d-byte), count=%d: %s\n",
242
+ sink.size(),
243
+ name,
244
+ sizeof(T),
245
+ data.size(),
246
+ str);
247
+ }
248
+
249
+ size_t written_total = WriteArithmetic<size_t>(data.size());
250
+ if (data.empty()) {
251
+ return written_total;
252
+ }
253
+
254
+ if constexpr (std::is_arithmetic_v<T>) {
255
+ written_total += WriteArithmeticVector<T>(data);
256
+ } else {
257
+ written_total += WriteNonArithmeticVector<T>(data);
258
+ }
259
+
260
+ if (is_debug) {
261
+ std::string name = GetName<T>();
262
+ Debug("WriteVector<%s>() wrote %d bytes\n", name, written_total);
263
+ }
264
+
265
+ return written_total;
266
+ }
267
+
268
+ // The layout of a written string:
269
+ // [ 4/8 bytes ] length
270
+ // [ |length| bytes ] contents
271
+ template <typename Impl>
272
+ size_t BlobSerializer<Impl>::WriteStringView(std::string_view data,
273
+ StringLogMode mode) {
274
+ Debug("At 0x%x: WriteStringView(), length=%zu: %p\n",
275
+ sink.size(),
276
+ data.size(),
277
+ data.data());
278
+ size_t written_total = WriteArithmetic<size_t>(data.size());
279
+
280
+ size_t length = data.size();
281
+ if (length == 0) {
282
+ Debug("WriteStringView() wrote an empty view\n");
283
+ return written_total;
284
+ }
285
+ sink.insert(sink.end(), data.data(), data.data() + length);
286
+ written_total += length;
287
+
288
+ Debug("WriteStringView() wrote %zu bytes\n", written_total);
289
+ if (mode == StringLogMode::kAddressAndContent) {
290
+ Debug("%s", data);
291
+ }
292
+
293
+ return written_total;
294
+ }
295
+
296
+ template <typename Impl>
297
+ size_t BlobSerializer<Impl>::WriteString(const std::string& data) {
298
+ return WriteStringView(data, StringLogMode::kAddressAndContent);
299
+ }
300
+
301
+ static size_t kPreviewCount = 16;
302
+
303
+ // Helper for writing an array of numeric types.
304
+ template <typename Impl>
305
+ template <typename T>
306
+ requires std::is_arithmetic_v<T>
307
+ size_t BlobSerializer<Impl>::WriteArithmetic(const T* data, size_t count) {
308
+ DCHECK_GT(count, 0); // Should not write contents for vectors of size 0.
309
+ if (is_debug) {
310
+ size_t preview_count = count < kPreviewCount ? count : kPreviewCount;
311
+ std::string str = "{ ";
312
+ for (size_t i = 0; i < preview_count; ++i) {
313
+ str += (std::to_string(data[i]) + ",");
314
+ }
315
+ if (count > preview_count) {
316
+ str += "...";
317
+ }
318
+ str += "}";
319
+ std::string name = GetName<T>();
320
+ Debug("At 0x%x: Write<%s>() (%zu-byte), count=%zu: %s",
321
+ sink.size(),
322
+ name,
323
+ sizeof(T),
324
+ count,
325
+ str);
326
+ }
327
+
328
+ size_t size = sizeof(T) * count;
329
+ const char* pos = reinterpret_cast<const char*>(data);
330
+ sink.insert(sink.end(), pos, pos + size);
331
+
332
+ if (is_debug) {
333
+ Debug(", wrote %zu bytes\n", size);
334
+ }
335
+ return size;
336
+ }
337
+
338
+ // Helper for writing numeric vectors.
339
+ template <typename Impl>
340
+ template <typename Number>
341
+ requires std::is_arithmetic_v<Number>
342
+ size_t BlobSerializer<Impl>::WriteArithmeticVector(
343
+ const std::vector<Number>& data) {
344
+ return WriteArithmetic(data.data(), data.size());
345
+ }
346
+
347
+ // Helper for writing non-numeric vectors.
348
+ template <typename Impl>
349
+ template <typename T>
350
+ requires(!std::is_arithmetic_v<T>)
351
+ size_t
352
+ BlobSerializer<Impl>::WriteNonArithmeticVector(const std::vector<T>& data) {
353
+ DCHECK_GT(data.size(),
354
+ 0); // Should not write contents for vectors of size 0.
355
+ size_t written_total = 0;
356
+ bool original_is_debug = is_debug;
357
+ is_debug = original_is_debug && !std::is_same_v<T, std::string>;
358
+ for (size_t i = 0; i < data.size(); ++i) {
359
+ if (is_debug) {
360
+ Debug("\n[%d] ", i);
361
+ }
362
+ written_total += WriteElement<T>(data[i]);
363
+ }
364
+ is_debug = original_is_debug;
365
+
366
+ return written_total;
367
+ }
368
+
369
+ template <typename Impl>
370
+ template <typename T>
371
+ size_t BlobSerializer<Impl>::WriteElement(const T& data) {
372
+ if constexpr (std::is_arithmetic_v<T>) {
373
+ return WriteArithmetic<T>(data);
374
+ } else if constexpr (std::is_same_v<T, std::string>) {
375
+ return WriteString(data);
376
+ } else {
377
+ return impl()->template Write<T>(data);
378
+ }
379
+ }
380
+
381
+ } // namespace node
382
+
383
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
384
+
385
+ #endif // SRC_BLOB_SERIALIZER_DESERIALIZER_INL_H_
@@ -0,0 +1,142 @@
1
+ #ifndef SRC_BLOB_SERIALIZER_DESERIALIZER_H_
2
+ #define SRC_BLOB_SERIALIZER_DESERIALIZER_H_
3
+
4
+ #include <concepts>
5
+ #include <string>
6
+ #include <type_traits>
7
+ #include <vector>
8
+
9
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
10
+
11
+ // This is related to the blob that is used in snapshots and single executable
12
+ // applications and has nothing to do with `node_blob.h`.
13
+
14
+ namespace node {
15
+
16
+ class BlobSerializerDeserializer {
17
+ public:
18
+ explicit BlobSerializerDeserializer(bool is_debug_v) : is_debug(is_debug_v) {}
19
+
20
+ template <typename... Args>
21
+ void Debug(const char* format, Args&&... args) const;
22
+
23
+ template <typename T>
24
+ std::string ToStr(const T& arg) const;
25
+
26
+ template <typename T>
27
+ std::string GetName() const;
28
+
29
+ bool is_debug = false;
30
+ };
31
+
32
+ enum class StringLogMode {
33
+ kAddressOnly, // Can be used when the string contains binary content.
34
+ kAddressAndContent,
35
+ };
36
+
37
+ // Child classes are expected to implement T Read<T>() where
38
+ // !std::is_arithmetic_v<T> && !std::is_same_v<T, std::string>
39
+ template <typename Impl>
40
+ class BlobDeserializer : public BlobSerializerDeserializer {
41
+ public:
42
+ explicit BlobDeserializer(bool is_debug_v, std::string_view s)
43
+ : BlobSerializerDeserializer(is_debug_v), sink(s) {}
44
+ ~BlobDeserializer() = default;
45
+
46
+ size_t read_total = 0;
47
+ std::string_view sink;
48
+
49
+ Impl* impl() { return static_cast<Impl*>(this); }
50
+ const Impl* impl() const { return static_cast<const Impl*>(this); }
51
+
52
+ // Helper for reading numeric types.
53
+ template <typename T>
54
+ requires std::is_arithmetic_v<T>
55
+ T ReadArithmetic();
56
+
57
+ // Layout of vectors:
58
+ // [ 4/8 bytes ] count
59
+ // [ ... ] contents (count * size of individual elements)
60
+ template <typename T>
61
+ std::vector<T> ReadVector();
62
+
63
+ // ReadString() creates a copy of the data. ReadStringView() doesn't.
64
+ std::string ReadString();
65
+ std::string_view ReadStringView(StringLogMode mode);
66
+
67
+ // Helper for reading an array of numeric types.
68
+ template <typename T>
69
+ requires std::is_arithmetic_v<T>
70
+ void ReadArithmetic(T* out, size_t count);
71
+
72
+ // Helper for reading numeric vectors.
73
+ template <typename Number>
74
+ requires std::is_arithmetic_v<Number>
75
+ std::vector<Number> ReadArithmeticVector(size_t count);
76
+
77
+ private:
78
+ // Helper for reading non-numeric vectors.
79
+ template <typename T>
80
+ requires(!std::is_arithmetic_v<T>)
81
+ std::vector<T> ReadNonArithmeticVector(size_t count);
82
+
83
+ template <typename T>
84
+ T ReadElement();
85
+ };
86
+
87
+ // Child classes are expected to implement size_t Write<T>(const T&) where
88
+ // !std::is_arithmetic_v<T> && !std::is_same_v<T, std::string>
89
+ template <typename Impl>
90
+ class BlobSerializer : public BlobSerializerDeserializer {
91
+ public:
92
+ explicit BlobSerializer(bool is_debug_v)
93
+ : BlobSerializerDeserializer(is_debug_v) {}
94
+ ~BlobSerializer() = default;
95
+
96
+ Impl* impl() { return static_cast<Impl*>(this); }
97
+ const Impl* impl() const { return static_cast<const Impl*>(this); }
98
+
99
+ std::vector<char> sink;
100
+
101
+ // Helper for writing numeric types.
102
+ template <typename T>
103
+ requires std::is_arithmetic_v<T>
104
+ size_t WriteArithmetic(const T& data);
105
+
106
+ // Layout of vectors:
107
+ // [ 4/8 bytes ] count
108
+ // [ ... ] contents (count * size of individual elements)
109
+ template <typename T>
110
+ size_t WriteVector(const std::vector<T>& data);
111
+
112
+ // The layout of a written string:
113
+ // [ 4/8 bytes ] length
114
+ // [ |length| bytes ] contents
115
+ size_t WriteStringView(std::string_view data, StringLogMode mode);
116
+ size_t WriteString(const std::string& data);
117
+
118
+ // Helper for writing an array of numeric types.
119
+ template <typename T>
120
+ requires std::is_arithmetic_v<T>
121
+ size_t WriteArithmetic(const T* data, size_t count);
122
+
123
+ // Helper for writing numeric vectors.
124
+ template <typename Number>
125
+ requires std::is_arithmetic_v<Number>
126
+ size_t WriteArithmeticVector(const std::vector<Number>& data);
127
+
128
+ private:
129
+ // Helper for writing non-numeric vectors.
130
+ template <typename T>
131
+ requires(!std::is_arithmetic_v<T>)
132
+ size_t WriteNonArithmeticVector(const std::vector<T>& data);
133
+
134
+ template <typename T>
135
+ size_t WriteElement(const T& data);
136
+ };
137
+
138
+ } // namespace node
139
+
140
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
141
+
142
+ #endif // SRC_BLOB_SERIALIZER_DESERIALIZER_H_
@@ -0,0 +1,57 @@
1
+ #ifndef SRC_BUILTIN_INFO_H_
2
+ #define SRC_BUILTIN_INFO_H_
3
+
4
+ #include <cinttypes>
5
+ #include <string>
6
+ #include <unordered_map>
7
+ #include <vector>
8
+
9
+ // This file must not depend on node.h or other code that depends on
10
+ // the full Node.js implementation because it is used during the
11
+ // compilation of the Node.js implementation itself (especially js2c).
12
+
13
+ namespace node {
14
+ namespace builtins {
15
+
16
+ enum class BuiltinSourceType {
17
+ kBootstrapRealm, // internal/bootstrap/realm
18
+ kBootstrapScript, // internal/bootstrap/*
19
+ kPerContextScript, // internal/per_context/*
20
+ kMainScript, // internal/main/*
21
+ kFunction, // others
22
+ kSourceTextModule, // selected modules, ends with .mjs in source
23
+ };
24
+
25
+ struct BuiltinInfo {
26
+ // C++17 inline static
27
+ inline static const std::unordered_map<BuiltinSourceType,
28
+ std::vector<std::string>>
29
+ parameter_map{
30
+ {BuiltinSourceType::kBootstrapRealm,
31
+ {"process",
32
+ "getLinkedBinding",
33
+ "getInternalBinding",
34
+ "primordials"}},
35
+ {BuiltinSourceType::kBootstrapScript,
36
+ {"process", "require", "internalBinding", "primordials"}},
37
+ {BuiltinSourceType::kPerContextScript,
38
+ {"exports", "primordials", "privateSymbols", "perIsolateSymbols"}},
39
+ {BuiltinSourceType::kMainScript,
40
+ {"process", "require", "internalBinding", "primordials"}},
41
+ {BuiltinSourceType::kFunction,
42
+ {"exports",
43
+ "require",
44
+ "module",
45
+ "process",
46
+ "internalBinding",
47
+ "primordials"}},
48
+ };
49
+ };
50
+
51
+ std::string GetBuiltinSourceTypeName(BuiltinSourceType type);
52
+ BuiltinSourceType GetBuiltinSourceType(const std::string& id,
53
+ const std::string& filename);
54
+ } // namespace builtins
55
+ } // namespace node
56
+
57
+ #endif // SRC_BUILTIN_INFO_H_