@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,38 @@
1
+ #ifndef SRC_NODE_PROFILING_H_
2
+ #define SRC_NODE_PROFILING_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "v8-profiler.h"
7
+ #include "v8.h"
8
+
9
+ #include <cstdint>
10
+ #include <sstream>
11
+
12
+ namespace node {
13
+
14
+ struct HeapProfileOptions {
15
+ uint64_t sample_interval = 512 * 1024;
16
+ int stack_depth = 16;
17
+ v8::HeapProfiler::SamplingFlags flags =
18
+ v8::HeapProfiler::SamplingFlags::kSamplingNoFlags;
19
+ };
20
+
21
+ HeapProfileOptions ParseHeapProfileOptions(
22
+ const v8::FunctionCallbackInfo<v8::Value>& args);
23
+
24
+ bool SerializeHeapProfile(v8::Isolate* isolate, std::ostringstream& out_stream);
25
+
26
+ struct CpuProfileOptions {
27
+ int sampling_interval_us = 0;
28
+ uint32_t max_samples = v8::CpuProfilingOptions::kNoSampleLimit;
29
+ };
30
+
31
+ CpuProfileOptions ParseCpuProfileOptions(
32
+ const v8::FunctionCallbackInfo<v8::Value>& args);
33
+
34
+ } // namespace node
35
+
36
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
37
+
38
+ #endif // SRC_NODE_PROFILING_H_
@@ -0,0 +1,156 @@
1
+ #ifndef SRC_NODE_REALM_INL_H_
2
+ #define SRC_NODE_REALM_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node_context_data.h"
7
+ #include "node_realm.h"
8
+ #include "util-inl.h"
9
+
10
+ namespace node {
11
+
12
+ inline Realm* Realm::GetCurrent(v8::Isolate* isolate) {
13
+ if (!isolate->InContext()) [[unlikely]] {
14
+ return nullptr;
15
+ }
16
+ v8::HandleScope handle_scope(isolate);
17
+ return GetCurrent(isolate->GetCurrentContext());
18
+ }
19
+
20
+ inline Realm* Realm::GetCurrent(v8::Local<v8::Context> context) {
21
+ if (!ContextEmbedderTag::IsNodeContext(context)) [[unlikely]] {
22
+ return nullptr;
23
+ }
24
+ return static_cast<Realm*>(context->GetAlignedPointerFromEmbedderData(
25
+ ContextEmbedderIndex::kRealm, EmbedderDataTag::kPerContextData));
26
+ }
27
+
28
+ inline Realm* Realm::GetCurrent(
29
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
30
+ return GetCurrent(info.GetIsolate()->GetCurrentContext());
31
+ }
32
+
33
+ template <typename T>
34
+ inline Realm* Realm::GetCurrent(const v8::PropertyCallbackInfo<T>& info) {
35
+ return GetCurrent(info.GetIsolate()->GetCurrentContext());
36
+ }
37
+
38
+ inline IsolateData* Realm::isolate_data() const {
39
+ return env_->isolate_data();
40
+ }
41
+
42
+ inline Environment* Realm::env() const {
43
+ return env_;
44
+ }
45
+
46
+ inline v8::Isolate* Realm::isolate() const {
47
+ return isolate_;
48
+ }
49
+
50
+ inline v8::Local<v8::Context> Realm::context() const {
51
+ return PersistentToLocal::Strong(context_);
52
+ }
53
+
54
+ inline Realm::Kind Realm::kind() const {
55
+ return kind_;
56
+ }
57
+
58
+ inline bool Realm::has_run_bootstrapping_code() const {
59
+ return has_run_bootstrapping_code_;
60
+ }
61
+
62
+ // static
63
+ template <typename T, typename U>
64
+ inline T* Realm::GetBindingData(const v8::PropertyCallbackInfo<U>& info) {
65
+ return GetBindingData<T>(info.GetIsolate()->GetCurrentContext());
66
+ }
67
+
68
+ // static
69
+ template <typename T>
70
+ inline T* Realm::GetBindingData(
71
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
72
+ return GetBindingData<T>(info.GetIsolate()->GetCurrentContext());
73
+ }
74
+
75
+ // static
76
+ template <typename T>
77
+ inline T* Realm::GetBindingData(v8::Local<v8::Context> context) {
78
+ Realm* realm = GetCurrent(context);
79
+ return realm->GetBindingData<T>();
80
+ }
81
+
82
+ template <typename T>
83
+ inline T* Realm::GetBindingData() {
84
+ constexpr size_t binding_index = static_cast<size_t>(T::binding_type_int);
85
+ static_assert(binding_index < std::tuple_size_v<BindingDataStore>);
86
+ auto ptr = binding_data_store_[binding_index];
87
+ if (!ptr) [[unlikely]] {
88
+ return nullptr;
89
+ }
90
+ T* result = static_cast<T*>(ptr.get());
91
+ DCHECK_NOT_NULL(result);
92
+ return result;
93
+ }
94
+
95
+ template <std::derived_from<BaseObject> T, typename... Args>
96
+ inline T* Realm::AddBindingData(v8::Local<v8::Object> target, Args&&... args) {
97
+ // The binding data must be weak so that it won't keep the realm reachable
98
+ // from strong GC roots indefinitely. The wrapper object of binding data
99
+ // should be referenced from JavaScript, thus the binding data should be
100
+ // reachable throughout the lifetime of the realm.
101
+ BaseObjectWeakPtr<T> item =
102
+ MakeWeakBaseObject<T>(this, target, std::forward<Args>(args)...);
103
+ constexpr size_t binding_index = static_cast<size_t>(T::binding_type_int);
104
+ static_assert(binding_index < std::tuple_size_v<BindingDataStore>);
105
+ // Each slot is expected to be assigned only once.
106
+ CHECK(!binding_data_store_[binding_index]);
107
+ binding_data_store_[binding_index] = item;
108
+ return item.get();
109
+ }
110
+
111
+ inline BindingDataStore* Realm::binding_data_store() {
112
+ return &binding_data_store_;
113
+ }
114
+
115
+ template <typename T>
116
+ void Realm::ForEachBaseObject(T&& iterator) const {
117
+ for (auto bo : base_object_list_) {
118
+ iterator(bo);
119
+ }
120
+ }
121
+
122
+ int64_t Realm::base_object_created_after_bootstrap() const {
123
+ return base_object_count_ - base_object_created_by_bootstrap_;
124
+ }
125
+
126
+ int64_t Realm::base_object_count() const {
127
+ return base_object_count_;
128
+ }
129
+
130
+ void Realm::TrackBaseObject(BaseObject* bo) {
131
+ DCHECK_EQ(bo->realm(), this);
132
+ base_object_list_.PushBack(bo);
133
+ ++base_object_count_;
134
+ }
135
+
136
+ CppgcWrapperListNode::CppgcWrapperListNode(CppgcMixin* ptr) : persistent(ptr) {}
137
+
138
+ void Realm::TrackCppgcWrapper(CppgcMixin* handle) {
139
+ DCHECK_EQ(handle->realm(), this);
140
+ cppgc_wrapper_list_.PushFront(new CppgcWrapperListNode(handle));
141
+ }
142
+
143
+ void Realm::UntrackBaseObject(BaseObject* bo) {
144
+ DCHECK_EQ(bo->realm(), this);
145
+ --base_object_count_;
146
+ }
147
+
148
+ bool Realm::PendingCleanup() const {
149
+ return !base_object_list_.IsEmpty();
150
+ }
151
+
152
+ } // namespace node
153
+
154
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
155
+
156
+ #endif // SRC_NODE_REALM_INL_H_
@@ -0,0 +1,236 @@
1
+ #ifndef SRC_NODE_REALM_H_
2
+ #define SRC_NODE_REALM_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <v8.h>
7
+ #include <unordered_map>
8
+ #include "cleanup_queue.h"
9
+ #include "cppgc_helpers.h"
10
+ #include "env_properties.h"
11
+ #include "memory_tracker.h"
12
+ #include "node_snapshotable.h"
13
+
14
+ namespace node {
15
+
16
+ struct RealmSerializeInfo {
17
+ std::vector<std::string> builtins;
18
+ std::vector<PropInfo> persistent_values;
19
+ std::vector<PropInfo> native_objects;
20
+
21
+ SnapshotIndex context;
22
+ friend std::ostream& operator<<(std::ostream& o, const RealmSerializeInfo& i);
23
+ };
24
+
25
+ using BindingDataStore =
26
+ std::array<BaseObjectWeakPtr<BaseObject>,
27
+ static_cast<size_t>(BindingDataType::kBindingDataTypeCount)>;
28
+
29
+ /**
30
+ * This is a wrapper around a weak persistent of CppgcMixin, used in the
31
+ * CppgcWrapperList to avoid accessing already garbage collected CppgcMixins.
32
+ */
33
+ class CppgcWrapperListNode {
34
+ public:
35
+ explicit inline CppgcWrapperListNode(CppgcMixin* ptr);
36
+ inline explicit operator bool() const { return !persistent; }
37
+ inline CppgcMixin* operator->() const { return persistent.Get(); }
38
+ inline CppgcMixin* operator*() const { return persistent.Get(); }
39
+
40
+ cppgc::WeakPersistent<CppgcMixin> persistent;
41
+ // Used by ContainerOf in the ListNode implementation for fast manipulation of
42
+ // CppgcWrapperList.
43
+ ListNode<CppgcWrapperListNode> wrapper_list_node;
44
+ };
45
+
46
+ /**
47
+ * A per-realm list of weak persistent of cppgc wrappers, which implements
48
+ * iterations that require iterate over cppgc wrappers created by Node.js.
49
+ */
50
+ class CppgcWrapperList
51
+ : public ListHead<CppgcWrapperListNode,
52
+ &CppgcWrapperListNode::wrapper_list_node>,
53
+ public MemoryRetainer {
54
+ public:
55
+ void Cleanup();
56
+ void PurgeEmpty();
57
+
58
+ SET_MEMORY_INFO_NAME(CppgcWrapperList)
59
+ SET_SELF_SIZE(CppgcWrapperList)
60
+ void MemoryInfo(MemoryTracker* tracker) const override;
61
+ };
62
+
63
+ /**
64
+ * node::Realm is a container for a set of JavaScript objects and functions
65
+ * that associated with a particular global environment.
66
+ *
67
+ * An ECMAScript realm (https://tc39.es/ecma262/#sec-code-realms) representing
68
+ * a global environment in which script is run. Each ECMAScript realm comes
69
+ * with a global object and a set of intrinsic objects. An ECMAScript realm has
70
+ * a [[HostDefined]] field, which contains the node::Realm object.
71
+ *
72
+ * Realm can be a principal realm or a synthetic realm. A principal realm is
73
+ * created with an Environment as its principal global environment to evaluate
74
+ * scripts. A synthetic realm is created with JS APIs like ShadowRealm.
75
+ *
76
+ * Native bindings and builtin modules can be evaluated in either a principal
77
+ * realm or a synthetic realm.
78
+ */
79
+ class Realm : public MemoryRetainer {
80
+ public:
81
+ enum Kind {
82
+ kPrincipal,
83
+ kShadowRealm,
84
+ };
85
+
86
+ static inline Realm* GetCurrent(v8::Isolate* isolate);
87
+ static inline Realm* GetCurrent(v8::Local<v8::Context> context);
88
+ static inline Realm* GetCurrent(
89
+ const v8::FunctionCallbackInfo<v8::Value>& info);
90
+ template <typename T>
91
+ static inline Realm* GetCurrent(const v8::PropertyCallbackInfo<T>& info);
92
+
93
+ Realm(Environment* env, v8::Local<v8::Context> context, Kind kind);
94
+
95
+ Realm(const Realm&) = delete;
96
+ Realm& operator=(const Realm&) = delete;
97
+ Realm(Realm&&) = delete;
98
+ Realm& operator=(Realm&&) = delete;
99
+
100
+ void MemoryInfo(MemoryTracker* tracker) const override;
101
+
102
+ void CreateProperties();
103
+ RealmSerializeInfo Serialize(v8::SnapshotCreator* creator);
104
+ void DeserializeProperties(const RealmSerializeInfo* info);
105
+
106
+ v8::MaybeLocal<v8::Value> ExecuteBootstrapper(const char* id);
107
+ v8::MaybeLocal<v8::Value> RunBootstrapping();
108
+
109
+ inline void TrackBaseObject(BaseObject* bo);
110
+ inline void UntrackBaseObject(BaseObject* bo);
111
+ inline bool PendingCleanup() const;
112
+ void RunCleanup();
113
+
114
+ template <typename T>
115
+ void ForEachBaseObject(T&& iterator) const;
116
+
117
+ void PrintInfoForSnapshot();
118
+ void VerifyNoStrongBaseObjects();
119
+
120
+ inline IsolateData* isolate_data() const;
121
+ inline Environment* env() const;
122
+ inline v8::Isolate* isolate() const;
123
+ inline Kind kind() const;
124
+ inline virtual v8::Local<v8::Context> context() const;
125
+ inline bool has_run_bootstrapping_code() const;
126
+
127
+ // Methods created using SetMethod(), SetPrototypeMethod(), etc. inside
128
+ // this scope can access the created T* object using
129
+ // GetBindingData<T>(args) later.
130
+ template <std::derived_from<BaseObject> T, typename... Args>
131
+ T* AddBindingData(v8::Local<v8::Object> target, Args&&... args);
132
+ template <typename T, typename U>
133
+ static inline T* GetBindingData(const v8::PropertyCallbackInfo<U>& info);
134
+ template <typename T>
135
+ static inline T* GetBindingData(
136
+ const v8::FunctionCallbackInfo<v8::Value>& info);
137
+ template <typename T>
138
+ static inline T* GetBindingData(v8::Local<v8::Context> context);
139
+ template <typename T>
140
+ inline T* GetBindingData();
141
+ inline BindingDataStore* binding_data_store();
142
+
143
+ // The BaseObject count is a debugging helper that makes sure that there are
144
+ // no memory leaks caused by BaseObjects staying alive longer than expected
145
+ // (in particular, no circular BaseObjectPtr references).
146
+ inline int64_t base_object_count() const;
147
+
148
+ // Base object count created after the bootstrap of the realm.
149
+ inline int64_t base_object_created_after_bootstrap() const;
150
+
151
+ inline void TrackCppgcWrapper(CppgcMixin* handle);
152
+ inline CppgcWrapperList* cppgc_wrapper_list() { return &cppgc_wrapper_list_; }
153
+
154
+ #define V(PropertyName, TypeName) \
155
+ virtual v8::Local<TypeName> PropertyName() const = 0; \
156
+ virtual void set_##PropertyName(v8::Local<TypeName> value) = 0;
157
+ PER_REALM_STRONG_PERSISTENT_VALUES(V)
158
+ #undef V
159
+
160
+ std::set<struct node_module*> internal_bindings;
161
+ std::set<std::string> builtins_with_cache;
162
+ std::set<std::string> builtins_without_cache;
163
+ // This is only filled during deserialization. We use a vector since
164
+ // it's only used for tests.
165
+ std::vector<std::string> builtins_in_snapshot;
166
+
167
+ // This used during the destruction of cppgc wrappers to inform a GC epilogue
168
+ // callback to clean up the weak persistents used to track cppgc wrappers if
169
+ // the wrappers are already garbage collected to prevent holding on to
170
+ // excessive useless persistents.
171
+ inline void set_should_purge_empty_cppgc_wrappers(bool value) {
172
+ should_purge_empty_cppgc_wrappers_ = value;
173
+ }
174
+
175
+ protected:
176
+ ~Realm();
177
+
178
+ virtual v8::MaybeLocal<v8::Value> BootstrapRealm() = 0;
179
+
180
+ Environment* env_;
181
+ // Shorthand for isolate pointer.
182
+ v8::Isolate* isolate_;
183
+ v8::Global<v8::Context> context_;
184
+ bool should_purge_empty_cppgc_wrappers_ = false;
185
+
186
+ #define V(PropertyName, TypeName) v8::Global<TypeName> PropertyName##_;
187
+ PER_REALM_STRONG_PERSISTENT_VALUES(V)
188
+ #undef V
189
+
190
+ static void PurgeEmptyCppgcWrappers(v8::Isolate* isolate,
191
+ v8::GCType type,
192
+ v8::GCCallbackFlags flags,
193
+ void* data);
194
+
195
+ private:
196
+ void InitializeContext(v8::Local<v8::Context> context,
197
+ const RealmSerializeInfo* realm_info);
198
+ void DoneBootstrapping();
199
+
200
+ Kind kind_;
201
+ bool has_run_bootstrapping_code_ = false;
202
+
203
+ int64_t base_object_count_ = 0;
204
+ int64_t base_object_created_by_bootstrap_ = 0;
205
+
206
+ BindingDataStore binding_data_store_;
207
+
208
+ BaseObjectList base_object_list_;
209
+ CppgcWrapperList cppgc_wrapper_list_;
210
+ };
211
+
212
+ class PrincipalRealm final : public Realm {
213
+ public:
214
+ PrincipalRealm(Environment* env,
215
+ v8::Local<v8::Context> context,
216
+ const RealmSerializeInfo* realm_info);
217
+ ~PrincipalRealm();
218
+
219
+ SET_MEMORY_INFO_NAME(PrincipalRealm)
220
+ SET_SELF_SIZE(PrincipalRealm)
221
+
222
+ #define V(PropertyName, TypeName) \
223
+ v8::Local<TypeName> PropertyName() const override; \
224
+ void set_##PropertyName(v8::Local<TypeName> value) override;
225
+ PER_REALM_STRONG_PERSISTENT_VALUES(V)
226
+ #undef V
227
+
228
+ protected:
229
+ v8::MaybeLocal<v8::Value> BootstrapRealm() override;
230
+ };
231
+
232
+ } // namespace node
233
+
234
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
235
+
236
+ #endif // SRC_NODE_REALM_H_
@@ -0,0 +1,43 @@
1
+ #ifndef SRC_NODE_REPORT_H_
2
+ #define SRC_NODE_REPORT_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node.h"
7
+ #include "node_buffer.h"
8
+ #include "uv.h"
9
+ #include "util.h"
10
+
11
+ #ifndef _WIN32
12
+ #include <sys/types.h>
13
+ #include <unistd.h>
14
+ #endif
15
+
16
+ #include <iomanip>
17
+ #include <sstream>
18
+
19
+ namespace node {
20
+ namespace report {
21
+ // Function declarations - utility functions in src/node_report_utils.cc
22
+ void WalkHandleNetwork(uv_handle_t* h, void* arg);
23
+ void WalkHandleNoNetwork(uv_handle_t* h, void* arg);
24
+
25
+ template <std::integral T>
26
+ std::string ValueToHexString(T value) {
27
+ std::stringstream hex;
28
+
29
+ hex << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex <<
30
+ value;
31
+ return hex.str();
32
+ }
33
+
34
+ // Function declarations - export functions in src/node_report_module.cc
35
+ void WriteReport(const v8::FunctionCallbackInfo<v8::Value>& info);
36
+ void GetReport(const v8::FunctionCallbackInfo<v8::Value>& info);
37
+
38
+ } // namespace report
39
+ } // namespace node
40
+
41
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
42
+
43
+ #endif // SRC_NODE_REPORT_H_
@@ -0,0 +1,82 @@
1
+ #ifndef SRC_NODE_REVERT_H_
2
+ #define SRC_NODE_REVERT_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node.h"
7
+
8
+ /**
9
+ * Note that it is expected for this list to vary across specific LTS and
10
+ * Stable versions! Only CVE's whose fixes require *breaking* changes within
11
+ * a given LTS or Stable may be added to this list, and only with TSC
12
+ * consensus.
13
+ *
14
+ * For *main* this list should always be empty!
15
+ **/
16
+ namespace node {
17
+
18
+ #define SECURITY_REVERSIONS(XX) \
19
+ // XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title")
20
+
21
+ enum reversion {
22
+ #define V(code, ...) SECURITY_REVERT_##code,
23
+ SECURITY_REVERSIONS(V)
24
+ #undef V
25
+ };
26
+
27
+ namespace per_process {
28
+ extern unsigned int reverted_cve;
29
+ }
30
+
31
+ #ifdef _MSC_VER
32
+ #pragma warning(push)
33
+ // MSVC C4065: switch statement contains 'default' but no 'case' labels
34
+ #pragma warning(disable : 4065)
35
+ #endif
36
+
37
+ inline const char* RevertMessage(const reversion cve) {
38
+ #define V(code, label, msg) case SECURITY_REVERT_##code: return label ": " msg;
39
+ switch (cve) {
40
+ SECURITY_REVERSIONS(V)
41
+ default:
42
+ return "Unknown";
43
+ }
44
+ #undef V
45
+ }
46
+
47
+ #ifdef _MSC_VER
48
+ #pragma warning(pop)
49
+ #endif
50
+
51
+ inline void Revert(const reversion cve) {
52
+ per_process::reverted_cve |= 1 << cve;
53
+ printf("SECURITY WARNING: Reverting %s\n", RevertMessage(cve));
54
+ }
55
+
56
+ inline void Revert(const char* cve, std::string* error) {
57
+ #define V(code, label, _) \
58
+ if (strcmp(cve, label) == 0) return Revert(SECURITY_REVERT_##code);
59
+ SECURITY_REVERSIONS(V)
60
+ #undef V
61
+ *error = "Error: Attempt to revert an unknown CVE [";
62
+ *error += cve;
63
+ *error += ']';
64
+ }
65
+
66
+ inline bool IsReverted(const reversion cve) {
67
+ return per_process::reverted_cve & (1 << cve);
68
+ }
69
+
70
+ inline bool IsReverted(const char* cve) {
71
+ #define V(code, label, _) \
72
+ if (strcmp(cve, label) == 0) return IsReverted(SECURITY_REVERT_##code);
73
+ SECURITY_REVERSIONS(V)
74
+ return false;
75
+ #undef V
76
+ }
77
+
78
+ } // namespace node
79
+
80
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
81
+
82
+ #endif // SRC_NODE_REVERT_H_