@kungfu-tech/libnode-win32-x64 0.0.0-bootstrap.0 → 22.22.3-kf.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +3 -0
  3. package/dist/node/include/acorn_version.h +6 -0
  4. package/dist/node/include/aliased_buffer-inl.h +244 -0
  5. package/dist/node/include/aliased_buffer.h +206 -0
  6. package/dist/node/include/aliased_struct-inl.h +54 -0
  7. package/dist/node/include/aliased_struct.h +63 -0
  8. package/dist/node/include/amaro_version.h +6 -0
  9. package/dist/node/include/async_context_frame.h +33 -0
  10. package/dist/node/include/async_wrap-inl.h +96 -0
  11. package/dist/node/include/async_wrap.h +243 -0
  12. package/dist/node/include/base_object-inl.h +335 -0
  13. package/dist/node/include/base_object.h +342 -0
  14. package/dist/node/include/base_object_types.h +74 -0
  15. package/dist/node/include/blob_serializer_deserializer-inl.h +385 -0
  16. package/dist/node/include/blob_serializer_deserializer.h +132 -0
  17. package/dist/node/include/callback_queue-inl.h +97 -0
  18. package/dist/node/include/callback_queue.h +79 -0
  19. package/dist/node/include/cares_wrap.h +447 -0
  20. package/dist/node/include/cjs_module_lexer_version.h +6 -0
  21. package/dist/node/include/cleanup_queue-inl.h +36 -0
  22. package/dist/node/include/cleanup_queue.h +79 -0
  23. package/dist/node/include/compile_cache.h +104 -0
  24. package/dist/node/include/connect_wrap.h +26 -0
  25. package/dist/node/include/connection_wrap.h +30 -0
  26. package/dist/node/include/cppgc/allocation.h +310 -0
  27. package/dist/node/include/cppgc/common.h +28 -0
  28. package/dist/node/include/cppgc/cross-thread-persistent.h +466 -0
  29. package/dist/node/include/cppgc/custom-space.h +97 -0
  30. package/dist/node/include/cppgc/default-platform.h +67 -0
  31. package/dist/node/include/cppgc/ephemeron-pair.h +30 -0
  32. package/dist/node/include/cppgc/explicit-management.h +100 -0
  33. package/dist/node/include/cppgc/garbage-collected.h +106 -0
  34. package/dist/node/include/cppgc/heap-consistency.h +309 -0
  35. package/dist/node/include/cppgc/heap-handle.h +48 -0
  36. package/dist/node/include/cppgc/heap-state.h +82 -0
  37. package/dist/node/include/cppgc/heap-statistics.h +120 -0
  38. package/dist/node/include/cppgc/heap.h +202 -0
  39. package/dist/node/include/cppgc/internal/api-constants.h +87 -0
  40. package/dist/node/include/cppgc/internal/atomic-entry-flag.h +48 -0
  41. package/dist/node/include/cppgc/internal/base-page-handle.h +45 -0
  42. package/dist/node/include/cppgc/internal/caged-heap-local-data.h +121 -0
  43. package/dist/node/include/cppgc/internal/caged-heap.h +68 -0
  44. package/dist/node/include/cppgc/internal/compiler-specific.h +38 -0
  45. package/dist/node/include/cppgc/internal/finalizer-trait.h +93 -0
  46. package/dist/node/include/cppgc/internal/gc-info.h +148 -0
  47. package/dist/node/include/cppgc/internal/logging.h +50 -0
  48. package/dist/node/include/cppgc/internal/member-storage.h +256 -0
  49. package/dist/node/include/cppgc/internal/name-trait.h +137 -0
  50. package/dist/node/include/cppgc/internal/persistent-node.h +214 -0
  51. package/dist/node/include/cppgc/internal/pointer-policies.h +243 -0
  52. package/dist/node/include/cppgc/internal/write-barrier.h +487 -0
  53. package/dist/node/include/cppgc/liveness-broker.h +78 -0
  54. package/dist/node/include/cppgc/macros.h +35 -0
  55. package/dist/node/include/cppgc/member.h +629 -0
  56. package/dist/node/include/cppgc/name-provider.h +65 -0
  57. package/dist/node/include/cppgc/object-size-trait.h +58 -0
  58. package/dist/node/include/cppgc/persistent.h +377 -0
  59. package/dist/node/include/cppgc/platform.h +163 -0
  60. package/dist/node/include/cppgc/prefinalizer.h +75 -0
  61. package/dist/node/include/cppgc/process-heap-statistics.h +36 -0
  62. package/dist/node/include/cppgc/sentinel-pointer.h +39 -0
  63. package/dist/node/include/cppgc/source-location.h +16 -0
  64. package/dist/node/include/cppgc/testing.h +106 -0
  65. package/dist/node/include/cppgc/trace-trait.h +128 -0
  66. package/dist/node/include/cppgc/type-traits.h +271 -0
  67. package/dist/node/include/cppgc/visitor.h +504 -0
  68. package/dist/node/include/crypto/crypto_aes.h +88 -0
  69. package/dist/node/include/crypto/crypto_bio.h +193 -0
  70. package/dist/node/include/crypto/crypto_cipher.h +293 -0
  71. package/dist/node/include/crypto/crypto_clienthello-inl.h +90 -0
  72. package/dist/node/include/crypto/crypto_clienthello.h +131 -0
  73. package/dist/node/include/crypto/crypto_common.h +64 -0
  74. package/dist/node/include/crypto/crypto_context.h +171 -0
  75. package/dist/node/include/crypto/crypto_dh.h +126 -0
  76. package/dist/node/include/crypto/crypto_dsa.h +52 -0
  77. package/dist/node/include/crypto/crypto_ec.h +164 -0
  78. package/dist/node/include/crypto/crypto_hash.h +91 -0
  79. package/dist/node/include/crypto/crypto_hkdf.h +61 -0
  80. package/dist/node/include/crypto/crypto_hmac.h +92 -0
  81. package/dist/node/include/crypto/crypto_keygen.h +299 -0
  82. package/dist/node/include/crypto/crypto_keys.h +392 -0
  83. package/dist/node/include/crypto/crypto_pbkdf2.h +74 -0
  84. package/dist/node/include/crypto/crypto_random.h +124 -0
  85. package/dist/node/include/crypto/crypto_rsa.h +136 -0
  86. package/dist/node/include/crypto/crypto_scrypt.h +85 -0
  87. package/dist/node/include/crypto/crypto_sig.h +165 -0
  88. package/dist/node/include/crypto/crypto_spkac.h +21 -0
  89. package/dist/node/include/crypto/crypto_timing.h +20 -0
  90. package/dist/node/include/crypto/crypto_tls.h +305 -0
  91. package/dist/node/include/crypto/crypto_util.h +725 -0
  92. package/dist/node/include/crypto/crypto_x509.h +140 -0
  93. package/dist/node/include/dataqueue/queue.h +306 -0
  94. package/dist/node/include/debug_utils-inl.h +278 -0
  95. package/dist/node/include/debug_utils.h +196 -0
  96. package/dist/node/include/diagnosticfilename-inl.h +33 -0
  97. package/dist/node/include/embedded_data.h +17 -0
  98. package/dist/node/include/encoding_binding.h +61 -0
  99. package/dist/node/include/env-inl.h +984 -0
  100. package/dist/node/include/env.h +1287 -0
  101. package/dist/node/include/env_properties.h +540 -0
  102. package/dist/node/include/handle_wrap.h +123 -0
  103. package/dist/node/include/histogram-inl.h +107 -0
  104. package/dist/node/include/histogram.h +279 -0
  105. package/dist/node/include/inspector/io_agent.h +30 -0
  106. package/dist/node/include/inspector/main_thread_interface.h +116 -0
  107. package/dist/node/include/inspector/network_agent.h +94 -0
  108. package/dist/node/include/inspector/network_inspector.h +45 -0
  109. package/dist/node/include/inspector/network_requests_buffer.h +195 -0
  110. package/dist/node/include/inspector/network_resource_manager.h +29 -0
  111. package/dist/node/include/inspector/node_json.h +24 -0
  112. package/dist/node/include/inspector/node_string.h +101 -0
  113. package/dist/node/include/inspector/protocol_helper.h +27 -0
  114. package/dist/node/include/inspector/runtime_agent.h +41 -0
  115. package/dist/node/include/inspector/target_agent.h +75 -0
  116. package/dist/node/include/inspector/tracing_agent.h +43 -0
  117. package/dist/node/include/inspector/worker_agent.h +40 -0
  118. package/dist/node/include/inspector/worker_inspector.h +124 -0
  119. package/dist/node/include/inspector_agent.h +165 -0
  120. package/dist/node/include/inspector_io.h +78 -0
  121. package/dist/node/include/inspector_profiler.h +149 -0
  122. package/dist/node/include/inspector_socket.h +60 -0
  123. package/dist/node/include/inspector_socket_server.h +110 -0
  124. package/dist/node/include/js_native_api.h +607 -0
  125. package/dist/node/include/js_native_api_types.h +226 -0
  126. package/dist/node/include/js_native_api_v8.h +485 -0
  127. package/dist/node/include/js_native_api_v8_internals.h +45 -0
  128. package/dist/node/include/js_stream.h +52 -0
  129. package/dist/node/include/json_utils.h +172 -0
  130. package/dist/node/include/large_pages/node_large_page.h +34 -0
  131. package/dist/node/include/libplatform/libplatform-export.h +29 -0
  132. package/dist/node/include/libplatform/libplatform.h +112 -0
  133. package/dist/node/include/libplatform/v8-tracing.h +333 -0
  134. package/dist/node/include/memory_tracker-inl.h +359 -0
  135. package/dist/node/include/memory_tracker.h +289 -0
  136. package/dist/node/include/module_wrap.h +216 -0
  137. package/dist/node/include/node.h +1593 -0
  138. package/dist/node/include/node_api.h +265 -0
  139. package/dist/node/include/node_api_internals.h +48 -0
  140. package/dist/node/include/node_api_types.h +56 -0
  141. package/dist/node/include/node_binding.h +161 -0
  142. package/dist/node/include/node_blob.h +159 -0
  143. package/dist/node/include/node_bob-inl.h +36 -0
  144. package/dist/node/include/node_bob.h +107 -0
  145. package/dist/node/include/node_buffer.h +92 -0
  146. package/dist/node/include/node_builtins.h +220 -0
  147. package/dist/node/include/node_config_file.h +46 -0
  148. package/dist/node/include/node_constants.h +82 -0
  149. package/dist/node/include/node_context_data.h +168 -0
  150. package/dist/node/include/node_contextify.h +204 -0
  151. package/dist/node/include/node_crypto.h +56 -0
  152. package/dist/node/include/node_debug.h +30 -0
  153. package/dist/node/include/node_dir.h +52 -0
  154. package/dist/node/include/node_dotenv.h +45 -0
  155. package/dist/node/include/node_errors.h +380 -0
  156. package/dist/node/include/node_exit_code.h +54 -0
  157. package/dist/node/include/node_external_reference.h +165 -0
  158. package/dist/node/include/node_file-inl.h +406 -0
  159. package/dist/node/include/node_file.h +537 -0
  160. package/dist/node/include/node_http2.h +1177 -0
  161. package/dist/node/include/node_http2_state.h +159 -0
  162. package/dist/node/include/node_http_common-inl.h +202 -0
  163. package/dist/node/include/node_http_common.h +535 -0
  164. package/dist/node/include/node_i18n.h +132 -0
  165. package/dist/node/include/node_internals.h +483 -0
  166. package/dist/node/include/node_main_instance.h +67 -0
  167. package/dist/node/include/node_mem-inl.h +113 -0
  168. package/dist/node/include/node_mem.h +45 -0
  169. package/dist/node/include/node_messaging.h +389 -0
  170. package/dist/node/include/node_metadata.h +164 -0
  171. package/dist/node/include/node_modules.h +91 -0
  172. package/dist/node/include/node_mutex.h +323 -0
  173. package/dist/node/include/node_object_wrap.h +132 -0
  174. package/dist/node/include/node_options-inl.h +490 -0
  175. package/dist/node/include/node_options.h +615 -0
  176. package/dist/node/include/node_perf.h +166 -0
  177. package/dist/node/include/node_perf_common.h +102 -0
  178. package/dist/node/include/node_platform.h +238 -0
  179. package/dist/node/include/node_process-inl.h +26 -0
  180. package/dist/node/include/node_process.h +112 -0
  181. package/dist/node/include/node_realm-inl.h +151 -0
  182. package/dist/node/include/node_realm.h +183 -0
  183. package/dist/node/include/node_report.h +43 -0
  184. package/dist/node/include/node_revert.h +82 -0
  185. package/dist/node/include/node_root_certs.h +3520 -0
  186. package/dist/node/include/node_sea.h +74 -0
  187. package/dist/node/include/node_shadow_realm.h +46 -0
  188. package/dist/node/include/node_snapshot_builder.h +57 -0
  189. package/dist/node/include/node_snapshotable.h +174 -0
  190. package/dist/node/include/node_sockaddr-inl.h +257 -0
  191. package/dist/node/include/node_sockaddr.h +394 -0
  192. package/dist/node/include/node_sqlite.h +270 -0
  193. package/dist/node/include/node_stat_watcher.h +73 -0
  194. package/dist/node/include/node_task_runner.h +92 -0
  195. package/dist/node/include/node_threadsafe_cow-inl.h +54 -0
  196. package/dist/node/include/node_threadsafe_cow.h +105 -0
  197. package/dist/node/include/node_union_bytes.h +81 -0
  198. package/dist/node/include/node_url.h +96 -0
  199. package/dist/node/include/node_v8.h +77 -0
  200. package/dist/node/include/node_v8_platform-inl.h +185 -0
  201. package/dist/node/include/node_version.h +110 -0
  202. package/dist/node/include/node_wasi.h +184 -0
  203. package/dist/node/include/node_wasm_web_api.h +55 -0
  204. package/dist/node/include/node_watchdog.h +154 -0
  205. package/dist/node/include/node_webstorage.h +60 -0
  206. package/dist/node/include/node_worker.h +158 -0
  207. package/dist/node/include/path.h +33 -0
  208. package/dist/node/include/permission/addon_permission.h +31 -0
  209. package/dist/node/include/permission/child_process_permission.h +31 -0
  210. package/dist/node/include/permission/fs_permission.h +167 -0
  211. package/dist/node/include/permission/inspector_permission.h +31 -0
  212. package/dist/node/include/permission/permission.h +138 -0
  213. package/dist/node/include/permission/permission_base.h +65 -0
  214. package/dist/node/include/permission/wasi_permission.h +31 -0
  215. package/dist/node/include/permission/worker_permission.h +31 -0
  216. package/dist/node/include/pipe_wrap.h +80 -0
  217. package/dist/node/include/quic/application.h +159 -0
  218. package/dist/node/include/quic/bindingdata.h +272 -0
  219. package/dist/node/include/quic/cid.h +127 -0
  220. package/dist/node/include/quic/data.h +148 -0
  221. package/dist/node/include/quic/defs.h +245 -0
  222. package/dist/node/include/quic/endpoint.h +458 -0
  223. package/dist/node/include/quic/http3.h +15 -0
  224. package/dist/node/include/quic/logstream.h +81 -0
  225. package/dist/node/include/quic/packet.h +152 -0
  226. package/dist/node/include/quic/preferredaddress.h +72 -0
  227. package/dist/node/include/quic/session.h +443 -0
  228. package/dist/node/include/quic/sessionticket.h +108 -0
  229. package/dist/node/include/quic/streams.h +232 -0
  230. package/dist/node/include/quic/tlscontext.h +227 -0
  231. package/dist/node/include/quic/tokens.h +256 -0
  232. package/dist/node/include/quic/transportparams.h +165 -0
  233. package/dist/node/include/req_wrap-inl.h +171 -0
  234. package/dist/node/include/req_wrap.h +77 -0
  235. package/dist/node/include/spawn_sync.h +243 -0
  236. package/dist/node/include/stream_base-inl.h +173 -0
  237. package/dist/node/include/stream_base.h +478 -0
  238. package/dist/node/include/stream_pipe.h +76 -0
  239. package/dist/node/include/stream_wrap.h +132 -0
  240. package/dist/node/include/string_bytes.h +113 -0
  241. package/dist/node/include/string_decoder-inl.h +31 -0
  242. package/dist/node/include/string_decoder.h +49 -0
  243. package/dist/node/include/tcp_wrap.h +105 -0
  244. package/dist/node/include/threadpoolwork-inl.h +70 -0
  245. package/dist/node/include/timer_wrap-inl.h +32 -0
  246. package/dist/node/include/timer_wrap.h +85 -0
  247. package/dist/node/include/timers.h +70 -0
  248. package/dist/node/include/tracing/agent.h +195 -0
  249. package/dist/node/include/tracing/node_trace_buffer.h +83 -0
  250. package/dist/node/include/tracing/node_trace_writer.h +75 -0
  251. package/dist/node/include/tracing/trace_event.h +722 -0
  252. package/dist/node/include/tracing/trace_event_common.h +1109 -0
  253. package/dist/node/include/tracing/traced_value.h +129 -0
  254. package/dist/node/include/tty_wrap.h +65 -0
  255. package/dist/node/include/udp_wrap.h +230 -0
  256. package/dist/node/include/undici_version.h +6 -0
  257. package/dist/node/include/util-inl.h +700 -0
  258. package/dist/node/include/util.h +1021 -0
  259. package/dist/node/include/uv/aix.h +32 -0
  260. package/dist/node/include/uv/bsd.h +34 -0
  261. package/dist/node/include/uv/darwin.h +61 -0
  262. package/dist/node/include/uv/errno.h +483 -0
  263. package/dist/node/include/uv/linux.h +34 -0
  264. package/dist/node/include/uv/os390.h +33 -0
  265. package/dist/node/include/uv/posix.h +31 -0
  266. package/dist/node/include/uv/sunos.h +44 -0
  267. package/dist/node/include/uv/threadpool.h +37 -0
  268. package/dist/node/include/uv/tree.h +521 -0
  269. package/dist/node/include/uv/unix.h +512 -0
  270. package/dist/node/include/uv/version.h +43 -0
  271. package/dist/node/include/uv/win.h +698 -0
  272. package/dist/node/include/uv.h +1990 -0
  273. package/dist/node/include/v8-array-buffer.h +525 -0
  274. package/dist/node/include/v8-callbacks.h +462 -0
  275. package/dist/node/include/v8-container.h +183 -0
  276. package/dist/node/include/v8-context.h +485 -0
  277. package/dist/node/include/v8-cppgc.h +245 -0
  278. package/dist/node/include/v8-data.h +80 -0
  279. package/dist/node/include/v8-date.h +48 -0
  280. package/dist/node/include/v8-debug.h +168 -0
  281. package/dist/node/include/v8-embedder-heap.h +82 -0
  282. package/dist/node/include/v8-embedder-state-scope.h +52 -0
  283. package/dist/node/include/v8-exception.h +223 -0
  284. package/dist/node/include/v8-extension.h +62 -0
  285. package/dist/node/include/v8-external.h +37 -0
  286. package/dist/node/include/v8-fast-api-calls.h +984 -0
  287. package/dist/node/include/v8-forward.h +82 -0
  288. package/dist/node/include/v8-function-callback.h +607 -0
  289. package/dist/node/include/v8-function.h +140 -0
  290. package/dist/node/include/v8-handle-base.h +137 -0
  291. package/dist/node/include/v8-initialization.h +289 -0
  292. package/dist/node/include/v8-inspector-protocol.h +13 -0
  293. package/dist/node/include/v8-inspector.h +419 -0
  294. package/dist/node/include/v8-internal.h +1397 -0
  295. package/dist/node/include/v8-isolate.h +1767 -0
  296. package/dist/node/include/v8-json.h +47 -0
  297. package/dist/node/include/v8-local-handle.h +758 -0
  298. package/dist/node/include/v8-locker.h +138 -0
  299. package/dist/node/include/v8-maybe.h +160 -0
  300. package/dist/node/include/v8-memory-span.h +198 -0
  301. package/dist/node/include/v8-message.h +233 -0
  302. package/dist/node/include/v8-metrics.h +264 -0
  303. package/dist/node/include/v8-microtask-queue.h +157 -0
  304. package/dist/node/include/v8-microtask.h +28 -0
  305. package/dist/node/include/v8-object.h +824 -0
  306. package/dist/node/include/v8-persistent-handle.h +582 -0
  307. package/dist/node/include/v8-platform.h +1358 -0
  308. package/dist/node/include/v8-primitive-object.h +118 -0
  309. package/dist/node/include/v8-primitive.h +877 -0
  310. package/dist/node/include/v8-profiler.h +1302 -0
  311. package/dist/node/include/v8-promise.h +174 -0
  312. package/dist/node/include/v8-proxy.h +50 -0
  313. package/dist/node/include/v8-regexp.h +106 -0
  314. package/dist/node/include/v8-script.h +904 -0
  315. package/dist/node/include/v8-snapshot.h +266 -0
  316. package/dist/node/include/v8-source-location.h +92 -0
  317. package/dist/node/include/v8-statistics.h +238 -0
  318. package/dist/node/include/v8-template.h +1297 -0
  319. package/dist/node/include/v8-traced-handle.h +432 -0
  320. package/dist/node/include/v8-typed-array.h +390 -0
  321. package/dist/node/include/v8-unwinder-state.h +31 -0
  322. package/dist/node/include/v8-unwinder.h +132 -0
  323. package/dist/node/include/v8-util.h +665 -0
  324. package/dist/node/include/v8-value-serializer-version.h +24 -0
  325. package/dist/node/include/v8-value-serializer.h +316 -0
  326. package/dist/node/include/v8-value.h +655 -0
  327. package/dist/node/include/v8-version-string.h +38 -0
  328. package/dist/node/include/v8-version.h +20 -0
  329. package/dist/node/include/v8-wasm-trap-handler-posix.h +31 -0
  330. package/dist/node/include/v8-wasm-trap-handler-win.h +28 -0
  331. package/dist/node/include/v8-wasm.h +201 -0
  332. package/dist/node/include/v8-weak-callback-info.h +80 -0
  333. package/dist/node/include/v8.h +88 -0
  334. package/dist/node/include/v8config.h +981 -0
  335. package/dist/node/include/zlib_version.h +6 -0
  336. package/dist/node/libnode.dll +0 -0
  337. package/dist/node/libnode.lib +0 -0
  338. package/dist/node/libnodebuildinfo.json +10 -0
  339. package/dist/node/link_node.lib +0 -0
  340. package/dist/node/link_node.node +0 -0
  341. package/index.js +5 -0
  342. package/libnode.release.json +8 -0
  343. package/package.json +29 -1
@@ -0,0 +1,138 @@
1
+ // Copyright 2021 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_V8_LOCKER_H_
6
+ #define INCLUDE_V8_LOCKER_H_
7
+
8
+ #include "v8config.h" // NOLINT(build/include_directory)
9
+
10
+ namespace v8 {
11
+
12
+ namespace internal {
13
+ class Isolate;
14
+ } // namespace internal
15
+
16
+ class Isolate;
17
+
18
+ /**
19
+ * Multiple threads in V8 are allowed, but only one thread at a time is allowed
20
+ * to use any given V8 isolate, see the comments in the Isolate class. The
21
+ * definition of 'using a V8 isolate' includes accessing handles or holding onto
22
+ * object pointers obtained from V8 handles while in the particular V8 isolate.
23
+ * It is up to the user of V8 to ensure, perhaps with locking, that this
24
+ * constraint is not violated. In addition to any other synchronization
25
+ * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be
26
+ * used to signal thread switches to V8.
27
+ *
28
+ * v8::Locker is a scoped lock object. While it's active, i.e. between its
29
+ * construction and destruction, the current thread is allowed to use the locked
30
+ * isolate. V8 guarantees that an isolate can be locked by at most one thread at
31
+ * any time. In other words, the scope of a v8::Locker is a critical section.
32
+ *
33
+ * Sample usage:
34
+ * \code
35
+ * ...
36
+ * {
37
+ * v8::Locker locker(isolate);
38
+ * v8::Isolate::Scope isolate_scope(isolate);
39
+ * ...
40
+ * // Code using V8 and isolate goes here.
41
+ * ...
42
+ * } // Destructor called here
43
+ * \endcode
44
+ *
45
+ * If you wish to stop using V8 in a thread A you can do this either by
46
+ * destroying the v8::Locker object as above or by constructing a v8::Unlocker
47
+ * object:
48
+ *
49
+ * \code
50
+ * {
51
+ * isolate->Exit();
52
+ * v8::Unlocker unlocker(isolate);
53
+ * ...
54
+ * // Code not using V8 goes here while V8 can run in another thread.
55
+ * ...
56
+ * } // Destructor called here.
57
+ * isolate->Enter();
58
+ * \endcode
59
+ *
60
+ * The Unlocker object is intended for use in a long-running callback from V8,
61
+ * where you want to release the V8 lock for other threads to use.
62
+ *
63
+ * The v8::Locker is a recursive lock, i.e. you can lock more than once in a
64
+ * given thread. This can be useful if you have code that can be called either
65
+ * from code that holds the lock or from code that does not. The Unlocker is
66
+ * not recursive so you can not have several Unlockers on the stack at once, and
67
+ * you cannot use an Unlocker in a thread that is not inside a Locker's scope.
68
+ *
69
+ * An unlocker will unlock several lockers if it has to and reinstate the
70
+ * correct depth of locking on its destruction, e.g.:
71
+ *
72
+ * \code
73
+ * // V8 not locked.
74
+ * {
75
+ * v8::Locker locker(isolate);
76
+ * Isolate::Scope isolate_scope(isolate);
77
+ * // V8 locked.
78
+ * {
79
+ * v8::Locker another_locker(isolate);
80
+ * // V8 still locked (2 levels).
81
+ * {
82
+ * isolate->Exit();
83
+ * v8::Unlocker unlocker(isolate);
84
+ * // V8 not locked.
85
+ * }
86
+ * isolate->Enter();
87
+ * // V8 locked again (2 levels).
88
+ * }
89
+ * // V8 still locked (1 level).
90
+ * }
91
+ * // V8 Now no longer locked.
92
+ * \endcode
93
+ */
94
+ class V8_EXPORT Unlocker {
95
+ public:
96
+ /**
97
+ * Initialize Unlocker for a given Isolate.
98
+ */
99
+ V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
100
+
101
+ ~Unlocker();
102
+
103
+ private:
104
+ void Initialize(Isolate* isolate);
105
+
106
+ internal::Isolate* isolate_;
107
+ };
108
+
109
+ class V8_EXPORT Locker {
110
+ public:
111
+ /**
112
+ * Initialize Locker for a given Isolate.
113
+ */
114
+ V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
115
+
116
+ ~Locker();
117
+
118
+ /**
119
+ * Returns whether or not the locker for a given isolate, is locked by the
120
+ * current thread.
121
+ */
122
+ static bool IsLocked(Isolate* isolate);
123
+
124
+ // Disallow copying and assigning.
125
+ Locker(const Locker&) = delete;
126
+ void operator=(const Locker&) = delete;
127
+
128
+ private:
129
+ void Initialize(Isolate* isolate);
130
+
131
+ bool has_lock_;
132
+ bool top_level_;
133
+ internal::Isolate* isolate_;
134
+ };
135
+
136
+ } // namespace v8
137
+
138
+ #endif // INCLUDE_V8_LOCKER_H_
@@ -0,0 +1,160 @@
1
+ // Copyright 2021 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_V8_MAYBE_H_
6
+ #define INCLUDE_V8_MAYBE_H_
7
+
8
+ #include <type_traits>
9
+ #include <utility>
10
+
11
+ #include "v8-internal.h" // NOLINT(build/include_directory)
12
+ #include "v8config.h" // NOLINT(build/include_directory)
13
+
14
+ namespace v8 {
15
+
16
+ namespace api_internal {
17
+ // Called when ToChecked is called on an empty Maybe.
18
+ V8_EXPORT void FromJustIsNothing();
19
+ } // namespace api_internal
20
+
21
+ /**
22
+ * A simple Maybe type, representing an object which may or may not have a
23
+ * value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html.
24
+ *
25
+ * If an API method returns a Maybe<>, the API method can potentially fail
26
+ * either because an exception is thrown, or because an exception is pending,
27
+ * e.g. because a previous API call threw an exception that hasn't been caught
28
+ * yet, or because a TerminateExecution exception was thrown. In that case, a
29
+ * "Nothing" value is returned.
30
+ */
31
+ template <class T>
32
+ class Maybe {
33
+ public:
34
+ V8_INLINE bool IsNothing() const { return !has_value_; }
35
+ V8_INLINE bool IsJust() const { return has_value_; }
36
+
37
+ /**
38
+ * An alias for |FromJust|. Will crash if the Maybe<> is nothing.
39
+ */
40
+ V8_INLINE T ToChecked() const { return FromJust(); }
41
+
42
+ /**
43
+ * Short-hand for ToChecked(), which doesn't return a value. To be used, where
44
+ * the actual value of the Maybe is not needed like Object::Set.
45
+ */
46
+ V8_INLINE void Check() const {
47
+ if (V8_UNLIKELY(!IsJust())) api_internal::FromJustIsNothing();
48
+ }
49
+
50
+ /**
51
+ * Converts this Maybe<> to a value of type T. If this Maybe<> is
52
+ * nothing (empty), |false| is returned and |out| is left untouched.
53
+ */
54
+ V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
55
+ if (V8_LIKELY(IsJust())) *out = value_;
56
+ return IsJust();
57
+ }
58
+
59
+ /**
60
+ * Converts this Maybe<> to a value of type T. If this Maybe<> is
61
+ * nothing (empty), V8 will crash the process.
62
+ */
63
+ V8_INLINE T FromJust() const& {
64
+ if (V8_UNLIKELY(!IsJust())) api_internal::FromJustIsNothing();
65
+ return value_;
66
+ }
67
+
68
+ /**
69
+ * Converts this Maybe<> to a value of type T. If this Maybe<> is
70
+ * nothing (empty), V8 will crash the process.
71
+ */
72
+ V8_INLINE T FromJust() && {
73
+ if (V8_UNLIKELY(!IsJust())) api_internal::FromJustIsNothing();
74
+ return std::move(value_);
75
+ }
76
+
77
+ /**
78
+ * Converts this Maybe<> to a value of type T, using a default value if this
79
+ * Maybe<> is nothing (empty).
80
+ */
81
+ V8_INLINE T FromMaybe(const T& default_value) const {
82
+ return has_value_ ? value_ : default_value;
83
+ }
84
+
85
+ V8_INLINE bool operator==(const Maybe& other) const {
86
+ return (IsJust() == other.IsJust()) &&
87
+ (!IsJust() || FromJust() == other.FromJust());
88
+ }
89
+
90
+ V8_INLINE bool operator!=(const Maybe& other) const {
91
+ return !operator==(other);
92
+ }
93
+
94
+ private:
95
+ Maybe() : has_value_(false) {}
96
+ explicit Maybe(const T& t) : has_value_(true), value_(t) {}
97
+ explicit Maybe(T&& t) : has_value_(true), value_(std::move(t)) {}
98
+
99
+ bool has_value_;
100
+ T value_;
101
+
102
+ template <class U>
103
+ friend Maybe<U> Nothing();
104
+ template <class U>
105
+ friend Maybe<U> Just(const U& u);
106
+ template <class U, std::enable_if_t<!std::is_lvalue_reference_v<U>>*>
107
+ friend Maybe<U> Just(U&& u);
108
+ };
109
+
110
+ template <class T>
111
+ inline Maybe<T> Nothing() {
112
+ return Maybe<T>();
113
+ }
114
+
115
+ template <class T>
116
+ inline Maybe<T> Just(const T& t) {
117
+ return Maybe<T>(t);
118
+ }
119
+
120
+ // Don't use forwarding references here but instead use two overloads.
121
+ // Forwarding references only work when type deduction takes place, which is not
122
+ // the case for callsites such as Just<Type>(t).
123
+ template <class T, std::enable_if_t<!std::is_lvalue_reference_v<T>>* = nullptr>
124
+ inline Maybe<T> Just(T&& t) {
125
+ return Maybe<T>(std::move(t));
126
+ }
127
+
128
+ // A template specialization of Maybe<T> for the case of T = void.
129
+ template <>
130
+ class Maybe<void> {
131
+ public:
132
+ V8_INLINE bool IsNothing() const { return !is_valid_; }
133
+ V8_INLINE bool IsJust() const { return is_valid_; }
134
+
135
+ V8_INLINE bool operator==(const Maybe& other) const {
136
+ return IsJust() == other.IsJust();
137
+ }
138
+
139
+ V8_INLINE bool operator!=(const Maybe& other) const {
140
+ return !operator==(other);
141
+ }
142
+
143
+ private:
144
+ struct JustTag {};
145
+
146
+ Maybe() : is_valid_(false) {}
147
+ explicit Maybe(JustTag) : is_valid_(true) {}
148
+
149
+ bool is_valid_;
150
+
151
+ template <class U>
152
+ friend Maybe<U> Nothing();
153
+ friend Maybe<void> JustVoid();
154
+ };
155
+
156
+ inline Maybe<void> JustVoid() { return Maybe<void>(Maybe<void>::JustTag()); }
157
+
158
+ } // namespace v8
159
+
160
+ #endif // INCLUDE_V8_MAYBE_H_
@@ -0,0 +1,198 @@
1
+ // Copyright 2021 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_V8_MEMORY_SPAN_H_
6
+ #define INCLUDE_V8_MEMORY_SPAN_H_
7
+
8
+ #include <stddef.h>
9
+
10
+ #include <array>
11
+ #include <iterator>
12
+ #include <type_traits>
13
+
14
+ #include "v8config.h" // NOLINT(build/include_directory)
15
+
16
+ namespace v8 {
17
+
18
+ /**
19
+ * Points to an unowned contiguous buffer holding a known number of elements.
20
+ *
21
+ * This is similar to std::span (under consideration for C++20), but does not
22
+ * require advanced C++ support. In the (far) future, this may be replaced with
23
+ * or aliased to std::span.
24
+ *
25
+ * To facilitate future migration, this class exposes a subset of the interface
26
+ * implemented by std::span.
27
+ */
28
+ template <typename T>
29
+ class V8_EXPORT MemorySpan {
30
+ private:
31
+ /** Some C++ machinery, brought from the future. */
32
+ template <typename From, typename To>
33
+ using is_array_convertible = std::is_convertible<From (*)[], To (*)[]>;
34
+ template <typename From, typename To>
35
+ static constexpr bool is_array_convertible_v =
36
+ is_array_convertible<From, To>::value;
37
+
38
+ template <typename It>
39
+ using iter_reference_t = decltype(*std::declval<It&>());
40
+
41
+ template <typename It, typename = void>
42
+ struct is_compatible_iterator : std::false_type {};
43
+ template <typename It>
44
+ struct is_compatible_iterator<
45
+ It,
46
+ std::void_t<
47
+ std::is_base_of<std::random_access_iterator_tag,
48
+ typename std::iterator_traits<It>::iterator_category>,
49
+ is_array_convertible<std::remove_reference_t<iter_reference_t<It>>,
50
+ T>>> : std::true_type {};
51
+ template <typename It>
52
+ static constexpr bool is_compatible_iterator_v =
53
+ is_compatible_iterator<It>::value;
54
+
55
+ template <typename U>
56
+ static constexpr U* to_address(U* p) noexcept {
57
+ return p;
58
+ }
59
+
60
+ template <typename It,
61
+ typename = std::void_t<decltype(std::declval<It&>().operator->())>>
62
+ static constexpr auto to_address(It it) noexcept {
63
+ return it.operator->();
64
+ }
65
+
66
+ public:
67
+ /** The default constructor creates an empty span. */
68
+ constexpr MemorySpan() = default;
69
+
70
+ /** Constructor from nullptr and count, for backwards compatibility.
71
+ * This is not compatible with C++20 std::span.
72
+ */
73
+ constexpr MemorySpan(std::nullptr_t, size_t) {}
74
+
75
+ /** Constructor from "iterator" and count. */
76
+ template <typename Iterator,
77
+ std::enable_if_t<is_compatible_iterator_v<Iterator>, bool> = true>
78
+ constexpr MemorySpan(Iterator first,
79
+ size_t count) // NOLINT(runtime/explicit)
80
+ : data_(to_address(first)), size_(count) {}
81
+
82
+ /** Constructor from two "iterators". */
83
+ template <typename Iterator,
84
+ std::enable_if_t<is_compatible_iterator_v<Iterator> &&
85
+ !std::is_convertible_v<Iterator, size_t>,
86
+ bool> = true>
87
+ constexpr MemorySpan(Iterator first,
88
+ Iterator last) // NOLINT(runtime/explicit)
89
+ : data_(to_address(first)), size_(last - first) {}
90
+
91
+ /** Implicit conversion from C-style array. */
92
+ template <size_t N>
93
+ constexpr MemorySpan(T (&a)[N]) noexcept // NOLINT(runtime/explicit)
94
+ : data_(a), size_(N) {}
95
+
96
+ /** Implicit conversion from std::array. */
97
+ template <typename U, size_t N,
98
+ std::enable_if_t<is_array_convertible_v<U, T>, bool> = true>
99
+ constexpr MemorySpan(
100
+ std::array<U, N>& a) noexcept // NOLINT(runtime/explicit)
101
+ : data_(a.data()), size_{N} {}
102
+
103
+ /** Implicit conversion from const std::array. */
104
+ template <typename U, size_t N,
105
+ std::enable_if_t<is_array_convertible_v<const U, T>, bool> = true>
106
+ constexpr MemorySpan(
107
+ const std::array<U, N>& a) noexcept // NOLINT(runtime/explicit)
108
+ : data_(a.data()), size_{N} {}
109
+
110
+ /** Returns a pointer to the beginning of the buffer. */
111
+ constexpr T* data() const { return data_; }
112
+ /** Returns the number of elements that the buffer holds. */
113
+ constexpr size_t size() const { return size_; }
114
+
115
+ constexpr T& operator[](size_t i) const { return data_[i]; }
116
+
117
+ /** Returns true if the buffer is empty. */
118
+ constexpr bool empty() const { return size() == 0; }
119
+
120
+ class Iterator {
121
+ public:
122
+ using iterator_category = std::forward_iterator_tag;
123
+ using value_type = T;
124
+ using difference_type = std::ptrdiff_t;
125
+ using pointer = value_type*;
126
+ using reference = value_type&;
127
+
128
+ T& operator*() const { return *ptr_; }
129
+ T* operator->() const { return ptr_; }
130
+
131
+ bool operator==(Iterator other) const { return ptr_ == other.ptr_; }
132
+ bool operator!=(Iterator other) const { return !(*this == other); }
133
+
134
+ Iterator& operator++() {
135
+ ++ptr_;
136
+ return *this;
137
+ }
138
+
139
+ Iterator operator++(int) {
140
+ Iterator temp(*this);
141
+ ++(*this);
142
+ return temp;
143
+ }
144
+
145
+ private:
146
+ friend class MemorySpan<T>;
147
+
148
+ explicit Iterator(T* ptr) : ptr_(ptr) {}
149
+
150
+ T* ptr_ = nullptr;
151
+ };
152
+
153
+ Iterator begin() const { return Iterator(data_); }
154
+ Iterator end() const { return Iterator(data_ + size_); }
155
+
156
+ private:
157
+ T* data_ = nullptr;
158
+ size_t size_ = 0;
159
+ };
160
+
161
+ /**
162
+ * Helper function template to create an array of fixed length, initialized by
163
+ * the provided initializer list, without explicitly specifying the array size,
164
+ * e.g.
165
+ *
166
+ * auto arr = v8::to_array<Local<String>>({v8_str("one"), v8_str("two")});
167
+ *
168
+ * In the future, this may be replaced with or aliased to std::to_array (under
169
+ * consideration for C++20).
170
+ */
171
+
172
+ namespace detail {
173
+ template <class T, std::size_t N, std::size_t... I>
174
+ constexpr std::array<std::remove_cv_t<T>, N> to_array_lvalue_impl(
175
+ T (&a)[N], std::index_sequence<I...>) {
176
+ return {{a[I]...}};
177
+ }
178
+
179
+ template <class T, std::size_t N, std::size_t... I>
180
+ constexpr std::array<std::remove_cv_t<T>, N> to_array_rvalue_impl(
181
+ T (&&a)[N], std::index_sequence<I...>) {
182
+ return {{std::move(a[I])...}};
183
+ }
184
+ } // namespace detail
185
+
186
+ template <class T, std::size_t N>
187
+ constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N]) {
188
+ return detail::to_array_lvalue_impl(a, std::make_index_sequence<N>{});
189
+ }
190
+
191
+ template <class T, std::size_t N>
192
+ constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&&a)[N]) {
193
+ return detail::to_array_rvalue_impl(std::move(a),
194
+ std::make_index_sequence<N>{});
195
+ }
196
+
197
+ } // namespace v8
198
+ #endif // INCLUDE_V8_MEMORY_SPAN_H_