@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,443 @@
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_INTERNALS_H_
23
+ #define SRC_NODE_INTERNALS_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include "env.h"
28
+ #include "node.h"
29
+ #include "node_binding.h"
30
+ #include "node_mutex.h"
31
+ #include "tracing/trace_event.h"
32
+ #include "util.h"
33
+ #include "uv.h"
34
+ #include "v8.h"
35
+
36
+ #include <cstdint>
37
+ #include <cstdlib>
38
+
39
+ #include <string>
40
+ #include <vector>
41
+
42
+ struct sockaddr;
43
+
44
+ namespace node {
45
+
46
+ namespace builtins {
47
+ class BuiltinLoader;
48
+ }
49
+
50
+ namespace per_process {
51
+ extern Mutex env_var_mutex;
52
+ extern uint64_t node_start_time;
53
+ } // namespace per_process
54
+
55
+ // Forward declaration
56
+ class Environment;
57
+
58
+ // Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object.
59
+ // Sets address and port properties on the info object and returns it.
60
+ // If |info| is omitted, a new object is returned.
61
+ v8::MaybeLocal<v8::Object> AddressToJS(
62
+ Environment* env,
63
+ const sockaddr* addr,
64
+ v8::Local<v8::Object> info = v8::Local<v8::Object>());
65
+
66
+ template <typename T, int (*F)(const typename T::HandleType*, sockaddr*, int*)>
67
+ void GetSockOrPeerName(const v8::FunctionCallbackInfo<v8::Value>& args) {
68
+ T* wrap;
69
+ ASSIGN_OR_RETURN_UNWRAP(&wrap,
70
+ args.Holder(),
71
+ args.GetReturnValue().Set(UV_EBADF));
72
+ CHECK(args[0]->IsObject());
73
+ sockaddr_storage storage;
74
+ int addrlen = sizeof(storage);
75
+ sockaddr* const addr = reinterpret_cast<sockaddr*>(&storage);
76
+ const int err = F(&wrap->handle_, addr, &addrlen);
77
+ if (err == 0)
78
+ AddressToJS(wrap->env(), addr, args[0].As<v8::Object>());
79
+ args.GetReturnValue().Set(err);
80
+ }
81
+
82
+ void PrintStackTrace(v8::Isolate* isolate, v8::Local<v8::StackTrace> stack);
83
+ void PrintCaughtException(v8::Isolate* isolate,
84
+ v8::Local<v8::Context> context,
85
+ const v8::TryCatch& try_catch);
86
+ std::string FormatCaughtException(v8::Isolate* isolate,
87
+ v8::Local<v8::Context> context,
88
+ const v8::TryCatch& try_catch);
89
+
90
+ void ResetStdio(); // Safe to call more than once and from signal handlers.
91
+ #ifdef __POSIX__
92
+ void SignalExit(int signal, siginfo_t* info, void* ucontext);
93
+ #endif
94
+
95
+ std::string GetProcessTitle(const char* default_title);
96
+ std::string GetHumanReadableProcessName();
97
+
98
+ v8::Maybe<bool> InitializeBaseContextForSnapshot(
99
+ v8::Local<v8::Context> context);
100
+ v8::Maybe<bool> InitializeContextRuntime(v8::Local<v8::Context> context);
101
+ v8::Maybe<bool> InitializePrimordials(v8::Local<v8::Context> context);
102
+
103
+ class NodeArrayBufferAllocator : public ArrayBufferAllocator {
104
+ public:
105
+ inline uint32_t* zero_fill_field() { return &zero_fill_field_; }
106
+
107
+ void* Allocate(size_t size) override; // Defined in src/node.cc
108
+ void* AllocateUninitialized(size_t size) override;
109
+ void Free(void* data, size_t size) override;
110
+ void* Reallocate(void* data, size_t old_size, size_t size) override;
111
+ virtual void RegisterPointer(void* data, size_t size) {
112
+ total_mem_usage_.fetch_add(size, std::memory_order_relaxed);
113
+ }
114
+ virtual void UnregisterPointer(void* data, size_t size) {
115
+ total_mem_usage_.fetch_sub(size, std::memory_order_relaxed);
116
+ }
117
+
118
+ NodeArrayBufferAllocator* GetImpl() final { return this; }
119
+ inline uint64_t total_mem_usage() const {
120
+ return total_mem_usage_.load(std::memory_order_relaxed);
121
+ }
122
+
123
+ private:
124
+ uint32_t zero_fill_field_ = 1; // Boolean but exposed as uint32 to JS land.
125
+ std::atomic<size_t> total_mem_usage_ {0};
126
+
127
+ // Delegate to V8's allocator for compatibility with the V8 memory cage.
128
+ std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_{
129
+ v8::ArrayBuffer::Allocator::NewDefaultAllocator()};
130
+ };
131
+
132
+ class DebuggingArrayBufferAllocator final : public NodeArrayBufferAllocator {
133
+ public:
134
+ ~DebuggingArrayBufferAllocator() override;
135
+ void* Allocate(size_t size) override;
136
+ void* AllocateUninitialized(size_t size) override;
137
+ void Free(void* data, size_t size) override;
138
+ void* Reallocate(void* data, size_t old_size, size_t size) override;
139
+ void RegisterPointer(void* data, size_t size) override;
140
+ void UnregisterPointer(void* data, size_t size) override;
141
+
142
+ private:
143
+ void RegisterPointerInternal(void* data, size_t size);
144
+ void UnregisterPointerInternal(void* data, size_t size);
145
+ Mutex mutex_;
146
+ std::unordered_map<void*, size_t> allocations_;
147
+ };
148
+
149
+ namespace Buffer {
150
+ v8::MaybeLocal<v8::Object> Copy(Environment* env, const char* data, size_t len);
151
+ v8::MaybeLocal<v8::Object> New(Environment* env, size_t size);
152
+ // Takes ownership of |data|.
153
+ v8::MaybeLocal<v8::Object> New(Environment* env,
154
+ char* data,
155
+ size_t length,
156
+ void (*callback)(char* data, void* hint),
157
+ void* hint);
158
+ // Takes ownership of |data|. Must allocate |data| with the current Isolate's
159
+ // ArrayBuffer::Allocator().
160
+ v8::MaybeLocal<v8::Object> New(Environment* env,
161
+ char* data,
162
+ size_t length);
163
+ // Creates a Buffer instance over an existing ArrayBuffer.
164
+ v8::MaybeLocal<v8::Uint8Array> New(Environment* env,
165
+ v8::Local<v8::ArrayBuffer> ab,
166
+ size_t byte_offset,
167
+ size_t length);
168
+ // Construct a Buffer from a MaybeStackBuffer (and also its subclasses like
169
+ // Utf8Value and TwoByteValue).
170
+ // If |buf| is invalidated, an empty MaybeLocal is returned, and nothing is
171
+ // changed.
172
+ // If |buf| contains actual data, this method takes ownership of |buf|'s
173
+ // underlying buffer. However, |buf| itself can be reused even after this call,
174
+ // but its capacity, if increased through AllocateSufficientStorage, is not
175
+ // guaranteed to stay the same.
176
+ template <typename T>
177
+ static v8::MaybeLocal<v8::Object> New(Environment* env,
178
+ MaybeStackBuffer<T>* buf) {
179
+ v8::MaybeLocal<v8::Object> ret;
180
+ char* src = reinterpret_cast<char*>(buf->out());
181
+ const size_t len_in_bytes = buf->length() * sizeof(buf->out()[0]);
182
+
183
+ if (buf->IsAllocated())
184
+ ret = New(env, src, len_in_bytes);
185
+ else if (!buf->IsInvalidated())
186
+ ret = Copy(env, src, len_in_bytes);
187
+
188
+ if (ret.IsEmpty())
189
+ return ret;
190
+
191
+ if (buf->IsAllocated())
192
+ buf->Release();
193
+
194
+ return ret;
195
+ }
196
+ } // namespace Buffer
197
+
198
+ v8::MaybeLocal<v8::Value> InternalMakeCallback(
199
+ Environment* env,
200
+ v8::Local<v8::Object> resource,
201
+ v8::Local<v8::Object> recv,
202
+ const v8::Local<v8::Function> callback,
203
+ int argc,
204
+ v8::Local<v8::Value> argv[],
205
+ async_context asyncContext);
206
+
207
+ v8::MaybeLocal<v8::Value> MakeSyncCallback(v8::Isolate* isolate,
208
+ v8::Local<v8::Object> recv,
209
+ v8::Local<v8::Function> callback,
210
+ int argc,
211
+ v8::Local<v8::Value> argv[]);
212
+
213
+ class InternalCallbackScope {
214
+ public:
215
+ enum Flags {
216
+ kNoFlags = 0,
217
+ // Indicates whether 'before' and 'after' hooks should be skipped.
218
+ kSkipAsyncHooks = 1,
219
+ // Indicates whether nextTick and microtask queues should be skipped.
220
+ // This should only be used when there is no call into JS in this scope.
221
+ // (The HTTP parser also uses it for some weird backwards
222
+ // compatibility issues, but it shouldn't.)
223
+ kSkipTaskQueues = 2
224
+ };
225
+ InternalCallbackScope(Environment* env,
226
+ v8::Local<v8::Object> object,
227
+ const async_context& asyncContext,
228
+ int flags = kNoFlags);
229
+ // Utility that can be used by AsyncWrap classes.
230
+ explicit InternalCallbackScope(AsyncWrap* async_wrap, int flags = 0);
231
+ ~InternalCallbackScope();
232
+ void Close();
233
+
234
+ inline bool Failed() const { return failed_; }
235
+ inline void MarkAsFailed() { failed_ = true; }
236
+
237
+ private:
238
+ Environment* env_;
239
+ async_context async_context_;
240
+ v8::Local<v8::Object> object_;
241
+ bool skip_hooks_;
242
+ bool skip_task_queues_;
243
+ bool failed_ = false;
244
+ bool pushed_ids_ = false;
245
+ bool closed_ = false;
246
+ };
247
+
248
+ class DebugSealHandleScope {
249
+ public:
250
+ explicit inline DebugSealHandleScope(v8::Isolate* isolate = nullptr)
251
+ #ifdef DEBUG
252
+ : actual_scope_(isolate != nullptr ? isolate : v8::Isolate::GetCurrent())
253
+ #endif
254
+ {}
255
+
256
+ private:
257
+ #ifdef DEBUG
258
+ v8::SealHandleScope actual_scope_;
259
+ #endif
260
+ };
261
+
262
+ class ThreadPoolWork {
263
+ public:
264
+ explicit inline ThreadPoolWork(Environment* env, const char* type)
265
+ : env_(env), type_(type) {
266
+ CHECK_NOT_NULL(env);
267
+ }
268
+ inline virtual ~ThreadPoolWork() = default;
269
+
270
+ inline void ScheduleWork();
271
+ inline int CancelWork();
272
+
273
+ virtual void DoThreadPoolWork() = 0;
274
+ virtual void AfterThreadPoolWork(int status) = 0;
275
+
276
+ Environment* env() const { return env_; }
277
+
278
+ private:
279
+ Environment* env_;
280
+ uv_work_t work_req_;
281
+ const char* type_;
282
+ };
283
+
284
+ #define TRACING_CATEGORY_NODE "node"
285
+ #define TRACING_CATEGORY_NODE1(one) \
286
+ TRACING_CATEGORY_NODE "," \
287
+ TRACING_CATEGORY_NODE "." #one
288
+ #define TRACING_CATEGORY_NODE2(one, two) \
289
+ TRACING_CATEGORY_NODE "," \
290
+ TRACING_CATEGORY_NODE "." #one "," \
291
+ TRACING_CATEGORY_NODE "." #one "." #two
292
+
293
+ // Functions defined in node.cc that are exposed via the bootstrapper object
294
+
295
+ #if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
296
+ #define NODE_IMPLEMENTS_POSIX_CREDENTIALS 1
297
+ #endif // defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
298
+
299
+ namespace credentials {
300
+ bool SafeGetenv(const char* key,
301
+ std::string* text,
302
+ std::shared_ptr<KVStore> env_vars = nullptr,
303
+ v8::Isolate* isolate = nullptr);
304
+ } // namespace credentials
305
+
306
+ void DefineZlibConstants(v8::Local<v8::Object> target);
307
+ v8::Isolate* NewIsolate(v8::Isolate::CreateParams* params,
308
+ uv_loop_t* event_loop,
309
+ MultiIsolatePlatform* platform,
310
+ const SnapshotData* snapshot_data = nullptr,
311
+ const IsolateSettings& settings = {});
312
+ // This overload automatically picks the right 'main_script_id' if no callback
313
+ // was provided by the embedder.
314
+ v8::MaybeLocal<v8::Value> StartExecution(Environment* env,
315
+ StartExecutionCallback cb = nullptr);
316
+ v8::MaybeLocal<v8::Object> GetPerContextExports(v8::Local<v8::Context> context);
317
+ void MarkBootstrapComplete(const v8::FunctionCallbackInfo<v8::Value>& args);
318
+
319
+ class InitializationResultImpl final : public InitializationResult {
320
+ public:
321
+ ~InitializationResultImpl() = default;
322
+ int exit_code() const { return static_cast<int>(exit_code_enum()); }
323
+ ExitCode exit_code_enum() const { return exit_code_; }
324
+ bool early_return() const { return early_return_; }
325
+ const std::vector<std::string>& args() const { return args_; }
326
+ const std::vector<std::string>& exec_args() const { return exec_args_; }
327
+ const std::vector<std::string>& errors() const { return errors_; }
328
+ MultiIsolatePlatform* platform() const { return platform_; }
329
+
330
+ ExitCode exit_code_ = ExitCode::kNoFailure;
331
+ std::vector<std::string> args_;
332
+ std::vector<std::string> exec_args_;
333
+ std::vector<std::string> errors_;
334
+ bool early_return_ = false;
335
+ MultiIsolatePlatform* platform_ = nullptr;
336
+ };
337
+
338
+ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s);
339
+ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s);
340
+ void SetIsolateCreateParamsForNode(v8::Isolate::CreateParams* params);
341
+
342
+ #if HAVE_INSPECTOR
343
+ namespace profiler {
344
+ void StartProfilers(Environment* env);
345
+ }
346
+ #endif // HAVE_INSPECTOR
347
+
348
+ #ifdef __POSIX__
349
+ static constexpr unsigned kMaxSignal = 32;
350
+ #endif
351
+
352
+ bool HasSignalJSHandler(int signum);
353
+
354
+ #ifdef _WIN32
355
+ typedef SYSTEMTIME TIME_TYPE;
356
+ #else // UNIX, OSX
357
+ typedef struct tm TIME_TYPE;
358
+ #endif
359
+
360
+ double GetCurrentTimeInMicroseconds();
361
+ int WriteFileSync(const char* path, uv_buf_t buf);
362
+ int WriteFileSync(v8::Isolate* isolate,
363
+ const char* path,
364
+ v8::Local<v8::String> string);
365
+
366
+ class DiagnosticFilename {
367
+ public:
368
+ static void LocalTime(TIME_TYPE* tm_struct);
369
+
370
+ inline DiagnosticFilename(Environment* env,
371
+ const char* prefix,
372
+ const char* ext);
373
+
374
+ inline DiagnosticFilename(uint64_t thread_id,
375
+ const char* prefix,
376
+ const char* ext);
377
+
378
+ inline const char* operator*() const;
379
+
380
+ private:
381
+ static std::string MakeFilename(
382
+ uint64_t thread_id,
383
+ const char* prefix,
384
+ const char* ext);
385
+
386
+ std::string filename_;
387
+ };
388
+
389
+ namespace heap {
390
+ v8::Maybe<void> WriteSnapshot(Environment* env,
391
+ const char* filename,
392
+ v8::HeapProfiler::HeapSnapshotOptions options);
393
+ }
394
+
395
+ namespace heap {
396
+
397
+ void DeleteHeapSnapshot(const v8::HeapSnapshot* snapshot);
398
+ using HeapSnapshotPointer =
399
+ DeleteFnPtr<const v8::HeapSnapshot, DeleteHeapSnapshot>;
400
+
401
+ BaseObjectPtr<AsyncWrap> CreateHeapSnapshotStream(
402
+ Environment* env, HeapSnapshotPointer&& snapshot);
403
+ } // namespace heap
404
+
405
+ namespace fs {
406
+ std::string Basename(const std::string& str, const std::string& extension);
407
+ } // namespace fs
408
+
409
+ node_module napi_module_to_node_module(const napi_module* mod);
410
+
411
+ std::ostream& operator<<(std::ostream& output,
412
+ const std::vector<SnapshotIndex>& v);
413
+ std::ostream& operator<<(std::ostream& output,
414
+ const std::vector<std::string>& vec);
415
+ std::ostream& operator<<(std::ostream& output,
416
+ const std::vector<PropInfo>& vec);
417
+ std::ostream& operator<<(std::ostream& output, const PropInfo& d);
418
+ std::ostream& operator<<(std::ostream& output, const EnvSerializeInfo& d);
419
+ std::ostream& operator<<(std::ostream& output,
420
+ const ImmediateInfo::SerializeInfo& d);
421
+ std::ostream& operator<<(std::ostream& output,
422
+ const TickInfo::SerializeInfo& d);
423
+ std::ostream& operator<<(std::ostream& output,
424
+ const AsyncHooks::SerializeInfo& d);
425
+ std::ostream& operator<<(std::ostream& output, const SnapshotMetadata& d);
426
+
427
+ namespace performance {
428
+ std::ostream& operator<<(std::ostream& output,
429
+ const PerformanceState::SerializeInfo& d);
430
+ }
431
+
432
+ bool linux_at_secure();
433
+
434
+ namespace heap {
435
+ v8::HeapProfiler::HeapSnapshotOptions GetHeapSnapshotOptions(
436
+ v8::Local<v8::Value> options);
437
+ } // namespace heap
438
+
439
+ } // namespace node
440
+
441
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
442
+
443
+ #endif // SRC_NODE_INTERNALS_H_
@@ -0,0 +1,67 @@
1
+ #ifndef SRC_NODE_MAIN_INSTANCE_H_
2
+ #define SRC_NODE_MAIN_INSTANCE_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <cstddef>
7
+ #include <memory>
8
+
9
+ #include "node.h"
10
+ #include "node_exit_code.h"
11
+ #include "util.h"
12
+ #include "uv.h"
13
+ #include "v8.h"
14
+
15
+ namespace node {
16
+
17
+ class ExternalReferenceRegistry;
18
+ struct EnvSerializeInfo;
19
+ struct SnapshotData;
20
+
21
+ // TODO(joyeecheung): align this with the Worker/WorkerThreadData class.
22
+ // We may be able to create an abstract class to reuse some of the routines.
23
+ class NodeMainInstance {
24
+ public:
25
+ // Create a main instance that owns the isolate
26
+ NodeMainInstance(const SnapshotData* snapshot_data,
27
+ uv_loop_t* event_loop,
28
+ MultiIsolatePlatform* platform,
29
+ const std::vector<std::string>& args,
30
+ const std::vector<std::string>& exec_args);
31
+ ~NodeMainInstance();
32
+
33
+ // Start running the Node.js instances, return the exit code when finished.
34
+ ExitCode Run();
35
+ void Run(ExitCode* exit_code, Environment* env);
36
+
37
+ IsolateData* isolate_data() { return isolate_data_.get(); }
38
+
39
+ DeleteFnPtr<Environment, FreeEnvironment> CreateMainEnvironment(
40
+ ExitCode* exit_code);
41
+
42
+ NodeMainInstance(const NodeMainInstance&) = delete;
43
+ NodeMainInstance& operator=(const NodeMainInstance&) = delete;
44
+ NodeMainInstance(NodeMainInstance&&) = delete;
45
+ NodeMainInstance& operator=(NodeMainInstance&&) = delete;
46
+
47
+ private:
48
+ NodeMainInstance(v8::Isolate* isolate,
49
+ uv_loop_t* event_loop,
50
+ MultiIsolatePlatform* platform,
51
+ const std::vector<std::string>& args,
52
+ const std::vector<std::string>& exec_args);
53
+
54
+ std::vector<std::string> args_;
55
+ std::vector<std::string> exec_args_;
56
+ std::unique_ptr<ArrayBufferAllocator> array_buffer_allocator_;
57
+ v8::Isolate* isolate_;
58
+ MultiIsolatePlatform* platform_;
59
+ std::unique_ptr<IsolateData> isolate_data_;
60
+ std::unique_ptr<v8::Isolate::CreateParams> isolate_params_;
61
+ const SnapshotData* snapshot_data_ = nullptr;
62
+ };
63
+
64
+ } // namespace node
65
+
66
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
67
+ #endif // SRC_NODE_MAIN_INSTANCE_H_
@@ -0,0 +1,112 @@
1
+ #ifndef SRC_NODE_MEM_INL_H_
2
+ #define SRC_NODE_MEM_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node_mem.h"
7
+ #include "node_internals.h"
8
+
9
+ namespace node {
10
+ namespace mem {
11
+
12
+ template <typename Class, typename AllocatorStruct>
13
+ AllocatorStruct NgLibMemoryManager<Class, AllocatorStruct>::MakeAllocator() {
14
+ return AllocatorStruct {
15
+ static_cast<void*>(static_cast<Class*>(this)),
16
+ MallocImpl,
17
+ FreeImpl,
18
+ CallocImpl,
19
+ ReallocImpl
20
+ };
21
+ }
22
+
23
+ template <typename Class, typename T>
24
+ void* NgLibMemoryManager<Class, T>::ReallocImpl(void* ptr,
25
+ size_t size,
26
+ void* user_data) {
27
+ Class* manager = static_cast<Class*>(user_data);
28
+
29
+ size_t previous_size = 0;
30
+ char* original_ptr = nullptr;
31
+
32
+ // We prepend each allocated buffer with a size_t containing the full
33
+ // size of the allocation.
34
+ if (size > 0) size += sizeof(size_t);
35
+
36
+ if (ptr != nullptr) {
37
+ // We are free()ing or re-allocating.
38
+ original_ptr = static_cast<char*>(ptr) - sizeof(size_t);
39
+ previous_size = *reinterpret_cast<size_t*>(original_ptr);
40
+ // This means we called StopTracking() on this pointer before.
41
+ if (previous_size == 0) {
42
+ // Fall back to the standard Realloc() function.
43
+ char* ret = UncheckedRealloc(original_ptr, size);
44
+ if (ret != nullptr)
45
+ ret += sizeof(size_t);
46
+ return ret;
47
+ }
48
+ }
49
+
50
+ manager->CheckAllocatedSize(previous_size);
51
+
52
+ char* mem = UncheckedRealloc(original_ptr, size);
53
+
54
+ if (mem != nullptr) {
55
+ // Adjust the memory info counter.
56
+ // TODO(addaleax): Avoid the double bookkeeping we do with
57
+ // current_nghttp2_memory_ + AdjustAmountOfExternalAllocatedMemory
58
+ // and provide versions of our memory allocation utilities that take an
59
+ // Environment*/Isolate* parameter and call the V8 method transparently.
60
+ const int64_t new_size = size - previous_size;
61
+ manager->IncreaseAllocatedSize(new_size);
62
+ manager->env()->isolate()->AdjustAmountOfExternalAllocatedMemory(
63
+ new_size);
64
+ *reinterpret_cast<size_t*>(mem) = size;
65
+ mem += sizeof(size_t);
66
+ } else if (size == 0) {
67
+ manager->DecreaseAllocatedSize(previous_size);
68
+ manager->env()->isolate()->AdjustAmountOfExternalAllocatedMemory(
69
+ -static_cast<int64_t>(previous_size));
70
+ }
71
+ return mem;
72
+ }
73
+
74
+ template <typename Class, typename T>
75
+ void* NgLibMemoryManager<Class, T>::MallocImpl(size_t size, void* user_data) {
76
+ return ReallocImpl(nullptr, size, user_data);
77
+ }
78
+
79
+ template <typename Class, typename T>
80
+ void NgLibMemoryManager<Class, T>::FreeImpl(void* ptr, void* user_data) {
81
+ if (ptr == nullptr) return;
82
+ CHECK_NULL(ReallocImpl(ptr, 0, user_data));
83
+ }
84
+
85
+ template <typename Class, typename T>
86
+ void* NgLibMemoryManager<Class, T>::CallocImpl(size_t nmemb,
87
+ size_t size,
88
+ void* user_data) {
89
+ size_t real_size = MultiplyWithOverflowCheck(nmemb, size);
90
+ void* mem = MallocImpl(real_size, user_data);
91
+ if (mem != nullptr)
92
+ memset(mem, 0, real_size);
93
+ return mem;
94
+ }
95
+
96
+ template <typename Class, typename T>
97
+ void NgLibMemoryManager<Class, T>::StopTrackingMemory(void* ptr) {
98
+ size_t* original_ptr = reinterpret_cast<size_t*>(
99
+ static_cast<char*>(ptr) - sizeof(size_t));
100
+ Class* manager = static_cast<Class*>(this);
101
+ manager->DecreaseAllocatedSize(*original_ptr);
102
+ manager->env()->isolate()->AdjustAmountOfExternalAllocatedMemory(
103
+ -static_cast<int64_t>(*original_ptr));
104
+ *original_ptr = 0;
105
+ }
106
+
107
+ } // namespace mem
108
+ } // namespace node
109
+
110
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
111
+
112
+ #endif // SRC_NODE_MEM_INL_H_
@@ -0,0 +1,45 @@
1
+ #ifndef SRC_NODE_MEM_H_
2
+ #define SRC_NODE_MEM_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <cstddef>
7
+
8
+ namespace node {
9
+ namespace mem {
10
+
11
+ // nghttp2 allows custom allocators that
12
+ // follow exactly the same structure and behavior, but
13
+ // use different struct names. To allow for code re-use,
14
+ // the NgLibMemoryManager template class can be used for both.
15
+
16
+ struct NgLibMemoryManagerBase {
17
+ virtual void StopTrackingMemory(void* ptr) = 0;
18
+ };
19
+
20
+ template <typename Class, typename AllocatorStructName>
21
+ class NgLibMemoryManager : public NgLibMemoryManagerBase {
22
+ public:
23
+ // Class needs to provide these methods:
24
+ // void CheckAllocatedSize(size_t previous_size) const;
25
+ // void IncreaseAllocatedSize(size_t size);
26
+ // void DecreaseAllocatedSize(size_t size);
27
+ // Environment* env() const;
28
+
29
+ AllocatorStructName MakeAllocator();
30
+
31
+ void StopTrackingMemory(void* ptr) override;
32
+
33
+ private:
34
+ static void* ReallocImpl(void* ptr, size_t size, void* user_data);
35
+ static void* MallocImpl(size_t size, void* user_data);
36
+ static void FreeImpl(void* ptr, void* user_data);
37
+ static void* CallocImpl(size_t nmemb, size_t size, void* user_data);
38
+ };
39
+
40
+ } // namespace mem
41
+ } // namespace node
42
+
43
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
44
+
45
+ #endif // SRC_NODE_MEM_H_