@encharm/cws 4.5.2 → 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 (284) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/CLAUDE.md +81 -0
  3. package/README.md +10 -5
  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/24/tracing/agent.h +195 -0
  30. package/src/headers/24/tracing/trace_event.h +722 -0
  31. package/src/headers/26/acorn_version.h +6 -0
  32. package/src/headers/26/aliased_buffer-inl.h +264 -0
  33. package/src/headers/26/aliased_buffer.h +205 -0
  34. package/src/headers/26/aliased_struct-inl.h +143 -0
  35. package/src/headers/26/aliased_struct.h +248 -0
  36. package/src/headers/26/amaro_version.h +6 -0
  37. package/src/headers/26/async_context_frame.h +33 -0
  38. package/src/headers/26/async_wrap-inl.h +123 -0
  39. package/src/headers/26/async_wrap.h +254 -0
  40. package/src/headers/26/base_object-inl.h +333 -0
  41. package/src/headers/26/base_object.h +339 -0
  42. package/src/headers/26/base_object_types.h +76 -0
  43. package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
  44. package/src/headers/26/blob_serializer_deserializer.h +142 -0
  45. package/src/headers/26/builtin_info.h +57 -0
  46. package/src/headers/26/callback_queue-inl.h +97 -0
  47. package/src/headers/26/callback_queue.h +79 -0
  48. package/src/headers/26/cares_wrap.h +475 -0
  49. package/src/headers/26/cleanup_queue-inl.h +36 -0
  50. package/src/headers/26/cleanup_queue.h +79 -0
  51. package/src/headers/26/compile_cache.h +134 -0
  52. package/src/headers/26/connect_wrap.h +26 -0
  53. package/src/headers/26/connection_wrap.h +30 -0
  54. package/src/headers/26/cppgc_helpers-inl.h +69 -0
  55. package/src/headers/26/cppgc_helpers.h +162 -0
  56. package/src/headers/26/crypto/crypto_aes.h +107 -0
  57. package/src/headers/26/crypto/crypto_argon2.h +88 -0
  58. package/src/headers/26/crypto/crypto_bio.h +193 -0
  59. package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
  60. package/src/headers/26/crypto/crypto_cipher.h +291 -0
  61. package/src/headers/26/crypto/crypto_common.h +48 -0
  62. package/src/headers/26/crypto/crypto_context.h +219 -0
  63. package/src/headers/26/crypto/crypto_dh.h +104 -0
  64. package/src/headers/26/crypto/crypto_dsa.h +50 -0
  65. package/src/headers/26/crypto/crypto_ec.h +102 -0
  66. package/src/headers/26/crypto/crypto_hash.h +157 -0
  67. package/src/headers/26/crypto/crypto_hkdf.h +62 -0
  68. package/src/headers/26/crypto/crypto_hmac.h +92 -0
  69. package/src/headers/26/crypto/crypto_kem.h +131 -0
  70. package/src/headers/26/crypto/crypto_keygen.h +382 -0
  71. package/src/headers/26/crypto/crypto_keys.h +366 -0
  72. package/src/headers/26/crypto/crypto_kmac.h +79 -0
  73. package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
  74. package/src/headers/26/crypto/crypto_pqc.h +39 -0
  75. package/src/headers/26/crypto/crypto_random.h +127 -0
  76. package/src/headers/26/crypto/crypto_rsa.h +108 -0
  77. package/src/headers/26/crypto/crypto_scrypt.h +85 -0
  78. package/src/headers/26/crypto/crypto_sig.h +159 -0
  79. package/src/headers/26/crypto/crypto_spkac.h +21 -0
  80. package/src/headers/26/crypto/crypto_timing.h +20 -0
  81. package/src/headers/26/crypto/crypto_tls.h +342 -0
  82. package/src/headers/26/crypto/crypto_turboshake.h +105 -0
  83. package/src/headers/26/crypto/crypto_util.h +775 -0
  84. package/src/headers/26/crypto/crypto_x509.h +140 -0
  85. package/src/headers/26/dataqueue/queue.h +311 -0
  86. package/src/headers/26/debug_utils-inl.h +291 -0
  87. package/src/headers/26/debug_utils.h +200 -0
  88. package/src/headers/26/diagnosticfilename-inl.h +33 -0
  89. package/src/headers/26/embedded_data.h +17 -0
  90. package/src/headers/26/encoding_binding.h +59 -0
  91. package/src/headers/26/env-inl.h +956 -0
  92. package/src/headers/26/env.h +1294 -0
  93. package/src/headers/26/env_properties.h +562 -0
  94. package/src/headers/26/ffi/data.h +30 -0
  95. package/src/headers/26/ffi/fast.h +96 -0
  96. package/src/headers/26/ffi/jit_memory.h +26 -0
  97. package/src/headers/26/ffi/types.h +99 -0
  98. package/src/headers/26/handle_wrap.h +123 -0
  99. package/src/headers/26/histogram-inl.h +211 -0
  100. package/src/headers/26/histogram.h +474 -0
  101. package/src/headers/26/inspector/dom_storage_agent.h +68 -0
  102. package/src/headers/26/inspector/inspector_object_utils.h +38 -0
  103. package/src/headers/26/inspector/io_agent.h +30 -0
  104. package/src/headers/26/inspector/main_thread_interface.h +116 -0
  105. package/src/headers/26/inspector/network_agent.h +110 -0
  106. package/src/headers/26/inspector/network_inspector.h +45 -0
  107. package/src/headers/26/inspector/network_requests_buffer.h +195 -0
  108. package/src/headers/26/inspector/network_resource_manager.h +29 -0
  109. package/src/headers/26/inspector/node_json.h +24 -0
  110. package/src/headers/26/inspector/node_string.h +101 -0
  111. package/src/headers/26/inspector/notification_emitter.h +38 -0
  112. package/src/headers/26/inspector/protocol_helper.h +27 -0
  113. package/src/headers/26/inspector/runtime_agent.h +41 -0
  114. package/src/headers/26/inspector/storage_agent.h +33 -0
  115. package/src/headers/26/inspector/target_agent.h +59 -0
  116. package/src/headers/26/inspector/target_manager.h +70 -0
  117. package/src/headers/26/inspector/tracing_agent.h +43 -0
  118. package/src/headers/26/inspector/worker_agent.h +40 -0
  119. package/src/headers/26/inspector/worker_inspector.h +124 -0
  120. package/src/headers/26/inspector_agent.h +168 -0
  121. package/src/headers/26/inspector_io.h +78 -0
  122. package/src/headers/26/inspector_profiler.h +149 -0
  123. package/src/headers/26/inspector_socket.h +60 -0
  124. package/src/headers/26/inspector_socket_server.h +110 -0
  125. package/src/headers/26/js_native_api.h +634 -0
  126. package/src/headers/26/js_native_api_types.h +244 -0
  127. package/src/headers/26/js_native_api_v8.h +485 -0
  128. package/src/headers/26/js_native_api_v8_internals.h +45 -0
  129. package/src/headers/26/js_stream.h +57 -0
  130. package/src/headers/26/json_utils.h +172 -0
  131. package/src/headers/26/large_pages/node_large_page.h +34 -0
  132. package/src/headers/26/lru_cache-inl.h +69 -0
  133. package/src/headers/26/memory_tracker-inl.h +461 -0
  134. package/src/headers/26/memory_tracker.h +341 -0
  135. package/src/headers/26/module_wrap.h +231 -0
  136. package/src/headers/26/ncrypto.h +2008 -0
  137. package/src/headers/26/node.h +1693 -0
  138. package/src/headers/26/node_api.h +265 -0
  139. package/src/headers/26/node_api_internals.h +48 -0
  140. package/src/headers/26/node_api_types.h +58 -0
  141. package/src/headers/26/node_binding.h +170 -0
  142. package/src/headers/26/node_blob.h +160 -0
  143. package/src/headers/26/node_bob-inl.h +36 -0
  144. package/src/headers/26/node_bob.h +107 -0
  145. package/src/headers/26/node_buffer.h +92 -0
  146. package/src/headers/26/node_builtins.h +239 -0
  147. package/src/headers/26/node_concepts.h +46 -0
  148. package/src/headers/26/node_config_file.h +77 -0
  149. package/src/headers/26/node_constants.h +82 -0
  150. package/src/headers/26/node_context_data.h +171 -0
  151. package/src/headers/26/node_contextify.h +261 -0
  152. package/src/headers/26/node_crypto.h +66 -0
  153. package/src/headers/26/node_debug.h +30 -0
  154. package/src/headers/26/node_diagnostics_channel.h +121 -0
  155. package/src/headers/26/node_dir.h +52 -0
  156. package/src/headers/26/node_dotenv.h +45 -0
  157. package/src/headers/26/node_errors.h +378 -0
  158. package/src/headers/26/node_exit_code.h +54 -0
  159. package/src/headers/26/node_external_reference.h +171 -0
  160. package/src/headers/26/node_ffi.h +212 -0
  161. package/src/headers/26/node_file-inl.h +421 -0
  162. package/src/headers/26/node_file.h +561 -0
  163. package/src/headers/26/node_file_utils.h +39 -0
  164. package/src/headers/26/node_hash.h +212 -0
  165. package/src/headers/26/node_http2.h +1202 -0
  166. package/src/headers/26/node_http2_state.h +159 -0
  167. package/src/headers/26/node_http_common-inl.h +199 -0
  168. package/src/headers/26/node_http_common.h +535 -0
  169. package/src/headers/26/node_i18n.h +132 -0
  170. package/src/headers/26/node_internals.h +485 -0
  171. package/src/headers/26/node_locks.h +184 -0
  172. package/src/headers/26/node_main_instance.h +67 -0
  173. package/src/headers/26/node_mem-inl.h +113 -0
  174. package/src/headers/26/node_mem.h +45 -0
  175. package/src/headers/26/node_messaging.h +389 -0
  176. package/src/headers/26/node_metadata.h +172 -0
  177. package/src/headers/26/node_modules.h +102 -0
  178. package/src/headers/26/node_mutex.h +323 -0
  179. package/src/headers/26/node_object_wrap.h +145 -0
  180. package/src/headers/26/node_options-inl.h +524 -0
  181. package/src/headers/26/node_options.h +710 -0
  182. package/src/headers/26/node_perf.h +167 -0
  183. package/src/headers/26/node_perf_common.h +103 -0
  184. package/src/headers/26/node_platform.h +290 -0
  185. package/src/headers/26/node_process-inl.h +26 -0
  186. package/src/headers/26/node_process.h +112 -0
  187. package/src/headers/26/node_profiling.h +38 -0
  188. package/src/headers/26/node_realm-inl.h +156 -0
  189. package/src/headers/26/node_realm.h +236 -0
  190. package/src/headers/26/node_report.h +43 -0
  191. package/src/headers/26/node_revert.h +82 -0
  192. package/src/headers/26/node_root_certs.h +2937 -0
  193. package/src/headers/26/node_sea.h +101 -0
  194. package/src/headers/26/node_shadow_realm.h +46 -0
  195. package/src/headers/26/node_snapshot_builder.h +57 -0
  196. package/src/headers/26/node_snapshotable.h +167 -0
  197. package/src/headers/26/node_sockaddr-inl.h +248 -0
  198. package/src/headers/26/node_sockaddr.h +459 -0
  199. package/src/headers/26/node_sqlite.h +607 -0
  200. package/src/headers/26/node_stat_watcher.h +73 -0
  201. package/src/headers/26/node_task_runner.h +92 -0
  202. package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
  203. package/src/headers/26/node_threadsafe_cow.h +105 -0
  204. package/src/headers/26/node_union_bytes.h +81 -0
  205. package/src/headers/26/node_url.h +101 -0
  206. package/src/headers/26/node_url_pattern.h +118 -0
  207. package/src/headers/26/node_v8.h +78 -0
  208. package/src/headers/26/node_v8_embedder.h +26 -0
  209. package/src/headers/26/node_v8_platform-inl.h +96 -0
  210. package/src/headers/26/node_version.h +116 -0
  211. package/src/headers/26/node_wasi.h +184 -0
  212. package/src/headers/26/node_wasm_web_api.h +55 -0
  213. package/src/headers/26/node_watchdog.h +164 -0
  214. package/src/headers/26/node_webstorage.h +62 -0
  215. package/src/headers/26/node_worker.h +162 -0
  216. package/src/headers/26/path.h +36 -0
  217. package/src/headers/26/permission/boolean_permission.h +50 -0
  218. package/src/headers/26/permission/fs_permission.h +192 -0
  219. package/src/headers/26/permission/permission.h +155 -0
  220. package/src/headers/26/permission/permission_base.h +79 -0
  221. package/src/headers/26/pipe_wrap.h +80 -0
  222. package/src/headers/26/quic/application.h +279 -0
  223. package/src/headers/26/quic/arena.h +373 -0
  224. package/src/headers/26/quic/bindingdata.h +440 -0
  225. package/src/headers/26/quic/cid.h +127 -0
  226. package/src/headers/26/quic/data.h +358 -0
  227. package/src/headers/26/quic/defs.h +417 -0
  228. package/src/headers/26/quic/endpoint.h +519 -0
  229. package/src/headers/26/quic/guard.h +5 -0
  230. package/src/headers/26/quic/http3.h +25 -0
  231. package/src/headers/26/quic/packet.h +166 -0
  232. package/src/headers/26/quic/preferredaddress.h +72 -0
  233. package/src/headers/26/quic/session.h +770 -0
  234. package/src/headers/26/quic/session_manager.h +107 -0
  235. package/src/headers/26/quic/sessionticket.h +110 -0
  236. package/src/headers/26/quic/streams.h +518 -0
  237. package/src/headers/26/quic/tlscontext.h +353 -0
  238. package/src/headers/26/quic/tokens.h +263 -0
  239. package/src/headers/26/quic/transportparams.h +184 -0
  240. package/src/headers/26/req_wrap-inl.h +175 -0
  241. package/src/headers/26/req_wrap.h +79 -0
  242. package/src/headers/26/spawn_sync.h +243 -0
  243. package/src/headers/26/stream_base-inl.h +170 -0
  244. package/src/headers/26/stream_base.h +487 -0
  245. package/src/headers/26/stream_pipe.h +76 -0
  246. package/src/headers/26/stream_wrap.h +137 -0
  247. package/src/headers/26/string_bytes.h +114 -0
  248. package/src/headers/26/string_decoder-inl.h +31 -0
  249. package/src/headers/26/string_decoder.h +49 -0
  250. package/src/headers/26/tcp_wrap.h +138 -0
  251. package/src/headers/26/threadpoolwork-inl.h +70 -0
  252. package/src/headers/26/timer_wrap-inl.h +32 -0
  253. package/src/headers/26/timer_wrap.h +87 -0
  254. package/src/headers/26/timers.h +70 -0
  255. package/src/headers/26/tracing/agent.h +125 -0
  256. package/src/headers/26/tracing/agent_legacy.h +146 -0
  257. package/src/headers/26/tracing/agent_perfetto.h +145 -0
  258. package/src/headers/26/tracing/node_trace_buffer.h +91 -0
  259. package/src/headers/26/tracing/node_trace_writer.h +79 -0
  260. package/src/headers/26/tracing/trace_event.h +27 -0
  261. package/src/headers/26/tracing/trace_event_helper.h +40 -0
  262. package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
  263. package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
  264. package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
  265. package/src/headers/26/tracing/traced_value.h +167 -0
  266. package/src/headers/26/tty_wrap.h +65 -0
  267. package/src/headers/26/udp_wrap.h +231 -0
  268. package/src/headers/26/undici_version.h +6 -0
  269. package/src/headers/26/util-inl.h +788 -0
  270. package/src/headers/26/util.h +1207 -0
  271. package/src/headers/26/v8-cpp-heap-external.h +56 -0
  272. package/src/headers/26/v8-external-memory-accounter.h +60 -0
  273. package/src/headers/26/v8-fast-api-calls.h +784 -0
  274. package/src/headers/26/v8-inspector-protocol.h +13 -0
  275. package/src/headers/26/v8-inspector.h +458 -0
  276. package/src/headers/26/v8-metrics.h +273 -0
  277. package/src/headers/26/v8-trace-categories.h +28 -0
  278. package/src/headers/26/v8-unwinder-state.h +30 -0
  279. package/src/headers/26/v8-util.h +549 -0
  280. package/src/headers/26/v8-value-serializer-version.h +24 -0
  281. package/src/headers/26/v8-version-string.h +38 -0
  282. package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
  283. package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
  284. package/src/headers/26/zlib_version.h +6 -0
@@ -0,0 +1,41 @@
1
+ #ifndef SRC_INSPECTOR_RUNTIME_AGENT_H_
2
+ #define SRC_INSPECTOR_RUNTIME_AGENT_H_
3
+
4
+ #include "node/inspector/protocol/NodeRuntime.h"
5
+ #include "v8.h"
6
+
7
+ namespace node {
8
+ class Environment;
9
+
10
+ namespace inspector {
11
+ namespace protocol {
12
+
13
+ class RuntimeAgent : public NodeRuntime::Backend {
14
+ public:
15
+ RuntimeAgent();
16
+
17
+ void Wire(UberDispatcher* dispatcher);
18
+
19
+ DispatchResponse notifyWhenWaitingForDisconnect(bool enabled) override;
20
+
21
+ DispatchResponse enable() override;
22
+
23
+ DispatchResponse disable() override;
24
+
25
+ bool notifyWaitingForDisconnect();
26
+
27
+ void setWaitingForDebugger();
28
+
29
+ void unsetWaitingForDebugger();
30
+
31
+ private:
32
+ std::shared_ptr<NodeRuntime::Frontend> frontend_;
33
+ bool notify_when_waiting_for_disconnect_;
34
+ bool enabled_;
35
+ bool is_waiting_for_debugger_;
36
+ };
37
+ } // namespace protocol
38
+ } // namespace inspector
39
+ } // namespace node
40
+
41
+ #endif // SRC_INSPECTOR_RUNTIME_AGENT_H_
@@ -0,0 +1,33 @@
1
+ #ifndef SRC_INSPECTOR_STORAGE_AGENT_H_
2
+ #define SRC_INSPECTOR_STORAGE_AGENT_H_
3
+
4
+ #include "env.h"
5
+ #include "node/inspector/protocol/Storage.h"
6
+
7
+ namespace node {
8
+ namespace inspector {
9
+ namespace protocol {
10
+
11
+ class StorageAgent : public protocol::Storage::Backend {
12
+ public:
13
+ explicit StorageAgent(Environment* env);
14
+ ~StorageAgent() override;
15
+
16
+ void Wire(protocol::UberDispatcher* dispatcher);
17
+
18
+ DispatchResponse getStorageKey(std::optional<protocol::String> frameId,
19
+ protocol::String* storageKey) override;
20
+
21
+ StorageAgent(const StorageAgent&) = delete;
22
+ StorageAgent& operator=(const StorageAgent&) = delete;
23
+
24
+ private:
25
+ std::string to_absolute_path(const std::filesystem::path& input);
26
+ std::unique_ptr<protocol::Storage::Frontend> frontend_;
27
+ Environment* env_;
28
+ };
29
+ } // namespace protocol
30
+ } // namespace inspector
31
+ } // namespace node
32
+
33
+ #endif // SRC_INSPECTOR_STORAGE_AGENT_H_
@@ -0,0 +1,59 @@
1
+ #ifndef SRC_INSPECTOR_TARGET_AGENT_H_
2
+ #define SRC_INSPECTOR_TARGET_AGENT_H_
3
+
4
+ #include <memory>
5
+ #include <string_view>
6
+ #include "inspector/target_manager.h"
7
+ #include "inspector/worker_inspector.h"
8
+ #include "node/inspector/protocol/Target.h"
9
+
10
+ namespace node {
11
+
12
+ namespace inspector {
13
+ class TargetInspector;
14
+
15
+ namespace protocol {
16
+
17
+ class TargetAgent : public Target::Backend,
18
+ public std::enable_shared_from_this<TargetAgent> {
19
+ public:
20
+ void Wire(UberDispatcher* dispatcher);
21
+
22
+ void createAndAttachIfNecessary(std::shared_ptr<MainThreadHandle> worker,
23
+ const std::string& title,
24
+ const std::string& url);
25
+
26
+ DispatchResponse getTargets(
27
+ std::unique_ptr<protocol::Array<Target::TargetInfo>>* out_targetInfos)
28
+ override;
29
+ DispatchResponse setAutoAttach(bool auto_attach,
30
+ bool wait_for_debugger_on_start) override;
31
+
32
+ void listenWorker(std::weak_ptr<WorkerManager> worker_manager);
33
+ void reset();
34
+
35
+ private:
36
+ int getNextTargetId();
37
+ int getNextSessionId();
38
+ void targetCreated(const std::string_view target_id,
39
+ const std::string_view type,
40
+ const std::string_view title,
41
+ const std::string_view url);
42
+ void attachedToTarget(std::shared_ptr<MainThreadHandle> worker,
43
+ const std::string& target_id,
44
+ const std::string& type,
45
+ const std::string& title,
46
+ const std::string& url);
47
+
48
+ std::shared_ptr<Target::Frontend> frontend_;
49
+ std::weak_ptr<WorkerManager> worker_manager_;
50
+ std::unique_ptr<WorkerManagerEventHandle> worker_event_handle_ = nullptr;
51
+ std::unique_ptr<TargetManager> target_manager_ =
52
+ std::make_unique<TargetManager>();
53
+ };
54
+
55
+ } // namespace protocol
56
+ } // namespace inspector
57
+ } // namespace node
58
+
59
+ #endif // SRC_INSPECTOR_TARGET_AGENT_H_
@@ -0,0 +1,70 @@
1
+ #ifndef SRC_INSPECTOR_TARGET_MANAGER_H_
2
+ #define SRC_INSPECTOR_TARGET_MANAGER_H_
3
+
4
+ #include <memory>
5
+ #include <string>
6
+ #include <unordered_map>
7
+ #include <vector>
8
+
9
+ #include "node_mutex.h"
10
+
11
+ namespace node {
12
+ namespace inspector {
13
+
14
+ class MainThreadHandle;
15
+
16
+ class TargetManager {
17
+ public:
18
+ struct TargetInfo {
19
+ std::string target_id;
20
+ std::string type;
21
+ std::string title;
22
+ std::string url;
23
+ std::shared_ptr<MainThreadHandle> worker;
24
+ bool attached;
25
+ };
26
+
27
+ TargetManager() = default;
28
+
29
+ int NextTargetId();
30
+ int NextSessionId();
31
+
32
+ void SetAutoAttach(bool auto_attach, bool wait_for_debugger_on_start);
33
+ bool auto_attach() const { return auto_attach_; }
34
+ bool wait_for_debugger_on_start() const {
35
+ return wait_for_debugger_on_start_;
36
+ }
37
+
38
+ void AddTarget(std::shared_ptr<MainThreadHandle> worker,
39
+ const std::string& target_id,
40
+ const std::string& type,
41
+ const std::string& title,
42
+ const std::string& url,
43
+ bool attached);
44
+ std::vector<TargetInfo> GetTargetsSnapshot() const;
45
+ std::vector<TargetInfo>& targets() { return targets_; }
46
+ const std::vector<TargetInfo>& targets() const { return targets_; }
47
+
48
+ static void RegisterSessionWorker(int session_id,
49
+ std::shared_ptr<MainThreadHandle> worker);
50
+ static std::shared_ptr<MainThreadHandle> WorkerForSession(int session_id);
51
+
52
+ private:
53
+ static Mutex session_state_lock_;
54
+ static std::unordered_map<int, std::shared_ptr<MainThreadHandle>>
55
+ session_worker_map_;
56
+ static int next_session_id_;
57
+
58
+ int next_target_id_ = 1;
59
+ bool auto_attach_ = false;
60
+ // TODO(islandryu): Honor this flag for worker targets. It is stored here
61
+ // so Target.setAutoAttach() state can be tracked, but worker startup pause
62
+ // behavior does not change based on it yet.
63
+ bool wait_for_debugger_on_start_ = true;
64
+ std::vector<TargetInfo> targets_;
65
+ };
66
+
67
+ } // namespace inspector
68
+ } // namespace node
69
+
70
+ #endif // SRC_INSPECTOR_TARGET_MANAGER_H_
@@ -0,0 +1,43 @@
1
+ #ifndef SRC_INSPECTOR_TRACING_AGENT_H_
2
+ #define SRC_INSPECTOR_TRACING_AGENT_H_
3
+
4
+ #include "node/inspector/protocol/NodeTracing.h"
5
+ #include "tracing/agent.h"
6
+ #include "v8.h"
7
+
8
+
9
+ namespace node {
10
+ class Environment;
11
+
12
+ namespace inspector {
13
+ class MainThreadHandle;
14
+
15
+ namespace protocol {
16
+
17
+ class TracingAgent : public NodeTracing::Backend {
18
+ public:
19
+ explicit TracingAgent(Environment*, std::shared_ptr<MainThreadHandle>);
20
+ ~TracingAgent() override;
21
+
22
+ void Wire(UberDispatcher* dispatcher);
23
+
24
+ DispatchResponse start(
25
+ std::unique_ptr<protocol::NodeTracing::TraceConfig> traceConfig) override;
26
+ DispatchResponse stop() override;
27
+ DispatchResponse getCategories(
28
+ std::unique_ptr<protocol::Array<String>>* categories) override;
29
+
30
+ private:
31
+ Environment* env_;
32
+ std::shared_ptr<MainThreadHandle> main_thread_;
33
+ tracing::AgentWriterHandle trace_writer_;
34
+ int frontend_object_id_ = 0;
35
+ std::shared_ptr<NodeTracing::Frontend> frontend_;
36
+ };
37
+
38
+
39
+ } // namespace protocol
40
+ } // namespace inspector
41
+ } // namespace node
42
+
43
+ #endif // SRC_INSPECTOR_TRACING_AGENT_H_
@@ -0,0 +1,40 @@
1
+ #ifndef SRC_INSPECTOR_WORKER_AGENT_H_
2
+ #define SRC_INSPECTOR_WORKER_AGENT_H_
3
+
4
+ #include "node/inspector/protocol/NodeWorker.h"
5
+ #include "v8.h"
6
+
7
+
8
+ namespace node {
9
+ namespace inspector {
10
+ class WorkerManagerEventHandle;
11
+ class WorkerManager;
12
+
13
+ namespace protocol {
14
+ class NodeWorkers;
15
+
16
+ class WorkerAgent : public NodeWorker::Backend {
17
+ public:
18
+ explicit WorkerAgent(std::weak_ptr<WorkerManager> manager);
19
+ ~WorkerAgent() override = default;
20
+
21
+ void Wire(UberDispatcher* dispatcher);
22
+
23
+ DispatchResponse sendMessageToWorker(const String& message,
24
+ const String& sessionId) override;
25
+
26
+ DispatchResponse enable(bool waitForDebuggerOnStart) override;
27
+ DispatchResponse disable() override;
28
+ DispatchResponse detach(const String& sessionId) override;
29
+
30
+ private:
31
+ std::shared_ptr<NodeWorker::Frontend> frontend_;
32
+ std::weak_ptr<WorkerManager> manager_;
33
+ std::unique_ptr<WorkerManagerEventHandle> event_handle_;
34
+ std::shared_ptr<NodeWorkers> workers_;
35
+ };
36
+ } // namespace protocol
37
+ } // namespace inspector
38
+ } // namespace node
39
+
40
+ #endif // SRC_INSPECTOR_WORKER_AGENT_H_
@@ -0,0 +1,124 @@
1
+ #ifndef SRC_INSPECTOR_WORKER_INSPECTOR_H_
2
+ #define SRC_INSPECTOR_WORKER_INSPECTOR_H_
3
+
4
+ #include "inspector/network_resource_manager.h"
5
+ #if !HAVE_INSPECTOR
6
+ #error("This header can only be used when inspector is enabled")
7
+ #endif
8
+
9
+ #include <cstdint>
10
+ #include <memory>
11
+ #include <string>
12
+ #include <unordered_map>
13
+ #include <unordered_set>
14
+
15
+ namespace node {
16
+ namespace inspector {
17
+ class InspectorSession;
18
+ class InspectorSessionDelegate;
19
+ class MainThreadHandle;
20
+ class WorkerManager;
21
+
22
+ class WorkerDelegate {
23
+ public:
24
+ virtual void WorkerCreated(const std::string& title,
25
+ const std::string& url,
26
+ bool waiting,
27
+ std::shared_ptr<MainThreadHandle> worker) = 0;
28
+ virtual ~WorkerDelegate() = default;
29
+ };
30
+
31
+ class WorkerManagerEventHandle {
32
+ public:
33
+ explicit WorkerManagerEventHandle(std::shared_ptr<WorkerManager> manager,
34
+ int id)
35
+ : manager_(manager), id_(id) {}
36
+ void SetWaitOnStart(bool wait_on_start);
37
+ ~WorkerManagerEventHandle();
38
+
39
+ private:
40
+ std::shared_ptr<WorkerManager> manager_;
41
+ int id_;
42
+ };
43
+
44
+ struct WorkerInfo {
45
+ WorkerInfo(const std::string& target_title,
46
+ const std::string& target_url,
47
+ std::shared_ptr<MainThreadHandle> worker_thread)
48
+ : title(target_title),
49
+ url(target_url),
50
+ worker_thread(worker_thread) {}
51
+ std::string title;
52
+ std::string url;
53
+ std::shared_ptr<MainThreadHandle> worker_thread;
54
+ };
55
+
56
+ class ParentInspectorHandle {
57
+ public:
58
+ ParentInspectorHandle(
59
+ uint64_t id,
60
+ std::string_view url,
61
+ std::shared_ptr<MainThreadHandle> parent_thread,
62
+ bool wait_for_connect,
63
+ std::string_view name,
64
+ std::shared_ptr<NetworkResourceManager> network_resource_manager);
65
+ ~ParentInspectorHandle();
66
+ std::unique_ptr<ParentInspectorHandle> NewParentInspectorHandle(
67
+ uint64_t thread_id, std::string_view url, std::string_view name) {
68
+ return std::make_unique<ParentInspectorHandle>(
69
+ thread_id, url, parent_thread_, wait_, name, network_resource_manager_);
70
+ }
71
+ void WorkerStarted(std::shared_ptr<MainThreadHandle> worker_thread,
72
+ bool waiting);
73
+ bool WaitForConnect() {
74
+ return wait_;
75
+ }
76
+ const std::string& url() const { return url_; }
77
+ std::unique_ptr<inspector::InspectorSession> Connect(
78
+ std::unique_ptr<inspector::InspectorSessionDelegate> delegate,
79
+ bool prevent_shutdown);
80
+ std::shared_ptr<NetworkResourceManager> GetNetworkResourceManager() {
81
+ return network_resource_manager_;
82
+ }
83
+
84
+ private:
85
+ uint64_t id_;
86
+ std::string url_;
87
+ std::shared_ptr<MainThreadHandle> parent_thread_;
88
+ bool wait_;
89
+ std::string name_;
90
+ std::shared_ptr<NetworkResourceManager> network_resource_manager_;
91
+ };
92
+
93
+ class WorkerManager : public std::enable_shared_from_this<WorkerManager> {
94
+ public:
95
+ explicit WorkerManager(std::shared_ptr<MainThreadHandle> thread)
96
+ : thread_(thread) {}
97
+
98
+ std::unique_ptr<ParentInspectorHandle> NewParentHandle(
99
+ uint64_t thread_id,
100
+ std::string_view url,
101
+ std::string_view name,
102
+ std::shared_ptr<NetworkResourceManager> network_resource_manager);
103
+ void WorkerStarted(uint64_t session_id, const WorkerInfo& info, bool waiting);
104
+ void WorkerFinished(uint64_t session_id);
105
+ std::unique_ptr<WorkerManagerEventHandle> SetAutoAttach(
106
+ std::unique_ptr<WorkerDelegate> attach_delegate);
107
+ void SetWaitOnStartForDelegate(int id, bool wait);
108
+ void RemoveAttachDelegate(int id);
109
+ std::shared_ptr<MainThreadHandle> MainThread() {
110
+ return thread_;
111
+ }
112
+
113
+ private:
114
+ std::shared_ptr<MainThreadHandle> thread_;
115
+ std::unordered_map<uint64_t, WorkerInfo> children_;
116
+ std::unordered_map<int, std::unique_ptr<WorkerDelegate>> delegates_;
117
+ // If any one needs it, workers stop for all
118
+ std::unordered_set<int> delegates_waiting_on_start_;
119
+ int next_delegate_id_ = 0;
120
+ };
121
+ } // namespace inspector
122
+ } // namespace node
123
+
124
+ #endif // SRC_INSPECTOR_WORKER_INSPECTOR_H_
@@ -0,0 +1,168 @@
1
+ #pragma once
2
+
3
+ #include "inspector/network_resource_manager.h"
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #if !HAVE_INSPECTOR
7
+ #error("This header can only be used when inspector is enabled")
8
+ #endif
9
+
10
+ #include "node_options.h"
11
+ #include "v8.h"
12
+
13
+ #include <cstddef>
14
+ #include <memory>
15
+
16
+ namespace v8_inspector {
17
+ class StringView;
18
+ } // namespace v8_inspector
19
+
20
+ namespace node {
21
+ // Forward declaration to break recursive dependency chain with src/env.h.
22
+ class Environment;
23
+ struct ContextInfo;
24
+
25
+ namespace inspector {
26
+ class InspectorIo;
27
+ class ParentInspectorHandle;
28
+ class NodeInspectorClient;
29
+ class WorkerManager;
30
+
31
+ class InspectorSession {
32
+ public:
33
+ virtual ~InspectorSession() = default;
34
+ virtual void Dispatch(const v8_inspector::StringView& message) = 0;
35
+ };
36
+
37
+ class InspectorSessionDelegate {
38
+ public:
39
+ virtual ~InspectorSessionDelegate() = default;
40
+ virtual void SendMessageToFrontend(const v8_inspector::StringView& message)
41
+ = 0;
42
+ };
43
+
44
+ class Agent {
45
+ public:
46
+ explicit Agent(node::Environment* env);
47
+ ~Agent();
48
+
49
+ // Create client_, may create io_ if option enabled
50
+ bool Start(const std::string& path,
51
+ const DebugOptions& options,
52
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port,
53
+ bool is_main);
54
+ // Stop and destroy io_
55
+ void Stop();
56
+
57
+ bool IsListening() { return io_ != nullptr; }
58
+ // Returns true if the Node inspector is actually in use. It will be true
59
+ // if either the user explicitly opted into inspector (e.g. with the
60
+ // --inspect command line flag) or if inspector JS API had been used.
61
+ bool IsActive();
62
+
63
+ // Blocks till frontend connects and sends "runIfWaitingForDebugger"
64
+ void WaitForConnect();
65
+ bool WaitForConnectByOptions();
66
+ void StopIfWaitingForConnect();
67
+
68
+ // Blocks till all the sessions with "WaitForDisconnectOnShutdown" disconnect
69
+ void WaitForDisconnect();
70
+ void ReportUncaughtException(v8::Local<v8::Value> error,
71
+ v8::Local<v8::Message> message);
72
+
73
+ void EmitProtocolEvent(v8::Local<v8::Context> context,
74
+ const v8_inspector::StringView& event,
75
+ v8::Local<v8::Object> params);
76
+
77
+ void SetupNetworkTracking(v8::Local<v8::Function> enable_function,
78
+ v8::Local<v8::Function> disable_function);
79
+ void EnableNetworkTracking();
80
+ void DisableNetworkTracking();
81
+
82
+ // Async stack traces instrumentation.
83
+ void AsyncTaskScheduled(const v8_inspector::StringView& taskName, void* task,
84
+ bool recurring);
85
+ void AsyncTaskCanceled(void* task);
86
+ void AsyncTaskStarted(void* task);
87
+ void AsyncTaskFinished(void* task);
88
+ void AllAsyncTasksCanceled();
89
+
90
+ void RegisterAsyncHook(v8::Isolate* isolate,
91
+ v8::Local<v8::Function> enable_function,
92
+ v8::Local<v8::Function> disable_function);
93
+ void SetAsyncHookTrackingEnabled(bool enabled);
94
+
95
+ void SetParentHandle(std::unique_ptr<ParentInspectorHandle> parent_handle);
96
+ std::unique_ptr<ParentInspectorHandle> GetParentHandle(uint64_t thread_id,
97
+ std::string_view url,
98
+ std::string_view name);
99
+
100
+ // Called to create inspector sessions that can be used from the same thread.
101
+ // The inspector responds by using the delegate to send messages back.
102
+ std::unique_ptr<InspectorSession> Connect(
103
+ std::unique_ptr<InspectorSessionDelegate> delegate,
104
+ bool prevent_shutdown);
105
+
106
+ // Called from the worker to create inspector sessions that is connected
107
+ // to the main thread.
108
+ // The inspector responds by using the delegate to send messages back.
109
+ std::unique_ptr<InspectorSession> ConnectToMainThread(
110
+ std::unique_ptr<InspectorSessionDelegate> delegate,
111
+ bool prevent_shutdown);
112
+
113
+ void PauseOnNextJavascriptStatement(const std::string& reason);
114
+
115
+ std::string GetWsUrl() const;
116
+
117
+ // Can only be called from the main thread.
118
+ bool StartIoThread();
119
+
120
+ // Calls StartIoThread() from off the main thread.
121
+ void RequestIoThreadStart();
122
+
123
+ const DebugOptions& options() { return debug_options_; }
124
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port() { return host_port_; }
125
+ void ContextCreated(v8::Local<v8::Context> context, const ContextInfo& info);
126
+
127
+ // Interface for interacting with inspectors in worker threads
128
+ std::shared_ptr<WorkerManager> GetWorkerManager();
129
+
130
+ inline Environment* env() const { return parent_env_; }
131
+ std::shared_ptr<NetworkResourceManager> GetNetworkResourceManager();
132
+
133
+ private:
134
+ void SyncAsyncHookState();
135
+ void ToggleNetworkTracking(v8::Isolate* isolate, v8::Local<v8::Function> fn);
136
+
137
+ node::Environment* parent_env_;
138
+ // Encapsulates majority of the Inspector functionality
139
+ std::shared_ptr<NodeInspectorClient> client_;
140
+ // Interface for transports, e.g. WebSocket server
141
+ std::unique_ptr<InspectorIo> io_;
142
+ std::unique_ptr<ParentInspectorHandle> parent_handle_;
143
+ std::string path_;
144
+
145
+ // This is a copy of the debug options parsed from CLI in the Environment.
146
+ // Do not use the host_port in that, instead manipulate the shared host_port_
147
+ // pointer which is meant to store the actual host and port of the inspector
148
+ // server.
149
+ DebugOptions debug_options_;
150
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port_;
151
+
152
+ // The state of the async hook used for async stack traces that the protocol
153
+ // last requested, and the state JS currently has. SyncAsyncHookState()
154
+ // reconciles the two when it is possible and safe to call into JS.
155
+ bool async_hook_wanted_ = false;
156
+ bool async_hook_enabled_ = false;
157
+ bool syncing_async_hook_state_ = false;
158
+
159
+ bool network_tracking_enabled_ = false;
160
+ bool pending_enable_network_tracking = false;
161
+ bool pending_disable_network_tracking = false;
162
+ std::shared_ptr<NetworkResourceManager> network_resource_manager_;
163
+ };
164
+
165
+ } // namespace inspector
166
+ } // namespace node
167
+
168
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
@@ -0,0 +1,78 @@
1
+ #pragma once
2
+
3
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
+
5
+ #if !HAVE_INSPECTOR
6
+ #error("This header can only be used when inspector is enabled")
7
+ #endif
8
+
9
+ #include "inspector_socket_server.h"
10
+ #include "node_mutex.h"
11
+
12
+ #include "uv.h"
13
+
14
+ #include <cstddef>
15
+ #include <memory>
16
+
17
+ namespace node {
18
+ // Forward declaration to break recursive dependency chain with src/env.h.
19
+ class Environment;
20
+ namespace inspector {
21
+
22
+ class MainThreadHandle;
23
+ class RequestQueue;
24
+
25
+ class InspectorIo {
26
+ public:
27
+ // Start the inspector agent thread, waiting for it to initialize
28
+ // bool Start();
29
+ // Returns empty pointer if thread was not started
30
+ static std::unique_ptr<InspectorIo> Start(
31
+ std::shared_ptr<MainThreadHandle> main_thread,
32
+ const std::string& path,
33
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port,
34
+ const InspectPublishUid& inspect_publish_uid);
35
+
36
+ // Will block till the transport thread shuts down
37
+ ~InspectorIo();
38
+
39
+ void StopAcceptingNewConnections();
40
+ std::string GetWsUrl() const;
41
+
42
+ private:
43
+ InspectorIo(std::shared_ptr<MainThreadHandle> handle,
44
+ const std::string& path,
45
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port,
46
+ const InspectPublishUid& inspect_publish_uid);
47
+
48
+ // Wrapper for agent->ThreadMain()
49
+ static void ThreadMain(void* agent);
50
+
51
+ // Runs a uv_loop_t
52
+ void ThreadMain();
53
+
54
+ // This is a thread-safe object that will post async tasks. It lives as long
55
+ // as an Inspector object lives (almost as long as an Isolate).
56
+ std::shared_ptr<MainThreadHandle> main_thread_;
57
+ // Used to post on a frontend interface thread, lives while the server is
58
+ // running
59
+ std::shared_ptr<RequestQueue> request_queue_;
60
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port_;
61
+ InspectPublishUid inspect_publish_uid_;
62
+
63
+ // The IO thread runs its own uv_loop to implement the TCP server off
64
+ // the main thread.
65
+ uv_thread_t thread_;
66
+
67
+ // For setting up interthread communications
68
+ Mutex thread_start_lock_;
69
+ ConditionVariable thread_start_condition_;
70
+ std::string script_name_;
71
+ // May be accessed from any thread
72
+ const std::string id_;
73
+ };
74
+
75
+ } // namespace inspector
76
+ } // namespace node
77
+
78
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS