@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,244 @@
|
|
|
1
|
+
#ifndef SRC_ALIASED_BUFFER_INL_H_
|
|
2
|
+
#define SRC_ALIASED_BUFFER_INL_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "aliased_buffer.h"
|
|
7
|
+
#include "memory_tracker-inl.h"
|
|
8
|
+
#include "util-inl.h"
|
|
9
|
+
|
|
10
|
+
namespace node {
|
|
11
|
+
|
|
12
|
+
typedef size_t AliasedBufferIndex;
|
|
13
|
+
|
|
14
|
+
template <typename NativeT, typename V8T>
|
|
15
|
+
AliasedBufferBase<NativeT, V8T>::AliasedBufferBase(
|
|
16
|
+
v8::Isolate* isolate, const size_t count, const AliasedBufferIndex* index)
|
|
17
|
+
: isolate_(isolate), count_(count), byte_offset_(0), index_(index) {
|
|
18
|
+
CHECK_GT(count, 0);
|
|
19
|
+
if (index != nullptr) {
|
|
20
|
+
// Will be deserialized later.
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const v8::HandleScope handle_scope(isolate_);
|
|
24
|
+
const size_t size_in_bytes =
|
|
25
|
+
MultiplyWithOverflowCheck(sizeof(NativeT), count);
|
|
26
|
+
|
|
27
|
+
// allocate v8 ArrayBuffer
|
|
28
|
+
v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate_, size_in_bytes);
|
|
29
|
+
buffer_ = static_cast<NativeT*>(ab->Data());
|
|
30
|
+
|
|
31
|
+
// allocate v8 TypedArray
|
|
32
|
+
v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count);
|
|
33
|
+
js_array_ = v8::Global<V8T>(isolate, js_array);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
template <typename NativeT, typename V8T>
|
|
37
|
+
AliasedBufferBase<NativeT, V8T>::AliasedBufferBase(
|
|
38
|
+
v8::Isolate* isolate,
|
|
39
|
+
const size_t byte_offset,
|
|
40
|
+
const size_t count,
|
|
41
|
+
const AliasedBufferBase<uint8_t, v8::Uint8Array>& backing_buffer,
|
|
42
|
+
const AliasedBufferIndex* index)
|
|
43
|
+
: isolate_(isolate),
|
|
44
|
+
count_(count),
|
|
45
|
+
byte_offset_(byte_offset),
|
|
46
|
+
index_(index) {
|
|
47
|
+
if (index != nullptr) {
|
|
48
|
+
// Will be deserialized later.
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const v8::HandleScope handle_scope(isolate_);
|
|
52
|
+
v8::Local<v8::ArrayBuffer> ab = backing_buffer.GetArrayBuffer();
|
|
53
|
+
|
|
54
|
+
// validate that the byte_offset is aligned with sizeof(NativeT)
|
|
55
|
+
CHECK_EQ(byte_offset & (sizeof(NativeT) - 1), 0);
|
|
56
|
+
// validate this fits inside the backing buffer
|
|
57
|
+
CHECK_LE(MultiplyWithOverflowCheck(sizeof(NativeT), count),
|
|
58
|
+
ab->ByteLength() - byte_offset);
|
|
59
|
+
|
|
60
|
+
buffer_ = reinterpret_cast<NativeT*>(
|
|
61
|
+
const_cast<uint8_t*>(backing_buffer.GetNativeBuffer() + byte_offset));
|
|
62
|
+
|
|
63
|
+
v8::Local<V8T> js_array = V8T::New(ab, byte_offset, count);
|
|
64
|
+
js_array_ = v8::Global<V8T>(isolate, js_array);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
template <typename NativeT, typename V8T>
|
|
68
|
+
AliasedBufferBase<NativeT, V8T>::AliasedBufferBase(
|
|
69
|
+
const AliasedBufferBase& that)
|
|
70
|
+
: isolate_(that.isolate_),
|
|
71
|
+
count_(that.count_),
|
|
72
|
+
byte_offset_(that.byte_offset_),
|
|
73
|
+
buffer_(that.buffer_) {
|
|
74
|
+
js_array_ = v8::Global<V8T>(that.isolate_, that.GetJSArray());
|
|
75
|
+
DCHECK(is_valid());
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
template <typename NativeT, typename V8T>
|
|
79
|
+
AliasedBufferIndex AliasedBufferBase<NativeT, V8T>::Serialize(
|
|
80
|
+
v8::Local<v8::Context> context, v8::SnapshotCreator* creator) {
|
|
81
|
+
DCHECK(is_valid());
|
|
82
|
+
return creator->AddData(context, GetJSArray());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
template <typename NativeT, typename V8T>
|
|
86
|
+
inline void AliasedBufferBase<NativeT, V8T>::Deserialize(
|
|
87
|
+
v8::Local<v8::Context> context) {
|
|
88
|
+
DCHECK_NOT_NULL(index_);
|
|
89
|
+
v8::Local<V8T> arr =
|
|
90
|
+
context->GetDataFromSnapshotOnce<V8T>(*index_).ToLocalChecked();
|
|
91
|
+
// These may not hold true for AliasedBuffers that have grown, so should
|
|
92
|
+
// be removed when we expand the snapshot support.
|
|
93
|
+
DCHECK_EQ(count_, arr->Length());
|
|
94
|
+
DCHECK_EQ(byte_offset_, arr->ByteOffset());
|
|
95
|
+
uint8_t* raw = static_cast<uint8_t*>(arr->Buffer()->Data());
|
|
96
|
+
buffer_ = reinterpret_cast<NativeT*>(raw + byte_offset_);
|
|
97
|
+
js_array_.Reset(isolate_, arr);
|
|
98
|
+
index_ = nullptr;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
template <typename NativeT, typename V8T>
|
|
102
|
+
AliasedBufferBase<NativeT, V8T>& AliasedBufferBase<NativeT, V8T>::operator=(
|
|
103
|
+
AliasedBufferBase<NativeT, V8T>&& that) noexcept {
|
|
104
|
+
DCHECK(is_valid());
|
|
105
|
+
this->~AliasedBufferBase();
|
|
106
|
+
isolate_ = that.isolate_;
|
|
107
|
+
count_ = that.count_;
|
|
108
|
+
byte_offset_ = that.byte_offset_;
|
|
109
|
+
buffer_ = that.buffer_;
|
|
110
|
+
|
|
111
|
+
js_array_.Reset(isolate_, that.js_array_.Get(isolate_));
|
|
112
|
+
|
|
113
|
+
that.buffer_ = nullptr;
|
|
114
|
+
that.js_array_.Reset();
|
|
115
|
+
return *this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
template <typename NativeT, typename V8T>
|
|
119
|
+
v8::Local<V8T> AliasedBufferBase<NativeT, V8T>::GetJSArray() const {
|
|
120
|
+
DCHECK(is_valid());
|
|
121
|
+
return js_array_.Get(isolate_);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
template <typename NativeT, typename V8T>
|
|
125
|
+
void AliasedBufferBase<NativeT, V8T>::Release() {
|
|
126
|
+
DCHECK_NULL(index_);
|
|
127
|
+
js_array_.Reset();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
template <typename NativeT, typename V8T>
|
|
131
|
+
inline void AliasedBufferBase<NativeT, V8T>::MakeWeak() {
|
|
132
|
+
DCHECK(is_valid());
|
|
133
|
+
js_array_.SetWeak();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
template <typename NativeT, typename V8T>
|
|
137
|
+
v8::Local<v8::ArrayBuffer> AliasedBufferBase<NativeT, V8T>::GetArrayBuffer()
|
|
138
|
+
const {
|
|
139
|
+
return GetJSArray()->Buffer();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
template <typename NativeT, typename V8T>
|
|
143
|
+
inline const NativeT* AliasedBufferBase<NativeT, V8T>::GetNativeBuffer() const {
|
|
144
|
+
DCHECK(is_valid());
|
|
145
|
+
return buffer_;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
template <typename NativeT, typename V8T>
|
|
149
|
+
inline const NativeT* AliasedBufferBase<NativeT, V8T>::operator*() const {
|
|
150
|
+
return GetNativeBuffer();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
template <typename NativeT, typename V8T>
|
|
154
|
+
inline void AliasedBufferBase<NativeT, V8T>::SetValue(const size_t index,
|
|
155
|
+
NativeT value) {
|
|
156
|
+
DCHECK_LT(index, count_);
|
|
157
|
+
DCHECK(is_valid());
|
|
158
|
+
buffer_[index] = value;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
template <typename NativeT, typename V8T>
|
|
162
|
+
inline const NativeT AliasedBufferBase<NativeT, V8T>::GetValue(
|
|
163
|
+
const size_t index) const {
|
|
164
|
+
DCHECK(is_valid());
|
|
165
|
+
DCHECK_LT(index, count_);
|
|
166
|
+
return buffer_[index];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
template <typename NativeT, typename V8T>
|
|
170
|
+
typename AliasedBufferBase<NativeT, V8T>::Reference
|
|
171
|
+
AliasedBufferBase<NativeT, V8T>::operator[](size_t index) {
|
|
172
|
+
DCHECK(is_valid());
|
|
173
|
+
return Reference(this, index);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
template <typename NativeT, typename V8T>
|
|
177
|
+
NativeT AliasedBufferBase<NativeT, V8T>::operator[](size_t index) const {
|
|
178
|
+
return GetValue(index);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
template <typename NativeT, typename V8T>
|
|
182
|
+
size_t AliasedBufferBase<NativeT, V8T>::Length() const {
|
|
183
|
+
return count_;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
template <typename NativeT, typename V8T>
|
|
187
|
+
void AliasedBufferBase<NativeT, V8T>::reserve(size_t new_capacity) {
|
|
188
|
+
DCHECK(is_valid());
|
|
189
|
+
DCHECK_GE(new_capacity, count_);
|
|
190
|
+
DCHECK_EQ(byte_offset_, 0);
|
|
191
|
+
const v8::HandleScope handle_scope(isolate_);
|
|
192
|
+
|
|
193
|
+
const size_t old_size_in_bytes = sizeof(NativeT) * count_;
|
|
194
|
+
const size_t new_size_in_bytes =
|
|
195
|
+
MultiplyWithOverflowCheck(sizeof(NativeT), new_capacity);
|
|
196
|
+
|
|
197
|
+
// allocate v8 new ArrayBuffer
|
|
198
|
+
v8::Local<v8::ArrayBuffer> ab =
|
|
199
|
+
v8::ArrayBuffer::New(isolate_, new_size_in_bytes);
|
|
200
|
+
|
|
201
|
+
// allocate new native buffer
|
|
202
|
+
NativeT* new_buffer = static_cast<NativeT*>(ab->Data());
|
|
203
|
+
// copy old content
|
|
204
|
+
memcpy(new_buffer, buffer_, old_size_in_bytes);
|
|
205
|
+
|
|
206
|
+
// allocate v8 TypedArray
|
|
207
|
+
v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, new_capacity);
|
|
208
|
+
|
|
209
|
+
// move over old v8 TypedArray
|
|
210
|
+
js_array_ = std::move(v8::Global<V8T>(isolate_, js_array));
|
|
211
|
+
|
|
212
|
+
buffer_ = new_buffer;
|
|
213
|
+
count_ = new_capacity;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
template <typename NativeT, typename V8T>
|
|
217
|
+
inline bool AliasedBufferBase<NativeT, V8T>::is_valid() const {
|
|
218
|
+
return index_ == nullptr && !js_array_.IsEmpty();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
template <typename NativeT, typename V8T>
|
|
222
|
+
inline size_t AliasedBufferBase<NativeT, V8T>::SelfSize() const {
|
|
223
|
+
return sizeof(*this);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
#define VM(NativeT, V8T) \
|
|
227
|
+
template <> \
|
|
228
|
+
inline const char* AliasedBufferBase<NativeT, v8::V8T>::MemoryInfoName() \
|
|
229
|
+
const { \
|
|
230
|
+
return "Aliased" #V8T; \
|
|
231
|
+
} \
|
|
232
|
+
template <> \
|
|
233
|
+
inline void AliasedBufferBase<NativeT, v8::V8T>::MemoryInfo( \
|
|
234
|
+
node::MemoryTracker* tracker) const { \
|
|
235
|
+
tracker->TrackField("js_array", js_array_); \
|
|
236
|
+
}
|
|
237
|
+
ALIASED_BUFFER_LIST(VM)
|
|
238
|
+
#undef VM
|
|
239
|
+
|
|
240
|
+
} // namespace node
|
|
241
|
+
|
|
242
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
243
|
+
|
|
244
|
+
#endif // SRC_ALIASED_BUFFER_INL_H_
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#ifndef SRC_ALIASED_BUFFER_H_
|
|
2
|
+
#define SRC_ALIASED_BUFFER_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <cinttypes>
|
|
7
|
+
#include "memory_tracker.h"
|
|
8
|
+
#include "v8.h"
|
|
9
|
+
|
|
10
|
+
namespace node {
|
|
11
|
+
|
|
12
|
+
typedef size_t AliasedBufferIndex;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Do not use this class directly when creating instances of it - use the
|
|
16
|
+
* Aliased*Array defined at the end of this file instead.
|
|
17
|
+
*
|
|
18
|
+
* This class encapsulates the technique of having a native buffer mapped to
|
|
19
|
+
* a JS object. Writes to the native buffer can happen efficiently without
|
|
20
|
+
* going through JS, and the data is then available to user's via the exposed
|
|
21
|
+
* JS object.
|
|
22
|
+
*
|
|
23
|
+
* While this technique is computationally efficient, it is effectively a
|
|
24
|
+
* write to JS program state w/out going through the standard
|
|
25
|
+
* (monitored) API. Thus, any VM capabilities to detect the modification are
|
|
26
|
+
* circumvented.
|
|
27
|
+
*
|
|
28
|
+
* The encapsulation herein provides a placeholder where such writes can be
|
|
29
|
+
* observed. Any notification APIs will be left as a future exercise.
|
|
30
|
+
*/
|
|
31
|
+
template <class NativeT, class V8T>
|
|
32
|
+
class AliasedBufferBase final : public MemoryRetainer {
|
|
33
|
+
public:
|
|
34
|
+
static_assert(std::is_scalar_v<NativeT>);
|
|
35
|
+
|
|
36
|
+
AliasedBufferBase(v8::Isolate* isolate,
|
|
37
|
+
size_t count,
|
|
38
|
+
const AliasedBufferIndex* index = nullptr);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Create an AliasedBufferBase over a sub-region of another aliased buffer.
|
|
42
|
+
* The two will share a v8::ArrayBuffer instance &
|
|
43
|
+
* a native buffer, but will each read/write to different sections of the
|
|
44
|
+
* native buffer.
|
|
45
|
+
*
|
|
46
|
+
* Note that byte_offset must be aligned by sizeof(NativeT).
|
|
47
|
+
*/
|
|
48
|
+
// TODO(refack): refactor into a non-owning `AliasedBufferBaseView`
|
|
49
|
+
AliasedBufferBase(
|
|
50
|
+
v8::Isolate* isolate,
|
|
51
|
+
size_t byte_offset,
|
|
52
|
+
size_t count,
|
|
53
|
+
const AliasedBufferBase<uint8_t, v8::Uint8Array>& backing_buffer,
|
|
54
|
+
const AliasedBufferIndex* index = nullptr);
|
|
55
|
+
|
|
56
|
+
AliasedBufferBase(const AliasedBufferBase& that);
|
|
57
|
+
|
|
58
|
+
AliasedBufferIndex Serialize(v8::Local<v8::Context> context,
|
|
59
|
+
v8::SnapshotCreator* creator);
|
|
60
|
+
|
|
61
|
+
void Deserialize(v8::Local<v8::Context> context);
|
|
62
|
+
|
|
63
|
+
AliasedBufferBase& operator=(AliasedBufferBase&& that) noexcept;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Helper class that is returned from operator[] to support assignment into
|
|
67
|
+
* a specified location.
|
|
68
|
+
*/
|
|
69
|
+
class Reference {
|
|
70
|
+
public:
|
|
71
|
+
Reference(AliasedBufferBase* aliased_buffer, const size_t index)
|
|
72
|
+
: aliased_buffer_(aliased_buffer), index_(index) {}
|
|
73
|
+
|
|
74
|
+
Reference(const Reference& that)
|
|
75
|
+
: aliased_buffer_(that.aliased_buffer_),
|
|
76
|
+
index_(that.index_) {
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Reference& operator=(const NativeT& val) {
|
|
80
|
+
aliased_buffer_->SetValue(index_, val);
|
|
81
|
+
return *this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Reference& operator=(const Reference& val) {
|
|
85
|
+
return *this = static_cast<NativeT>(val);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
operator NativeT() const {
|
|
89
|
+
return aliased_buffer_->GetValue(index_);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Reference& operator+=(const NativeT& val) {
|
|
93
|
+
const NativeT current = aliased_buffer_->GetValue(index_);
|
|
94
|
+
aliased_buffer_->SetValue(index_, current + val);
|
|
95
|
+
return *this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
Reference& operator+=(const Reference& val) {
|
|
99
|
+
return this->operator+=(static_cast<NativeT>(val));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
Reference& operator-=(const NativeT& val) {
|
|
103
|
+
const NativeT current = aliased_buffer_->GetValue(index_);
|
|
104
|
+
aliased_buffer_->SetValue(index_, current - val);
|
|
105
|
+
return *this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private:
|
|
109
|
+
AliasedBufferBase* aliased_buffer_;
|
|
110
|
+
size_t index_;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get the underlying v8 TypedArray overlaid on top of the native buffer
|
|
115
|
+
*/
|
|
116
|
+
v8::Local<V8T> GetJSArray() const;
|
|
117
|
+
|
|
118
|
+
void Release();
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Make the global reference to the typed array weak. The caller must make
|
|
122
|
+
* sure that no operation can be done on the AliasedBuffer when the typed
|
|
123
|
+
* array becomes unreachable. Usually this means the caller must maintain
|
|
124
|
+
* a JS reference to the typed array from JS object.
|
|
125
|
+
*/
|
|
126
|
+
void MakeWeak();
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get the underlying v8::ArrayBuffer underlying the TypedArray and
|
|
130
|
+
* overlaying the native buffer
|
|
131
|
+
*/
|
|
132
|
+
v8::Local<v8::ArrayBuffer> GetArrayBuffer() const;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get the underlying native buffer. Note that all reads/writes should occur
|
|
136
|
+
* through the GetValue/SetValue/operator[] methods
|
|
137
|
+
*/
|
|
138
|
+
const NativeT* GetNativeBuffer() const;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Synonym for GetBuffer()
|
|
142
|
+
*/
|
|
143
|
+
const NativeT* operator*() const;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Set position index to given value.
|
|
147
|
+
*/
|
|
148
|
+
void SetValue(size_t index, NativeT value);
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get value at position index
|
|
152
|
+
*/
|
|
153
|
+
const NativeT GetValue(size_t index) const;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Effectively, a synonym for GetValue/SetValue
|
|
157
|
+
*/
|
|
158
|
+
Reference operator[](size_t index);
|
|
159
|
+
|
|
160
|
+
NativeT operator[](size_t index) const;
|
|
161
|
+
|
|
162
|
+
size_t Length() const;
|
|
163
|
+
|
|
164
|
+
// Should only be used to extend the array.
|
|
165
|
+
// Should only be used on an owning array, not one created as a sub array of
|
|
166
|
+
// an owning `AliasedBufferBase`.
|
|
167
|
+
void reserve(size_t new_capacity);
|
|
168
|
+
|
|
169
|
+
size_t SelfSize() const override;
|
|
170
|
+
|
|
171
|
+
const char* MemoryInfoName() const override;
|
|
172
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
173
|
+
|
|
174
|
+
private:
|
|
175
|
+
bool is_valid() const;
|
|
176
|
+
v8::Isolate* isolate_ = nullptr;
|
|
177
|
+
size_t count_ = 0;
|
|
178
|
+
size_t byte_offset_ = 0;
|
|
179
|
+
NativeT* buffer_ = nullptr;
|
|
180
|
+
v8::Global<V8T> js_array_;
|
|
181
|
+
|
|
182
|
+
// Deserialize data
|
|
183
|
+
const AliasedBufferIndex* index_ = nullptr;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
#define ALIASED_BUFFER_LIST(V) \
|
|
187
|
+
V(int8_t, Int8Array) \
|
|
188
|
+
V(uint8_t, Uint8Array) \
|
|
189
|
+
V(int16_t, Int16Array) \
|
|
190
|
+
V(uint16_t, Uint16Array) \
|
|
191
|
+
V(int32_t, Int32Array) \
|
|
192
|
+
V(uint32_t, Uint32Array) \
|
|
193
|
+
V(float, Float32Array) \
|
|
194
|
+
V(double, Float64Array) \
|
|
195
|
+
V(int64_t, BigInt64Array)
|
|
196
|
+
|
|
197
|
+
#define V(NativeT, V8T) \
|
|
198
|
+
typedef AliasedBufferBase<NativeT, v8::V8T> Aliased##V8T;
|
|
199
|
+
ALIASED_BUFFER_LIST(V)
|
|
200
|
+
#undef V
|
|
201
|
+
|
|
202
|
+
} // namespace node
|
|
203
|
+
|
|
204
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
205
|
+
|
|
206
|
+
#endif // SRC_ALIASED_BUFFER_H_
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#ifndef SRC_ALIASED_STRUCT_INL_H_
|
|
2
|
+
#define SRC_ALIASED_STRUCT_INL_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "aliased_struct.h"
|
|
7
|
+
#include "v8.h"
|
|
8
|
+
#include <memory>
|
|
9
|
+
|
|
10
|
+
namespace node {
|
|
11
|
+
|
|
12
|
+
template <typename T>
|
|
13
|
+
template <typename... Args>
|
|
14
|
+
AliasedStruct<T>::AliasedStruct(v8::Isolate* isolate, Args&&... args)
|
|
15
|
+
: isolate_(isolate) {
|
|
16
|
+
const v8::HandleScope handle_scope(isolate);
|
|
17
|
+
|
|
18
|
+
store_ = v8::ArrayBuffer::NewBackingStore(isolate, sizeof(T));
|
|
19
|
+
ptr_ = new (store_->Data()) T(std::forward<Args>(args)...);
|
|
20
|
+
DCHECK_NOT_NULL(ptr_);
|
|
21
|
+
|
|
22
|
+
v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(isolate, store_);
|
|
23
|
+
buffer_ = v8::Global<v8::ArrayBuffer>(isolate, buffer);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
template <typename T>
|
|
27
|
+
AliasedStruct<T>::AliasedStruct(const AliasedStruct& that)
|
|
28
|
+
: AliasedStruct(that.isolate_, *that) {}
|
|
29
|
+
|
|
30
|
+
template <typename T>
|
|
31
|
+
AliasedStruct<T>& AliasedStruct<T>::operator=(
|
|
32
|
+
AliasedStruct<T>&& that) noexcept {
|
|
33
|
+
this->~AliasedStruct();
|
|
34
|
+
isolate_ = that.isolate_;
|
|
35
|
+
store_ = that.store_;
|
|
36
|
+
ptr_ = that.ptr_;
|
|
37
|
+
|
|
38
|
+
buffer_ = std::move(that.buffer_);
|
|
39
|
+
|
|
40
|
+
that.ptr_ = nullptr;
|
|
41
|
+
that.store_.reset();
|
|
42
|
+
return *this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
template <typename T>
|
|
46
|
+
AliasedStruct<T>::~AliasedStruct() {
|
|
47
|
+
if (ptr_ != nullptr) ptr_->~T();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
} // namespace node
|
|
51
|
+
|
|
52
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
53
|
+
|
|
54
|
+
#endif // SRC_ALIASED_STRUCT_INL_H_
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#ifndef SRC_ALIASED_STRUCT_H_
|
|
2
|
+
#define SRC_ALIASED_STRUCT_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "node_internals.h"
|
|
7
|
+
#include "v8.h"
|
|
8
|
+
#include <memory>
|
|
9
|
+
|
|
10
|
+
namespace node {
|
|
11
|
+
|
|
12
|
+
// AliasedStruct is a utility that allows uses a V8 Backing Store
|
|
13
|
+
// to be exposed to the C++/C side as a struct and to the
|
|
14
|
+
// JavaScript side as an ArrayBuffer to efficiently share
|
|
15
|
+
// data without marshalling. It is similar in nature to
|
|
16
|
+
// AliasedBuffer.
|
|
17
|
+
//
|
|
18
|
+
// struct Foo { int x; }
|
|
19
|
+
//
|
|
20
|
+
// AliasedStruct<Foo> foo;
|
|
21
|
+
// foo->x = 1;
|
|
22
|
+
//
|
|
23
|
+
// Local<ArrayBuffer> ab = foo.GetArrayBuffer();
|
|
24
|
+
template <typename T>
|
|
25
|
+
class AliasedStruct final {
|
|
26
|
+
public:
|
|
27
|
+
template <typename... Args>
|
|
28
|
+
explicit AliasedStruct(v8::Isolate* isolate, Args&&... args);
|
|
29
|
+
|
|
30
|
+
inline AliasedStruct(const AliasedStruct& that);
|
|
31
|
+
|
|
32
|
+
inline ~AliasedStruct();
|
|
33
|
+
|
|
34
|
+
inline AliasedStruct& operator=(AliasedStruct&& that) noexcept;
|
|
35
|
+
|
|
36
|
+
v8::Local<v8::ArrayBuffer> GetArrayBuffer() const {
|
|
37
|
+
return buffer_.Get(isolate_);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const T* Data() const { return ptr_; }
|
|
41
|
+
|
|
42
|
+
T* Data() { return ptr_; }
|
|
43
|
+
|
|
44
|
+
const T& operator*() const { return *ptr_; }
|
|
45
|
+
|
|
46
|
+
T& operator*() { return *ptr_; }
|
|
47
|
+
|
|
48
|
+
const T* operator->() const { return ptr_; }
|
|
49
|
+
|
|
50
|
+
T* operator->() { return ptr_; }
|
|
51
|
+
|
|
52
|
+
private:
|
|
53
|
+
v8::Isolate* isolate_;
|
|
54
|
+
std::shared_ptr<v8::BackingStore> store_;
|
|
55
|
+
T* ptr_;
|
|
56
|
+
v8::Global<v8::ArrayBuffer> buffer_;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace node
|
|
60
|
+
|
|
61
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
62
|
+
|
|
63
|
+
#endif // SRC_ALIASED_STRUCT_H_
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#ifndef SRC_ASYNC_CONTEXT_FRAME_H_
|
|
2
|
+
#define SRC_ASYNC_CONTEXT_FRAME_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "base_object.h"
|
|
7
|
+
#include "v8.h"
|
|
8
|
+
|
|
9
|
+
#include <cstdint>
|
|
10
|
+
|
|
11
|
+
namespace node {
|
|
12
|
+
namespace async_context_frame {
|
|
13
|
+
|
|
14
|
+
class Scope {
|
|
15
|
+
public:
|
|
16
|
+
explicit Scope(v8::Isolate* isolate, v8::Local<v8::Value> object);
|
|
17
|
+
~Scope();
|
|
18
|
+
|
|
19
|
+
private:
|
|
20
|
+
v8::Isolate* isolate_;
|
|
21
|
+
v8::Global<v8::Value> prior_;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
v8::Local<v8::Value> current(v8::Isolate* isolate);
|
|
25
|
+
void set(v8::Isolate* isolate, v8::Local<v8::Value> value);
|
|
26
|
+
v8::Local<v8::Value> exchange(v8::Isolate* isolate, v8::Local<v8::Value> value);
|
|
27
|
+
|
|
28
|
+
} // namespace async_context_frame
|
|
29
|
+
} // namespace node
|
|
30
|
+
|
|
31
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
32
|
+
|
|
33
|
+
#endif // SRC_ASYNC_CONTEXT_FRAME_H_
|