@encharm/cws 4.3.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/README.md +5 -7
  2. package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
  3. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  4. package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
  5. package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
  6. package/dist/bindings/cws_darwin_x64_node108.node +0 -0
  7. package/dist/bindings/cws_darwin_x64_node115.node +0 -0
  8. package/dist/bindings/cws_darwin_x64_node83.node +0 -0
  9. package/dist/bindings/cws_darwin_x64_node93.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node108.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node83.node +0 -0
  13. package/dist/bindings/cws_linux_arm64_node93.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node108.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node83.node +0 -0
  17. package/dist/bindings/cws_linux_x64_node93.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node108.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node83.node +0 -0
  21. package/dist/bindings/cws_win32_x64_node93.node +0 -0
  22. package/dist/shared.js +1 -1
  23. package/package.json +5 -5
  24. package/src/Addon.cpp +4 -12
  25. package/src/Addon.h +55 -90
  26. package/src/Socket.h +1 -0
  27. package/src/cSNode.cpp +3 -8
  28. package/src/headers/20/acorn_version.h +6 -0
  29. package/src/headers/20/aliased_buffer-inl.h +243 -0
  30. package/src/headers/20/aliased_buffer.h +206 -0
  31. package/src/headers/20/aliased_struct-inl.h +54 -0
  32. package/src/headers/20/aliased_struct.h +63 -0
  33. package/src/headers/20/async_wrap-inl.h +93 -0
  34. package/src/headers/20/async_wrap.h +252 -0
  35. package/src/headers/20/base64-inl.h +193 -0
  36. package/src/headers/20/base64.h +53 -0
  37. package/src/headers/20/base64_version.h +6 -0
  38. package/src/headers/20/base_object-inl.h +316 -0
  39. package/src/headers/20/base_object.h +320 -0
  40. package/src/headers/20/base_object_types.h +73 -0
  41. package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
  42. package/src/headers/20/blob_serializer_deserializer.h +132 -0
  43. package/src/headers/20/callback_queue-inl.h +97 -0
  44. package/src/headers/20/callback_queue.h +79 -0
  45. package/src/headers/20/cares_wrap.h +524 -0
  46. package/src/headers/20/cjs_module_lexer_version.h +6 -0
  47. package/src/headers/20/cleanup_queue-inl.h +62 -0
  48. package/src/headers/20/cleanup_queue.h +85 -0
  49. package/src/headers/20/connect_wrap.h +26 -0
  50. package/src/headers/20/connection_wrap.h +29 -0
  51. package/src/headers/20/cppgc/DEPS +8 -0
  52. package/src/headers/20/cppgc/OWNERS +2 -0
  53. package/src/headers/20/cppgc/README.md +135 -0
  54. package/src/headers/20/cppgc/allocation.h +310 -0
  55. package/src/headers/20/cppgc/common.h +28 -0
  56. package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
  57. package/src/headers/20/cppgc/custom-space.h +97 -0
  58. package/src/headers/20/cppgc/default-platform.h +67 -0
  59. package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
  60. package/src/headers/20/cppgc/explicit-management.h +100 -0
  61. package/src/headers/20/cppgc/garbage-collected.h +106 -0
  62. package/src/headers/20/cppgc/heap-consistency.h +309 -0
  63. package/src/headers/20/cppgc/heap-handle.h +48 -0
  64. package/src/headers/20/cppgc/heap-state.h +82 -0
  65. package/src/headers/20/cppgc/heap-statistics.h +120 -0
  66. package/src/headers/20/cppgc/heap.h +202 -0
  67. package/src/headers/20/cppgc/internal/api-constants.h +68 -0
  68. package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
  69. package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
  70. package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
  71. package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
  72. package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
  73. package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
  74. package/src/headers/20/cppgc/internal/gc-info.h +157 -0
  75. package/src/headers/20/cppgc/internal/logging.h +50 -0
  76. package/src/headers/20/cppgc/internal/member-storage.h +248 -0
  77. package/src/headers/20/cppgc/internal/name-trait.h +137 -0
  78. package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
  79. package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
  80. package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
  81. package/src/headers/20/cppgc/liveness-broker.h +78 -0
  82. package/src/headers/20/cppgc/macros.h +35 -0
  83. package/src/headers/20/cppgc/member.h +604 -0
  84. package/src/headers/20/cppgc/name-provider.h +65 -0
  85. package/src/headers/20/cppgc/object-size-trait.h +58 -0
  86. package/src/headers/20/cppgc/persistent.h +373 -0
  87. package/src/headers/20/cppgc/platform.h +158 -0
  88. package/src/headers/20/cppgc/prefinalizer.h +75 -0
  89. package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
  90. package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
  91. package/src/headers/20/cppgc/source-location.h +92 -0
  92. package/src/headers/20/cppgc/testing.h +106 -0
  93. package/src/headers/20/cppgc/trace-trait.h +120 -0
  94. package/src/headers/20/cppgc/type-traits.h +250 -0
  95. package/src/headers/20/cppgc/visitor.h +426 -0
  96. package/src/headers/20/crypto/crypto_clienthello.h +131 -0
  97. package/src/headers/20/crypto/crypto_context.h +160 -0
  98. package/src/headers/20/crypto/crypto_keys.h +416 -0
  99. package/src/headers/20/crypto/crypto_tls.h +295 -0
  100. package/src/headers/20/crypto/crypto_util.h +805 -0
  101. package/src/headers/20/crypto_clienthello.h +131 -0
  102. package/src/headers/20/debug_utils-inl.h +226 -0
  103. package/src/headers/20/debug_utils.h +188 -0
  104. package/src/headers/20/diagnosticfilename-inl.h +33 -0
  105. package/src/headers/20/encoding_binding.h +59 -0
  106. package/src/headers/20/env-inl.h +923 -0
  107. package/src/headers/20/env.h +1193 -0
  108. package/src/headers/20/env_properties.h +444 -0
  109. package/src/headers/20/handle_wrap.h +123 -0
  110. package/src/headers/20/histogram-inl.h +107 -0
  111. package/src/headers/20/histogram.h +240 -0
  112. package/src/headers/20/inspector_agent.h +144 -0
  113. package/src/headers/20/inspector_io.h +78 -0
  114. package/src/headers/20/inspector_profiler.h +149 -0
  115. package/src/headers/20/inspector_socket.h +60 -0
  116. package/src/headers/20/inspector_socket_server.h +110 -0
  117. package/src/headers/20/js_native_api.h +591 -0
  118. package/src/headers/20/js_native_api_types.h +168 -0
  119. package/src/headers/20/js_native_api_v8.h +426 -0
  120. package/src/headers/20/js_native_api_v8_internals.h +39 -0
  121. package/src/headers/20/js_stream.h +52 -0
  122. package/src/headers/20/json_parser.h +38 -0
  123. package/src/headers/20/json_utils.h +172 -0
  124. package/src/headers/20/memory_tracker-inl.h +356 -0
  125. package/src/headers/20/memory_tracker.h +289 -0
  126. package/src/headers/20/module_wrap.h +117 -0
  127. package/src/headers/20/node.h +1514 -0
  128. package/src/headers/20/node_api.h +260 -0
  129. package/src/headers/20/node_api_internals.h +42 -0
  130. package/src/headers/20/node_api_types.h +52 -0
  131. package/src/headers/20/node_binding.h +142 -0
  132. package/src/headers/20/node_blob.h +159 -0
  133. package/src/headers/20/node_bob-inl.h +36 -0
  134. package/src/headers/20/node_bob.h +107 -0
  135. package/src/headers/20/node_buffer.h +92 -0
  136. package/src/headers/20/node_builtins.h +197 -0
  137. package/src/headers/20/node_constants.h +79 -0
  138. package/src/headers/20/node_context_data.h +98 -0
  139. package/src/headers/20/node_contextify.h +182 -0
  140. package/src/headers/20/node_crypto.h +56 -0
  141. package/src/headers/20/node_dir.h +52 -0
  142. package/src/headers/20/node_dotenv.h +37 -0
  143. package/src/headers/20/node_errors.h +313 -0
  144. package/src/headers/20/node_exit_code.h +54 -0
  145. package/src/headers/20/node_external_reference.h +172 -0
  146. package/src/headers/20/node_file-inl.h +357 -0
  147. package/src/headers/20/node_file.h +524 -0
  148. package/src/headers/20/node_http2.h +1146 -0
  149. package/src/headers/20/node_http2_state.h +147 -0
  150. package/src/headers/20/node_http_common-inl.h +201 -0
  151. package/src/headers/20/node_http_common.h +532 -0
  152. package/src/headers/20/node_i18n.h +145 -0
  153. package/src/headers/20/node_internals.h +443 -0
  154. package/src/headers/20/node_main_instance.h +67 -0
  155. package/src/headers/20/node_mem-inl.h +112 -0
  156. package/src/headers/20/node_mem.h +45 -0
  157. package/src/headers/20/node_messaging.h +377 -0
  158. package/src/headers/20/node_metadata.h +138 -0
  159. package/src/headers/20/node_mutex.h +323 -0
  160. package/src/headers/20/node_object_wrap.h +132 -0
  161. package/src/headers/20/node_options-inl.h +478 -0
  162. package/src/headers/20/node_options.h +538 -0
  163. package/src/headers/20/node_perf.h +166 -0
  164. package/src/headers/20/node_perf_common.h +98 -0
  165. package/src/headers/20/node_platform.h +195 -0
  166. package/src/headers/20/node_process-inl.h +26 -0
  167. package/src/headers/20/node_process.h +99 -0
  168. package/src/headers/20/node_realm-inl.h +139 -0
  169. package/src/headers/20/node_realm.h +184 -0
  170. package/src/headers/20/node_report.h +42 -0
  171. package/src/headers/20/node_revert.h +82 -0
  172. package/src/headers/20/node_root_certs.h +3443 -0
  173. package/src/headers/20/node_sea.h +56 -0
  174. package/src/headers/20/node_shadow_realm.h +46 -0
  175. package/src/headers/20/node_snapshot_builder.h +54 -0
  176. package/src/headers/20/node_snapshotable.h +164 -0
  177. package/src/headers/20/node_sockaddr-inl.h +266 -0
  178. package/src/headers/20/node_sockaddr.h +405 -0
  179. package/src/headers/20/node_stat_watcher.h +73 -0
  180. package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
  181. package/src/headers/20/node_threadsafe_cow.h +105 -0
  182. package/src/headers/20/node_union_bytes.h +81 -0
  183. package/src/headers/20/node_url.h +92 -0
  184. package/src/headers/20/node_v8.h +77 -0
  185. package/src/headers/20/node_v8_platform-inl.h +205 -0
  186. package/src/headers/20/node_version.h +109 -0
  187. package/src/headers/20/node_wasi.h +184 -0
  188. package/src/headers/20/node_wasm_web_api.h +55 -0
  189. package/src/headers/20/node_watchdog.h +154 -0
  190. package/src/headers/20/node_worker.h +151 -0
  191. package/src/headers/20/permission/child_process_permission.h +28 -0
  192. package/src/headers/20/permission/fs_permission.h +152 -0
  193. package/src/headers/20/permission/permission.h +71 -0
  194. package/src/headers/20/permission/permission_base.h +49 -0
  195. package/src/headers/20/permission/worker_permission.h +28 -0
  196. package/src/headers/20/pipe_wrap.h +80 -0
  197. package/src/headers/20/req_wrap-inl.h +171 -0
  198. package/src/headers/20/req_wrap.h +77 -0
  199. package/src/headers/20/spawn_sync.h +242 -0
  200. package/src/headers/20/stream_base-inl.h +173 -0
  201. package/src/headers/20/stream_base.h +469 -0
  202. package/src/headers/20/stream_pipe.h +76 -0
  203. package/src/headers/20/stream_wrap.h +131 -0
  204. package/src/headers/20/string_bytes.h +120 -0
  205. package/src/headers/20/string_decoder-inl.h +37 -0
  206. package/src/headers/20/string_decoder.h +50 -0
  207. package/src/headers/20/string_search.h +638 -0
  208. package/src/headers/20/tcp_wrap.h +105 -0
  209. package/src/headers/20/threadpoolwork-inl.h +70 -0
  210. package/src/headers/20/timer_wrap-inl.h +32 -0
  211. package/src/headers/20/timer_wrap.h +85 -0
  212. package/src/headers/20/timers.h +70 -0
  213. package/src/headers/20/tracing/agent.h +195 -0
  214. package/src/headers/20/tracing/trace_event.h +720 -0
  215. package/src/headers/20/tracing/trace_event_common.h +1109 -0
  216. package/src/headers/20/tty_wrap.h +65 -0
  217. package/src/headers/20/udp_wrap.h +227 -0
  218. package/src/headers/20/undici_version.h +6 -0
  219. package/src/headers/20/util-inl.h +623 -0
  220. package/src/headers/20/util.h +988 -0
  221. package/src/headers/20/v8-cppgc.h +245 -0
  222. package/src/headers/20/v8-fast-api-calls.h +957 -0
  223. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  224. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  225. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  226. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  227. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  228. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  229. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  230. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  231. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  232. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  233. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  234. package/dist/bindings/cws_win32_x64_node79.node +0 -0
@@ -0,0 +1,54 @@
1
+ #ifndef SRC_NODE_EXIT_CODE_H_
2
+ #define SRC_NODE_EXIT_CODE_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ namespace node {
7
+ #define EXIT_CODE_LIST(V) \
8
+ V(NoFailure, 0) \
9
+ /* 1 was intended for uncaught JS exceptions from the user land but we */ \
10
+ /* actually use this for all kinds of generic errors. */ \
11
+ V(GenericUserError, 1) \
12
+ /* 2 is unused */ \
13
+ /* 3 is actually unused because we pre-compile all builtins during */ \
14
+ /* snapshot building, when we exit with 1 if there's any error. */ \
15
+ V(InternalJSParseError, 3) \
16
+ /* 4 is actually unused. We exit with 1 in this case. */ \
17
+ V(InternalJSEvaluationFailure, 4) \
18
+ /* 5 is actually unused. We exit with 133 (128+SIGTRAP) or 134 */ \
19
+ /* (128+SIGABRT) in this case. */ \
20
+ V(V8FatalError, 5) \
21
+ V(InvalidFatalExceptionMonkeyPatching, 6) \
22
+ V(ExceptionInFatalExceptionHandler, 7) \
23
+ /* 8 is unused */ \
24
+ V(InvalidCommandLineArgument, 9) \
25
+ V(BootstrapFailure, 10) \
26
+ /* 11 is unused */ \
27
+ /* This was intended for invalid inspector arguments but is actually now */ \
28
+ /* just a duplicate of InvalidCommandLineArgument */ \
29
+ V(InvalidCommandLineArgument2, 12) \
30
+ V(UnfinishedTopLevelAwait, 13) \
31
+ V(StartupSnapshotFailure, 14) \
32
+ /* If the process exits from unhandled signals e.g. SIGABRT, SIGTRAP, */ \
33
+ /* typically the exit codes are 128 + signal number. We also exit with */ \
34
+ /* certain error codes directly for legacy reasons. Here we define those */ \
35
+ /* that are used to normalize the exit code on Windows. */ \
36
+ V(Abort, 134)
37
+
38
+ // TODO(joyeecheung): expose this to user land when the codes are stable.
39
+ // The underlying type should be an int, or we can get undefined behavior when
40
+ // casting error codes into exit codes (technically we shouldn't do that,
41
+ // but that's how things have been).
42
+ enum class ExitCode : int {
43
+ #define V(Name, Code) k##Name = Code,
44
+ EXIT_CODE_LIST(V)
45
+ #undef V
46
+ };
47
+
48
+ [[noreturn]] void Exit(ExitCode exit_code);
49
+
50
+ } // namespace node
51
+
52
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
53
+
54
+ #endif // SRC_NODE_EXIT_CODE_H_
@@ -0,0 +1,172 @@
1
+ #ifndef SRC_NODE_EXTERNAL_REFERENCE_H_
2
+ #define SRC_NODE_EXTERNAL_REFERENCE_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <cinttypes>
7
+ #include <vector>
8
+ #include "v8-fast-api-calls.h"
9
+ #include "v8.h"
10
+
11
+ namespace node {
12
+
13
+ using CFunctionCallbackWithOneByteString =
14
+ uint32_t (*)(v8::Local<v8::Value>, const v8::FastOneByteString&);
15
+ using CFunctionCallback = void (*)(v8::Local<v8::Value> receiver);
16
+ using CFunctionCallbackReturnDouble =
17
+ double (*)(v8::Local<v8::Object> receiver);
18
+ using CFunctionCallbackWithInt64 = void (*)(v8::Local<v8::Object> receiver,
19
+ int64_t);
20
+ using CFunctionCallbackWithBool = void (*)(v8::Local<v8::Object> receiver,
21
+ bool);
22
+ using CFunctionCallbackWithString =
23
+ bool (*)(v8::Local<v8::Value>, const v8::FastOneByteString& input);
24
+ using CFunctionCallbackWithStrings =
25
+ bool (*)(v8::Local<v8::Value>,
26
+ const v8::FastOneByteString& input,
27
+ const v8::FastOneByteString& base);
28
+ using CFunctionWithUint32 = uint32_t (*)(v8::Local<v8::Value>,
29
+ const uint32_t input);
30
+
31
+ // This class manages the external references from the V8 heap
32
+ // to the C++ addresses in Node.js.
33
+ class ExternalReferenceRegistry {
34
+ public:
35
+ ExternalReferenceRegistry();
36
+
37
+ #define ALLOWED_EXTERNAL_REFERENCE_TYPES(V) \
38
+ V(CFunctionCallback) \
39
+ V(CFunctionCallbackWithOneByteString) \
40
+ V(CFunctionCallbackReturnDouble) \
41
+ V(CFunctionCallbackWithInt64) \
42
+ V(CFunctionCallbackWithBool) \
43
+ V(CFunctionCallbackWithString) \
44
+ V(CFunctionCallbackWithStrings) \
45
+ V(CFunctionWithUint32) \
46
+ V(const v8::CFunctionInfo*) \
47
+ V(v8::FunctionCallback) \
48
+ V(v8::AccessorGetterCallback) \
49
+ V(v8::AccessorSetterCallback) \
50
+ V(v8::AccessorNameGetterCallback) \
51
+ V(v8::AccessorNameSetterCallback) \
52
+ V(v8::GenericNamedPropertyDefinerCallback) \
53
+ V(v8::GenericNamedPropertyDeleterCallback) \
54
+ V(v8::GenericNamedPropertyEnumeratorCallback) \
55
+ V(v8::GenericNamedPropertyQueryCallback) \
56
+ V(v8::GenericNamedPropertySetterCallback) \
57
+ V(v8::IndexedPropertySetterCallback) \
58
+ V(v8::IndexedPropertyDefinerCallback) \
59
+ V(v8::IndexedPropertyDeleterCallback) \
60
+ V(v8::IndexedPropertyQueryCallback) \
61
+ V(v8::IndexedPropertyDescriptorCallback) \
62
+ V(const v8::String::ExternalStringResourceBase*)
63
+
64
+ #define V(ExternalReferenceType) \
65
+ void Register(ExternalReferenceType addr) { RegisterT(addr); }
66
+ ALLOWED_EXTERNAL_REFERENCE_TYPES(V)
67
+ #undef V
68
+
69
+ // This can be called only once.
70
+ const std::vector<intptr_t>& external_references();
71
+
72
+ bool is_empty() { return external_references_.empty(); }
73
+
74
+ private:
75
+ template <typename T>
76
+ void RegisterT(T* address) {
77
+ external_references_.push_back(reinterpret_cast<intptr_t>(address));
78
+ }
79
+ bool is_finalized_ = false;
80
+ std::vector<intptr_t> external_references_;
81
+ };
82
+
83
+ #define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \
84
+ V(async_wrap) \
85
+ V(binding) \
86
+ V(blob) \
87
+ V(buffer) \
88
+ V(builtins) \
89
+ V(cares_wrap) \
90
+ V(contextify) \
91
+ V(credentials) \
92
+ V(encoding_binding) \
93
+ V(env_var) \
94
+ V(errors) \
95
+ V(fs) \
96
+ V(fs_dir) \
97
+ V(fs_event_wrap) \
98
+ V(handle_wrap) \
99
+ V(heap_utils) \
100
+ V(messaging) \
101
+ V(mksnapshot) \
102
+ V(module_wrap) \
103
+ V(options) \
104
+ V(os) \
105
+ V(performance) \
106
+ V(permission) \
107
+ V(process_methods) \
108
+ V(process_object) \
109
+ V(report) \
110
+ V(task_queue) \
111
+ V(tcp_wrap) \
112
+ V(tty_wrap) \
113
+ V(url) \
114
+ V(util) \
115
+ V(pipe_wrap) \
116
+ V(sea) \
117
+ V(serdes) \
118
+ V(string_decoder) \
119
+ V(stream_wrap) \
120
+ V(signal_wrap) \
121
+ V(trace_events) \
122
+ V(timers) \
123
+ V(types) \
124
+ V(uv) \
125
+ V(v8) \
126
+ V(zlib) \
127
+ V(wasm_web_api) \
128
+ V(worker)
129
+
130
+ #if NODE_HAVE_I18N_SUPPORT
131
+ #define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) V(icu)
132
+ #else
133
+ #define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)
134
+ #endif // NODE_HAVE_I18N_SUPPORT
135
+
136
+ #if HAVE_INSPECTOR
137
+ #define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) \
138
+ V(inspector) \
139
+ V(profiler)
140
+ #else
141
+ #define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)
142
+ #endif // HAVE_INSPECTOR
143
+
144
+ #if HAVE_OPENSSL
145
+ #define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V) V(crypto) V(tls_wrap)
146
+ #else
147
+ #define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V)
148
+ #endif // HAVE_OPENSSL
149
+
150
+ #define EXTERNAL_REFERENCE_BINDING_LIST(V) \
151
+ EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \
152
+ EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) \
153
+ EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) \
154
+ EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V)
155
+
156
+ } // namespace node
157
+
158
+ // Declare all the external reference registration functions here,
159
+ // and define them later with #NODE_BINDING_EXTERNAL_REFERENCE(modname, func);
160
+ #define V(modname) \
161
+ void _register_external_reference_##modname( \
162
+ node::ExternalReferenceRegistry* registry);
163
+ EXTERNAL_REFERENCE_BINDING_LIST(V)
164
+ #undef V
165
+
166
+ #define NODE_BINDING_EXTERNAL_REFERENCE(modname, func) \
167
+ void _register_external_reference_##modname( \
168
+ node::ExternalReferenceRegistry* registry) { \
169
+ func(registry); \
170
+ }
171
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
172
+ #endif // SRC_NODE_EXTERNAL_REFERENCE_H_
@@ -0,0 +1,357 @@
1
+ #ifndef SRC_NODE_FILE_INL_H_
2
+ #define SRC_NODE_FILE_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node_file.h"
7
+ #include "req_wrap-inl.h"
8
+
9
+ namespace node {
10
+ namespace fs {
11
+
12
+ FSContinuationData::FSContinuationData(uv_fs_t* req, int mode, uv_fs_cb done_cb)
13
+ : done_cb_(done_cb), req_(req), mode_(mode) {
14
+ }
15
+
16
+ void FSContinuationData::PushPath(std::string&& path) {
17
+ paths_.emplace_back(std::move(path));
18
+ }
19
+
20
+ void FSContinuationData::PushPath(const std::string& path) {
21
+ paths_.push_back(path);
22
+ }
23
+
24
+ void FSContinuationData::MaybeSetFirstPath(const std::string& path) {
25
+ if (first_path_.empty()) {
26
+ first_path_ = path;
27
+ }
28
+ }
29
+
30
+ std::string FSContinuationData::PopPath() {
31
+ CHECK(!paths_.empty());
32
+ std::string path = std::move(paths_.back());
33
+ paths_.pop_back();
34
+ return path;
35
+ }
36
+
37
+ void FSContinuationData::Done(int result) {
38
+ req_->result = result;
39
+ done_cb_(req_);
40
+ }
41
+
42
+ FSReqBase::FSReqBase(BindingData* binding_data,
43
+ v8::Local<v8::Object> req,
44
+ AsyncWrap::ProviderType type,
45
+ bool use_bigint)
46
+ : ReqWrap(binding_data->env(), req, type),
47
+ use_bigint_(use_bigint),
48
+ binding_data_(binding_data) {
49
+ }
50
+
51
+ void FSReqBase::Init(const char* syscall,
52
+ const char* data,
53
+ size_t len,
54
+ enum encoding encoding) {
55
+ syscall_ = syscall;
56
+ encoding_ = encoding;
57
+
58
+ if (data != nullptr) {
59
+ CHECK(!has_data_);
60
+ buffer_.AllocateSufficientStorage(len + 1);
61
+ buffer_.SetLengthAndZeroTerminate(len);
62
+ memcpy(*buffer_, data, len);
63
+ has_data_ = true;
64
+ }
65
+ }
66
+
67
+ FSReqBase::FSReqBuffer&
68
+ FSReqBase::Init(const char* syscall, size_t len, enum encoding encoding) {
69
+ syscall_ = syscall;
70
+ encoding_ = encoding;
71
+
72
+ buffer_.AllocateSufficientStorage(len + 1);
73
+ has_data_ = false; // so that the data does not show up in error messages
74
+ return buffer_;
75
+ }
76
+
77
+ FSReqCallback::FSReqCallback(BindingData* binding_data,
78
+ v8::Local<v8::Object> req,
79
+ bool use_bigint)
80
+ : FSReqBase(binding_data,
81
+ req,
82
+ AsyncWrap::PROVIDER_FSREQCALLBACK,
83
+ use_bigint) {}
84
+
85
+ template <typename NativeT, typename V8T>
86
+ void FillStatsArray(AliasedBufferBase<NativeT, V8T>* fields,
87
+ const uv_stat_t* s,
88
+ const size_t offset) {
89
+ #define SET_FIELD_WITH_STAT(stat_offset, stat) \
90
+ fields->SetValue(offset + static_cast<size_t>(FsStatsOffset::stat_offset), \
91
+ static_cast<NativeT>(stat))
92
+
93
+ // On win32, time is stored in uint64_t and starts from 1601-01-01.
94
+ // libuv calculates tv_sec and tv_nsec from it and converts to signed long,
95
+ // which causes Y2038 overflow. On the other platforms it is safe to treat
96
+ // negative values as pre-epoch time.
97
+ #ifdef _WIN32
98
+ #define SET_FIELD_WITH_TIME_STAT(stat_offset, stat) \
99
+ /* NOLINTNEXTLINE(runtime/int) */ \
100
+ SET_FIELD_WITH_STAT(stat_offset, static_cast<unsigned long>(stat))
101
+ #else
102
+ #define SET_FIELD_WITH_TIME_STAT(stat_offset, stat) \
103
+ SET_FIELD_WITH_STAT(stat_offset, static_cast<double>(stat))
104
+ #endif // _WIN32
105
+
106
+ SET_FIELD_WITH_STAT(kDev, s->st_dev);
107
+ SET_FIELD_WITH_STAT(kMode, s->st_mode);
108
+ SET_FIELD_WITH_STAT(kNlink, s->st_nlink);
109
+ SET_FIELD_WITH_STAT(kUid, s->st_uid);
110
+ SET_FIELD_WITH_STAT(kGid, s->st_gid);
111
+ SET_FIELD_WITH_STAT(kRdev, s->st_rdev);
112
+ SET_FIELD_WITH_STAT(kBlkSize, s->st_blksize);
113
+ SET_FIELD_WITH_STAT(kIno, s->st_ino);
114
+ SET_FIELD_WITH_STAT(kSize, s->st_size);
115
+ SET_FIELD_WITH_STAT(kBlocks, s->st_blocks);
116
+
117
+ SET_FIELD_WITH_TIME_STAT(kATimeSec, s->st_atim.tv_sec);
118
+ SET_FIELD_WITH_TIME_STAT(kATimeNsec, s->st_atim.tv_nsec);
119
+ SET_FIELD_WITH_TIME_STAT(kMTimeSec, s->st_mtim.tv_sec);
120
+ SET_FIELD_WITH_TIME_STAT(kMTimeNsec, s->st_mtim.tv_nsec);
121
+ SET_FIELD_WITH_TIME_STAT(kCTimeSec, s->st_ctim.tv_sec);
122
+ SET_FIELD_WITH_TIME_STAT(kCTimeNsec, s->st_ctim.tv_nsec);
123
+ SET_FIELD_WITH_TIME_STAT(kBirthTimeSec, s->st_birthtim.tv_sec);
124
+ SET_FIELD_WITH_TIME_STAT(kBirthTimeNsec, s->st_birthtim.tv_nsec);
125
+
126
+ #undef SET_FIELD_WITH_TIME_STAT
127
+ #undef SET_FIELD_WITH_STAT
128
+ }
129
+
130
+ v8::Local<v8::Value> FillGlobalStatsArray(BindingData* binding_data,
131
+ const bool use_bigint,
132
+ const uv_stat_t* s,
133
+ const bool second) {
134
+ const ptrdiff_t offset =
135
+ second ? static_cast<ptrdiff_t>(FsStatsOffset::kFsStatsFieldsNumber) : 0;
136
+ if (use_bigint) {
137
+ auto* const arr = &binding_data->stats_field_bigint_array;
138
+ FillStatsArray(arr, s, offset);
139
+ return arr->GetJSArray();
140
+ } else {
141
+ auto* const arr = &binding_data->stats_field_array;
142
+ FillStatsArray(arr, s, offset);
143
+ return arr->GetJSArray();
144
+ }
145
+ }
146
+
147
+ template <typename NativeT, typename V8T>
148
+ void FillStatFsArray(AliasedBufferBase<NativeT, V8T>* fields,
149
+ const uv_statfs_t* s) {
150
+ #define SET_FIELD(field, stat) \
151
+ fields->SetValue(static_cast<size_t>(FsStatFsOffset::field), \
152
+ static_cast<NativeT>(stat))
153
+
154
+ SET_FIELD(kType, s->f_type);
155
+ SET_FIELD(kBSize, s->f_bsize);
156
+ SET_FIELD(kBlocks, s->f_blocks);
157
+ SET_FIELD(kBFree, s->f_bfree);
158
+ SET_FIELD(kBAvail, s->f_bavail);
159
+ SET_FIELD(kFiles, s->f_files);
160
+ SET_FIELD(kFFree, s->f_ffree);
161
+
162
+ #undef SET_FIELD
163
+ }
164
+
165
+ v8::Local<v8::Value> FillGlobalStatFsArray(BindingData* binding_data,
166
+ const bool use_bigint,
167
+ const uv_statfs_t* s) {
168
+ if (use_bigint) {
169
+ auto* const arr = &binding_data->statfs_field_bigint_array;
170
+ FillStatFsArray(arr, s);
171
+ return arr->GetJSArray();
172
+ } else {
173
+ auto* const arr = &binding_data->statfs_field_array;
174
+ FillStatFsArray(arr, s);
175
+ return arr->GetJSArray();
176
+ }
177
+ }
178
+
179
+ template <typename AliasedBufferT>
180
+ FSReqPromise<AliasedBufferT>*
181
+ FSReqPromise<AliasedBufferT>::New(BindingData* binding_data,
182
+ bool use_bigint) {
183
+ Environment* env = binding_data->env();
184
+ v8::Local<v8::Object> obj;
185
+ if (!env->fsreqpromise_constructor_template()
186
+ ->NewInstance(env->context())
187
+ .ToLocal(&obj)) {
188
+ return nullptr;
189
+ }
190
+ v8::Local<v8::Promise::Resolver> resolver;
191
+ if (!v8::Promise::Resolver::New(env->context()).ToLocal(&resolver) ||
192
+ obj->Set(env->context(), env->promise_string(), resolver).IsNothing()) {
193
+ return nullptr;
194
+ }
195
+ return new FSReqPromise(binding_data, obj, use_bigint);
196
+ }
197
+
198
+ template <typename AliasedBufferT>
199
+ FSReqPromise<AliasedBufferT>::~FSReqPromise() {
200
+ // Validate that the promise was explicitly resolved or rejected but only if
201
+ // the Isolate is not terminating because in this case the promise might have
202
+ // not finished.
203
+ CHECK_IMPLIES(!finished_, !env()->can_call_into_js());
204
+ }
205
+
206
+ template <typename AliasedBufferT>
207
+ FSReqPromise<AliasedBufferT>::FSReqPromise(BindingData* binding_data,
208
+ v8::Local<v8::Object> obj,
209
+ bool use_bigint)
210
+ : FSReqBase(
211
+ binding_data, obj, AsyncWrap::PROVIDER_FSREQPROMISE, use_bigint),
212
+ stats_field_array_(
213
+ env()->isolate(),
214
+ static_cast<size_t>(FsStatsOffset::kFsStatsFieldsNumber)),
215
+ statfs_field_array_(
216
+ env()->isolate(),
217
+ static_cast<size_t>(FsStatFsOffset::kFsStatFsFieldsNumber)) {}
218
+
219
+ template <typename AliasedBufferT>
220
+ void FSReqPromise<AliasedBufferT>::Reject(v8::Local<v8::Value> reject) {
221
+ finished_ = true;
222
+ v8::HandleScope scope(env()->isolate());
223
+ InternalCallbackScope callback_scope(this);
224
+ v8::Local<v8::Value> value =
225
+ object()->Get(env()->context(),
226
+ env()->promise_string()).ToLocalChecked();
227
+ v8::Local<v8::Promise::Resolver> resolver = value.As<v8::Promise::Resolver>();
228
+ USE(resolver->Reject(env()->context(), reject).FromJust());
229
+ }
230
+
231
+ template <typename AliasedBufferT>
232
+ void FSReqPromise<AliasedBufferT>::Resolve(v8::Local<v8::Value> value) {
233
+ finished_ = true;
234
+ v8::HandleScope scope(env()->isolate());
235
+ InternalCallbackScope callback_scope(this);
236
+ v8::Local<v8::Value> val =
237
+ object()->Get(env()->context(),
238
+ env()->promise_string()).ToLocalChecked();
239
+ v8::Local<v8::Promise::Resolver> resolver = val.As<v8::Promise::Resolver>();
240
+ USE(resolver->Resolve(env()->context(), value).FromJust());
241
+ }
242
+
243
+ template <typename AliasedBufferT>
244
+ void FSReqPromise<AliasedBufferT>::ResolveStat(const uv_stat_t* stat) {
245
+ FillStatsArray(&stats_field_array_, stat);
246
+ Resolve(stats_field_array_.GetJSArray());
247
+ }
248
+
249
+ template <typename AliasedBufferT>
250
+ void FSReqPromise<AliasedBufferT>::ResolveStatFs(const uv_statfs_t* stat) {
251
+ FillStatFsArray(&statfs_field_array_, stat);
252
+ Resolve(statfs_field_array_.GetJSArray());
253
+ }
254
+
255
+ template <typename AliasedBufferT>
256
+ void FSReqPromise<AliasedBufferT>::SetReturnValue(
257
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
258
+ v8::Local<v8::Value> val =
259
+ object()->Get(env()->context(),
260
+ env()->promise_string()).ToLocalChecked();
261
+ v8::Local<v8::Promise::Resolver> resolver = val.As<v8::Promise::Resolver>();
262
+ args.GetReturnValue().Set(resolver->GetPromise());
263
+ }
264
+
265
+ template <typename AliasedBufferT>
266
+ void FSReqPromise<AliasedBufferT>::MemoryInfo(MemoryTracker* tracker) const {
267
+ FSReqBase::MemoryInfo(tracker);
268
+ tracker->TrackField("stats_field_array", stats_field_array_);
269
+ tracker->TrackField("statfs_field_array", statfs_field_array_);
270
+ }
271
+
272
+ FSReqBase* GetReqWrap(const v8::FunctionCallbackInfo<v8::Value>& args,
273
+ int index,
274
+ bool use_bigint) {
275
+ v8::Local<v8::Value> value = args[index];
276
+ if (value->IsObject()) {
277
+ return Unwrap<FSReqBase>(value.As<v8::Object>());
278
+ }
279
+
280
+ Realm* realm = Realm::GetCurrent(args);
281
+ BindingData* binding_data = realm->GetBindingData<BindingData>();
282
+
283
+ if (value->StrictEquals(realm->isolate_data()->fs_use_promises_symbol())) {
284
+ if (use_bigint) {
285
+ return FSReqPromise<AliasedBigInt64Array>::New(binding_data, use_bigint);
286
+ } else {
287
+ return FSReqPromise<AliasedFloat64Array>::New(binding_data, use_bigint);
288
+ }
289
+ }
290
+ return nullptr;
291
+ }
292
+
293
+ // Returns nullptr if the operation fails from the start.
294
+ template <typename Func, typename... Args>
295
+ FSReqBase* AsyncDestCall(Environment* env, FSReqBase* req_wrap,
296
+ const v8::FunctionCallbackInfo<v8::Value>& args,
297
+ const char* syscall, const char* dest,
298
+ size_t len, enum encoding enc, uv_fs_cb after,
299
+ Func fn, Args... fn_args) {
300
+ CHECK_NOT_NULL(req_wrap);
301
+ req_wrap->Init(syscall, dest, len, enc);
302
+ int err = req_wrap->Dispatch(fn, fn_args..., after);
303
+ if (err < 0) {
304
+ uv_fs_t* uv_req = req_wrap->req();
305
+ uv_req->result = err;
306
+ uv_req->path = nullptr;
307
+ after(uv_req); // after may delete req_wrap if there is an error
308
+ req_wrap = nullptr;
309
+ } else {
310
+ req_wrap->SetReturnValue(args);
311
+ }
312
+
313
+ return req_wrap;
314
+ }
315
+
316
+ // Returns nullptr if the operation fails from the start.
317
+ template <typename Func, typename... Args>
318
+ FSReqBase* AsyncCall(Environment* env,
319
+ FSReqBase* req_wrap,
320
+ const v8::FunctionCallbackInfo<v8::Value>& args,
321
+ const char* syscall, enum encoding enc,
322
+ uv_fs_cb after, Func fn, Args... fn_args) {
323
+ return AsyncDestCall(env, req_wrap, args,
324
+ syscall, nullptr, 0, enc,
325
+ after, fn, fn_args...);
326
+ }
327
+
328
+ // Template counterpart of SYNC_CALL, except that it only puts
329
+ // the error number and the syscall in the context instead of
330
+ // creating an error in the C++ land.
331
+ // ctx must be checked using value->IsObject() before being passed.
332
+ template <typename Func, typename... Args>
333
+ int SyncCall(Environment* env, v8::Local<v8::Value> ctx,
334
+ FSReqWrapSync* req_wrap, const char* syscall,
335
+ Func fn, Args... args) {
336
+ env->PrintSyncTrace();
337
+ int err = fn(env->event_loop(), &(req_wrap->req), args..., nullptr);
338
+ if (err < 0) {
339
+ v8::Local<v8::Context> context = env->context();
340
+ v8::Local<v8::Object> ctx_obj = ctx.As<v8::Object>();
341
+ v8::Isolate* isolate = env->isolate();
342
+ ctx_obj->Set(context,
343
+ env->errno_string(),
344
+ v8::Integer::New(isolate, err)).Check();
345
+ ctx_obj->Set(context,
346
+ env->syscall_string(),
347
+ OneByteString(isolate, syscall)).Check();
348
+ }
349
+ return err;
350
+ }
351
+
352
+ } // namespace fs
353
+ } // namespace node
354
+
355
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
356
+
357
+ #endif // SRC_NODE_FILE_INL_H_