@encharm/cws 4.3.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) 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 +55 -90
  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 +29 -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 +416 -0
  99. package/src/headers/20/crypto/crypto_tls.h +295 -0
  100. package/src/headers/20/crypto/crypto_util.h +805 -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 +444 -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 +591 -0
  118. package/src/headers/20/js_native_api_types.h +168 -0
  119. package/src/headers/20/js_native_api_v8.h +426 -0
  120. package/src/headers/20/js_native_api_v8_internals.h +39 -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 +1514 -0
  128. package/src/headers/20/node_api.h +260 -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 +79 -0
  138. package/src/headers/20/node_context_data.h +98 -0
  139. package/src/headers/20/node_contextify.h +182 -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 +357 -0
  147. package/src/headers/20/node_file.h +524 -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 +28 -0
  192. package/src/headers/20/permission/fs_permission.h +152 -0
  193. package/src/headers/20/permission/permission.h +71 -0
  194. package/src/headers/20/permission/permission_base.h +49 -0
  195. package/src/headers/20/permission/worker_permission.h +28 -0
  196. package/src/headers/20/pipe_wrap.h +80 -0
  197. package/src/headers/20/req_wrap-inl.h +171 -0
  198. package/src/headers/20/req_wrap.h +77 -0
  199. package/src/headers/20/spawn_sync.h +242 -0
  200. package/src/headers/20/stream_base-inl.h +173 -0
  201. package/src/headers/20/stream_base.h +469 -0
  202. package/src/headers/20/stream_pipe.h +76 -0
  203. package/src/headers/20/stream_wrap.h +131 -0
  204. package/src/headers/20/string_bytes.h +120 -0
  205. package/src/headers/20/string_decoder-inl.h +37 -0
  206. package/src/headers/20/string_decoder.h +50 -0
  207. package/src/headers/20/string_search.h +638 -0
  208. package/src/headers/20/tcp_wrap.h +105 -0
  209. package/src/headers/20/threadpoolwork-inl.h +70 -0
  210. package/src/headers/20/timer_wrap-inl.h +32 -0
  211. package/src/headers/20/timer_wrap.h +85 -0
  212. package/src/headers/20/timers.h +70 -0
  213. package/src/headers/20/tracing/agent.h +195 -0
  214. package/src/headers/20/tracing/trace_event.h +720 -0
  215. package/src/headers/20/tracing/trace_event_common.h +1109 -0
  216. package/src/headers/20/tty_wrap.h +65 -0
  217. package/src/headers/20/udp_wrap.h +227 -0
  218. package/src/headers/20/undici_version.h +6 -0
  219. package/src/headers/20/util-inl.h +623 -0
  220. package/src/headers/20/util.h +988 -0
  221. package/src/headers/20/v8-cppgc.h +245 -0
  222. package/src/headers/20/v8-fast-api-calls.h +957 -0
  223. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  224. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  225. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  226. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  227. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  228. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  229. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  230. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  231. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  232. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  233. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  234. package/dist/bindings/cws_win32_x64_node79.node +0 -0
@@ -0,0 +1,193 @@
1
+ #ifndef SRC_BASE64_INL_H_
2
+ #define SRC_BASE64_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "base64.h"
7
+ #include "libbase64.h"
8
+ #include "util.h"
9
+
10
+ namespace node {
11
+
12
+ static constexpr char base64_table_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
13
+ "abcdefghijklmnopqrstuvwxyz"
14
+ "0123456789-_";
15
+
16
+ extern const int8_t unbase64_table[256];
17
+
18
+
19
+ inline static int8_t unbase64(uint8_t x) {
20
+ return unbase64_table[x];
21
+ }
22
+
23
+
24
+ inline uint32_t ReadUint32BE(const unsigned char* p) {
25
+ return static_cast<uint32_t>(p[0] << 24U) |
26
+ static_cast<uint32_t>(p[1] << 16U) |
27
+ static_cast<uint32_t>(p[2] << 8U) |
28
+ static_cast<uint32_t>(p[3]);
29
+ }
30
+
31
+ #ifdef _MSC_VER
32
+ #pragma warning(push)
33
+ // MSVC C4003: not enough actual parameters for macro 'identifier'
34
+ #pragma warning(disable : 4003)
35
+ #endif
36
+
37
+ template <typename TypeName>
38
+ bool base64_decode_group_slow(char* const dst, const size_t dstlen,
39
+ const TypeName* const src, const size_t srclen,
40
+ size_t* const i, size_t* const k) {
41
+ uint8_t hi;
42
+ uint8_t lo;
43
+ #define V(expr) \
44
+ for (;;) { \
45
+ const uint8_t c = static_cast<uint8_t>(src[*i]); \
46
+ lo = unbase64(c); \
47
+ *i += 1; \
48
+ if (lo < 64) break; /* Legal character. */ \
49
+ if (c == '=' || *i >= srclen) return false; /* Stop decoding. */ \
50
+ } \
51
+ expr; \
52
+ if (*i >= srclen) return false; \
53
+ if (*k >= dstlen) return false; \
54
+ hi = lo;
55
+ V(/* Nothing. */);
56
+ V(dst[(*k)++] = ((hi & 0x3F) << 2) | ((lo & 0x30) >> 4));
57
+ V(dst[(*k)++] = ((hi & 0x0F) << 4) | ((lo & 0x3C) >> 2));
58
+ V(dst[(*k)++] = ((hi & 0x03) << 6) | ((lo & 0x3F) >> 0));
59
+ #undef V
60
+ return true; // Continue decoding.
61
+ }
62
+
63
+ #ifdef _MSC_VER
64
+ #pragma warning(pop)
65
+ #endif
66
+
67
+ template <typename TypeName>
68
+ size_t base64_decode_fast(char* const dst, const size_t dstlen,
69
+ const TypeName* const src, const size_t srclen,
70
+ const size_t decoded_size) {
71
+ const size_t available = dstlen < decoded_size ? dstlen : decoded_size;
72
+ const size_t max_k = available / 3 * 3;
73
+ size_t max_i = srclen / 4 * 4;
74
+ size_t i = 0;
75
+ size_t k = 0;
76
+ while (i < max_i && k < max_k) {
77
+ const unsigned char txt[] = {
78
+ static_cast<unsigned char>(unbase64(static_cast<uint8_t>(src[i + 0]))),
79
+ static_cast<unsigned char>(unbase64(static_cast<uint8_t>(src[i + 1]))),
80
+ static_cast<unsigned char>(unbase64(static_cast<uint8_t>(src[i + 2]))),
81
+ static_cast<unsigned char>(unbase64(static_cast<uint8_t>(src[i + 3]))),
82
+ };
83
+
84
+ const uint32_t v = ReadUint32BE(txt);
85
+ // If MSB is set, input contains whitespace or is not valid base64.
86
+ if (v & 0x80808080) {
87
+ if (!base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k))
88
+ return k;
89
+ max_i = i + (srclen - i) / 4 * 4; // Align max_i again.
90
+ } else {
91
+ dst[k + 0] = ((v >> 22) & 0xFC) | ((v >> 20) & 0x03);
92
+ dst[k + 1] = ((v >> 12) & 0xF0) | ((v >> 10) & 0x0F);
93
+ dst[k + 2] = ((v >> 2) & 0xC0) | ((v >> 0) & 0x3F);
94
+ i += 4;
95
+ k += 3;
96
+ }
97
+ }
98
+ if (i < srclen && k < dstlen) {
99
+ base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k);
100
+ }
101
+ return k;
102
+ }
103
+
104
+
105
+ template <typename TypeName>
106
+ size_t base64_decoded_size(const TypeName* src, size_t size) {
107
+ // 1-byte input cannot be decoded
108
+ if (size < 2)
109
+ return 0;
110
+
111
+ if (src[size - 1] == '=') {
112
+ size--;
113
+ if (src[size - 1] == '=')
114
+ size--;
115
+ }
116
+ return base64_decoded_size_fast(size);
117
+ }
118
+
119
+
120
+ template <typename TypeName>
121
+ size_t base64_decode(char* const dst, const size_t dstlen,
122
+ const TypeName* const src, const size_t srclen) {
123
+ const size_t decoded_size = base64_decoded_size(src, srclen);
124
+ return base64_decode_fast(dst, dstlen, src, srclen, decoded_size);
125
+ }
126
+
127
+
128
+ inline size_t base64_encode(const char* src,
129
+ size_t slen,
130
+ char* dst,
131
+ size_t dlen,
132
+ Base64Mode mode) {
133
+ // We know how much we'll write, just make sure that there's space.
134
+ CHECK(dlen >= base64_encoded_size(slen, mode) &&
135
+ "not enough space provided for base64 encode");
136
+
137
+ dlen = base64_encoded_size(slen, mode);
138
+
139
+ if (mode == Base64Mode::NORMAL) {
140
+ ::base64_encode(src, slen, dst, &dlen, 0);
141
+ return dlen;
142
+ }
143
+
144
+ unsigned a;
145
+ unsigned b;
146
+ unsigned c;
147
+ unsigned i;
148
+ unsigned k;
149
+ unsigned n;
150
+
151
+ const char* table = base64_table_url;
152
+
153
+ i = 0;
154
+ k = 0;
155
+ n = slen / 3 * 3;
156
+
157
+ while (i < n) {
158
+ a = src[i + 0] & 0xff;
159
+ b = src[i + 1] & 0xff;
160
+ c = src[i + 2] & 0xff;
161
+
162
+ dst[k + 0] = table[a >> 2];
163
+ dst[k + 1] = table[((a & 3) << 4) | (b >> 4)];
164
+ dst[k + 2] = table[((b & 0x0f) << 2) | (c >> 6)];
165
+ dst[k + 3] = table[c & 0x3f];
166
+
167
+ i += 3;
168
+ k += 4;
169
+ }
170
+
171
+ switch (slen - n) {
172
+ case 1:
173
+ a = src[i + 0] & 0xff;
174
+ dst[k + 0] = table[a >> 2];
175
+ dst[k + 1] = table[(a & 3) << 4];
176
+ break;
177
+ case 2:
178
+ a = src[i + 0] & 0xff;
179
+ b = src[i + 1] & 0xff;
180
+ dst[k + 0] = table[a >> 2];
181
+ dst[k + 1] = table[((a & 3) << 4) | (b >> 4)];
182
+ dst[k + 2] = table[(b & 0x0f) << 2];
183
+ break;
184
+ }
185
+
186
+ return dlen;
187
+ }
188
+
189
+ } // namespace node
190
+
191
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
192
+
193
+ #endif // SRC_BASE64_INL_H_
@@ -0,0 +1,53 @@
1
+ #ifndef SRC_BASE64_H_
2
+ #define SRC_BASE64_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "util.h"
7
+
8
+ #include <cmath>
9
+ #include <cstddef>
10
+ #include <cstdint>
11
+
12
+ namespace node {
13
+ //// Base 64 ////
14
+
15
+ enum class Base64Mode {
16
+ NORMAL,
17
+ URL
18
+ };
19
+
20
+ static inline constexpr size_t base64_encoded_size(
21
+ size_t size,
22
+ Base64Mode mode = Base64Mode::NORMAL) {
23
+ return mode == Base64Mode::NORMAL ? ((size + 2) / 3 * 4)
24
+ : static_cast<size_t>(std::ceil(
25
+ static_cast<double>(size * 4) / 3));
26
+ }
27
+
28
+ // Doesn't check for padding at the end. Can be 1-2 bytes over.
29
+ static inline constexpr size_t base64_decoded_size_fast(size_t size) {
30
+ // 1-byte input cannot be decoded
31
+ return size > 1 ? (size / 4) * 3 + (size % 4 + 1) / 2 : 0;
32
+ }
33
+
34
+ inline uint32_t ReadUint32BE(const unsigned char* p);
35
+
36
+ template <typename TypeName>
37
+ size_t base64_decoded_size(const TypeName* src, size_t size);
38
+
39
+ template <typename TypeName>
40
+ size_t base64_decode(char* const dst, const size_t dstlen,
41
+ const TypeName* const src, const size_t srclen);
42
+
43
+ inline size_t base64_encode(const char* src,
44
+ size_t slen,
45
+ char* dst,
46
+ size_t dlen,
47
+ Base64Mode mode = Base64Mode::NORMAL);
48
+ } // namespace node
49
+
50
+
51
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
52
+
53
+ #endif // SRC_BASE64_H_
@@ -0,0 +1,6 @@
1
+ // This is an auto generated file, please do not edit.
2
+ // Refer to tools/dep_updaters/update-base64.sh
3
+ #ifndef SRC_BASE64_VERSION_H_
4
+ #define SRC_BASE64_VERSION_H_
5
+ #define BASE64_VERSION "0.5.0"
6
+ #endif // SRC_BASE64_VERSION_H_
@@ -0,0 +1,316 @@
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_BASE_OBJECT_INL_H_
23
+ #define SRC_BASE_OBJECT_INL_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include "base_object.h"
28
+ #include "env-inl.h"
29
+ #include "util.h"
30
+
31
+ #include "v8.h"
32
+
33
+ namespace node {
34
+
35
+ BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> object)
36
+ : BaseObject(env->principal_realm(), object) {
37
+ // TODO(legendecas): Check the shorthand is only used in the principal realm
38
+ // while allowing to create a BaseObject in a vm context.
39
+ }
40
+
41
+ void BaseObject::Detach() {
42
+ CHECK_GT(pointer_data()->strong_ptr_count, 0);
43
+ pointer_data()->is_detached = true;
44
+ }
45
+
46
+ v8::Global<v8::Object>& BaseObject::persistent() {
47
+ return persistent_handle_;
48
+ }
49
+
50
+
51
+ v8::Local<v8::Object> BaseObject::object() const {
52
+ return PersistentToLocal::Default(env()->isolate(), persistent_handle_);
53
+ }
54
+
55
+ v8::Local<v8::Object> BaseObject::object(v8::Isolate* isolate) const {
56
+ v8::Local<v8::Object> handle = object();
57
+
58
+ DCHECK_EQ(handle->GetCreationContext().ToLocalChecked()->GetIsolate(),
59
+ isolate);
60
+ DCHECK_EQ(env()->isolate(), isolate);
61
+
62
+ return handle;
63
+ }
64
+
65
+ Environment* BaseObject::env() const {
66
+ return realm_->env();
67
+ }
68
+
69
+ Realm* BaseObject::realm() const {
70
+ return realm_;
71
+ }
72
+
73
+ bool BaseObject::IsBaseObject(IsolateData* isolate_data,
74
+ v8::Local<v8::Object> obj) {
75
+ if (obj->InternalFieldCount() < BaseObject::kInternalFieldCount) {
76
+ return false;
77
+ }
78
+
79
+ uint16_t* ptr = static_cast<uint16_t*>(
80
+ obj->GetAlignedPointerFromInternalField(BaseObject::kEmbedderType));
81
+ return ptr == isolate_data->embedder_id_for_non_cppgc();
82
+ }
83
+
84
+ void BaseObject::TagBaseObject(IsolateData* isolate_data,
85
+ v8::Local<v8::Object> object) {
86
+ DCHECK_GE(object->InternalFieldCount(), BaseObject::kInternalFieldCount);
87
+ object->SetAlignedPointerInInternalField(
88
+ BaseObject::kEmbedderType, isolate_data->embedder_id_for_non_cppgc());
89
+ }
90
+
91
+ void BaseObject::SetInternalFields(IsolateData* isolate_data,
92
+ v8::Local<v8::Object> object,
93
+ void* slot) {
94
+ TagBaseObject(isolate_data, object);
95
+ object->SetAlignedPointerInInternalField(BaseObject::kSlot, slot);
96
+ }
97
+
98
+ BaseObject* BaseObject::FromJSObject(v8::Local<v8::Value> value) {
99
+ v8::Local<v8::Object> obj = value.As<v8::Object>();
100
+ DCHECK_GE(obj->InternalFieldCount(), BaseObject::kInternalFieldCount);
101
+ return static_cast<BaseObject*>(
102
+ obj->GetAlignedPointerFromInternalField(BaseObject::kSlot));
103
+ }
104
+
105
+ template <typename T>
106
+ T* BaseObject::FromJSObject(v8::Local<v8::Value> object) {
107
+ return static_cast<T*>(FromJSObject(object));
108
+ }
109
+
110
+ void BaseObject::OnGCCollect() {
111
+ delete this;
112
+ }
113
+
114
+ void BaseObject::ClearWeak() {
115
+ if (has_pointer_data())
116
+ pointer_data()->wants_weak_jsobj = false;
117
+
118
+ persistent_handle_.ClearWeak();
119
+ }
120
+
121
+ bool BaseObject::IsWeakOrDetached() const {
122
+ if (persistent_handle_.IsWeak()) return true;
123
+
124
+ if (!has_pointer_data()) return false;
125
+ const PointerData* pd = const_cast<BaseObject*>(this)->pointer_data();
126
+ return pd->wants_weak_jsobj || pd->is_detached;
127
+ }
128
+
129
+ v8::EmbedderGraph::Node::Detachedness BaseObject::GetDetachedness() const {
130
+ return IsWeakOrDetached() ? v8::EmbedderGraph::Node::Detachedness::kDetached
131
+ : v8::EmbedderGraph::Node::Detachedness::kUnknown;
132
+ }
133
+
134
+ template <int Field>
135
+ void BaseObject::InternalFieldGet(
136
+ v8::Local<v8::String> property,
137
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
138
+ info.GetReturnValue().Set(
139
+ info.This()->GetInternalField(Field).As<v8::Value>());
140
+ }
141
+
142
+ template <int Field, bool (v8::Value::* typecheck)() const>
143
+ void BaseObject::InternalFieldSet(v8::Local<v8::String> property,
144
+ v8::Local<v8::Value> value,
145
+ const v8::PropertyCallbackInfo<void>& info) {
146
+ // This could be e.g. value->IsFunction().
147
+ CHECK(((*value)->*typecheck)());
148
+ info.This()->SetInternalField(Field, value);
149
+ }
150
+
151
+ bool BaseObject::has_pointer_data() const {
152
+ return pointer_data_ != nullptr;
153
+ }
154
+
155
+ template <typename T, bool kIsWeak>
156
+ BaseObject::PointerData*
157
+ BaseObjectPtrImpl<T, kIsWeak>::pointer_data() const {
158
+ if constexpr (kIsWeak) {
159
+ return data_.pointer_data;
160
+ }
161
+ if (get_base_object() == nullptr) {
162
+ return nullptr;
163
+ }
164
+ return get_base_object()->pointer_data();
165
+ }
166
+
167
+ template <typename T, bool kIsWeak>
168
+ BaseObject* BaseObjectPtrImpl<T, kIsWeak>::get_base_object() const {
169
+ if constexpr (kIsWeak) {
170
+ if (pointer_data() == nullptr) {
171
+ return nullptr;
172
+ }
173
+ return pointer_data()->self;
174
+ }
175
+ return data_.target;
176
+ }
177
+
178
+ template <typename T, bool kIsWeak>
179
+ BaseObjectPtrImpl<T, kIsWeak>::~BaseObjectPtrImpl() {
180
+ if constexpr (kIsWeak) {
181
+ if (pointer_data() != nullptr &&
182
+ --pointer_data()->weak_ptr_count == 0 &&
183
+ pointer_data()->self == nullptr) {
184
+ delete pointer_data();
185
+ }
186
+ } else if (get() != nullptr) {
187
+ get()->decrease_refcount();
188
+ }
189
+ }
190
+
191
+ template <typename T, bool kIsWeak>
192
+ BaseObjectPtrImpl<T, kIsWeak>::BaseObjectPtrImpl() {
193
+ data_.target = nullptr;
194
+ }
195
+
196
+ template <typename T, bool kIsWeak>
197
+ BaseObjectPtrImpl<T, kIsWeak>::BaseObjectPtrImpl(T* target)
198
+ : BaseObjectPtrImpl() {
199
+ if (target == nullptr) return;
200
+ if constexpr (kIsWeak) {
201
+ data_.pointer_data = target->pointer_data();
202
+ CHECK_NOT_NULL(pointer_data());
203
+ pointer_data()->weak_ptr_count++;
204
+ } else {
205
+ data_.target = target;
206
+ CHECK_NOT_NULL(pointer_data());
207
+ get()->increase_refcount();
208
+ }
209
+ }
210
+
211
+ template <typename T, bool kIsWeak>
212
+ template <typename U, bool kW>
213
+ BaseObjectPtrImpl<T, kIsWeak>::BaseObjectPtrImpl(
214
+ const BaseObjectPtrImpl<U, kW>& other)
215
+ : BaseObjectPtrImpl(other.get()) {}
216
+
217
+ template <typename T, bool kIsWeak>
218
+ BaseObjectPtrImpl<T, kIsWeak>::BaseObjectPtrImpl(const BaseObjectPtrImpl& other)
219
+ : BaseObjectPtrImpl(other.get()) {}
220
+
221
+ template <typename T, bool kIsWeak>
222
+ template <typename U, bool kW>
223
+ BaseObjectPtrImpl<T, kIsWeak>& BaseObjectPtrImpl<T, kIsWeak>::operator=(
224
+ const BaseObjectPtrImpl<U, kW>& other) {
225
+ if (other.get() == get()) return *this;
226
+ this->~BaseObjectPtrImpl();
227
+ return *new (this) BaseObjectPtrImpl(other);
228
+ }
229
+
230
+ template <typename T, bool kIsWeak>
231
+ BaseObjectPtrImpl<T, kIsWeak>& BaseObjectPtrImpl<T, kIsWeak>::operator=(
232
+ const BaseObjectPtrImpl& other) {
233
+ if (other.get() == get()) return *this;
234
+ this->~BaseObjectPtrImpl();
235
+ return *new (this) BaseObjectPtrImpl(other);
236
+ }
237
+
238
+ template <typename T, bool kIsWeak>
239
+ BaseObjectPtrImpl<T, kIsWeak>::BaseObjectPtrImpl(BaseObjectPtrImpl&& other)
240
+ : data_(other.data_) {
241
+ if constexpr (kIsWeak)
242
+ other.data_.target = nullptr;
243
+ else
244
+ other.data_.pointer_data = nullptr;
245
+ }
246
+
247
+ template <typename T, bool kIsWeak>
248
+ BaseObjectPtrImpl<T, kIsWeak>& BaseObjectPtrImpl<T, kIsWeak>::operator=(
249
+ BaseObjectPtrImpl&& other) {
250
+ if (&other == this) return *this;
251
+ this->~BaseObjectPtrImpl();
252
+ return *new (this) BaseObjectPtrImpl(std::move(other));
253
+ }
254
+
255
+ template <typename T, bool kIsWeak>
256
+ void BaseObjectPtrImpl<T, kIsWeak>::reset(T* ptr) {
257
+ *this = BaseObjectPtrImpl(ptr);
258
+ }
259
+
260
+ template <typename T, bool kIsWeak>
261
+ T* BaseObjectPtrImpl<T, kIsWeak>::get() const {
262
+ return static_cast<T*>(get_base_object());
263
+ }
264
+
265
+ template <typename T, bool kIsWeak>
266
+ T& BaseObjectPtrImpl<T, kIsWeak>::operator*() const {
267
+ return *get();
268
+ }
269
+
270
+ template <typename T, bool kIsWeak>
271
+ T* BaseObjectPtrImpl<T, kIsWeak>::operator->() const {
272
+ return get();
273
+ }
274
+
275
+ template <typename T, bool kIsWeak>
276
+ BaseObjectPtrImpl<T, kIsWeak>::operator bool() const {
277
+ return get() != nullptr;
278
+ }
279
+
280
+ template <typename T, bool kIsWeak>
281
+ template <typename U, bool kW>
282
+ bool BaseObjectPtrImpl<T, kIsWeak>::operator ==(
283
+ const BaseObjectPtrImpl<U, kW>& other) const {
284
+ return get() == other.get();
285
+ }
286
+
287
+ template <typename T, bool kIsWeak>
288
+ template <typename U, bool kW>
289
+ bool BaseObjectPtrImpl<T, kIsWeak>::operator !=(
290
+ const BaseObjectPtrImpl<U, kW>& other) const {
291
+ return get() != other.get();
292
+ }
293
+
294
+ template <typename T, typename... Args>
295
+ BaseObjectPtr<T> MakeBaseObject(Args&&... args) {
296
+ return BaseObjectPtr<T>(new T(std::forward<Args>(args)...));
297
+ }
298
+ template <typename T, typename... Args>
299
+ BaseObjectWeakPtr<T> MakeWeakBaseObject(Args&&... args) {
300
+ T* target = new T(std::forward<Args>(args)...);
301
+ target->MakeWeak();
302
+ return BaseObjectWeakPtr<T>(target);
303
+ }
304
+
305
+ template <typename T, typename... Args>
306
+ BaseObjectPtr<T> MakeDetachedBaseObject(Args&&... args) {
307
+ BaseObjectPtr<T> target = MakeBaseObject<T>(std::forward<Args>(args)...);
308
+ target->Detach();
309
+ return target;
310
+ }
311
+
312
+ } // namespace node
313
+
314
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
315
+
316
+ #endif // SRC_BASE_OBJECT_INL_H_