@encharm/cws 4.0.2 → 4.3.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 (410) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/LICENSE +3 -2
  3. package/README.md +9 -2
  4. package/binding.gyp +2 -2
  5. package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  7. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  8. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  9. package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
  10. package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
  11. package/dist/bindings/cws_darwin_x64_node108.node +0 -0
  12. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  13. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  14. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  15. package/dist/bindings/cws_darwin_x64_node83.node +0 -0
  16. package/dist/bindings/cws_darwin_x64_node93.node +0 -0
  17. package/dist/bindings/cws_linux_x64_node108.node +0 -0
  18. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  19. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  20. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  21. package/dist/bindings/cws_linux_x64_node83.node +0 -0
  22. package/dist/bindings/cws_linux_x64_node93.node +0 -0
  23. package/dist/bindings/cws_win32_x64_node108.node +0 -0
  24. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  25. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  26. package/dist/bindings/cws_win32_x64_node79.node +0 -0
  27. package/dist/bindings/cws_win32_x64_node83.node +0 -0
  28. package/dist/bindings/cws_win32_x64_node93.node +0 -0
  29. package/dist/client.d.ts +1 -0
  30. package/dist/client.js +4 -0
  31. package/dist/index.js +3 -2
  32. package/dist/server.js +1 -0
  33. package/dist/shared.js +2 -1
  34. package/package.json +1 -1
  35. package/src/Addon.cpp +1 -0
  36. package/src/Addon.h +35 -2
  37. package/src/HTTPSocket.cpp +1 -1
  38. package/src/LICENSE +4 -0
  39. package/src/Socket.h +12 -3
  40. package/src/headers/{13 → 18}/aliased_buffer.h +61 -9
  41. package/src/headers/18/aliased_struct-inl.h +54 -0
  42. package/src/headers/18/aliased_struct.h +63 -0
  43. package/src/headers/{12 → 18}/async_wrap-inl.h +0 -0
  44. package/src/headers/{12 → 18}/async_wrap.h +26 -2
  45. package/src/headers/{12/base64.h → 18/base64-inl.h} +78 -86
  46. package/src/headers/18/base64.h +69 -0
  47. package/src/headers/{12 → 18}/base_object-inl.h +46 -25
  48. package/src/headers/{12 → 18}/base_object.h +82 -17
  49. package/src/headers/{12 → 18}/callback_queue-inl.h +9 -9
  50. package/src/headers/{12 → 18}/callback_queue.h +13 -5
  51. package/src/headers/18/cares_wrap.h +523 -0
  52. package/src/headers/{12 → 18}/connect_wrap.h +0 -0
  53. package/src/headers/{12 → 18}/connection_wrap.h +0 -0
  54. package/src/headers/18/crypto/crypto_aes.h +89 -0
  55. package/src/headers/{13/node_crypto_bio.h → 18/crypto/crypto_bio.h} +3 -4
  56. package/src/headers/18/crypto/crypto_cipher.h +291 -0
  57. package/src/headers/{13/node_crypto_clienthello-inl.h → 18/crypto/crypto_clienthello-inl.h} +4 -5
  58. package/src/headers/{13/node_crypto_clienthello.h → 18/crypto/crypto_clienthello.h} +3 -4
  59. package/src/headers/{12/node_crypto_common.h → 18/crypto/crypto_common.h} +49 -36
  60. package/src/headers/18/crypto/crypto_context.h +147 -0
  61. package/src/headers/18/crypto/crypto_dh.h +156 -0
  62. package/src/headers/18/crypto/crypto_dsa.h +77 -0
  63. package/src/headers/18/crypto/crypto_ec.h +170 -0
  64. package/src/headers/{12/node_crypto_groups.h → 18/crypto/crypto_groups.h} +3 -3
  65. package/src/headers/18/crypto/crypto_hash.h +89 -0
  66. package/src/headers/18/crypto/crypto_hkdf.h +65 -0
  67. package/src/headers/18/crypto/crypto_hmac.h +94 -0
  68. package/src/headers/18/crypto/crypto_keygen.h +305 -0
  69. package/src/headers/18/crypto/crypto_keys.h +420 -0
  70. package/src/headers/18/crypto/crypto_pbkdf2.h +76 -0
  71. package/src/headers/18/crypto/crypto_random.h +130 -0
  72. package/src/headers/18/crypto/crypto_rsa.h +141 -0
  73. package/src/headers/18/crypto/crypto_scrypt.h +87 -0
  74. package/src/headers/18/crypto/crypto_sig.h +168 -0
  75. package/src/headers/18/crypto/crypto_spkac.h +21 -0
  76. package/src/headers/18/crypto/crypto_timing.h +20 -0
  77. package/src/headers/{12/tls_wrap.h → 18/crypto/crypto_tls.h} +137 -66
  78. package/src/headers/18/crypto/crypto_util.h +791 -0
  79. package/src/headers/18/crypto/crypto_x509.h +143 -0
  80. package/src/headers/{12 → 18}/debug_utils-inl.h +0 -0
  81. package/src/headers/{13 → 18}/debug_utils.h +7 -4
  82. package/src/headers/{12 → 18}/diagnosticfilename-inl.h +0 -0
  83. package/src/headers/{12 → 18}/env-inl.h +397 -304
  84. package/src/headers/{12 → 18}/env.h +397 -172
  85. package/src/headers/{12 → 18}/handle_wrap.h +7 -3
  86. package/src/headers/18/histogram-inl.h +107 -0
  87. package/src/headers/18/histogram.h +239 -0
  88. package/src/headers/{13 → 18}/inspector_agent.h +4 -7
  89. package/src/headers/{12 → 18}/inspector_io.h +0 -0
  90. package/src/headers/{13 → 18}/inspector_profiler.h +17 -5
  91. package/src/headers/{12 → 18}/inspector_socket.h +0 -0
  92. package/src/headers/{12 → 18}/inspector_socket_server.h +0 -0
  93. package/src/headers/18/js_native_api.h +571 -0
  94. package/src/headers/{13 → 18}/js_native_api_types.h +30 -7
  95. package/src/headers/{12 → 18}/js_native_api_v8.h +220 -83
  96. package/src/headers/{12 → 18}/js_native_api_v8_internals.h +6 -5
  97. package/src/headers/{12 → 18}/js_stream.h +0 -0
  98. package/src/headers/{12 → 18}/json_utils.h +0 -0
  99. package/src/headers/{13 → 18}/memory_tracker-inl.h +6 -5
  100. package/src/headers/{13 → 18}/memory_tracker.h +0 -7
  101. package/src/headers/{13 → 18}/module_wrap.h +24 -7
  102. package/src/headers/{13 → 18}/node.h +329 -68
  103. package/src/headers/18/node_api.h +288 -0
  104. package/src/headers/18/node_api_internals.h +38 -0
  105. package/src/headers/{12 → 18}/node_api_types.h +12 -9
  106. package/src/headers/{12 → 18}/node_binding.h +0 -0
  107. package/src/headers/18/node_blob.h +191 -0
  108. package/src/headers/18/node_bob-inl.h +37 -0
  109. package/src/headers/18/node_bob.h +111 -0
  110. package/src/headers/{13 → 18}/node_buffer.h +0 -0
  111. package/src/headers/{13 → 18}/node_constants.h +5 -1
  112. package/src/headers/{12 → 18}/node_context_data.h +5 -0
  113. package/src/headers/{12 → 18}/node_contextify.h +37 -2
  114. package/src/headers/{10/node_javascript.h → 18/node_crypto.h} +30 -14
  115. package/src/headers/{12 → 18}/node_dir.h +0 -0
  116. package/src/headers/{12 → 18}/node_dtrace.h +0 -0
  117. package/src/headers/{12 → 18}/node_errors.h +90 -24
  118. package/src/headers/18/node_external_reference.h +145 -0
  119. package/src/headers/{13 → 18}/node_file-inl.h +38 -21
  120. package/src/headers/{12 → 18}/node_file.h +74 -13
  121. package/src/headers/{13 → 18}/node_http2.h +365 -269
  122. package/src/headers/{12 → 18}/node_http2_state.h +40 -50
  123. package/src/headers/{13 → 18}/node_http_common-inl.h +25 -5
  124. package/src/headers/{13 → 18}/node_http_common.h +24 -20
  125. package/src/headers/{13 → 18}/node_i18n.h +2 -1
  126. package/src/headers/{12 → 18}/node_internals.h +39 -41
  127. package/src/headers/{12 → 18}/node_main_instance.h +15 -18
  128. package/src/headers/{12 → 18}/node_mem-inl.h +0 -0
  129. package/src/headers/{12 → 18}/node_mem.h +1 -1
  130. package/src/headers/{13 → 18}/node_messaging.h +170 -23
  131. package/src/headers/{12 → 18}/node_metadata.h +17 -4
  132. package/src/headers/{12 → 18}/node_mutex.h +77 -1
  133. package/src/headers/{12 → 18}/node_native_module.h +11 -1
  134. package/src/headers/{12 → 18}/node_native_module_env.h +14 -8
  135. package/src/headers/{12 → 18}/node_object_wrap.h +0 -0
  136. package/src/headers/{13 → 18}/node_options-inl.h +51 -21
  137. package/src/headers/{13 → 18}/node_options.h +46 -14
  138. package/src/headers/18/node_perf.h +168 -0
  139. package/src/headers/{12 → 18}/node_perf_common.h +16 -22
  140. package/src/headers/{12 → 18}/node_platform.h +21 -16
  141. package/src/headers/18/node_process-inl.h +26 -0
  142. package/src/headers/18/node_process.h +97 -0
  143. package/src/headers/{13 → 18}/node_report.h +2 -2
  144. package/src/headers/{13 → 18}/node_revert.h +10 -0
  145. package/src/headers/{12 → 18}/node_root_certs.h +439 -651
  146. package/src/headers/18/node_snapshot_builder.h +43 -0
  147. package/src/headers/18/node_snapshotable.h +130 -0
  148. package/src/headers/{12 → 18}/node_sockaddr-inl.h +100 -4
  149. package/src/headers/18/node_sockaddr.h +405 -0
  150. package/src/headers/{13 → 18}/node_stat_watcher.h +7 -1
  151. package/src/headers/{12 → 18}/node_union_bytes.h +0 -0
  152. package/src/headers/{13 → 18}/node_url.h +18 -1
  153. package/src/headers/18/node_v8.h +41 -0
  154. package/src/headers/{12 → 18}/node_v8_platform-inl.h +10 -0
  155. package/src/headers/{13 → 18}/node_version.h +7 -7
  156. package/src/headers/{12 → 18}/node_wasi.h +0 -0
  157. package/src/headers/18/node_wasm_web_api.h +55 -0
  158. package/src/headers/{13 → 18}/node_watchdog.h +0 -0
  159. package/src/headers/{10 → 18}/node_win32_etw_provider-inl.h +7 -6
  160. package/src/headers/{10 → 18}/node_win32_etw_provider.h +0 -0
  161. package/src/headers/{13 → 18}/node_worker.h +24 -17
  162. package/src/headers/{12 → 18}/pipe_wrap.h +2 -0
  163. package/src/headers/{12 → 18}/req_wrap-inl.h +0 -0
  164. package/src/headers/{13 → 18}/req_wrap.h +1 -1
  165. package/src/headers/{12 → 18}/spawn_sync.h +0 -0
  166. package/src/headers/{13 → 18}/stream_base-inl.h +58 -22
  167. package/src/headers/{13 → 18}/stream_base.h +29 -3
  168. package/src/headers/{13 → 18}/stream_pipe.h +8 -3
  169. package/src/headers/{12 → 18}/stream_wrap.h +4 -1
  170. package/src/headers/{13 → 18}/string_bytes.h +0 -7
  171. package/src/headers/{12 → 18}/string_decoder-inl.h +0 -0
  172. package/src/headers/{10 → 18}/string_decoder.h +0 -0
  173. package/src/headers/{13 → 18}/string_search.h +2 -2
  174. package/src/headers/{12 → 18}/tcp_wrap.h +4 -0
  175. package/src/headers/{12 → 18}/threadpoolwork-inl.h +0 -0
  176. package/src/headers/18/timer_wrap-inl.h +32 -0
  177. package/src/headers/18/timer_wrap.h +85 -0
  178. package/src/headers/{13 → 18}/tracing/agent.h +1 -1
  179. package/src/headers/{12 → 18}/tracing/node_trace_buffer.h +0 -0
  180. package/src/headers/{12 → 18}/tracing/node_trace_writer.h +0 -0
  181. package/src/headers/{13 → 18}/tracing/trace_event.h +23 -13
  182. package/src/headers/{12 → 18}/tracing/trace_event_common.h +0 -0
  183. package/src/headers/{12 → 18}/tracing/traced_value.h +0 -0
  184. package/src/headers/{13 → 18}/tty_wrap.h +2 -1
  185. package/src/headers/{13 → 18}/udp_wrap.h +5 -0
  186. package/src/headers/{13 → 18}/util-inl.h +69 -15
  187. package/src/headers/{13 → 18}/util.h +93 -31
  188. package/src/headers/18/v8-fast-api-calls.h +939 -0
  189. package/src/headers/{12 → 18}/v8abbr.h +2 -2
  190. package/dist/bindings/cws_darwin_64.node +0 -0
  191. package/dist/bindings/cws_darwin_72.node +0 -0
  192. package/dist/bindings/cws_darwin_79.node +0 -0
  193. package/dist/bindings/cws_darwin_83.node +0 -0
  194. package/dist/bindings/cws_darwin_93.node +0 -0
  195. package/dist/bindings/cws_linux_64.node +0 -0
  196. package/dist/bindings/cws_linux_72.node +0 -0
  197. package/dist/bindings/cws_linux_79.node +0 -0
  198. package/dist/bindings/cws_linux_83.node +0 -0
  199. package/dist/bindings/cws_linux_93.node +0 -0
  200. package/dist/bindings/cws_win32_64.node +0 -0
  201. package/dist/bindings/cws_win32_72.node +0 -0
  202. package/dist/bindings/cws_win32_79.node +0 -0
  203. package/dist/bindings/cws_win32_83.node +0 -0
  204. package/dist/bindings/cws_win32_93.node +0 -0
  205. package/src/headers/10/aliased_buffer.h +0 -241
  206. package/src/headers/10/async_wrap-inl.h +0 -106
  207. package/src/headers/10/async_wrap.h +0 -218
  208. package/src/headers/10/base64.h +0 -197
  209. package/src/headers/10/base_object-inl.h +0 -132
  210. package/src/headers/10/base_object.h +0 -115
  211. package/src/headers/10/connect_wrap.h +0 -28
  212. package/src/headers/10/connection_wrap.h +0 -30
  213. package/src/headers/10/debug_utils.h +0 -128
  214. package/src/headers/10/env-inl.h +0 -906
  215. package/src/headers/10/env.h +0 -1046
  216. package/src/headers/10/handle_wrap.h +0 -114
  217. package/src/headers/10/inspector_agent.h +0 -137
  218. package/src/headers/10/inspector_io.h +0 -97
  219. package/src/headers/10/inspector_socket.h +0 -59
  220. package/src/headers/10/inspector_socket_server.h +0 -104
  221. package/src/headers/10/js_stream.h +0 -57
  222. package/src/headers/10/memory_tracker-inl.h +0 -318
  223. package/src/headers/10/memory_tracker.h +0 -246
  224. package/src/headers/10/module_wrap.h +0 -100
  225. package/src/headers/10/node.h +0 -863
  226. package/src/headers/10/node_api.h +0 -752
  227. package/src/headers/10/node_api_types.h +0 -171
  228. package/src/headers/10/node_buffer.h +0 -90
  229. package/src/headers/10/node_code_cache.h +0 -17
  230. package/src/headers/10/node_constants.h +0 -74
  231. package/src/headers/10/node_context_data.h +0 -39
  232. package/src/headers/10/node_contextify.h +0 -141
  233. package/src/headers/10/node_counters.h +0 -59
  234. package/src/headers/10/node_crypto.h +0 -699
  235. package/src/headers/10/node_crypto_bio.h +0 -177
  236. package/src/headers/10/node_crypto_clienthello-inl.h +0 -92
  237. package/src/headers/10/node_crypto_clienthello.h +0 -131
  238. package/src/headers/10/node_crypto_groups.h +0 -416
  239. package/src/headers/10/node_dtrace.h +0 -84
  240. package/src/headers/10/node_errors.h +0 -118
  241. package/src/headers/10/node_file.h +0 -373
  242. package/src/headers/10/node_http2.h +0 -1304
  243. package/src/headers/10/node_http2_state.h +0 -158
  244. package/src/headers/10/node_i18n.h +0 -69
  245. package/src/headers/10/node_internals.h +0 -952
  246. package/src/headers/10/node_messaging.h +0 -219
  247. package/src/headers/10/node_mutex.h +0 -191
  248. package/src/headers/10/node_object_wrap.h +0 -130
  249. package/src/headers/10/node_options-inl.h +0 -444
  250. package/src/headers/10/node_options.h +0 -397
  251. package/src/headers/10/node_perf.h +0 -134
  252. package/src/headers/10/node_perf_common.h +0 -96
  253. package/src/headers/10/node_persistent.h +0 -30
  254. package/src/headers/10/node_platform.h +0 -170
  255. package/src/headers/10/node_revert.h +0 -75
  256. package/src/headers/10/node_root_certs.h +0 -3393
  257. package/src/headers/10/node_stat_watcher.h +0 -65
  258. package/src/headers/10/node_url.h +0 -193
  259. package/src/headers/10/node_version.h +0 -120
  260. package/src/headers/10/node_watchdog.h +0 -114
  261. package/src/headers/10/node_win32_perfctr_provider.h +0 -58
  262. package/src/headers/10/node_worker.h +0 -94
  263. package/src/headers/10/pipe_wrap.h +0 -76
  264. package/src/headers/10/req_wrap-inl.h +0 -166
  265. package/src/headers/10/req_wrap.h +0 -61
  266. package/src/headers/10/sharedarraybuffer_metadata.h +0 -67
  267. package/src/headers/10/spawn_sync.h +0 -240
  268. package/src/headers/10/stream_base-inl.h +0 -458
  269. package/src/headers/10/stream_base.h +0 -378
  270. package/src/headers/10/stream_pipe.h +0 -72
  271. package/src/headers/10/stream_wrap.h +0 -130
  272. package/src/headers/10/string_bytes.h +0 -126
  273. package/src/headers/10/string_decoder-inl.h +0 -38
  274. package/src/headers/10/string_search.h +0 -620
  275. package/src/headers/10/tcp_wrap.h +0 -99
  276. package/src/headers/10/tls_wrap.h +0 -195
  277. package/src/headers/10/tracing/agent.h +0 -178
  278. package/src/headers/10/tracing/node_trace_buffer.h +0 -83
  279. package/src/headers/10/tracing/node_trace_writer.h +0 -75
  280. package/src/headers/10/tracing/trace_event.h +0 -706
  281. package/src/headers/10/tracing/trace_event_common.h +0 -1102
  282. package/src/headers/10/tracing/traced_value.h +0 -68
  283. package/src/headers/10/tty_wrap.h +0 -63
  284. package/src/headers/10/udp_wrap.h +0 -102
  285. package/src/headers/10/util-inl.h +0 -459
  286. package/src/headers/10/util.h +0 -508
  287. package/src/headers/10/v8abbr.h +0 -121
  288. package/src/headers/12/aliased_buffer.h +0 -263
  289. package/src/headers/12/debug_utils.h +0 -181
  290. package/src/headers/12/histogram-inl.h +0 -83
  291. package/src/headers/12/histogram.h +0 -98
  292. package/src/headers/12/http_parser_adaptor.h +0 -24
  293. package/src/headers/12/inspector_agent.h +0 -147
  294. package/src/headers/12/inspector_profiler.h +0 -137
  295. package/src/headers/12/js_native_api.h +0 -541
  296. package/src/headers/12/js_native_api_types.h +0 -139
  297. package/src/headers/12/memory_tracker-inl.h +0 -339
  298. package/src/headers/12/memory_tracker.h +0 -283
  299. package/src/headers/12/module_wrap.h +0 -99
  300. package/src/headers/12/node.h +0 -887
  301. package/src/headers/12/node_api.h +0 -239
  302. package/src/headers/12/node_buffer.h +0 -92
  303. package/src/headers/12/node_constants.h +0 -80
  304. package/src/headers/12/node_crypto.h +0 -800
  305. package/src/headers/12/node_crypto_bio.h +0 -195
  306. package/src/headers/12/node_crypto_clienthello-inl.h +0 -91
  307. package/src/headers/12/node_crypto_clienthello.h +0 -132
  308. package/src/headers/12/node_file-inl.h +0 -289
  309. package/src/headers/12/node_http2.h +0 -1311
  310. package/src/headers/12/node_http_parser_impl.h +0 -994
  311. package/src/headers/12/node_i18n.h +0 -144
  312. package/src/headers/12/node_messaging.h +0 -227
  313. package/src/headers/12/node_options-inl.h +0 -447
  314. package/src/headers/12/node_options.h +0 -479
  315. package/src/headers/12/node_perf.h +0 -181
  316. package/src/headers/12/node_process.h +0 -41
  317. package/src/headers/12/node_report.h +0 -47
  318. package/src/headers/12/node_revert.h +0 -78
  319. package/src/headers/12/node_sockaddr.h +0 -123
  320. package/src/headers/12/node_stat_watcher.h +0 -66
  321. package/src/headers/12/node_url.h +0 -188
  322. package/src/headers/12/node_version.h +0 -98
  323. package/src/headers/12/node_watchdog.h +0 -152
  324. package/src/headers/12/node_win32_etw_provider-inl.h +0 -287
  325. package/src/headers/12/node_win32_etw_provider.h +0 -99
  326. package/src/headers/12/node_worker.h +0 -142
  327. package/src/headers/12/req_wrap.h +0 -77
  328. package/src/headers/12/sharedarraybuffer_metadata.h +0 -72
  329. package/src/headers/12/stream_base-inl.h +0 -323
  330. package/src/headers/12/stream_base.h +0 -431
  331. package/src/headers/12/stream_pipe.h +0 -72
  332. package/src/headers/12/string_bytes.h +0 -142
  333. package/src/headers/12/string_decoder.h +0 -50
  334. package/src/headers/12/string_search.h +0 -638
  335. package/src/headers/12/tracing/agent.h +0 -195
  336. package/src/headers/12/tracing/trace_event.h +0 -710
  337. package/src/headers/12/tty_wrap.h +0 -64
  338. package/src/headers/12/udp_wrap.h +0 -222
  339. package/src/headers/12/util-inl.h +0 -529
  340. package/src/headers/12/util.h +0 -765
  341. package/src/headers/13/async_wrap-inl.h +0 -94
  342. package/src/headers/13/async_wrap.h +0 -224
  343. package/src/headers/13/base64.h +0 -197
  344. package/src/headers/13/base_object-inl.h +0 -353
  345. package/src/headers/13/base_object.h +0 -229
  346. package/src/headers/13/connect_wrap.h +0 -26
  347. package/src/headers/13/connection_wrap.h +0 -30
  348. package/src/headers/13/debug_utils-inl.h +0 -223
  349. package/src/headers/13/diagnosticfilename-inl.h +0 -33
  350. package/src/headers/13/env-inl.h +0 -1293
  351. package/src/headers/13/env.h +0 -1469
  352. package/src/headers/13/handle_wrap.h +0 -117
  353. package/src/headers/13/histogram-inl.h +0 -83
  354. package/src/headers/13/histogram.h +0 -98
  355. package/src/headers/13/inspector_io.h +0 -78
  356. package/src/headers/13/inspector_socket.h +0 -60
  357. package/src/headers/13/inspector_socket_server.h +0 -110
  358. package/src/headers/13/js_native_api.h +0 -541
  359. package/src/headers/13/js_native_api_v8.h +0 -303
  360. package/src/headers/13/js_native_api_v8_internals.h +0 -38
  361. package/src/headers/13/js_stream.h +0 -52
  362. package/src/headers/13/json_utils.h +0 -160
  363. package/src/headers/13/node_api.h +0 -239
  364. package/src/headers/13/node_api_types.h +0 -44
  365. package/src/headers/13/node_binding.h +0 -99
  366. package/src/headers/13/node_context_data.h +0 -39
  367. package/src/headers/13/node_contextify.h +0 -161
  368. package/src/headers/13/node_crypto.h +0 -800
  369. package/src/headers/13/node_crypto_common.h +0 -138
  370. package/src/headers/13/node_crypto_groups.h +0 -415
  371. package/src/headers/13/node_dir.h +0 -52
  372. package/src/headers/13/node_dtrace.h +0 -86
  373. package/src/headers/13/node_errors.h +0 -210
  374. package/src/headers/13/node_file.h +0 -364
  375. package/src/headers/13/node_http2_state.h +0 -144
  376. package/src/headers/13/node_internals.h +0 -405
  377. package/src/headers/13/node_main_instance.h +0 -97
  378. package/src/headers/13/node_mem-inl.h +0 -112
  379. package/src/headers/13/node_mem.h +0 -41
  380. package/src/headers/13/node_metadata.h +0 -109
  381. package/src/headers/13/node_mutex.h +0 -247
  382. package/src/headers/13/node_native_module.h +0 -99
  383. package/src/headers/13/node_native_module_env.h +0 -65
  384. package/src/headers/13/node_object_wrap.h +0 -132
  385. package/src/headers/13/node_perf.h +0 -181
  386. package/src/headers/13/node_perf_common.h +0 -97
  387. package/src/headers/13/node_platform.h +0 -190
  388. package/src/headers/13/node_process.h +0 -41
  389. package/src/headers/13/node_root_certs.h +0 -3424
  390. package/src/headers/13/node_sockaddr-inl.h +0 -170
  391. package/src/headers/13/node_sockaddr.h +0 -123
  392. package/src/headers/13/node_union_bytes.h +0 -103
  393. package/src/headers/13/node_v8_platform-inl.h +0 -184
  394. package/src/headers/13/node_wasi.h +0 -108
  395. package/src/headers/13/node_win32_etw_provider-inl.h +0 -287
  396. package/src/headers/13/node_win32_etw_provider.h +0 -99
  397. package/src/headers/13/pipe_wrap.h +0 -78
  398. package/src/headers/13/req_wrap-inl.h +0 -170
  399. package/src/headers/13/spawn_sync.h +0 -242
  400. package/src/headers/13/stream_wrap.h +0 -130
  401. package/src/headers/13/string_decoder-inl.h +0 -37
  402. package/src/headers/13/string_decoder.h +0 -50
  403. package/src/headers/13/tcp_wrap.h +0 -101
  404. package/src/headers/13/threadpoolwork-inl.h +0 -57
  405. package/src/headers/13/tls_wrap.h +0 -221
  406. package/src/headers/13/tracing/node_trace_buffer.h +0 -83
  407. package/src/headers/13/tracing/node_trace_writer.h +0 -75
  408. package/src/headers/13/tracing/trace_event_common.h +0 -1109
  409. package/src/headers/13/tracing/traced_value.h +0 -70
  410. package/src/headers/13/v8abbr.h +0 -124
@@ -28,11 +28,13 @@
28
28
  #include "callback_queue-inl.h"
29
29
  #include "env.h"
30
30
  #include "node.h"
31
+ #include "node_context_data.h"
32
+ #include "node_internals.h"
33
+ #include "node_perf_common.h"
31
34
  #include "util-inl.h"
32
35
  #include "uv.h"
36
+ #include "v8-fast-api-calls.h"
33
37
  #include "v8.h"
34
- #include "node_perf_common.h"
35
- #include "node_context_data.h"
36
38
 
37
39
  #include <cstddef>
38
40
  #include <cstdint>
@@ -41,20 +43,22 @@
41
43
 
42
44
  namespace node {
43
45
 
44
- inline v8::Isolate* IsolateData::isolate() const {
45
- return isolate_;
46
+ NoArrayBufferZeroFillScope::NoArrayBufferZeroFillScope(
47
+ IsolateData* isolate_data)
48
+ : node_allocator_(isolate_data->node_allocator()) {
49
+ if (node_allocator_ != nullptr) node_allocator_->zero_fill_field()[0] = 0;
46
50
  }
47
51
 
48
- inline uv_loop_t* IsolateData::event_loop() const {
49
- return event_loop_;
52
+ NoArrayBufferZeroFillScope::~NoArrayBufferZeroFillScope() {
53
+ if (node_allocator_ != nullptr) node_allocator_->zero_fill_field()[0] = 1;
50
54
  }
51
55
 
52
- inline bool IsolateData::uses_node_allocator() const {
53
- return uses_node_allocator_;
56
+ inline v8::Isolate* IsolateData::isolate() const {
57
+ return isolate_;
54
58
  }
55
59
 
56
- inline v8::ArrayBuffer::Allocator* IsolateData::allocator() const {
57
- return allocator_;
60
+ inline uv_loop_t* IsolateData::event_loop() const {
61
+ return event_loop_;
58
62
  }
59
63
 
60
64
  inline NodeArrayBufferAllocator* IsolateData::node_allocator() const {
@@ -65,33 +69,19 @@ inline MultiIsolatePlatform* IsolateData::platform() const {
65
69
  return platform_;
66
70
  }
67
71
 
68
- inline v8::Local<v8::String> IsolateData::async_wrap_provider(int index) const {
69
- return async_wrap_providers_[index].Get(isolate_);
72
+ inline void IsolateData::set_worker_context(worker::Worker* context) {
73
+ CHECK_NULL(worker_context_); // Should be set only once.
74
+ worker_context_ = context;
70
75
  }
71
76
 
72
- inline AsyncHooks::AsyncHooks()
73
- : async_ids_stack_(env()->isolate(), 16 * 2),
74
- fields_(env()->isolate(), kFieldsCount),
75
- async_id_fields_(env()->isolate(), kUidFieldsCount) {
76
- clear_async_id_stack();
77
-
78
- // Always perform async_hooks checks, not just when async_hooks is enabled.
79
- // TODO(AndreasMadsen): Consider removing this for LTS releases.
80
- // See discussion in https://github.com/nodejs/node/pull/15454
81
- // When removing this, do it by reverting the commit. Otherwise the test
82
- // and flag changes won't be included.
83
- fields_[kCheck] = 1;
84
-
85
- // kDefaultTriggerAsyncId should be -1, this indicates that there is no
86
- // specified default value and it should fallback to the executionAsyncId.
87
- // 0 is not used as the magic value, because that indicates a missing context
88
- // which is different from a default context.
89
- async_id_fields_[AsyncHooks::kDefaultTriggerAsyncId] = -1;
77
+ inline worker::Worker* IsolateData::worker_context() const {
78
+ return worker_context_;
79
+ }
90
80
 
91
- // kAsyncIdCounter should start at 1 because that'll be the id the execution
92
- // context during bootstrap (code that runs before entering uv_run()).
93
- async_id_fields_[AsyncHooks::kAsyncIdCounter] = 1;
81
+ inline v8::Local<v8::String> IsolateData::async_wrap_provider(int index) const {
82
+ return async_wrap_providers_[index].Get(isolate_);
94
83
  }
84
+
95
85
  inline AliasedUint32Array& AsyncHooks::fields() {
96
86
  return fields_;
97
87
  }
@@ -104,8 +94,35 @@ inline AliasedFloat64Array& AsyncHooks::async_ids_stack() {
104
94
  return async_ids_stack_;
105
95
  }
106
96
 
107
- inline v8::Local<v8::Array> AsyncHooks::execution_async_resources() {
108
- return PersistentToLocal::Strong(execution_async_resources_);
97
+ v8::Local<v8::Array> AsyncHooks::js_execution_async_resources() {
98
+ if (UNLIKELY(js_execution_async_resources_.IsEmpty())) {
99
+ js_execution_async_resources_.Reset(
100
+ env()->isolate(), v8::Array::New(env()->isolate()));
101
+ }
102
+ return PersistentToLocal::Strong(js_execution_async_resources_);
103
+ }
104
+
105
+ v8::Local<v8::Object> AsyncHooks::native_execution_async_resource(size_t i) {
106
+ if (i >= native_execution_async_resources_.size()) return {};
107
+ return native_execution_async_resources_[i];
108
+ }
109
+
110
+ inline void AsyncHooks::SetJSPromiseHooks(v8::Local<v8::Function> init,
111
+ v8::Local<v8::Function> before,
112
+ v8::Local<v8::Function> after,
113
+ v8::Local<v8::Function> resolve) {
114
+ js_promise_hooks_[0].Reset(env()->isolate(), init);
115
+ js_promise_hooks_[1].Reset(env()->isolate(), before);
116
+ js_promise_hooks_[2].Reset(env()->isolate(), after);
117
+ js_promise_hooks_[3].Reset(env()->isolate(), resolve);
118
+ for (auto it = contexts_.begin(); it != contexts_.end(); it++) {
119
+ if (it->IsEmpty()) {
120
+ contexts_.erase(it--);
121
+ continue;
122
+ }
123
+ PersistentToLocal::Weak(env()->isolate(), *it)
124
+ ->SetPromiseHooks(init, before, after, resolve);
125
+ }
109
126
  }
110
127
 
111
128
  inline v8::Local<v8::String> AsyncHooks::provider_string(int idx) {
@@ -123,9 +140,7 @@ inline Environment* AsyncHooks::env() {
123
140
  // Remember to keep this code aligned with pushAsyncContext() in JS.
124
141
  inline void AsyncHooks::push_async_context(double async_id,
125
142
  double trigger_async_id,
126
- v8::Local<v8::Value> resource) {
127
- v8::HandleScope handle_scope(env()->isolate());
128
-
143
+ v8::Local<v8::Object> resource) {
129
144
  // Since async_hooks is experimental, do only perform the check
130
145
  // when async_hooks is enabled.
131
146
  if (fields_[kCheck] > 0) {
@@ -142,33 +157,33 @@ inline void AsyncHooks::push_async_context(double async_id,
142
157
  async_id_fields_[kExecutionAsyncId] = async_id;
143
158
  async_id_fields_[kTriggerAsyncId] = trigger_async_id;
144
159
 
145
- auto resources = execution_async_resources();
146
- USE(resources->Set(env()->context(), offset, resource));
160
+ #ifdef DEBUG
161
+ for (uint32_t i = offset; i < native_execution_async_resources_.size(); i++)
162
+ CHECK(native_execution_async_resources_[i].IsEmpty());
163
+ #endif
164
+
165
+ // When this call comes from JS (as a way of increasing the stack size),
166
+ // `resource` will be empty, because JS caches these values anyway.
167
+ if (!resource.IsEmpty()) {
168
+ native_execution_async_resources_.resize(offset + 1);
169
+ // Caveat: This is a v8::Local<> assignment, we do not keep a v8::Global<>!
170
+ native_execution_async_resources_[offset] = resource;
171
+ }
147
172
  }
148
173
 
149
174
  // Remember to keep this code aligned with popAsyncContext() in JS.
150
175
  inline bool AsyncHooks::pop_async_context(double async_id) {
151
176
  // In case of an exception then this may have already been reset, if the
152
177
  // stack was multiple MakeCallback()'s deep.
153
- if (fields_[kStackLength] == 0) return false;
178
+ if (UNLIKELY(fields_[kStackLength] == 0)) return false;
154
179
 
155
180
  // Ask for the async_id to be restored as a check that the stack
156
181
  // hasn't been corrupted.
157
182
  // Since async_hooks is experimental, do only perform the check
158
183
  // when async_hooks is enabled.
159
- if (fields_[kCheck] > 0 && async_id_fields_[kExecutionAsyncId] != async_id) {
160
- fprintf(stderr,
161
- "Error: async hook stack has become corrupted ("
162
- "actual: %.f, expected: %.f)\n",
163
- async_id_fields_.GetValue(kExecutionAsyncId),
164
- async_id);
165
- DumpBacktrace(stderr);
166
- fflush(stderr);
167
- if (!env()->abort_on_uncaught_exception())
168
- exit(1);
169
- fprintf(stderr, "\n");
170
- fflush(stderr);
171
- ABORT_NO_BACKTRACE();
184
+ if (UNLIKELY(fields_[kCheck] > 0 &&
185
+ async_id_fields_[kExecutionAsyncId] != async_id)) {
186
+ FailWithCorruptedAsyncStack(async_id);
172
187
  }
173
188
 
174
189
  uint32_t offset = fields_[kStackLength] - 1;
@@ -176,23 +191,90 @@ inline bool AsyncHooks::pop_async_context(double async_id) {
176
191
  async_id_fields_[kTriggerAsyncId] = async_ids_stack_[2 * offset + 1];
177
192
  fields_[kStackLength] = offset;
178
193
 
179
- auto resources = execution_async_resources();
180
- USE(resources->Delete(env()->context(), offset));
194
+ if (LIKELY(offset < native_execution_async_resources_.size() &&
195
+ !native_execution_async_resources_[offset].IsEmpty())) {
196
+ #ifdef DEBUG
197
+ for (uint32_t i = offset + 1;
198
+ i < native_execution_async_resources_.size();
199
+ i++) {
200
+ CHECK(native_execution_async_resources_[i].IsEmpty());
201
+ }
202
+ #endif
203
+ native_execution_async_resources_.resize(offset);
204
+ if (native_execution_async_resources_.size() <
205
+ native_execution_async_resources_.capacity() / 2 &&
206
+ native_execution_async_resources_.size() > 16) {
207
+ native_execution_async_resources_.shrink_to_fit();
208
+ }
209
+ }
210
+
211
+ if (UNLIKELY(js_execution_async_resources()->Length() > offset)) {
212
+ v8::HandleScope handle_scope(env()->isolate());
213
+ USE(js_execution_async_resources()->Set(
214
+ env()->context(),
215
+ env()->length_string(),
216
+ v8::Integer::NewFromUnsigned(env()->isolate(), offset)));
217
+ }
181
218
 
182
219
  return fields_[kStackLength] > 0;
183
220
  }
184
221
 
185
- // Keep in sync with clearAsyncIdStack in lib/internal/async_hooks.js.
186
- inline void AsyncHooks::clear_async_id_stack() {
187
- auto isolate = env()->isolate();
222
+ void AsyncHooks::clear_async_id_stack() {
223
+ v8::Isolate* isolate = env()->isolate();
188
224
  v8::HandleScope handle_scope(isolate);
189
- execution_async_resources_.Reset(isolate, v8::Array::New(isolate));
225
+ if (!js_execution_async_resources_.IsEmpty()) {
226
+ USE(PersistentToLocal::Strong(js_execution_async_resources_)->Set(
227
+ env()->context(),
228
+ env()->length_string(),
229
+ v8::Integer::NewFromUnsigned(isolate, 0)));
230
+ }
231
+ native_execution_async_resources_.clear();
232
+ native_execution_async_resources_.shrink_to_fit();
190
233
 
191
234
  async_id_fields_[kExecutionAsyncId] = 0;
192
235
  async_id_fields_[kTriggerAsyncId] = 0;
193
236
  fields_[kStackLength] = 0;
194
237
  }
195
238
 
239
+ inline void AsyncHooks::AddContext(v8::Local<v8::Context> ctx) {
240
+ ctx->SetPromiseHooks(
241
+ js_promise_hooks_[0].IsEmpty() ?
242
+ v8::Local<v8::Function>() :
243
+ PersistentToLocal::Strong(js_promise_hooks_[0]),
244
+ js_promise_hooks_[1].IsEmpty() ?
245
+ v8::Local<v8::Function>() :
246
+ PersistentToLocal::Strong(js_promise_hooks_[1]),
247
+ js_promise_hooks_[2].IsEmpty() ?
248
+ v8::Local<v8::Function>() :
249
+ PersistentToLocal::Strong(js_promise_hooks_[2]),
250
+ js_promise_hooks_[3].IsEmpty() ?
251
+ v8::Local<v8::Function>() :
252
+ PersistentToLocal::Strong(js_promise_hooks_[3]));
253
+
254
+ size_t id = contexts_.size();
255
+ contexts_.resize(id + 1);
256
+ contexts_[id].Reset(env()->isolate(), ctx);
257
+ contexts_[id].SetWeak();
258
+ }
259
+
260
+ inline void AsyncHooks::RemoveContext(v8::Local<v8::Context> ctx) {
261
+ v8::Isolate* isolate = env()->isolate();
262
+ v8::HandleScope handle_scope(isolate);
263
+ contexts_.erase(std::remove_if(contexts_.begin(),
264
+ contexts_.end(),
265
+ [&](auto&& el) { return el.IsEmpty(); }),
266
+ contexts_.end());
267
+ for (auto it = contexts_.begin(); it != contexts_.end(); it++) {
268
+ v8::Local<v8::Context> saved_context =
269
+ PersistentToLocal::Weak(isolate, *it);
270
+ if (saved_context == ctx) {
271
+ it->Reset();
272
+ contexts_.erase(it);
273
+ break;
274
+ }
275
+ }
276
+ }
277
+
196
278
  // The DefaultTriggerAsyncIdScope(AsyncWrap*) constructor is defined in
197
279
  // async_wrap-inl.h to avoid a circular dependency.
198
280
 
@@ -230,9 +312,6 @@ inline void Environment::PopAsyncCallbackScope() {
230
312
  async_callback_scope_depth_--;
231
313
  }
232
314
 
233
- inline ImmediateInfo::ImmediateInfo(v8::Isolate* isolate)
234
- : fields_(isolate, kFieldsCount) {}
235
-
236
315
  inline AliasedUint32Array& ImmediateInfo::fields() {
237
316
  return fields_;
238
317
  }
@@ -257,9 +336,6 @@ inline void ImmediateInfo::ref_count_dec(uint32_t decrement) {
257
336
  fields_[kRefCount] -= decrement;
258
337
  }
259
338
 
260
- inline TickInfo::TickInfo(v8::Isolate* isolate)
261
- : fields_(isolate, kFieldsCount) {}
262
-
263
339
  inline AliasedUint8Array& TickInfo::fields() {
264
340
  return fields_;
265
341
  }
@@ -279,9 +355,15 @@ inline void Environment::AssignToContext(v8::Local<v8::Context> context,
279
355
  // Used by Environment::GetCurrent to know that we are on a node context.
280
356
  context->SetAlignedPointerInEmbedderData(
281
357
  ContextEmbedderIndex::kContextTag, Environment::kNodeContextTagPtr);
358
+ // Used to retrieve bindings
359
+ context->SetAlignedPointerInEmbedderData(
360
+ ContextEmbedderIndex::kBindingListIndex, &(this->bindings_));
361
+
282
362
  #if HAVE_INSPECTOR
283
363
  inspector_agent()->ContextCreated(context, info);
284
364
  #endif // HAVE_INSPECTOR
365
+
366
+ this->async_hooks()->AddContext(context);
285
367
  }
286
368
 
287
369
  inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
@@ -310,31 +392,55 @@ inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) {
310
392
 
311
393
  inline Environment* Environment::GetCurrent(
312
394
  const v8::FunctionCallbackInfo<v8::Value>& info) {
313
- return GetFromCallbackData(info.Data());
395
+ return GetCurrent(info.GetIsolate()->GetCurrentContext());
314
396
  }
315
397
 
316
398
  template <typename T>
317
399
  inline Environment* Environment::GetCurrent(
318
400
  const v8::PropertyCallbackInfo<T>& info) {
319
- return GetFromCallbackData(info.Data());
401
+ return GetCurrent(info.GetIsolate()->GetCurrentContext());
402
+ }
403
+
404
+ template <typename T, typename U>
405
+ inline T* Environment::GetBindingData(const v8::PropertyCallbackInfo<U>& info) {
406
+ return GetBindingData<T>(info.GetIsolate()->GetCurrentContext());
320
407
  }
321
408
 
322
- inline Environment* Environment::GetFromCallbackData(v8::Local<v8::Value> val) {
323
- DCHECK(val->IsObject());
324
- v8::Local<v8::Object> obj = val.As<v8::Object>();
325
- DCHECK_GE(obj->InternalFieldCount(), 1);
326
- Environment* env =
327
- static_cast<Environment*>(obj->GetAlignedPointerFromInternalField(0));
328
- DCHECK(env->as_callback_data_template()->HasInstance(obj));
329
- return env;
409
+ template <typename T>
410
+ inline T* Environment::GetBindingData(
411
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
412
+ return GetBindingData<T>(info.GetIsolate()->GetCurrentContext());
330
413
  }
331
414
 
332
- inline Environment* Environment::GetThreadLocalEnv() {
333
- return static_cast<Environment*>(uv_key_get(&thread_local_env));
415
+ template <typename T>
416
+ inline T* Environment::GetBindingData(v8::Local<v8::Context> context) {
417
+ BindingDataStore* map = static_cast<BindingDataStore*>(
418
+ context->GetAlignedPointerFromEmbedderData(
419
+ ContextEmbedderIndex::kBindingListIndex));
420
+ DCHECK_NOT_NULL(map);
421
+ auto it = map->find(T::type_name);
422
+ if (UNLIKELY(it == map->end())) return nullptr;
423
+ T* result = static_cast<T*>(it->second.get());
424
+ DCHECK_NOT_NULL(result);
425
+ DCHECK_EQ(result->env(), GetCurrent(context));
426
+ return result;
334
427
  }
335
428
 
336
- inline bool Environment::profiler_idle_notifier_started() const {
337
- return profiler_idle_notifier_started_;
429
+ template <typename T>
430
+ inline T* Environment::AddBindingData(
431
+ v8::Local<v8::Context> context,
432
+ v8::Local<v8::Object> target) {
433
+ DCHECK_EQ(GetCurrent(context), this);
434
+ // This won't compile if T is not a BaseObject subclass.
435
+ BaseObjectPtr<T> item = MakeDetachedBaseObject<T>(this, target);
436
+ BindingDataStore* map = static_cast<BindingDataStore*>(
437
+ context->GetAlignedPointerFromEmbedderData(
438
+ ContextEmbedderIndex::kBindingListIndex));
439
+ DCHECK_NOT_NULL(map);
440
+ auto result = map->emplace(T::type_name, item);
441
+ CHECK(result.second);
442
+ DCHECK_EQ(GetBindingData<T>(context), item.get());
443
+ return item.get();
338
444
  }
339
445
 
340
446
  inline v8::Isolate* Environment::isolate() const {
@@ -463,6 +569,14 @@ inline bool Environment::abort_on_uncaught_exception() const {
463
569
  return options_->abort_on_uncaught_exception;
464
570
  }
465
571
 
572
+ inline void Environment::set_force_context_aware(bool value) {
573
+ options_->force_context_aware = value;
574
+ }
575
+
576
+ inline bool Environment::force_context_aware() const {
577
+ return options_->force_context_aware;
578
+ }
579
+
466
580
  inline void Environment::set_abort_on_uncaught_exception(bool value) {
467
581
  options_->abort_on_uncaught_exception = value;
468
582
  }
@@ -540,76 +654,6 @@ inline double Environment::get_default_trigger_async_id() {
540
654
  return default_trigger_async_id;
541
655
  }
542
656
 
543
- inline double* Environment::heap_statistics_buffer() const {
544
- CHECK_NOT_NULL(heap_statistics_buffer_);
545
- return heap_statistics_buffer_;
546
- }
547
-
548
- inline void Environment::set_heap_statistics_buffer(double* pointer) {
549
- CHECK_NULL(heap_statistics_buffer_); // Should be set only once.
550
- heap_statistics_buffer_ = pointer;
551
- }
552
-
553
- inline double* Environment::heap_space_statistics_buffer() const {
554
- CHECK_NOT_NULL(heap_space_statistics_buffer_);
555
- return heap_space_statistics_buffer_;
556
- }
557
-
558
- inline void Environment::set_heap_space_statistics_buffer(double* pointer) {
559
- CHECK_NULL(heap_space_statistics_buffer_); // Should be set only once.
560
- heap_space_statistics_buffer_ = pointer;
561
- }
562
-
563
- inline double* Environment::heap_code_statistics_buffer() const {
564
- CHECK_NOT_NULL(heap_code_statistics_buffer_);
565
- return heap_code_statistics_buffer_;
566
- }
567
-
568
- inline void Environment::set_heap_code_statistics_buffer(double* pointer) {
569
- CHECK_NULL(heap_code_statistics_buffer_); // Should be set only once.
570
- heap_code_statistics_buffer_ = pointer;
571
- }
572
-
573
- inline char* Environment::http_parser_buffer() const {
574
- return http_parser_buffer_;
575
- }
576
-
577
- inline void Environment::set_http_parser_buffer(char* buffer) {
578
- CHECK_NULL(http_parser_buffer_); // Should be set only once.
579
- http_parser_buffer_ = buffer;
580
- }
581
-
582
- inline bool Environment::http_parser_buffer_in_use() const {
583
- return http_parser_buffer_in_use_;
584
- }
585
-
586
- inline void Environment::set_http_parser_buffer_in_use(bool in_use) {
587
- http_parser_buffer_in_use_ = in_use;
588
- }
589
-
590
- inline http2::Http2State* Environment::http2_state() const {
591
- return http2_state_.get();
592
- }
593
-
594
- inline void Environment::set_http2_state(
595
- std::unique_ptr<http2::Http2State> buffer) {
596
- CHECK(!http2_state_); // Should be set only once.
597
- http2_state_ = std::move(buffer);
598
- }
599
-
600
- inline AliasedFloat64Array* Environment::fs_stats_field_array() {
601
- return &fs_stats_field_array_;
602
- }
603
-
604
- inline AliasedBigUint64Array* Environment::fs_stats_field_bigint_array() {
605
- return &fs_stats_field_bigint_array_;
606
- }
607
-
608
- inline std::vector<std::unique_ptr<fs::FileHandleReadWrap>>&
609
- Environment::file_handle_read_wrap_freelist() {
610
- return file_handle_read_wrap_freelist_;
611
- }
612
-
613
657
  inline std::shared_ptr<EnvironmentOptions> Environment::options() {
614
658
  return options_;
615
659
  }
@@ -626,6 +670,22 @@ inline const std::string& Environment::exec_path() const {
626
670
  return exec_path_;
627
671
  }
628
672
 
673
+ inline std::string Environment::GetCwd() {
674
+ char cwd[PATH_MAX_BYTES];
675
+ size_t size = PATH_MAX_BYTES;
676
+ const int err = uv_cwd(cwd, &size);
677
+
678
+ if (err == 0) {
679
+ CHECK_GT(size, 0);
680
+ return cwd;
681
+ }
682
+
683
+ // This can fail if the cwd is deleted. In that case, fall back to
684
+ // exec_path.
685
+ const std::string& exec_path = exec_path_;
686
+ return exec_path.substr(0, exec_path.find_last_of(kPathSeparator));
687
+ }
688
+
629
689
  #if HAVE_INSPECTOR
630
690
  inline void Environment::set_coverage_directory(const char* dir) {
631
691
  coverage_directory_ = std::string(dir);
@@ -732,45 +792,39 @@ inline void IsolateData::set_options(
732
792
  }
733
793
 
734
794
  template <typename Fn>
735
- void Environment::CreateImmediate(Fn&& cb, bool ref) {
736
- auto callback = native_immediates_.CreateCallback(std::move(cb), ref);
795
+ void Environment::SetImmediate(Fn&& cb, CallbackFlags::Flags flags) {
796
+ auto callback = native_immediates_.CreateCallback(std::move(cb), flags);
737
797
  native_immediates_.Push(std::move(callback));
738
- }
739
-
740
- template <typename Fn>
741
- void Environment::SetImmediate(Fn&& cb) {
742
- CreateImmediate(std::move(cb), true);
743
798
 
744
- if (immediate_info()->ref_count() == 0)
745
- ToggleImmediateRef(true);
746
- immediate_info()->ref_count_inc(1);
747
- }
748
-
749
- template <typename Fn>
750
- void Environment::SetUnrefImmediate(Fn&& cb) {
751
- CreateImmediate(std::move(cb), false);
799
+ if (flags & CallbackFlags::kRefed) {
800
+ if (immediate_info()->ref_count() == 0)
801
+ ToggleImmediateRef(true);
802
+ immediate_info()->ref_count_inc(1);
803
+ }
752
804
  }
753
805
 
754
806
  template <typename Fn>
755
- void Environment::SetImmediateThreadsafe(Fn&& cb, bool refed) {
756
- auto callback =
757
- native_immediates_threadsafe_.CreateCallback(std::move(cb), refed);
807
+ void Environment::SetImmediateThreadsafe(Fn&& cb, CallbackFlags::Flags flags) {
808
+ auto callback = native_immediates_threadsafe_.CreateCallback(
809
+ std::move(cb), flags);
758
810
  {
759
811
  Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_);
760
812
  native_immediates_threadsafe_.Push(std::move(callback));
813
+ if (task_queues_async_initialized_)
814
+ uv_async_send(&task_queues_async_);
761
815
  }
762
- uv_async_send(&task_queues_async_);
763
816
  }
764
817
 
765
818
  template <typename Fn>
766
819
  void Environment::RequestInterrupt(Fn&& cb) {
767
- auto callback =
768
- native_immediates_interrupts_.CreateCallback(std::move(cb), false);
820
+ auto callback = native_immediates_interrupts_.CreateCallback(
821
+ std::move(cb), CallbackFlags::kRefed);
769
822
  {
770
823
  Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_);
771
824
  native_immediates_interrupts_.Push(std::move(callback));
825
+ if (task_queues_async_initialized_)
826
+ uv_async_send(&task_queues_async_);
772
827
  }
773
- uv_async_send(&task_queues_async_);
774
828
  RequestInterruptFromV8();
775
829
  }
776
830
 
@@ -786,8 +840,12 @@ inline bool Environment::has_run_bootstrapping_code() const {
786
840
  return has_run_bootstrapping_code_;
787
841
  }
788
842
 
789
- inline void Environment::set_has_run_bootstrapping_code(bool value) {
790
- has_run_bootstrapping_code_ = value;
843
+ inline void Environment::DoneBootstrapping() {
844
+ has_run_bootstrapping_code_ = true;
845
+ // This adjusts the return value of base_object_created_after_bootstrap() so
846
+ // that tests that check the count do not have to account for internally
847
+ // created BaseObjects.
848
+ base_object_created_by_bootstrap_ = base_object_count_;
791
849
  }
792
850
 
793
851
  inline bool Environment::has_serialized_options() const {
@@ -799,15 +857,66 @@ inline void Environment::set_has_serialized_options(bool value) {
799
857
  }
800
858
 
801
859
  inline bool Environment::is_main_thread() const {
802
- return flags_ & kIsMainThread;
860
+ return worker_context() == nullptr;
861
+ }
862
+
863
+ inline bool Environment::no_native_addons() const {
864
+ return (flags_ & EnvironmentFlags::kNoNativeAddons) ||
865
+ !options_->allow_native_addons;
866
+ }
867
+
868
+ inline bool Environment::should_not_register_esm_loader() const {
869
+ return flags_ & EnvironmentFlags::kNoRegisterESMLoader;
803
870
  }
804
871
 
805
872
  inline bool Environment::owns_process_state() const {
806
- return flags_ & kOwnsProcessState;
873
+ return flags_ & EnvironmentFlags::kOwnsProcessState;
807
874
  }
808
875
 
809
876
  inline bool Environment::owns_inspector() const {
810
- return flags_ & kOwnsInspector;
877
+ return flags_ & EnvironmentFlags::kOwnsInspector;
878
+ }
879
+
880
+ inline bool Environment::should_create_inspector() const {
881
+ return (flags_ & EnvironmentFlags::kNoCreateInspector) == 0;
882
+ }
883
+
884
+ inline bool Environment::tracks_unmanaged_fds() const {
885
+ return flags_ & EnvironmentFlags::kTrackUnmanagedFds;
886
+ }
887
+
888
+ inline bool Environment::hide_console_windows() const {
889
+ return flags_ & EnvironmentFlags::kHideConsoleWindows;
890
+ }
891
+
892
+ inline bool Environment::no_global_search_paths() const {
893
+ return (flags_ & EnvironmentFlags::kNoGlobalSearchPaths) ||
894
+ !options_->global_search_paths;
895
+ }
896
+
897
+ inline bool Environment::no_browser_globals() const {
898
+ // configure --no-browser-globals
899
+ #ifdef NODE_NO_BROWSER_GLOBALS
900
+ return true;
901
+ #else
902
+ return flags_ & EnvironmentFlags::kNoBrowserGlobals;
903
+ #endif
904
+ }
905
+
906
+ bool Environment::filehandle_close_warning() const {
907
+ return emit_filehandle_warning_;
908
+ }
909
+
910
+ void Environment::set_filehandle_close_warning(bool on) {
911
+ emit_filehandle_warning_ = on;
912
+ }
913
+
914
+ void Environment::set_source_maps_enabled(bool on) {
915
+ source_maps_enabled_ = on;
916
+ }
917
+
918
+ bool Environment::source_maps_enabled() const {
919
+ return source_maps_enabled_;
811
920
  }
812
921
 
813
922
  inline uint64_t Environment::thread_id() const {
@@ -815,12 +924,7 @@ inline uint64_t Environment::thread_id() const {
815
924
  }
816
925
 
817
926
  inline worker::Worker* Environment::worker_context() const {
818
- return worker_context_;
819
- }
820
-
821
- inline void Environment::set_worker_context(worker::Worker* context) {
822
- CHECK_NULL(worker_context_); // Should be set only once.
823
- worker_context_ = context;
927
+ return isolate_data()->worker_context();
824
928
  }
825
929
 
826
930
  inline void Environment::add_sub_worker_context(worker::Worker* context) {
@@ -862,6 +966,11 @@ inline node_module* Environment::extra_linked_bindings_head() {
862
966
  &extra_linked_bindings_.front() : nullptr;
863
967
  }
864
968
 
969
+ inline node_module* Environment::extra_linked_bindings_tail() {
970
+ return extra_linked_bindings_.size() > 0 ?
971
+ &extra_linked_bindings_.back() : nullptr;
972
+ }
973
+
865
974
  inline const Mutex& Environment::extra_linked_bindings_mutex() const {
866
975
  return extra_linked_bindings_mutex_;
867
976
  }
@@ -870,116 +979,30 @@ inline performance::PerformanceState* Environment::performance_state() {
870
979
  return performance_state_.get();
871
980
  }
872
981
 
873
- inline std::unordered_map<std::string, uint64_t>*
874
- Environment::performance_marks() {
875
- return &performance_marks_;
876
- }
877
-
878
982
  inline IsolateData* Environment::isolate_data() const {
879
983
  return isolate_data_;
880
984
  }
881
985
 
882
- inline char* Environment::AllocateUnchecked(size_t size) {
883
- return static_cast<char*>(
884
- isolate_data()->allocator()->AllocateUninitialized(size));
885
- }
886
-
887
- inline char* Environment::Allocate(size_t size) {
888
- char* ret = AllocateUnchecked(size);
889
- CHECK_NE(ret, nullptr);
890
- return ret;
891
- }
892
-
893
- inline void Environment::Free(char* data, size_t size) {
894
- if (data != nullptr)
895
- isolate_data()->allocator()->Free(data, size);
896
- }
897
-
898
- inline AllocatedBuffer Environment::AllocateManaged(size_t size, bool checked) {
899
- char* data = checked ? Allocate(size) : AllocateUnchecked(size);
900
- if (data == nullptr) size = 0;
901
- return AllocatedBuffer(this, uv_buf_init(data, size));
902
- }
903
-
904
- inline AllocatedBuffer::AllocatedBuffer(Environment* env, uv_buf_t buf)
905
- : env_(env), buffer_(buf) {}
906
-
907
- inline void AllocatedBuffer::Resize(size_t len) {
908
- // The `len` check is to make sure we don't end up with `nullptr` as our base.
909
- char* new_data = env_->Reallocate(buffer_.base, buffer_.len,
910
- len > 0 ? len : 1);
911
- CHECK_NOT_NULL(new_data);
912
- buffer_ = uv_buf_init(new_data, len);
913
- }
914
-
915
- inline uv_buf_t AllocatedBuffer::release() {
916
- uv_buf_t ret = buffer_;
917
- buffer_ = uv_buf_init(nullptr, 0);
918
- return ret;
919
- }
920
-
921
- inline char* AllocatedBuffer::data() {
922
- return buffer_.base;
923
- }
924
-
925
- inline const char* AllocatedBuffer::data() const {
926
- return buffer_.base;
927
- }
928
-
929
- inline size_t AllocatedBuffer::size() const {
930
- return buffer_.len;
931
- }
932
-
933
- inline AllocatedBuffer::AllocatedBuffer(Environment* env)
934
- : env_(env), buffer_(uv_buf_init(nullptr, 0)) {}
935
-
936
- inline AllocatedBuffer::AllocatedBuffer(AllocatedBuffer&& other)
937
- : AllocatedBuffer() {
938
- *this = std::move(other);
939
- }
940
-
941
- inline AllocatedBuffer& AllocatedBuffer::operator=(AllocatedBuffer&& other) {
942
- clear();
943
- env_ = other.env_;
944
- buffer_ = other.release();
945
- return *this;
946
- }
947
-
948
- inline AllocatedBuffer::~AllocatedBuffer() {
949
- clear();
986
+ inline uv_buf_t Environment::allocate_managed_buffer(
987
+ const size_t suggested_size) {
988
+ NoArrayBufferZeroFillScope no_zero_fill_scope(isolate_data());
989
+ std::unique_ptr<v8::BackingStore> bs =
990
+ v8::ArrayBuffer::NewBackingStore(isolate(), suggested_size);
991
+ uv_buf_t buf = uv_buf_init(static_cast<char*>(bs->Data()), bs->ByteLength());
992
+ released_allocated_buffers_.emplace(buf.base, std::move(bs));
993
+ return buf;
950
994
  }
951
995
 
952
- inline void AllocatedBuffer::clear() {
953
- uv_buf_t buf = release();
996
+ inline std::unique_ptr<v8::BackingStore> Environment::release_managed_buffer(
997
+ const uv_buf_t& buf) {
998
+ std::unique_ptr<v8::BackingStore> bs;
954
999
  if (buf.base != nullptr) {
955
- CHECK_NOT_NULL(env_);
956
- env_->Free(buf.base, buf.len);
1000
+ auto it = released_allocated_buffers_.find(buf.base);
1001
+ CHECK_NE(it, released_allocated_buffers_.end());
1002
+ bs = std::move(it->second);
1003
+ released_allocated_buffers_.erase(it);
957
1004
  }
958
- }
959
-
960
- // It's a bit awkward to define this Buffer::New() overload here, but it
961
- // avoids a circular dependency with node_internals.h.
962
- namespace Buffer {
963
- v8::MaybeLocal<v8::Object> New(Environment* env,
964
- char* data,
965
- size_t length,
966
- bool uses_malloc);
967
- }
968
-
969
- inline v8::MaybeLocal<v8::Object> AllocatedBuffer::ToBuffer() {
970
- CHECK_NOT_NULL(env_);
971
- v8::MaybeLocal<v8::Object> obj = Buffer::New(env_, data(), size(), false);
972
- if (!obj.IsEmpty()) release();
973
- return obj;
974
- }
975
-
976
- inline v8::Local<v8::ArrayBuffer> AllocatedBuffer::ToArrayBuffer() {
977
- CHECK_NOT_NULL(env_);
978
- uv_buf_t buf = release();
979
- return v8::ArrayBuffer::New(env_->isolate(),
980
- buf.base,
981
- buf.len,
982
- v8::ArrayBufferCreationMode::kInternalized);
1005
+ return bs;
983
1006
  }
984
1007
 
985
1008
  inline void Environment::ThrowError(const char* errmsg) {
@@ -1018,14 +1041,20 @@ inline void Environment::ThrowUVException(int errorno,
1018
1041
  UVException(isolate(), errorno, syscall, message, path, dest));
1019
1042
  }
1020
1043
 
1021
- inline v8::Local<v8::FunctionTemplate>
1022
- Environment::NewFunctionTemplate(v8::FunctionCallback callback,
1023
- v8::Local<v8::Signature> signature,
1024
- v8::ConstructorBehavior behavior,
1025
- v8::SideEffectType side_effect_type) {
1026
- v8::Local<v8::Object> external = as_callback_data();
1027
- return v8::FunctionTemplate::New(isolate(), callback, external,
1028
- signature, 0, behavior, side_effect_type);
1044
+ inline v8::Local<v8::FunctionTemplate> Environment::NewFunctionTemplate(
1045
+ v8::FunctionCallback callback,
1046
+ v8::Local<v8::Signature> signature,
1047
+ v8::ConstructorBehavior behavior,
1048
+ v8::SideEffectType side_effect_type,
1049
+ const v8::CFunction* c_function) {
1050
+ return v8::FunctionTemplate::New(isolate(),
1051
+ callback,
1052
+ v8::Local<v8::Value>(),
1053
+ signature,
1054
+ 0,
1055
+ behavior,
1056
+ side_effect_type,
1057
+ c_function);
1029
1058
  }
1030
1059
 
1031
1060
  inline void Environment::SetMethod(v8::Local<v8::Object> that,
@@ -1046,6 +1075,25 @@ inline void Environment::SetMethod(v8::Local<v8::Object> that,
1046
1075
  function->SetName(name_string); // NODE_SET_METHOD() compatibility.
1047
1076
  }
1048
1077
 
1078
+ inline void Environment::SetFastMethod(v8::Local<v8::Object> that,
1079
+ const char* name,
1080
+ v8::FunctionCallback slow_callback,
1081
+ const v8::CFunction* c_function) {
1082
+ v8::Local<v8::Context> context = isolate()->GetCurrentContext();
1083
+ v8::Local<v8::Function> function =
1084
+ NewFunctionTemplate(slow_callback,
1085
+ v8::Local<v8::Signature>(),
1086
+ v8::ConstructorBehavior::kThrow,
1087
+ v8::SideEffectType::kHasNoSideEffect,
1088
+ c_function)
1089
+ ->GetFunction(context)
1090
+ .ToLocalChecked();
1091
+ const v8::NewStringType type = v8::NewStringType::kInternalized;
1092
+ v8::Local<v8::String> name_string =
1093
+ v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1094
+ that->Set(context, name_string, function).Check();
1095
+ }
1096
+
1049
1097
  inline void Environment::SetMethodNoSideEffect(v8::Local<v8::Object> that,
1050
1098
  const char* name,
1051
1099
  v8::FunctionCallback callback) {
@@ -1110,7 +1158,28 @@ inline void Environment::SetInstanceMethod(v8::Local<v8::FunctionTemplate> that,
1110
1158
  t->SetClassName(name_string);
1111
1159
  }
1112
1160
 
1113
- void Environment::AddCleanupHook(void (*fn)(void*), void* arg) {
1161
+ inline void Environment::SetConstructorFunction(
1162
+ v8::Local<v8::Object> that,
1163
+ const char* name,
1164
+ v8::Local<v8::FunctionTemplate> tmpl,
1165
+ SetConstructorFunctionFlag flag) {
1166
+ SetConstructorFunction(that, OneByteString(isolate(), name), tmpl, flag);
1167
+ }
1168
+
1169
+ inline void Environment::SetConstructorFunction(
1170
+ v8::Local<v8::Object> that,
1171
+ v8::Local<v8::String> name,
1172
+ v8::Local<v8::FunctionTemplate> tmpl,
1173
+ SetConstructorFunctionFlag flag) {
1174
+ if (LIKELY(flag == SetConstructorFunctionFlag::SET_CLASS_NAME))
1175
+ tmpl->SetClassName(name);
1176
+ that->Set(
1177
+ context(),
1178
+ name,
1179
+ tmpl->GetFunction(context()).ToLocalChecked()).Check();
1180
+ }
1181
+
1182
+ void Environment::AddCleanupHook(CleanupCallback fn, void* arg) {
1114
1183
  auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback {
1115
1184
  fn, arg, cleanup_hook_counter_++
1116
1185
  });
@@ -1118,17 +1187,11 @@ void Environment::AddCleanupHook(void (*fn)(void*), void* arg) {
1118
1187
  CHECK_EQ(insertion_info.second, true);
1119
1188
  }
1120
1189
 
1121
- void Environment::RemoveCleanupHook(void (*fn)(void*), void* arg) {
1190
+ void Environment::RemoveCleanupHook(CleanupCallback fn, void* arg) {
1122
1191
  CleanupHookCallback search { fn, arg, 0 };
1123
1192
  cleanup_hooks_.erase(search);
1124
1193
  }
1125
1194
 
1126
- inline void Environment::RegisterFinalizationGroupForCleanup(
1127
- v8::Local<v8::FinalizationGroup> group) {
1128
- cleanup_finalization_groups_.emplace_back(isolate(), group);
1129
- uv_async_send(&task_queues_async_);
1130
- }
1131
-
1132
1195
  size_t CleanupHookCallback::Hash::operator()(
1133
1196
  const CleanupHookCallback& cb) const {
1134
1197
  return std::hash<void*>()(cb.arg_);
@@ -1155,14 +1218,39 @@ void Environment::ForEachBaseObject(T&& iterator) {
1155
1218
  }
1156
1219
  }
1157
1220
 
1221
+ template <typename T>
1222
+ void Environment::ForEachBindingData(T&& iterator) {
1223
+ BindingDataStore* map = static_cast<BindingDataStore*>(
1224
+ context()->GetAlignedPointerFromEmbedderData(
1225
+ ContextEmbedderIndex::kBindingListIndex));
1226
+ DCHECK_NOT_NULL(map);
1227
+ for (auto& it : *map) {
1228
+ iterator(it.first, it.second);
1229
+ }
1230
+ }
1231
+
1158
1232
  void Environment::modify_base_object_count(int64_t delta) {
1159
1233
  base_object_count_ += delta;
1160
1234
  }
1161
1235
 
1236
+ int64_t Environment::base_object_created_after_bootstrap() const {
1237
+ return base_object_count_ - base_object_created_by_bootstrap_;
1238
+ }
1239
+
1162
1240
  int64_t Environment::base_object_count() const {
1163
1241
  return base_object_count_;
1164
1242
  }
1165
1243
 
1244
+ void Environment::set_main_utf16(std::unique_ptr<v8::String::Value> str) {
1245
+ CHECK(!main_utf16_);
1246
+ main_utf16_ = std::move(str);
1247
+ }
1248
+
1249
+ void Environment::set_process_exit_handler(
1250
+ std::function<void(Environment*, int)>&& handler) {
1251
+ process_exit_handler_ = std::move(handler);
1252
+ }
1253
+
1166
1254
  #define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
1167
1255
  #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
1168
1256
  #define VS(PropertyName, StringValue) V(v8::String, PropertyName)
@@ -1205,11 +1293,16 @@ int64_t Environment::base_object_count() const {
1205
1293
  ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)
1206
1294
  #undef V
1207
1295
 
1208
- inline v8::Local<v8::Context> Environment::context() const {
1209
- return PersistentToLocal::Strong(context_);
1210
- }
1296
+ v8::Local<v8::Context> Environment::context() const {
1297
+ return PersistentToLocal::Strong(context_);
1298
+ }
1299
+
1211
1300
  } // namespace node
1212
1301
 
1302
+ // These two files depend on each other. Including base_object-inl.h after this
1303
+ // file is the easiest way to avoid issues with that circular dependency.
1304
+ #include "base_object-inl.h"
1305
+
1213
1306
  #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
1214
1307
 
1215
1308
  #endif // SRC_ENV_INL_H_