@kungfu-tech/libnode-win32-x64 22.22.3-kf.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.
- package/dist/node/include/acorn_version.h +6 -0
- package/dist/node/include/aliased_buffer-inl.h +244 -0
- package/dist/node/include/aliased_buffer.h +206 -0
- package/dist/node/include/aliased_struct-inl.h +54 -0
- package/dist/node/include/aliased_struct.h +63 -0
- package/dist/node/include/amaro_version.h +6 -0
- package/dist/node/include/async_context_frame.h +33 -0
- package/dist/node/include/async_wrap-inl.h +96 -0
- package/dist/node/include/async_wrap.h +243 -0
- package/dist/node/include/base_object-inl.h +335 -0
- package/dist/node/include/base_object.h +342 -0
- package/dist/node/include/base_object_types.h +74 -0
- package/dist/node/include/blob_serializer_deserializer-inl.h +385 -0
- package/dist/node/include/blob_serializer_deserializer.h +132 -0
- package/dist/node/include/callback_queue-inl.h +97 -0
- package/dist/node/include/callback_queue.h +79 -0
- package/dist/node/include/cares_wrap.h +447 -0
- package/dist/node/include/cjs_module_lexer_version.h +6 -0
- package/dist/node/include/cleanup_queue-inl.h +36 -0
- package/dist/node/include/cleanup_queue.h +79 -0
- package/dist/node/include/compile_cache.h +104 -0
- package/dist/node/include/connect_wrap.h +26 -0
- package/dist/node/include/connection_wrap.h +30 -0
- package/dist/node/include/cppgc/allocation.h +310 -0
- package/dist/node/include/cppgc/common.h +28 -0
- package/dist/node/include/cppgc/cross-thread-persistent.h +466 -0
- package/dist/node/include/cppgc/custom-space.h +97 -0
- package/dist/node/include/cppgc/default-platform.h +67 -0
- package/dist/node/include/cppgc/ephemeron-pair.h +30 -0
- package/dist/node/include/cppgc/explicit-management.h +100 -0
- package/dist/node/include/cppgc/garbage-collected.h +106 -0
- package/dist/node/include/cppgc/heap-consistency.h +309 -0
- package/dist/node/include/cppgc/heap-handle.h +48 -0
- package/dist/node/include/cppgc/heap-state.h +82 -0
- package/dist/node/include/cppgc/heap-statistics.h +120 -0
- package/dist/node/include/cppgc/heap.h +202 -0
- package/dist/node/include/cppgc/internal/api-constants.h +87 -0
- package/dist/node/include/cppgc/internal/atomic-entry-flag.h +48 -0
- package/dist/node/include/cppgc/internal/base-page-handle.h +45 -0
- package/dist/node/include/cppgc/internal/caged-heap-local-data.h +121 -0
- package/dist/node/include/cppgc/internal/caged-heap.h +68 -0
- package/dist/node/include/cppgc/internal/compiler-specific.h +38 -0
- package/dist/node/include/cppgc/internal/finalizer-trait.h +93 -0
- package/dist/node/include/cppgc/internal/gc-info.h +148 -0
- package/dist/node/include/cppgc/internal/logging.h +50 -0
- package/dist/node/include/cppgc/internal/member-storage.h +256 -0
- package/dist/node/include/cppgc/internal/name-trait.h +137 -0
- package/dist/node/include/cppgc/internal/persistent-node.h +214 -0
- package/dist/node/include/cppgc/internal/pointer-policies.h +243 -0
- package/dist/node/include/cppgc/internal/write-barrier.h +487 -0
- package/dist/node/include/cppgc/liveness-broker.h +78 -0
- package/dist/node/include/cppgc/macros.h +35 -0
- package/dist/node/include/cppgc/member.h +629 -0
- package/dist/node/include/cppgc/name-provider.h +65 -0
- package/dist/node/include/cppgc/object-size-trait.h +58 -0
- package/dist/node/include/cppgc/persistent.h +377 -0
- package/dist/node/include/cppgc/platform.h +163 -0
- package/dist/node/include/cppgc/prefinalizer.h +75 -0
- package/dist/node/include/cppgc/process-heap-statistics.h +36 -0
- package/dist/node/include/cppgc/sentinel-pointer.h +39 -0
- package/dist/node/include/cppgc/source-location.h +16 -0
- package/dist/node/include/cppgc/testing.h +106 -0
- package/dist/node/include/cppgc/trace-trait.h +128 -0
- package/dist/node/include/cppgc/type-traits.h +271 -0
- package/dist/node/include/cppgc/visitor.h +504 -0
- package/dist/node/include/crypto/crypto_aes.h +88 -0
- package/dist/node/include/crypto/crypto_bio.h +193 -0
- package/dist/node/include/crypto/crypto_cipher.h +293 -0
- package/dist/node/include/crypto/crypto_clienthello-inl.h +90 -0
- package/dist/node/include/crypto/crypto_clienthello.h +131 -0
- package/dist/node/include/crypto/crypto_common.h +64 -0
- package/dist/node/include/crypto/crypto_context.h +171 -0
- package/dist/node/include/crypto/crypto_dh.h +126 -0
- package/dist/node/include/crypto/crypto_dsa.h +52 -0
- package/dist/node/include/crypto/crypto_ec.h +164 -0
- package/dist/node/include/crypto/crypto_hash.h +91 -0
- package/dist/node/include/crypto/crypto_hkdf.h +61 -0
- package/dist/node/include/crypto/crypto_hmac.h +92 -0
- package/dist/node/include/crypto/crypto_keygen.h +299 -0
- package/dist/node/include/crypto/crypto_keys.h +392 -0
- package/dist/node/include/crypto/crypto_pbkdf2.h +74 -0
- package/dist/node/include/crypto/crypto_random.h +124 -0
- package/dist/node/include/crypto/crypto_rsa.h +136 -0
- package/dist/node/include/crypto/crypto_scrypt.h +85 -0
- package/dist/node/include/crypto/crypto_sig.h +165 -0
- package/dist/node/include/crypto/crypto_spkac.h +21 -0
- package/dist/node/include/crypto/crypto_timing.h +20 -0
- package/dist/node/include/crypto/crypto_tls.h +305 -0
- package/dist/node/include/crypto/crypto_util.h +725 -0
- package/dist/node/include/crypto/crypto_x509.h +140 -0
- package/dist/node/include/dataqueue/queue.h +306 -0
- package/dist/node/include/debug_utils-inl.h +278 -0
- package/dist/node/include/debug_utils.h +196 -0
- package/dist/node/include/diagnosticfilename-inl.h +33 -0
- package/dist/node/include/embedded_data.h +17 -0
- package/dist/node/include/encoding_binding.h +61 -0
- package/dist/node/include/env-inl.h +984 -0
- package/dist/node/include/env.h +1287 -0
- package/dist/node/include/env_properties.h +540 -0
- package/dist/node/include/handle_wrap.h +123 -0
- package/dist/node/include/histogram-inl.h +107 -0
- package/dist/node/include/histogram.h +279 -0
- package/dist/node/include/inspector/io_agent.h +30 -0
- package/dist/node/include/inspector/main_thread_interface.h +116 -0
- package/dist/node/include/inspector/network_agent.h +94 -0
- package/dist/node/include/inspector/network_inspector.h +45 -0
- package/dist/node/include/inspector/network_requests_buffer.h +195 -0
- package/dist/node/include/inspector/network_resource_manager.h +29 -0
- package/dist/node/include/inspector/node_json.h +24 -0
- package/dist/node/include/inspector/node_string.h +101 -0
- package/dist/node/include/inspector/protocol_helper.h +27 -0
- package/dist/node/include/inspector/runtime_agent.h +41 -0
- package/dist/node/include/inspector/target_agent.h +75 -0
- package/dist/node/include/inspector/tracing_agent.h +43 -0
- package/dist/node/include/inspector/worker_agent.h +40 -0
- package/dist/node/include/inspector/worker_inspector.h +124 -0
- package/dist/node/include/inspector_agent.h +165 -0
- package/dist/node/include/inspector_io.h +78 -0
- package/dist/node/include/inspector_profiler.h +149 -0
- package/dist/node/include/inspector_socket.h +60 -0
- package/dist/node/include/inspector_socket_server.h +110 -0
- package/dist/node/include/js_native_api.h +607 -0
- package/dist/node/include/js_native_api_types.h +226 -0
- package/dist/node/include/js_native_api_v8.h +485 -0
- package/dist/node/include/js_native_api_v8_internals.h +45 -0
- package/dist/node/include/js_stream.h +52 -0
- package/dist/node/include/json_utils.h +172 -0
- package/dist/node/include/large_pages/node_large_page.h +34 -0
- package/dist/node/include/libplatform/libplatform-export.h +29 -0
- package/dist/node/include/libplatform/libplatform.h +112 -0
- package/dist/node/include/libplatform/v8-tracing.h +333 -0
- package/dist/node/include/memory_tracker-inl.h +359 -0
- package/dist/node/include/memory_tracker.h +289 -0
- package/dist/node/include/module_wrap.h +216 -0
- package/dist/node/include/node.h +1593 -0
- package/dist/node/include/node_api.h +265 -0
- package/dist/node/include/node_api_internals.h +48 -0
- package/dist/node/include/node_api_types.h +56 -0
- package/dist/node/include/node_binding.h +161 -0
- package/dist/node/include/node_blob.h +159 -0
- package/dist/node/include/node_bob-inl.h +36 -0
- package/dist/node/include/node_bob.h +107 -0
- package/dist/node/include/node_buffer.h +92 -0
- package/dist/node/include/node_builtins.h +220 -0
- package/dist/node/include/node_config_file.h +46 -0
- package/dist/node/include/node_constants.h +82 -0
- package/dist/node/include/node_context_data.h +168 -0
- package/dist/node/include/node_contextify.h +204 -0
- package/dist/node/include/node_crypto.h +56 -0
- package/dist/node/include/node_debug.h +30 -0
- package/dist/node/include/node_dir.h +52 -0
- package/dist/node/include/node_dotenv.h +45 -0
- package/dist/node/include/node_errors.h +380 -0
- package/dist/node/include/node_exit_code.h +54 -0
- package/dist/node/include/node_external_reference.h +165 -0
- package/dist/node/include/node_file-inl.h +406 -0
- package/dist/node/include/node_file.h +537 -0
- package/dist/node/include/node_http2.h +1177 -0
- package/dist/node/include/node_http2_state.h +159 -0
- package/dist/node/include/node_http_common-inl.h +202 -0
- package/dist/node/include/node_http_common.h +535 -0
- package/dist/node/include/node_i18n.h +132 -0
- package/dist/node/include/node_internals.h +483 -0
- package/dist/node/include/node_main_instance.h +67 -0
- package/dist/node/include/node_mem-inl.h +113 -0
- package/dist/node/include/node_mem.h +45 -0
- package/dist/node/include/node_messaging.h +389 -0
- package/dist/node/include/node_metadata.h +164 -0
- package/dist/node/include/node_modules.h +91 -0
- package/dist/node/include/node_mutex.h +323 -0
- package/dist/node/include/node_object_wrap.h +132 -0
- package/dist/node/include/node_options-inl.h +490 -0
- package/dist/node/include/node_options.h +615 -0
- package/dist/node/include/node_perf.h +166 -0
- package/dist/node/include/node_perf_common.h +102 -0
- package/dist/node/include/node_platform.h +238 -0
- package/dist/node/include/node_process-inl.h +26 -0
- package/dist/node/include/node_process.h +112 -0
- package/dist/node/include/node_realm-inl.h +151 -0
- package/dist/node/include/node_realm.h +183 -0
- package/dist/node/include/node_report.h +43 -0
- package/dist/node/include/node_revert.h +82 -0
- package/dist/node/include/node_root_certs.h +3520 -0
- package/dist/node/include/node_sea.h +74 -0
- package/dist/node/include/node_shadow_realm.h +46 -0
- package/dist/node/include/node_snapshot_builder.h +57 -0
- package/dist/node/include/node_snapshotable.h +174 -0
- package/dist/node/include/node_sockaddr-inl.h +257 -0
- package/dist/node/include/node_sockaddr.h +394 -0
- package/dist/node/include/node_sqlite.h +270 -0
- package/dist/node/include/node_stat_watcher.h +73 -0
- package/dist/node/include/node_task_runner.h +92 -0
- package/dist/node/include/node_threadsafe_cow-inl.h +54 -0
- package/dist/node/include/node_threadsafe_cow.h +105 -0
- package/dist/node/include/node_union_bytes.h +81 -0
- package/dist/node/include/node_url.h +96 -0
- package/dist/node/include/node_v8.h +77 -0
- package/dist/node/include/node_v8_platform-inl.h +185 -0
- package/dist/node/include/node_version.h +110 -0
- package/dist/node/include/node_wasi.h +184 -0
- package/dist/node/include/node_wasm_web_api.h +55 -0
- package/dist/node/include/node_watchdog.h +154 -0
- package/dist/node/include/node_webstorage.h +60 -0
- package/dist/node/include/node_worker.h +158 -0
- package/dist/node/include/path.h +33 -0
- package/dist/node/include/permission/addon_permission.h +31 -0
- package/dist/node/include/permission/child_process_permission.h +31 -0
- package/dist/node/include/permission/fs_permission.h +167 -0
- package/dist/node/include/permission/inspector_permission.h +31 -0
- package/dist/node/include/permission/permission.h +138 -0
- package/dist/node/include/permission/permission_base.h +65 -0
- package/dist/node/include/permission/wasi_permission.h +31 -0
- package/dist/node/include/permission/worker_permission.h +31 -0
- package/dist/node/include/pipe_wrap.h +80 -0
- package/dist/node/include/quic/application.h +159 -0
- package/dist/node/include/quic/bindingdata.h +272 -0
- package/dist/node/include/quic/cid.h +127 -0
- package/dist/node/include/quic/data.h +148 -0
- package/dist/node/include/quic/defs.h +245 -0
- package/dist/node/include/quic/endpoint.h +458 -0
- package/dist/node/include/quic/http3.h +15 -0
- package/dist/node/include/quic/logstream.h +81 -0
- package/dist/node/include/quic/packet.h +152 -0
- package/dist/node/include/quic/preferredaddress.h +72 -0
- package/dist/node/include/quic/session.h +443 -0
- package/dist/node/include/quic/sessionticket.h +108 -0
- package/dist/node/include/quic/streams.h +232 -0
- package/dist/node/include/quic/tlscontext.h +227 -0
- package/dist/node/include/quic/tokens.h +256 -0
- package/dist/node/include/quic/transportparams.h +165 -0
- package/dist/node/include/req_wrap-inl.h +171 -0
- package/dist/node/include/req_wrap.h +77 -0
- package/dist/node/include/spawn_sync.h +243 -0
- package/dist/node/include/stream_base-inl.h +173 -0
- package/dist/node/include/stream_base.h +478 -0
- package/dist/node/include/stream_pipe.h +76 -0
- package/dist/node/include/stream_wrap.h +132 -0
- package/dist/node/include/string_bytes.h +113 -0
- package/dist/node/include/string_decoder-inl.h +31 -0
- package/dist/node/include/string_decoder.h +49 -0
- package/dist/node/include/tcp_wrap.h +105 -0
- package/dist/node/include/threadpoolwork-inl.h +70 -0
- package/dist/node/include/timer_wrap-inl.h +32 -0
- package/dist/node/include/timer_wrap.h +85 -0
- package/dist/node/include/timers.h +70 -0
- package/dist/node/include/tracing/agent.h +195 -0
- package/dist/node/include/tracing/node_trace_buffer.h +83 -0
- package/dist/node/include/tracing/node_trace_writer.h +75 -0
- package/dist/node/include/tracing/trace_event.h +722 -0
- package/dist/node/include/tracing/trace_event_common.h +1109 -0
- package/dist/node/include/tracing/traced_value.h +129 -0
- package/dist/node/include/tty_wrap.h +65 -0
- package/dist/node/include/udp_wrap.h +230 -0
- package/dist/node/include/undici_version.h +6 -0
- package/dist/node/include/util-inl.h +700 -0
- package/dist/node/include/util.h +1021 -0
- package/dist/node/include/uv/aix.h +32 -0
- package/dist/node/include/uv/bsd.h +34 -0
- package/dist/node/include/uv/darwin.h +61 -0
- package/dist/node/include/uv/errno.h +483 -0
- package/dist/node/include/uv/linux.h +34 -0
- package/dist/node/include/uv/os390.h +33 -0
- package/dist/node/include/uv/posix.h +31 -0
- package/dist/node/include/uv/sunos.h +44 -0
- package/dist/node/include/uv/threadpool.h +37 -0
- package/dist/node/include/uv/tree.h +521 -0
- package/dist/node/include/uv/unix.h +512 -0
- package/dist/node/include/uv/version.h +43 -0
- package/dist/node/include/uv/win.h +698 -0
- package/dist/node/include/uv.h +1990 -0
- package/dist/node/include/v8-array-buffer.h +525 -0
- package/dist/node/include/v8-callbacks.h +462 -0
- package/dist/node/include/v8-container.h +183 -0
- package/dist/node/include/v8-context.h +485 -0
- package/dist/node/include/v8-cppgc.h +245 -0
- package/dist/node/include/v8-data.h +80 -0
- package/dist/node/include/v8-date.h +48 -0
- package/dist/node/include/v8-debug.h +168 -0
- package/dist/node/include/v8-embedder-heap.h +82 -0
- package/dist/node/include/v8-embedder-state-scope.h +52 -0
- package/dist/node/include/v8-exception.h +223 -0
- package/dist/node/include/v8-extension.h +62 -0
- package/dist/node/include/v8-external.h +37 -0
- package/dist/node/include/v8-fast-api-calls.h +984 -0
- package/dist/node/include/v8-forward.h +82 -0
- package/dist/node/include/v8-function-callback.h +607 -0
- package/dist/node/include/v8-function.h +140 -0
- package/dist/node/include/v8-handle-base.h +137 -0
- package/dist/node/include/v8-initialization.h +289 -0
- package/dist/node/include/v8-inspector-protocol.h +13 -0
- package/dist/node/include/v8-inspector.h +419 -0
- package/dist/node/include/v8-internal.h +1397 -0
- package/dist/node/include/v8-isolate.h +1767 -0
- package/dist/node/include/v8-json.h +47 -0
- package/dist/node/include/v8-local-handle.h +758 -0
- package/dist/node/include/v8-locker.h +138 -0
- package/dist/node/include/v8-maybe.h +160 -0
- package/dist/node/include/v8-memory-span.h +198 -0
- package/dist/node/include/v8-message.h +233 -0
- package/dist/node/include/v8-metrics.h +264 -0
- package/dist/node/include/v8-microtask-queue.h +157 -0
- package/dist/node/include/v8-microtask.h +28 -0
- package/dist/node/include/v8-object.h +824 -0
- package/dist/node/include/v8-persistent-handle.h +582 -0
- package/dist/node/include/v8-platform.h +1358 -0
- package/dist/node/include/v8-primitive-object.h +118 -0
- package/dist/node/include/v8-primitive.h +877 -0
- package/dist/node/include/v8-profiler.h +1302 -0
- package/dist/node/include/v8-promise.h +174 -0
- package/dist/node/include/v8-proxy.h +50 -0
- package/dist/node/include/v8-regexp.h +106 -0
- package/dist/node/include/v8-script.h +904 -0
- package/dist/node/include/v8-snapshot.h +266 -0
- package/dist/node/include/v8-source-location.h +92 -0
- package/dist/node/include/v8-statistics.h +238 -0
- package/dist/node/include/v8-template.h +1297 -0
- package/dist/node/include/v8-traced-handle.h +432 -0
- package/dist/node/include/v8-typed-array.h +390 -0
- package/dist/node/include/v8-unwinder-state.h +31 -0
- package/dist/node/include/v8-unwinder.h +132 -0
- package/dist/node/include/v8-util.h +665 -0
- package/dist/node/include/v8-value-serializer-version.h +24 -0
- package/dist/node/include/v8-value-serializer.h +316 -0
- package/dist/node/include/v8-value.h +655 -0
- package/dist/node/include/v8-version-string.h +38 -0
- package/dist/node/include/v8-version.h +20 -0
- package/dist/node/include/v8-wasm-trap-handler-posix.h +31 -0
- package/dist/node/include/v8-wasm-trap-handler-win.h +28 -0
- package/dist/node/include/v8-wasm.h +201 -0
- package/dist/node/include/v8-weak-callback-info.h +80 -0
- package/dist/node/include/v8.h +88 -0
- package/dist/node/include/v8config.h +981 -0
- package/dist/node/include/zlib_version.h +6 -0
- package/dist/node/libnode.dll +0 -0
- package/dist/node/libnode.lib +0 -0
- package/dist/node/libnodebuildinfo.json +10 -0
- package/dist/node/link_node.lib +0 -0
- package/dist/node/link_node.node +0 -0
- package/libnode.release.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,1021 @@
|
|
|
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_UTIL_H_
|
|
23
|
+
#define SRC_UTIL_H_
|
|
24
|
+
|
|
25
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
26
|
+
|
|
27
|
+
#include "uv.h"
|
|
28
|
+
#include "v8-inspector.h"
|
|
29
|
+
#include "v8-profiler.h"
|
|
30
|
+
#include "v8.h"
|
|
31
|
+
|
|
32
|
+
#include "node.h"
|
|
33
|
+
#include "node_exit_code.h"
|
|
34
|
+
|
|
35
|
+
#include <climits>
|
|
36
|
+
#include <cstddef>
|
|
37
|
+
#include <cstdio>
|
|
38
|
+
#include <cstdlib>
|
|
39
|
+
#include <cstring>
|
|
40
|
+
|
|
41
|
+
#include <array>
|
|
42
|
+
#include <bit>
|
|
43
|
+
#include <filesystem>
|
|
44
|
+
#include <limits>
|
|
45
|
+
#include <memory>
|
|
46
|
+
#include <optional>
|
|
47
|
+
#include <set>
|
|
48
|
+
#include <sstream>
|
|
49
|
+
#include <string>
|
|
50
|
+
#include <string_view>
|
|
51
|
+
#include <type_traits>
|
|
52
|
+
#include <unordered_map>
|
|
53
|
+
#include <utility>
|
|
54
|
+
#include <vector>
|
|
55
|
+
|
|
56
|
+
#ifdef __GNUC__
|
|
57
|
+
#define MUST_USE_RESULT __attribute__((warn_unused_result))
|
|
58
|
+
#else
|
|
59
|
+
#define MUST_USE_RESULT
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
namespace node {
|
|
63
|
+
|
|
64
|
+
constexpr char kPathSeparator = std::filesystem::path::preferred_separator;
|
|
65
|
+
|
|
66
|
+
#ifdef _WIN32
|
|
67
|
+
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
|
|
68
|
+
#define PATH_MAX_BYTES (MAX_PATH * 4)
|
|
69
|
+
#else
|
|
70
|
+
#define PATH_MAX_BYTES (PATH_MAX)
|
|
71
|
+
#endif
|
|
72
|
+
|
|
73
|
+
// These should be used in our code as opposed to the native
|
|
74
|
+
// versions as they abstract out some platform and or
|
|
75
|
+
// compiler version specific functionality
|
|
76
|
+
// malloc(0) and realloc(ptr, 0) have implementation-defined behavior in
|
|
77
|
+
// that the standard allows them to either return a unique pointer or a
|
|
78
|
+
// nullptr for zero-sized allocation requests. Normalize by always using
|
|
79
|
+
// a nullptr.
|
|
80
|
+
template <typename T>
|
|
81
|
+
inline T* UncheckedRealloc(T* pointer, size_t n);
|
|
82
|
+
template <typename T>
|
|
83
|
+
inline T* UncheckedMalloc(size_t n);
|
|
84
|
+
template <typename T>
|
|
85
|
+
inline T* UncheckedCalloc(size_t n);
|
|
86
|
+
|
|
87
|
+
// Same things, but aborts immediately instead of returning nullptr when
|
|
88
|
+
// no memory is available.
|
|
89
|
+
template <typename T>
|
|
90
|
+
inline T* Realloc(T* pointer, size_t n);
|
|
91
|
+
template <typename T>
|
|
92
|
+
inline T* Malloc(size_t n);
|
|
93
|
+
template <typename T>
|
|
94
|
+
inline T* Calloc(size_t n);
|
|
95
|
+
|
|
96
|
+
inline char* Malloc(size_t n);
|
|
97
|
+
inline char* Calloc(size_t n);
|
|
98
|
+
inline char* UncheckedMalloc(size_t n);
|
|
99
|
+
inline char* UncheckedCalloc(size_t n);
|
|
100
|
+
|
|
101
|
+
template <typename T>
|
|
102
|
+
inline T MultiplyWithOverflowCheck(T a, T b);
|
|
103
|
+
|
|
104
|
+
namespace per_process {
|
|
105
|
+
// Tells whether the per-process V8::Initialize() is called and
|
|
106
|
+
// if it is safe to call v8::Isolate::TryGetCurrent().
|
|
107
|
+
extern bool v8_initialized;
|
|
108
|
+
} // namespace per_process
|
|
109
|
+
|
|
110
|
+
// Used by the allocation functions when allocation fails.
|
|
111
|
+
// Thin wrapper around v8::Isolate::LowMemoryNotification() that checks
|
|
112
|
+
// whether V8 is initialized.
|
|
113
|
+
void LowMemoryNotification();
|
|
114
|
+
|
|
115
|
+
// The reason that Assert() takes a struct argument instead of individual
|
|
116
|
+
// const char*s is to ease instruction cache pressure in calls from CHECK.
|
|
117
|
+
struct AssertionInfo {
|
|
118
|
+
const char* file_line; // filename:line
|
|
119
|
+
const char* message;
|
|
120
|
+
const char* function;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// This indirectly calls backtrace so it can not be marked as [[noreturn]].
|
|
124
|
+
void NODE_EXTERN_PRIVATE Assert(const AssertionInfo& info);
|
|
125
|
+
void DumpNativeBacktrace(FILE* fp);
|
|
126
|
+
void DumpJavaScriptBacktrace(FILE* fp);
|
|
127
|
+
|
|
128
|
+
// Windows 8+ does not like abort() in Release mode
|
|
129
|
+
#ifdef _WIN32
|
|
130
|
+
#define ABORT_NO_BACKTRACE() _exit(static_cast<int>(node::ExitCode::kAbort))
|
|
131
|
+
#else
|
|
132
|
+
#define ABORT_NO_BACKTRACE() abort()
|
|
133
|
+
#endif
|
|
134
|
+
|
|
135
|
+
// Caller of this macro must not be marked as [[noreturn]]. Printing of
|
|
136
|
+
// backtraces may not work correctly in [[noreturn]] functions because
|
|
137
|
+
// when generating code for them the compiler can choose not to
|
|
138
|
+
// maintain the frame pointers or link registers that are necessary for
|
|
139
|
+
// correct backtracing.
|
|
140
|
+
// `ABORT` must be a macro and not a [[noreturn]] function to make sure the
|
|
141
|
+
// backtrace is correct.
|
|
142
|
+
#define ABORT() \
|
|
143
|
+
do { \
|
|
144
|
+
node::DumpNativeBacktrace(stderr); \
|
|
145
|
+
node::DumpJavaScriptBacktrace(stderr); \
|
|
146
|
+
fflush(stderr); \
|
|
147
|
+
ABORT_NO_BACKTRACE(); \
|
|
148
|
+
} while (0)
|
|
149
|
+
|
|
150
|
+
#define ERROR_AND_ABORT(expr) \
|
|
151
|
+
do { \
|
|
152
|
+
/* Make sure that this struct does not end up in inline code, but */ \
|
|
153
|
+
/* rather in a read-only data section when modifying this code. */ \
|
|
154
|
+
static const node::AssertionInfo error_and_abort_args = { \
|
|
155
|
+
__FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME}; \
|
|
156
|
+
node::Assert(error_and_abort_args); \
|
|
157
|
+
/* `node::Assert` doesn't return. Add an [[noreturn]] abort() here to */ \
|
|
158
|
+
/* make the compiler happy about no return value in the caller */ \
|
|
159
|
+
/* function when calling ERROR_AND_ABORT. */ \
|
|
160
|
+
ABORT_NO_BACKTRACE(); \
|
|
161
|
+
} while (0)
|
|
162
|
+
|
|
163
|
+
#ifdef __GNUC__
|
|
164
|
+
#define PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__
|
|
165
|
+
#else
|
|
166
|
+
#if defined(_MSC_VER)
|
|
167
|
+
#define PRETTY_FUNCTION_NAME __FUNCSIG__
|
|
168
|
+
#else
|
|
169
|
+
#define PRETTY_FUNCTION_NAME ""
|
|
170
|
+
#endif
|
|
171
|
+
#endif
|
|
172
|
+
|
|
173
|
+
#define STRINGIFY_(x) #x
|
|
174
|
+
#define STRINGIFY(x) STRINGIFY_(x)
|
|
175
|
+
|
|
176
|
+
#define CHECK(expr) \
|
|
177
|
+
do { \
|
|
178
|
+
if (!(expr)) [[unlikely]] { \
|
|
179
|
+
ERROR_AND_ABORT(expr); \
|
|
180
|
+
} \
|
|
181
|
+
} while (0)
|
|
182
|
+
|
|
183
|
+
#define CHECK_EQ(a, b) CHECK((a) == (b))
|
|
184
|
+
#define CHECK_GE(a, b) CHECK((a) >= (b))
|
|
185
|
+
#define CHECK_GT(a, b) CHECK((a) > (b))
|
|
186
|
+
#define CHECK_LE(a, b) CHECK((a) <= (b))
|
|
187
|
+
#define CHECK_LT(a, b) CHECK((a) < (b))
|
|
188
|
+
#define CHECK_NE(a, b) CHECK((a) != (b))
|
|
189
|
+
#define CHECK_NULL(val) CHECK((val) == nullptr)
|
|
190
|
+
#define CHECK_NOT_NULL(val) CHECK((val) != nullptr)
|
|
191
|
+
#define CHECK_IMPLIES(a, b) CHECK(!(a) || (b))
|
|
192
|
+
|
|
193
|
+
#ifdef DEBUG
|
|
194
|
+
#define DCHECK(expr) CHECK(expr)
|
|
195
|
+
#define DCHECK_EQ(a, b) CHECK((a) == (b))
|
|
196
|
+
#define DCHECK_GE(a, b) CHECK((a) >= (b))
|
|
197
|
+
#define DCHECK_GT(a, b) CHECK((a) > (b))
|
|
198
|
+
#define DCHECK_LE(a, b) CHECK((a) <= (b))
|
|
199
|
+
#define DCHECK_LT(a, b) CHECK((a) < (b))
|
|
200
|
+
#define DCHECK_NE(a, b) CHECK((a) != (b))
|
|
201
|
+
#define DCHECK_NULL(val) CHECK((val) == nullptr)
|
|
202
|
+
#define DCHECK_NOT_NULL(val) CHECK((val) != nullptr)
|
|
203
|
+
#define DCHECK_IMPLIES(a, b) CHECK(!(a) || (b))
|
|
204
|
+
#else
|
|
205
|
+
#define DCHECK(expr)
|
|
206
|
+
#define DCHECK_EQ(a, b)
|
|
207
|
+
#define DCHECK_GE(a, b)
|
|
208
|
+
#define DCHECK_GT(a, b)
|
|
209
|
+
#define DCHECK_LE(a, b)
|
|
210
|
+
#define DCHECK_LT(a, b)
|
|
211
|
+
#define DCHECK_NE(a, b)
|
|
212
|
+
#define DCHECK_NULL(val)
|
|
213
|
+
#define DCHECK_NOT_NULL(val)
|
|
214
|
+
#define DCHECK_IMPLIES(a, b)
|
|
215
|
+
#endif
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
#define UNREACHABLE(...) \
|
|
219
|
+
ERROR_AND_ABORT("Unreachable code reached" __VA_OPT__(": ") __VA_ARGS__)
|
|
220
|
+
|
|
221
|
+
// ECMA-262, 15th edition, 21.1.2.6. Number.MAX_SAFE_INTEGER (2^53-1)
|
|
222
|
+
constexpr int64_t kMaxSafeJsInteger = 9007199254740991;
|
|
223
|
+
|
|
224
|
+
inline bool IsSafeJsInt(v8::Local<v8::Value> v);
|
|
225
|
+
|
|
226
|
+
// TAILQ-style intrusive list node.
|
|
227
|
+
template <typename T>
|
|
228
|
+
class ListNode;
|
|
229
|
+
|
|
230
|
+
// TAILQ-style intrusive list head.
|
|
231
|
+
template <typename T, ListNode<T> (T::*M)>
|
|
232
|
+
class ListHead;
|
|
233
|
+
|
|
234
|
+
template <typename T>
|
|
235
|
+
class ListNode {
|
|
236
|
+
public:
|
|
237
|
+
inline ListNode();
|
|
238
|
+
inline ~ListNode();
|
|
239
|
+
inline void Remove();
|
|
240
|
+
inline bool IsEmpty() const;
|
|
241
|
+
|
|
242
|
+
ListNode(const ListNode&) = delete;
|
|
243
|
+
ListNode& operator=(const ListNode&) = delete;
|
|
244
|
+
|
|
245
|
+
private:
|
|
246
|
+
template <typename U, ListNode<U> (U::*M)> friend class ListHead;
|
|
247
|
+
friend int GenDebugSymbols();
|
|
248
|
+
ListNode* prev_;
|
|
249
|
+
ListNode* next_;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
template <typename T, ListNode<T> (T::*M)>
|
|
253
|
+
class ListHead {
|
|
254
|
+
public:
|
|
255
|
+
class Iterator {
|
|
256
|
+
public:
|
|
257
|
+
inline T* operator*() const;
|
|
258
|
+
inline const Iterator& operator++();
|
|
259
|
+
inline bool operator!=(const Iterator& that) const;
|
|
260
|
+
|
|
261
|
+
private:
|
|
262
|
+
friend class ListHead;
|
|
263
|
+
inline explicit Iterator(ListNode<T>* node);
|
|
264
|
+
ListNode<T>* node_;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
inline ListHead() = default;
|
|
268
|
+
inline ~ListHead();
|
|
269
|
+
inline void PushBack(T* element);
|
|
270
|
+
inline void PushFront(T* element);
|
|
271
|
+
inline bool IsEmpty() const;
|
|
272
|
+
inline T* PopFront();
|
|
273
|
+
inline Iterator begin() const;
|
|
274
|
+
inline Iterator end() const;
|
|
275
|
+
|
|
276
|
+
ListHead(const ListHead&) = delete;
|
|
277
|
+
ListHead& operator=(const ListHead&) = delete;
|
|
278
|
+
|
|
279
|
+
private:
|
|
280
|
+
friend int GenDebugSymbols();
|
|
281
|
+
ListNode<T> head_;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// The helper is for doing safe downcasts from base types to derived types.
|
|
285
|
+
template <typename Inner, typename Outer>
|
|
286
|
+
class ContainerOfHelper {
|
|
287
|
+
public:
|
|
288
|
+
inline ContainerOfHelper(Inner Outer::*field, Inner* pointer);
|
|
289
|
+
template <typename TypeName>
|
|
290
|
+
inline operator TypeName*() const;
|
|
291
|
+
private:
|
|
292
|
+
Outer* const pointer_;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// Calculate the address of the outer (i.e. embedding) struct from
|
|
296
|
+
// the interior pointer to a data member.
|
|
297
|
+
template <typename Inner, typename Outer>
|
|
298
|
+
constexpr ContainerOfHelper<Inner, Outer> ContainerOf(Inner Outer::*field,
|
|
299
|
+
Inner* pointer);
|
|
300
|
+
|
|
301
|
+
class KVStore {
|
|
302
|
+
public:
|
|
303
|
+
KVStore() = default;
|
|
304
|
+
virtual ~KVStore() = default;
|
|
305
|
+
KVStore(const KVStore&) = delete;
|
|
306
|
+
KVStore& operator=(const KVStore&) = delete;
|
|
307
|
+
KVStore(KVStore&&) = delete;
|
|
308
|
+
KVStore& operator=(KVStore&&) = delete;
|
|
309
|
+
|
|
310
|
+
virtual v8::MaybeLocal<v8::String> Get(v8::Isolate* isolate,
|
|
311
|
+
v8::Local<v8::String> key) const = 0;
|
|
312
|
+
virtual std::optional<std::string> Get(const char* key) const = 0;
|
|
313
|
+
virtual void Set(v8::Isolate* isolate,
|
|
314
|
+
v8::Local<v8::String> key,
|
|
315
|
+
v8::Local<v8::String> value) = 0;
|
|
316
|
+
virtual int32_t Query(v8::Isolate* isolate,
|
|
317
|
+
v8::Local<v8::String> key) const = 0;
|
|
318
|
+
virtual int32_t Query(const char* key) const = 0;
|
|
319
|
+
virtual void Delete(v8::Isolate* isolate, v8::Local<v8::String> key) = 0;
|
|
320
|
+
virtual v8::Local<v8::Array> Enumerate(v8::Isolate* isolate) const = 0;
|
|
321
|
+
|
|
322
|
+
virtual std::shared_ptr<KVStore> Clone(v8::Isolate* isolate) const;
|
|
323
|
+
virtual v8::Maybe<void> AssignFromObject(v8::Local<v8::Context> context,
|
|
324
|
+
v8::Local<v8::Object> entries);
|
|
325
|
+
v8::Maybe<void> AssignToObject(v8::Isolate* isolate,
|
|
326
|
+
v8::Local<v8::Context> context,
|
|
327
|
+
v8::Local<v8::Object> object);
|
|
328
|
+
|
|
329
|
+
static std::shared_ptr<KVStore> CreateMapKVStore();
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// Convenience wrapper around v8::String::NewFromOneByte().
|
|
333
|
+
inline v8::Local<v8::String> OneByteString(
|
|
334
|
+
v8::Isolate* isolate,
|
|
335
|
+
const char* data,
|
|
336
|
+
int length = -1,
|
|
337
|
+
v8::NewStringType type = v8::NewStringType::kNormal);
|
|
338
|
+
|
|
339
|
+
// For the people that compile with -funsigned-char.
|
|
340
|
+
inline v8::Local<v8::String> OneByteString(
|
|
341
|
+
v8::Isolate* isolate,
|
|
342
|
+
const signed char* data,
|
|
343
|
+
int length = -1,
|
|
344
|
+
v8::NewStringType type = v8::NewStringType::kNormal);
|
|
345
|
+
|
|
346
|
+
inline v8::Local<v8::String> OneByteString(
|
|
347
|
+
v8::Isolate* isolate,
|
|
348
|
+
const unsigned char* data,
|
|
349
|
+
int length = -1,
|
|
350
|
+
v8::NewStringType type = v8::NewStringType::kNormal);
|
|
351
|
+
|
|
352
|
+
inline v8::Local<v8::String> OneByteString(
|
|
353
|
+
v8::Isolate* isolate,
|
|
354
|
+
std::string_view str,
|
|
355
|
+
v8::NewStringType type = v8::NewStringType::kNormal);
|
|
356
|
+
|
|
357
|
+
// Used to be a macro, hence the uppercase name.
|
|
358
|
+
template <std::size_t N>
|
|
359
|
+
requires(N > 0)
|
|
360
|
+
inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING(v8::Isolate* isolate,
|
|
361
|
+
const char (&data)[N]) {
|
|
362
|
+
CHECK_EQ(data[N - 1], '\0');
|
|
363
|
+
return OneByteString(isolate, data, N - 1, v8::NewStringType::kInternalized);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// tolower() is locale-sensitive. Use ToLower() instead.
|
|
367
|
+
inline char ToLower(char c);
|
|
368
|
+
template <typename T>
|
|
369
|
+
inline std::string ToLower(const T& in);
|
|
370
|
+
|
|
371
|
+
// toupper() is locale-sensitive. Use ToUpper() instead.
|
|
372
|
+
inline char ToUpper(char c);
|
|
373
|
+
template <typename T>
|
|
374
|
+
inline std::string ToUpper(const T& in);
|
|
375
|
+
|
|
376
|
+
// strcasecmp() is locale-sensitive. Use StringEqualNoCase() instead.
|
|
377
|
+
inline bool StringEqualNoCase(const char* a, const char* b);
|
|
378
|
+
|
|
379
|
+
// strncasecmp() is locale-sensitive. Use StringEqualNoCaseN() instead.
|
|
380
|
+
inline bool StringEqualNoCaseN(const char* a, const char* b, size_t length);
|
|
381
|
+
|
|
382
|
+
template <typename T, size_t N>
|
|
383
|
+
constexpr size_t arraysize(const T (&)[N]) {
|
|
384
|
+
return N;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
template <typename T, size_t N>
|
|
388
|
+
constexpr size_t strsize(const T (&)[N]) {
|
|
389
|
+
return N - 1;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Allocates an array of member type T. For up to kStackStorageSize items,
|
|
393
|
+
// the stack is used, otherwise malloc().
|
|
394
|
+
template <typename T, size_t kStackStorageSize = 1024>
|
|
395
|
+
class MaybeStackBuffer {
|
|
396
|
+
public:
|
|
397
|
+
// Disallow copy constructor
|
|
398
|
+
MaybeStackBuffer(const MaybeStackBuffer&) = delete;
|
|
399
|
+
// Disallow copy assignment operator
|
|
400
|
+
MaybeStackBuffer& operator=(const MaybeStackBuffer& other) = delete;
|
|
401
|
+
|
|
402
|
+
const T* out() const {
|
|
403
|
+
return buf_;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
T* out() {
|
|
407
|
+
return buf_;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// operator* for compatibility with `v8::String::(Utf8)Value`
|
|
411
|
+
T* operator*() {
|
|
412
|
+
return buf_;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const T* operator*() const {
|
|
416
|
+
return buf_;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
T& operator[](size_t index) {
|
|
420
|
+
CHECK_LT(index, length());
|
|
421
|
+
return buf_[index];
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const T& operator[](size_t index) const {
|
|
425
|
+
CHECK_LT(index, length());
|
|
426
|
+
return buf_[index];
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
size_t length() const {
|
|
430
|
+
return length_;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Current maximum capacity of the buffer with which SetLength() can be used
|
|
434
|
+
// without first calling AllocateSufficientStorage().
|
|
435
|
+
size_t capacity() const {
|
|
436
|
+
return capacity_;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Make sure enough space for `storage` entries is available.
|
|
440
|
+
// This method can be called multiple times throughout the lifetime of the
|
|
441
|
+
// buffer, but once this has been called Invalidate() cannot be used.
|
|
442
|
+
// Content of the buffer in the range [0, length()) is preserved.
|
|
443
|
+
void AllocateSufficientStorage(size_t storage);
|
|
444
|
+
|
|
445
|
+
void SetLength(size_t length) {
|
|
446
|
+
// capacity() returns how much memory is actually available.
|
|
447
|
+
CHECK_LE(length, capacity());
|
|
448
|
+
length_ = length;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
void SetLengthAndZeroTerminate(size_t length) {
|
|
452
|
+
// capacity() returns how much memory is actually available.
|
|
453
|
+
CHECK_LE(length + 1, capacity());
|
|
454
|
+
SetLength(length);
|
|
455
|
+
|
|
456
|
+
// T() is 0 for integer types, nullptr for pointers, etc.
|
|
457
|
+
buf_[length] = T();
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Make dereferencing this object return nullptr.
|
|
461
|
+
// This method can be called multiple times throughout the lifetime of the
|
|
462
|
+
// buffer, but once this has been called AllocateSufficientStorage() cannot
|
|
463
|
+
// be used.
|
|
464
|
+
void Invalidate() {
|
|
465
|
+
CHECK(!IsAllocated());
|
|
466
|
+
capacity_ = 0;
|
|
467
|
+
length_ = 0;
|
|
468
|
+
buf_ = nullptr;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// If the buffer is stored in the heap rather than on the stack.
|
|
472
|
+
bool IsAllocated() const {
|
|
473
|
+
return !IsInvalidated() && buf_ != buf_st_;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// If Invalidate() has been called.
|
|
477
|
+
bool IsInvalidated() const {
|
|
478
|
+
return buf_ == nullptr;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// Release ownership of the malloc'd buffer.
|
|
482
|
+
// Note: This does not free the buffer.
|
|
483
|
+
void Release() {
|
|
484
|
+
CHECK(IsAllocated());
|
|
485
|
+
buf_ = buf_st_;
|
|
486
|
+
length_ = 0;
|
|
487
|
+
capacity_ = arraysize(buf_st_);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
MaybeStackBuffer()
|
|
491
|
+
: length_(0), capacity_(arraysize(buf_st_)), buf_(buf_st_) {
|
|
492
|
+
// Default to a zero-length, null-terminated buffer.
|
|
493
|
+
buf_[0] = T();
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
explicit MaybeStackBuffer(size_t storage) : MaybeStackBuffer() {
|
|
497
|
+
AllocateSufficientStorage(storage);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
~MaybeStackBuffer() {
|
|
501
|
+
if (IsAllocated())
|
|
502
|
+
free(buf_);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
inline std::basic_string<T> ToString() const { return {out(), length()}; }
|
|
506
|
+
inline std::basic_string_view<T> ToStringView() const {
|
|
507
|
+
return {out(), length()};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
private:
|
|
511
|
+
size_t length_;
|
|
512
|
+
// capacity of the malloc'ed buf_
|
|
513
|
+
size_t capacity_;
|
|
514
|
+
T* buf_;
|
|
515
|
+
T buf_st_[kStackStorageSize];
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// Provides access to an ArrayBufferView's storage, either the original,
|
|
519
|
+
// or for small data, a copy of it. This object's lifetime is bound to the
|
|
520
|
+
// original ArrayBufferView's lifetime.
|
|
521
|
+
template <typename T, size_t kStackStorageSize = 64>
|
|
522
|
+
class ArrayBufferViewContents {
|
|
523
|
+
public:
|
|
524
|
+
ArrayBufferViewContents() = default;
|
|
525
|
+
|
|
526
|
+
ArrayBufferViewContents(const ArrayBufferViewContents&) = delete;
|
|
527
|
+
void operator=(const ArrayBufferViewContents&) = delete;
|
|
528
|
+
|
|
529
|
+
explicit inline ArrayBufferViewContents(v8::Local<v8::Value> value);
|
|
530
|
+
explicit inline ArrayBufferViewContents(v8::Local<v8::Object> value);
|
|
531
|
+
explicit inline ArrayBufferViewContents(v8::Local<v8::ArrayBufferView> abv);
|
|
532
|
+
inline void Read(v8::Local<v8::ArrayBufferView> abv);
|
|
533
|
+
inline void ReadValue(v8::Local<v8::Value> buf);
|
|
534
|
+
|
|
535
|
+
inline bool WasDetached() const { return was_detached_; }
|
|
536
|
+
inline const T* data() const { return data_; }
|
|
537
|
+
inline size_t length() const { return length_; }
|
|
538
|
+
|
|
539
|
+
private:
|
|
540
|
+
// Declaring operator new and delete as deleted is not spec compliant.
|
|
541
|
+
// Therefore, declare them private instead to disable dynamic alloc.
|
|
542
|
+
void* operator new(size_t size);
|
|
543
|
+
void* operator new[](size_t size);
|
|
544
|
+
void operator delete(void*, size_t);
|
|
545
|
+
void operator delete[](void*, size_t);
|
|
546
|
+
|
|
547
|
+
T stack_storage_[kStackStorageSize];
|
|
548
|
+
T* data_ = nullptr;
|
|
549
|
+
size_t length_ = 0;
|
|
550
|
+
bool was_detached_ = false;
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
class Utf8Value : public MaybeStackBuffer<char> {
|
|
554
|
+
public:
|
|
555
|
+
explicit Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> value);
|
|
556
|
+
|
|
557
|
+
inline bool operator==(const char* a) const { return strcmp(out(), a) == 0; }
|
|
558
|
+
inline bool operator!=(const char* a) const { return !(*this == a); }
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
class TwoByteValue : public MaybeStackBuffer<uint16_t> {
|
|
562
|
+
public:
|
|
563
|
+
explicit TwoByteValue(v8::Isolate* isolate, v8::Local<v8::Value> value);
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
class BufferValue : public MaybeStackBuffer<char> {
|
|
567
|
+
public:
|
|
568
|
+
explicit BufferValue(v8::Isolate* isolate, v8::Local<v8::Value> value);
|
|
569
|
+
|
|
570
|
+
inline std::u8string_view ToU8StringView() const {
|
|
571
|
+
return std::u8string_view(reinterpret_cast<const char8_t*>(out()),
|
|
572
|
+
length());
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
#define SPREAD_BUFFER_ARG(val, name) \
|
|
577
|
+
CHECK((val)->IsArrayBufferView()); \
|
|
578
|
+
v8::Local<v8::ArrayBufferView> name = (val).As<v8::ArrayBufferView>(); \
|
|
579
|
+
const size_t name##_offset = name->ByteOffset(); \
|
|
580
|
+
const size_t name##_length = name->ByteLength(); \
|
|
581
|
+
char* const name##_data = \
|
|
582
|
+
static_cast<char*>(name->Buffer()->Data()) + name##_offset; \
|
|
583
|
+
if (name##_length > 0) CHECK_NE(name##_data, nullptr);
|
|
584
|
+
|
|
585
|
+
// Use this when a variable or parameter is unused in order to explicitly
|
|
586
|
+
// silence a compiler warning about that.
|
|
587
|
+
template <typename T> inline void USE(T&&) {}
|
|
588
|
+
|
|
589
|
+
template <typename Fn>
|
|
590
|
+
struct OnScopeLeaveImpl {
|
|
591
|
+
Fn fn_;
|
|
592
|
+
bool active_;
|
|
593
|
+
|
|
594
|
+
explicit OnScopeLeaveImpl(Fn&& fn) : fn_(std::move(fn)), active_(true) {}
|
|
595
|
+
~OnScopeLeaveImpl() { if (active_) fn_(); }
|
|
596
|
+
|
|
597
|
+
OnScopeLeaveImpl(const OnScopeLeaveImpl& other) = delete;
|
|
598
|
+
OnScopeLeaveImpl& operator=(const OnScopeLeaveImpl& other) = delete;
|
|
599
|
+
OnScopeLeaveImpl(OnScopeLeaveImpl&& other)
|
|
600
|
+
: fn_(std::move(other.fn_)), active_(other.active_) {
|
|
601
|
+
other.active_ = false;
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// Run a function when exiting the current scope. Used like this:
|
|
606
|
+
// auto on_scope_leave = OnScopeLeave([&] {
|
|
607
|
+
// // ... run some code ...
|
|
608
|
+
// });
|
|
609
|
+
template <typename Fn>
|
|
610
|
+
inline MUST_USE_RESULT OnScopeLeaveImpl<Fn> OnScopeLeave(Fn&& fn) {
|
|
611
|
+
return OnScopeLeaveImpl<Fn>{std::move(fn)};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// Simple RAII wrapper for contiguous data that uses malloc()/free().
|
|
615
|
+
template <typename T>
|
|
616
|
+
struct MallocedBuffer {
|
|
617
|
+
T* data;
|
|
618
|
+
size_t size;
|
|
619
|
+
|
|
620
|
+
T* release() {
|
|
621
|
+
T* ret = data;
|
|
622
|
+
data = nullptr;
|
|
623
|
+
return ret;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
void Truncate(size_t new_size) {
|
|
627
|
+
CHECK_LE(new_size, size);
|
|
628
|
+
size = new_size;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
void Realloc(size_t new_size) {
|
|
632
|
+
Truncate(new_size);
|
|
633
|
+
data = UncheckedRealloc(data, new_size);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
bool is_empty() const { return data == nullptr; }
|
|
637
|
+
|
|
638
|
+
MallocedBuffer() : data(nullptr), size(0) {}
|
|
639
|
+
explicit MallocedBuffer(size_t size) : data(Malloc<T>(size)), size(size) {}
|
|
640
|
+
MallocedBuffer(T* data, size_t size) : data(data), size(size) {}
|
|
641
|
+
MallocedBuffer(MallocedBuffer&& other) : data(other.data), size(other.size) {
|
|
642
|
+
other.data = nullptr;
|
|
643
|
+
}
|
|
644
|
+
MallocedBuffer& operator=(MallocedBuffer&& other) {
|
|
645
|
+
this->~MallocedBuffer();
|
|
646
|
+
return *new(this) MallocedBuffer(std::move(other));
|
|
647
|
+
}
|
|
648
|
+
~MallocedBuffer() {
|
|
649
|
+
free(data);
|
|
650
|
+
}
|
|
651
|
+
MallocedBuffer(const MallocedBuffer&) = delete;
|
|
652
|
+
MallocedBuffer& operator=(const MallocedBuffer&) = delete;
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
// Test whether some value can be called with ().
|
|
656
|
+
template <typename T>
|
|
657
|
+
concept is_callable =
|
|
658
|
+
std::is_function<T>::value || requires { &T::operator(); };
|
|
659
|
+
|
|
660
|
+
template <typename T, void (*function)(T*)>
|
|
661
|
+
struct FunctionDeleter {
|
|
662
|
+
void operator()(T* pointer) const { function(pointer); }
|
|
663
|
+
typedef std::unique_ptr<T, FunctionDeleter> Pointer;
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
template <typename T, void (*function)(T*)>
|
|
667
|
+
using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
|
|
668
|
+
|
|
669
|
+
// Convert a v8::Array into an std::vector using the callback-based API.
|
|
670
|
+
// This can be faster than calling Array::Get() repeatedly when the array
|
|
671
|
+
// has more than 2 entries.
|
|
672
|
+
// Note that iterating over an array in C++ and performing operations on each
|
|
673
|
+
// element in a C++ loop is still slower than iterating over the array in JS
|
|
674
|
+
// and calling into native in the JS loop repeatedly on each element,
|
|
675
|
+
// as of V8 11.9.
|
|
676
|
+
inline v8::Maybe<void> FromV8Array(v8::Local<v8::Context> context,
|
|
677
|
+
v8::Local<v8::Array> js_array,
|
|
678
|
+
std::vector<v8::Global<v8::Value>>* out);
|
|
679
|
+
std::vector<std::string_view> SplitString(const std::string_view in,
|
|
680
|
+
const std::string_view delim);
|
|
681
|
+
|
|
682
|
+
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
|
|
683
|
+
std::string_view str,
|
|
684
|
+
v8::Isolate* isolate = nullptr);
|
|
685
|
+
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
|
|
686
|
+
v8_inspector::StringView str,
|
|
687
|
+
v8::Isolate* isolate);
|
|
688
|
+
template <typename T, typename test_for_number =
|
|
689
|
+
typename std::enable_if<std::numeric_limits<T>::is_specialized, bool>::type>
|
|
690
|
+
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
|
|
691
|
+
const T& number,
|
|
692
|
+
v8::Isolate* isolate = nullptr);
|
|
693
|
+
template <typename T>
|
|
694
|
+
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
|
|
695
|
+
const std::vector<T>& vec,
|
|
696
|
+
v8::Isolate* isolate = nullptr);
|
|
697
|
+
template <typename T>
|
|
698
|
+
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
|
|
699
|
+
const std::set<T>& set,
|
|
700
|
+
v8::Isolate* isolate = nullptr);
|
|
701
|
+
template <typename T, typename U>
|
|
702
|
+
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
|
|
703
|
+
const std::unordered_map<T, U>& map,
|
|
704
|
+
v8::Isolate* isolate = nullptr);
|
|
705
|
+
|
|
706
|
+
// These macros expects a `Isolate* isolate` and a `Local<Context> context`
|
|
707
|
+
// to be in the scope.
|
|
708
|
+
#define READONLY_PROPERTY(obj, name, value) \
|
|
709
|
+
do { \
|
|
710
|
+
obj->DefineOwnProperty( \
|
|
711
|
+
context, FIXED_ONE_BYTE_STRING(isolate, name), value, v8::ReadOnly) \
|
|
712
|
+
.Check(); \
|
|
713
|
+
} while (0)
|
|
714
|
+
|
|
715
|
+
#define READONLY_DONT_ENUM_PROPERTY(obj, name, var) \
|
|
716
|
+
do { \
|
|
717
|
+
obj->DefineOwnProperty( \
|
|
718
|
+
context, \
|
|
719
|
+
OneByteString(isolate, name), \
|
|
720
|
+
var, \
|
|
721
|
+
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)) \
|
|
722
|
+
.Check(); \
|
|
723
|
+
} while (0)
|
|
724
|
+
|
|
725
|
+
#define READONLY_FALSE_PROPERTY(obj, name) \
|
|
726
|
+
READONLY_PROPERTY(obj, name, v8::False(isolate))
|
|
727
|
+
|
|
728
|
+
#define READONLY_TRUE_PROPERTY(obj, name) \
|
|
729
|
+
READONLY_PROPERTY(obj, name, v8::True(isolate))
|
|
730
|
+
|
|
731
|
+
#define READONLY_STRING_PROPERTY(obj, name, str) \
|
|
732
|
+
READONLY_PROPERTY(obj, name, ToV8Value(context, str).ToLocalChecked())
|
|
733
|
+
|
|
734
|
+
// Variation on NODE_DEFINE_CONSTANT that sets a String value.
|
|
735
|
+
#define NODE_DEFINE_STRING_CONSTANT(target, name, constant) \
|
|
736
|
+
do { \
|
|
737
|
+
v8::Isolate* isolate = target->GetIsolate(); \
|
|
738
|
+
v8::Local<v8::String> constant_name = \
|
|
739
|
+
v8::String::NewFromUtf8(isolate, name).ToLocalChecked(); \
|
|
740
|
+
v8::Local<v8::String> constant_value = \
|
|
741
|
+
v8::String::NewFromUtf8(isolate, constant).ToLocalChecked(); \
|
|
742
|
+
v8::PropertyAttribute constant_attributes = \
|
|
743
|
+
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); \
|
|
744
|
+
target \
|
|
745
|
+
->DefineOwnProperty(isolate->GetCurrentContext(), \
|
|
746
|
+
constant_name, \
|
|
747
|
+
constant_value, \
|
|
748
|
+
constant_attributes) \
|
|
749
|
+
.Check(); \
|
|
750
|
+
} while (0)
|
|
751
|
+
|
|
752
|
+
constexpr inline bool IsLittleEndian() {
|
|
753
|
+
return std::endian::native == std::endian::little;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
constexpr inline bool IsBigEndian() {
|
|
757
|
+
return std::endian::native == std::endian::big;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
static_assert(IsLittleEndian() || IsBigEndian(),
|
|
761
|
+
"Node.js does not support mixed-endian systems");
|
|
762
|
+
|
|
763
|
+
class SlicedArguments : public MaybeStackBuffer<v8::Local<v8::Value>> {
|
|
764
|
+
public:
|
|
765
|
+
inline explicit SlicedArguments(
|
|
766
|
+
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start = 0);
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
// Convert a v8::PersistentBase, e.g. v8::Global, to a Local, with an extra
|
|
770
|
+
// optimization for strong persistent handles.
|
|
771
|
+
class PersistentToLocal {
|
|
772
|
+
public:
|
|
773
|
+
// If persistent.IsWeak() == false, then do not call persistent.Reset()
|
|
774
|
+
// while the returned Local<T> is still in scope, it will destroy the
|
|
775
|
+
// reference to the object.
|
|
776
|
+
template <class TypeName>
|
|
777
|
+
static inline v8::Local<TypeName> Default(
|
|
778
|
+
v8::Isolate* isolate,
|
|
779
|
+
const v8::PersistentBase<TypeName>& persistent) {
|
|
780
|
+
if (persistent.IsWeak()) {
|
|
781
|
+
return PersistentToLocal::Weak(isolate, persistent);
|
|
782
|
+
} else {
|
|
783
|
+
return PersistentToLocal::Strong(persistent);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Unchecked conversion from a non-weak Persistent<T> to Local<T>,
|
|
788
|
+
// use with care!
|
|
789
|
+
//
|
|
790
|
+
// Do not call persistent.Reset() while the returned Local<T> is still in
|
|
791
|
+
// scope, it will destroy the reference to the object.
|
|
792
|
+
template <class TypeName>
|
|
793
|
+
static inline v8::Local<TypeName> Strong(
|
|
794
|
+
const v8::PersistentBase<TypeName>& persistent) {
|
|
795
|
+
DCHECK(!persistent.IsWeak());
|
|
796
|
+
return *reinterpret_cast<v8::Local<TypeName>*>(
|
|
797
|
+
const_cast<v8::PersistentBase<TypeName>*>(&persistent));
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
template <class TypeName>
|
|
801
|
+
static inline v8::Local<TypeName> Weak(
|
|
802
|
+
v8::Isolate* isolate,
|
|
803
|
+
const v8::PersistentBase<TypeName>& persistent) {
|
|
804
|
+
return v8::Local<TypeName>::New(isolate, persistent);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
// Can be used as a key for std::unordered_map when lookup performance is more
|
|
809
|
+
// important than size and the keys are statically used to avoid redundant hash
|
|
810
|
+
// computations.
|
|
811
|
+
class FastStringKey {
|
|
812
|
+
public:
|
|
813
|
+
// consteval ensures that the argument is a compile-time constant.
|
|
814
|
+
consteval explicit FastStringKey(std::string_view name);
|
|
815
|
+
// passing something that is not a compile-time constant needs explicit
|
|
816
|
+
// opt-in via this helper, as it defeats the purpose of FastStringKey.
|
|
817
|
+
static constexpr FastStringKey AllowDynamic(std::string_view name);
|
|
818
|
+
|
|
819
|
+
struct Hash {
|
|
820
|
+
constexpr size_t operator()(const FastStringKey& key) const;
|
|
821
|
+
};
|
|
822
|
+
constexpr bool operator==(const FastStringKey& other) const;
|
|
823
|
+
|
|
824
|
+
constexpr std::string_view as_string_view() const;
|
|
825
|
+
|
|
826
|
+
private:
|
|
827
|
+
constexpr explicit FastStringKey(std::string_view name, int dummy);
|
|
828
|
+
|
|
829
|
+
static constexpr size_t HashImpl(std::string_view str);
|
|
830
|
+
|
|
831
|
+
const std::string_view name_;
|
|
832
|
+
const size_t cached_hash_;
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
// Like std::static_pointer_cast but for unique_ptr with the default deleter.
|
|
836
|
+
template <typename T, typename U>
|
|
837
|
+
std::unique_ptr<T> static_unique_pointer_cast(std::unique_ptr<U>&& ptr) {
|
|
838
|
+
return std::unique_ptr<T>(static_cast<T*>(ptr.release()));
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
#define MAYBE_FIELD_PTR(ptr, field) ptr == nullptr ? nullptr : &(ptr->field)
|
|
842
|
+
|
|
843
|
+
// Returns a non-zero code if it fails to open or read the file,
|
|
844
|
+
// aborts if it fails to close the file.
|
|
845
|
+
int ReadFileSync(std::string* result, const char* path);
|
|
846
|
+
// Reads all contents of a FILE*, aborts if it fails.
|
|
847
|
+
std::vector<char> ReadFileSync(FILE* fp);
|
|
848
|
+
|
|
849
|
+
v8::Local<v8::FunctionTemplate> NewFunctionTemplate(
|
|
850
|
+
v8::Isolate* isolate,
|
|
851
|
+
v8::FunctionCallback callback,
|
|
852
|
+
v8::Local<v8::Signature> signature = v8::Local<v8::Signature>(),
|
|
853
|
+
v8::ConstructorBehavior behavior = v8::ConstructorBehavior::kAllow,
|
|
854
|
+
v8::SideEffectType side_effect = v8::SideEffectType::kHasSideEffect,
|
|
855
|
+
const v8::CFunction* c_function = nullptr);
|
|
856
|
+
|
|
857
|
+
// Convenience methods for NewFunctionTemplate().
|
|
858
|
+
void SetMethod(v8::Local<v8::Context> context,
|
|
859
|
+
v8::Local<v8::Object> that,
|
|
860
|
+
const std::string_view name,
|
|
861
|
+
v8::FunctionCallback callback);
|
|
862
|
+
// Similar to SetProtoMethod but without receiver signature checks.
|
|
863
|
+
void SetMethod(v8::Isolate* isolate,
|
|
864
|
+
v8::Local<v8::Template> that,
|
|
865
|
+
const std::string_view name,
|
|
866
|
+
v8::FunctionCallback callback);
|
|
867
|
+
|
|
868
|
+
void SetFastMethod(v8::Isolate* isolate,
|
|
869
|
+
v8::Local<v8::Template> that,
|
|
870
|
+
const std::string_view name,
|
|
871
|
+
v8::FunctionCallback slow_callback,
|
|
872
|
+
const v8::CFunction* c_function);
|
|
873
|
+
void SetFastMethod(v8::Local<v8::Context> context,
|
|
874
|
+
v8::Local<v8::Object> that,
|
|
875
|
+
const std::string_view name,
|
|
876
|
+
v8::FunctionCallback slow_callback,
|
|
877
|
+
const v8::CFunction* c_function);
|
|
878
|
+
void SetFastMethod(v8::Isolate* isolate,
|
|
879
|
+
v8::Local<v8::Template> that,
|
|
880
|
+
const std::string_view name,
|
|
881
|
+
v8::FunctionCallback slow_callback,
|
|
882
|
+
const v8::MemorySpan<const v8::CFunction>& methods);
|
|
883
|
+
void SetFastMethodNoSideEffect(v8::Isolate* isolate,
|
|
884
|
+
v8::Local<v8::Template> that,
|
|
885
|
+
const std::string_view name,
|
|
886
|
+
v8::FunctionCallback slow_callback,
|
|
887
|
+
const v8::CFunction* c_function);
|
|
888
|
+
void SetFastMethodNoSideEffect(v8::Local<v8::Context> context,
|
|
889
|
+
v8::Local<v8::Object> that,
|
|
890
|
+
const std::string_view name,
|
|
891
|
+
v8::FunctionCallback slow_callback,
|
|
892
|
+
const v8::CFunction* c_function);
|
|
893
|
+
void SetFastMethodNoSideEffect(
|
|
894
|
+
v8::Isolate* isolate,
|
|
895
|
+
v8::Local<v8::Template> that,
|
|
896
|
+
const std::string_view name,
|
|
897
|
+
v8::FunctionCallback slow_callback,
|
|
898
|
+
const v8::MemorySpan<const v8::CFunction>& methods);
|
|
899
|
+
void SetProtoMethod(v8::Isolate* isolate,
|
|
900
|
+
v8::Local<v8::FunctionTemplate> that,
|
|
901
|
+
const std::string_view name,
|
|
902
|
+
v8::FunctionCallback callback);
|
|
903
|
+
|
|
904
|
+
void SetInstanceMethod(v8::Isolate* isolate,
|
|
905
|
+
v8::Local<v8::FunctionTemplate> that,
|
|
906
|
+
const std::string_view name,
|
|
907
|
+
v8::FunctionCallback callback);
|
|
908
|
+
|
|
909
|
+
// Safe variants denote the function has no side effects.
|
|
910
|
+
void SetMethodNoSideEffect(v8::Local<v8::Context> context,
|
|
911
|
+
v8::Local<v8::Object> that,
|
|
912
|
+
const std::string_view name,
|
|
913
|
+
v8::FunctionCallback callback);
|
|
914
|
+
void SetProtoMethodNoSideEffect(v8::Isolate* isolate,
|
|
915
|
+
v8::Local<v8::FunctionTemplate> that,
|
|
916
|
+
const std::string_view name,
|
|
917
|
+
v8::FunctionCallback callback);
|
|
918
|
+
void SetMethodNoSideEffect(v8::Isolate* isolate,
|
|
919
|
+
v8::Local<v8::Template> that,
|
|
920
|
+
const std::string_view name,
|
|
921
|
+
v8::FunctionCallback callback);
|
|
922
|
+
|
|
923
|
+
enum class SetConstructorFunctionFlag {
|
|
924
|
+
NONE,
|
|
925
|
+
SET_CLASS_NAME,
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
void SetConstructorFunction(v8::Local<v8::Context> context,
|
|
929
|
+
v8::Local<v8::Object> that,
|
|
930
|
+
const char* name,
|
|
931
|
+
v8::Local<v8::FunctionTemplate> tmpl,
|
|
932
|
+
SetConstructorFunctionFlag flag =
|
|
933
|
+
SetConstructorFunctionFlag::SET_CLASS_NAME);
|
|
934
|
+
|
|
935
|
+
void SetConstructorFunction(v8::Local<v8::Context> context,
|
|
936
|
+
v8::Local<v8::Object> that,
|
|
937
|
+
v8::Local<v8::String> name,
|
|
938
|
+
v8::Local<v8::FunctionTemplate> tmpl,
|
|
939
|
+
SetConstructorFunctionFlag flag =
|
|
940
|
+
SetConstructorFunctionFlag::SET_CLASS_NAME);
|
|
941
|
+
|
|
942
|
+
void SetConstructorFunction(v8::Isolate* isolate,
|
|
943
|
+
v8::Local<v8::Template> that,
|
|
944
|
+
const char* name,
|
|
945
|
+
v8::Local<v8::FunctionTemplate> tmpl,
|
|
946
|
+
SetConstructorFunctionFlag flag =
|
|
947
|
+
SetConstructorFunctionFlag::SET_CLASS_NAME);
|
|
948
|
+
|
|
949
|
+
void SetConstructorFunction(v8::Isolate* isolate,
|
|
950
|
+
v8::Local<v8::Template> that,
|
|
951
|
+
v8::Local<v8::String> name,
|
|
952
|
+
v8::Local<v8::FunctionTemplate> tmpl,
|
|
953
|
+
SetConstructorFunctionFlag flag =
|
|
954
|
+
SetConstructorFunctionFlag::SET_CLASS_NAME);
|
|
955
|
+
|
|
956
|
+
// Like RAIIIsolate, except doesn't enter the isolate while it's in scope.
|
|
957
|
+
class RAIIIsolateWithoutEntering {
|
|
958
|
+
public:
|
|
959
|
+
explicit RAIIIsolateWithoutEntering(const SnapshotData* data = nullptr);
|
|
960
|
+
~RAIIIsolateWithoutEntering();
|
|
961
|
+
|
|
962
|
+
v8::Isolate* get() const { return isolate_; }
|
|
963
|
+
|
|
964
|
+
private:
|
|
965
|
+
std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_;
|
|
966
|
+
v8::Isolate* isolate_;
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
// Simple RAII class to spin up a v8::Isolate instance and enter it
|
|
970
|
+
// immediately.
|
|
971
|
+
class RAIIIsolate {
|
|
972
|
+
public:
|
|
973
|
+
explicit RAIIIsolate(const SnapshotData* data = nullptr);
|
|
974
|
+
~RAIIIsolate();
|
|
975
|
+
|
|
976
|
+
v8::Isolate* get() const { return isolate_.get(); }
|
|
977
|
+
|
|
978
|
+
private:
|
|
979
|
+
RAIIIsolateWithoutEntering isolate_;
|
|
980
|
+
v8::Isolate::Scope isolate_scope_;
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
std::string DetermineSpecificErrorType(Environment* env,
|
|
984
|
+
v8::Local<v8::Value> input);
|
|
985
|
+
|
|
986
|
+
v8::Maybe<int32_t> GetValidatedFd(Environment* env, v8::Local<v8::Value> input);
|
|
987
|
+
v8::Maybe<int> GetValidFileMode(Environment* env,
|
|
988
|
+
v8::Local<v8::Value> input,
|
|
989
|
+
uv_fs_type type);
|
|
990
|
+
|
|
991
|
+
class JSONOutputStream final : public v8::OutputStream {
|
|
992
|
+
public:
|
|
993
|
+
JSONOutputStream() = default;
|
|
994
|
+
|
|
995
|
+
int GetChunkSize() override { return 65536; }
|
|
996
|
+
|
|
997
|
+
void EndOfStream() override {}
|
|
998
|
+
|
|
999
|
+
WriteResult WriteAsciiChunk(char* data, const int size) override {
|
|
1000
|
+
out_stream_.write(data, size);
|
|
1001
|
+
return kContinue;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
std::ostringstream& out_stream() { return out_stream_; }
|
|
1005
|
+
|
|
1006
|
+
private:
|
|
1007
|
+
std::ostringstream out_stream_;
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
#ifdef _WIN32
|
|
1011
|
+
// Returns true if OS==Windows and filename ends in .bat or .cmd,
|
|
1012
|
+
// case insensitive.
|
|
1013
|
+
inline bool IsWindowsBatchFile(const char* filename);
|
|
1014
|
+
inline std::wstring ConvertToWideString(const std::string& str, UINT code_page);
|
|
1015
|
+
#endif // _WIN32
|
|
1016
|
+
|
|
1017
|
+
} // namespace node
|
|
1018
|
+
|
|
1019
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
1020
|
+
|
|
1021
|
+
#endif // SRC_UTIL_H_
|