@encharm/cws 4.5.1 → 4.5.2

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 (237) hide show
  1. package/binding.gyp +1 -1
  2. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  3. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  4. package/package.json +1 -1
  5. package/src/Addon.h +6 -1
  6. package/src/headers/24/acorn_version.h +6 -0
  7. package/src/headers/24/addon_permission.h +31 -0
  8. package/src/headers/24/agent.h +195 -0
  9. package/src/headers/24/aliased_buffer-inl.h +244 -0
  10. package/src/headers/24/aliased_buffer.h +206 -0
  11. package/src/headers/24/aliased_struct-inl.h +54 -0
  12. package/src/headers/24/aliased_struct.h +63 -0
  13. package/src/headers/24/amaro_version.h +6 -0
  14. package/src/headers/24/application.h +165 -0
  15. package/src/headers/24/async_context_frame.h +33 -0
  16. package/src/headers/24/async_wrap-inl.h +96 -0
  17. package/src/headers/24/async_wrap.h +244 -0
  18. package/src/headers/24/base_object-inl.h +330 -0
  19. package/src/headers/24/base_object.h +338 -0
  20. package/src/headers/24/base_object_types.h +74 -0
  21. package/src/headers/24/bindingdata.h +272 -0
  22. package/src/headers/24/blob_serializer_deserializer-inl.h +385 -0
  23. package/src/headers/24/blob_serializer_deserializer.h +132 -0
  24. package/src/headers/24/callback_queue-inl.h +97 -0
  25. package/src/headers/24/callback_queue.h +79 -0
  26. package/src/headers/24/cares_wrap.h +447 -0
  27. package/src/headers/24/child_process_permission.h +31 -0
  28. package/src/headers/24/cid.h +127 -0
  29. package/src/headers/24/cjs_module_lexer_version.h +6 -0
  30. package/src/headers/24/cleanup_queue-inl.h +36 -0
  31. package/src/headers/24/cleanup_queue.h +79 -0
  32. package/src/headers/24/compile_cache.h +113 -0
  33. package/src/headers/24/connect_wrap.h +26 -0
  34. package/src/headers/24/connection_wrap.h +30 -0
  35. package/src/headers/24/cppgc_helpers-inl.h +65 -0
  36. package/src/headers/24/cppgc_helpers.h +162 -0
  37. package/src/headers/24/crypto/crypto_aes.h +97 -0
  38. package/src/headers/24/crypto/crypto_argon2.h +86 -0
  39. package/src/headers/24/crypto/crypto_bio.h +193 -0
  40. package/src/headers/24/crypto/crypto_chacha20_poly1305.h +64 -0
  41. package/src/headers/24/crypto/crypto_cipher.h +281 -0
  42. package/src/headers/24/crypto/crypto_clienthello-inl.h +90 -0
  43. package/src/headers/24/crypto/crypto_clienthello.h +131 -0
  44. package/src/headers/24/crypto/crypto_common.h +48 -0
  45. package/src/headers/24/crypto/crypto_context.h +171 -0
  46. package/src/headers/24/crypto/crypto_dh.h +126 -0
  47. package/src/headers/24/crypto/crypto_dsa.h +50 -0
  48. package/src/headers/24/crypto/crypto_ec.h +163 -0
  49. package/src/headers/24/crypto/crypto_hash.h +89 -0
  50. package/src/headers/24/crypto/crypto_hkdf.h +61 -0
  51. package/src/headers/24/crypto/crypto_hmac.h +92 -0
  52. package/src/headers/24/crypto/crypto_kem.h +113 -0
  53. package/src/headers/24/crypto/crypto_keygen.h +290 -0
  54. package/src/headers/24/crypto/crypto_keys.h +392 -0
  55. package/src/headers/24/crypto/crypto_ml_dsa.h +21 -0
  56. package/src/headers/24/crypto/crypto_pbkdf2.h +74 -0
  57. package/src/headers/24/crypto/crypto_random.h +124 -0
  58. package/src/headers/24/crypto/crypto_rsa.h +136 -0
  59. package/src/headers/24/crypto/crypto_scrypt.h +85 -0
  60. package/src/headers/24/crypto/crypto_sig.h +156 -0
  61. package/src/headers/24/crypto/crypto_spkac.h +21 -0
  62. package/src/headers/24/crypto/crypto_timing.h +20 -0
  63. package/src/headers/24/crypto/crypto_tls.h +309 -0
  64. package/src/headers/24/crypto/crypto_util.h +598 -0
  65. package/src/headers/24/crypto/crypto_x509.h +140 -0
  66. package/src/headers/24/data.h +148 -0
  67. package/src/headers/24/debug_utils-inl.h +232 -0
  68. package/src/headers/24/debug_utils.h +193 -0
  69. package/src/headers/24/defs.h +254 -0
  70. package/src/headers/24/diagnosticfilename-inl.h +33 -0
  71. package/src/headers/24/embedded_data.h +17 -0
  72. package/src/headers/24/encoding_binding.h +60 -0
  73. package/src/headers/24/endpoint.h +421 -0
  74. package/src/headers/24/env-inl.h +935 -0
  75. package/src/headers/24/env.h +1257 -0
  76. package/src/headers/24/env_properties.h +561 -0
  77. package/src/headers/24/fs_permission.h +167 -0
  78. package/src/headers/24/handle_wrap.h +123 -0
  79. package/src/headers/24/histogram-inl.h +107 -0
  80. package/src/headers/24/histogram.h +279 -0
  81. package/src/headers/24/http3.h +44 -0
  82. package/src/headers/24/inspector_agent.h +165 -0
  83. package/src/headers/24/inspector_io.h +78 -0
  84. package/src/headers/24/inspector_permission.h +31 -0
  85. package/src/headers/24/inspector_profiler.h +149 -0
  86. package/src/headers/24/inspector_socket.h +60 -0
  87. package/src/headers/24/inspector_socket_server.h +110 -0
  88. package/src/headers/24/io_agent.h +30 -0
  89. package/src/headers/24/js_native_api.h +615 -0
  90. package/src/headers/24/js_native_api_types.h +211 -0
  91. package/src/headers/24/js_native_api_v8.h +485 -0
  92. package/src/headers/24/js_native_api_v8_internals.h +45 -0
  93. package/src/headers/24/js_stream.h +52 -0
  94. package/src/headers/24/json_parser.h +40 -0
  95. package/src/headers/24/json_utils.h +172 -0
  96. package/src/headers/24/logstream.h +81 -0
  97. package/src/headers/24/main_thread_interface.h +116 -0
  98. package/src/headers/24/memory_tracker-inl.h +454 -0
  99. package/src/headers/24/memory_tracker.h +333 -0
  100. package/src/headers/24/module_wrap.h +229 -0
  101. package/src/headers/24/ncrypto.h +1625 -0
  102. package/src/headers/24/network_agent.h +118 -0
  103. package/src/headers/24/network_inspector.h +45 -0
  104. package/src/headers/24/network_resource_manager.h +29 -0
  105. package/src/headers/24/node.h +1620 -0
  106. package/src/headers/24/node_api.h +269 -0
  107. package/src/headers/24/node_api_internals.h +46 -0
  108. package/src/headers/24/node_api_types.h +52 -0
  109. package/src/headers/24/node_binding.h +163 -0
  110. package/src/headers/24/node_blob.h +159 -0
  111. package/src/headers/24/node_bob-inl.h +36 -0
  112. package/src/headers/24/node_bob.h +107 -0
  113. package/src/headers/24/node_buffer.h +92 -0
  114. package/src/headers/24/node_builtins.h +223 -0
  115. package/src/headers/24/node_config_file.h +65 -0
  116. package/src/headers/24/node_constants.h +82 -0
  117. package/src/headers/24/node_context_data.h +168 -0
  118. package/src/headers/24/node_contextify.h +261 -0
  119. package/src/headers/24/node_crypto.h +62 -0
  120. package/src/headers/24/node_debug.h +25 -0
  121. package/src/headers/24/node_dir.h +52 -0
  122. package/src/headers/24/node_dotenv.h +45 -0
  123. package/src/headers/24/node_errors.h +391 -0
  124. package/src/headers/24/node_exit_code.h +54 -0
  125. package/src/headers/24/node_external_reference.h +167 -0
  126. package/src/headers/24/node_file-inl.h +412 -0
  127. package/src/headers/24/node_file.h +540 -0
  128. package/src/headers/24/node_http2.h +1175 -0
  129. package/src/headers/24/node_http2_state.h +159 -0
  130. package/src/headers/24/node_http_common-inl.h +198 -0
  131. package/src/headers/24/node_http_common.h +535 -0
  132. package/src/headers/24/node_i18n.h +132 -0
  133. package/src/headers/24/node_internals.h +476 -0
  134. package/src/headers/24/node_json.h +24 -0
  135. package/src/headers/24/node_large_page.h +34 -0
  136. package/src/headers/24/node_locks.h +180 -0
  137. package/src/headers/24/node_main_instance.h +67 -0
  138. package/src/headers/24/node_mem-inl.h +112 -0
  139. package/src/headers/24/node_mem.h +45 -0
  140. package/src/headers/24/node_messaging.h +389 -0
  141. package/src/headers/24/node_metadata.h +164 -0
  142. package/src/headers/24/node_modules.h +93 -0
  143. package/src/headers/24/node_mutex.h +323 -0
  144. package/src/headers/24/node_object_wrap.h +132 -0
  145. package/src/headers/24/node_options-inl.h +524 -0
  146. package/src/headers/24/node_options.h +682 -0
  147. package/src/headers/24/node_perf.h +166 -0
  148. package/src/headers/24/node_perf_common.h +102 -0
  149. package/src/headers/24/node_platform.h +286 -0
  150. package/src/headers/24/node_process-inl.h +26 -0
  151. package/src/headers/24/node_process.h +111 -0
  152. package/src/headers/24/node_realm-inl.h +153 -0
  153. package/src/headers/24/node_realm.h +236 -0
  154. package/src/headers/24/node_report.h +43 -0
  155. package/src/headers/24/node_revert.h +82 -0
  156. package/src/headers/24/node_root_certs.h +3546 -0
  157. package/src/headers/24/node_sea.h +74 -0
  158. package/src/headers/24/node_shadow_realm.h +46 -0
  159. package/src/headers/24/node_snapshot_builder.h +57 -0
  160. package/src/headers/24/node_snapshotable.h +174 -0
  161. package/src/headers/24/node_sockaddr-inl.h +257 -0
  162. package/src/headers/24/node_sockaddr.h +394 -0
  163. package/src/headers/24/node_sqlite.h +270 -0
  164. package/src/headers/24/node_stat_watcher.h +73 -0
  165. package/src/headers/24/node_string.h +101 -0
  166. package/src/headers/24/node_task_runner.h +92 -0
  167. package/src/headers/24/node_threadsafe_cow-inl.h +54 -0
  168. package/src/headers/24/node_threadsafe_cow.h +105 -0
  169. package/src/headers/24/node_trace_buffer.h +83 -0
  170. package/src/headers/24/node_trace_writer.h +75 -0
  171. package/src/headers/24/node_union_bytes.h +81 -0
  172. package/src/headers/24/node_url.h +101 -0
  173. package/src/headers/24/node_url_pattern.h +118 -0
  174. package/src/headers/24/node_v8.h +77 -0
  175. package/src/headers/24/node_v8_platform-inl.h +185 -0
  176. package/src/headers/24/node_version.h +110 -0
  177. package/src/headers/24/node_wasi.h +185 -0
  178. package/src/headers/24/node_wasm_web_api.h +55 -0
  179. package/src/headers/24/node_watchdog.h +154 -0
  180. package/src/headers/24/node_webstorage.h +60 -0
  181. package/src/headers/24/node_worker.h +159 -0
  182. package/src/headers/24/packet.h +155 -0
  183. package/src/headers/24/path.h +33 -0
  184. package/src/headers/24/permission/addon_permission.h +31 -0
  185. package/src/headers/24/permission/child_process_permission.h +31 -0
  186. package/src/headers/24/permission/fs_permission.h +167 -0
  187. package/src/headers/24/permission/inspector_permission.h +31 -0
  188. package/src/headers/24/permission/permission.h +100 -0
  189. package/src/headers/24/permission/permission_base.h +65 -0
  190. package/src/headers/24/permission/wasi_permission.h +31 -0
  191. package/src/headers/24/permission/worker_permission.h +31 -0
  192. package/src/headers/24/permission.h +100 -0
  193. package/src/headers/24/permission_base.h +65 -0
  194. package/src/headers/24/pipe_wrap.h +80 -0
  195. package/src/headers/24/preferredaddress.h +72 -0
  196. package/src/headers/24/protocol_helper.h +27 -0
  197. package/src/headers/24/queue.h +306 -0
  198. package/src/headers/24/req_wrap-inl.h +176 -0
  199. package/src/headers/24/req_wrap.h +79 -0
  200. package/src/headers/24/runtime_agent.h +41 -0
  201. package/src/headers/24/session.h +528 -0
  202. package/src/headers/24/sessionticket.h +108 -0
  203. package/src/headers/24/spawn_sync.h +243 -0
  204. package/src/headers/24/stream_base-inl.h +173 -0
  205. package/src/headers/24/stream_base.h +478 -0
  206. package/src/headers/24/stream_pipe.h +76 -0
  207. package/src/headers/24/stream_wrap.h +132 -0
  208. package/src/headers/24/streams.h +370 -0
  209. package/src/headers/24/string_bytes.h +109 -0
  210. package/src/headers/24/string_decoder-inl.h +31 -0
  211. package/src/headers/24/string_decoder.h +49 -0
  212. package/src/headers/24/target_agent.h +75 -0
  213. package/src/headers/24/tcp_wrap.h +105 -0
  214. package/src/headers/24/threadpoolwork-inl.h +70 -0
  215. package/src/headers/24/timer_wrap-inl.h +32 -0
  216. package/src/headers/24/timer_wrap.h +87 -0
  217. package/src/headers/24/timers.h +75 -0
  218. package/src/headers/24/tlscontext.h +228 -0
  219. package/src/headers/24/tokens.h +256 -0
  220. package/src/headers/24/trace_event.h +722 -0
  221. package/src/headers/24/trace_event_common.h +1109 -0
  222. package/src/headers/24/traced_value.h +129 -0
  223. package/src/headers/24/tracing_agent.h +43 -0
  224. package/src/headers/24/transportparams.h +166 -0
  225. package/src/headers/24/tty_wrap.h +65 -0
  226. package/src/headers/24/udp_wrap.h +230 -0
  227. package/src/headers/24/undici_version.h +6 -0
  228. package/src/headers/24/util-inl.h +711 -0
  229. package/src/headers/24/util.h +1016 -0
  230. package/src/headers/24/v8-external-memory-accounter.h +60 -0
  231. package/src/headers/24/v8-fast-api-calls.h +819 -0
  232. package/src/headers/24/v8-inspector.h +426 -0
  233. package/src/headers/24/wasi_permission.h +31 -0
  234. package/src/headers/24/worker_agent.h +40 -0
  235. package/src/headers/24/worker_inspector.h +124 -0
  236. package/src/headers/24/worker_permission.h +31 -0
  237. package/src/headers/24/zlib_version.h +6 -0
@@ -0,0 +1,44 @@
1
+ #pragma once
2
+
3
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
+ #if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
5
+
6
+ #include <base_object.h>
7
+ #include <env.h>
8
+ #include <memory_tracker.h>
9
+ #include "session.h"
10
+
11
+ namespace node::quic {
12
+ // Provides an implementation of the HTTP/3 Application implementation
13
+ class Http3Application final : public Session::ApplicationProvider {
14
+ public:
15
+ static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
16
+ static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
17
+ Environment* env);
18
+ static void InitPerIsolate(IsolateData* isolate_data,
19
+ v8::Local<v8::ObjectTemplate> target);
20
+ static void InitPerContext(Realm* realm, v8::Local<v8::Object> target);
21
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
22
+
23
+ Http3Application(Environment* env,
24
+ v8::Local<v8::Object> object,
25
+ const Session::Application_Options& options);
26
+
27
+ std::unique_ptr<Session::Application> Create(Session* session) override;
28
+
29
+ void MemoryInfo(MemoryTracker* tracker) const override;
30
+ SET_SELF_SIZE(Http3Application)
31
+ SET_MEMORY_INFO_NAME(Http3Application)
32
+
33
+ std::string ToString() const;
34
+
35
+ private:
36
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
37
+
38
+ Session::Application_Options options_;
39
+ };
40
+
41
+ } // namespace node::quic
42
+
43
+ #endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
44
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
@@ -0,0 +1,165 @@
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 EnableAsyncHook();
94
+ void DisableAsyncHook();
95
+
96
+ void SetParentHandle(std::unique_ptr<ParentInspectorHandle> parent_handle);
97
+ std::unique_ptr<ParentInspectorHandle> GetParentHandle(uint64_t thread_id,
98
+ std::string_view url,
99
+ std::string_view name);
100
+
101
+ // Called to create inspector sessions that can be used from the same thread.
102
+ // The inspector responds by using the delegate to send messages back.
103
+ std::unique_ptr<InspectorSession> Connect(
104
+ std::unique_ptr<InspectorSessionDelegate> delegate,
105
+ bool prevent_shutdown);
106
+
107
+ // Called from the worker to create inspector sessions that is connected
108
+ // to the main thread.
109
+ // The inspector responds by using the delegate to send messages back.
110
+ std::unique_ptr<InspectorSession> ConnectToMainThread(
111
+ std::unique_ptr<InspectorSessionDelegate> delegate,
112
+ bool prevent_shutdown);
113
+
114
+ void PauseOnNextJavascriptStatement(const std::string& reason);
115
+
116
+ std::string GetWsUrl() const;
117
+
118
+ // Can only be called from the main thread.
119
+ bool StartIoThread();
120
+
121
+ // Calls StartIoThread() from off the main thread.
122
+ void RequestIoThreadStart();
123
+
124
+ const DebugOptions& options() { return debug_options_; }
125
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port() { return host_port_; }
126
+ void ContextCreated(v8::Local<v8::Context> context, const ContextInfo& info);
127
+
128
+ // Interface for interacting with inspectors in worker threads
129
+ std::shared_ptr<WorkerManager> GetWorkerManager();
130
+
131
+ inline Environment* env() const { return parent_env_; }
132
+ std::shared_ptr<NetworkResourceManager> GetNetworkResourceManager();
133
+
134
+ private:
135
+ void ToggleAsyncHook(v8::Isolate* isolate, v8::Local<v8::Function> fn);
136
+ void ToggleNetworkTracking(v8::Isolate* isolate, v8::Local<v8::Function> fn);
137
+
138
+ node::Environment* parent_env_;
139
+ // Encapsulates majority of the Inspector functionality
140
+ std::shared_ptr<NodeInspectorClient> client_;
141
+ // Interface for transports, e.g. WebSocket server
142
+ std::unique_ptr<InspectorIo> io_;
143
+ std::unique_ptr<ParentInspectorHandle> parent_handle_;
144
+ std::string path_;
145
+
146
+ // This is a copy of the debug options parsed from CLI in the Environment.
147
+ // Do not use the host_port in that, instead manipulate the shared host_port_
148
+ // pointer which is meant to store the actual host and port of the inspector
149
+ // server.
150
+ DebugOptions debug_options_;
151
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port_;
152
+
153
+ bool pending_enable_async_hook_ = false;
154
+ bool pending_disable_async_hook_ = false;
155
+
156
+ bool network_tracking_enabled_ = false;
157
+ bool pending_enable_network_tracking = false;
158
+ bool pending_disable_network_tracking = false;
159
+ std::shared_ptr<NetworkResourceManager> network_resource_manager_;
160
+ };
161
+
162
+ } // namespace inspector
163
+ } // namespace node
164
+
165
+ #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
@@ -0,0 +1,31 @@
1
+ #ifndef SRC_PERMISSION_INSPECTOR_PERMISSION_H_
2
+ #define SRC_PERMISSION_INSPECTOR_PERMISSION_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <string>
7
+ #include "permission/permission_base.h"
8
+
9
+ namespace node {
10
+
11
+ namespace permission {
12
+
13
+ class InspectorPermission final : public PermissionBase {
14
+ public:
15
+ void Apply(Environment* env,
16
+ const std::vector<std::string>& allow,
17
+ PermissionScope scope) override;
18
+ bool is_granted(Environment* env,
19
+ PermissionScope perm,
20
+ const std::string_view& param = "") const override;
21
+
22
+ private:
23
+ bool deny_all_;
24
+ };
25
+
26
+ } // namespace permission
27
+
28
+ } // namespace node
29
+
30
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
31
+ #endif // SRC_PERMISSION_INSPECTOR_PERMISSION_H_
@@ -0,0 +1,149 @@
1
+ #ifndef SRC_INSPECTOR_PROFILER_H_
2
+ #define SRC_INSPECTOR_PROFILER_H_
3
+
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 <optional>
11
+ #include <unordered_set>
12
+ #include "inspector_agent.h"
13
+ #include "simdjson.h"
14
+
15
+ namespace node {
16
+ // Forward declaration to break recursive dependency chain with src/env.h.
17
+ class Environment;
18
+
19
+ namespace profiler {
20
+
21
+ class V8ProfilerConnection {
22
+ public:
23
+ class V8ProfilerSessionDelegate : public inspector::InspectorSessionDelegate {
24
+ public:
25
+ explicit V8ProfilerSessionDelegate(V8ProfilerConnection* connection)
26
+ : connection_(connection) {}
27
+
28
+ void SendMessageToFrontend(
29
+ const v8_inspector::StringView& message) override;
30
+
31
+ private:
32
+ V8ProfilerConnection* connection_;
33
+ };
34
+
35
+ explicit V8ProfilerConnection(Environment* env);
36
+ virtual ~V8ProfilerConnection() = default;
37
+
38
+ Environment* env() const { return env_; }
39
+
40
+ // Dispatch a protocol message, and returns the id of the message.
41
+ // `method` does not need to be surrounded by quotes.
42
+ // The optional `params` should be formatted in JSON.
43
+ // The strings should be in one byte characters - which is enough for
44
+ // the commands we use here.
45
+ uint64_t DispatchMessage(const char* method,
46
+ const char* params = nullptr,
47
+ bool is_profile_request = false);
48
+
49
+ // Use DispatchMessage() to dispatch necessary inspector messages
50
+ // to start and end the profiling.
51
+ virtual void Start() = 0;
52
+ virtual void End() = 0;
53
+
54
+ // Return a descriptive name of the profile for debugging.
55
+ virtual const char* type() const = 0;
56
+ // Return if the profile is ending and the response can be parsed.
57
+ virtual bool ending() const = 0;
58
+ // Return the directory where the profile should be placed.
59
+ virtual std::string GetDirectory() const = 0;
60
+ // Return the filename the profile should be written as.
61
+ virtual std::string GetFilename() const = 0;
62
+ // Return the profile object parsed from `message.result`,
63
+ // which will be then written as a JSON.
64
+ virtual std::optional<std::string_view> GetProfile(
65
+ simdjson::ondemand::object* result);
66
+ virtual void WriteProfile(simdjson::ondemand::object* result);
67
+
68
+ bool HasProfileId(uint64_t id) const { return profile_ids_.contains(id); }
69
+
70
+ void RemoveProfileId(uint64_t id) { profile_ids_.erase(id); }
71
+
72
+ private:
73
+ uint64_t next_id() { return id_++; }
74
+ std::unique_ptr<inspector::InspectorSession> session_;
75
+ uint64_t id_ = 1;
76
+ std::unordered_set<uint64_t> profile_ids_;
77
+
78
+ protected:
79
+ simdjson::ondemand::parser json_parser_;
80
+ Environment* env_ = nullptr;
81
+ };
82
+
83
+ class V8CoverageConnection : public V8ProfilerConnection {
84
+ public:
85
+ explicit V8CoverageConnection(Environment* env) : V8ProfilerConnection(env) {}
86
+
87
+ void Start() override;
88
+ void End() override;
89
+
90
+ const char* type() const override { return "coverage"; }
91
+ bool ending() const override { return ending_; }
92
+
93
+ std::string GetDirectory() const override;
94
+ std::string GetFilename() const override;
95
+ std::optional<std::string_view> GetProfile(
96
+ simdjson::ondemand::object* result) override;
97
+ void WriteProfile(simdjson::ondemand::object* result) override;
98
+ void WriteSourceMapCache();
99
+ void TakeCoverage();
100
+ void StopCoverage();
101
+
102
+ private:
103
+ std::unique_ptr<inspector::InspectorSession> session_;
104
+ bool ending_ = false;
105
+ };
106
+
107
+ class V8CpuProfilerConnection : public V8ProfilerConnection {
108
+ public:
109
+ explicit V8CpuProfilerConnection(Environment* env)
110
+ : V8ProfilerConnection(env) {}
111
+
112
+ void Start() override;
113
+ void End() override;
114
+
115
+ const char* type() const override { return "CPU"; }
116
+ bool ending() const override { return ending_; }
117
+
118
+ std::string GetDirectory() const override;
119
+ std::string GetFilename() const override;
120
+
121
+ private:
122
+ std::unique_ptr<inspector::InspectorSession> session_;
123
+ bool ending_ = false;
124
+ };
125
+
126
+ class V8HeapProfilerConnection : public V8ProfilerConnection {
127
+ public:
128
+ explicit V8HeapProfilerConnection(Environment* env)
129
+ : V8ProfilerConnection(env) {}
130
+
131
+ void Start() override;
132
+ void End() override;
133
+
134
+ const char* type() const override { return "heap"; }
135
+ bool ending() const override { return ending_; }
136
+
137
+ std::string GetDirectory() const override;
138
+ std::string GetFilename() const override;
139
+
140
+ private:
141
+ std::unique_ptr<inspector::InspectorSession> session_;
142
+ bool ending_ = false;
143
+ };
144
+
145
+ } // namespace profiler
146
+ } // namespace node
147
+
148
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
149
+ #endif // SRC_INSPECTOR_PROFILER_H_
@@ -0,0 +1,60 @@
1
+ #ifndef SRC_INSPECTOR_SOCKET_H_
2
+ #define SRC_INSPECTOR_SOCKET_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "util.h"
7
+ #include "uv.h"
8
+
9
+ #include <string>
10
+ #include <vector>
11
+
12
+ namespace node {
13
+ namespace inspector {
14
+
15
+ class ProtocolHandler;
16
+
17
+ // HTTP Wrapper around a uv_tcp_t
18
+ class InspectorSocket {
19
+ public:
20
+ class Delegate {
21
+ public:
22
+ virtual void OnHttpGet(const std::string& host,
23
+ const std::string& path) = 0;
24
+ virtual void OnSocketUpgrade(const std::string& host,
25
+ const std::string& path,
26
+ const std::string& accept_key) = 0;
27
+ virtual void OnWsFrame(const std::vector<char>& frame) = 0;
28
+ virtual ~Delegate() = default;
29
+ };
30
+
31
+ using DelegatePointer = std::unique_ptr<Delegate>;
32
+ using Pointer = std::unique_ptr<InspectorSocket>;
33
+
34
+ static Pointer Accept(uv_stream_t* server, DelegatePointer delegate);
35
+
36
+ ~InspectorSocket();
37
+
38
+ void AcceptUpgrade(const std::string& accept_key);
39
+ void CancelHandshake();
40
+ void Write(const char* data, size_t len);
41
+ void SwitchProtocol(ProtocolHandler* handler);
42
+ std::string GetHost();
43
+
44
+ InspectorSocket(const InspectorSocket&) = delete;
45
+ InspectorSocket& operator=(const InspectorSocket&) = delete;
46
+
47
+ private:
48
+ static void Shutdown(ProtocolHandler*);
49
+ InspectorSocket() = default;
50
+
51
+ DeleteFnPtr<ProtocolHandler, Shutdown> protocol_handler_;
52
+ };
53
+
54
+
55
+ } // namespace inspector
56
+ } // namespace node
57
+
58
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
59
+
60
+ #endif // SRC_INSPECTOR_SOCKET_H_
@@ -0,0 +1,110 @@
1
+ #ifndef SRC_INSPECTOR_SOCKET_SERVER_H_
2
+ #define SRC_INSPECTOR_SOCKET_SERVER_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "inspector_agent.h"
7
+ #include "inspector_socket.h"
8
+ #include "uv.h"
9
+
10
+ #include <map>
11
+ #include <string>
12
+ #include <vector>
13
+
14
+ #if !HAVE_INSPECTOR
15
+ #error("This header can only be used when inspector is enabled")
16
+ #endif
17
+
18
+ namespace node {
19
+ namespace inspector {
20
+
21
+ std::string FormatWsAddress(const std::string& host, int port,
22
+ const std::string& target_id,
23
+ bool include_protocol);
24
+
25
+ class InspectorSocketServer;
26
+ class SocketSession;
27
+ class ServerSocket;
28
+
29
+ class SocketServerDelegate {
30
+ public:
31
+ virtual void AssignServer(InspectorSocketServer* server) = 0;
32
+ virtual void StartSession(int session_id, const std::string& target_id) = 0;
33
+ virtual void EndSession(int session_id) = 0;
34
+ virtual void MessageReceived(int session_id, const std::string& message) = 0;
35
+ virtual std::vector<std::string> GetTargetIds() = 0;
36
+ virtual std::string GetTargetTitle(const std::string& id) = 0;
37
+ virtual std::string GetTargetUrl(const std::string& id) = 0;
38
+ virtual ~SocketServerDelegate() = default;
39
+ };
40
+
41
+ // HTTP Server, writes messages requested as TransportActions, and responds
42
+ // to HTTP requests and WS upgrades.
43
+
44
+ class InspectorSocketServer {
45
+ public:
46
+ InspectorSocketServer(std::unique_ptr<SocketServerDelegate> delegate,
47
+ uv_loop_t* loop,
48
+ const std::string& host,
49
+ int port,
50
+ const InspectPublishUid& inspect_publish_uid,
51
+ FILE* out = stderr);
52
+ ~InspectorSocketServer();
53
+
54
+ // Start listening on host/port
55
+ bool Start();
56
+
57
+ // Called by the TransportAction sent with InspectorIo::Write():
58
+ // kKill and kStop
59
+ void Stop();
60
+ // kSendMessage
61
+ void Send(int session_id, const std::string& message);
62
+ // kKill
63
+ void TerminateConnections();
64
+ int Port() const;
65
+
66
+ // Session connection lifecycle
67
+ void Accept(int server_port, uv_stream_t* server_socket);
68
+ bool HandleGetRequest(int session_id, const std::string& host,
69
+ const std::string& path);
70
+ void SessionStarted(int session_id, const std::string& target_id,
71
+ const std::string& ws_id);
72
+ void SessionTerminated(int session_id);
73
+ void MessageReceived(int session_id, const std::string& message) {
74
+ delegate_->MessageReceived(session_id, message);
75
+ }
76
+ SocketSession* Session(int session_id);
77
+ bool done() const {
78
+ return server_sockets_.empty() && connected_sessions_.empty();
79
+ }
80
+
81
+ static void CloseServerSocket(ServerSocket*);
82
+ using ServerSocketPtr = DeleteFnPtr<ServerSocket, CloseServerSocket>;
83
+
84
+ private:
85
+ void SendListResponse(InspectorSocket* socket, const std::string& host,
86
+ SocketSession* session);
87
+ std::string GetFrontendURL(bool is_compat,
88
+ const std::string &formatted_address);
89
+ bool TargetExists(const std::string& id);
90
+
91
+ enum class ServerState {kNew, kRunning, kStopped};
92
+ uv_loop_t* loop_;
93
+ std::unique_ptr<SocketServerDelegate> delegate_;
94
+ const std::string host_;
95
+ int port_;
96
+ InspectPublishUid inspect_publish_uid_;
97
+ std::vector<ServerSocketPtr> server_sockets_;
98
+ std::map<int, std::pair<std::string, std::unique_ptr<SocketSession>>>
99
+ connected_sessions_;
100
+ int next_session_id_;
101
+ FILE* out_;
102
+ ServerState state_;
103
+ };
104
+
105
+ } // namespace inspector
106
+ } // namespace node
107
+
108
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
109
+
110
+ #endif // SRC_INSPECTOR_SOCKET_SERVER_H_
@@ -0,0 +1,30 @@
1
+ #ifndef SRC_INSPECTOR_IO_AGENT_H_
2
+ #define SRC_INSPECTOR_IO_AGENT_H_
3
+
4
+ #include <memory>
5
+ #include "inspector/network_resource_manager.h"
6
+ #include "node/inspector/protocol/IO.h"
7
+
8
+ namespace node::inspector::protocol {
9
+
10
+ class IoAgent : public IO::Backend {
11
+ public:
12
+ explicit IoAgent(
13
+ std::shared_ptr<NetworkResourceManager> network_resource_manager)
14
+ : network_resource_manager_(std::move(network_resource_manager)) {}
15
+ void Wire(UberDispatcher* dispatcher);
16
+ DispatchResponse read(const String& in_handle,
17
+ std::optional<int> in_offset,
18
+ std::optional<int> in_size,
19
+ String* out_data,
20
+ bool* out_eof) override;
21
+ DispatchResponse close(const String& in_handle) override;
22
+
23
+ private:
24
+ std::shared_ptr<IO::Frontend> frontend_;
25
+ std::unordered_map<std::string, int> offset_map_ =
26
+ {}; // Maps stream_id to offset
27
+ std::shared_ptr<NetworkResourceManager> network_resource_manager_;
28
+ };
29
+ } // namespace node::inspector::protocol
30
+ #endif // SRC_INSPECTOR_IO_AGENT_H_