@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
@@ -1,1293 +0,0 @@
1
- // Copyright Joyent, Inc. and other Node contributors.
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a
4
- // copy of this software and associated documentation files (the
5
- // "Software"), to deal in the Software without restriction, including
6
- // without limitation the rights to use, copy, modify, merge, publish,
7
- // distribute, sublicense, and/or sell copies of the Software, and to permit
8
- // persons to whom the Software is furnished to do so, subject to the
9
- // following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be included
12
- // in all copies or substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
22
- #ifndef SRC_ENV_INL_H_
23
- #define SRC_ENV_INL_H_
24
-
25
- #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
-
27
- #include "aliased_buffer.h"
28
- #include "env.h"
29
- #include "node.h"
30
- #include "util-inl.h"
31
- #include "uv.h"
32
- #include "v8.h"
33
- #include "node_perf_common.h"
34
- #include "node_context_data.h"
35
-
36
- #include <cstddef>
37
- #include <cstdint>
38
-
39
- #include <utility>
40
-
41
- namespace node {
42
-
43
- inline v8::Isolate* IsolateData::isolate() const {
44
- return isolate_;
45
- }
46
-
47
- inline uv_loop_t* IsolateData::event_loop() const {
48
- return event_loop_;
49
- }
50
-
51
- inline bool IsolateData::uses_node_allocator() const {
52
- return uses_node_allocator_;
53
- }
54
-
55
- inline v8::ArrayBuffer::Allocator* IsolateData::allocator() const {
56
- return allocator_;
57
- }
58
-
59
- inline NodeArrayBufferAllocator* IsolateData::node_allocator() const {
60
- return node_allocator_;
61
- }
62
-
63
- inline MultiIsolatePlatform* IsolateData::platform() const {
64
- return platform_;
65
- }
66
-
67
- inline AsyncHooks::AsyncHooks()
68
- : async_ids_stack_(env()->isolate(), 16 * 2),
69
- fields_(env()->isolate(), kFieldsCount),
70
- async_id_fields_(env()->isolate(), kUidFieldsCount) {
71
- clear_async_id_stack();
72
-
73
- // Always perform async_hooks checks, not just when async_hooks is enabled.
74
- // TODO(AndreasMadsen): Consider removing this for LTS releases.
75
- // See discussion in https://github.com/nodejs/node/pull/15454
76
- // When removing this, do it by reverting the commit. Otherwise the test
77
- // and flag changes won't be included.
78
- fields_[kCheck] = 1;
79
-
80
- // kDefaultTriggerAsyncId should be -1, this indicates that there is no
81
- // specified default value and it should fallback to the executionAsyncId.
82
- // 0 is not used as the magic value, because that indicates a missing context
83
- // which is different from a default context.
84
- async_id_fields_[AsyncHooks::kDefaultTriggerAsyncId] = -1;
85
-
86
- // kAsyncIdCounter should start at 1 because that'll be the id the execution
87
- // context during bootstrap (code that runs before entering uv_run()).
88
- async_id_fields_[AsyncHooks::kAsyncIdCounter] = 1;
89
-
90
- // Create all the provider strings that will be passed to JS. Place them in
91
- // an array so the array index matches the PROVIDER id offset. This way the
92
- // strings can be retrieved quickly.
93
- #define V(Provider) \
94
- providers_[AsyncWrap::PROVIDER_ ## Provider].Set( \
95
- env()->isolate(), \
96
- v8::String::NewFromOneByte( \
97
- env()->isolate(), \
98
- reinterpret_cast<const uint8_t*>(#Provider), \
99
- v8::NewStringType::kInternalized, \
100
- sizeof(#Provider) - 1).ToLocalChecked());
101
- NODE_ASYNC_PROVIDER_TYPES(V)
102
- #undef V
103
- }
104
- inline AliasedUint32Array& AsyncHooks::fields() {
105
- return fields_;
106
- }
107
-
108
- inline AliasedFloat64Array& AsyncHooks::async_id_fields() {
109
- return async_id_fields_;
110
- }
111
-
112
- inline AliasedFloat64Array& AsyncHooks::async_ids_stack() {
113
- return async_ids_stack_;
114
- }
115
-
116
- inline v8::Local<v8::Array> AsyncHooks::execution_async_resources() {
117
- return PersistentToLocal::Strong(execution_async_resources_);
118
- }
119
-
120
- inline v8::Local<v8::String> AsyncHooks::provider_string(int idx) {
121
- return providers_[idx].Get(env()->isolate());
122
- }
123
-
124
- inline void AsyncHooks::no_force_checks() {
125
- fields_[kCheck] -= 1;
126
- }
127
-
128
- inline Environment* AsyncHooks::env() {
129
- return Environment::ForAsyncHooks(this);
130
- }
131
-
132
- // Remember to keep this code aligned with pushAsyncContext() in JS.
133
- inline void AsyncHooks::push_async_context(double async_id,
134
- double trigger_async_id,
135
- v8::Local<v8::Value> resource) {
136
- v8::HandleScope handle_scope(env()->isolate());
137
-
138
- // Since async_hooks is experimental, do only perform the check
139
- // when async_hooks is enabled.
140
- if (fields_[kCheck] > 0) {
141
- CHECK_GE(async_id, -1);
142
- CHECK_GE(trigger_async_id, -1);
143
- }
144
-
145
- uint32_t offset = fields_[kStackLength];
146
- if (offset * 2 >= async_ids_stack_.Length())
147
- grow_async_ids_stack();
148
- async_ids_stack_[2 * offset] = async_id_fields_[kExecutionAsyncId];
149
- async_ids_stack_[2 * offset + 1] = async_id_fields_[kTriggerAsyncId];
150
- fields_[kStackLength] += 1;
151
- async_id_fields_[kExecutionAsyncId] = async_id;
152
- async_id_fields_[kTriggerAsyncId] = trigger_async_id;
153
-
154
- auto resources = execution_async_resources();
155
- USE(resources->Set(env()->context(), offset, resource));
156
- }
157
-
158
- // Remember to keep this code aligned with popAsyncContext() in JS.
159
- inline bool AsyncHooks::pop_async_context(double async_id) {
160
- // In case of an exception then this may have already been reset, if the
161
- // stack was multiple MakeCallback()'s deep.
162
- if (fields_[kStackLength] == 0) return false;
163
-
164
- // Ask for the async_id to be restored as a check that the stack
165
- // hasn't been corrupted.
166
- // Since async_hooks is experimental, do only perform the check
167
- // when async_hooks is enabled.
168
- if (fields_[kCheck] > 0 && async_id_fields_[kExecutionAsyncId] != async_id) {
169
- fprintf(stderr,
170
- "Error: async hook stack has become corrupted ("
171
- "actual: %.f, expected: %.f)\n",
172
- async_id_fields_.GetValue(kExecutionAsyncId),
173
- async_id);
174
- DumpBacktrace(stderr);
175
- fflush(stderr);
176
- if (!env()->abort_on_uncaught_exception())
177
- exit(1);
178
- fprintf(stderr, "\n");
179
- fflush(stderr);
180
- ABORT_NO_BACKTRACE();
181
- }
182
-
183
- uint32_t offset = fields_[kStackLength] - 1;
184
- async_id_fields_[kExecutionAsyncId] = async_ids_stack_[2 * offset];
185
- async_id_fields_[kTriggerAsyncId] = async_ids_stack_[2 * offset + 1];
186
- fields_[kStackLength] = offset;
187
-
188
- auto resources = execution_async_resources();
189
- USE(resources->Delete(env()->context(), offset));
190
-
191
- return fields_[kStackLength] > 0;
192
- }
193
-
194
- // Keep in sync with clearAsyncIdStack in lib/internal/async_hooks.js.
195
- inline void AsyncHooks::clear_async_id_stack() {
196
- auto isolate = env()->isolate();
197
- v8::HandleScope handle_scope(isolate);
198
- execution_async_resources_.Reset(isolate, v8::Array::New(isolate));
199
-
200
- async_id_fields_[kExecutionAsyncId] = 0;
201
- async_id_fields_[kTriggerAsyncId] = 0;
202
- fields_[kStackLength] = 0;
203
- }
204
-
205
- // The DefaultTriggerAsyncIdScope(AsyncWrap*) constructor is defined in
206
- // async_wrap-inl.h to avoid a circular dependency.
207
-
208
- inline AsyncHooks::DefaultTriggerAsyncIdScope ::DefaultTriggerAsyncIdScope(
209
- Environment* env, double default_trigger_async_id)
210
- : async_hooks_(env->async_hooks()) {
211
- if (env->async_hooks()->fields()[AsyncHooks::kCheck] > 0) {
212
- CHECK_GE(default_trigger_async_id, 0);
213
- }
214
-
215
- old_default_trigger_async_id_ =
216
- async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId];
217
- async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] =
218
- default_trigger_async_id;
219
- }
220
-
221
- inline AsyncHooks::DefaultTriggerAsyncIdScope ::~DefaultTriggerAsyncIdScope() {
222
- async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] =
223
- old_default_trigger_async_id_;
224
- }
225
-
226
- Environment* Environment::ForAsyncHooks(AsyncHooks* hooks) {
227
- return ContainerOf(&Environment::async_hooks_, hooks);
228
- }
229
-
230
- inline size_t Environment::async_callback_scope_depth() const {
231
- return async_callback_scope_depth_;
232
- }
233
-
234
- inline void Environment::PushAsyncCallbackScope() {
235
- async_callback_scope_depth_++;
236
- }
237
-
238
- inline void Environment::PopAsyncCallbackScope() {
239
- async_callback_scope_depth_--;
240
- }
241
-
242
- inline ImmediateInfo::ImmediateInfo(v8::Isolate* isolate)
243
- : fields_(isolate, kFieldsCount) {}
244
-
245
- inline AliasedUint32Array& ImmediateInfo::fields() {
246
- return fields_;
247
- }
248
-
249
- inline uint32_t ImmediateInfo::count() const {
250
- return fields_[kCount];
251
- }
252
-
253
- inline uint32_t ImmediateInfo::ref_count() const {
254
- return fields_[kRefCount];
255
- }
256
-
257
- inline bool ImmediateInfo::has_outstanding() const {
258
- return fields_[kHasOutstanding] == 1;
259
- }
260
-
261
- inline void ImmediateInfo::ref_count_inc(uint32_t increment) {
262
- fields_[kRefCount] += increment;
263
- }
264
-
265
- inline void ImmediateInfo::ref_count_dec(uint32_t decrement) {
266
- fields_[kRefCount] -= decrement;
267
- }
268
-
269
- inline TickInfo::TickInfo(v8::Isolate* isolate)
270
- : fields_(isolate, kFieldsCount) {}
271
-
272
- inline AliasedUint8Array& TickInfo::fields() {
273
- return fields_;
274
- }
275
-
276
- inline bool TickInfo::has_tick_scheduled() const {
277
- return fields_[kHasTickScheduled] == 1;
278
- }
279
-
280
- inline bool TickInfo::has_rejection_to_warn() const {
281
- return fields_[kHasRejectionToWarn] == 1;
282
- }
283
-
284
- inline void Environment::AssignToContext(v8::Local<v8::Context> context,
285
- const ContextInfo& info) {
286
- context->SetAlignedPointerInEmbedderData(
287
- ContextEmbedderIndex::kEnvironment, this);
288
- // Used by Environment::GetCurrent to know that we are on a node context.
289
- context->SetAlignedPointerInEmbedderData(
290
- ContextEmbedderIndex::kContextTag, Environment::kNodeContextTagPtr);
291
- #if HAVE_INSPECTOR
292
- inspector_agent()->ContextCreated(context, info);
293
- #endif // HAVE_INSPECTOR
294
- }
295
-
296
- inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
297
- if (UNLIKELY(!isolate->InContext())) return nullptr;
298
- v8::HandleScope handle_scope(isolate);
299
- return GetCurrent(isolate->GetCurrentContext());
300
- }
301
-
302
- inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) {
303
- if (UNLIKELY(context.IsEmpty())) {
304
- return nullptr;
305
- }
306
- if (UNLIKELY(context->GetNumberOfEmbedderDataFields() <=
307
- ContextEmbedderIndex::kContextTag)) {
308
- return nullptr;
309
- }
310
- if (UNLIKELY(context->GetAlignedPointerFromEmbedderData(
311
- ContextEmbedderIndex::kContextTag) !=
312
- Environment::kNodeContextTagPtr)) {
313
- return nullptr;
314
- }
315
- return static_cast<Environment*>(
316
- context->GetAlignedPointerFromEmbedderData(
317
- ContextEmbedderIndex::kEnvironment));
318
- }
319
-
320
- inline Environment* Environment::GetCurrent(
321
- const v8::FunctionCallbackInfo<v8::Value>& info) {
322
- return GetFromCallbackData(info.Data());
323
- }
324
-
325
- template <typename T>
326
- inline Environment* Environment::GetCurrent(
327
- const v8::PropertyCallbackInfo<T>& info) {
328
- return GetFromCallbackData(info.Data());
329
- }
330
-
331
- inline Environment* Environment::GetFromCallbackData(v8::Local<v8::Value> val) {
332
- DCHECK(val->IsObject());
333
- v8::Local<v8::Object> obj = val.As<v8::Object>();
334
- DCHECK_GE(obj->InternalFieldCount(), 1);
335
- Environment* env =
336
- static_cast<Environment*>(obj->GetAlignedPointerFromInternalField(0));
337
- DCHECK(env->as_callback_data_template()->HasInstance(obj));
338
- return env;
339
- }
340
-
341
- inline Environment* Environment::GetThreadLocalEnv() {
342
- return static_cast<Environment*>(uv_key_get(&thread_local_env));
343
- }
344
-
345
- inline bool Environment::profiler_idle_notifier_started() const {
346
- return profiler_idle_notifier_started_;
347
- }
348
-
349
- inline v8::Isolate* Environment::isolate() const {
350
- return isolate_;
351
- }
352
-
353
- inline Environment* Environment::from_timer_handle(uv_timer_t* handle) {
354
- return ContainerOf(&Environment::timer_handle_, handle);
355
- }
356
-
357
- inline uv_timer_t* Environment::timer_handle() {
358
- return &timer_handle_;
359
- }
360
-
361
- inline Environment* Environment::from_immediate_check_handle(
362
- uv_check_t* handle) {
363
- return ContainerOf(&Environment::immediate_check_handle_, handle);
364
- }
365
-
366
- inline uv_check_t* Environment::immediate_check_handle() {
367
- return &immediate_check_handle_;
368
- }
369
-
370
- inline uv_idle_t* Environment::immediate_idle_handle() {
371
- return &immediate_idle_handle_;
372
- }
373
-
374
- inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
375
- HandleCleanupCb cb,
376
- void* arg) {
377
- handle_cleanup_queue_.push_back(HandleCleanup{handle, cb, arg});
378
- }
379
-
380
- template <typename T, typename OnCloseCallback>
381
- inline void Environment::CloseHandle(T* handle, OnCloseCallback callback) {
382
- handle_cleanup_waiting_++;
383
- static_assert(sizeof(T) >= sizeof(uv_handle_t), "T is a libuv handle");
384
- static_assert(offsetof(T, data) == offsetof(uv_handle_t, data),
385
- "T is a libuv handle");
386
- static_assert(offsetof(T, close_cb) == offsetof(uv_handle_t, close_cb),
387
- "T is a libuv handle");
388
- struct CloseData {
389
- Environment* env;
390
- OnCloseCallback callback;
391
- void* original_data;
392
- };
393
- handle->data = new CloseData { this, callback, handle->data };
394
- uv_close(reinterpret_cast<uv_handle_t*>(handle), [](uv_handle_t* handle) {
395
- std::unique_ptr<CloseData> data { static_cast<CloseData*>(handle->data) };
396
- data->env->handle_cleanup_waiting_--;
397
- handle->data = data->original_data;
398
- data->callback(reinterpret_cast<T*>(handle));
399
- });
400
- }
401
-
402
- void Environment::IncreaseWaitingRequestCounter() {
403
- request_waiting_++;
404
- }
405
-
406
- void Environment::DecreaseWaitingRequestCounter() {
407
- request_waiting_--;
408
- CHECK_GE(request_waiting_, 0);
409
- }
410
-
411
- inline uv_loop_t* Environment::event_loop() const {
412
- return isolate_data()->event_loop();
413
- }
414
-
415
- inline void Environment::TryLoadAddon(
416
- const char* filename,
417
- int flags,
418
- const std::function<bool(binding::DLib*)>& was_loaded) {
419
- loaded_addons_.emplace_back(filename, flags);
420
- if (!was_loaded(&loaded_addons_.back())) {
421
- loaded_addons_.pop_back();
422
- }
423
- }
424
-
425
- #if HAVE_INSPECTOR
426
- inline bool Environment::is_in_inspector_console_call() const {
427
- return is_in_inspector_console_call_;
428
- }
429
-
430
- inline void Environment::set_is_in_inspector_console_call(bool value) {
431
- is_in_inspector_console_call_ = value;
432
- }
433
- #endif
434
-
435
- inline AsyncHooks* Environment::async_hooks() {
436
- return &async_hooks_;
437
- }
438
-
439
- inline ImmediateInfo* Environment::immediate_info() {
440
- return &immediate_info_;
441
- }
442
-
443
- inline TickInfo* Environment::tick_info() {
444
- return &tick_info_;
445
- }
446
-
447
- inline uint64_t Environment::timer_base() const {
448
- return timer_base_;
449
- }
450
-
451
- inline std::shared_ptr<KVStore> Environment::env_vars() {
452
- return env_vars_;
453
- }
454
-
455
- inline void Environment::set_env_vars(std::shared_ptr<KVStore> env_vars) {
456
- env_vars_ = env_vars;
457
- }
458
-
459
- inline bool Environment::printed_error() const {
460
- return printed_error_;
461
- }
462
-
463
- inline void Environment::set_printed_error(bool value) {
464
- printed_error_ = value;
465
- }
466
-
467
- inline void Environment::set_trace_sync_io(bool value) {
468
- trace_sync_io_ = value;
469
- }
470
-
471
- inline bool Environment::abort_on_uncaught_exception() const {
472
- return options_->abort_on_uncaught_exception;
473
- }
474
-
475
- inline void Environment::set_abort_on_uncaught_exception(bool value) {
476
- options_->abort_on_uncaught_exception = value;
477
- }
478
-
479
- inline AliasedUint32Array& Environment::should_abort_on_uncaught_toggle() {
480
- return should_abort_on_uncaught_toggle_;
481
- }
482
-
483
- inline AliasedInt32Array& Environment::stream_base_state() {
484
- return stream_base_state_;
485
- }
486
-
487
- inline uint32_t Environment::get_next_module_id() {
488
- return module_id_counter_++;
489
- }
490
- inline uint32_t Environment::get_next_script_id() {
491
- return script_id_counter_++;
492
- }
493
- inline uint32_t Environment::get_next_function_id() {
494
- return function_id_counter_++;
495
- }
496
-
497
- ShouldNotAbortOnUncaughtScope::ShouldNotAbortOnUncaughtScope(
498
- Environment* env)
499
- : env_(env) {
500
- env_->PushShouldNotAbortOnUncaughtScope();
501
- }
502
-
503
- ShouldNotAbortOnUncaughtScope::~ShouldNotAbortOnUncaughtScope() {
504
- Close();
505
- }
506
-
507
- void ShouldNotAbortOnUncaughtScope::Close() {
508
- if (env_ != nullptr) {
509
- env_->PopShouldNotAbortOnUncaughtScope();
510
- env_ = nullptr;
511
- }
512
- }
513
-
514
- inline void Environment::PushShouldNotAbortOnUncaughtScope() {
515
- should_not_abort_scope_counter_++;
516
- }
517
-
518
- inline void Environment::PopShouldNotAbortOnUncaughtScope() {
519
- should_not_abort_scope_counter_--;
520
- }
521
-
522
- inline bool Environment::inside_should_not_abort_on_uncaught_scope() const {
523
- return should_not_abort_scope_counter_ > 0;
524
- }
525
-
526
- inline std::vector<double>* Environment::destroy_async_id_list() {
527
- return &destroy_async_id_list_;
528
- }
529
-
530
- inline double Environment::new_async_id() {
531
- async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] += 1;
532
- return async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter];
533
- }
534
-
535
- inline double Environment::execution_async_id() {
536
- return async_hooks()->async_id_fields()[AsyncHooks::kExecutionAsyncId];
537
- }
538
-
539
- inline double Environment::trigger_async_id() {
540
- return async_hooks()->async_id_fields()[AsyncHooks::kTriggerAsyncId];
541
- }
542
-
543
- inline double Environment::get_default_trigger_async_id() {
544
- double default_trigger_async_id =
545
- async_hooks()->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId];
546
- // If defaultTriggerAsyncId isn't set, use the executionAsyncId
547
- if (default_trigger_async_id < 0)
548
- default_trigger_async_id = execution_async_id();
549
- return default_trigger_async_id;
550
- }
551
-
552
- inline double* Environment::heap_statistics_buffer() const {
553
- CHECK_NOT_NULL(heap_statistics_buffer_);
554
- return heap_statistics_buffer_;
555
- }
556
-
557
- inline void Environment::set_heap_statistics_buffer(double* pointer) {
558
- CHECK_NULL(heap_statistics_buffer_); // Should be set only once.
559
- heap_statistics_buffer_ = pointer;
560
- }
561
-
562
- inline double* Environment::heap_space_statistics_buffer() const {
563
- CHECK_NOT_NULL(heap_space_statistics_buffer_);
564
- return heap_space_statistics_buffer_;
565
- }
566
-
567
- inline void Environment::set_heap_space_statistics_buffer(double* pointer) {
568
- CHECK_NULL(heap_space_statistics_buffer_); // Should be set only once.
569
- heap_space_statistics_buffer_ = pointer;
570
- }
571
-
572
- inline double* Environment::heap_code_statistics_buffer() const {
573
- CHECK_NOT_NULL(heap_code_statistics_buffer_);
574
- return heap_code_statistics_buffer_;
575
- }
576
-
577
- inline void Environment::set_heap_code_statistics_buffer(double* pointer) {
578
- CHECK_NULL(heap_code_statistics_buffer_); // Should be set only once.
579
- heap_code_statistics_buffer_ = pointer;
580
- }
581
-
582
- inline char* Environment::http_parser_buffer() const {
583
- return http_parser_buffer_;
584
- }
585
-
586
- inline void Environment::set_http_parser_buffer(char* buffer) {
587
- CHECK_NULL(http_parser_buffer_); // Should be set only once.
588
- http_parser_buffer_ = buffer;
589
- }
590
-
591
- inline bool Environment::http_parser_buffer_in_use() const {
592
- return http_parser_buffer_in_use_;
593
- }
594
-
595
- inline void Environment::set_http_parser_buffer_in_use(bool in_use) {
596
- http_parser_buffer_in_use_ = in_use;
597
- }
598
-
599
- inline http2::Http2State* Environment::http2_state() const {
600
- return http2_state_.get();
601
- }
602
-
603
- inline void Environment::set_http2_state(
604
- std::unique_ptr<http2::Http2State> buffer) {
605
- CHECK(!http2_state_); // Should be set only once.
606
- http2_state_ = std::move(buffer);
607
- }
608
-
609
- inline AliasedFloat64Array* Environment::fs_stats_field_array() {
610
- return &fs_stats_field_array_;
611
- }
612
-
613
- inline AliasedBigUint64Array* Environment::fs_stats_field_bigint_array() {
614
- return &fs_stats_field_bigint_array_;
615
- }
616
-
617
- inline std::vector<std::unique_ptr<fs::FileHandleReadWrap>>&
618
- Environment::file_handle_read_wrap_freelist() {
619
- return file_handle_read_wrap_freelist_;
620
- }
621
-
622
- inline std::shared_ptr<EnvironmentOptions> Environment::options() {
623
- return options_;
624
- }
625
-
626
- inline const std::vector<std::string>& Environment::argv() {
627
- return argv_;
628
- }
629
-
630
- inline const std::vector<std::string>& Environment::exec_argv() {
631
- return exec_argv_;
632
- }
633
-
634
- inline const std::string& Environment::exec_path() const {
635
- return exec_path_;
636
- }
637
-
638
- #if HAVE_INSPECTOR
639
- inline void Environment::set_coverage_directory(const char* dir) {
640
- coverage_directory_ = std::string(dir);
641
- }
642
-
643
- inline void Environment::set_coverage_connection(
644
- std::unique_ptr<profiler::V8CoverageConnection> connection) {
645
- CHECK_NULL(coverage_connection_);
646
- std::swap(coverage_connection_, connection);
647
- }
648
-
649
- inline profiler::V8CoverageConnection* Environment::coverage_connection() {
650
- return coverage_connection_.get();
651
- }
652
-
653
- inline const std::string& Environment::coverage_directory() const {
654
- return coverage_directory_;
655
- }
656
-
657
- inline void Environment::set_cpu_profiler_connection(
658
- std::unique_ptr<profiler::V8CpuProfilerConnection> connection) {
659
- CHECK_NULL(cpu_profiler_connection_);
660
- std::swap(cpu_profiler_connection_, connection);
661
- }
662
-
663
- inline profiler::V8CpuProfilerConnection*
664
- Environment::cpu_profiler_connection() {
665
- return cpu_profiler_connection_.get();
666
- }
667
-
668
- inline void Environment::set_cpu_prof_interval(uint64_t interval) {
669
- cpu_prof_interval_ = interval;
670
- }
671
-
672
- inline uint64_t Environment::cpu_prof_interval() const {
673
- return cpu_prof_interval_;
674
- }
675
-
676
- inline void Environment::set_cpu_prof_name(const std::string& name) {
677
- cpu_prof_name_ = name;
678
- }
679
-
680
- inline const std::string& Environment::cpu_prof_name() const {
681
- return cpu_prof_name_;
682
- }
683
-
684
- inline void Environment::set_cpu_prof_dir(const std::string& dir) {
685
- cpu_prof_dir_ = dir;
686
- }
687
-
688
- inline const std::string& Environment::cpu_prof_dir() const {
689
- return cpu_prof_dir_;
690
- }
691
-
692
- inline void Environment::set_heap_profiler_connection(
693
- std::unique_ptr<profiler::V8HeapProfilerConnection> connection) {
694
- CHECK_NULL(heap_profiler_connection_);
695
- std::swap(heap_profiler_connection_, connection);
696
- }
697
-
698
- inline profiler::V8HeapProfilerConnection*
699
- Environment::heap_profiler_connection() {
700
- return heap_profiler_connection_.get();
701
- }
702
-
703
- inline void Environment::set_heap_prof_name(const std::string& name) {
704
- heap_prof_name_ = name;
705
- }
706
-
707
- inline const std::string& Environment::heap_prof_name() const {
708
- return heap_prof_name_;
709
- }
710
-
711
- inline void Environment::set_heap_prof_dir(const std::string& dir) {
712
- heap_prof_dir_ = dir;
713
- }
714
-
715
- inline const std::string& Environment::heap_prof_dir() const {
716
- return heap_prof_dir_;
717
- }
718
-
719
- inline void Environment::set_heap_prof_interval(uint64_t interval) {
720
- heap_prof_interval_ = interval;
721
- }
722
-
723
- inline uint64_t Environment::heap_prof_interval() const {
724
- return heap_prof_interval_;
725
- }
726
-
727
- #endif // HAVE_INSPECTOR
728
-
729
- inline
730
- std::shared_ptr<ExclusiveAccess<HostPort>> Environment::inspector_host_port() {
731
- return inspector_host_port_;
732
- }
733
-
734
- inline std::shared_ptr<PerIsolateOptions> IsolateData::options() {
735
- return options_;
736
- }
737
-
738
- inline void IsolateData::set_options(
739
- std::shared_ptr<PerIsolateOptions> options) {
740
- options_ = std::move(options);
741
- }
742
-
743
- std::unique_ptr<Environment::NativeImmediateCallback>
744
- Environment::NativeImmediateQueue::Shift() {
745
- std::unique_ptr<Environment::NativeImmediateCallback> ret = std::move(head_);
746
- if (ret) {
747
- head_ = ret->get_next();
748
- if (!head_)
749
- tail_ = nullptr; // The queue is now empty.
750
- }
751
- size_--;
752
- return ret;
753
- }
754
-
755
- void Environment::NativeImmediateQueue::Push(
756
- std::unique_ptr<Environment::NativeImmediateCallback> cb) {
757
- NativeImmediateCallback* prev_tail = tail_;
758
-
759
- size_++;
760
- tail_ = cb.get();
761
- if (prev_tail != nullptr)
762
- prev_tail->set_next(std::move(cb));
763
- else
764
- head_ = std::move(cb);
765
- }
766
-
767
- void Environment::NativeImmediateQueue::ConcatMove(
768
- NativeImmediateQueue&& other) {
769
- size_ += other.size_;
770
- if (tail_ != nullptr)
771
- tail_->set_next(std::move(other.head_));
772
- else
773
- head_ = std::move(other.head_);
774
- tail_ = other.tail_;
775
- other.tail_ = nullptr;
776
- other.size_ = 0;
777
- }
778
-
779
- size_t Environment::NativeImmediateQueue::size() const {
780
- return size_.load();
781
- }
782
-
783
- template <typename Fn>
784
- void Environment::CreateImmediate(Fn&& cb, bool ref) {
785
- auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>(
786
- std::move(cb), ref);
787
- native_immediates_.Push(std::move(callback));
788
- }
789
-
790
- template <typename Fn>
791
- void Environment::SetImmediate(Fn&& cb) {
792
- CreateImmediate(std::move(cb), true);
793
-
794
- if (immediate_info()->ref_count() == 0)
795
- ToggleImmediateRef(true);
796
- immediate_info()->ref_count_inc(1);
797
- }
798
-
799
- template <typename Fn>
800
- void Environment::SetUnrefImmediate(Fn&& cb) {
801
- CreateImmediate(std::move(cb), false);
802
- }
803
-
804
- template <typename Fn>
805
- void Environment::SetImmediateThreadsafe(Fn&& cb) {
806
- auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>(
807
- std::move(cb), false);
808
- {
809
- Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_);
810
- native_immediates_threadsafe_.Push(std::move(callback));
811
- }
812
- uv_async_send(&task_queues_async_);
813
- }
814
-
815
- template <typename Fn>
816
- void Environment::RequestInterrupt(Fn&& cb) {
817
- auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>(
818
- std::move(cb), false);
819
- {
820
- Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_);
821
- native_immediates_interrupts_.Push(std::move(callback));
822
- }
823
- uv_async_send(&task_queues_async_);
824
- RequestInterruptFromV8();
825
- }
826
-
827
- Environment::NativeImmediateCallback::NativeImmediateCallback(bool refed)
828
- : refed_(refed) {}
829
-
830
- bool Environment::NativeImmediateCallback::is_refed() const {
831
- return refed_;
832
- }
833
-
834
- std::unique_ptr<Environment::NativeImmediateCallback>
835
- Environment::NativeImmediateCallback::get_next() {
836
- return std::move(next_);
837
- }
838
-
839
- void Environment::NativeImmediateCallback::set_next(
840
- std::unique_ptr<NativeImmediateCallback> next) {
841
- next_ = std::move(next);
842
- }
843
-
844
- template <typename Fn>
845
- Environment::NativeImmediateCallbackImpl<Fn>::NativeImmediateCallbackImpl(
846
- Fn&& callback, bool refed)
847
- : NativeImmediateCallback(refed),
848
- callback_(std::move(callback)) {}
849
-
850
- template <typename Fn>
851
- void Environment::NativeImmediateCallbackImpl<Fn>::Call(Environment* env) {
852
- callback_(env);
853
- }
854
-
855
- inline bool Environment::can_call_into_js() const {
856
- return can_call_into_js_ && !is_stopping();
857
- }
858
-
859
- inline void Environment::set_can_call_into_js(bool can_call_into_js) {
860
- can_call_into_js_ = can_call_into_js;
861
- }
862
-
863
- inline bool Environment::has_run_bootstrapping_code() const {
864
- return has_run_bootstrapping_code_;
865
- }
866
-
867
- inline void Environment::set_has_run_bootstrapping_code(bool value) {
868
- has_run_bootstrapping_code_ = value;
869
- }
870
-
871
- inline bool Environment::has_serialized_options() const {
872
- return has_serialized_options_;
873
- }
874
-
875
- inline void Environment::set_has_serialized_options(bool value) {
876
- has_serialized_options_ = value;
877
- }
878
-
879
- inline bool Environment::is_main_thread() const {
880
- return flags_ & kIsMainThread;
881
- }
882
-
883
- inline bool Environment::owns_process_state() const {
884
- return flags_ & kOwnsProcessState;
885
- }
886
-
887
- inline bool Environment::owns_inspector() const {
888
- return flags_ & kOwnsInspector;
889
- }
890
-
891
- inline uint64_t Environment::thread_id() const {
892
- return thread_id_;
893
- }
894
-
895
- inline worker::Worker* Environment::worker_context() const {
896
- return worker_context_;
897
- }
898
-
899
- inline void Environment::set_worker_context(worker::Worker* context) {
900
- CHECK_NULL(worker_context_); // Should be set only once.
901
- worker_context_ = context;
902
- }
903
-
904
- inline void Environment::add_sub_worker_context(worker::Worker* context) {
905
- sub_worker_contexts_.insert(context);
906
- }
907
-
908
- inline void Environment::remove_sub_worker_context(worker::Worker* context) {
909
- sub_worker_contexts_.erase(context);
910
- }
911
-
912
- template <typename Fn>
913
- inline void Environment::ForEachWorker(Fn&& iterator) {
914
- for (worker::Worker* w : sub_worker_contexts_) iterator(w);
915
- }
916
-
917
- inline void Environment::add_refs(int64_t diff) {
918
- task_queues_async_refs_ += diff;
919
- CHECK_GE(task_queues_async_refs_, 0);
920
- if (task_queues_async_refs_ == 0)
921
- uv_unref(reinterpret_cast<uv_handle_t*>(&task_queues_async_));
922
- else
923
- uv_ref(reinterpret_cast<uv_handle_t*>(&task_queues_async_));
924
- }
925
-
926
- inline bool Environment::is_stopping() const {
927
- return is_stopping_.load();
928
- }
929
-
930
- inline void Environment::set_stopping(bool value) {
931
- is_stopping_.store(value);
932
- }
933
-
934
- inline std::list<node_module>* Environment::extra_linked_bindings() {
935
- return &extra_linked_bindings_;
936
- }
937
-
938
- inline node_module* Environment::extra_linked_bindings_head() {
939
- return extra_linked_bindings_.size() > 0 ?
940
- &extra_linked_bindings_.front() : nullptr;
941
- }
942
-
943
- inline const Mutex& Environment::extra_linked_bindings_mutex() const {
944
- return extra_linked_bindings_mutex_;
945
- }
946
-
947
- inline performance::PerformanceState* Environment::performance_state() {
948
- return performance_state_.get();
949
- }
950
-
951
- inline std::unordered_map<std::string, uint64_t>*
952
- Environment::performance_marks() {
953
- return &performance_marks_;
954
- }
955
-
956
- inline IsolateData* Environment::isolate_data() const {
957
- return isolate_data_;
958
- }
959
-
960
- inline char* Environment::AllocateUnchecked(size_t size) {
961
- return static_cast<char*>(
962
- isolate_data()->allocator()->AllocateUninitialized(size));
963
- }
964
-
965
- inline char* Environment::Allocate(size_t size) {
966
- char* ret = AllocateUnchecked(size);
967
- CHECK_NE(ret, nullptr);
968
- return ret;
969
- }
970
-
971
- inline void Environment::Free(char* data, size_t size) {
972
- if (data != nullptr)
973
- isolate_data()->allocator()->Free(data, size);
974
- }
975
-
976
- inline AllocatedBuffer Environment::AllocateManaged(size_t size, bool checked) {
977
- char* data = checked ? Allocate(size) : AllocateUnchecked(size);
978
- if (data == nullptr) size = 0;
979
- return AllocatedBuffer(this, uv_buf_init(data, size));
980
- }
981
-
982
- inline AllocatedBuffer::AllocatedBuffer(Environment* env, uv_buf_t buf)
983
- : env_(env), buffer_(buf) {}
984
-
985
- inline void AllocatedBuffer::Resize(size_t len) {
986
- // The `len` check is to make sure we don't end up with `nullptr` as our base.
987
- char* new_data = env_->Reallocate(buffer_.base, buffer_.len,
988
- len > 0 ? len : 1);
989
- CHECK_NOT_NULL(new_data);
990
- buffer_ = uv_buf_init(new_data, len);
991
- }
992
-
993
- inline uv_buf_t AllocatedBuffer::release() {
994
- uv_buf_t ret = buffer_;
995
- buffer_ = uv_buf_init(nullptr, 0);
996
- return ret;
997
- }
998
-
999
- inline char* AllocatedBuffer::data() {
1000
- return buffer_.base;
1001
- }
1002
-
1003
- inline const char* AllocatedBuffer::data() const {
1004
- return buffer_.base;
1005
- }
1006
-
1007
- inline size_t AllocatedBuffer::size() const {
1008
- return buffer_.len;
1009
- }
1010
-
1011
- inline AllocatedBuffer::AllocatedBuffer(Environment* env)
1012
- : env_(env), buffer_(uv_buf_init(nullptr, 0)) {}
1013
-
1014
- inline AllocatedBuffer::AllocatedBuffer(AllocatedBuffer&& other)
1015
- : AllocatedBuffer() {
1016
- *this = std::move(other);
1017
- }
1018
-
1019
- inline AllocatedBuffer& AllocatedBuffer::operator=(AllocatedBuffer&& other) {
1020
- clear();
1021
- env_ = other.env_;
1022
- buffer_ = other.release();
1023
- return *this;
1024
- }
1025
-
1026
- inline AllocatedBuffer::~AllocatedBuffer() {
1027
- clear();
1028
- }
1029
-
1030
- inline void AllocatedBuffer::clear() {
1031
- uv_buf_t buf = release();
1032
- if (buf.base != nullptr) {
1033
- CHECK_NOT_NULL(env_);
1034
- env_->Free(buf.base, buf.len);
1035
- }
1036
- }
1037
-
1038
- // It's a bit awkward to define this Buffer::New() overload here, but it
1039
- // avoids a circular dependency with node_internals.h.
1040
- namespace Buffer {
1041
- v8::MaybeLocal<v8::Object> New(Environment* env,
1042
- char* data,
1043
- size_t length,
1044
- bool uses_malloc);
1045
- }
1046
-
1047
- inline v8::MaybeLocal<v8::Object> AllocatedBuffer::ToBuffer() {
1048
- CHECK_NOT_NULL(env_);
1049
- v8::MaybeLocal<v8::Object> obj = Buffer::New(env_, data(), size(), false);
1050
- if (!obj.IsEmpty()) release();
1051
- return obj;
1052
- }
1053
-
1054
- inline v8::Local<v8::ArrayBuffer> AllocatedBuffer::ToArrayBuffer() {
1055
- CHECK_NOT_NULL(env_);
1056
- uv_buf_t buf = release();
1057
- return v8::ArrayBuffer::New(env_->isolate(),
1058
- buf.base,
1059
- buf.len,
1060
- v8::ArrayBufferCreationMode::kInternalized);
1061
- }
1062
-
1063
- inline void Environment::ThrowError(const char* errmsg) {
1064
- ThrowError(v8::Exception::Error, errmsg);
1065
- }
1066
-
1067
- inline void Environment::ThrowTypeError(const char* errmsg) {
1068
- ThrowError(v8::Exception::TypeError, errmsg);
1069
- }
1070
-
1071
- inline void Environment::ThrowRangeError(const char* errmsg) {
1072
- ThrowError(v8::Exception::RangeError, errmsg);
1073
- }
1074
-
1075
- inline void Environment::ThrowError(
1076
- v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
1077
- const char* errmsg) {
1078
- v8::HandleScope handle_scope(isolate());
1079
- isolate()->ThrowException(fun(OneByteString(isolate(), errmsg)));
1080
- }
1081
-
1082
- inline void Environment::ThrowErrnoException(int errorno,
1083
- const char* syscall,
1084
- const char* message,
1085
- const char* path) {
1086
- isolate()->ThrowException(
1087
- ErrnoException(isolate(), errorno, syscall, message, path));
1088
- }
1089
-
1090
- inline void Environment::ThrowUVException(int errorno,
1091
- const char* syscall,
1092
- const char* message,
1093
- const char* path,
1094
- const char* dest) {
1095
- isolate()->ThrowException(
1096
- UVException(isolate(), errorno, syscall, message, path, dest));
1097
- }
1098
-
1099
- inline v8::Local<v8::FunctionTemplate>
1100
- Environment::NewFunctionTemplate(v8::FunctionCallback callback,
1101
- v8::Local<v8::Signature> signature,
1102
- v8::ConstructorBehavior behavior,
1103
- v8::SideEffectType side_effect_type) {
1104
- v8::Local<v8::Object> external = as_callback_data();
1105
- return v8::FunctionTemplate::New(isolate(), callback, external,
1106
- signature, 0, behavior, side_effect_type);
1107
- }
1108
-
1109
- inline void Environment::SetMethod(v8::Local<v8::Object> that,
1110
- const char* name,
1111
- v8::FunctionCallback callback) {
1112
- v8::Local<v8::Context> context = isolate()->GetCurrentContext();
1113
- v8::Local<v8::Function> function =
1114
- NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
1115
- v8::ConstructorBehavior::kThrow,
1116
- v8::SideEffectType::kHasSideEffect)
1117
- ->GetFunction(context)
1118
- .ToLocalChecked();
1119
- // kInternalized strings are created in the old space.
1120
- const v8::NewStringType type = v8::NewStringType::kInternalized;
1121
- v8::Local<v8::String> name_string =
1122
- v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1123
- that->Set(context, name_string, function).Check();
1124
- function->SetName(name_string); // NODE_SET_METHOD() compatibility.
1125
- }
1126
-
1127
- inline void Environment::SetMethodNoSideEffect(v8::Local<v8::Object> that,
1128
- const char* name,
1129
- v8::FunctionCallback callback) {
1130
- v8::Local<v8::Context> context = isolate()->GetCurrentContext();
1131
- v8::Local<v8::Function> function =
1132
- NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
1133
- v8::ConstructorBehavior::kThrow,
1134
- v8::SideEffectType::kHasNoSideEffect)
1135
- ->GetFunction(context)
1136
- .ToLocalChecked();
1137
- // kInternalized strings are created in the old space.
1138
- const v8::NewStringType type = v8::NewStringType::kInternalized;
1139
- v8::Local<v8::String> name_string =
1140
- v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1141
- that->Set(context, name_string, function).Check();
1142
- function->SetName(name_string); // NODE_SET_METHOD() compatibility.
1143
- }
1144
-
1145
- inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
1146
- const char* name,
1147
- v8::FunctionCallback callback) {
1148
- v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
1149
- v8::Local<v8::FunctionTemplate> t =
1150
- NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow,
1151
- v8::SideEffectType::kHasSideEffect);
1152
- // kInternalized strings are created in the old space.
1153
- const v8::NewStringType type = v8::NewStringType::kInternalized;
1154
- v8::Local<v8::String> name_string =
1155
- v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1156
- that->PrototypeTemplate()->Set(name_string, t);
1157
- t->SetClassName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility.
1158
- }
1159
-
1160
- inline void Environment::SetProtoMethodNoSideEffect(
1161
- v8::Local<v8::FunctionTemplate> that,
1162
- const char* name,
1163
- v8::FunctionCallback callback) {
1164
- v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
1165
- v8::Local<v8::FunctionTemplate> t =
1166
- NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow,
1167
- v8::SideEffectType::kHasNoSideEffect);
1168
- // kInternalized strings are created in the old space.
1169
- const v8::NewStringType type = v8::NewStringType::kInternalized;
1170
- v8::Local<v8::String> name_string =
1171
- v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1172
- that->PrototypeTemplate()->Set(name_string, t);
1173
- t->SetClassName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility.
1174
- }
1175
-
1176
- inline void Environment::SetInstanceMethod(v8::Local<v8::FunctionTemplate> that,
1177
- const char* name,
1178
- v8::FunctionCallback callback) {
1179
- v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
1180
- v8::Local<v8::FunctionTemplate> t =
1181
- NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow,
1182
- v8::SideEffectType::kHasSideEffect);
1183
- // kInternalized strings are created in the old space.
1184
- const v8::NewStringType type = v8::NewStringType::kInternalized;
1185
- v8::Local<v8::String> name_string =
1186
- v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1187
- that->InstanceTemplate()->Set(name_string, t);
1188
- t->SetClassName(name_string);
1189
- }
1190
-
1191
- void Environment::AddCleanupHook(void (*fn)(void*), void* arg) {
1192
- auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback {
1193
- fn, arg, cleanup_hook_counter_++
1194
- });
1195
- // Make sure there was no existing element with these values.
1196
- CHECK_EQ(insertion_info.second, true);
1197
- }
1198
-
1199
- void Environment::RemoveCleanupHook(void (*fn)(void*), void* arg) {
1200
- CleanupHookCallback search { fn, arg, 0 };
1201
- cleanup_hooks_.erase(search);
1202
- }
1203
-
1204
- inline void Environment::RegisterFinalizationGroupForCleanup(
1205
- v8::Local<v8::FinalizationGroup> group) {
1206
- cleanup_finalization_groups_.emplace_back(isolate(), group);
1207
- uv_async_send(&task_queues_async_);
1208
- }
1209
-
1210
- size_t CleanupHookCallback::Hash::operator()(
1211
- const CleanupHookCallback& cb) const {
1212
- return std::hash<void*>()(cb.arg_);
1213
- }
1214
-
1215
- bool CleanupHookCallback::Equal::operator()(
1216
- const CleanupHookCallback& a, const CleanupHookCallback& b) const {
1217
- return a.fn_ == b.fn_ && a.arg_ == b.arg_;
1218
- }
1219
-
1220
- BaseObject* CleanupHookCallback::GetBaseObject() const {
1221
- if (fn_ == BaseObject::DeleteMe)
1222
- return static_cast<BaseObject*>(arg_);
1223
- else
1224
- return nullptr;
1225
- }
1226
-
1227
- template <typename T>
1228
- void Environment::ForEachBaseObject(T&& iterator) {
1229
- for (const auto& hook : cleanup_hooks_) {
1230
- BaseObject* obj = hook.GetBaseObject();
1231
- if (obj != nullptr)
1232
- iterator(obj);
1233
- }
1234
- }
1235
-
1236
- void Environment::modify_base_object_count(int64_t delta) {
1237
- base_object_count_ += delta;
1238
- }
1239
-
1240
- int64_t Environment::base_object_count() const {
1241
- return base_object_count_;
1242
- }
1243
-
1244
- #define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
1245
- #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
1246
- #define VS(PropertyName, StringValue) V(v8::String, PropertyName)
1247
- #define V(TypeName, PropertyName) \
1248
- inline \
1249
- v8::Local<TypeName> IsolateData::PropertyName() const { \
1250
- return PropertyName ## _ .Get(isolate_); \
1251
- }
1252
- PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
1253
- PER_ISOLATE_SYMBOL_PROPERTIES(VY)
1254
- PER_ISOLATE_STRING_PROPERTIES(VS)
1255
- #undef V
1256
- #undef VS
1257
- #undef VY
1258
- #undef VP
1259
-
1260
- #define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
1261
- #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
1262
- #define VS(PropertyName, StringValue) V(v8::String, PropertyName)
1263
- #define V(TypeName, PropertyName) \
1264
- inline v8::Local<TypeName> Environment::PropertyName() const { \
1265
- return isolate_data()->PropertyName(); \
1266
- }
1267
- PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
1268
- PER_ISOLATE_SYMBOL_PROPERTIES(VY)
1269
- PER_ISOLATE_STRING_PROPERTIES(VS)
1270
- #undef V
1271
- #undef VS
1272
- #undef VY
1273
- #undef VP
1274
-
1275
- #define V(PropertyName, TypeName) \
1276
- inline v8::Local<TypeName> Environment::PropertyName() const { \
1277
- return PersistentToLocal::Strong(PropertyName ## _); \
1278
- } \
1279
- inline void Environment::set_ ## PropertyName(v8::Local<TypeName> value) { \
1280
- PropertyName ## _.Reset(isolate(), value); \
1281
- }
1282
- ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V)
1283
- ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)
1284
- #undef V
1285
-
1286
- inline v8::Local<v8::Context> Environment::context() const {
1287
- return PersistentToLocal::Strong(context_);
1288
- }
1289
- } // namespace node
1290
-
1291
- #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
1292
-
1293
- #endif // SRC_ENV_INL_H_