@encharm/cws 4.5.3 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/CLAUDE.md +83 -0
  3. package/README.md +20 -4
  4. package/binding.gyp +8 -2
  5. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
  7. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  8. package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
  9. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node127.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node137.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node147.node +0 -0
  13. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node127.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node147.node +0 -0
  17. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node127.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node137.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node147.node +0 -0
  21. package/dist/client.d.ts +1 -0
  22. package/dist/client.js +15 -1
  23. package/dist/index.d.ts +6 -1
  24. package/dist/index.js +2 -0
  25. package/dist/server.d.ts +1 -0
  26. package/dist/server.js +16 -2
  27. package/dist/shared.d.ts +1 -0
  28. package/dist/shared.js +3 -2
  29. package/package.json +1 -1
  30. package/src/Addon.cpp +4 -1
  31. package/src/Addon.h +80 -15
  32. package/src/Extensions.cpp +7 -1
  33. package/src/Extensions.h +2 -1
  34. package/src/Group.cpp +1 -1
  35. package/src/Group.h +4 -1
  36. package/src/HTTPSocket.cpp +1 -1
  37. package/src/Hub.cpp +11 -76
  38. package/src/Hub.h +12 -10
  39. package/src/Networking.h +11 -0
  40. package/src/Socket.h +201 -6
  41. package/src/WebSocket.cpp +8 -5
  42. package/src/Zlib.cpp +138 -0
  43. package/src/Zlib.h +38 -0
  44. package/src/cSNode.cpp +2 -0
  45. package/src/cSNode.h +4 -0
  46. package/src/headers/26/acorn_version.h +6 -0
  47. package/src/headers/26/aliased_buffer-inl.h +264 -0
  48. package/src/headers/26/aliased_buffer.h +205 -0
  49. package/src/headers/26/aliased_struct-inl.h +143 -0
  50. package/src/headers/26/aliased_struct.h +248 -0
  51. package/src/headers/26/amaro_version.h +6 -0
  52. package/src/headers/26/async_context_frame.h +33 -0
  53. package/src/headers/26/async_wrap-inl.h +123 -0
  54. package/src/headers/26/async_wrap.h +254 -0
  55. package/src/headers/26/base_object-inl.h +333 -0
  56. package/src/headers/26/base_object.h +339 -0
  57. package/src/headers/26/base_object_types.h +76 -0
  58. package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
  59. package/src/headers/26/blob_serializer_deserializer.h +142 -0
  60. package/src/headers/26/builtin_info.h +57 -0
  61. package/src/headers/26/callback_queue-inl.h +97 -0
  62. package/src/headers/26/callback_queue.h +79 -0
  63. package/src/headers/26/cares_wrap.h +475 -0
  64. package/src/headers/26/cleanup_queue-inl.h +36 -0
  65. package/src/headers/26/cleanup_queue.h +79 -0
  66. package/src/headers/26/compile_cache.h +134 -0
  67. package/src/headers/26/connect_wrap.h +26 -0
  68. package/src/headers/26/connection_wrap.h +30 -0
  69. package/src/headers/26/cppgc_helpers-inl.h +69 -0
  70. package/src/headers/26/cppgc_helpers.h +162 -0
  71. package/src/headers/26/crypto/crypto_aes.h +107 -0
  72. package/src/headers/26/crypto/crypto_argon2.h +88 -0
  73. package/src/headers/26/crypto/crypto_bio.h +193 -0
  74. package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
  75. package/src/headers/26/crypto/crypto_cipher.h +291 -0
  76. package/src/headers/26/crypto/crypto_common.h +48 -0
  77. package/src/headers/26/crypto/crypto_context.h +219 -0
  78. package/src/headers/26/crypto/crypto_dh.h +104 -0
  79. package/src/headers/26/crypto/crypto_dsa.h +50 -0
  80. package/src/headers/26/crypto/crypto_ec.h +102 -0
  81. package/src/headers/26/crypto/crypto_hash.h +157 -0
  82. package/src/headers/26/crypto/crypto_hkdf.h +62 -0
  83. package/src/headers/26/crypto/crypto_hmac.h +92 -0
  84. package/src/headers/26/crypto/crypto_kem.h +131 -0
  85. package/src/headers/26/crypto/crypto_keygen.h +382 -0
  86. package/src/headers/26/crypto/crypto_keys.h +366 -0
  87. package/src/headers/26/crypto/crypto_kmac.h +79 -0
  88. package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
  89. package/src/headers/26/crypto/crypto_pqc.h +39 -0
  90. package/src/headers/26/crypto/crypto_random.h +127 -0
  91. package/src/headers/26/crypto/crypto_rsa.h +108 -0
  92. package/src/headers/26/crypto/crypto_scrypt.h +85 -0
  93. package/src/headers/26/crypto/crypto_sig.h +159 -0
  94. package/src/headers/26/crypto/crypto_spkac.h +21 -0
  95. package/src/headers/26/crypto/crypto_timing.h +20 -0
  96. package/src/headers/26/crypto/crypto_tls.h +342 -0
  97. package/src/headers/26/crypto/crypto_turboshake.h +105 -0
  98. package/src/headers/26/crypto/crypto_util.h +775 -0
  99. package/src/headers/26/crypto/crypto_x509.h +140 -0
  100. package/src/headers/26/dataqueue/queue.h +311 -0
  101. package/src/headers/26/debug_utils-inl.h +291 -0
  102. package/src/headers/26/debug_utils.h +200 -0
  103. package/src/headers/26/diagnosticfilename-inl.h +33 -0
  104. package/src/headers/26/embedded_data.h +17 -0
  105. package/src/headers/26/encoding_binding.h +59 -0
  106. package/src/headers/26/env-inl.h +956 -0
  107. package/src/headers/26/env.h +1294 -0
  108. package/src/headers/26/env_properties.h +562 -0
  109. package/src/headers/26/ffi/data.h +30 -0
  110. package/src/headers/26/ffi/fast.h +96 -0
  111. package/src/headers/26/ffi/jit_memory.h +26 -0
  112. package/src/headers/26/ffi/types.h +99 -0
  113. package/src/headers/26/handle_wrap.h +123 -0
  114. package/src/headers/26/histogram-inl.h +211 -0
  115. package/src/headers/26/histogram.h +474 -0
  116. package/src/headers/26/inspector/dom_storage_agent.h +68 -0
  117. package/src/headers/26/inspector/inspector_object_utils.h +38 -0
  118. package/src/headers/26/inspector/io_agent.h +30 -0
  119. package/src/headers/26/inspector/main_thread_interface.h +116 -0
  120. package/src/headers/26/inspector/network_agent.h +110 -0
  121. package/src/headers/26/inspector/network_inspector.h +45 -0
  122. package/src/headers/26/inspector/network_requests_buffer.h +195 -0
  123. package/src/headers/26/inspector/network_resource_manager.h +29 -0
  124. package/src/headers/26/inspector/node_json.h +24 -0
  125. package/src/headers/26/inspector/node_string.h +101 -0
  126. package/src/headers/26/inspector/notification_emitter.h +38 -0
  127. package/src/headers/26/inspector/protocol_helper.h +27 -0
  128. package/src/headers/26/inspector/runtime_agent.h +41 -0
  129. package/src/headers/26/inspector/storage_agent.h +33 -0
  130. package/src/headers/26/inspector/target_agent.h +59 -0
  131. package/src/headers/26/inspector/target_manager.h +70 -0
  132. package/src/headers/26/inspector/tracing_agent.h +43 -0
  133. package/src/headers/26/inspector/worker_agent.h +40 -0
  134. package/src/headers/26/inspector/worker_inspector.h +124 -0
  135. package/src/headers/26/inspector_agent.h +168 -0
  136. package/src/headers/26/inspector_io.h +78 -0
  137. package/src/headers/26/inspector_profiler.h +149 -0
  138. package/src/headers/26/inspector_socket.h +60 -0
  139. package/src/headers/26/inspector_socket_server.h +110 -0
  140. package/src/headers/26/js_native_api.h +634 -0
  141. package/src/headers/26/js_native_api_types.h +244 -0
  142. package/src/headers/26/js_native_api_v8.h +485 -0
  143. package/src/headers/26/js_native_api_v8_internals.h +45 -0
  144. package/src/headers/26/js_stream.h +57 -0
  145. package/src/headers/26/json_utils.h +172 -0
  146. package/src/headers/26/large_pages/node_large_page.h +34 -0
  147. package/src/headers/26/lru_cache-inl.h +69 -0
  148. package/src/headers/26/memory_tracker-inl.h +461 -0
  149. package/src/headers/26/memory_tracker.h +341 -0
  150. package/src/headers/26/module_wrap.h +231 -0
  151. package/src/headers/26/ncrypto.h +2008 -0
  152. package/src/headers/26/node.h +1693 -0
  153. package/src/headers/26/node_api.h +265 -0
  154. package/src/headers/26/node_api_internals.h +48 -0
  155. package/src/headers/26/node_api_types.h +58 -0
  156. package/src/headers/26/node_binding.h +170 -0
  157. package/src/headers/26/node_blob.h +160 -0
  158. package/src/headers/26/node_bob-inl.h +36 -0
  159. package/src/headers/26/node_bob.h +107 -0
  160. package/src/headers/26/node_buffer.h +92 -0
  161. package/src/headers/26/node_builtins.h +239 -0
  162. package/src/headers/26/node_concepts.h +46 -0
  163. package/src/headers/26/node_config_file.h +77 -0
  164. package/src/headers/26/node_constants.h +82 -0
  165. package/src/headers/26/node_context_data.h +171 -0
  166. package/src/headers/26/node_contextify.h +261 -0
  167. package/src/headers/26/node_crypto.h +66 -0
  168. package/src/headers/26/node_debug.h +30 -0
  169. package/src/headers/26/node_diagnostics_channel.h +121 -0
  170. package/src/headers/26/node_dir.h +52 -0
  171. package/src/headers/26/node_dotenv.h +45 -0
  172. package/src/headers/26/node_errors.h +378 -0
  173. package/src/headers/26/node_exit_code.h +54 -0
  174. package/src/headers/26/node_external_reference.h +171 -0
  175. package/src/headers/26/node_ffi.h +212 -0
  176. package/src/headers/26/node_file-inl.h +421 -0
  177. package/src/headers/26/node_file.h +561 -0
  178. package/src/headers/26/node_file_utils.h +39 -0
  179. package/src/headers/26/node_hash.h +212 -0
  180. package/src/headers/26/node_http2.h +1202 -0
  181. package/src/headers/26/node_http2_state.h +159 -0
  182. package/src/headers/26/node_http_common-inl.h +199 -0
  183. package/src/headers/26/node_http_common.h +535 -0
  184. package/src/headers/26/node_i18n.h +132 -0
  185. package/src/headers/26/node_internals.h +485 -0
  186. package/src/headers/26/node_locks.h +184 -0
  187. package/src/headers/26/node_main_instance.h +67 -0
  188. package/src/headers/26/node_mem-inl.h +113 -0
  189. package/src/headers/26/node_mem.h +45 -0
  190. package/src/headers/26/node_messaging.h +389 -0
  191. package/src/headers/26/node_metadata.h +172 -0
  192. package/src/headers/26/node_modules.h +102 -0
  193. package/src/headers/26/node_mutex.h +323 -0
  194. package/src/headers/26/node_object_wrap.h +145 -0
  195. package/src/headers/26/node_options-inl.h +524 -0
  196. package/src/headers/26/node_options.h +710 -0
  197. package/src/headers/26/node_perf.h +167 -0
  198. package/src/headers/26/node_perf_common.h +103 -0
  199. package/src/headers/26/node_platform.h +290 -0
  200. package/src/headers/26/node_process-inl.h +26 -0
  201. package/src/headers/26/node_process.h +112 -0
  202. package/src/headers/26/node_profiling.h +38 -0
  203. package/src/headers/26/node_realm-inl.h +156 -0
  204. package/src/headers/26/node_realm.h +236 -0
  205. package/src/headers/26/node_report.h +43 -0
  206. package/src/headers/26/node_revert.h +82 -0
  207. package/src/headers/26/node_root_certs.h +2937 -0
  208. package/src/headers/26/node_sea.h +101 -0
  209. package/src/headers/26/node_shadow_realm.h +46 -0
  210. package/src/headers/26/node_snapshot_builder.h +57 -0
  211. package/src/headers/26/node_snapshotable.h +167 -0
  212. package/src/headers/26/node_sockaddr-inl.h +248 -0
  213. package/src/headers/26/node_sockaddr.h +459 -0
  214. package/src/headers/26/node_sqlite.h +607 -0
  215. package/src/headers/26/node_stat_watcher.h +73 -0
  216. package/src/headers/26/node_task_runner.h +92 -0
  217. package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
  218. package/src/headers/26/node_threadsafe_cow.h +105 -0
  219. package/src/headers/26/node_union_bytes.h +81 -0
  220. package/src/headers/26/node_url.h +101 -0
  221. package/src/headers/26/node_url_pattern.h +118 -0
  222. package/src/headers/26/node_v8.h +78 -0
  223. package/src/headers/26/node_v8_embedder.h +26 -0
  224. package/src/headers/26/node_v8_platform-inl.h +96 -0
  225. package/src/headers/26/node_version.h +116 -0
  226. package/src/headers/26/node_wasi.h +184 -0
  227. package/src/headers/26/node_wasm_web_api.h +55 -0
  228. package/src/headers/26/node_watchdog.h +164 -0
  229. package/src/headers/26/node_webstorage.h +62 -0
  230. package/src/headers/26/node_worker.h +162 -0
  231. package/src/headers/26/path.h +36 -0
  232. package/src/headers/26/permission/boolean_permission.h +50 -0
  233. package/src/headers/26/permission/fs_permission.h +192 -0
  234. package/src/headers/26/permission/permission.h +155 -0
  235. package/src/headers/26/permission/permission_base.h +79 -0
  236. package/src/headers/26/pipe_wrap.h +80 -0
  237. package/src/headers/26/quic/application.h +279 -0
  238. package/src/headers/26/quic/arena.h +373 -0
  239. package/src/headers/26/quic/bindingdata.h +440 -0
  240. package/src/headers/26/quic/cid.h +127 -0
  241. package/src/headers/26/quic/data.h +358 -0
  242. package/src/headers/26/quic/defs.h +417 -0
  243. package/src/headers/26/quic/endpoint.h +519 -0
  244. package/src/headers/26/quic/guard.h +5 -0
  245. package/src/headers/26/quic/http3.h +25 -0
  246. package/src/headers/26/quic/packet.h +166 -0
  247. package/src/headers/26/quic/preferredaddress.h +72 -0
  248. package/src/headers/26/quic/session.h +770 -0
  249. package/src/headers/26/quic/session_manager.h +107 -0
  250. package/src/headers/26/quic/sessionticket.h +110 -0
  251. package/src/headers/26/quic/streams.h +518 -0
  252. package/src/headers/26/quic/tlscontext.h +353 -0
  253. package/src/headers/26/quic/tokens.h +263 -0
  254. package/src/headers/26/quic/transportparams.h +184 -0
  255. package/src/headers/26/req_wrap-inl.h +175 -0
  256. package/src/headers/26/req_wrap.h +79 -0
  257. package/src/headers/26/spawn_sync.h +243 -0
  258. package/src/headers/26/stream_base-inl.h +170 -0
  259. package/src/headers/26/stream_base.h +487 -0
  260. package/src/headers/26/stream_pipe.h +76 -0
  261. package/src/headers/26/stream_wrap.h +137 -0
  262. package/src/headers/26/string_bytes.h +114 -0
  263. package/src/headers/26/string_decoder-inl.h +31 -0
  264. package/src/headers/26/string_decoder.h +49 -0
  265. package/src/headers/26/tcp_wrap.h +138 -0
  266. package/src/headers/26/threadpoolwork-inl.h +70 -0
  267. package/src/headers/26/timer_wrap-inl.h +32 -0
  268. package/src/headers/26/timer_wrap.h +87 -0
  269. package/src/headers/26/timers.h +70 -0
  270. package/src/headers/26/tracing/agent.h +125 -0
  271. package/src/headers/26/tracing/agent_legacy.h +146 -0
  272. package/src/headers/26/tracing/agent_perfetto.h +145 -0
  273. package/src/headers/26/tracing/node_trace_buffer.h +91 -0
  274. package/src/headers/26/tracing/node_trace_writer.h +79 -0
  275. package/src/headers/26/tracing/trace_event.h +27 -0
  276. package/src/headers/26/tracing/trace_event_helper.h +40 -0
  277. package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
  278. package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
  279. package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
  280. package/src/headers/26/tracing/traced_value.h +167 -0
  281. package/src/headers/26/tty_wrap.h +65 -0
  282. package/src/headers/26/udp_wrap.h +231 -0
  283. package/src/headers/26/undici_version.h +6 -0
  284. package/src/headers/26/util-inl.h +788 -0
  285. package/src/headers/26/util.h +1207 -0
  286. package/src/headers/26/v8-cpp-heap-external.h +56 -0
  287. package/src/headers/26/v8-external-memory-accounter.h +60 -0
  288. package/src/headers/26/v8-fast-api-calls.h +784 -0
  289. package/src/headers/26/v8-inspector-protocol.h +13 -0
  290. package/src/headers/26/v8-inspector.h +458 -0
  291. package/src/headers/26/v8-metrics.h +273 -0
  292. package/src/headers/26/v8-trace-categories.h +28 -0
  293. package/src/headers/26/v8-unwinder-state.h +30 -0
  294. package/src/headers/26/v8-util.h +549 -0
  295. package/src/headers/26/v8-value-serializer-version.h +24 -0
  296. package/src/headers/26/v8-version-string.h +38 -0
  297. package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
  298. package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
  299. package/src/headers/26/zlib_version.h +6 -0
  300. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +0 -20
  301. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
  302. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +0 -931
  303. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +0 -20
  304. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
  305. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +0 -931
@@ -0,0 +1,171 @@
1
+ #ifndef SRC_NODE_CONTEXT_DATA_H_
2
+ #define SRC_NODE_CONTEXT_DATA_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node_v8_embedder.h"
7
+ #include "util.h"
8
+ #include "v8.h"
9
+
10
+ namespace node {
11
+
12
+ // Pick an index that's hopefully out of the way when we're embedded inside
13
+ // another application. Performance-wise or memory-wise it doesn't matter:
14
+ // Context::SetAlignedPointerInEmbedderData() is backed by a FixedArray,
15
+ // worst case we pay a one-time penalty for resizing the array.
16
+ #ifndef NODE_CONTEXT_EMBEDDER_DATA_INDEX
17
+ #define NODE_CONTEXT_EMBEDDER_DATA_INDEX 32
18
+ #endif
19
+
20
+ #ifndef NODE_CONTEXT_SANDBOX_OBJECT_INDEX
21
+ #define NODE_CONTEXT_SANDBOX_OBJECT_INDEX 33
22
+ #endif
23
+
24
+ #ifndef NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX
25
+ #define NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX 34
26
+ #endif
27
+
28
+ #ifndef NODE_BINDING_DATA_STORE_INDEX
29
+ #define NODE_BINDING_DATA_STORE_INDEX 35
30
+ #endif
31
+
32
+ #ifndef NODE_CONTEXT_ALLOW_CODE_GENERATION_FROM_STRINGS_INDEX
33
+ #define NODE_CONTEXT_ALLOW_CODE_GENERATION_FROM_STRINGS_INDEX 36
34
+ #endif
35
+
36
+ #ifndef NODE_CONTEXT_CONTEXTIFY_CONTEXT_INDEX
37
+ #define NODE_CONTEXT_CONTEXTIFY_CONTEXT_INDEX 37
38
+ #endif
39
+
40
+ #ifndef NODE_CONTEXT_REALM_INDEX
41
+ #define NODE_CONTEXT_REALM_INDEX 38
42
+ #endif
43
+
44
+ // NODE_CONTEXT_TAG must be greater than any embedder indexes so that a single
45
+ // check on the number of embedder data fields can assure the presence of all
46
+ // embedder indexes.
47
+ #ifndef NODE_CONTEXT_TAG
48
+ #define NODE_CONTEXT_TAG 39
49
+ #endif
50
+
51
+ /**
52
+ * These are indexes used to set Node.js-specific data in the V8 contexts
53
+ * via v8::Context::SetAlignedPointerInEmbedderData() (for pointers) and
54
+ * v8::Context::SetEmbedderData() (for v8::Values).
55
+ *
56
+ * There are five types of contexts in Node.js:
57
+ * 1. Default V8 context, with nothing Node.js-specific. This is normally only
58
+ * created by the embedders that uses v8::Context APIs directly and is not
59
+ * available through the Node.js JS APIs. Its context snapshot in the
60
+ * built-in v8 startup snapshot is stored using
61
+ * v8::SnapshotCreator::SetDefaultContext() - effectively at index 0.
62
+ * 2. Default Node.js main context. When Node.js is launched typically there is
63
+ * a main thread on which a main node::Environment is created. The
64
+ * Environment is associated with its own v8::Isolate (env->isolate()) and a
65
+ * main v8::Context (env->context()). The corresponding data structure is
66
+ * node::NodeMainInstance and the Environment is created in
67
+ * node::NodeMainInstance::Run(). Its context snapshot in the built-in V8
68
+ * startup snapshot is stored at node::SnapshotData::kNodeMainContextIndex.
69
+ * 3. Node.js worker context. When a Worker instance is created via
70
+ * new worker_threads.Worker(), it gets its own OS thread, its
71
+ * own node::Environment, its own v8::Isolate and its own v8::Context.
72
+ * The corresponding data structure is node::Worker and the Environment
73
+ * is created in node::Worker::Run().
74
+ * Its context snapshot in the built-in V8 startup snapshot is stored at
75
+ * node::SnapshotData::kNodeBaseContextIndex.
76
+ * 4. Contextified vm context: When a contextified context is created via
77
+ * vm.createContext() or other related vm APIs, the vm.Context instance
78
+ * gets its own v8::Context. It shares the thread, the v8::Isolate and
79
+ * the node::Environment with the context where the vm APIs are called.
80
+ * The corresponding data structure is node::ContextifyContext and
81
+ * the initialization code is in node::ContextifyContext::New().
82
+ * Its context snapshot in the built-in V8 startup snapshot is stored at
83
+ * node::SnapshotData::kNodeVMContextIndex.
84
+ * 5. ShadowRealm context: When a JS ShadowRealm is created via new ShadowRealm,
85
+ * it gets its own v8::Context. It also shares the thread, the v8::Isolate
86
+ * and the node::Environment with the context where the ShadowRealm
87
+ * constructor is called. The corresponding data structure is
88
+ * node::ShadowRealm and the initialization code is in
89
+ * node::ShadowRealm::New().
90
+ */
91
+ enum ContextEmbedderIndex {
92
+ // Pointer to the node::Environment associated with the context. Only set for
93
+ // context type 2-5. Used by Environment::GetCurrent(context) to retrieve
94
+ // the node::Environment associated with any Node.js context in the
95
+ // V8 callbacks.
96
+ kEnvironment = NODE_CONTEXT_EMBEDDER_DATA_INDEX,
97
+ // A v8::Value which is the sandbox object used to create the contextified vm
98
+ // context. For example the first argument of vm.createContext().
99
+ // Only set for context type 4 and used in ContextifyContext methods.
100
+ kSandboxObject = NODE_CONTEXT_SANDBOX_OBJECT_INDEX,
101
+ // A v8::Value indicating whether the context allows WebAssembly code
102
+ // generation.
103
+ // Only set for context type 2-5, and for them the default is v8::True.
104
+ // For context type 4 it's configurable via options.codeGeneration.wasm in the
105
+ // vm APIs. Used in the default v8::AllowWasmCodeGenerationCallback.
106
+ kAllowWasmCodeGeneration = NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX,
107
+ // A v8::Value indicating whether the context allows code generation via
108
+ // eval() or new Function().
109
+ // Only set for context type 2-5, and for them the default is v8::True.
110
+ // For context type 4 it's configurable via options.codeGeneration.strings in
111
+ // the
112
+ // vm APIs. Used in the default v8::AllowCodeGenerationFromStringsCallback.
113
+ kAllowCodeGenerationFromStrings =
114
+ NODE_CONTEXT_ALLOW_CODE_GENERATION_FROM_STRINGS_INDEX,
115
+ // Pointer to the node::ContextifyContext associated with vm.Contexts.
116
+ // Only set for context type 4. Used by ContextifyContext::Get() to get
117
+ // to the ContextifyContext from the property interceptors.
118
+ kContextifyContext = NODE_CONTEXT_CONTEXTIFY_CONTEXT_INDEX,
119
+ // Pointer to the node::Realm associated with the context.
120
+ // Only set for context type 2-3 and 5. For context type 2-3, it points to a
121
+ // node::PrincipalRealm. For context type 5 it points to a node::ShadowRealm.
122
+ // Used by Realm::GetCurrent(context) to retrieve the associated node::Realm
123
+ // with any Node.js context in the V8 callbacks.
124
+ kRealm = NODE_CONTEXT_REALM_INDEX,
125
+ // Pointer to a constant address which is
126
+ // node::ContextEmbedderTag::kNodeContextTagPtr.
127
+ // Only set for context type 2-5. Used by ContextEmbedderTag::IsNodeContext()
128
+ // to check whether a context is a Node.js context.
129
+ kContextTag = NODE_CONTEXT_TAG,
130
+ };
131
+
132
+ class ContextEmbedderTag {
133
+ public:
134
+ static inline void TagNodeContext(v8::Local<v8::Context> context) {
135
+ // Used by ContextEmbedderTag::IsNodeContext to know that we are on a node
136
+ // context.
137
+ context->SetAlignedPointerInEmbedderData(
138
+ ContextEmbedderIndex::kContextTag,
139
+ ContextEmbedderTag::kNodeContextTagPtr,
140
+ EmbedderDataTag::kPerContextData);
141
+ }
142
+
143
+ static inline bool IsNodeContext(v8::Local<v8::Context> context) {
144
+ if (context.IsEmpty()) [[unlikely]] {
145
+ return false;
146
+ }
147
+ if (context->GetNumberOfEmbedderDataFields() <=
148
+ ContextEmbedderIndex::kContextTag) [[unlikely]] {
149
+ return false;
150
+ }
151
+ if (context->GetAlignedPointerFromEmbedderData(
152
+ ContextEmbedderIndex::kContextTag,
153
+ EmbedderDataTag::kPerContextData) !=
154
+ ContextEmbedderTag::kNodeContextTagPtr) [[unlikely]] {
155
+ return false;
156
+ }
157
+ return true;
158
+ }
159
+
160
+ private:
161
+ static void* const kNodeContextTagPtr;
162
+ static int const kNodeContextTag;
163
+
164
+ ContextEmbedderTag() = delete;
165
+ };
166
+
167
+ } // namespace node
168
+
169
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
170
+
171
+ #endif // SRC_NODE_CONTEXT_DATA_H_
@@ -0,0 +1,261 @@
1
+ #ifndef SRC_NODE_CONTEXTIFY_H_
2
+ #define SRC_NODE_CONTEXTIFY_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "base_object-inl.h"
7
+ #include "cppgc_helpers-inl.h"
8
+ #include "node_context_data.h"
9
+ #include "node_errors.h"
10
+
11
+ namespace node {
12
+ class ExternalReferenceRegistry;
13
+
14
+ namespace contextify {
15
+
16
+ struct ContextOptions {
17
+ v8::Local<v8::String> name;
18
+ v8::Local<v8::String> origin;
19
+ v8::Local<v8::Boolean> allow_code_gen_strings;
20
+ v8::Local<v8::Boolean> allow_code_gen_wasm;
21
+ std::unique_ptr<v8::MicrotaskQueue> own_microtask_queue;
22
+ v8::Local<v8::Symbol> host_defined_options_id;
23
+ bool vanilla = false;
24
+ };
25
+
26
+ /**
27
+ * The memory management of a vm context is as follows:
28
+ *
29
+ * user code
30
+ * │
31
+ * As global proxy or ▼
32
+ * ┌──────────────┐ kSandboxObject embedder data ┌────────────────┐
33
+ * ┌─► │ V8 Context │────────────────────────────────►│ Wrapper holder │
34
+ * │ └──────────────┘ └───────┬────────┘
35
+ * │ ▲ Object constructor/creation context │
36
+ * │ │ │
37
+ * │ ┌──────┴────────────┐ contextify_context_private_symbol │
38
+ * │ │ ContextifyContext │◄────────────────────────────────────┘
39
+ * │ │ JS Wrapper │◄──────────► ┌─────────────────────────┐
40
+ * │ └───────────────────┘ cppgc │ node::ContextifyContext │
41
+ * │ │ C++ Object │
42
+ * └──────────────────────────────────► └─────────────────────────┘
43
+ * v8::TracedReference / ContextEmbedderIndex::kContextifyContext
44
+ *
45
+ * There are two possibilities for the "wrapper holder":
46
+ *
47
+ * 1. When vm.constants.DONT_CONTEXTIFY is used, the wrapper holder is the V8
48
+ * context's global proxy object
49
+ * 2. Otherwise it's the arbitrary "sandbox object" that users pass into
50
+ * vm.createContext() or a new empty object created internally if they pass
51
+ * undefined.
52
+ *
53
+ * In 2, the global object of the new V8 context is created using
54
+ * global_object_template with interceptors that perform any requested
55
+ * operations on the global object in the context first on the sandbox object
56
+ * living outside of the new context, then fall back to the global proxy of the
57
+ * new context.
58
+ *
59
+ * It's critical for the user-accessible wrapper holder to keep the
60
+ * ContextifyContext wrapper alive via contextify_context_private_symbol
61
+ * so that the V8 context is always available to the user while they still
62
+ * hold the vm "context" object alive.
63
+ *
64
+ * It's also critical for the V8 context to keep the wrapper holder
65
+ * (specifically, the "sandbox object" if users pass one) as well as the
66
+ * node::ContextifyContext C++ object alive, so that when the code
67
+ * runs inside the object and accesses the global object, the interceptors
68
+ * can still access the "sandbox object" and perform operations
69
+ * on them, even if users already relinquish access to the outer
70
+ * "sandbox object".
71
+ *
72
+ * The v8::TracedReference and the ContextEmbedderIndex::kContextifyContext
73
+ * slot in the context only act as shortcuts between
74
+ * the node::ContextifyContext C++ object and the V8 context.
75
+ */
76
+ class ContextifyContext final : CPPGC_MIXIN(ContextifyContext) {
77
+ public:
78
+ SET_CPPGC_NAME(ContextifyContext)
79
+ void Trace(cppgc::Visitor* visitor) const final;
80
+ SET_NO_MEMORY_INFO()
81
+
82
+ ContextifyContext(Environment* env,
83
+ v8::Local<v8::Object> wrapper,
84
+ v8::Local<v8::Context> v8_context,
85
+ ContextOptions* options);
86
+
87
+ // The destructors don't need to do anything because when the wrapper is
88
+ // going away, the context is already going away or otherwise it would've
89
+ // been holding the wrapper alive, so there's no need to reset the pointers
90
+ // in the context. Also, any global handles to the context would've been
91
+ // empty at this point, and the per-Environment context tracking code is
92
+ // capable of dealing with empty handles from contexts purged elsewhere.
93
+ ~ContextifyContext() = default;
94
+
95
+ static v8::MaybeLocal<v8::Context> CreateV8Context(
96
+ v8::Isolate* isolate,
97
+ v8::Local<v8::ObjectTemplate> object_template,
98
+ const SnapshotData* snapshot_data,
99
+ v8::MicrotaskQueue* queue);
100
+ static void CreatePerIsolateProperties(IsolateData* isolate_data,
101
+ v8::Local<v8::ObjectTemplate> target);
102
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
103
+
104
+ static ContextifyContext* ContextFromContextifiedSandbox(
105
+ Environment* env, const v8::Local<v8::Object>& wrapper_holder);
106
+
107
+ inline v8::Local<v8::Context> context() const {
108
+ return context_.Get(env()->isolate());
109
+ }
110
+
111
+ inline v8::Local<v8::Object> global_proxy() const {
112
+ return context()->Global();
113
+ }
114
+
115
+ inline v8::Local<v8::Object> sandbox() const {
116
+ // Only vanilla contexts have undefined sandboxes. sandbox() is only used by
117
+ // interceptors who are not supposed to be called on vanilla contexts.
118
+ v8::Local<v8::Value> result =
119
+ context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject);
120
+ CHECK(!result->IsUndefined());
121
+ return result.As<v8::Object>();
122
+ }
123
+
124
+ inline v8::MicrotaskQueue* microtask_queue() const {
125
+ return microtask_queue_.get();
126
+ }
127
+
128
+ template <typename T>
129
+ static ContextifyContext* Get(const v8::PropertyCallbackInfo<T>& args);
130
+ static ContextifyContext* Get(v8::Local<v8::Object> object);
131
+
132
+ static void InitializeGlobalTemplates(IsolateData* isolate_data);
133
+
134
+ private:
135
+ static ContextifyContext* New(Environment* env,
136
+ v8::Local<v8::Object> sandbox_obj,
137
+ ContextOptions* options);
138
+ // Initialize a context created from CreateV8Context()
139
+ static ContextifyContext* New(v8::Local<v8::Context> ctx,
140
+ Environment* env,
141
+ v8::Local<v8::Object> sandbox_obj,
142
+ ContextOptions* options);
143
+
144
+ static bool IsStillInitializing(const ContextifyContext* ctx);
145
+ static void MakeContext(const v8::FunctionCallbackInfo<v8::Value>& args);
146
+ static void IsContext(const v8::FunctionCallbackInfo<v8::Value>& args);
147
+ static v8::Intercepted PropertyQueryCallback(
148
+ v8::Local<v8::Name> property,
149
+ const v8::PropertyCallbackInfo<v8::Integer>& args);
150
+ static v8::Intercepted PropertyGetterCallback(
151
+ v8::Local<v8::Name> property,
152
+ const v8::PropertyCallbackInfo<v8::Value>& args);
153
+ static v8::Intercepted PropertySetterCallback(
154
+ v8::Local<v8::Name> property,
155
+ v8::Local<v8::Value> value,
156
+ const v8::PropertyCallbackInfo<void>& args);
157
+ static v8::Intercepted PropertyDescriptorCallback(
158
+ v8::Local<v8::Name> property,
159
+ const v8::PropertyCallbackInfo<v8::Value>& args);
160
+ static v8::Intercepted PropertyDefinerCallback(
161
+ v8::Local<v8::Name> property,
162
+ const v8::PropertyDescriptor& desc,
163
+ const v8::PropertyCallbackInfo<void>& args);
164
+ static v8::Intercepted PropertyDeleterCallback(
165
+ v8::Local<v8::Name> property,
166
+ const v8::PropertyCallbackInfo<v8::Boolean>& args);
167
+ static void PropertyEnumeratorCallback(
168
+ const v8::PropertyCallbackInfo<v8::Array>& args);
169
+ static v8::Intercepted IndexedPropertyQueryCallback(
170
+ uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& args);
171
+ static v8::Intercepted IndexedPropertyGetterCallback(
172
+ uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args);
173
+ static v8::Intercepted IndexedPropertySetterCallback(
174
+ uint32_t index,
175
+ v8::Local<v8::Value> value,
176
+ const v8::PropertyCallbackInfo<void>& args);
177
+ static v8::Intercepted IndexedPropertyDescriptorCallback(
178
+ uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args);
179
+ static v8::Intercepted IndexedPropertyDefinerCallback(
180
+ uint32_t index,
181
+ const v8::PropertyDescriptor& desc,
182
+ const v8::PropertyCallbackInfo<void>& args);
183
+ static v8::Intercepted IndexedPropertyDeleterCallback(
184
+ uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& args);
185
+ static void IndexedPropertyEnumeratorCallback(
186
+ const v8::PropertyCallbackInfo<v8::Array>& args);
187
+
188
+ v8::TracedReference<v8::Context> context_;
189
+ std::unique_ptr<v8::MicrotaskQueue> microtask_queue_;
190
+ };
191
+
192
+ class ContextifyScript final : CPPGC_MIXIN(ContextifyScript) {
193
+ public:
194
+ SET_CPPGC_NAME(ContextifyScript)
195
+ void Trace(cppgc::Visitor* visitor) const final;
196
+ SET_NO_MEMORY_INFO()
197
+
198
+ ContextifyScript(Environment* env, v8::Local<v8::Object> object);
199
+ ~ContextifyScript() override;
200
+
201
+ v8::Local<v8::UnboundScript> unbound_script() const;
202
+ void set_unbound_script(v8::Local<v8::UnboundScript>);
203
+
204
+ static void CreatePerIsolateProperties(IsolateData* isolate_data,
205
+ v8::Local<v8::ObjectTemplate> target);
206
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
207
+ static ContextifyScript* New(Environment* env, v8::Local<v8::Object> object);
208
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
209
+ static bool InstanceOf(Environment* env, const v8::Local<v8::Value>& args);
210
+ static void CreateCachedData(const v8::FunctionCallbackInfo<v8::Value>& args);
211
+ static void RunInContext(const v8::FunctionCallbackInfo<v8::Value>& args);
212
+ static bool EvalMachine(v8::Local<v8::Context> context,
213
+ Environment* env,
214
+ const int64_t timeout,
215
+ const bool display_errors,
216
+ const bool break_on_sigint,
217
+ const bool break_on_first_line,
218
+ v8::MicrotaskQueue* microtask_queue,
219
+ const v8::FunctionCallbackInfo<v8::Value>& args);
220
+
221
+ private:
222
+ v8::TracedReference<v8::UnboundScript> script_;
223
+ };
224
+
225
+ class ContextifyFunction final {
226
+ public:
227
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
228
+ static void CreatePerIsolateProperties(IsolateData* isolate_data,
229
+ v8::Local<v8::ObjectTemplate> target);
230
+
231
+ static void CompileFunction(const v8::FunctionCallbackInfo<v8::Value>& args);
232
+ static v8::MaybeLocal<v8::Object> CompileFunctionAndCacheResult(
233
+ Environment* env,
234
+ v8::Local<v8::Context> parsing_context,
235
+ v8::ScriptCompiler::Source* source,
236
+ v8::LocalVector<v8::String> params,
237
+ v8::LocalVector<v8::Object> context_extensions,
238
+ v8::ScriptCompiler::CompileOptions options,
239
+ bool produce_cached_data,
240
+ v8::Local<v8::Symbol> id_symbol,
241
+ const errors::TryCatchScope& try_catch);
242
+
243
+ private:
244
+ ContextifyFunction() = delete;
245
+ ~ContextifyFunction() = delete;
246
+ };
247
+
248
+ v8::Maybe<void> StoreCodeCacheResult(
249
+ Environment* env,
250
+ v8::Local<v8::Object> target,
251
+ v8::ScriptCompiler::CompileOptions compile_options,
252
+ const v8::ScriptCompiler::Source& source,
253
+ bool produce_cached_data,
254
+ std::unique_ptr<v8::ScriptCompiler::CachedData> new_cached_data);
255
+
256
+ } // namespace contextify
257
+ } // namespace node
258
+
259
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
260
+
261
+ #endif // SRC_NODE_CONTEXTIFY_H_
@@ -0,0 +1,66 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ #ifndef SRC_NODE_CRYPTO_H_
23
+ #define SRC_NODE_CRYPTO_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ // All of the crypto definitions previously contained in this header
28
+ // have been split across multiple headers in src/crypto. This header
29
+ // remains for convenience for any code that still imports it. New
30
+ // code should include the relevant src/crypto headers directly.
31
+ #include "crypto/crypto_aes.h"
32
+ #include "crypto/crypto_argon2.h"
33
+ #include "crypto/crypto_bio.h"
34
+ #include "crypto/crypto_chacha20_poly1305.h"
35
+ #include "crypto/crypto_cipher.h"
36
+ #include "crypto/crypto_context.h"
37
+ #include "crypto/crypto_dh.h"
38
+ #include "crypto/crypto_dsa.h"
39
+ #include "crypto/crypto_ec.h"
40
+ #include "crypto/crypto_hash.h"
41
+ #include "crypto/crypto_hkdf.h"
42
+ #include "crypto/crypto_hmac.h"
43
+ #if OPENSSL_WITH_KEM
44
+ #include "crypto/crypto_kem.h"
45
+ #endif
46
+ #if OPENSSL_WITH_EVP_MAC
47
+ #include "crypto/crypto_kmac.h"
48
+ #endif
49
+ #include "crypto/crypto_keygen.h"
50
+ #include "crypto/crypto_keys.h"
51
+ #include "crypto/crypto_pbkdf2.h"
52
+ #include "crypto/crypto_pqc.h"
53
+ #include "crypto/crypto_random.h"
54
+ #include "crypto/crypto_rsa.h"
55
+ #include "crypto/crypto_scrypt.h"
56
+ #include "crypto/crypto_sig.h"
57
+ #include "crypto/crypto_spkac.h"
58
+ #include "crypto/crypto_timing.h"
59
+ #include "crypto/crypto_tls.h"
60
+ #include "crypto/crypto_turboshake.h"
61
+ #include "crypto/crypto_util.h"
62
+ #include "crypto/crypto_x509.h"
63
+
64
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
65
+
66
+ #endif // SRC_NODE_CRYPTO_H_
@@ -0,0 +1,30 @@
1
+ #pragma once
2
+
3
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
+
5
+ #ifdef DEBUG
6
+ #include "util.h"
7
+ #endif // DEBUG
8
+
9
+ namespace node {
10
+ namespace debug {
11
+
12
+ #ifdef DEBUG
13
+ void TrackV8FastApiCall(FastStringKey key);
14
+ int GetV8FastApiCallCount(FastStringKey key);
15
+
16
+ void CountGenericUsage(FastStringKey counter_name);
17
+ #define COUNT_GENERIC_USAGE(name) \
18
+ node::debug::CountGenericUsage(FastStringKey(name))
19
+
20
+ #define TRACK_V8_FAST_API_CALL(key) \
21
+ node::debug::TrackV8FastApiCall(FastStringKey(key))
22
+ #else // !DEBUG
23
+ #define TRACK_V8_FAST_API_CALL(key)
24
+ #define COUNT_GENERIC_USAGE(name)
25
+ #endif // DEBUG
26
+
27
+ } // namespace debug
28
+ } // namespace node
29
+
30
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
@@ -0,0 +1,121 @@
1
+ #ifndef SRC_NODE_DIAGNOSTICS_CHANNEL_H_
2
+ #define SRC_NODE_DIAGNOSTICS_CHANNEL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <cinttypes>
7
+ #include <functional>
8
+ #include <string>
9
+ #include <unordered_map>
10
+ #include <vector>
11
+ #include "aliased_buffer.h"
12
+ #include "base_object.h"
13
+ #include "node_snapshotable.h"
14
+
15
+ namespace node {
16
+ class ExternalReferenceRegistry;
17
+
18
+ namespace diagnostics_channel {
19
+
20
+ class Channel;
21
+
22
+ class BindingData : public SnapshotableObject {
23
+ public:
24
+ static constexpr size_t kInitialChannelCapacity = 1024;
25
+
26
+ struct InternalFieldInfo : public node::InternalFieldInfoBase {
27
+ AliasedBufferIndex subscribers;
28
+ size_t subscribers_capacity;
29
+ };
30
+
31
+ BindingData(Realm* realm,
32
+ v8::Local<v8::Object> wrap,
33
+ InternalFieldInfo* info = nullptr);
34
+
35
+ SERIALIZABLE_OBJECT_METHODS()
36
+ SET_BINDING_ID(diagnostics_channel_binding_data)
37
+
38
+ void MemoryInfo(MemoryTracker* tracker) const override;
39
+ SET_SELF_SIZE(BindingData)
40
+ SET_MEMORY_INFO_NAME(BindingData)
41
+
42
+ AliasedUint32Array subscribers_;
43
+
44
+ uint32_t next_channel_index_ = 0;
45
+ std::unordered_map<std::string, uint32_t> channel_indices_;
46
+
47
+ uint32_t GetOrCreateChannelIndex(const std::string& name);
48
+
49
+ v8::Global<v8::Function> link_callback_;
50
+ v8::Global<v8::FunctionTemplate> channel_wrap_template_;
51
+ std::vector<BaseObjectPtr<Channel>> channels_;
52
+
53
+ static void LinkNativeChannel(
54
+ const v8::FunctionCallbackInfo<v8::Value>& args);
55
+
56
+ using ChannelStatusCallback = std::function<void(bool is_active)>;
57
+ void SetChannelStatusCallback(uint32_t index, ChannelStatusCallback cb);
58
+
59
+ static void NotifyChannelActive(
60
+ const v8::FunctionCallbackInfo<v8::Value>& args);
61
+ static void NotifyChannelInactive(
62
+ const v8::FunctionCallbackInfo<v8::Value>& args);
63
+
64
+ static void CreatePerIsolateProperties(IsolateData* isolate_data,
65
+ v8::Local<v8::ObjectTemplate> target);
66
+ static void CreatePerContextProperties(v8::Local<v8::Object> target,
67
+ v8::Local<v8::Value> unused,
68
+ v8::Local<v8::Context> context,
69
+ void* priv);
70
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
71
+
72
+ private:
73
+ InternalFieldInfo* internal_field_info_ = nullptr;
74
+ std::unordered_map<uint32_t, ChannelStatusCallback> channel_status_callbacks_;
75
+ };
76
+
77
+ class Channel : public BaseObject {
78
+ public:
79
+ // Public for MakeDetachedBaseObject.
80
+ Channel(Environment* env,
81
+ v8::Local<v8::Object> wrap,
82
+ BindingData* binding_data,
83
+ uint32_t index,
84
+ std::string name);
85
+
86
+ static BaseObjectPtr<Channel> Get(Environment* env, std::string_view name);
87
+
88
+ inline bool HasSubscribers() const {
89
+ return binding_data_ != nullptr && binding_data_->subscribers_[index_] > 0;
90
+ }
91
+
92
+ void Publish(Environment* env, v8::Local<v8::Value> message);
93
+
94
+ void Link(v8::Isolate* isolate, v8::Local<v8::Object> js_channel);
95
+
96
+ inline bool IsLinked() const { return !js_channel_.IsEmpty(); }
97
+
98
+ void Unlink();
99
+
100
+ void MemoryInfo(MemoryTracker* tracker) const override;
101
+ SET_MEMORY_INFO_NAME(Channel)
102
+ SET_SELF_SIZE(Channel)
103
+
104
+ private:
105
+ friend class BindingData;
106
+
107
+ void CachePublishFn(v8::Isolate* isolate, v8::Local<v8::Object> js_channel);
108
+
109
+ BindingData* binding_data_;
110
+ uint32_t index_;
111
+ std::string name_;
112
+ v8::Global<v8::Object> js_channel_;
113
+ v8::Global<v8::Function> publish_fn_;
114
+ };
115
+
116
+ } // namespace diagnostics_channel
117
+ } // namespace node
118
+
119
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
120
+
121
+ #endif // SRC_NODE_DIAGNOSTICS_CHANNEL_H_