@encharm/cws 4.5.3 → 4.8.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 (305) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/CLAUDE.md +83 -0
  3. package/README.md +20 -4
  4. package/binding.gyp +8 -2
  5. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
  7. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  8. package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
  9. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node127.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node137.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node147.node +0 -0
  13. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node127.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node147.node +0 -0
  17. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node127.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node137.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node147.node +0 -0
  21. package/dist/client.d.ts +1 -0
  22. package/dist/client.js +15 -1
  23. package/dist/index.d.ts +6 -1
  24. package/dist/index.js +2 -0
  25. package/dist/server.d.ts +1 -0
  26. package/dist/server.js +16 -2
  27. package/dist/shared.d.ts +1 -0
  28. package/dist/shared.js +3 -2
  29. package/package.json +1 -1
  30. package/src/Addon.cpp +4 -1
  31. package/src/Addon.h +80 -15
  32. package/src/Extensions.cpp +7 -1
  33. package/src/Extensions.h +2 -1
  34. package/src/Group.cpp +1 -1
  35. package/src/Group.h +4 -1
  36. package/src/HTTPSocket.cpp +1 -1
  37. package/src/Hub.cpp +11 -76
  38. package/src/Hub.h +12 -10
  39. package/src/Networking.h +11 -0
  40. package/src/Socket.h +201 -6
  41. package/src/WebSocket.cpp +8 -5
  42. package/src/Zlib.cpp +138 -0
  43. package/src/Zlib.h +38 -0
  44. package/src/cSNode.cpp +2 -0
  45. package/src/cSNode.h +4 -0
  46. package/src/headers/26/acorn_version.h +6 -0
  47. package/src/headers/26/aliased_buffer-inl.h +264 -0
  48. package/src/headers/26/aliased_buffer.h +205 -0
  49. package/src/headers/26/aliased_struct-inl.h +143 -0
  50. package/src/headers/26/aliased_struct.h +248 -0
  51. package/src/headers/26/amaro_version.h +6 -0
  52. package/src/headers/26/async_context_frame.h +33 -0
  53. package/src/headers/26/async_wrap-inl.h +123 -0
  54. package/src/headers/26/async_wrap.h +254 -0
  55. package/src/headers/26/base_object-inl.h +333 -0
  56. package/src/headers/26/base_object.h +339 -0
  57. package/src/headers/26/base_object_types.h +76 -0
  58. package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
  59. package/src/headers/26/blob_serializer_deserializer.h +142 -0
  60. package/src/headers/26/builtin_info.h +57 -0
  61. package/src/headers/26/callback_queue-inl.h +97 -0
  62. package/src/headers/26/callback_queue.h +79 -0
  63. package/src/headers/26/cares_wrap.h +475 -0
  64. package/src/headers/26/cleanup_queue-inl.h +36 -0
  65. package/src/headers/26/cleanup_queue.h +79 -0
  66. package/src/headers/26/compile_cache.h +134 -0
  67. package/src/headers/26/connect_wrap.h +26 -0
  68. package/src/headers/26/connection_wrap.h +30 -0
  69. package/src/headers/26/cppgc_helpers-inl.h +69 -0
  70. package/src/headers/26/cppgc_helpers.h +162 -0
  71. package/src/headers/26/crypto/crypto_aes.h +107 -0
  72. package/src/headers/26/crypto/crypto_argon2.h +88 -0
  73. package/src/headers/26/crypto/crypto_bio.h +193 -0
  74. package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
  75. package/src/headers/26/crypto/crypto_cipher.h +291 -0
  76. package/src/headers/26/crypto/crypto_common.h +48 -0
  77. package/src/headers/26/crypto/crypto_context.h +219 -0
  78. package/src/headers/26/crypto/crypto_dh.h +104 -0
  79. package/src/headers/26/crypto/crypto_dsa.h +50 -0
  80. package/src/headers/26/crypto/crypto_ec.h +102 -0
  81. package/src/headers/26/crypto/crypto_hash.h +157 -0
  82. package/src/headers/26/crypto/crypto_hkdf.h +62 -0
  83. package/src/headers/26/crypto/crypto_hmac.h +92 -0
  84. package/src/headers/26/crypto/crypto_kem.h +131 -0
  85. package/src/headers/26/crypto/crypto_keygen.h +382 -0
  86. package/src/headers/26/crypto/crypto_keys.h +366 -0
  87. package/src/headers/26/crypto/crypto_kmac.h +79 -0
  88. package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
  89. package/src/headers/26/crypto/crypto_pqc.h +39 -0
  90. package/src/headers/26/crypto/crypto_random.h +127 -0
  91. package/src/headers/26/crypto/crypto_rsa.h +108 -0
  92. package/src/headers/26/crypto/crypto_scrypt.h +85 -0
  93. package/src/headers/26/crypto/crypto_sig.h +159 -0
  94. package/src/headers/26/crypto/crypto_spkac.h +21 -0
  95. package/src/headers/26/crypto/crypto_timing.h +20 -0
  96. package/src/headers/26/crypto/crypto_tls.h +342 -0
  97. package/src/headers/26/crypto/crypto_turboshake.h +105 -0
  98. package/src/headers/26/crypto/crypto_util.h +775 -0
  99. package/src/headers/26/crypto/crypto_x509.h +140 -0
  100. package/src/headers/26/dataqueue/queue.h +311 -0
  101. package/src/headers/26/debug_utils-inl.h +291 -0
  102. package/src/headers/26/debug_utils.h +200 -0
  103. package/src/headers/26/diagnosticfilename-inl.h +33 -0
  104. package/src/headers/26/embedded_data.h +17 -0
  105. package/src/headers/26/encoding_binding.h +59 -0
  106. package/src/headers/26/env-inl.h +956 -0
  107. package/src/headers/26/env.h +1294 -0
  108. package/src/headers/26/env_properties.h +562 -0
  109. package/src/headers/26/ffi/data.h +30 -0
  110. package/src/headers/26/ffi/fast.h +96 -0
  111. package/src/headers/26/ffi/jit_memory.h +26 -0
  112. package/src/headers/26/ffi/types.h +99 -0
  113. package/src/headers/26/handle_wrap.h +123 -0
  114. package/src/headers/26/histogram-inl.h +211 -0
  115. package/src/headers/26/histogram.h +474 -0
  116. package/src/headers/26/inspector/dom_storage_agent.h +68 -0
  117. package/src/headers/26/inspector/inspector_object_utils.h +38 -0
  118. package/src/headers/26/inspector/io_agent.h +30 -0
  119. package/src/headers/26/inspector/main_thread_interface.h +116 -0
  120. package/src/headers/26/inspector/network_agent.h +110 -0
  121. package/src/headers/26/inspector/network_inspector.h +45 -0
  122. package/src/headers/26/inspector/network_requests_buffer.h +195 -0
  123. package/src/headers/26/inspector/network_resource_manager.h +29 -0
  124. package/src/headers/26/inspector/node_json.h +24 -0
  125. package/src/headers/26/inspector/node_string.h +101 -0
  126. package/src/headers/26/inspector/notification_emitter.h +38 -0
  127. package/src/headers/26/inspector/protocol_helper.h +27 -0
  128. package/src/headers/26/inspector/runtime_agent.h +41 -0
  129. package/src/headers/26/inspector/storage_agent.h +33 -0
  130. package/src/headers/26/inspector/target_agent.h +59 -0
  131. package/src/headers/26/inspector/target_manager.h +70 -0
  132. package/src/headers/26/inspector/tracing_agent.h +43 -0
  133. package/src/headers/26/inspector/worker_agent.h +40 -0
  134. package/src/headers/26/inspector/worker_inspector.h +124 -0
  135. package/src/headers/26/inspector_agent.h +168 -0
  136. package/src/headers/26/inspector_io.h +78 -0
  137. package/src/headers/26/inspector_profiler.h +149 -0
  138. package/src/headers/26/inspector_socket.h +60 -0
  139. package/src/headers/26/inspector_socket_server.h +110 -0
  140. package/src/headers/26/js_native_api.h +634 -0
  141. package/src/headers/26/js_native_api_types.h +244 -0
  142. package/src/headers/26/js_native_api_v8.h +485 -0
  143. package/src/headers/26/js_native_api_v8_internals.h +45 -0
  144. package/src/headers/26/js_stream.h +57 -0
  145. package/src/headers/26/json_utils.h +172 -0
  146. package/src/headers/26/large_pages/node_large_page.h +34 -0
  147. package/src/headers/26/lru_cache-inl.h +69 -0
  148. package/src/headers/26/memory_tracker-inl.h +461 -0
  149. package/src/headers/26/memory_tracker.h +341 -0
  150. package/src/headers/26/module_wrap.h +231 -0
  151. package/src/headers/26/ncrypto.h +2008 -0
  152. package/src/headers/26/node.h +1693 -0
  153. package/src/headers/26/node_api.h +265 -0
  154. package/src/headers/26/node_api_internals.h +48 -0
  155. package/src/headers/26/node_api_types.h +58 -0
  156. package/src/headers/26/node_binding.h +170 -0
  157. package/src/headers/26/node_blob.h +160 -0
  158. package/src/headers/26/node_bob-inl.h +36 -0
  159. package/src/headers/26/node_bob.h +107 -0
  160. package/src/headers/26/node_buffer.h +92 -0
  161. package/src/headers/26/node_builtins.h +239 -0
  162. package/src/headers/26/node_concepts.h +46 -0
  163. package/src/headers/26/node_config_file.h +77 -0
  164. package/src/headers/26/node_constants.h +82 -0
  165. package/src/headers/26/node_context_data.h +171 -0
  166. package/src/headers/26/node_contextify.h +261 -0
  167. package/src/headers/26/node_crypto.h +66 -0
  168. package/src/headers/26/node_debug.h +30 -0
  169. package/src/headers/26/node_diagnostics_channel.h +121 -0
  170. package/src/headers/26/node_dir.h +52 -0
  171. package/src/headers/26/node_dotenv.h +45 -0
  172. package/src/headers/26/node_errors.h +378 -0
  173. package/src/headers/26/node_exit_code.h +54 -0
  174. package/src/headers/26/node_external_reference.h +171 -0
  175. package/src/headers/26/node_ffi.h +212 -0
  176. package/src/headers/26/node_file-inl.h +421 -0
  177. package/src/headers/26/node_file.h +561 -0
  178. package/src/headers/26/node_file_utils.h +39 -0
  179. package/src/headers/26/node_hash.h +212 -0
  180. package/src/headers/26/node_http2.h +1202 -0
  181. package/src/headers/26/node_http2_state.h +159 -0
  182. package/src/headers/26/node_http_common-inl.h +199 -0
  183. package/src/headers/26/node_http_common.h +535 -0
  184. package/src/headers/26/node_i18n.h +132 -0
  185. package/src/headers/26/node_internals.h +485 -0
  186. package/src/headers/26/node_locks.h +184 -0
  187. package/src/headers/26/node_main_instance.h +67 -0
  188. package/src/headers/26/node_mem-inl.h +113 -0
  189. package/src/headers/26/node_mem.h +45 -0
  190. package/src/headers/26/node_messaging.h +389 -0
  191. package/src/headers/26/node_metadata.h +172 -0
  192. package/src/headers/26/node_modules.h +102 -0
  193. package/src/headers/26/node_mutex.h +323 -0
  194. package/src/headers/26/node_object_wrap.h +145 -0
  195. package/src/headers/26/node_options-inl.h +524 -0
  196. package/src/headers/26/node_options.h +710 -0
  197. package/src/headers/26/node_perf.h +167 -0
  198. package/src/headers/26/node_perf_common.h +103 -0
  199. package/src/headers/26/node_platform.h +290 -0
  200. package/src/headers/26/node_process-inl.h +26 -0
  201. package/src/headers/26/node_process.h +112 -0
  202. package/src/headers/26/node_profiling.h +38 -0
  203. package/src/headers/26/node_realm-inl.h +156 -0
  204. package/src/headers/26/node_realm.h +236 -0
  205. package/src/headers/26/node_report.h +43 -0
  206. package/src/headers/26/node_revert.h +82 -0
  207. package/src/headers/26/node_root_certs.h +2937 -0
  208. package/src/headers/26/node_sea.h +101 -0
  209. package/src/headers/26/node_shadow_realm.h +46 -0
  210. package/src/headers/26/node_snapshot_builder.h +57 -0
  211. package/src/headers/26/node_snapshotable.h +167 -0
  212. package/src/headers/26/node_sockaddr-inl.h +248 -0
  213. package/src/headers/26/node_sockaddr.h +459 -0
  214. package/src/headers/26/node_sqlite.h +607 -0
  215. package/src/headers/26/node_stat_watcher.h +73 -0
  216. package/src/headers/26/node_task_runner.h +92 -0
  217. package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
  218. package/src/headers/26/node_threadsafe_cow.h +105 -0
  219. package/src/headers/26/node_union_bytes.h +81 -0
  220. package/src/headers/26/node_url.h +101 -0
  221. package/src/headers/26/node_url_pattern.h +118 -0
  222. package/src/headers/26/node_v8.h +78 -0
  223. package/src/headers/26/node_v8_embedder.h +26 -0
  224. package/src/headers/26/node_v8_platform-inl.h +96 -0
  225. package/src/headers/26/node_version.h +116 -0
  226. package/src/headers/26/node_wasi.h +184 -0
  227. package/src/headers/26/node_wasm_web_api.h +55 -0
  228. package/src/headers/26/node_watchdog.h +164 -0
  229. package/src/headers/26/node_webstorage.h +62 -0
  230. package/src/headers/26/node_worker.h +162 -0
  231. package/src/headers/26/path.h +36 -0
  232. package/src/headers/26/permission/boolean_permission.h +50 -0
  233. package/src/headers/26/permission/fs_permission.h +192 -0
  234. package/src/headers/26/permission/permission.h +155 -0
  235. package/src/headers/26/permission/permission_base.h +79 -0
  236. package/src/headers/26/pipe_wrap.h +80 -0
  237. package/src/headers/26/quic/application.h +279 -0
  238. package/src/headers/26/quic/arena.h +373 -0
  239. package/src/headers/26/quic/bindingdata.h +440 -0
  240. package/src/headers/26/quic/cid.h +127 -0
  241. package/src/headers/26/quic/data.h +358 -0
  242. package/src/headers/26/quic/defs.h +417 -0
  243. package/src/headers/26/quic/endpoint.h +519 -0
  244. package/src/headers/26/quic/guard.h +5 -0
  245. package/src/headers/26/quic/http3.h +25 -0
  246. package/src/headers/26/quic/packet.h +166 -0
  247. package/src/headers/26/quic/preferredaddress.h +72 -0
  248. package/src/headers/26/quic/session.h +770 -0
  249. package/src/headers/26/quic/session_manager.h +107 -0
  250. package/src/headers/26/quic/sessionticket.h +110 -0
  251. package/src/headers/26/quic/streams.h +518 -0
  252. package/src/headers/26/quic/tlscontext.h +353 -0
  253. package/src/headers/26/quic/tokens.h +263 -0
  254. package/src/headers/26/quic/transportparams.h +184 -0
  255. package/src/headers/26/req_wrap-inl.h +175 -0
  256. package/src/headers/26/req_wrap.h +79 -0
  257. package/src/headers/26/spawn_sync.h +243 -0
  258. package/src/headers/26/stream_base-inl.h +170 -0
  259. package/src/headers/26/stream_base.h +487 -0
  260. package/src/headers/26/stream_pipe.h +76 -0
  261. package/src/headers/26/stream_wrap.h +137 -0
  262. package/src/headers/26/string_bytes.h +114 -0
  263. package/src/headers/26/string_decoder-inl.h +31 -0
  264. package/src/headers/26/string_decoder.h +49 -0
  265. package/src/headers/26/tcp_wrap.h +138 -0
  266. package/src/headers/26/threadpoolwork-inl.h +70 -0
  267. package/src/headers/26/timer_wrap-inl.h +32 -0
  268. package/src/headers/26/timer_wrap.h +87 -0
  269. package/src/headers/26/timers.h +70 -0
  270. package/src/headers/26/tracing/agent.h +125 -0
  271. package/src/headers/26/tracing/agent_legacy.h +146 -0
  272. package/src/headers/26/tracing/agent_perfetto.h +145 -0
  273. package/src/headers/26/tracing/node_trace_buffer.h +91 -0
  274. package/src/headers/26/tracing/node_trace_writer.h +79 -0
  275. package/src/headers/26/tracing/trace_event.h +27 -0
  276. package/src/headers/26/tracing/trace_event_helper.h +40 -0
  277. package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
  278. package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
  279. package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
  280. package/src/headers/26/tracing/traced_value.h +167 -0
  281. package/src/headers/26/tty_wrap.h +65 -0
  282. package/src/headers/26/udp_wrap.h +231 -0
  283. package/src/headers/26/undici_version.h +6 -0
  284. package/src/headers/26/util-inl.h +788 -0
  285. package/src/headers/26/util.h +1207 -0
  286. package/src/headers/26/v8-cpp-heap-external.h +56 -0
  287. package/src/headers/26/v8-external-memory-accounter.h +60 -0
  288. package/src/headers/26/v8-fast-api-calls.h +784 -0
  289. package/src/headers/26/v8-inspector-protocol.h +13 -0
  290. package/src/headers/26/v8-inspector.h +458 -0
  291. package/src/headers/26/v8-metrics.h +273 -0
  292. package/src/headers/26/v8-trace-categories.h +28 -0
  293. package/src/headers/26/v8-unwinder-state.h +30 -0
  294. package/src/headers/26/v8-util.h +549 -0
  295. package/src/headers/26/v8-value-serializer-version.h +24 -0
  296. package/src/headers/26/v8-version-string.h +38 -0
  297. package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
  298. package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
  299. package/src/headers/26/zlib_version.h +6 -0
  300. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +0 -20
  301. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
  302. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +0 -931
  303. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +0 -20
  304. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
  305. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +0 -931
@@ -0,0 +1,92 @@
1
+ #ifndef SRC_NODE_TASK_RUNNER_H_
2
+ #define SRC_NODE_TASK_RUNNER_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node_internals.h"
7
+ #include "simdjson.h"
8
+ #include "spawn_sync.h"
9
+ #include "uv.h"
10
+
11
+ #include <filesystem>
12
+ #include <optional>
13
+ #include <string_view>
14
+ #include <tuple>
15
+
16
+ namespace node::task_runner {
17
+
18
+ using PositionalArgs = std::vector<std::string_view>;
19
+
20
+ // ProcessRunner is the class responsible for running a process.
21
+ // A class instance is created for each process to be run.
22
+ // The class is responsible for spawning the process and handling its exit.
23
+ // The class also handles the environment variables and arguments.
24
+ class ProcessRunner {
25
+ public:
26
+ ProcessRunner(std::shared_ptr<InitializationResultImpl> result,
27
+ const std::filesystem::path& package_json_path,
28
+ std::string_view script_name,
29
+ std::string_view command,
30
+ std::string_view path_env_var,
31
+ const PositionalArgs& positional_args);
32
+ void Run();
33
+ static void ExitCallback(uv_process_t* req,
34
+ int64_t exit_status,
35
+ int term_signal);
36
+
37
+ private:
38
+ uv_loop_t* loop_ = uv_default_loop();
39
+ uv_process_t process_{};
40
+ uv_process_options_t options_{};
41
+ uv_stdio_container_t child_stdio_[3]{};
42
+ std::shared_ptr<InitializationResultImpl> init_result_;
43
+ std::vector<std::string> command_args_{};
44
+ std::vector<std::string> env_vars_{};
45
+ std::unique_ptr<char* []> env_ {}; // memory for options_.env
46
+ std::unique_ptr<char* []> arg_ {}; // memory for options_.args
47
+ std::string cwd_;
48
+
49
+ // OnExit is the callback function that is called when the process exits.
50
+ void OnExit(int64_t exit_status, int term_signal);
51
+ void SetEnvironmentVariables();
52
+
53
+ #ifdef _WIN32
54
+ std::string file_ = "cmd.exe";
55
+ #else
56
+ std::string file_ = "/bin/sh";
57
+ #endif // _WIN32
58
+
59
+ // Represents the absolute path to the package.json file.
60
+ std::filesystem::path package_json_path_;
61
+ // Represents the name of the script that is being run.
62
+ std::string script_name_;
63
+ // Represents PATH environment variable that contains
64
+ // all subdirectory paths appended with node_modules/.bin suffix.
65
+ std::string path_env_var_;
66
+ };
67
+
68
+ // This function traverses up to the root directory.
69
+ // While traversing up, if it finds a package.json file, it reads its content.
70
+ // If it cannot find a package.json file, it returns std::nullopt.
71
+ // Otherwise, it returns a tuple of:
72
+ // - the path to the package.json file
73
+ // - package.json file content
74
+ // - `path_env_var` variable
75
+ //
76
+ // For example, on POSIX, it returns the following for `path_env_var`,
77
+ // if the current directory is `/anonrig`:
78
+ // `/anonrig/node_modules/.bin:/node_modules/.bin`
79
+ std::optional<std::tuple<std::filesystem::path, std::string, std::string>>
80
+ FindPackageJson(const std::filesystem::path& cwd);
81
+
82
+ void RunTask(const std::shared_ptr<InitializationResultImpl>& result,
83
+ std::string_view command_id,
84
+ const PositionalArgs& positional_args);
85
+ PositionalArgs GetPositionalArgs(const std::vector<std::string>& args);
86
+ std::string EscapeShell(std::string_view command);
87
+
88
+ } // namespace node::task_runner
89
+
90
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
91
+
92
+ #endif // SRC_NODE_TASK_RUNNER_H_
@@ -0,0 +1,54 @@
1
+ #ifndef SRC_NODE_THREADSAFE_COW_INL_H_
2
+ #define SRC_NODE_THREADSAFE_COW_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ namespace node {
7
+
8
+ template <typename T>
9
+ T* CopyOnWrite<T>::write() {
10
+ if (data_.use_count() > 1l) {
11
+ data_ = std::make_shared<T>(*data_);
12
+ }
13
+ return data_.get();
14
+ }
15
+
16
+ template <typename T>
17
+ ThreadsafeCopyOnWrite<T>::Read::Read(const ThreadsafeCopyOnWrite<T>* cow)
18
+ : cow_(cow), lock_(cow->impl_->mutex) {}
19
+
20
+ template <typename T>
21
+ const T& ThreadsafeCopyOnWrite<T>::Read::operator*() const {
22
+ return cow_->impl_->data;
23
+ }
24
+
25
+ template <typename T>
26
+ const T* ThreadsafeCopyOnWrite<T>::Read::operator->() const {
27
+ return &cow_->impl_->data;
28
+ }
29
+
30
+ template <typename T>
31
+ ThreadsafeCopyOnWrite<T>::Write::Write(ThreadsafeCopyOnWrite<T>* cow)
32
+ : cow_(cow), impl_(cow->impl_.write()), lock_(impl_->mutex) {}
33
+
34
+ template <typename T>
35
+ T& ThreadsafeCopyOnWrite<T>::Write::operator*() {
36
+ return impl_->data;
37
+ }
38
+
39
+ template <typename T>
40
+ T* ThreadsafeCopyOnWrite<T>::Write::operator->() {
41
+ return &impl_->data;
42
+ }
43
+
44
+ template <typename T>
45
+ ThreadsafeCopyOnWrite<T>::Impl::Impl(const Impl& other) {
46
+ RwLock::ScopedReadLock lock(other.mutex);
47
+ data = other.data;
48
+ }
49
+
50
+ } // namespace node
51
+
52
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
53
+
54
+ #endif // SRC_NODE_THREADSAFE_COW_INL_H_
@@ -0,0 +1,105 @@
1
+ #ifndef SRC_NODE_THREADSAFE_COW_H_
2
+ #define SRC_NODE_THREADSAFE_COW_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "util.h"
7
+ #include "uv.h"
8
+
9
+ #include <memory> // std::shared_ptr<T>
10
+ #include <utility> // std::forward<T>
11
+
12
+ namespace node {
13
+
14
+ // Copy-on-write utility. Not threadsafe, i.e. there is no synchronization
15
+ // of the copy operation with other operations.
16
+ template <typename T>
17
+ class CopyOnWrite final {
18
+ public:
19
+ template <typename... Args>
20
+ explicit CopyOnWrite(Args&&... args)
21
+ : data_(std::make_shared<T>(std::forward<Args>(args)...)) {}
22
+
23
+ CopyOnWrite(const CopyOnWrite<T>& other) = default;
24
+ CopyOnWrite& operator=(const CopyOnWrite<T>& other) = default;
25
+ CopyOnWrite(CopyOnWrite<T>&& other) = default;
26
+ CopyOnWrite& operator=(CopyOnWrite<T>&& other) = default;
27
+
28
+ const T* read() const { return data_.get(); }
29
+ T* write();
30
+
31
+ const T& operator*() const { return *read(); }
32
+ const T* operator->() const { return read(); }
33
+
34
+ private:
35
+ std::shared_ptr<T> data_;
36
+ };
37
+
38
+ // Threadsafe copy-on-write utility. Consumers need to use the Read and
39
+ // Write helpers to access the target data structure.
40
+ template <typename T>
41
+ class ThreadsafeCopyOnWrite final {
42
+ private:
43
+ // Define this early since some of the public members depend on it
44
+ // and some compilers need it to be defined first in that case.
45
+ struct Impl {
46
+ explicit Impl(const T& data) : data(data) {}
47
+ explicit Impl(T&& data) : data(std::move(data)) {}
48
+
49
+ Impl(const Impl& other);
50
+ Impl& operator=(const Impl& other) = delete;
51
+ Impl(Impl&& other) = delete;
52
+ Impl& operator=(Impl&& other) = delete;
53
+
54
+ RwLock mutex;
55
+ T data;
56
+ };
57
+
58
+ public:
59
+ template <typename... Args>
60
+ ThreadsafeCopyOnWrite(Args&&... args)
61
+ : impl_(T(std::forward<Args>(args)...)) {}
62
+
63
+ ThreadsafeCopyOnWrite(const ThreadsafeCopyOnWrite<T>& other) = default;
64
+ ThreadsafeCopyOnWrite& operator=(const ThreadsafeCopyOnWrite<T>& other) =
65
+ default;
66
+ ThreadsafeCopyOnWrite(ThreadsafeCopyOnWrite<T>&& other) = default;
67
+ ThreadsafeCopyOnWrite& operator=(ThreadsafeCopyOnWrite<T>&& other) = default;
68
+
69
+ class Read {
70
+ public:
71
+ explicit Read(const ThreadsafeCopyOnWrite<T>* cow);
72
+
73
+ const T& operator*() const;
74
+ const T* operator->() const;
75
+
76
+ private:
77
+ const ThreadsafeCopyOnWrite<T>* cow_;
78
+ RwLock::ScopedReadLock lock_;
79
+ };
80
+
81
+ class Write {
82
+ public:
83
+ explicit Write(ThreadsafeCopyOnWrite<T>* cow);
84
+
85
+ T& operator*();
86
+ T* operator->();
87
+
88
+ private:
89
+ ThreadsafeCopyOnWrite<T>* cow_;
90
+ typename ThreadsafeCopyOnWrite<T>::Impl* impl_;
91
+ RwLock::ScopedLock lock_;
92
+ };
93
+
94
+ Read read() const { return Read(this); }
95
+ Write write() { return Write(this); }
96
+
97
+ private:
98
+ CopyOnWrite<Impl> impl_;
99
+ };
100
+
101
+ } // namespace node
102
+
103
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
104
+
105
+ #endif // SRC_NODE_THREADSAFE_COW_H_
@@ -0,0 +1,81 @@
1
+
2
+ #ifndef SRC_NODE_UNION_BYTES_H_
3
+ #define SRC_NODE_UNION_BYTES_H_
4
+
5
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
6
+
7
+ #include "v8.h"
8
+
9
+ namespace node {
10
+
11
+ // An external resource intended to be used with static lifetime.
12
+ template <typename Char, typename IChar, typename Base>
13
+ class StaticExternalByteResource : public Base {
14
+ static_assert(sizeof(IChar) == sizeof(Char),
15
+ "incompatible interface and internal pointers");
16
+
17
+ public:
18
+ explicit StaticExternalByteResource(const Char* data,
19
+ size_t length,
20
+ std::shared_ptr<void> owning_ptr)
21
+ : data_(data), length_(length), owning_ptr_(owning_ptr) {}
22
+
23
+ const IChar* data() const override {
24
+ return reinterpret_cast<const IChar*>(data_);
25
+ }
26
+ size_t length() const override { return length_; }
27
+
28
+ void Dispose() override {
29
+ // We ignore Dispose calls from V8, even if we "own" a resource via
30
+ // owning_ptr_. All instantiations of this class are static or owned by a
31
+ // static map, and will be destructed when static variables are destructed.
32
+ }
33
+
34
+ StaticExternalByteResource(const StaticExternalByteResource&) = delete;
35
+ StaticExternalByteResource& operator=(const StaticExternalByteResource&) =
36
+ delete;
37
+
38
+ private:
39
+ const Char* data_;
40
+ const size_t length_;
41
+ std::shared_ptr<void> owning_ptr_;
42
+ };
43
+
44
+ using StaticExternalOneByteResource =
45
+ StaticExternalByteResource<uint8_t,
46
+ char,
47
+ v8::String::ExternalOneByteStringResource>;
48
+ using StaticExternalTwoByteResource =
49
+ StaticExternalByteResource<uint16_t,
50
+ uint16_t,
51
+ v8::String::ExternalStringResource>;
52
+
53
+ // Similar to a v8::String, but it's independent from Isolates
54
+ // and can be materialized in Isolates as external Strings
55
+ // via ToStringChecked.
56
+ class UnionBytes {
57
+ public:
58
+ explicit UnionBytes(StaticExternalOneByteResource* one_byte_resource)
59
+ : one_byte_resource_(one_byte_resource), two_byte_resource_(nullptr) {}
60
+ explicit UnionBytes(StaticExternalTwoByteResource* two_byte_resource)
61
+ : one_byte_resource_(nullptr), two_byte_resource_(two_byte_resource) {}
62
+
63
+ UnionBytes(const UnionBytes&) = default;
64
+ UnionBytes& operator=(const UnionBytes&) = default;
65
+ UnionBytes(UnionBytes&&) = default;
66
+ UnionBytes& operator=(UnionBytes&&) = default;
67
+
68
+ bool is_one_byte() const { return one_byte_resource_ != nullptr; }
69
+
70
+ v8::Local<v8::String> ToStringChecked(v8::Isolate* isolate) const;
71
+
72
+ private:
73
+ StaticExternalOneByteResource* one_byte_resource_;
74
+ StaticExternalTwoByteResource* two_byte_resource_;
75
+ };
76
+
77
+ } // namespace node
78
+
79
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
80
+
81
+ #endif // SRC_NODE_UNION_BYTES_H_
@@ -0,0 +1,101 @@
1
+ #ifndef SRC_NODE_URL_H_
2
+ #define SRC_NODE_URL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <cinttypes>
7
+ #include "ada.h"
8
+ #include "aliased_buffer.h"
9
+ #include "node.h"
10
+ #include "node_snapshotable.h"
11
+ #include "util.h"
12
+ #include "v8-fast-api-calls.h"
13
+ #include "v8.h"
14
+
15
+ #include <optional>
16
+ #include <string>
17
+
18
+ namespace node {
19
+ class ExternalReferenceRegistry;
20
+
21
+ namespace url {
22
+
23
+ enum url_update_action {
24
+ kProtocol = 0,
25
+ kHost = 1,
26
+ kHostname = 2,
27
+ kPort = 3,
28
+ kUsername = 4,
29
+ kPassword = 5,
30
+ kPathname = 6,
31
+ kSearch = 7,
32
+ kHash = 8,
33
+ kHref = 9,
34
+ };
35
+
36
+ class BindingData : public SnapshotableObject {
37
+ public:
38
+ BindingData(Realm* realm, v8::Local<v8::Object> obj);
39
+
40
+ using InternalFieldInfo = InternalFieldInfoBase;
41
+
42
+ SERIALIZABLE_OBJECT_METHODS()
43
+ SET_BINDING_ID(url_binding_data)
44
+
45
+ void MemoryInfo(MemoryTracker* tracker) const override;
46
+ SET_SELF_SIZE(BindingData)
47
+ SET_MEMORY_INFO_NAME(BindingData)
48
+
49
+ static void DomainToASCII(const v8::FunctionCallbackInfo<v8::Value>& args);
50
+ static void DomainToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args);
51
+
52
+ static void CanParse(const v8::FunctionCallbackInfo<v8::Value>& args);
53
+ static bool FastCanParse(v8::Local<v8::Value> receiver,
54
+ v8::Local<v8::Value> input,
55
+ // NOLINTNEXTLINE(runtime/references) This is V8 api.
56
+ v8::FastApiCallbackOptions& options);
57
+ static bool FastCanParseWithBase(
58
+ v8::Local<v8::Value> receiver,
59
+ v8::Local<v8::Value> input,
60
+ v8::Local<v8::Value> base,
61
+ // NOLINTNEXTLINE(runtime/references) This is V8 api.
62
+ v8::FastApiCallbackOptions& options);
63
+
64
+ static void Format(const v8::FunctionCallbackInfo<v8::Value>& args);
65
+ static void GetOrigin(const v8::FunctionCallbackInfo<v8::Value>& args);
66
+ static void Parse(const v8::FunctionCallbackInfo<v8::Value>& args);
67
+ static void PathToFileURL(const v8::FunctionCallbackInfo<v8::Value>& args);
68
+ static void Update(const v8::FunctionCallbackInfo<v8::Value>& args);
69
+
70
+ static void CreatePerIsolateProperties(IsolateData* isolate_data,
71
+ v8::Local<v8::ObjectTemplate> ctor);
72
+ static void CreatePerContextProperties(v8::Local<v8::Object> target,
73
+ v8::Local<v8::Value> unused,
74
+ v8::Local<v8::Context> context,
75
+ void* priv);
76
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
77
+
78
+ private:
79
+ static constexpr size_t kURLComponentsLength = 9;
80
+ AliasedUint32Array url_components_buffer_;
81
+
82
+ void UpdateComponents(const ada::url_components& components,
83
+ const ada::scheme::type type);
84
+
85
+ static v8::CFunction fast_can_parse_methods_[];
86
+ };
87
+
88
+ void ThrowInvalidURL(Environment* env,
89
+ std::string_view input,
90
+ std::optional<std::string> base);
91
+ std::string FromFilePath(std::string_view file_path);
92
+ std::optional<std::string> FileURLToPath(Environment* env,
93
+ const ada::url_aggregator& file_url);
94
+
95
+ } // namespace url
96
+
97
+ } // namespace node
98
+
99
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
100
+
101
+ #endif // SRC_NODE_URL_H_
@@ -0,0 +1,118 @@
1
+ #ifndef SRC_NODE_URL_PATTERN_H_
2
+ #define SRC_NODE_URL_PATTERN_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "ada.h"
7
+ #include "base_object.h"
8
+ #include "util.h"
9
+
10
+ #include <v8.h>
11
+
12
+ #include <optional>
13
+ #include <string_view>
14
+
15
+ namespace node::url_pattern {
16
+
17
+ #define URL_PATTERN_COMPONENTS(V) \
18
+ V(Protocol, protocol) \
19
+ V(Username, username) \
20
+ V(Password, password) \
21
+ V(Hostname, hostname) \
22
+ V(Port, port) \
23
+ V(Pathname, pathname) \
24
+ V(Search, search) \
25
+ V(Hash, hash)
26
+
27
+ // By default, ada::url_pattern doesn't ship with any regex library.
28
+ // Ada has a std::regex implementation, but it is considered unsafe and does
29
+ // not have a fully compliant ecmascript syntax support. Therefore, Ada
30
+ // supports passing custom regex provider that conforms to the following
31
+ // class and function structure. For more information, please look into
32
+ // url_pattern_regex.h inside github.com/ada-url/ada.
33
+ class URLPatternRegexProvider {
34
+ public:
35
+ using regex_type = v8::Global<v8::RegExp>;
36
+ static std::optional<regex_type> create_instance(std::string_view pattern,
37
+ bool ignore_case);
38
+ static std::optional<std::vector<std::optional<std::string>>> regex_search(
39
+ std::string_view input, const regex_type& pattern);
40
+ static bool regex_match(std::string_view input, const regex_type& pattern);
41
+ };
42
+
43
+ class URLPattern : public BaseObject {
44
+ public:
45
+ URLPattern(Environment* env,
46
+ v8::Local<v8::Object> object,
47
+ ada::url_pattern<URLPatternRegexProvider>&& url_pattern);
48
+
49
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
50
+
51
+ // V8 APIs
52
+ // - Functions
53
+ static void Exec(const v8::FunctionCallbackInfo<v8::Value>& info);
54
+ static void Test(const v8::FunctionCallbackInfo<v8::Value>& info);
55
+ // - Component Getters
56
+ #define URL_PATTERN_COMPONENT_GETTERS(name, _) \
57
+ static void name(const v8::FunctionCallbackInfo<v8::Value>& info);
58
+ URL_PATTERN_COMPONENTS(URL_PATTERN_COMPONENT_GETTERS)
59
+ #undef URL_PATTERN_COMPONENT_GETTERS
60
+ // - Has Regexp Groups
61
+ static void HasRegexpGroups(const v8::FunctionCallbackInfo<v8::Value>& info);
62
+
63
+ void MemoryInfo(MemoryTracker* tracker) const override;
64
+ SET_MEMORY_INFO_NAME(URLPattern)
65
+ SET_SELF_SIZE(URLPattern)
66
+
67
+ class URLPatternInit {
68
+ public:
69
+ static std::optional<ada::url_pattern_init> FromJsObject(
70
+ Environment* env, v8::Local<v8::Object> obj);
71
+ static v8::MaybeLocal<v8::Value> ToJsObject(
72
+ Environment* env, const ada::url_pattern_init& init);
73
+ };
74
+
75
+ class URLPatternOptions {
76
+ public:
77
+ static std::optional<ada::url_pattern_options> FromJsObject(
78
+ Environment* env, v8::Local<v8::Object> obj);
79
+ };
80
+
81
+ class URLPatternResult {
82
+ public:
83
+ static v8::MaybeLocal<v8::Value> ToJSValue(
84
+ Environment* env, const ada::url_pattern_result& result);
85
+ };
86
+
87
+ class URLPatternComponentResult {
88
+ public:
89
+ static v8::MaybeLocal<v8::Object> ToJSObject(
90
+ Environment* env, const ada::url_pattern_component_result& result);
91
+ };
92
+
93
+ private:
94
+ ada::url_pattern<URLPatternRegexProvider> url_pattern_;
95
+ // Getter methods
96
+ #define URL_PATTERN_COMPONENT_GETTERS(name, _) v8::MaybeLocal<v8::Value> name();
97
+ URL_PATTERN_COMPONENTS(URL_PATTERN_COMPONENT_GETTERS)
98
+ #undef URL_PATTERN_COMPONENT_GETTERS
99
+ bool HasRegExpGroups() const;
100
+ // Public API
101
+ v8::MaybeLocal<v8::Value> Exec(
102
+ Environment* env,
103
+ const ada::url_pattern_input& input,
104
+ std::optional<std::string_view>& baseURL); // NOLINT (runtime/references)
105
+ bool Test(
106
+ Environment* env,
107
+ const ada::url_pattern_input& input,
108
+ std::optional<std::string_view>& baseURL); // NOLINT (runtime/references)
109
+
110
+ #define URL_PATTERN_CACHED_VALUES(_, name) v8::Global<v8::Value> name;
111
+ URL_PATTERN_COMPONENTS(URL_PATTERN_CACHED_VALUES)
112
+ #undef URL_PATTERN_CACHED_VALUES
113
+ };
114
+
115
+ } // namespace node::url_pattern
116
+
117
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
118
+ #endif // SRC_NODE_URL_PATTERN_H_
@@ -0,0 +1,78 @@
1
+ #ifndef SRC_NODE_V8_H_
2
+ #define SRC_NODE_V8_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <sstream>
7
+ #include "aliased_buffer.h"
8
+ #include "base_object.h"
9
+ #include "json_utils.h"
10
+ #include "node_errors.h"
11
+ #include "node_snapshotable.h"
12
+ #include "util.h"
13
+ #include "v8.h"
14
+
15
+ namespace node {
16
+ class Environment;
17
+ struct InternalFieldInfoBase;
18
+
19
+ namespace v8_utils {
20
+ class BindingData : public SnapshotableObject {
21
+ public:
22
+ struct InternalFieldInfo : public node::InternalFieldInfoBase {
23
+ AliasedBufferIndex heap_statistics_buffer;
24
+ AliasedBufferIndex heap_space_statistics_buffer;
25
+ AliasedBufferIndex heap_code_statistics_buffer;
26
+ };
27
+ BindingData(Realm* realm,
28
+ v8::Local<v8::Object> obj,
29
+ InternalFieldInfo* info = nullptr);
30
+
31
+ SERIALIZABLE_OBJECT_METHODS()
32
+ SET_BINDING_ID(v8_binding_data)
33
+
34
+ AliasedFloat64Array heap_statistics_buffer;
35
+ AliasedFloat64Array heap_space_statistics_buffer;
36
+ AliasedFloat64Array heap_code_statistics_buffer;
37
+
38
+ void MemoryInfo(MemoryTracker* tracker) const override;
39
+ SET_SELF_SIZE(BindingData)
40
+ SET_MEMORY_INFO_NAME(BindingData)
41
+
42
+ private:
43
+ InternalFieldInfo* internal_field_info_ = nullptr;
44
+ };
45
+
46
+ class GCProfiler : public BaseObject {
47
+ public:
48
+ enum class GCProfilerState { kInitialized, kStarted, kStopped };
49
+ GCProfiler(Environment* env, v8::Local<v8::Object> object);
50
+ inline ~GCProfiler() override;
51
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
52
+ static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
53
+ static void Stop(const v8::FunctionCallbackInfo<v8::Value>& args);
54
+
55
+ JSONWriter* writer();
56
+
57
+ std::ostringstream* out_stream();
58
+
59
+ SET_NO_MEMORY_INFO()
60
+ SET_MEMORY_INFO_NAME(GCProfiler)
61
+ SET_SELF_SIZE(GCProfiler)
62
+
63
+ uint64_t start_time;
64
+ uint8_t current_gc_type;
65
+ GCProfilerState state;
66
+
67
+ private:
68
+ std::ostringstream out_stream_;
69
+ JSONWriter writer_;
70
+ };
71
+
72
+ } // namespace v8_utils
73
+
74
+ } // namespace node
75
+
76
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
77
+
78
+ #endif // SRC_NODE_V8_H_
@@ -0,0 +1,26 @@
1
+ #ifndef SRC_NODE_V8_EMBEDDER_H_
2
+ #define SRC_NODE_V8_EMBEDDER_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <cstdint>
7
+
8
+ namespace node {
9
+
10
+ // Type tags for different kinds of embedder data stored in V8 aligned pointer
11
+ // slots.
12
+ enum EmbedderDataTag : uint16_t {
13
+ // kDefault is used in slots that don't use V8 type tagging.
14
+ kDefault = 0,
15
+ // kEmbedderType is used by BaseObject to store the kEmbedderType value.
16
+ kEmbedderType,
17
+ // kPerContextData is used to store data on a `v8::Context`, including
18
+ // slots indexed by ContextEmbedderIndex.
19
+ kPerContextData,
20
+ };
21
+
22
+ } // namespace node
23
+
24
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
25
+
26
+ #endif // SRC_NODE_V8_EMBEDDER_H_