@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,426 @@
1
+ // Copyright 2020 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_CPPGC_VISITOR_H_
6
+ #define INCLUDE_CPPGC_VISITOR_H_
7
+
8
+ #include "cppgc/custom-space.h"
9
+ #include "cppgc/ephemeron-pair.h"
10
+ #include "cppgc/garbage-collected.h"
11
+ #include "cppgc/internal/logging.h"
12
+ #include "cppgc/internal/pointer-policies.h"
13
+ #include "cppgc/liveness-broker.h"
14
+ #include "cppgc/member.h"
15
+ #include "cppgc/sentinel-pointer.h"
16
+ #include "cppgc/source-location.h"
17
+ #include "cppgc/trace-trait.h"
18
+ #include "cppgc/type-traits.h"
19
+
20
+ namespace cppgc {
21
+
22
+ namespace internal {
23
+ template <typename T, typename WeaknessPolicy, typename LocationPolicy,
24
+ typename CheckingPolicy>
25
+ class BasicCrossThreadPersistent;
26
+ template <typename T, typename WeaknessPolicy, typename LocationPolicy,
27
+ typename CheckingPolicy>
28
+ class BasicPersistent;
29
+ class ConservativeTracingVisitor;
30
+ class VisitorBase;
31
+ class VisitorFactory;
32
+ } // namespace internal
33
+
34
+ using WeakCallback = void (*)(const LivenessBroker&, const void*);
35
+
36
+ /**
37
+ * Visitor passed to trace methods. All managed pointers must have called the
38
+ * Visitor's trace method on them.
39
+ *
40
+ * \code
41
+ * class Foo final : public GarbageCollected<Foo> {
42
+ * public:
43
+ * void Trace(Visitor* visitor) const {
44
+ * visitor->Trace(foo_);
45
+ * visitor->Trace(weak_foo_);
46
+ * }
47
+ * private:
48
+ * Member<Foo> foo_;
49
+ * WeakMember<Foo> weak_foo_;
50
+ * };
51
+ * \endcode
52
+ */
53
+ class V8_EXPORT Visitor {
54
+ public:
55
+ class Key {
56
+ private:
57
+ Key() = default;
58
+ friend class internal::VisitorFactory;
59
+ };
60
+
61
+ explicit Visitor(Key) {}
62
+
63
+ virtual ~Visitor() = default;
64
+
65
+ /**
66
+ * Trace method for Member.
67
+ *
68
+ * \param member Member reference retaining an object.
69
+ */
70
+ template <typename T>
71
+ void Trace(const Member<T>& member) {
72
+ const T* value = member.GetRawAtomic();
73
+ CPPGC_DCHECK(value != kSentinelPointer);
74
+ TraceImpl(value);
75
+ }
76
+
77
+ /**
78
+ * Trace method for WeakMember.
79
+ *
80
+ * \param weak_member WeakMember reference weakly retaining an object.
81
+ */
82
+ template <typename T>
83
+ void Trace(const WeakMember<T>& weak_member) {
84
+ static_assert(sizeof(T), "Pointee type must be fully defined.");
85
+ static_assert(internal::IsGarbageCollectedOrMixinType<T>::value,
86
+ "T must be GarbageCollected or GarbageCollectedMixin type");
87
+ static_assert(!internal::IsAllocatedOnCompactableSpace<T>::value,
88
+ "Weak references to compactable objects are not allowed");
89
+
90
+ const T* value = weak_member.GetRawAtomic();
91
+
92
+ // Bailout assumes that WeakMember emits write barrier.
93
+ if (!value) {
94
+ return;
95
+ }
96
+
97
+ CPPGC_DCHECK(value != kSentinelPointer);
98
+ VisitWeak(value, TraceTrait<T>::GetTraceDescriptor(value),
99
+ &HandleWeak<WeakMember<T>>, &weak_member);
100
+ }
101
+
102
+ #if defined(CPPGC_POINTER_COMPRESSION)
103
+ /**
104
+ * Trace method for UncompressedMember.
105
+ *
106
+ * \param member UncompressedMember reference retaining an object.
107
+ */
108
+ template <typename T>
109
+ void Trace(const subtle::UncompressedMember<T>& member) {
110
+ const T* value = member.GetRawAtomic();
111
+ CPPGC_DCHECK(value != kSentinelPointer);
112
+ TraceImpl(value);
113
+ }
114
+ #endif // defined(CPPGC_POINTER_COMPRESSION)
115
+
116
+ /**
117
+ * Trace method for inlined objects that are not allocated themselves but
118
+ * otherwise follow managed heap layout and have a Trace() method.
119
+ *
120
+ * \param object reference of the inlined object.
121
+ */
122
+ template <typename T>
123
+ void Trace(const T& object) {
124
+ #if V8_ENABLE_CHECKS
125
+ // This object is embedded in potentially multiple nested objects. The
126
+ // outermost object must not be in construction as such objects are (a) not
127
+ // processed immediately, and (b) only processed conservatively if not
128
+ // otherwise possible.
129
+ CheckObjectNotInConstruction(&object);
130
+ #endif // V8_ENABLE_CHECKS
131
+ TraceTrait<T>::Trace(this, &object);
132
+ }
133
+
134
+ /**
135
+ * Registers a weak callback method on the object of type T. See
136
+ * LivenessBroker for an usage example.
137
+ *
138
+ * \param object of type T specifying a weak callback method.
139
+ */
140
+ template <typename T, void (T::*method)(const LivenessBroker&)>
141
+ void RegisterWeakCallbackMethod(const T* object) {
142
+ RegisterWeakCallback(&WeakCallbackMethodDelegate<T, method>, object);
143
+ }
144
+
145
+ /**
146
+ * Trace method for EphemeronPair.
147
+ *
148
+ * \param ephemeron_pair EphemeronPair reference weakly retaining a key object
149
+ * and strongly retaining a value object in case the key object is alive.
150
+ */
151
+ template <typename K, typename V>
152
+ void Trace(const EphemeronPair<K, V>& ephemeron_pair) {
153
+ TraceEphemeron(ephemeron_pair.key, &ephemeron_pair.value);
154
+ RegisterWeakCallbackMethod<EphemeronPair<K, V>,
155
+ &EphemeronPair<K, V>::ClearValueIfKeyIsDead>(
156
+ &ephemeron_pair);
157
+ }
158
+
159
+ /**
160
+ * Trace method for a single ephemeron. Used for tracing a raw ephemeron in
161
+ * which the `key` and `value` are kept separately.
162
+ *
163
+ * \param weak_member_key WeakMember reference weakly retaining a key object.
164
+ * \param member_value Member reference with ephemeron semantics.
165
+ */
166
+ template <typename KeyType, typename ValueType>
167
+ void TraceEphemeron(const WeakMember<KeyType>& weak_member_key,
168
+ const Member<ValueType>* member_value) {
169
+ const KeyType* key = weak_member_key.GetRawAtomic();
170
+ if (!key) return;
171
+
172
+ // `value` must always be non-null.
173
+ CPPGC_DCHECK(member_value);
174
+ const ValueType* value = member_value->GetRawAtomic();
175
+ if (!value) return;
176
+
177
+ // KeyType and ValueType may refer to GarbageCollectedMixin.
178
+ TraceDescriptor value_desc =
179
+ TraceTrait<ValueType>::GetTraceDescriptor(value);
180
+ CPPGC_DCHECK(value_desc.base_object_payload);
181
+ const void* key_base_object_payload =
182
+ TraceTrait<KeyType>::GetTraceDescriptor(key).base_object_payload;
183
+ CPPGC_DCHECK(key_base_object_payload);
184
+
185
+ VisitEphemeron(key_base_object_payload, value, value_desc);
186
+ }
187
+
188
+ /**
189
+ * Trace method for a single ephemeron. Used for tracing a raw ephemeron in
190
+ * which the `key` and `value` are kept separately. Note that this overload
191
+ * is for non-GarbageCollected `value`s that can be traced though.
192
+ *
193
+ * \param key `WeakMember` reference weakly retaining a key object.
194
+ * \param value Reference weakly retaining a value object. Note that
195
+ * `ValueType` here should not be `Member`. It is expected that
196
+ * `TraceTrait<ValueType>::GetTraceDescriptor(value)` returns a
197
+ * `TraceDescriptor` with a null base pointer but a valid trace method.
198
+ */
199
+ template <typename KeyType, typename ValueType>
200
+ void TraceEphemeron(const WeakMember<KeyType>& weak_member_key,
201
+ const ValueType* value) {
202
+ static_assert(!IsGarbageCollectedOrMixinTypeV<ValueType>,
203
+ "garbage-collected types must use WeakMember and Member");
204
+ const KeyType* key = weak_member_key.GetRawAtomic();
205
+ if (!key) return;
206
+
207
+ // `value` must always be non-null.
208
+ CPPGC_DCHECK(value);
209
+ TraceDescriptor value_desc =
210
+ TraceTrait<ValueType>::GetTraceDescriptor(value);
211
+ // `value_desc.base_object_payload` must be null as this override is only
212
+ // taken for non-garbage-collected values.
213
+ CPPGC_DCHECK(!value_desc.base_object_payload);
214
+
215
+ // KeyType might be a GarbageCollectedMixin.
216
+ const void* key_base_object_payload =
217
+ TraceTrait<KeyType>::GetTraceDescriptor(key).base_object_payload;
218
+ CPPGC_DCHECK(key_base_object_payload);
219
+
220
+ VisitEphemeron(key_base_object_payload, value, value_desc);
221
+ }
222
+
223
+ /**
224
+ * Trace method that strongifies a WeakMember.
225
+ *
226
+ * \param weak_member WeakMember reference retaining an object.
227
+ */
228
+ template <typename T>
229
+ void TraceStrongly(const WeakMember<T>& weak_member) {
230
+ const T* value = weak_member.GetRawAtomic();
231
+ CPPGC_DCHECK(value != kSentinelPointer);
232
+ TraceImpl(value);
233
+ }
234
+
235
+ /**
236
+ * Trace method for retaining containers strongly.
237
+ *
238
+ * \param object reference to the container.
239
+ */
240
+ template <typename T>
241
+ void TraceStrongContainer(const T* object) {
242
+ TraceImpl(object);
243
+ }
244
+
245
+ /**
246
+ * Trace method for retaining containers weakly. Note that weak containers
247
+ * should emit write barriers.
248
+ *
249
+ * \param object reference to the container.
250
+ * \param callback to be invoked.
251
+ * \param callback_data custom data that is passed to the callback.
252
+ */
253
+ template <typename T>
254
+ void TraceWeakContainer(const T* object, WeakCallback callback,
255
+ const void* callback_data) {
256
+ if (!object) return;
257
+ VisitWeakContainer(object, TraceTrait<T>::GetTraceDescriptor(object),
258
+ TraceTrait<T>::GetWeakTraceDescriptor(object), callback,
259
+ callback_data);
260
+ }
261
+
262
+ /**
263
+ * Registers a slot containing a reference to an object allocated on a
264
+ * compactable space. Such references maybe be arbitrarily moved by the GC.
265
+ *
266
+ * \param slot location of reference to object that might be moved by the GC.
267
+ * The slot must contain an uncompressed pointer.
268
+ */
269
+ template <typename T>
270
+ void RegisterMovableReference(const T** slot) {
271
+ static_assert(internal::IsAllocatedOnCompactableSpace<T>::value,
272
+ "Only references to objects allocated on compactable spaces "
273
+ "should be registered as movable slots.");
274
+ static_assert(!IsGarbageCollectedMixinTypeV<T>,
275
+ "Mixin types do not support compaction.");
276
+ HandleMovableReference(reinterpret_cast<const void**>(slot));
277
+ }
278
+
279
+ /**
280
+ * Registers a weak callback that is invoked during garbage collection.
281
+ *
282
+ * \param callback to be invoked.
283
+ * \param data custom data that is passed to the callback.
284
+ */
285
+ virtual void RegisterWeakCallback(WeakCallback callback, const void* data) {}
286
+
287
+ /**
288
+ * Defers tracing an object from a concurrent thread to the mutator thread.
289
+ * Should be called by Trace methods of types that are not safe to trace
290
+ * concurrently.
291
+ *
292
+ * \param parameter tells the trace callback which object was deferred.
293
+ * \param callback to be invoked for tracing on the mutator thread.
294
+ * \param deferred_size size of deferred object.
295
+ *
296
+ * \returns false if the object does not need to be deferred (i.e. currently
297
+ * traced on the mutator thread) and true otherwise (i.e. currently traced on
298
+ * a concurrent thread).
299
+ */
300
+ virtual V8_WARN_UNUSED_RESULT bool DeferTraceToMutatorThreadIfConcurrent(
301
+ const void* parameter, TraceCallback callback, size_t deferred_size) {
302
+ // By default tracing is not deferred.
303
+ return false;
304
+ }
305
+
306
+ protected:
307
+ virtual void Visit(const void* self, TraceDescriptor) {}
308
+ virtual void VisitWeak(const void* self, TraceDescriptor, WeakCallback,
309
+ const void* weak_member) {}
310
+ virtual void VisitEphemeron(const void* key, const void* value,
311
+ TraceDescriptor value_desc) {}
312
+ virtual void VisitWeakContainer(const void* self, TraceDescriptor strong_desc,
313
+ TraceDescriptor weak_desc,
314
+ WeakCallback callback, const void* data) {}
315
+ virtual void HandleMovableReference(const void**) {}
316
+
317
+ private:
318
+ template <typename T, void (T::*method)(const LivenessBroker&)>
319
+ static void WeakCallbackMethodDelegate(const LivenessBroker& info,
320
+ const void* self) {
321
+ // Callback is registered through a potential const Trace method but needs
322
+ // to be able to modify fields. See HandleWeak.
323
+ (const_cast<T*>(static_cast<const T*>(self))->*method)(info);
324
+ }
325
+
326
+ template <typename PointerType>
327
+ static void HandleWeak(const LivenessBroker& info, const void* object) {
328
+ const PointerType* weak = static_cast<const PointerType*>(object);
329
+ auto* raw_ptr = weak->GetFromGC();
330
+ if (!info.IsHeapObjectAlive(raw_ptr)) {
331
+ weak->ClearFromGC();
332
+ }
333
+ }
334
+
335
+ template <typename T>
336
+ void TraceImpl(const T* t) {
337
+ static_assert(sizeof(T), "Pointee type must be fully defined.");
338
+ static_assert(internal::IsGarbageCollectedOrMixinType<T>::value,
339
+ "T must be GarbageCollected or GarbageCollectedMixin type");
340
+ if (!t) {
341
+ return;
342
+ }
343
+ Visit(t, TraceTrait<T>::GetTraceDescriptor(t));
344
+ }
345
+
346
+ #if V8_ENABLE_CHECKS
347
+ void CheckObjectNotInConstruction(const void* address);
348
+ #endif // V8_ENABLE_CHECKS
349
+
350
+ template <typename T, typename WeaknessPolicy, typename LocationPolicy,
351
+ typename CheckingPolicy>
352
+ friend class internal::BasicCrossThreadPersistent;
353
+ template <typename T, typename WeaknessPolicy, typename LocationPolicy,
354
+ typename CheckingPolicy>
355
+ friend class internal::BasicPersistent;
356
+ friend class internal::ConservativeTracingVisitor;
357
+ friend class internal::VisitorBase;
358
+ };
359
+
360
+ namespace internal {
361
+
362
+ class V8_EXPORT RootVisitor {
363
+ public:
364
+ explicit RootVisitor(Visitor::Key) {}
365
+
366
+ virtual ~RootVisitor() = default;
367
+
368
+ template <typename AnyStrongPersistentType,
369
+ std::enable_if_t<
370
+ AnyStrongPersistentType::IsStrongPersistent::value>* = nullptr>
371
+ void Trace(const AnyStrongPersistentType& p) {
372
+ using PointeeType = typename AnyStrongPersistentType::PointeeType;
373
+ const void* object = Extract(p);
374
+ if (!object) {
375
+ return;
376
+ }
377
+ VisitRoot(object, TraceTrait<PointeeType>::GetTraceDescriptor(object),
378
+ p.Location());
379
+ }
380
+
381
+ template <typename AnyWeakPersistentType,
382
+ std::enable_if_t<
383
+ !AnyWeakPersistentType::IsStrongPersistent::value>* = nullptr>
384
+ void Trace(const AnyWeakPersistentType& p) {
385
+ using PointeeType = typename AnyWeakPersistentType::PointeeType;
386
+ static_assert(!internal::IsAllocatedOnCompactableSpace<PointeeType>::value,
387
+ "Weak references to compactable objects are not allowed");
388
+ const void* object = Extract(p);
389
+ if (!object) {
390
+ return;
391
+ }
392
+ VisitWeakRoot(object, TraceTrait<PointeeType>::GetTraceDescriptor(object),
393
+ &HandleWeak<AnyWeakPersistentType>, &p, p.Location());
394
+ }
395
+
396
+ protected:
397
+ virtual void VisitRoot(const void*, TraceDescriptor, const SourceLocation&) {}
398
+ virtual void VisitWeakRoot(const void* self, TraceDescriptor, WeakCallback,
399
+ const void* weak_root, const SourceLocation&) {}
400
+
401
+ private:
402
+ template <typename AnyPersistentType>
403
+ static const void* Extract(AnyPersistentType& p) {
404
+ using PointeeType = typename AnyPersistentType::PointeeType;
405
+ static_assert(sizeof(PointeeType),
406
+ "Persistent's pointee type must be fully defined");
407
+ static_assert(internal::IsGarbageCollectedOrMixinType<PointeeType>::value,
408
+ "Persistent's pointee type must be GarbageCollected or "
409
+ "GarbageCollectedMixin");
410
+ return p.GetFromGC();
411
+ }
412
+
413
+ template <typename PointerType>
414
+ static void HandleWeak(const LivenessBroker& info, const void* object) {
415
+ const PointerType* weak = static_cast<const PointerType*>(object);
416
+ auto* raw_ptr = weak->GetFromGC();
417
+ if (!info.IsHeapObjectAlive(raw_ptr)) {
418
+ weak->ClearFromGC();
419
+ }
420
+ }
421
+ };
422
+
423
+ } // namespace internal
424
+ } // namespace cppgc
425
+
426
+ #endif // INCLUDE_CPPGC_VISITOR_H_
@@ -0,0 +1,131 @@
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_CRYPTO_CRYPTO_CLIENTHELLO_H_
23
+ #define SRC_CRYPTO_CRYPTO_CLIENTHELLO_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include <cstddef> // size_t
28
+ #include <cstdint>
29
+
30
+ namespace node {
31
+ namespace crypto {
32
+ // Parse the client hello so we can do async session resumption. OpenSSL's
33
+ // session resumption uses synchronous callbacks, see SSL_CTX_sess_set_get_cb
34
+ // and get_session_cb.
35
+ //
36
+ // TLS1.3 handshakes masquerade as TLS1.2 session resumption, and to do this,
37
+ // they always include a session_id in the ClientHello, making up a bogus value
38
+ // if necessary. The parser can't know if its a bogus id, and will cause a
39
+ // 'newSession' event to be emitted. This should do no harm, the id won't be
40
+ // found, and the handshake will continue.
41
+ class ClientHelloParser {
42
+ public:
43
+ inline ClientHelloParser();
44
+
45
+ class ClientHello {
46
+ public:
47
+ inline uint8_t session_size() const { return session_size_; }
48
+ inline const uint8_t* session_id() const { return session_id_; }
49
+ inline bool has_ticket() const { return has_ticket_; }
50
+ inline uint8_t servername_size() const { return servername_size_; }
51
+ inline const uint8_t* servername() const { return servername_; }
52
+
53
+ private:
54
+ uint8_t session_size_;
55
+ const uint8_t* session_id_;
56
+ bool has_ticket_;
57
+ uint8_t servername_size_;
58
+ const uint8_t* servername_;
59
+
60
+ friend class ClientHelloParser;
61
+ };
62
+
63
+ typedef void (*OnHelloCb)(void* arg, const ClientHello& hello);
64
+ typedef void (*OnEndCb)(void* arg);
65
+
66
+ void Parse(const uint8_t* data, size_t avail);
67
+
68
+ inline void Reset();
69
+ inline void Start(OnHelloCb onhello_cb, OnEndCb onend_cb, void* cb_arg);
70
+ inline void End();
71
+ inline bool IsPaused() const;
72
+ inline bool IsEnded() const;
73
+
74
+ private:
75
+ static const size_t kMaxTLSFrameLen = 16 * 1024 + 5;
76
+ static const size_t kMaxSSLExFrameLen = 32 * 1024;
77
+ static const uint8_t kServernameHostname = 0;
78
+ static const size_t kMinStatusRequestSize = 5;
79
+
80
+ enum ParseState {
81
+ kWaiting,
82
+ kTLSHeader,
83
+ kPaused,
84
+ kEnded
85
+ };
86
+
87
+ enum FrameType {
88
+ kChangeCipherSpec = 20,
89
+ kAlert = 21,
90
+ kHandshake = 22,
91
+ kApplicationData = 23,
92
+ kOther = 255
93
+ };
94
+
95
+ enum HandshakeType {
96
+ kClientHello = 1
97
+ };
98
+
99
+ enum ExtensionType {
100
+ kServerName = 0,
101
+ kTLSSessionTicket = 35
102
+ };
103
+
104
+ bool ParseRecordHeader(const uint8_t* data, size_t avail);
105
+ void ParseHeader(const uint8_t* data, size_t avail);
106
+ void ParseExtension(const uint16_t type,
107
+ const uint8_t* data,
108
+ size_t len);
109
+ bool ParseTLSClientHello(const uint8_t* data, size_t avail);
110
+
111
+ ParseState state_;
112
+ OnHelloCb onhello_cb_;
113
+ OnEndCb onend_cb_;
114
+ void* cb_arg_;
115
+ size_t frame_len_ = 0;
116
+ size_t body_offset_ = 0;
117
+ size_t extension_offset_ = 0;
118
+ uint8_t session_size_ = 0;
119
+ const uint8_t* session_id_ = nullptr;
120
+ uint16_t servername_size_ = 0;
121
+ const uint8_t* servername_ = nullptr;
122
+ uint16_t tls_ticket_size_ = -1;
123
+ const uint8_t* tls_ticket_ = nullptr;
124
+ };
125
+
126
+ } // namespace crypto
127
+ } // namespace node
128
+
129
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
130
+
131
+ #endif // SRC_CRYPTO_CRYPTO_CLIENTHELLO_H_