@encharm/cws 4.3.0 → 4.4.1

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 (238) hide show
  1. package/README.md +5 -7
  2. package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
  3. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  4. package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
  5. package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
  6. package/dist/bindings/cws_darwin_x64_node108.node +0 -0
  7. package/dist/bindings/cws_darwin_x64_node115.node +0 -0
  8. package/dist/bindings/cws_darwin_x64_node83.node +0 -0
  9. package/dist/bindings/cws_darwin_x64_node93.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node108.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node83.node +0 -0
  13. package/dist/bindings/cws_linux_arm64_node93.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node108.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node83.node +0 -0
  17. package/dist/bindings/cws_linux_x64_node93.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node108.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node83.node +0 -0
  21. package/dist/bindings/cws_win32_x64_node93.node +0 -0
  22. package/dist/shared.js +1 -1
  23. package/package.json +5 -5
  24. package/src/Addon.cpp +4 -12
  25. package/src/Addon.h +67 -91
  26. package/src/Socket.h +1 -0
  27. package/src/cSNode.cpp +3 -8
  28. package/src/headers/20/acorn_version.h +6 -0
  29. package/src/headers/20/aliased_buffer-inl.h +243 -0
  30. package/src/headers/20/aliased_buffer.h +206 -0
  31. package/src/headers/20/aliased_struct-inl.h +54 -0
  32. package/src/headers/20/aliased_struct.h +63 -0
  33. package/src/headers/20/async_wrap-inl.h +93 -0
  34. package/src/headers/20/async_wrap.h +252 -0
  35. package/src/headers/20/base64-inl.h +193 -0
  36. package/src/headers/20/base64.h +53 -0
  37. package/src/headers/20/base64_version.h +6 -0
  38. package/src/headers/20/base_object-inl.h +316 -0
  39. package/src/headers/20/base_object.h +320 -0
  40. package/src/headers/20/base_object_types.h +73 -0
  41. package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
  42. package/src/headers/20/blob_serializer_deserializer.h +132 -0
  43. package/src/headers/20/callback_queue-inl.h +97 -0
  44. package/src/headers/20/callback_queue.h +79 -0
  45. package/src/headers/20/cares_wrap.h +524 -0
  46. package/src/headers/20/cjs_module_lexer_version.h +6 -0
  47. package/src/headers/20/cleanup_queue-inl.h +62 -0
  48. package/src/headers/20/cleanup_queue.h +85 -0
  49. package/src/headers/20/connect_wrap.h +26 -0
  50. package/src/headers/20/connection_wrap.h +30 -0
  51. package/src/headers/20/cppgc/DEPS +8 -0
  52. package/src/headers/20/cppgc/OWNERS +2 -0
  53. package/src/headers/20/cppgc/README.md +135 -0
  54. package/src/headers/20/cppgc/allocation.h +310 -0
  55. package/src/headers/20/cppgc/common.h +28 -0
  56. package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
  57. package/src/headers/20/cppgc/custom-space.h +97 -0
  58. package/src/headers/20/cppgc/default-platform.h +67 -0
  59. package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
  60. package/src/headers/20/cppgc/explicit-management.h +100 -0
  61. package/src/headers/20/cppgc/garbage-collected.h +106 -0
  62. package/src/headers/20/cppgc/heap-consistency.h +309 -0
  63. package/src/headers/20/cppgc/heap-handle.h +48 -0
  64. package/src/headers/20/cppgc/heap-state.h +82 -0
  65. package/src/headers/20/cppgc/heap-statistics.h +120 -0
  66. package/src/headers/20/cppgc/heap.h +202 -0
  67. package/src/headers/20/cppgc/internal/api-constants.h +68 -0
  68. package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
  69. package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
  70. package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
  71. package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
  72. package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
  73. package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
  74. package/src/headers/20/cppgc/internal/gc-info.h +157 -0
  75. package/src/headers/20/cppgc/internal/logging.h +50 -0
  76. package/src/headers/20/cppgc/internal/member-storage.h +248 -0
  77. package/src/headers/20/cppgc/internal/name-trait.h +137 -0
  78. package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
  79. package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
  80. package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
  81. package/src/headers/20/cppgc/liveness-broker.h +78 -0
  82. package/src/headers/20/cppgc/macros.h +35 -0
  83. package/src/headers/20/cppgc/member.h +604 -0
  84. package/src/headers/20/cppgc/name-provider.h +65 -0
  85. package/src/headers/20/cppgc/object-size-trait.h +58 -0
  86. package/src/headers/20/cppgc/persistent.h +373 -0
  87. package/src/headers/20/cppgc/platform.h +158 -0
  88. package/src/headers/20/cppgc/prefinalizer.h +75 -0
  89. package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
  90. package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
  91. package/src/headers/20/cppgc/source-location.h +92 -0
  92. package/src/headers/20/cppgc/testing.h +106 -0
  93. package/src/headers/20/cppgc/trace-trait.h +120 -0
  94. package/src/headers/20/cppgc/type-traits.h +250 -0
  95. package/src/headers/20/cppgc/visitor.h +426 -0
  96. package/src/headers/20/crypto/crypto_clienthello.h +131 -0
  97. package/src/headers/20/crypto/crypto_context.h +160 -0
  98. package/src/headers/20/crypto/crypto_keys.h +419 -0
  99. package/src/headers/20/crypto/crypto_tls.h +304 -0
  100. package/src/headers/20/crypto/crypto_util.h +806 -0
  101. package/src/headers/20/crypto_clienthello.h +131 -0
  102. package/src/headers/20/debug_utils-inl.h +226 -0
  103. package/src/headers/20/debug_utils.h +188 -0
  104. package/src/headers/20/diagnosticfilename-inl.h +33 -0
  105. package/src/headers/20/encoding_binding.h +59 -0
  106. package/src/headers/20/env-inl.h +923 -0
  107. package/src/headers/20/env.h +1193 -0
  108. package/src/headers/20/env_properties.h +446 -0
  109. package/src/headers/20/handle_wrap.h +123 -0
  110. package/src/headers/20/histogram-inl.h +107 -0
  111. package/src/headers/20/histogram.h +240 -0
  112. package/src/headers/20/inspector_agent.h +144 -0
  113. package/src/headers/20/inspector_io.h +78 -0
  114. package/src/headers/20/inspector_profiler.h +149 -0
  115. package/src/headers/20/inspector_socket.h +60 -0
  116. package/src/headers/20/inspector_socket_server.h +110 -0
  117. package/src/headers/20/js_native_api.h +601 -0
  118. package/src/headers/20/js_native_api_types.h +168 -0
  119. package/src/headers/20/js_native_api_v8.h +463 -0
  120. package/src/headers/20/js_native_api_v8_internals.h +45 -0
  121. package/src/headers/20/js_stream.h +52 -0
  122. package/src/headers/20/json_parser.h +38 -0
  123. package/src/headers/20/json_utils.h +172 -0
  124. package/src/headers/20/memory_tracker-inl.h +356 -0
  125. package/src/headers/20/memory_tracker.h +289 -0
  126. package/src/headers/20/module_wrap.h +117 -0
  127. package/src/headers/20/node.h +1516 -0
  128. package/src/headers/20/node_api.h +261 -0
  129. package/src/headers/20/node_api_internals.h +42 -0
  130. package/src/headers/20/node_api_types.h +52 -0
  131. package/src/headers/20/node_binding.h +142 -0
  132. package/src/headers/20/node_blob.h +159 -0
  133. package/src/headers/20/node_bob-inl.h +36 -0
  134. package/src/headers/20/node_bob.h +107 -0
  135. package/src/headers/20/node_buffer.h +92 -0
  136. package/src/headers/20/node_builtins.h +197 -0
  137. package/src/headers/20/node_constants.h +82 -0
  138. package/src/headers/20/node_context_data.h +98 -0
  139. package/src/headers/20/node_contextify.h +206 -0
  140. package/src/headers/20/node_crypto.h +56 -0
  141. package/src/headers/20/node_dir.h +52 -0
  142. package/src/headers/20/node_dotenv.h +37 -0
  143. package/src/headers/20/node_errors.h +313 -0
  144. package/src/headers/20/node_exit_code.h +54 -0
  145. package/src/headers/20/node_external_reference.h +172 -0
  146. package/src/headers/20/node_file-inl.h +389 -0
  147. package/src/headers/20/node_file.h +537 -0
  148. package/src/headers/20/node_http2.h +1146 -0
  149. package/src/headers/20/node_http2_state.h +147 -0
  150. package/src/headers/20/node_http_common-inl.h +201 -0
  151. package/src/headers/20/node_http_common.h +532 -0
  152. package/src/headers/20/node_i18n.h +145 -0
  153. package/src/headers/20/node_internals.h +443 -0
  154. package/src/headers/20/node_main_instance.h +67 -0
  155. package/src/headers/20/node_mem-inl.h +112 -0
  156. package/src/headers/20/node_mem.h +45 -0
  157. package/src/headers/20/node_messaging.h +377 -0
  158. package/src/headers/20/node_metadata.h +138 -0
  159. package/src/headers/20/node_mutex.h +323 -0
  160. package/src/headers/20/node_object_wrap.h +132 -0
  161. package/src/headers/20/node_options-inl.h +478 -0
  162. package/src/headers/20/node_options.h +538 -0
  163. package/src/headers/20/node_perf.h +166 -0
  164. package/src/headers/20/node_perf_common.h +98 -0
  165. package/src/headers/20/node_platform.h +195 -0
  166. package/src/headers/20/node_process-inl.h +26 -0
  167. package/src/headers/20/node_process.h +99 -0
  168. package/src/headers/20/node_realm-inl.h +139 -0
  169. package/src/headers/20/node_realm.h +184 -0
  170. package/src/headers/20/node_report.h +42 -0
  171. package/src/headers/20/node_revert.h +82 -0
  172. package/src/headers/20/node_root_certs.h +3443 -0
  173. package/src/headers/20/node_sea.h +56 -0
  174. package/src/headers/20/node_shadow_realm.h +46 -0
  175. package/src/headers/20/node_snapshot_builder.h +54 -0
  176. package/src/headers/20/node_snapshotable.h +164 -0
  177. package/src/headers/20/node_sockaddr-inl.h +266 -0
  178. package/src/headers/20/node_sockaddr.h +405 -0
  179. package/src/headers/20/node_stat_watcher.h +73 -0
  180. package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
  181. package/src/headers/20/node_threadsafe_cow.h +105 -0
  182. package/src/headers/20/node_union_bytes.h +81 -0
  183. package/src/headers/20/node_url.h +92 -0
  184. package/src/headers/20/node_v8.h +77 -0
  185. package/src/headers/20/node_v8_platform-inl.h +205 -0
  186. package/src/headers/20/node_version.h +109 -0
  187. package/src/headers/20/node_wasi.h +184 -0
  188. package/src/headers/20/node_wasm_web_api.h +55 -0
  189. package/src/headers/20/node_watchdog.h +154 -0
  190. package/src/headers/20/node_worker.h +151 -0
  191. package/src/headers/20/permission/child_process_permission.h +29 -0
  192. package/src/headers/20/permission/fs_permission.h +154 -0
  193. package/src/headers/20/permission/inspector_permission.h +29 -0
  194. package/src/headers/20/permission/permission.h +74 -0
  195. package/src/headers/20/permission/permission_base.h +53 -0
  196. package/src/headers/20/permission/worker_permission.h +29 -0
  197. package/src/headers/20/pipe_wrap.h +80 -0
  198. package/src/headers/20/req_wrap-inl.h +171 -0
  199. package/src/headers/20/req_wrap.h +77 -0
  200. package/src/headers/20/spawn_sync.h +242 -0
  201. package/src/headers/20/stream_base-inl.h +173 -0
  202. package/src/headers/20/stream_base.h +469 -0
  203. package/src/headers/20/stream_pipe.h +76 -0
  204. package/src/headers/20/stream_wrap.h +131 -0
  205. package/src/headers/20/string_bytes.h +120 -0
  206. package/src/headers/20/string_decoder-inl.h +37 -0
  207. package/src/headers/20/string_decoder.h +50 -0
  208. package/src/headers/20/string_search.h +638 -0
  209. package/src/headers/20/tcp_wrap.h +105 -0
  210. package/src/headers/20/threadpoolwork-inl.h +70 -0
  211. package/src/headers/20/timer_wrap-inl.h +32 -0
  212. package/src/headers/20/timer_wrap.h +85 -0
  213. package/src/headers/20/timers.h +70 -0
  214. package/src/headers/20/tracing/agent.h +195 -0
  215. package/src/headers/20/tracing/node_trace_buffer.h +83 -0
  216. package/src/headers/20/tracing/node_trace_writer.h +75 -0
  217. package/src/headers/20/tracing/trace_event.h +720 -0
  218. package/src/headers/20/tracing/trace_event_common.h +1109 -0
  219. package/src/headers/20/tracing/traced_value.h +70 -0
  220. package/src/headers/20/tty_wrap.h +65 -0
  221. package/src/headers/20/udp_wrap.h +227 -0
  222. package/src/headers/20/undici_version.h +6 -0
  223. package/src/headers/20/util-inl.h +623 -0
  224. package/src/headers/20/util.h +988 -0
  225. package/src/headers/20/v8-cppgc.h +245 -0
  226. package/src/headers/20/v8-fast-api-calls.h +957 -0
  227. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  228. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  229. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  230. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  231. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  232. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  233. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  234. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  235. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  236. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  237. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  238. package/dist/bindings/cws_win32_x64_node79.node +0 -0
@@ -0,0 +1,107 @@
1
+ #ifndef SRC_HISTOGRAM_INL_H_
2
+ #define SRC_HISTOGRAM_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "histogram.h"
7
+ #include "base_object-inl.h"
8
+ #include "node_internals.h"
9
+
10
+ namespace node {
11
+
12
+ void Histogram::Reset() {
13
+ Mutex::ScopedLock lock(mutex_);
14
+ hdr_reset(histogram_.get());
15
+ exceeds_ = 0;
16
+ count_ = 0;
17
+ prev_ = 0;
18
+ }
19
+
20
+ double Histogram::Add(const Histogram& other) {
21
+ Mutex::ScopedLock lock(mutex_);
22
+ count_ += other.count_;
23
+ exceeds_ += other.exceeds_;
24
+ if (other.prev_ > prev_)
25
+ prev_ = other.prev_;
26
+ return static_cast<double>(hdr_add(histogram_.get(), other.histogram_.get()));
27
+ }
28
+
29
+ size_t Histogram::Count() const {
30
+ Mutex::ScopedLock lock(mutex_);
31
+ return count_;
32
+ }
33
+
34
+ int64_t Histogram::Min() const {
35
+ Mutex::ScopedLock lock(mutex_);
36
+ return hdr_min(histogram_.get());
37
+ }
38
+
39
+ int64_t Histogram::Max() const {
40
+ Mutex::ScopedLock lock(mutex_);
41
+ return hdr_max(histogram_.get());
42
+ }
43
+
44
+ double Histogram::Mean() const {
45
+ Mutex::ScopedLock lock(mutex_);
46
+ return hdr_mean(histogram_.get());
47
+ }
48
+
49
+ double Histogram::Stddev() const {
50
+ Mutex::ScopedLock lock(mutex_);
51
+ return hdr_stddev(histogram_.get());
52
+ }
53
+
54
+ int64_t Histogram::Percentile(double percentile) const {
55
+ Mutex::ScopedLock lock(mutex_);
56
+ CHECK_GT(percentile, 0);
57
+ CHECK_LE(percentile, 100);
58
+ return hdr_value_at_percentile(histogram_.get(), percentile);
59
+ }
60
+
61
+ template <typename Iterator>
62
+ void Histogram::Percentiles(Iterator&& fn) {
63
+ Mutex::ScopedLock lock(mutex_);
64
+ hdr_iter iter;
65
+ hdr_iter_percentile_init(&iter, histogram_.get(), 1);
66
+ while (hdr_iter_next(&iter)) {
67
+ double key = iter.specifics.percentiles.percentile;
68
+ fn(key, iter.value);
69
+ }
70
+ }
71
+
72
+ bool Histogram::Record(int64_t value) {
73
+ Mutex::ScopedLock lock(mutex_);
74
+ bool recorded = hdr_record_value(histogram_.get(), value);
75
+ if (!recorded)
76
+ exceeds_++;
77
+ else
78
+ count_++;
79
+ return recorded;
80
+ }
81
+
82
+ uint64_t Histogram::RecordDelta() {
83
+ Mutex::ScopedLock lock(mutex_);
84
+ uint64_t time = uv_hrtime();
85
+ int64_t delta = 0;
86
+ if (prev_ > 0) {
87
+ CHECK_GE(time, prev_);
88
+ delta = time - prev_;
89
+ if (hdr_record_value(histogram_.get(), delta))
90
+ count_++;
91
+ else
92
+ exceeds_++;
93
+ }
94
+ prev_ = time;
95
+ return delta;
96
+ }
97
+
98
+ size_t Histogram::GetMemorySize() const {
99
+ Mutex::ScopedLock lock(mutex_);
100
+ return hdr_get_memory_size(histogram_.get());
101
+ }
102
+
103
+ } // namespace node
104
+
105
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
106
+
107
+ #endif // SRC_HISTOGRAM_INL_H_
@@ -0,0 +1,240 @@
1
+ #ifndef SRC_HISTOGRAM_H_
2
+ #define SRC_HISTOGRAM_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <hdr/hdr_histogram.h>
7
+ #include "base_object.h"
8
+ #include "memory_tracker.h"
9
+ #include "node_messaging.h"
10
+ #include "util.h"
11
+ #include "uv.h"
12
+ #include "v8.h"
13
+
14
+ #include <functional>
15
+ #include <limits>
16
+ #include <map>
17
+ #include <string>
18
+
19
+ namespace node {
20
+
21
+ class ExternalReferenceRegistry;
22
+
23
+ constexpr int kDefaultHistogramFigures = 3;
24
+
25
+ class Histogram : public MemoryRetainer {
26
+ public:
27
+ struct Options {
28
+ int64_t lowest = 1;
29
+ int64_t highest = std::numeric_limits<int64_t>::max();
30
+ int figures = kDefaultHistogramFigures;
31
+ };
32
+
33
+ explicit Histogram(const Options& options);
34
+ virtual ~Histogram() = default;
35
+
36
+ inline bool Record(int64_t value);
37
+ inline void Reset();
38
+ inline int64_t Min() const;
39
+ inline int64_t Max() const;
40
+ inline double Mean() const;
41
+ inline double Stddev() const;
42
+ inline int64_t Percentile(double percentile) const;
43
+ inline size_t Exceeds() const { return exceeds_; }
44
+ inline size_t Count() const;
45
+
46
+ inline uint64_t RecordDelta();
47
+
48
+ inline double Add(const Histogram& other);
49
+
50
+ // Iterator is a function type that takes two doubles as argument, one for
51
+ // percentile and one for the value at that percentile.
52
+ template <typename Iterator>
53
+ inline void Percentiles(Iterator&& fn);
54
+
55
+ inline size_t GetMemorySize() const;
56
+
57
+ void MemoryInfo(MemoryTracker* tracker) const override;
58
+ SET_MEMORY_INFO_NAME(Histogram)
59
+ SET_SELF_SIZE(Histogram)
60
+
61
+ private:
62
+ using HistogramPointer = DeleteFnPtr<hdr_histogram, hdr_close>;
63
+ HistogramPointer histogram_;
64
+ uint64_t prev_ = 0;
65
+ size_t exceeds_ = 0;
66
+ size_t count_ = 0;
67
+ Mutex mutex_;
68
+ };
69
+
70
+ class HistogramImpl {
71
+ public:
72
+ explicit HistogramImpl(
73
+ const Histogram::Options& options = Histogram::Options {});
74
+ explicit HistogramImpl(std::shared_ptr<Histogram> histogram);
75
+
76
+ Histogram* operator->() { return histogram_.get(); }
77
+
78
+ const std::shared_ptr<Histogram>& histogram() const { return histogram_; }
79
+
80
+ private:
81
+ std::shared_ptr<Histogram> histogram_;
82
+ };
83
+
84
+ class HistogramBase : public BaseObject, public HistogramImpl {
85
+ public:
86
+ static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
87
+ IsolateData* isolate_data);
88
+ static void Initialize(IsolateData* isolate_data,
89
+ v8::Local<v8::ObjectTemplate> target);
90
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
91
+
92
+ static BaseObjectPtr<HistogramBase> Create(
93
+ Environment* env,
94
+ const Histogram::Options& options = Histogram::Options {});
95
+
96
+ static BaseObjectPtr<HistogramBase> Create(
97
+ Environment* env,
98
+ std::shared_ptr<Histogram> histogram);
99
+
100
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
101
+
102
+ void MemoryInfo(MemoryTracker* tracker) const override;
103
+ SET_MEMORY_INFO_NAME(HistogramBase)
104
+ SET_SELF_SIZE(HistogramBase)
105
+
106
+ static void GetCountBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
107
+ static void GetMinBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
108
+ static void GetMaxBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
109
+ static void GetExceedsBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
110
+
111
+ static void GetCount(const v8::FunctionCallbackInfo<v8::Value>& args);
112
+ static void GetMin(const v8::FunctionCallbackInfo<v8::Value>& args);
113
+ static void GetMax(const v8::FunctionCallbackInfo<v8::Value>& args);
114
+ static void GetMean(const v8::FunctionCallbackInfo<v8::Value>& args);
115
+ static void GetExceeds(const v8::FunctionCallbackInfo<v8::Value>& args);
116
+ static void GetStddev(const v8::FunctionCallbackInfo<v8::Value>& args);
117
+ static void GetPercentile(
118
+ const v8::FunctionCallbackInfo<v8::Value>& args);
119
+ static void GetPercentileBigInt(
120
+ const v8::FunctionCallbackInfo<v8::Value>& args);
121
+ static void GetPercentiles(
122
+ const v8::FunctionCallbackInfo<v8::Value>& args);
123
+ static void GetPercentilesBigInt(
124
+ const v8::FunctionCallbackInfo<v8::Value>& args);
125
+ static void DoReset(const v8::FunctionCallbackInfo<v8::Value>& args);
126
+ static void Record(const v8::FunctionCallbackInfo<v8::Value>& args);
127
+ static void RecordDelta(const v8::FunctionCallbackInfo<v8::Value>& args);
128
+ static void Add(const v8::FunctionCallbackInfo<v8::Value>& args);
129
+
130
+ HistogramBase(
131
+ Environment* env,
132
+ v8::Local<v8::Object> wrap,
133
+ const Histogram::Options& options = Histogram::Options {});
134
+
135
+ HistogramBase(
136
+ Environment* env,
137
+ v8::Local<v8::Object> wrap,
138
+ std::shared_ptr<Histogram> histogram);
139
+
140
+ TransferMode GetTransferMode() const override {
141
+ return TransferMode::kCloneable;
142
+ }
143
+ std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
144
+
145
+ class HistogramTransferData : public worker::TransferData {
146
+ public:
147
+ explicit HistogramTransferData(const HistogramBase* histogram)
148
+ : histogram_(histogram->histogram()) {}
149
+
150
+ explicit HistogramTransferData(std::shared_ptr<Histogram> histogram)
151
+ : histogram_(std::move(histogram)) {}
152
+
153
+ BaseObjectPtr<BaseObject> Deserialize(
154
+ Environment* env,
155
+ v8::Local<v8::Context> context,
156
+ std::unique_ptr<worker::TransferData> self) override;
157
+
158
+ void MemoryInfo(MemoryTracker* tracker) const override;
159
+ SET_MEMORY_INFO_NAME(HistogramTransferData)
160
+ SET_SELF_SIZE(HistogramTransferData)
161
+
162
+ private:
163
+ std::shared_ptr<Histogram> histogram_;
164
+ };
165
+ };
166
+
167
+ class IntervalHistogram : public HandleWrap, public HistogramImpl {
168
+ public:
169
+ enum class StartFlags {
170
+ NONE,
171
+ RESET
172
+ };
173
+
174
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
175
+
176
+ static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
177
+ Environment* env);
178
+
179
+ static BaseObjectPtr<IntervalHistogram> Create(
180
+ Environment* env,
181
+ int32_t interval,
182
+ std::function<void(Histogram&)> on_interval,
183
+ const Histogram::Options& options);
184
+
185
+ IntervalHistogram(
186
+ Environment* env,
187
+ v8::Local<v8::Object> wrap,
188
+ AsyncWrap::ProviderType type,
189
+ int32_t interval,
190
+ std::function<void(Histogram&)> on_interval,
191
+ const Histogram::Options& options = Histogram::Options {});
192
+
193
+ static void GetCountBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
194
+ static void GetMinBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
195
+ static void GetMaxBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
196
+ static void GetExceedsBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
197
+
198
+ static void GetCount(const v8::FunctionCallbackInfo<v8::Value>& args);
199
+ static void GetMin(const v8::FunctionCallbackInfo<v8::Value>& args);
200
+ static void GetMax(const v8::FunctionCallbackInfo<v8::Value>& args);
201
+ static void GetMean(const v8::FunctionCallbackInfo<v8::Value>& args);
202
+ static void GetExceeds(const v8::FunctionCallbackInfo<v8::Value>& args);
203
+ static void GetStddev(const v8::FunctionCallbackInfo<v8::Value>& args);
204
+ static void GetPercentile(
205
+ const v8::FunctionCallbackInfo<v8::Value>& args);
206
+ static void GetPercentileBigInt(
207
+ const v8::FunctionCallbackInfo<v8::Value>& args);
208
+ static void GetPercentiles(
209
+ const v8::FunctionCallbackInfo<v8::Value>& args);
210
+ static void GetPercentilesBigInt(
211
+ const v8::FunctionCallbackInfo<v8::Value>& args);
212
+ static void DoReset(const v8::FunctionCallbackInfo<v8::Value>& args);
213
+ static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
214
+ static void Stop(const v8::FunctionCallbackInfo<v8::Value>& args);
215
+
216
+ TransferMode GetTransferMode() const override {
217
+ return TransferMode::kCloneable;
218
+ }
219
+ std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
220
+
221
+ void MemoryInfo(MemoryTracker* tracker) const override;
222
+ SET_MEMORY_INFO_NAME(IntervalHistogram)
223
+ SET_SELF_SIZE(IntervalHistogram)
224
+
225
+ private:
226
+ static void TimerCB(uv_timer_t* handle);
227
+ void OnStart(StartFlags flags = StartFlags::RESET);
228
+ void OnStop();
229
+
230
+ bool enabled_ = false;
231
+ int32_t interval_ = 0;
232
+ std::function<void(Histogram&)> on_interval_;
233
+ uv_timer_t timer_;
234
+ };
235
+
236
+ } // namespace node
237
+
238
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
239
+
240
+ #endif // SRC_HISTOGRAM_H_
@@ -0,0 +1,144 @@
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 "node_options.h"
10
+ #include "v8.h"
11
+
12
+ #include <cstddef>
13
+ #include <memory>
14
+
15
+ namespace v8_inspector {
16
+ class StringView;
17
+ } // namespace v8_inspector
18
+
19
+ namespace node {
20
+ // Forward declaration to break recursive dependency chain with src/env.h.
21
+ class Environment;
22
+ struct ContextInfo;
23
+
24
+ namespace inspector {
25
+ class InspectorIo;
26
+ class ParentInspectorHandle;
27
+ class NodeInspectorClient;
28
+ class WorkerManager;
29
+
30
+ class InspectorSession {
31
+ public:
32
+ virtual ~InspectorSession() = default;
33
+ virtual void Dispatch(const v8_inspector::StringView& message) = 0;
34
+ };
35
+
36
+ class InspectorSessionDelegate {
37
+ public:
38
+ virtual ~InspectorSessionDelegate() = default;
39
+ virtual void SendMessageToFrontend(const v8_inspector::StringView& message)
40
+ = 0;
41
+ };
42
+
43
+ class Agent {
44
+ public:
45
+ explicit Agent(node::Environment* env);
46
+ ~Agent();
47
+
48
+ // Create client_, may create io_ if option enabled
49
+ bool Start(const std::string& path,
50
+ const DebugOptions& options,
51
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port,
52
+ bool is_main);
53
+ // Stop and destroy io_
54
+ void Stop();
55
+
56
+ bool IsListening() { return io_ != nullptr; }
57
+ // Returns true if the Node inspector is actually in use. It will be true
58
+ // if either the user explicitly opted into inspector (e.g. with the
59
+ // --inspect command line flag) or if inspector JS API had been used.
60
+ bool IsActive();
61
+
62
+ // Blocks till frontend connects and sends "runIfWaitingForDebugger"
63
+ void WaitForConnect();
64
+ // Blocks till all the sessions with "WaitForDisconnectOnShutdown" disconnect
65
+ void WaitForDisconnect();
66
+ void ReportUncaughtException(v8::Local<v8::Value> error,
67
+ v8::Local<v8::Message> message);
68
+
69
+ // Async stack traces instrumentation.
70
+ void AsyncTaskScheduled(const v8_inspector::StringView& taskName, void* task,
71
+ bool recurring);
72
+ void AsyncTaskCanceled(void* task);
73
+ void AsyncTaskStarted(void* task);
74
+ void AsyncTaskFinished(void* task);
75
+ void AllAsyncTasksCanceled();
76
+
77
+ void RegisterAsyncHook(v8::Isolate* isolate,
78
+ v8::Local<v8::Function> enable_function,
79
+ v8::Local<v8::Function> disable_function);
80
+ void EnableAsyncHook();
81
+ void DisableAsyncHook();
82
+
83
+ void SetParentHandle(std::unique_ptr<ParentInspectorHandle> parent_handle);
84
+ std::unique_ptr<ParentInspectorHandle> GetParentHandle(
85
+ uint64_t thread_id, const std::string& url, const std::string& name);
86
+
87
+ // Called to create inspector sessions that can be used from the same thread.
88
+ // The inspector responds by using the delegate to send messages back.
89
+ std::unique_ptr<InspectorSession> Connect(
90
+ std::unique_ptr<InspectorSessionDelegate> delegate,
91
+ bool prevent_shutdown);
92
+
93
+ // Called from the worker to create inspector sessions that is connected
94
+ // to the main thread.
95
+ // The inspector responds by using the delegate to send messages back.
96
+ std::unique_ptr<InspectorSession> ConnectToMainThread(
97
+ std::unique_ptr<InspectorSessionDelegate> delegate,
98
+ bool prevent_shutdown);
99
+
100
+ void PauseOnNextJavascriptStatement(const std::string& reason);
101
+
102
+ std::string GetWsUrl() const;
103
+
104
+ // Can only be called from the main thread.
105
+ bool StartIoThread();
106
+
107
+ // Calls StartIoThread() from off the main thread.
108
+ void RequestIoThreadStart();
109
+
110
+ const DebugOptions& options() { return debug_options_; }
111
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port() { return host_port_; }
112
+ void ContextCreated(v8::Local<v8::Context> context, const ContextInfo& info);
113
+
114
+ // Interface for interacting with inspectors in worker threads
115
+ std::shared_ptr<WorkerManager> GetWorkerManager();
116
+
117
+ inline Environment* env() const { return parent_env_; }
118
+
119
+ private:
120
+ void ToggleAsyncHook(v8::Isolate* isolate, v8::Local<v8::Function> fn);
121
+
122
+ node::Environment* parent_env_;
123
+ // Encapsulates majority of the Inspector functionality
124
+ std::shared_ptr<NodeInspectorClient> client_;
125
+ // Interface for transports, e.g. WebSocket server
126
+ std::unique_ptr<InspectorIo> io_;
127
+ std::unique_ptr<ParentInspectorHandle> parent_handle_;
128
+ std::string path_;
129
+
130
+ // This is a copy of the debug options parsed from CLI in the Environment.
131
+ // Do not use the host_port in that, instead manipulate the shared host_port_
132
+ // pointer which is meant to store the actual host and port of the inspector
133
+ // server.
134
+ DebugOptions debug_options_;
135
+ std::shared_ptr<ExclusiveAccess<HostPort>> host_port_;
136
+
137
+ bool pending_enable_async_hook_ = false;
138
+ bool pending_disable_async_hook_ = false;
139
+ };
140
+
141
+ } // namespace inspector
142
+ } // namespace node
143
+
144
+ #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