@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,98 @@
1
+ #ifndef SRC_NODE_PERF_COMMON_H_
2
+ #define SRC_NODE_PERF_COMMON_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "aliased_buffer.h"
7
+ #include "node.h"
8
+ #include "uv.h"
9
+ #include "v8.h"
10
+
11
+ #include <algorithm>
12
+ #include <iostream>
13
+ #include <map>
14
+ #include <string>
15
+
16
+ namespace node {
17
+ namespace performance {
18
+
19
+ #define PERFORMANCE_NOW() uv_hrtime()
20
+
21
+ // These occur before the environment is created. Cache them
22
+ // here and add them to the milestones when the env is init'd.
23
+ extern const uint64_t performance_process_start;
24
+ extern const double performance_process_start_timestamp;
25
+ extern uint64_t performance_v8_start;
26
+
27
+ #define NODE_PERFORMANCE_MILESTONES(V) \
28
+ V(TIME_ORIGIN, "timeOrigin") \
29
+ V(ENVIRONMENT, "environment") \
30
+ V(NODE_START, "nodeStart") \
31
+ V(V8_START, "v8Start") \
32
+ V(LOOP_START, "loopStart") \
33
+ V(LOOP_EXIT, "loopExit") \
34
+ V(BOOTSTRAP_COMPLETE, "bootstrapComplete")
35
+
36
+ #define NODE_PERFORMANCE_ENTRY_TYPES(V) \
37
+ V(GC, "gc") \
38
+ V(HTTP, "http") \
39
+ V(HTTP2, "http2") \
40
+ V(NET, "net") \
41
+ V(DNS, "dns")
42
+
43
+ enum PerformanceMilestone {
44
+ #define V(name, _) NODE_PERFORMANCE_MILESTONE_##name,
45
+ NODE_PERFORMANCE_MILESTONES(V)
46
+ #undef V
47
+ NODE_PERFORMANCE_MILESTONE_INVALID
48
+ };
49
+
50
+ enum PerformanceEntryType {
51
+ #define V(name, _) NODE_PERFORMANCE_ENTRY_TYPE_##name,
52
+ NODE_PERFORMANCE_ENTRY_TYPES(V)
53
+ #undef V
54
+ NODE_PERFORMANCE_ENTRY_TYPE_INVALID
55
+ };
56
+
57
+ class PerformanceState {
58
+ public:
59
+ struct SerializeInfo {
60
+ AliasedBufferIndex root;
61
+ AliasedBufferIndex milestones;
62
+ AliasedBufferIndex observers;
63
+ };
64
+
65
+ explicit PerformanceState(v8::Isolate* isolate,
66
+ uint64_t time_origin,
67
+ const SerializeInfo* info);
68
+ SerializeInfo Serialize(v8::Local<v8::Context> context,
69
+ v8::SnapshotCreator* creator);
70
+ void Deserialize(v8::Local<v8::Context> context, uint64_t time_origin);
71
+ friend std::ostream& operator<<(std::ostream& o, const SerializeInfo& i);
72
+
73
+ AliasedUint8Array root;
74
+ AliasedFloat64Array milestones;
75
+ AliasedUint32Array observers;
76
+
77
+ uint64_t performance_last_gc_start_mark = 0;
78
+ uint16_t current_gc_type = 0;
79
+
80
+ void Mark(enum PerformanceMilestone milestone,
81
+ uint64_t ts = PERFORMANCE_NOW());
82
+
83
+ private:
84
+ void Initialize(uint64_t time_origin);
85
+ void ResetMilestones();
86
+ struct performance_state_internal {
87
+ // doubles first so that they are always sizeof(double)-aligned
88
+ double milestones[NODE_PERFORMANCE_MILESTONE_INVALID];
89
+ uint32_t observers[NODE_PERFORMANCE_ENTRY_TYPE_INVALID];
90
+ };
91
+ };
92
+
93
+ } // namespace performance
94
+ } // namespace node
95
+
96
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
97
+
98
+ #endif // SRC_NODE_PERF_COMMON_H_
@@ -0,0 +1,195 @@
1
+ #ifndef SRC_NODE_PLATFORM_H_
2
+ #define SRC_NODE_PLATFORM_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <queue>
7
+ #include <unordered_map>
8
+ #include <vector>
9
+ #include <functional>
10
+
11
+ #include "libplatform/libplatform.h"
12
+ #include "node.h"
13
+ #include "node_mutex.h"
14
+ #include "uv.h"
15
+
16
+ namespace node {
17
+
18
+ class NodePlatform;
19
+ class IsolateData;
20
+ class PerIsolatePlatformData;
21
+
22
+ template <class T>
23
+ class TaskQueue {
24
+ public:
25
+ TaskQueue();
26
+ ~TaskQueue() = default;
27
+
28
+ void Push(std::unique_ptr<T> task);
29
+ std::unique_ptr<T> Pop();
30
+ std::unique_ptr<T> BlockingPop();
31
+ std::queue<std::unique_ptr<T>> PopAll();
32
+ void NotifyOfCompletion();
33
+ void BlockingDrain();
34
+ void Stop();
35
+
36
+ private:
37
+ Mutex lock_;
38
+ ConditionVariable tasks_available_;
39
+ ConditionVariable tasks_drained_;
40
+ int outstanding_tasks_;
41
+ bool stopped_;
42
+ std::queue<std::unique_ptr<T>> task_queue_;
43
+ };
44
+
45
+ struct DelayedTask {
46
+ std::unique_ptr<v8::Task> task;
47
+ uv_timer_t timer;
48
+ double timeout;
49
+ std::shared_ptr<PerIsolatePlatformData> platform_data;
50
+ };
51
+
52
+ // This acts as the foreground task runner for a given Isolate.
53
+ class PerIsolatePlatformData :
54
+ public IsolatePlatformDelegate,
55
+ public v8::TaskRunner,
56
+ public std::enable_shared_from_this<PerIsolatePlatformData> {
57
+ public:
58
+ PerIsolatePlatformData(v8::Isolate* isolate, uv_loop_t* loop);
59
+ ~PerIsolatePlatformData() override;
60
+
61
+ std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner() override;
62
+ void PostTask(std::unique_ptr<v8::Task> task) override;
63
+ void PostIdleTask(std::unique_ptr<v8::IdleTask> task) override;
64
+ void PostDelayedTask(std::unique_ptr<v8::Task> task,
65
+ double delay_in_seconds) override;
66
+ bool IdleTasksEnabled() override { return false; }
67
+
68
+ // Non-nestable tasks are treated like regular tasks.
69
+ bool NonNestableTasksEnabled() const override { return true; }
70
+ bool NonNestableDelayedTasksEnabled() const override { return true; }
71
+ void PostNonNestableTask(std::unique_ptr<v8::Task> task) override;
72
+ void PostNonNestableDelayedTask(std::unique_ptr<v8::Task> task,
73
+ double delay_in_seconds) override;
74
+
75
+ void AddShutdownCallback(void (*callback)(void*), void* data);
76
+ void Shutdown();
77
+
78
+ // Returns true if work was dispatched or executed. New tasks that are
79
+ // posted during flushing of the queue are postponed until the next
80
+ // flushing.
81
+ bool FlushForegroundTasksInternal();
82
+
83
+ const uv_loop_t* event_loop() const { return loop_; }
84
+
85
+ private:
86
+ void DeleteFromScheduledTasks(DelayedTask* task);
87
+ void DecreaseHandleCount();
88
+
89
+ static void FlushTasks(uv_async_t* handle);
90
+ void RunForegroundTask(std::unique_ptr<v8::Task> task);
91
+ static void RunForegroundTask(uv_timer_t* timer);
92
+
93
+ struct ShutdownCallback {
94
+ void (*cb)(void*);
95
+ void* data;
96
+ };
97
+ typedef std::vector<ShutdownCallback> ShutdownCbList;
98
+ ShutdownCbList shutdown_callbacks_;
99
+ // shared_ptr to self to keep this object alive during shutdown.
100
+ std::shared_ptr<PerIsolatePlatformData> self_reference_;
101
+ uint32_t uv_handle_count_ = 1; // 1 = flush_tasks_
102
+
103
+ v8::Isolate* const isolate_;
104
+ uv_loop_t* const loop_;
105
+ uv_async_t* flush_tasks_ = nullptr;
106
+ TaskQueue<v8::Task> foreground_tasks_;
107
+ TaskQueue<DelayedTask> foreground_delayed_tasks_;
108
+
109
+ // Use a custom deleter because libuv needs to close the handle first.
110
+ typedef std::unique_ptr<DelayedTask, void(*)(DelayedTask*)>
111
+ DelayedTaskPointer;
112
+ std::vector<DelayedTaskPointer> scheduled_delayed_tasks_;
113
+ };
114
+
115
+ // This acts as the single worker thread task runner for all Isolates.
116
+ class WorkerThreadsTaskRunner {
117
+ public:
118
+ explicit WorkerThreadsTaskRunner(int thread_pool_size);
119
+
120
+ void PostTask(std::unique_ptr<v8::Task> task);
121
+ void PostDelayedTask(std::unique_ptr<v8::Task> task,
122
+ double delay_in_seconds);
123
+
124
+ void BlockingDrain();
125
+ void Shutdown();
126
+
127
+ int NumberOfWorkerThreads() const;
128
+
129
+ private:
130
+ TaskQueue<v8::Task> pending_worker_tasks_;
131
+
132
+ class DelayedTaskScheduler;
133
+ std::unique_ptr<DelayedTaskScheduler> delayed_task_scheduler_;
134
+
135
+ std::vector<std::unique_ptr<uv_thread_t>> threads_;
136
+ };
137
+
138
+ class NodePlatform : public MultiIsolatePlatform {
139
+ public:
140
+ NodePlatform(int thread_pool_size,
141
+ v8::TracingController* tracing_controller,
142
+ v8::PageAllocator* page_allocator = nullptr);
143
+ ~NodePlatform() override;
144
+
145
+ void DrainTasks(v8::Isolate* isolate) override;
146
+ void Shutdown();
147
+
148
+ // v8::Platform implementation.
149
+ int NumberOfWorkerThreads() override;
150
+ void CallOnWorkerThread(std::unique_ptr<v8::Task> task) override;
151
+ void CallDelayedOnWorkerThread(std::unique_ptr<v8::Task> task,
152
+ double delay_in_seconds) override;
153
+ bool IdleTasksEnabled(v8::Isolate* isolate) override;
154
+ double MonotonicallyIncreasingTime() override;
155
+ double CurrentClockTimeMillis() override;
156
+ v8::TracingController* GetTracingController() override;
157
+ bool FlushForegroundTasks(v8::Isolate* isolate) override;
158
+ std::unique_ptr<v8::JobHandle> CreateJob(
159
+ v8::TaskPriority priority,
160
+ std::unique_ptr<v8::JobTask> job_task) override;
161
+
162
+ void RegisterIsolate(v8::Isolate* isolate, uv_loop_t* loop) override;
163
+ void RegisterIsolate(v8::Isolate* isolate,
164
+ IsolatePlatformDelegate* delegate) override;
165
+
166
+ void UnregisterIsolate(v8::Isolate* isolate) override;
167
+ void AddIsolateFinishedCallback(v8::Isolate* isolate,
168
+ void (*callback)(void*), void* data) override;
169
+
170
+ std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
171
+ v8::Isolate* isolate) override;
172
+
173
+ Platform::StackTracePrinter GetStackTracePrinter() override;
174
+ v8::PageAllocator* GetPageAllocator() override;
175
+
176
+ private:
177
+ IsolatePlatformDelegate* ForIsolate(v8::Isolate* isolate);
178
+ std::shared_ptr<PerIsolatePlatformData> ForNodeIsolate(v8::Isolate* isolate);
179
+
180
+ Mutex per_isolate_mutex_;
181
+ using DelegatePair = std::pair<
182
+ IsolatePlatformDelegate*, std::shared_ptr<PerIsolatePlatformData>>;
183
+ std::unordered_map<v8::Isolate*, DelegatePair> per_isolate_;
184
+
185
+ v8::TracingController* tracing_controller_;
186
+ v8::PageAllocator* page_allocator_;
187
+ std::shared_ptr<WorkerThreadsTaskRunner> worker_thread_task_runner_;
188
+ bool has_shut_down_ = false;
189
+ };
190
+
191
+ } // namespace node
192
+
193
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
194
+
195
+ #endif // SRC_NODE_PLATFORM_H_
@@ -0,0 +1,26 @@
1
+ #ifndef SRC_NODE_PROCESS_INL_H_
2
+ #define SRC_NODE_PROCESS_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node_process.h"
7
+ #include "v8.h"
8
+ #include "debug_utils-inl.h"
9
+
10
+ namespace node {
11
+
12
+ // Call process.emitWarning(str), fmt is a snprintf() format string
13
+ template <typename... Args>
14
+ inline v8::Maybe<bool> ProcessEmitWarning(Environment* env,
15
+ const char* fmt,
16
+ Args&&... args) {
17
+ std::string warning = SPrintF(fmt, std::forward<Args>(args)...);
18
+
19
+ return ProcessEmitWarningGeneric(env, warning.c_str());
20
+ }
21
+
22
+ } // namespace node
23
+
24
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
25
+
26
+ #endif // SRC_NODE_PROCESS_INL_H_
@@ -0,0 +1,99 @@
1
+ #ifndef SRC_NODE_PROCESS_H_
2
+ #define SRC_NODE_PROCESS_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node_snapshotable.h"
7
+ #include "v8-fast-api-calls.h"
8
+ #include "v8.h"
9
+
10
+ namespace node {
11
+
12
+ class Environment;
13
+ class IsolateData;
14
+ class MemoryTracker;
15
+ class ExternalReferenceRegistry;
16
+ class Realm;
17
+
18
+ void CreateEnvProxyTemplate(v8::Isolate* isolate, IsolateData* isolate_data);
19
+
20
+ // Most of the time, it's best to use `console.error` to write
21
+ // to the process.stderr stream. However, in some cases, such as
22
+ // when debugging the stream.Writable class or the process.nextTick
23
+ // function, it is useful to bypass JavaScript entirely.
24
+ void RawDebug(const v8::FunctionCallbackInfo<v8::Value>& args);
25
+
26
+ v8::MaybeLocal<v8::Value> ProcessEmit(Environment* env,
27
+ const char* event,
28
+ v8::Local<v8::Value> message);
29
+
30
+ v8::Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
31
+ const char* warning,
32
+ const char* type = nullptr,
33
+ const char* code = nullptr);
34
+
35
+ template <typename... Args>
36
+ inline v8::Maybe<bool> ProcessEmitWarning(Environment* env,
37
+ const char* fmt,
38
+ Args&&... args);
39
+ v8::Maybe<bool> ProcessEmitExperimentalWarning(Environment* env,
40
+ const char* warning);
41
+ v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
42
+ const char* warning,
43
+ const char* deprecation_code);
44
+
45
+ v8::MaybeLocal<v8::Object> CreateProcessObject(Realm* env);
46
+ void PatchProcessObject(const v8::FunctionCallbackInfo<v8::Value>& args);
47
+
48
+ namespace process {
49
+ class BindingData : public SnapshotableObject {
50
+ public:
51
+ static void AddMethods(v8::Isolate* isolate,
52
+ v8::Local<v8::ObjectTemplate> target);
53
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
54
+
55
+ using InternalFieldInfo = InternalFieldInfoBase;
56
+
57
+ SERIALIZABLE_OBJECT_METHODS()
58
+ SET_BINDING_ID(process_binding_data)
59
+
60
+ BindingData(Realm* realm, v8::Local<v8::Object> object);
61
+
62
+ void MemoryInfo(MemoryTracker* tracker) const override;
63
+ SET_MEMORY_INFO_NAME(BindingData)
64
+ SET_SELF_SIZE(BindingData)
65
+
66
+ static BindingData* FromV8Value(v8::Local<v8::Value> receiver);
67
+ static void NumberImpl(BindingData* receiver);
68
+
69
+ static void FastNumber(v8::Local<v8::Value> receiver) {
70
+ NumberImpl(FromV8Value(receiver));
71
+ }
72
+
73
+ static void SlowNumber(const v8::FunctionCallbackInfo<v8::Value>& args);
74
+
75
+ static void BigIntImpl(BindingData* receiver);
76
+
77
+ static void FastBigInt(v8::Local<v8::Value> receiver) {
78
+ BigIntImpl(FromV8Value(receiver));
79
+ }
80
+
81
+ static void SlowBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
82
+
83
+ private:
84
+ static constexpr size_t kBufferSize =
85
+ std::max(sizeof(uint64_t), sizeof(uint32_t) * 3);
86
+ v8::Global<v8::ArrayBuffer> array_buffer_;
87
+ std::shared_ptr<v8::BackingStore> backing_store_;
88
+
89
+ // These need to be static so that we have their addresses available to
90
+ // register as external references in the snapshot at environment creation
91
+ // time.
92
+ static v8::CFunction fast_number_;
93
+ static v8::CFunction fast_bigint_;
94
+ };
95
+
96
+ } // namespace process
97
+ } // namespace node
98
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
99
+ #endif // SRC_NODE_PROCESS_H_
@@ -0,0 +1,139 @@
1
+ #ifndef SRC_NODE_REALM_INL_H_
2
+ #define SRC_NODE_REALM_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "cleanup_queue-inl.h"
7
+ #include "node_realm.h"
8
+
9
+ namespace node {
10
+
11
+ inline Realm* Realm::GetCurrent(v8::Isolate* isolate) {
12
+ if (UNLIKELY(!isolate->InContext())) return nullptr;
13
+ v8::HandleScope handle_scope(isolate);
14
+ return GetCurrent(isolate->GetCurrentContext());
15
+ }
16
+
17
+ inline Realm* Realm::GetCurrent(v8::Local<v8::Context> context) {
18
+ if (UNLIKELY(!ContextEmbedderTag::IsNodeContext(context))) return nullptr;
19
+ return static_cast<Realm*>(
20
+ context->GetAlignedPointerFromEmbedderData(ContextEmbedderIndex::kRealm));
21
+ }
22
+
23
+ inline Realm* Realm::GetCurrent(
24
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
25
+ return GetCurrent(info.GetIsolate()->GetCurrentContext());
26
+ }
27
+
28
+ template <typename T>
29
+ inline Realm* Realm::GetCurrent(const v8::PropertyCallbackInfo<T>& info) {
30
+ return GetCurrent(info.GetIsolate()->GetCurrentContext());
31
+ }
32
+
33
+ inline IsolateData* Realm::isolate_data() const {
34
+ return env_->isolate_data();
35
+ }
36
+
37
+ inline Environment* Realm::env() const {
38
+ return env_;
39
+ }
40
+
41
+ inline v8::Isolate* Realm::isolate() const {
42
+ return isolate_;
43
+ }
44
+
45
+ inline Realm::Kind Realm::kind() const {
46
+ return kind_;
47
+ }
48
+
49
+ inline bool Realm::has_run_bootstrapping_code() const {
50
+ return has_run_bootstrapping_code_;
51
+ }
52
+
53
+ // static
54
+ template <typename T, typename U>
55
+ inline T* Realm::GetBindingData(const v8::PropertyCallbackInfo<U>& info) {
56
+ return GetBindingData<T>(info.GetIsolate()->GetCurrentContext());
57
+ }
58
+
59
+ // static
60
+ template <typename T>
61
+ inline T* Realm::GetBindingData(
62
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
63
+ return GetBindingData<T>(info.GetIsolate()->GetCurrentContext());
64
+ }
65
+
66
+ // static
67
+ template <typename T>
68
+ inline T* Realm::GetBindingData(v8::Local<v8::Context> context) {
69
+ Realm* realm = GetCurrent(context);
70
+ return realm->GetBindingData<T>();
71
+ }
72
+
73
+ template <typename T>
74
+ inline T* Realm::GetBindingData() {
75
+ constexpr size_t binding_index = static_cast<size_t>(T::binding_type_int);
76
+ static_assert(binding_index < std::tuple_size_v<BindingDataStore>);
77
+ auto ptr = binding_data_store_[binding_index];
78
+ if (UNLIKELY(!ptr)) return nullptr;
79
+ T* result = static_cast<T*>(ptr.get());
80
+ DCHECK_NOT_NULL(result);
81
+ return result;
82
+ }
83
+
84
+ template <typename T, typename... Args>
85
+ inline T* Realm::AddBindingData(v8::Local<v8::Object> target, Args&&... args) {
86
+ // This won't compile if T is not a BaseObject subclass.
87
+ static_assert(std::is_base_of_v<BaseObject, T>);
88
+ // The binding data must be weak so that it won't keep the realm reachable
89
+ // from strong GC roots indefinitely. The wrapper object of binding data
90
+ // should be referenced from JavaScript, thus the binding data should be
91
+ // reachable throughout the lifetime of the realm.
92
+ BaseObjectWeakPtr<T> item =
93
+ MakeWeakBaseObject<T>(this, target, std::forward<Args>(args)...);
94
+ constexpr size_t binding_index = static_cast<size_t>(T::binding_type_int);
95
+ static_assert(binding_index < std::tuple_size_v<BindingDataStore>);
96
+ // Each slot is expected to be assigned only once.
97
+ CHECK(!binding_data_store_[binding_index]);
98
+ binding_data_store_[binding_index] = item;
99
+ return item.get();
100
+ }
101
+
102
+ inline BindingDataStore* Realm::binding_data_store() {
103
+ return &binding_data_store_;
104
+ }
105
+
106
+ template <typename T>
107
+ void Realm::ForEachBaseObject(T&& iterator) const {
108
+ cleanup_queue_.ForEachBaseObject(std::forward<T>(iterator));
109
+ }
110
+
111
+ void Realm::modify_base_object_count(int64_t delta) {
112
+ base_object_count_ += delta;
113
+ }
114
+
115
+ int64_t Realm::base_object_created_after_bootstrap() const {
116
+ return base_object_count_ - base_object_created_by_bootstrap_;
117
+ }
118
+
119
+ int64_t Realm::base_object_count() const {
120
+ return base_object_count_;
121
+ }
122
+
123
+ void Realm::AddCleanupHook(CleanupQueue::Callback fn, void* arg) {
124
+ cleanup_queue_.Add(fn, arg);
125
+ }
126
+
127
+ void Realm::RemoveCleanupHook(CleanupQueue::Callback fn, void* arg) {
128
+ cleanup_queue_.Remove(fn, arg);
129
+ }
130
+
131
+ bool Realm::HasCleanupHooks() const {
132
+ return !cleanup_queue_.empty();
133
+ }
134
+
135
+ } // namespace node
136
+
137
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
138
+
139
+ #endif // SRC_NODE_REALM_INL_H_