@encharm/cws 4.5.1 → 4.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/binding.gyp +1 -1
  2. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  3. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  4. package/package.json +1 -1
  5. package/src/Addon.h +6 -1
  6. package/src/headers/24/acorn_version.h +6 -0
  7. package/src/headers/24/addon_permission.h +31 -0
  8. package/src/headers/24/agent.h +195 -0
  9. package/src/headers/24/aliased_buffer-inl.h +244 -0
  10. package/src/headers/24/aliased_buffer.h +206 -0
  11. package/src/headers/24/aliased_struct-inl.h +54 -0
  12. package/src/headers/24/aliased_struct.h +63 -0
  13. package/src/headers/24/amaro_version.h +6 -0
  14. package/src/headers/24/application.h +165 -0
  15. package/src/headers/24/async_context_frame.h +33 -0
  16. package/src/headers/24/async_wrap-inl.h +96 -0
  17. package/src/headers/24/async_wrap.h +244 -0
  18. package/src/headers/24/base_object-inl.h +330 -0
  19. package/src/headers/24/base_object.h +338 -0
  20. package/src/headers/24/base_object_types.h +74 -0
  21. package/src/headers/24/bindingdata.h +272 -0
  22. package/src/headers/24/blob_serializer_deserializer-inl.h +385 -0
  23. package/src/headers/24/blob_serializer_deserializer.h +132 -0
  24. package/src/headers/24/callback_queue-inl.h +97 -0
  25. package/src/headers/24/callback_queue.h +79 -0
  26. package/src/headers/24/cares_wrap.h +447 -0
  27. package/src/headers/24/child_process_permission.h +31 -0
  28. package/src/headers/24/cid.h +127 -0
  29. package/src/headers/24/cjs_module_lexer_version.h +6 -0
  30. package/src/headers/24/cleanup_queue-inl.h +36 -0
  31. package/src/headers/24/cleanup_queue.h +79 -0
  32. package/src/headers/24/compile_cache.h +113 -0
  33. package/src/headers/24/connect_wrap.h +26 -0
  34. package/src/headers/24/connection_wrap.h +30 -0
  35. package/src/headers/24/cppgc_helpers-inl.h +65 -0
  36. package/src/headers/24/cppgc_helpers.h +162 -0
  37. package/src/headers/24/crypto/crypto_aes.h +97 -0
  38. package/src/headers/24/crypto/crypto_argon2.h +86 -0
  39. package/src/headers/24/crypto/crypto_bio.h +193 -0
  40. package/src/headers/24/crypto/crypto_chacha20_poly1305.h +64 -0
  41. package/src/headers/24/crypto/crypto_cipher.h +281 -0
  42. package/src/headers/24/crypto/crypto_clienthello-inl.h +90 -0
  43. package/src/headers/24/crypto/crypto_clienthello.h +131 -0
  44. package/src/headers/24/crypto/crypto_common.h +48 -0
  45. package/src/headers/24/crypto/crypto_context.h +171 -0
  46. package/src/headers/24/crypto/crypto_dh.h +126 -0
  47. package/src/headers/24/crypto/crypto_dsa.h +50 -0
  48. package/src/headers/24/crypto/crypto_ec.h +163 -0
  49. package/src/headers/24/crypto/crypto_hash.h +89 -0
  50. package/src/headers/24/crypto/crypto_hkdf.h +61 -0
  51. package/src/headers/24/crypto/crypto_hmac.h +92 -0
  52. package/src/headers/24/crypto/crypto_kem.h +113 -0
  53. package/src/headers/24/crypto/crypto_keygen.h +290 -0
  54. package/src/headers/24/crypto/crypto_keys.h +392 -0
  55. package/src/headers/24/crypto/crypto_ml_dsa.h +21 -0
  56. package/src/headers/24/crypto/crypto_pbkdf2.h +74 -0
  57. package/src/headers/24/crypto/crypto_random.h +124 -0
  58. package/src/headers/24/crypto/crypto_rsa.h +136 -0
  59. package/src/headers/24/crypto/crypto_scrypt.h +85 -0
  60. package/src/headers/24/crypto/crypto_sig.h +156 -0
  61. package/src/headers/24/crypto/crypto_spkac.h +21 -0
  62. package/src/headers/24/crypto/crypto_timing.h +20 -0
  63. package/src/headers/24/crypto/crypto_tls.h +309 -0
  64. package/src/headers/24/crypto/crypto_util.h +598 -0
  65. package/src/headers/24/crypto/crypto_x509.h +140 -0
  66. package/src/headers/24/data.h +148 -0
  67. package/src/headers/24/debug_utils-inl.h +232 -0
  68. package/src/headers/24/debug_utils.h +193 -0
  69. package/src/headers/24/defs.h +254 -0
  70. package/src/headers/24/diagnosticfilename-inl.h +33 -0
  71. package/src/headers/24/embedded_data.h +17 -0
  72. package/src/headers/24/encoding_binding.h +60 -0
  73. package/src/headers/24/endpoint.h +421 -0
  74. package/src/headers/24/env-inl.h +935 -0
  75. package/src/headers/24/env.h +1257 -0
  76. package/src/headers/24/env_properties.h +561 -0
  77. package/src/headers/24/fs_permission.h +167 -0
  78. package/src/headers/24/handle_wrap.h +123 -0
  79. package/src/headers/24/histogram-inl.h +107 -0
  80. package/src/headers/24/histogram.h +279 -0
  81. package/src/headers/24/http3.h +44 -0
  82. package/src/headers/24/inspector_agent.h +165 -0
  83. package/src/headers/24/inspector_io.h +78 -0
  84. package/src/headers/24/inspector_permission.h +31 -0
  85. package/src/headers/24/inspector_profiler.h +149 -0
  86. package/src/headers/24/inspector_socket.h +60 -0
  87. package/src/headers/24/inspector_socket_server.h +110 -0
  88. package/src/headers/24/io_agent.h +30 -0
  89. package/src/headers/24/js_native_api.h +615 -0
  90. package/src/headers/24/js_native_api_types.h +211 -0
  91. package/src/headers/24/js_native_api_v8.h +485 -0
  92. package/src/headers/24/js_native_api_v8_internals.h +45 -0
  93. package/src/headers/24/js_stream.h +52 -0
  94. package/src/headers/24/json_parser.h +40 -0
  95. package/src/headers/24/json_utils.h +172 -0
  96. package/src/headers/24/logstream.h +81 -0
  97. package/src/headers/24/main_thread_interface.h +116 -0
  98. package/src/headers/24/memory_tracker-inl.h +454 -0
  99. package/src/headers/24/memory_tracker.h +333 -0
  100. package/src/headers/24/module_wrap.h +229 -0
  101. package/src/headers/24/ncrypto.h +1625 -0
  102. package/src/headers/24/network_agent.h +118 -0
  103. package/src/headers/24/network_inspector.h +45 -0
  104. package/src/headers/24/network_resource_manager.h +29 -0
  105. package/src/headers/24/node.h +1620 -0
  106. package/src/headers/24/node_api.h +269 -0
  107. package/src/headers/24/node_api_internals.h +46 -0
  108. package/src/headers/24/node_api_types.h +52 -0
  109. package/src/headers/24/node_binding.h +163 -0
  110. package/src/headers/24/node_blob.h +159 -0
  111. package/src/headers/24/node_bob-inl.h +36 -0
  112. package/src/headers/24/node_bob.h +107 -0
  113. package/src/headers/24/node_buffer.h +92 -0
  114. package/src/headers/24/node_builtins.h +223 -0
  115. package/src/headers/24/node_config_file.h +65 -0
  116. package/src/headers/24/node_constants.h +82 -0
  117. package/src/headers/24/node_context_data.h +168 -0
  118. package/src/headers/24/node_contextify.h +261 -0
  119. package/src/headers/24/node_crypto.h +62 -0
  120. package/src/headers/24/node_debug.h +25 -0
  121. package/src/headers/24/node_dir.h +52 -0
  122. package/src/headers/24/node_dotenv.h +45 -0
  123. package/src/headers/24/node_errors.h +391 -0
  124. package/src/headers/24/node_exit_code.h +54 -0
  125. package/src/headers/24/node_external_reference.h +167 -0
  126. package/src/headers/24/node_file-inl.h +412 -0
  127. package/src/headers/24/node_file.h +540 -0
  128. package/src/headers/24/node_http2.h +1175 -0
  129. package/src/headers/24/node_http2_state.h +159 -0
  130. package/src/headers/24/node_http_common-inl.h +198 -0
  131. package/src/headers/24/node_http_common.h +535 -0
  132. package/src/headers/24/node_i18n.h +132 -0
  133. package/src/headers/24/node_internals.h +476 -0
  134. package/src/headers/24/node_json.h +24 -0
  135. package/src/headers/24/node_large_page.h +34 -0
  136. package/src/headers/24/node_locks.h +180 -0
  137. package/src/headers/24/node_main_instance.h +67 -0
  138. package/src/headers/24/node_mem-inl.h +112 -0
  139. package/src/headers/24/node_mem.h +45 -0
  140. package/src/headers/24/node_messaging.h +389 -0
  141. package/src/headers/24/node_metadata.h +164 -0
  142. package/src/headers/24/node_modules.h +93 -0
  143. package/src/headers/24/node_mutex.h +323 -0
  144. package/src/headers/24/node_object_wrap.h +132 -0
  145. package/src/headers/24/node_options-inl.h +524 -0
  146. package/src/headers/24/node_options.h +682 -0
  147. package/src/headers/24/node_perf.h +166 -0
  148. package/src/headers/24/node_perf_common.h +102 -0
  149. package/src/headers/24/node_platform.h +286 -0
  150. package/src/headers/24/node_process-inl.h +26 -0
  151. package/src/headers/24/node_process.h +111 -0
  152. package/src/headers/24/node_realm-inl.h +153 -0
  153. package/src/headers/24/node_realm.h +236 -0
  154. package/src/headers/24/node_report.h +43 -0
  155. package/src/headers/24/node_revert.h +82 -0
  156. package/src/headers/24/node_root_certs.h +3546 -0
  157. package/src/headers/24/node_sea.h +74 -0
  158. package/src/headers/24/node_shadow_realm.h +46 -0
  159. package/src/headers/24/node_snapshot_builder.h +57 -0
  160. package/src/headers/24/node_snapshotable.h +174 -0
  161. package/src/headers/24/node_sockaddr-inl.h +257 -0
  162. package/src/headers/24/node_sockaddr.h +394 -0
  163. package/src/headers/24/node_sqlite.h +270 -0
  164. package/src/headers/24/node_stat_watcher.h +73 -0
  165. package/src/headers/24/node_string.h +101 -0
  166. package/src/headers/24/node_task_runner.h +92 -0
  167. package/src/headers/24/node_threadsafe_cow-inl.h +54 -0
  168. package/src/headers/24/node_threadsafe_cow.h +105 -0
  169. package/src/headers/24/node_trace_buffer.h +83 -0
  170. package/src/headers/24/node_trace_writer.h +75 -0
  171. package/src/headers/24/node_union_bytes.h +81 -0
  172. package/src/headers/24/node_url.h +101 -0
  173. package/src/headers/24/node_url_pattern.h +118 -0
  174. package/src/headers/24/node_v8.h +77 -0
  175. package/src/headers/24/node_v8_platform-inl.h +185 -0
  176. package/src/headers/24/node_version.h +110 -0
  177. package/src/headers/24/node_wasi.h +185 -0
  178. package/src/headers/24/node_wasm_web_api.h +55 -0
  179. package/src/headers/24/node_watchdog.h +154 -0
  180. package/src/headers/24/node_webstorage.h +60 -0
  181. package/src/headers/24/node_worker.h +159 -0
  182. package/src/headers/24/packet.h +155 -0
  183. package/src/headers/24/path.h +33 -0
  184. package/src/headers/24/permission/addon_permission.h +31 -0
  185. package/src/headers/24/permission/child_process_permission.h +31 -0
  186. package/src/headers/24/permission/fs_permission.h +167 -0
  187. package/src/headers/24/permission/inspector_permission.h +31 -0
  188. package/src/headers/24/permission/permission.h +100 -0
  189. package/src/headers/24/permission/permission_base.h +65 -0
  190. package/src/headers/24/permission/wasi_permission.h +31 -0
  191. package/src/headers/24/permission/worker_permission.h +31 -0
  192. package/src/headers/24/permission.h +100 -0
  193. package/src/headers/24/permission_base.h +65 -0
  194. package/src/headers/24/pipe_wrap.h +80 -0
  195. package/src/headers/24/preferredaddress.h +72 -0
  196. package/src/headers/24/protocol_helper.h +27 -0
  197. package/src/headers/24/queue.h +306 -0
  198. package/src/headers/24/req_wrap-inl.h +176 -0
  199. package/src/headers/24/req_wrap.h +79 -0
  200. package/src/headers/24/runtime_agent.h +41 -0
  201. package/src/headers/24/session.h +528 -0
  202. package/src/headers/24/sessionticket.h +108 -0
  203. package/src/headers/24/spawn_sync.h +243 -0
  204. package/src/headers/24/stream_base-inl.h +173 -0
  205. package/src/headers/24/stream_base.h +478 -0
  206. package/src/headers/24/stream_pipe.h +76 -0
  207. package/src/headers/24/stream_wrap.h +132 -0
  208. package/src/headers/24/streams.h +370 -0
  209. package/src/headers/24/string_bytes.h +109 -0
  210. package/src/headers/24/string_decoder-inl.h +31 -0
  211. package/src/headers/24/string_decoder.h +49 -0
  212. package/src/headers/24/target_agent.h +75 -0
  213. package/src/headers/24/tcp_wrap.h +105 -0
  214. package/src/headers/24/threadpoolwork-inl.h +70 -0
  215. package/src/headers/24/timer_wrap-inl.h +32 -0
  216. package/src/headers/24/timer_wrap.h +87 -0
  217. package/src/headers/24/timers.h +75 -0
  218. package/src/headers/24/tlscontext.h +228 -0
  219. package/src/headers/24/tokens.h +256 -0
  220. package/src/headers/24/trace_event.h +722 -0
  221. package/src/headers/24/trace_event_common.h +1109 -0
  222. package/src/headers/24/traced_value.h +129 -0
  223. package/src/headers/24/tracing_agent.h +43 -0
  224. package/src/headers/24/transportparams.h +166 -0
  225. package/src/headers/24/tty_wrap.h +65 -0
  226. package/src/headers/24/udp_wrap.h +230 -0
  227. package/src/headers/24/undici_version.h +6 -0
  228. package/src/headers/24/util-inl.h +711 -0
  229. package/src/headers/24/util.h +1016 -0
  230. package/src/headers/24/v8-external-memory-accounter.h +60 -0
  231. package/src/headers/24/v8-fast-api-calls.h +819 -0
  232. package/src/headers/24/v8-inspector.h +426 -0
  233. package/src/headers/24/wasi_permission.h +31 -0
  234. package/src/headers/24/worker_agent.h +40 -0
  235. package/src/headers/24/worker_inspector.h +124 -0
  236. package/src/headers/24/worker_permission.h +31 -0
  237. package/src/headers/24/zlib_version.h +6 -0
package/binding.gyp CHANGED
@@ -32,7 +32,7 @@
32
32
  ['OS=="mac"', {
33
33
  'xcode_settings': {
34
34
  'MACOSX_DEPLOYMENT_TARGET': '10.7',
35
- 'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
35
+ 'CLANG_CXX_LANGUAGE_STANDARD': 'c++20',
36
36
  'CLANG_CXX_LIBRARY': 'libc++',
37
37
  'GCC_GENERATE_DEBUGGING_SYMBOLS': 'NO',
38
38
  'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@encharm/cws",
3
- "version": "4.5.1",
3
+ "version": "4.5.2",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "description": "cWS - fast C++ WebSocket implementation for Node.js",
package/src/Addon.h CHANGED
@@ -19,6 +19,11 @@
19
19
  #include "headers/22/base_object-inl.h"
20
20
  #endif
21
21
 
22
+ #if NODE_MAJOR_VERSION==24
23
+ #include "headers/24/crypto/crypto_tls.h"
24
+ #include "headers/24/base_object-inl.h"
25
+ #endif
26
+
22
27
  #include <tcp_wrap.h>
23
28
 
24
29
  using BaseObject = node::BaseObject;
@@ -672,4 +677,4 @@ struct Namespace {
672
677
 
673
678
  object->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "group").ToLocalChecked(), group);
674
679
  }
675
- };
680
+ };
@@ -0,0 +1,6 @@
1
+ // This is an auto generated file, please do not edit.
2
+ // Refer to tools/dep_updaters/update-acorn.sh
3
+ #ifndef SRC_ACORN_VERSION_H_
4
+ #define SRC_ACORN_VERSION_H_
5
+ #define ACORN_VERSION "8.15.0"
6
+ #endif // SRC_ACORN_VERSION_H_
@@ -0,0 +1,31 @@
1
+ #ifndef SRC_PERMISSION_ADDON_PERMISSION_H_
2
+ #define SRC_PERMISSION_ADDON_PERMISSION_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <string>
7
+ #include "permission/permission_base.h"
8
+
9
+ namespace node {
10
+
11
+ namespace permission {
12
+
13
+ class AddonPermission final : public PermissionBase {
14
+ public:
15
+ void Apply(Environment* env,
16
+ const std::vector<std::string>& allow,
17
+ PermissionScope scope) override;
18
+ bool is_granted(Environment* env,
19
+ PermissionScope perm,
20
+ const std::string_view& param = "") const override;
21
+
22
+ private:
23
+ bool deny_all_;
24
+ };
25
+
26
+ } // namespace permission
27
+
28
+ } // namespace node
29
+
30
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
31
+ #endif // SRC_PERMISSION_ADDON_PERMISSION_H_
@@ -0,0 +1,195 @@
1
+ #ifndef SRC_TRACING_AGENT_H_
2
+ #define SRC_TRACING_AGENT_H_
3
+
4
+ #include "libplatform/v8-tracing.h"
5
+ #include "uv.h"
6
+ #include "util.h"
7
+ #include "node_mutex.h"
8
+
9
+ #include <list>
10
+ #include <set>
11
+ #include <string>
12
+ #include <unordered_map>
13
+
14
+ namespace v8 {
15
+ class ConvertableToTraceFormat;
16
+ class TracingController;
17
+ } // namespace v8
18
+
19
+ namespace node {
20
+ namespace tracing {
21
+
22
+ using v8::platform::tracing::TraceConfig;
23
+ using v8::platform::tracing::TraceObject;
24
+
25
+ class Agent;
26
+
27
+ class AsyncTraceWriter {
28
+ public:
29
+ virtual ~AsyncTraceWriter() = default;
30
+ virtual void AppendTraceEvent(TraceObject* trace_event) = 0;
31
+ virtual void Flush(bool blocking) = 0;
32
+ virtual void InitializeOnThread(uv_loop_t* loop) {}
33
+ };
34
+
35
+ class TracingController : public v8::platform::tracing::TracingController {
36
+ public:
37
+ TracingController() : v8::platform::tracing::TracingController() {}
38
+
39
+ int64_t CurrentTimestampMicroseconds() override {
40
+ return uv_hrtime() / 1000;
41
+ }
42
+ void AddMetadataEvent(
43
+ const unsigned char* category_group_enabled,
44
+ const char* name,
45
+ int num_args,
46
+ const char** arg_names,
47
+ const unsigned char* arg_types,
48
+ const uint64_t* arg_values,
49
+ std::unique_ptr<v8::ConvertableToTraceFormat>* convertable_values,
50
+ unsigned int flags);
51
+ };
52
+
53
+ class AgentWriterHandle {
54
+ public:
55
+ inline AgentWriterHandle() = default;
56
+ inline ~AgentWriterHandle() { reset(); }
57
+
58
+ inline AgentWriterHandle(AgentWriterHandle&& other);
59
+ inline AgentWriterHandle& operator=(AgentWriterHandle&& other);
60
+ inline bool empty() const { return agent_ == nullptr; }
61
+ inline void reset();
62
+
63
+ inline void Enable(const std::set<std::string>& categories);
64
+ inline void Disable(const std::set<std::string>& categories);
65
+
66
+ inline bool IsDefaultHandle();
67
+
68
+ inline Agent* agent() { return agent_; }
69
+
70
+ inline v8::TracingController* GetTracingController();
71
+
72
+ AgentWriterHandle(const AgentWriterHandle& other) = delete;
73
+ AgentWriterHandle& operator=(const AgentWriterHandle& other) = delete;
74
+
75
+ private:
76
+ inline AgentWriterHandle(Agent* agent, int id) : agent_(agent), id_(id) {}
77
+
78
+ Agent* agent_ = nullptr;
79
+ int id_ = 0;
80
+
81
+ friend class Agent;
82
+ };
83
+
84
+ class Agent {
85
+ public:
86
+ Agent();
87
+ ~Agent();
88
+
89
+ TracingController* GetTracingController() {
90
+ TracingController* controller = tracing_controller_.get();
91
+ CHECK_NOT_NULL(controller);
92
+ return controller;
93
+ }
94
+
95
+ enum UseDefaultCategoryMode {
96
+ kUseDefaultCategories,
97
+ kIgnoreDefaultCategories
98
+ };
99
+
100
+ // Destroying the handle disconnects the client
101
+ AgentWriterHandle AddClient(const std::set<std::string>& categories,
102
+ std::unique_ptr<AsyncTraceWriter> writer,
103
+ enum UseDefaultCategoryMode mode);
104
+ // A handle that is only used for managing the default categories
105
+ // (which can then implicitly be used through using `USE_DEFAULT_CATEGORIES`
106
+ // when adding a client later).
107
+ AgentWriterHandle DefaultHandle();
108
+
109
+ // Returns a comma-separated list of enabled categories.
110
+ std::string GetEnabledCategories() const;
111
+
112
+ // Writes to all writers registered through AddClient().
113
+ void AppendTraceEvent(TraceObject* trace_event);
114
+
115
+ void AddMetadataEvent(std::unique_ptr<TraceObject> event);
116
+ // Flushes all writers registered through AddClient().
117
+ void Flush(bool blocking);
118
+
119
+ TraceConfig* CreateTraceConfig() const;
120
+
121
+ private:
122
+ friend class AgentWriterHandle;
123
+
124
+ void InitializeWritersOnThread();
125
+
126
+ void Start();
127
+ void StopTracing();
128
+ void Disconnect(int client);
129
+
130
+ void Enable(int id, const std::set<std::string>& categories);
131
+ void Disable(int id, const std::set<std::string>& categories);
132
+
133
+ uv_thread_t thread_;
134
+ uv_loop_t tracing_loop_;
135
+
136
+ bool started_ = false;
137
+ class ScopedSuspendTracing;
138
+
139
+ // Each individual Writer has one id.
140
+ int next_writer_id_ = 1;
141
+ enum { kDefaultHandleId = -1 };
142
+ // These maps store the original arguments to AddClient(), by id.
143
+ std::unordered_map<int, std::multiset<std::string>> categories_;
144
+ std::unordered_map<int, std::unique_ptr<AsyncTraceWriter>> writers_;
145
+ std::unique_ptr<TracingController> tracing_controller_;
146
+
147
+ // Variables related to initializing per-event-loop properties of individual
148
+ // writers, such as libuv handles.
149
+ Mutex initialize_writer_mutex_;
150
+ ConditionVariable initialize_writer_condvar_;
151
+ uv_async_t initialize_writer_async_;
152
+ std::set<AsyncTraceWriter*> to_be_initialized_;
153
+
154
+ Mutex metadata_events_mutex_;
155
+ std::list<std::unique_ptr<TraceObject>> metadata_events_;
156
+ };
157
+
158
+ void AgentWriterHandle::reset() {
159
+ if (agent_ != nullptr)
160
+ agent_->Disconnect(id_);
161
+ agent_ = nullptr;
162
+ }
163
+
164
+ AgentWriterHandle& AgentWriterHandle::operator=(AgentWriterHandle&& other) {
165
+ reset();
166
+ agent_ = other.agent_;
167
+ id_ = other.id_;
168
+ other.agent_ = nullptr;
169
+ return *this;
170
+ }
171
+
172
+ AgentWriterHandle::AgentWriterHandle(AgentWriterHandle&& other) {
173
+ *this = std::move(other);
174
+ }
175
+
176
+ void AgentWriterHandle::Enable(const std::set<std::string>& categories) {
177
+ if (agent_ != nullptr) agent_->Enable(id_, categories);
178
+ }
179
+
180
+ void AgentWriterHandle::Disable(const std::set<std::string>& categories) {
181
+ if (agent_ != nullptr) agent_->Disable(id_, categories);
182
+ }
183
+
184
+ bool AgentWriterHandle::IsDefaultHandle() {
185
+ return agent_ != nullptr && id_ == Agent::kDefaultHandleId;
186
+ }
187
+
188
+ inline v8::TracingController* AgentWriterHandle::GetTracingController() {
189
+ return agent_ != nullptr ? agent_->GetTracingController() : nullptr;
190
+ }
191
+
192
+ } // namespace tracing
193
+ } // namespace node
194
+
195
+ #endif // SRC_TRACING_AGENT_H_
@@ -0,0 +1,244 @@
1
+ #ifndef SRC_ALIASED_BUFFER_INL_H_
2
+ #define SRC_ALIASED_BUFFER_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "aliased_buffer.h"
7
+ #include "memory_tracker-inl.h"
8
+ #include "util-inl.h"
9
+
10
+ namespace node {
11
+
12
+ typedef size_t AliasedBufferIndex;
13
+
14
+ template <typename NativeT, typename V8T>
15
+ AliasedBufferBase<NativeT, V8T>::AliasedBufferBase(
16
+ v8::Isolate* isolate, const size_t count, const AliasedBufferIndex* index)
17
+ : isolate_(isolate), count_(count), byte_offset_(0), index_(index) {
18
+ CHECK_GT(count, 0);
19
+ if (index != nullptr) {
20
+ // Will be deserialized later.
21
+ return;
22
+ }
23
+ const v8::HandleScope handle_scope(isolate_);
24
+ const size_t size_in_bytes =
25
+ MultiplyWithOverflowCheck(sizeof(NativeT), count);
26
+
27
+ // allocate v8 ArrayBuffer
28
+ v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate_, size_in_bytes);
29
+ buffer_ = static_cast<NativeT*>(ab->Data());
30
+
31
+ // allocate v8 TypedArray
32
+ v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count);
33
+ js_array_ = v8::Global<V8T>(isolate, js_array);
34
+ }
35
+
36
+ template <typename NativeT, typename V8T>
37
+ AliasedBufferBase<NativeT, V8T>::AliasedBufferBase(
38
+ v8::Isolate* isolate,
39
+ const size_t byte_offset,
40
+ const size_t count,
41
+ const AliasedBufferBase<uint8_t, v8::Uint8Array>& backing_buffer,
42
+ const AliasedBufferIndex* index)
43
+ : isolate_(isolate),
44
+ count_(count),
45
+ byte_offset_(byte_offset),
46
+ index_(index) {
47
+ if (index != nullptr) {
48
+ // Will be deserialized later.
49
+ return;
50
+ }
51
+ const v8::HandleScope handle_scope(isolate_);
52
+ v8::Local<v8::ArrayBuffer> ab = backing_buffer.GetArrayBuffer();
53
+
54
+ // validate that the byte_offset is aligned with sizeof(NativeT)
55
+ CHECK_EQ(byte_offset & (sizeof(NativeT) - 1), 0);
56
+ // validate this fits inside the backing buffer
57
+ CHECK_LE(MultiplyWithOverflowCheck(sizeof(NativeT), count),
58
+ ab->ByteLength() - byte_offset);
59
+
60
+ buffer_ = reinterpret_cast<NativeT*>(
61
+ const_cast<uint8_t*>(backing_buffer.GetNativeBuffer() + byte_offset));
62
+
63
+ v8::Local<V8T> js_array = V8T::New(ab, byte_offset, count);
64
+ js_array_ = v8::Global<V8T>(isolate, js_array);
65
+ }
66
+
67
+ template <typename NativeT, typename V8T>
68
+ AliasedBufferBase<NativeT, V8T>::AliasedBufferBase(
69
+ const AliasedBufferBase& that)
70
+ : isolate_(that.isolate_),
71
+ count_(that.count_),
72
+ byte_offset_(that.byte_offset_),
73
+ buffer_(that.buffer_) {
74
+ js_array_ = v8::Global<V8T>(that.isolate_, that.GetJSArray());
75
+ DCHECK(is_valid());
76
+ }
77
+
78
+ template <typename NativeT, typename V8T>
79
+ AliasedBufferIndex AliasedBufferBase<NativeT, V8T>::Serialize(
80
+ v8::Local<v8::Context> context, v8::SnapshotCreator* creator) {
81
+ DCHECK(is_valid());
82
+ return creator->AddData(context, GetJSArray());
83
+ }
84
+
85
+ template <typename NativeT, typename V8T>
86
+ inline void AliasedBufferBase<NativeT, V8T>::Deserialize(
87
+ v8::Local<v8::Context> context) {
88
+ DCHECK_NOT_NULL(index_);
89
+ v8::Local<V8T> arr =
90
+ context->GetDataFromSnapshotOnce<V8T>(*index_).ToLocalChecked();
91
+ // These may not hold true for AliasedBuffers that have grown, so should
92
+ // be removed when we expand the snapshot support.
93
+ DCHECK_EQ(count_, arr->Length());
94
+ DCHECK_EQ(byte_offset_, arr->ByteOffset());
95
+ uint8_t* raw = static_cast<uint8_t*>(arr->Buffer()->Data());
96
+ buffer_ = reinterpret_cast<NativeT*>(raw + byte_offset_);
97
+ js_array_.Reset(isolate_, arr);
98
+ index_ = nullptr;
99
+ }
100
+
101
+ template <typename NativeT, typename V8T>
102
+ AliasedBufferBase<NativeT, V8T>& AliasedBufferBase<NativeT, V8T>::operator=(
103
+ AliasedBufferBase<NativeT, V8T>&& that) noexcept {
104
+ DCHECK(is_valid());
105
+ this->~AliasedBufferBase();
106
+ isolate_ = that.isolate_;
107
+ count_ = that.count_;
108
+ byte_offset_ = that.byte_offset_;
109
+ buffer_ = that.buffer_;
110
+
111
+ js_array_.Reset(isolate_, that.js_array_.Get(isolate_));
112
+
113
+ that.buffer_ = nullptr;
114
+ that.js_array_.Reset();
115
+ return *this;
116
+ }
117
+
118
+ template <typename NativeT, typename V8T>
119
+ v8::Local<V8T> AliasedBufferBase<NativeT, V8T>::GetJSArray() const {
120
+ DCHECK(is_valid());
121
+ return js_array_.Get(isolate_);
122
+ }
123
+
124
+ template <typename NativeT, typename V8T>
125
+ void AliasedBufferBase<NativeT, V8T>::Release() {
126
+ DCHECK_NULL(index_);
127
+ js_array_.Reset();
128
+ }
129
+
130
+ template <typename NativeT, typename V8T>
131
+ inline void AliasedBufferBase<NativeT, V8T>::MakeWeak() {
132
+ DCHECK(is_valid());
133
+ js_array_.SetWeak();
134
+ }
135
+
136
+ template <typename NativeT, typename V8T>
137
+ v8::Local<v8::ArrayBuffer> AliasedBufferBase<NativeT, V8T>::GetArrayBuffer()
138
+ const {
139
+ return GetJSArray()->Buffer();
140
+ }
141
+
142
+ template <typename NativeT, typename V8T>
143
+ inline const NativeT* AliasedBufferBase<NativeT, V8T>::GetNativeBuffer() const {
144
+ DCHECK(is_valid());
145
+ return buffer_;
146
+ }
147
+
148
+ template <typename NativeT, typename V8T>
149
+ inline const NativeT* AliasedBufferBase<NativeT, V8T>::operator*() const {
150
+ return GetNativeBuffer();
151
+ }
152
+
153
+ template <typename NativeT, typename V8T>
154
+ inline void AliasedBufferBase<NativeT, V8T>::SetValue(const size_t index,
155
+ NativeT value) {
156
+ DCHECK_LT(index, count_);
157
+ DCHECK(is_valid());
158
+ buffer_[index] = value;
159
+ }
160
+
161
+ template <typename NativeT, typename V8T>
162
+ inline const NativeT AliasedBufferBase<NativeT, V8T>::GetValue(
163
+ const size_t index) const {
164
+ DCHECK(is_valid());
165
+ DCHECK_LT(index, count_);
166
+ return buffer_[index];
167
+ }
168
+
169
+ template <typename NativeT, typename V8T>
170
+ typename AliasedBufferBase<NativeT, V8T>::Reference
171
+ AliasedBufferBase<NativeT, V8T>::operator[](size_t index) {
172
+ DCHECK(is_valid());
173
+ return Reference(this, index);
174
+ }
175
+
176
+ template <typename NativeT, typename V8T>
177
+ NativeT AliasedBufferBase<NativeT, V8T>::operator[](size_t index) const {
178
+ return GetValue(index);
179
+ }
180
+
181
+ template <typename NativeT, typename V8T>
182
+ size_t AliasedBufferBase<NativeT, V8T>::Length() const {
183
+ return count_;
184
+ }
185
+
186
+ template <typename NativeT, typename V8T>
187
+ void AliasedBufferBase<NativeT, V8T>::reserve(size_t new_capacity) {
188
+ DCHECK(is_valid());
189
+ DCHECK_GE(new_capacity, count_);
190
+ DCHECK_EQ(byte_offset_, 0);
191
+ const v8::HandleScope handle_scope(isolate_);
192
+
193
+ const size_t old_size_in_bytes = sizeof(NativeT) * count_;
194
+ const size_t new_size_in_bytes =
195
+ MultiplyWithOverflowCheck(sizeof(NativeT), new_capacity);
196
+
197
+ // allocate v8 new ArrayBuffer
198
+ v8::Local<v8::ArrayBuffer> ab =
199
+ v8::ArrayBuffer::New(isolate_, new_size_in_bytes);
200
+
201
+ // allocate new native buffer
202
+ NativeT* new_buffer = static_cast<NativeT*>(ab->Data());
203
+ // copy old content
204
+ memcpy(new_buffer, buffer_, old_size_in_bytes);
205
+
206
+ // allocate v8 TypedArray
207
+ v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, new_capacity);
208
+
209
+ // move over old v8 TypedArray
210
+ js_array_ = std::move(v8::Global<V8T>(isolate_, js_array));
211
+
212
+ buffer_ = new_buffer;
213
+ count_ = new_capacity;
214
+ }
215
+
216
+ template <typename NativeT, typename V8T>
217
+ inline bool AliasedBufferBase<NativeT, V8T>::is_valid() const {
218
+ return index_ == nullptr && !js_array_.IsEmpty();
219
+ }
220
+
221
+ template <typename NativeT, typename V8T>
222
+ inline size_t AliasedBufferBase<NativeT, V8T>::SelfSize() const {
223
+ return sizeof(*this);
224
+ }
225
+
226
+ #define VM(NativeT, V8T) \
227
+ template <> \
228
+ inline const char* AliasedBufferBase<NativeT, v8::V8T>::MemoryInfoName() \
229
+ const { \
230
+ return "Aliased" #V8T; \
231
+ } \
232
+ template <> \
233
+ inline void AliasedBufferBase<NativeT, v8::V8T>::MemoryInfo( \
234
+ node::MemoryTracker* tracker) const { \
235
+ tracker->TrackField("js_array", js_array_); \
236
+ }
237
+ ALIASED_BUFFER_LIST(VM)
238
+ #undef VM
239
+
240
+ } // namespace node
241
+
242
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
243
+
244
+ #endif // SRC_ALIASED_BUFFER_INL_H_