@encharm/cws 4.3.0 → 4.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/README.md +5 -7
  2. package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
  3. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  4. package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
  5. package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
  6. package/dist/bindings/cws_darwin_x64_node108.node +0 -0
  7. package/dist/bindings/cws_darwin_x64_node115.node +0 -0
  8. package/dist/bindings/cws_darwin_x64_node83.node +0 -0
  9. package/dist/bindings/cws_darwin_x64_node93.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node108.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node83.node +0 -0
  13. package/dist/bindings/cws_linux_arm64_node93.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node108.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node83.node +0 -0
  17. package/dist/bindings/cws_linux_x64_node93.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node108.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node83.node +0 -0
  21. package/dist/bindings/cws_win32_x64_node93.node +0 -0
  22. package/dist/shared.js +1 -1
  23. package/package.json +5 -5
  24. package/src/Addon.cpp +4 -12
  25. package/src/Addon.h +67 -91
  26. package/src/Socket.h +1 -0
  27. package/src/cSNode.cpp +3 -8
  28. package/src/headers/20/acorn_version.h +6 -0
  29. package/src/headers/20/aliased_buffer-inl.h +243 -0
  30. package/src/headers/20/aliased_buffer.h +206 -0
  31. package/src/headers/20/aliased_struct-inl.h +54 -0
  32. package/src/headers/20/aliased_struct.h +63 -0
  33. package/src/headers/20/async_wrap-inl.h +93 -0
  34. package/src/headers/20/async_wrap.h +252 -0
  35. package/src/headers/20/base64-inl.h +193 -0
  36. package/src/headers/20/base64.h +53 -0
  37. package/src/headers/20/base64_version.h +6 -0
  38. package/src/headers/20/base_object-inl.h +316 -0
  39. package/src/headers/20/base_object.h +320 -0
  40. package/src/headers/20/base_object_types.h +73 -0
  41. package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
  42. package/src/headers/20/blob_serializer_deserializer.h +132 -0
  43. package/src/headers/20/callback_queue-inl.h +97 -0
  44. package/src/headers/20/callback_queue.h +79 -0
  45. package/src/headers/20/cares_wrap.h +524 -0
  46. package/src/headers/20/cjs_module_lexer_version.h +6 -0
  47. package/src/headers/20/cleanup_queue-inl.h +62 -0
  48. package/src/headers/20/cleanup_queue.h +85 -0
  49. package/src/headers/20/connect_wrap.h +26 -0
  50. package/src/headers/20/connection_wrap.h +30 -0
  51. package/src/headers/20/cppgc/DEPS +8 -0
  52. package/src/headers/20/cppgc/OWNERS +2 -0
  53. package/src/headers/20/cppgc/README.md +135 -0
  54. package/src/headers/20/cppgc/allocation.h +310 -0
  55. package/src/headers/20/cppgc/common.h +28 -0
  56. package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
  57. package/src/headers/20/cppgc/custom-space.h +97 -0
  58. package/src/headers/20/cppgc/default-platform.h +67 -0
  59. package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
  60. package/src/headers/20/cppgc/explicit-management.h +100 -0
  61. package/src/headers/20/cppgc/garbage-collected.h +106 -0
  62. package/src/headers/20/cppgc/heap-consistency.h +309 -0
  63. package/src/headers/20/cppgc/heap-handle.h +48 -0
  64. package/src/headers/20/cppgc/heap-state.h +82 -0
  65. package/src/headers/20/cppgc/heap-statistics.h +120 -0
  66. package/src/headers/20/cppgc/heap.h +202 -0
  67. package/src/headers/20/cppgc/internal/api-constants.h +68 -0
  68. package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
  69. package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
  70. package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
  71. package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
  72. package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
  73. package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
  74. package/src/headers/20/cppgc/internal/gc-info.h +157 -0
  75. package/src/headers/20/cppgc/internal/logging.h +50 -0
  76. package/src/headers/20/cppgc/internal/member-storage.h +248 -0
  77. package/src/headers/20/cppgc/internal/name-trait.h +137 -0
  78. package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
  79. package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
  80. package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
  81. package/src/headers/20/cppgc/liveness-broker.h +78 -0
  82. package/src/headers/20/cppgc/macros.h +35 -0
  83. package/src/headers/20/cppgc/member.h +604 -0
  84. package/src/headers/20/cppgc/name-provider.h +65 -0
  85. package/src/headers/20/cppgc/object-size-trait.h +58 -0
  86. package/src/headers/20/cppgc/persistent.h +373 -0
  87. package/src/headers/20/cppgc/platform.h +158 -0
  88. package/src/headers/20/cppgc/prefinalizer.h +75 -0
  89. package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
  90. package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
  91. package/src/headers/20/cppgc/source-location.h +92 -0
  92. package/src/headers/20/cppgc/testing.h +106 -0
  93. package/src/headers/20/cppgc/trace-trait.h +120 -0
  94. package/src/headers/20/cppgc/type-traits.h +250 -0
  95. package/src/headers/20/cppgc/visitor.h +426 -0
  96. package/src/headers/20/crypto/crypto_clienthello.h +131 -0
  97. package/src/headers/20/crypto/crypto_context.h +160 -0
  98. package/src/headers/20/crypto/crypto_keys.h +419 -0
  99. package/src/headers/20/crypto/crypto_tls.h +304 -0
  100. package/src/headers/20/crypto/crypto_util.h +806 -0
  101. package/src/headers/20/crypto_clienthello.h +131 -0
  102. package/src/headers/20/debug_utils-inl.h +226 -0
  103. package/src/headers/20/debug_utils.h +188 -0
  104. package/src/headers/20/diagnosticfilename-inl.h +33 -0
  105. package/src/headers/20/encoding_binding.h +59 -0
  106. package/src/headers/20/env-inl.h +923 -0
  107. package/src/headers/20/env.h +1193 -0
  108. package/src/headers/20/env_properties.h +446 -0
  109. package/src/headers/20/handle_wrap.h +123 -0
  110. package/src/headers/20/histogram-inl.h +107 -0
  111. package/src/headers/20/histogram.h +240 -0
  112. package/src/headers/20/inspector_agent.h +144 -0
  113. package/src/headers/20/inspector_io.h +78 -0
  114. package/src/headers/20/inspector_profiler.h +149 -0
  115. package/src/headers/20/inspector_socket.h +60 -0
  116. package/src/headers/20/inspector_socket_server.h +110 -0
  117. package/src/headers/20/js_native_api.h +601 -0
  118. package/src/headers/20/js_native_api_types.h +168 -0
  119. package/src/headers/20/js_native_api_v8.h +463 -0
  120. package/src/headers/20/js_native_api_v8_internals.h +45 -0
  121. package/src/headers/20/js_stream.h +52 -0
  122. package/src/headers/20/json_parser.h +38 -0
  123. package/src/headers/20/json_utils.h +172 -0
  124. package/src/headers/20/memory_tracker-inl.h +356 -0
  125. package/src/headers/20/memory_tracker.h +289 -0
  126. package/src/headers/20/module_wrap.h +117 -0
  127. package/src/headers/20/node.h +1516 -0
  128. package/src/headers/20/node_api.h +261 -0
  129. package/src/headers/20/node_api_internals.h +42 -0
  130. package/src/headers/20/node_api_types.h +52 -0
  131. package/src/headers/20/node_binding.h +142 -0
  132. package/src/headers/20/node_blob.h +159 -0
  133. package/src/headers/20/node_bob-inl.h +36 -0
  134. package/src/headers/20/node_bob.h +107 -0
  135. package/src/headers/20/node_buffer.h +92 -0
  136. package/src/headers/20/node_builtins.h +197 -0
  137. package/src/headers/20/node_constants.h +82 -0
  138. package/src/headers/20/node_context_data.h +98 -0
  139. package/src/headers/20/node_contextify.h +206 -0
  140. package/src/headers/20/node_crypto.h +56 -0
  141. package/src/headers/20/node_dir.h +52 -0
  142. package/src/headers/20/node_dotenv.h +37 -0
  143. package/src/headers/20/node_errors.h +313 -0
  144. package/src/headers/20/node_exit_code.h +54 -0
  145. package/src/headers/20/node_external_reference.h +172 -0
  146. package/src/headers/20/node_file-inl.h +389 -0
  147. package/src/headers/20/node_file.h +537 -0
  148. package/src/headers/20/node_http2.h +1146 -0
  149. package/src/headers/20/node_http2_state.h +147 -0
  150. package/src/headers/20/node_http_common-inl.h +201 -0
  151. package/src/headers/20/node_http_common.h +532 -0
  152. package/src/headers/20/node_i18n.h +145 -0
  153. package/src/headers/20/node_internals.h +443 -0
  154. package/src/headers/20/node_main_instance.h +67 -0
  155. package/src/headers/20/node_mem-inl.h +112 -0
  156. package/src/headers/20/node_mem.h +45 -0
  157. package/src/headers/20/node_messaging.h +377 -0
  158. package/src/headers/20/node_metadata.h +138 -0
  159. package/src/headers/20/node_mutex.h +323 -0
  160. package/src/headers/20/node_object_wrap.h +132 -0
  161. package/src/headers/20/node_options-inl.h +478 -0
  162. package/src/headers/20/node_options.h +538 -0
  163. package/src/headers/20/node_perf.h +166 -0
  164. package/src/headers/20/node_perf_common.h +98 -0
  165. package/src/headers/20/node_platform.h +195 -0
  166. package/src/headers/20/node_process-inl.h +26 -0
  167. package/src/headers/20/node_process.h +99 -0
  168. package/src/headers/20/node_realm-inl.h +139 -0
  169. package/src/headers/20/node_realm.h +184 -0
  170. package/src/headers/20/node_report.h +42 -0
  171. package/src/headers/20/node_revert.h +82 -0
  172. package/src/headers/20/node_root_certs.h +3443 -0
  173. package/src/headers/20/node_sea.h +56 -0
  174. package/src/headers/20/node_shadow_realm.h +46 -0
  175. package/src/headers/20/node_snapshot_builder.h +54 -0
  176. package/src/headers/20/node_snapshotable.h +164 -0
  177. package/src/headers/20/node_sockaddr-inl.h +266 -0
  178. package/src/headers/20/node_sockaddr.h +405 -0
  179. package/src/headers/20/node_stat_watcher.h +73 -0
  180. package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
  181. package/src/headers/20/node_threadsafe_cow.h +105 -0
  182. package/src/headers/20/node_union_bytes.h +81 -0
  183. package/src/headers/20/node_url.h +92 -0
  184. package/src/headers/20/node_v8.h +77 -0
  185. package/src/headers/20/node_v8_platform-inl.h +205 -0
  186. package/src/headers/20/node_version.h +109 -0
  187. package/src/headers/20/node_wasi.h +184 -0
  188. package/src/headers/20/node_wasm_web_api.h +55 -0
  189. package/src/headers/20/node_watchdog.h +154 -0
  190. package/src/headers/20/node_worker.h +151 -0
  191. package/src/headers/20/permission/child_process_permission.h +29 -0
  192. package/src/headers/20/permission/fs_permission.h +154 -0
  193. package/src/headers/20/permission/inspector_permission.h +29 -0
  194. package/src/headers/20/permission/permission.h +74 -0
  195. package/src/headers/20/permission/permission_base.h +53 -0
  196. package/src/headers/20/permission/worker_permission.h +29 -0
  197. package/src/headers/20/pipe_wrap.h +80 -0
  198. package/src/headers/20/req_wrap-inl.h +171 -0
  199. package/src/headers/20/req_wrap.h +77 -0
  200. package/src/headers/20/spawn_sync.h +242 -0
  201. package/src/headers/20/stream_base-inl.h +173 -0
  202. package/src/headers/20/stream_base.h +469 -0
  203. package/src/headers/20/stream_pipe.h +76 -0
  204. package/src/headers/20/stream_wrap.h +131 -0
  205. package/src/headers/20/string_bytes.h +120 -0
  206. package/src/headers/20/string_decoder-inl.h +37 -0
  207. package/src/headers/20/string_decoder.h +50 -0
  208. package/src/headers/20/string_search.h +638 -0
  209. package/src/headers/20/tcp_wrap.h +105 -0
  210. package/src/headers/20/threadpoolwork-inl.h +70 -0
  211. package/src/headers/20/timer_wrap-inl.h +32 -0
  212. package/src/headers/20/timer_wrap.h +85 -0
  213. package/src/headers/20/timers.h +70 -0
  214. package/src/headers/20/tracing/agent.h +195 -0
  215. package/src/headers/20/tracing/node_trace_buffer.h +83 -0
  216. package/src/headers/20/tracing/node_trace_writer.h +75 -0
  217. package/src/headers/20/tracing/trace_event.h +720 -0
  218. package/src/headers/20/tracing/trace_event_common.h +1109 -0
  219. package/src/headers/20/tracing/traced_value.h +70 -0
  220. package/src/headers/20/tty_wrap.h +65 -0
  221. package/src/headers/20/udp_wrap.h +227 -0
  222. package/src/headers/20/undici_version.h +6 -0
  223. package/src/headers/20/util-inl.h +623 -0
  224. package/src/headers/20/util.h +988 -0
  225. package/src/headers/20/v8-cppgc.h +245 -0
  226. package/src/headers/20/v8-fast-api-calls.h +957 -0
  227. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  228. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  229. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  230. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  231. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  232. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  233. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  234. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  235. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  236. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  237. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  238. package/dist/bindings/cws_win32_x64_node79.node +0 -0
@@ -0,0 +1,107 @@
1
+ #ifndef SRC_NODE_BOB_H_
2
+ #define SRC_NODE_BOB_H_
3
+
4
+ #include <functional>
5
+
6
+ namespace node {
7
+ namespace bob {
8
+
9
+ constexpr size_t kMaxCountHint = 16;
10
+
11
+ // Negative status codes indicate error conditions.
12
+ enum Status : int {
13
+ // Indicates that an attempt was made to pull after end.
14
+ STATUS_EOS = 0,
15
+
16
+ // Indicates that there is additional data available
17
+ // and the consumer may continue to pull.
18
+ STATUS_CONTINUE = 1,
19
+
20
+ // Indicates that there is no additional data available
21
+ // but the stream has not ended. The consumer should not
22
+ // continue to pull but may resume pulling later when
23
+ // data is available.
24
+ STATUS_BLOCK = 2,
25
+
26
+ // Indicates that there is no additional data available
27
+ // but the stream has not ended and the source will call
28
+ // next again later when data is available. STATUS_WAIT
29
+ // must not be used with the OPTIONS_SYNC option.
30
+ STATUS_WAIT = 3,
31
+ };
32
+
33
+ enum Options : int {
34
+ OPTIONS_NONE = 0,
35
+
36
+ // Indicates that the consumer is requesting the end
37
+ // of the stream.
38
+ OPTIONS_END = 1,
39
+
40
+ // Indicates that the consumer requires the source to
41
+ // invoke Next synchronously. If the source is
42
+ // unable to provide data immediately but the
43
+ // stream has not yet ended, it should call Next
44
+ // using STATUS_BLOCK. When not set, the source
45
+ // may call Next asynchronously.
46
+ OPTIONS_SYNC = 2
47
+ };
48
+
49
+ // There are Sources and there are Consumers.
50
+ //
51
+ // Consumers get data by calling Source::Pull,
52
+ // optionally passing along a status and allocated
53
+ // buffer space for the source to fill, and a Next
54
+ // function the Source will call when data is
55
+ // available.
56
+ //
57
+ // The source calls Next to deliver the data. It can
58
+ // choose to either use the allocated buffer space
59
+ // provided by the consumer or it can allocate its own
60
+ // buffers and push those instead. If it allocates
61
+ // its own, it can send a Done function that the
62
+ // Sink will call when it is done consuming the data.
63
+ using Done = std::function<void(size_t)>;
64
+ template <typename T>
65
+ using Next = std::function<void(int, const T*, size_t count, Done done)>;
66
+
67
+ template <typename T>
68
+ class Source {
69
+ public:
70
+ virtual ~Source() = default;
71
+ virtual int Pull(
72
+ Next<T> next,
73
+ int options,
74
+ T* data,
75
+ size_t count,
76
+ size_t max_count_hint = kMaxCountHint) = 0;
77
+ };
78
+
79
+
80
+ template <typename T>
81
+ class SourceImpl : public Source<T> {
82
+ public:
83
+ int Pull(
84
+ Next<T> next,
85
+ int options,
86
+ T* data,
87
+ size_t count,
88
+ size_t max_count_hint = kMaxCountHint) override;
89
+
90
+ bool is_eos() const { return eos_; }
91
+
92
+ protected:
93
+ virtual int DoPull(
94
+ Next<T> next,
95
+ int options,
96
+ T* data,
97
+ size_t count,
98
+ size_t max_count_hint) = 0;
99
+
100
+ private:
101
+ bool eos_ = false;
102
+ };
103
+
104
+ } // namespace bob
105
+ } // namespace node
106
+
107
+ #endif // SRC_NODE_BOB_H_
@@ -0,0 +1,92 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ #ifndef SRC_NODE_BUFFER_H_
23
+ #define SRC_NODE_BUFFER_H_
24
+
25
+ #include "node.h"
26
+ #include "v8.h"
27
+
28
+ namespace node {
29
+
30
+ namespace Buffer {
31
+
32
+ static const size_t kMaxLength = v8::TypedArray::kMaxLength;
33
+
34
+ typedef void (*FreeCallback)(char* data, void* hint);
35
+
36
+ NODE_EXTERN bool HasInstance(v8::Local<v8::Value> val);
37
+ NODE_EXTERN bool HasInstance(v8::Local<v8::Object> val);
38
+ NODE_EXTERN char* Data(v8::Local<v8::Value> val);
39
+ NODE_EXTERN char* Data(v8::Local<v8::Object> val);
40
+ NODE_EXTERN size_t Length(v8::Local<v8::Value> val);
41
+ NODE_EXTERN size_t Length(v8::Local<v8::Object> val);
42
+
43
+ // public constructor - data is copied
44
+ NODE_EXTERN v8::MaybeLocal<v8::Object> Copy(v8::Isolate* isolate,
45
+ const char* data,
46
+ size_t len);
47
+
48
+ // public constructor
49
+ NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
50
+
51
+ // public constructor from string
52
+ NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
53
+ v8::Local<v8::String> string,
54
+ enum encoding enc = UTF8);
55
+
56
+ // public constructor - data is used, callback is passed data on object gc
57
+ NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
58
+ char* data,
59
+ size_t length,
60
+ FreeCallback callback,
61
+ void* hint);
62
+
63
+ // public constructor - data is used.
64
+ NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
65
+ char* data,
66
+ size_t len);
67
+
68
+ // Creates a Buffer instance over an existing ArrayBuffer.
69
+ NODE_EXTERN v8::MaybeLocal<v8::Uint8Array> New(v8::Isolate* isolate,
70
+ v8::Local<v8::ArrayBuffer> ab,
71
+ size_t byte_offset,
72
+ size_t length);
73
+
74
+ // This is verbose to be explicit with inline commenting
75
+ static inline bool IsWithinBounds(size_t off, size_t len, size_t max) {
76
+ // Asking to seek too far into the buffer
77
+ // check to avoid wrapping in subsequent subtraction
78
+ if (off > max)
79
+ return false;
80
+
81
+ // Asking for more than is left over in the buffer
82
+ if (max - off < len)
83
+ return false;
84
+
85
+ // Otherwise we're in bounds
86
+ return true;
87
+ }
88
+
89
+ } // namespace Buffer
90
+ } // namespace node
91
+
92
+ #endif // SRC_NODE_BUFFER_H_
@@ -0,0 +1,197 @@
1
+ #ifndef SRC_NODE_BUILTINS_H_
2
+ #define SRC_NODE_BUILTINS_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <list>
7
+ #include <map>
8
+ #include <memory>
9
+ #include <optional>
10
+ #include <set>
11
+ #include <string>
12
+ #include <vector>
13
+ #include "node_external_reference.h"
14
+ #include "node_mutex.h"
15
+ #include "node_threadsafe_cow.h"
16
+ #include "node_union_bytes.h"
17
+ #include "v8.h"
18
+
19
+ // Forward declare test fixture for `friend` declaration.
20
+ class PerProcessTest;
21
+
22
+ namespace node {
23
+ class SnapshotBuilder;
24
+ class ExternalReferenceRegistry;
25
+ class Realm;
26
+
27
+ namespace builtins {
28
+
29
+ class BuiltinCodeCacheData {
30
+ public:
31
+ BuiltinCodeCacheData() : data(nullptr), length(0), owning_ptr(nullptr) {}
32
+
33
+ explicit BuiltinCodeCacheData(
34
+ std::shared_ptr<v8::ScriptCompiler::CachedData> cached_data)
35
+ : data(cached_data->data),
36
+ length(cached_data->length),
37
+ owning_ptr(cached_data) {}
38
+
39
+ explicit BuiltinCodeCacheData(
40
+ std::shared_ptr<std::vector<uint8_t>> cached_data)
41
+ : data(cached_data->data()),
42
+ length(cached_data->size()),
43
+ owning_ptr(cached_data) {}
44
+
45
+ BuiltinCodeCacheData(const uint8_t* data, size_t length)
46
+ : data(data), length(length), owning_ptr(nullptr) {}
47
+
48
+ const uint8_t* data;
49
+ size_t length;
50
+
51
+ // Returns a v8::ScriptCompiler::CachedData corresponding to this
52
+ // BuiltinCodeCacheData. The lifetime of the returned
53
+ // v8::ScriptCompiler::CachedData must not outlive that of the data.
54
+ std::unique_ptr<v8::ScriptCompiler::CachedData> AsCachedData() {
55
+ return std::make_unique<v8::ScriptCompiler::CachedData>(
56
+ data, length, v8::ScriptCompiler::CachedData::BufferNotOwned);
57
+ }
58
+
59
+ private:
60
+ // If not null, represents a pointer which owns data. Otherwise indicates
61
+ // that data has static lifetime.
62
+ std::shared_ptr<void> owning_ptr;
63
+ };
64
+
65
+ struct CodeCacheInfo {
66
+ std::string id;
67
+ BuiltinCodeCacheData data;
68
+ };
69
+
70
+ using BuiltinSourceMap = std::map<std::string, UnionBytes>;
71
+ using BuiltinCodeCacheMap =
72
+ std::unordered_map<std::string, BuiltinCodeCacheData>;
73
+
74
+ // Generated by tools/js2c.py as node_javascript.cc
75
+ void RegisterExternalReferencesForInternalizedBuiltinCode(
76
+ ExternalReferenceRegistry* registry);
77
+
78
+ // Handles compilation and caching of built-in JavaScript modules and
79
+ // bootstrap scripts, whose source are bundled into the binary as static data.
80
+ class NODE_EXTERN_PRIVATE BuiltinLoader {
81
+ public:
82
+ BuiltinLoader();
83
+ BuiltinLoader(const BuiltinLoader&) = delete;
84
+ BuiltinLoader& operator=(const BuiltinLoader&) = delete;
85
+
86
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
87
+ static void CreatePerIsolateProperties(IsolateData* isolate_data,
88
+ v8::Local<v8::ObjectTemplate> target);
89
+ static void CreatePerContextProperties(v8::Local<v8::Object> target,
90
+ v8::Local<v8::Value> unused,
91
+ v8::Local<v8::Context> context,
92
+ void* priv);
93
+
94
+ // The parameters used to compile the scripts are detected based on
95
+ // the pattern of the id.
96
+ v8::MaybeLocal<v8::Function> LookupAndCompile(v8::Local<v8::Context> context,
97
+ const char* id,
98
+ Realm* optional_realm);
99
+
100
+ v8::MaybeLocal<v8::Value> CompileAndCall(v8::Local<v8::Context> context,
101
+ const char* id,
102
+ int argc,
103
+ v8::Local<v8::Value> argv[],
104
+ Realm* optional_realm);
105
+
106
+ v8::MaybeLocal<v8::Value> CompileAndCall(v8::Local<v8::Context> context,
107
+ const char* id,
108
+ Realm* realm);
109
+
110
+ // Returns config.gypi as a JSON string
111
+ v8::Local<v8::String> GetConfigString(v8::Isolate* isolate);
112
+ bool Exists(const char* id);
113
+ bool Add(const char* id, const UnionBytes& source);
114
+
115
+ bool CompileAllBuiltins(v8::Local<v8::Context> context);
116
+ void RefreshCodeCache(const std::vector<CodeCacheInfo>& in);
117
+ void CopyCodeCache(std::vector<CodeCacheInfo>* out) const;
118
+
119
+ void CopySourceAndCodeCacheReferenceFrom(const BuiltinLoader* other);
120
+
121
+ private:
122
+ // Only allow access from friends.
123
+ friend class CodeCacheBuilder;
124
+
125
+ // Generated by tools/js2c.py as node_javascript.cc
126
+ void LoadJavaScriptSource(); // Loads data into source_
127
+ UnionBytes GetConfig(); // Return data for config.gypi
128
+
129
+ std::vector<std::string_view> GetBuiltinIds() const;
130
+
131
+ struct BuiltinCategories {
132
+ std::set<std::string> can_be_required;
133
+ std::set<std::string> cannot_be_required;
134
+ };
135
+ // This method builds `BuiltinCategories` from scratch every time,
136
+ // and is therefore somewhat expensive, but also currently only being
137
+ // used for testing, so that should not be an issue.
138
+ BuiltinCategories GetBuiltinCategories() const;
139
+
140
+ const v8::ScriptCompiler::CachedData* GetCodeCache(const char* id) const;
141
+ enum class Result { kWithCache, kWithoutCache };
142
+ v8::MaybeLocal<v8::String> LoadBuiltinSource(v8::Isolate* isolate,
143
+ const char* id) const;
144
+ // If an exception is encountered (e.g. source code contains
145
+ // syntax error), the returned value is empty.
146
+ v8::MaybeLocal<v8::Function> LookupAndCompileInternal(
147
+ v8::Local<v8::Context> context,
148
+ const char* id,
149
+ std::vector<v8::Local<v8::String>>* parameters,
150
+ Realm* optional_realm);
151
+ void SaveCodeCache(const char* id, v8::Local<v8::Function> fn);
152
+
153
+ static void RecordResult(const char* id,
154
+ BuiltinLoader::Result result,
155
+ Realm* realm);
156
+ static void GetBuiltinCategories(
157
+ v8::Local<v8::Name> property,
158
+ const v8::PropertyCallbackInfo<v8::Value>& info);
159
+ static void GetCacheUsage(const v8::FunctionCallbackInfo<v8::Value>& args);
160
+ // Passing ids of built-in source code into JS land as
161
+ // internalBinding('builtins').builtinIds
162
+ static void BuiltinIdsGetter(v8::Local<v8::Name> property,
163
+ const v8::PropertyCallbackInfo<v8::Value>& info);
164
+ // Passing config.gypi into JS land as internalBinding('builtins').config
165
+ static void ConfigStringGetter(
166
+ v8::Local<v8::Name> property,
167
+ const v8::PropertyCallbackInfo<v8::Value>& info);
168
+ // Compile a specific built-in as a function
169
+ static void CompileFunction(const v8::FunctionCallbackInfo<v8::Value>& args);
170
+ static void HasCachedBuiltins(
171
+ const v8::FunctionCallbackInfo<v8::Value>& args);
172
+ // For legacy process.binding('natives')
173
+ static void GetNatives(v8::Local<v8::Name> property,
174
+ const v8::PropertyCallbackInfo<v8::Value>& info);
175
+
176
+ void AddExternalizedBuiltin(const char* id, const char* filename);
177
+
178
+ ThreadsafeCopyOnWrite<BuiltinSourceMap> source_;
179
+
180
+ const UnionBytes config_;
181
+
182
+ struct BuiltinCodeCache {
183
+ RwLock mutex;
184
+ BuiltinCodeCacheMap map;
185
+ bool has_code_cache = false;
186
+ };
187
+ std::shared_ptr<BuiltinCodeCache> code_cache_;
188
+
189
+ friend class ::PerProcessTest;
190
+ };
191
+ } // namespace builtins
192
+
193
+ } // namespace node
194
+
195
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
196
+
197
+ #endif // SRC_NODE_BUILTINS_H_
@@ -0,0 +1,82 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ #ifndef SRC_NODE_CONSTANTS_H_
23
+ #define SRC_NODE_CONSTANTS_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include "node.h"
28
+ #include "v8.h"
29
+
30
+ #define EXTENSIONLESS_FORMAT_JAVASCRIPT (0)
31
+ #define EXTENSIONLESS_FORMAT_WASM (1)
32
+
33
+ #if HAVE_OPENSSL
34
+
35
+ #ifndef RSA_PSS_SALTLEN_DIGEST
36
+ #define RSA_PSS_SALTLEN_DIGEST -1
37
+ #endif
38
+
39
+ #ifndef RSA_PSS_SALTLEN_MAX_SIGN
40
+ #define RSA_PSS_SALTLEN_MAX_SIGN -2
41
+ #endif
42
+
43
+ #ifndef RSA_PSS_SALTLEN_AUTO
44
+ #define RSA_PSS_SALTLEN_AUTO -2
45
+ #endif
46
+
47
+ #if defined(NODE_OPENSSL_DEFAULT_CIPHER_LIST)
48
+ #define DEFAULT_CIPHER_LIST_CORE NODE_OPENSSL_DEFAULT_CIPHER_LIST
49
+ #else
50
+ // TLSv1.3 suites start with TLS_, and are the OpenSSL defaults, see:
51
+ // https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_ciphersuites.html
52
+ #define DEFAULT_CIPHER_LIST_CORE \
53
+ "TLS_AES_256_GCM_SHA384:" \
54
+ "TLS_CHACHA20_POLY1305_SHA256:" \
55
+ "TLS_AES_128_GCM_SHA256:" \
56
+ "ECDHE-RSA-AES128-GCM-SHA256:" \
57
+ "ECDHE-ECDSA-AES128-GCM-SHA256:" \
58
+ "ECDHE-RSA-AES256-GCM-SHA384:" \
59
+ "ECDHE-ECDSA-AES256-GCM-SHA384:" \
60
+ "DHE-RSA-AES128-GCM-SHA256:" \
61
+ "ECDHE-RSA-AES128-SHA256:" \
62
+ "DHE-RSA-AES128-SHA256:" \
63
+ "ECDHE-RSA-AES256-SHA384:" \
64
+ "DHE-RSA-AES256-SHA384:" \
65
+ "ECDHE-RSA-AES256-SHA256:" \
66
+ "DHE-RSA-AES256-SHA256:" \
67
+ "HIGH:" \
68
+ "!aNULL:" \
69
+ "!eNULL:" \
70
+ "!EXPORT:" \
71
+ "!DES:" \
72
+ "!RC4:" \
73
+ "!MD5:" \
74
+ "!PSK:" \
75
+ "!SRP:" \
76
+ "!CAMELLIA"
77
+ #endif // NODE_OPENSSL_DEFAULT_CIPHER_LIST
78
+ #endif // HAVE_OPENSSL
79
+
80
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
81
+
82
+ #endif // SRC_NODE_CONSTANTS_H_
@@ -0,0 +1,98 @@
1
+ #ifndef SRC_NODE_CONTEXT_DATA_H_
2
+ #define SRC_NODE_CONTEXT_DATA_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "util.h"
7
+ #include "v8.h"
8
+
9
+ namespace node {
10
+
11
+ // Pick an index that's hopefully out of the way when we're embedded inside
12
+ // another application. Performance-wise or memory-wise it doesn't matter:
13
+ // Context::SetAlignedPointerInEmbedderData() is backed by a FixedArray,
14
+ // worst case we pay a one-time penalty for resizing the array.
15
+ #ifndef NODE_CONTEXT_EMBEDDER_DATA_INDEX
16
+ #define NODE_CONTEXT_EMBEDDER_DATA_INDEX 32
17
+ #endif
18
+
19
+ #ifndef NODE_CONTEXT_SANDBOX_OBJECT_INDEX
20
+ #define NODE_CONTEXT_SANDBOX_OBJECT_INDEX 33
21
+ #endif
22
+
23
+ #ifndef NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX
24
+ #define NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX 34
25
+ #endif
26
+
27
+ #ifndef NODE_BINDING_DATA_STORE_INDEX
28
+ #define NODE_BINDING_DATA_STORE_INDEX 35
29
+ #endif
30
+
31
+ #ifndef NODE_CONTEXT_ALLOW_CODE_GENERATION_FROM_STRINGS_INDEX
32
+ #define NODE_CONTEXT_ALLOW_CODE_GENERATION_FROM_STRINGS_INDEX 36
33
+ #endif
34
+
35
+ #ifndef NODE_CONTEXT_CONTEXTIFY_CONTEXT_INDEX
36
+ #define NODE_CONTEXT_CONTEXTIFY_CONTEXT_INDEX 37
37
+ #endif
38
+
39
+ #ifndef NODE_CONTEXT_REALM_INDEX
40
+ #define NODE_CONTEXT_REALM_INDEX 38
41
+ #endif
42
+
43
+ // NODE_CONTEXT_TAG must be greater than any embedder indexes so that a single
44
+ // check on the number of embedder data fields can assure the presence of all
45
+ // embedder indexes.
46
+ #ifndef NODE_CONTEXT_TAG
47
+ #define NODE_CONTEXT_TAG 39
48
+ #endif
49
+
50
+ enum ContextEmbedderIndex {
51
+ kEnvironment = NODE_CONTEXT_EMBEDDER_DATA_INDEX,
52
+ kSandboxObject = NODE_CONTEXT_SANDBOX_OBJECT_INDEX,
53
+ kAllowWasmCodeGeneration = NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX,
54
+ kAllowCodeGenerationFromStrings =
55
+ NODE_CONTEXT_ALLOW_CODE_GENERATION_FROM_STRINGS_INDEX,
56
+ kContextifyContext = NODE_CONTEXT_CONTEXTIFY_CONTEXT_INDEX,
57
+ kRealm = NODE_CONTEXT_REALM_INDEX,
58
+ kContextTag = NODE_CONTEXT_TAG,
59
+ };
60
+
61
+ class ContextEmbedderTag {
62
+ public:
63
+ static inline void TagNodeContext(v8::Local<v8::Context> context) {
64
+ // Used by ContextEmbedderTag::IsNodeContext to know that we are on a node
65
+ // context.
66
+ context->SetAlignedPointerInEmbedderData(
67
+ ContextEmbedderIndex::kContextTag,
68
+ ContextEmbedderTag::kNodeContextTagPtr);
69
+ }
70
+
71
+ static inline bool IsNodeContext(v8::Local<v8::Context> context) {
72
+ if (UNLIKELY(context.IsEmpty())) {
73
+ return false;
74
+ }
75
+ if (UNLIKELY(context->GetNumberOfEmbedderDataFields() <=
76
+ ContextEmbedderIndex::kContextTag)) {
77
+ return false;
78
+ }
79
+ if (UNLIKELY(context->GetAlignedPointerFromEmbedderData(
80
+ ContextEmbedderIndex::kContextTag) !=
81
+ ContextEmbedderTag::kNodeContextTagPtr)) {
82
+ return false;
83
+ }
84
+ return true;
85
+ }
86
+
87
+ private:
88
+ static void* const kNodeContextTagPtr;
89
+ static int const kNodeContextTag;
90
+
91
+ ContextEmbedderTag() = delete;
92
+ };
93
+
94
+ } // namespace node
95
+
96
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
97
+
98
+ #endif // SRC_NODE_CONTEXT_DATA_H_