@encharm/cws 4.5.1 → 4.5.3
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/README.md +3 -5
- package/binding.gyp +1 -1
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +20 -0
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +931 -0
- package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +20 -0
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +931 -0
- package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
- package/dist/bindings/cws_linux_x64_node137.node +0 -0
- package/dist/bindings/cws_win32_x64_node137.node +0 -0
- package/package.json +1 -1
- package/src/Addon.h +6 -1
- package/src/headers/24/acorn_version.h +6 -0
- package/src/headers/24/addon_permission.h +31 -0
- package/src/headers/24/agent.h +195 -0
- package/src/headers/24/aliased_buffer-inl.h +244 -0
- package/src/headers/24/aliased_buffer.h +206 -0
- package/src/headers/24/aliased_struct-inl.h +54 -0
- package/src/headers/24/aliased_struct.h +63 -0
- package/src/headers/24/amaro_version.h +6 -0
- package/src/headers/24/application.h +165 -0
- package/src/headers/24/async_context_frame.h +33 -0
- package/src/headers/24/async_wrap-inl.h +96 -0
- package/src/headers/24/async_wrap.h +244 -0
- package/src/headers/24/base_object-inl.h +330 -0
- package/src/headers/24/base_object.h +338 -0
- package/src/headers/24/base_object_types.h +74 -0
- package/src/headers/24/bindingdata.h +272 -0
- package/src/headers/24/blob_serializer_deserializer-inl.h +385 -0
- package/src/headers/24/blob_serializer_deserializer.h +132 -0
- package/src/headers/24/callback_queue-inl.h +97 -0
- package/src/headers/24/callback_queue.h +79 -0
- package/src/headers/24/cares_wrap.h +447 -0
- package/src/headers/24/child_process_permission.h +31 -0
- package/src/headers/24/cid.h +127 -0
- package/src/headers/24/cjs_module_lexer_version.h +6 -0
- package/src/headers/24/cleanup_queue-inl.h +36 -0
- package/src/headers/24/cleanup_queue.h +79 -0
- package/src/headers/24/compile_cache.h +113 -0
- package/src/headers/24/connect_wrap.h +26 -0
- package/src/headers/24/connection_wrap.h +30 -0
- package/src/headers/24/cppgc_helpers-inl.h +65 -0
- package/src/headers/24/cppgc_helpers.h +162 -0
- package/src/headers/24/crypto/crypto_aes.h +97 -0
- package/src/headers/24/crypto/crypto_argon2.h +86 -0
- package/src/headers/24/crypto/crypto_bio.h +193 -0
- package/src/headers/24/crypto/crypto_chacha20_poly1305.h +64 -0
- package/src/headers/24/crypto/crypto_cipher.h +281 -0
- package/src/headers/24/crypto/crypto_clienthello-inl.h +90 -0
- package/src/headers/24/crypto/crypto_clienthello.h +131 -0
- package/src/headers/24/crypto/crypto_common.h +48 -0
- package/src/headers/24/crypto/crypto_context.h +171 -0
- package/src/headers/24/crypto/crypto_dh.h +126 -0
- package/src/headers/24/crypto/crypto_dsa.h +50 -0
- package/src/headers/24/crypto/crypto_ec.h +163 -0
- package/src/headers/24/crypto/crypto_hash.h +89 -0
- package/src/headers/24/crypto/crypto_hkdf.h +61 -0
- package/src/headers/24/crypto/crypto_hmac.h +92 -0
- package/src/headers/24/crypto/crypto_kem.h +113 -0
- package/src/headers/24/crypto/crypto_keygen.h +290 -0
- package/src/headers/24/crypto/crypto_keys.h +392 -0
- package/src/headers/24/crypto/crypto_ml_dsa.h +21 -0
- package/src/headers/24/crypto/crypto_pbkdf2.h +74 -0
- package/src/headers/24/crypto/crypto_random.h +124 -0
- package/src/headers/24/crypto/crypto_rsa.h +136 -0
- package/src/headers/24/crypto/crypto_scrypt.h +85 -0
- package/src/headers/24/crypto/crypto_sig.h +156 -0
- package/src/headers/24/crypto/crypto_spkac.h +21 -0
- package/src/headers/24/crypto/crypto_timing.h +20 -0
- package/src/headers/24/crypto/crypto_tls.h +309 -0
- package/src/headers/24/crypto/crypto_util.h +598 -0
- package/src/headers/24/crypto/crypto_x509.h +140 -0
- package/src/headers/24/data.h +148 -0
- package/src/headers/24/debug_utils-inl.h +232 -0
- package/src/headers/24/debug_utils.h +193 -0
- package/src/headers/24/defs.h +254 -0
- package/src/headers/24/diagnosticfilename-inl.h +33 -0
- package/src/headers/24/embedded_data.h +17 -0
- package/src/headers/24/encoding_binding.h +60 -0
- package/src/headers/24/endpoint.h +421 -0
- package/src/headers/24/env-inl.h +935 -0
- package/src/headers/24/env.h +1257 -0
- package/src/headers/24/env_properties.h +561 -0
- package/src/headers/24/fs_permission.h +167 -0
- package/src/headers/24/handle_wrap.h +123 -0
- package/src/headers/24/histogram-inl.h +107 -0
- package/src/headers/24/histogram.h +279 -0
- package/src/headers/24/http3.h +44 -0
- package/src/headers/24/inspector_agent.h +165 -0
- package/src/headers/24/inspector_io.h +78 -0
- package/src/headers/24/inspector_permission.h +31 -0
- package/src/headers/24/inspector_profiler.h +149 -0
- package/src/headers/24/inspector_socket.h +60 -0
- package/src/headers/24/inspector_socket_server.h +110 -0
- package/src/headers/24/io_agent.h +30 -0
- package/src/headers/24/js_native_api.h +615 -0
- package/src/headers/24/js_native_api_types.h +211 -0
- package/src/headers/24/js_native_api_v8.h +485 -0
- package/src/headers/24/js_native_api_v8_internals.h +45 -0
- package/src/headers/24/js_stream.h +52 -0
- package/src/headers/24/json_parser.h +40 -0
- package/src/headers/24/json_utils.h +172 -0
- package/src/headers/24/logstream.h +81 -0
- package/src/headers/24/main_thread_interface.h +116 -0
- package/src/headers/24/memory_tracker-inl.h +454 -0
- package/src/headers/24/memory_tracker.h +333 -0
- package/src/headers/24/module_wrap.h +229 -0
- package/src/headers/24/ncrypto.h +1625 -0
- package/src/headers/24/network_agent.h +118 -0
- package/src/headers/24/network_inspector.h +45 -0
- package/src/headers/24/network_resource_manager.h +29 -0
- package/src/headers/24/node.h +1620 -0
- package/src/headers/24/node_api.h +269 -0
- package/src/headers/24/node_api_internals.h +46 -0
- package/src/headers/24/node_api_types.h +52 -0
- package/src/headers/24/node_binding.h +163 -0
- package/src/headers/24/node_blob.h +159 -0
- package/src/headers/24/node_bob-inl.h +36 -0
- package/src/headers/24/node_bob.h +107 -0
- package/src/headers/24/node_buffer.h +92 -0
- package/src/headers/24/node_builtins.h +223 -0
- package/src/headers/24/node_config_file.h +65 -0
- package/src/headers/24/node_constants.h +82 -0
- package/src/headers/24/node_context_data.h +168 -0
- package/src/headers/24/node_contextify.h +261 -0
- package/src/headers/24/node_crypto.h +62 -0
- package/src/headers/24/node_debug.h +25 -0
- package/src/headers/24/node_dir.h +52 -0
- package/src/headers/24/node_dotenv.h +45 -0
- package/src/headers/24/node_errors.h +391 -0
- package/src/headers/24/node_exit_code.h +54 -0
- package/src/headers/24/node_external_reference.h +167 -0
- package/src/headers/24/node_file-inl.h +412 -0
- package/src/headers/24/node_file.h +540 -0
- package/src/headers/24/node_http2.h +1175 -0
- package/src/headers/24/node_http2_state.h +159 -0
- package/src/headers/24/node_http_common-inl.h +198 -0
- package/src/headers/24/node_http_common.h +535 -0
- package/src/headers/24/node_i18n.h +132 -0
- package/src/headers/24/node_internals.h +476 -0
- package/src/headers/24/node_json.h +24 -0
- package/src/headers/24/node_large_page.h +34 -0
- package/src/headers/24/node_locks.h +180 -0
- package/src/headers/24/node_main_instance.h +67 -0
- package/src/headers/24/node_mem-inl.h +112 -0
- package/src/headers/24/node_mem.h +45 -0
- package/src/headers/24/node_messaging.h +389 -0
- package/src/headers/24/node_metadata.h +164 -0
- package/src/headers/24/node_modules.h +93 -0
- package/src/headers/24/node_mutex.h +323 -0
- package/src/headers/24/node_object_wrap.h +132 -0
- package/src/headers/24/node_options-inl.h +524 -0
- package/src/headers/24/node_options.h +682 -0
- package/src/headers/24/node_perf.h +166 -0
- package/src/headers/24/node_perf_common.h +102 -0
- package/src/headers/24/node_platform.h +286 -0
- package/src/headers/24/node_process-inl.h +26 -0
- package/src/headers/24/node_process.h +111 -0
- package/src/headers/24/node_realm-inl.h +153 -0
- package/src/headers/24/node_realm.h +236 -0
- package/src/headers/24/node_report.h +43 -0
- package/src/headers/24/node_revert.h +82 -0
- package/src/headers/24/node_root_certs.h +3546 -0
- package/src/headers/24/node_sea.h +74 -0
- package/src/headers/24/node_shadow_realm.h +46 -0
- package/src/headers/24/node_snapshot_builder.h +57 -0
- package/src/headers/24/node_snapshotable.h +174 -0
- package/src/headers/24/node_sockaddr-inl.h +257 -0
- package/src/headers/24/node_sockaddr.h +394 -0
- package/src/headers/24/node_sqlite.h +270 -0
- package/src/headers/24/node_stat_watcher.h +73 -0
- package/src/headers/24/node_string.h +101 -0
- package/src/headers/24/node_task_runner.h +92 -0
- package/src/headers/24/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/24/node_threadsafe_cow.h +105 -0
- package/src/headers/24/node_trace_buffer.h +83 -0
- package/src/headers/24/node_trace_writer.h +75 -0
- package/src/headers/24/node_union_bytes.h +81 -0
- package/src/headers/24/node_url.h +101 -0
- package/src/headers/24/node_url_pattern.h +118 -0
- package/src/headers/24/node_v8.h +77 -0
- package/src/headers/24/node_v8_platform-inl.h +185 -0
- package/src/headers/24/node_version.h +110 -0
- package/src/headers/24/node_wasi.h +185 -0
- package/src/headers/24/node_wasm_web_api.h +55 -0
- package/src/headers/24/node_watchdog.h +154 -0
- package/src/headers/24/node_webstorage.h +60 -0
- package/src/headers/24/node_worker.h +159 -0
- package/src/headers/24/packet.h +155 -0
- package/src/headers/24/path.h +33 -0
- package/src/headers/24/permission/addon_permission.h +31 -0
- package/src/headers/24/permission/child_process_permission.h +31 -0
- package/src/headers/24/permission/fs_permission.h +167 -0
- package/src/headers/24/permission/inspector_permission.h +31 -0
- package/src/headers/24/permission/permission.h +100 -0
- package/src/headers/24/permission/permission_base.h +65 -0
- package/src/headers/24/permission/wasi_permission.h +31 -0
- package/src/headers/24/permission/worker_permission.h +31 -0
- package/src/headers/24/permission.h +100 -0
- package/src/headers/24/permission_base.h +65 -0
- package/src/headers/24/pipe_wrap.h +80 -0
- package/src/headers/24/preferredaddress.h +72 -0
- package/src/headers/24/protocol_helper.h +27 -0
- package/src/headers/24/queue.h +306 -0
- package/src/headers/24/req_wrap-inl.h +176 -0
- package/src/headers/24/req_wrap.h +79 -0
- package/src/headers/24/runtime_agent.h +41 -0
- package/src/headers/24/session.h +528 -0
- package/src/headers/24/sessionticket.h +108 -0
- package/src/headers/24/spawn_sync.h +243 -0
- package/src/headers/24/stream_base-inl.h +173 -0
- package/src/headers/24/stream_base.h +478 -0
- package/src/headers/24/stream_pipe.h +76 -0
- package/src/headers/24/stream_wrap.h +132 -0
- package/src/headers/24/streams.h +370 -0
- package/src/headers/24/string_bytes.h +109 -0
- package/src/headers/24/string_decoder-inl.h +31 -0
- package/src/headers/24/string_decoder.h +49 -0
- package/src/headers/24/target_agent.h +75 -0
- package/src/headers/24/tcp_wrap.h +105 -0
- package/src/headers/24/threadpoolwork-inl.h +70 -0
- package/src/headers/24/timer_wrap-inl.h +32 -0
- package/src/headers/24/timer_wrap.h +87 -0
- package/src/headers/24/timers.h +75 -0
- package/src/headers/24/tlscontext.h +228 -0
- package/src/headers/24/tokens.h +256 -0
- package/src/headers/24/trace_event.h +722 -0
- package/src/headers/24/trace_event_common.h +1109 -0
- package/src/headers/24/traced_value.h +129 -0
- package/src/headers/24/tracing/agent.h +195 -0
- package/src/headers/24/tracing/trace_event.h +722 -0
- package/src/headers/24/tracing_agent.h +43 -0
- package/src/headers/24/transportparams.h +166 -0
- package/src/headers/24/tty_wrap.h +65 -0
- package/src/headers/24/udp_wrap.h +230 -0
- package/src/headers/24/undici_version.h +6 -0
- package/src/headers/24/util-inl.h +711 -0
- package/src/headers/24/util.h +1016 -0
- package/src/headers/24/v8-external-memory-accounter.h +60 -0
- package/src/headers/24/v8-fast-api-calls.h +819 -0
- package/src/headers/24/v8-inspector.h +426 -0
- package/src/headers/24/wasi_permission.h +31 -0
- package/src/headers/24/worker_agent.h +40 -0
- package/src/headers/24/worker_inspector.h +124 -0
- package/src/headers/24/worker_permission.h +31 -0
- package/src/headers/24/zlib_version.h +6 -0
|
@@ -0,0 +1,73 @@
|
|
|
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_NODE_STAT_WATCHER_H_
|
|
23
|
+
#define SRC_NODE_STAT_WATCHER_H_
|
|
24
|
+
|
|
25
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
26
|
+
|
|
27
|
+
#include "node.h"
|
|
28
|
+
#include "handle_wrap.h"
|
|
29
|
+
#include "uv.h"
|
|
30
|
+
#include "v8.h"
|
|
31
|
+
|
|
32
|
+
namespace node {
|
|
33
|
+
namespace fs {
|
|
34
|
+
class BindingData;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class Environment;
|
|
38
|
+
class ExternalReferenceRegistry;
|
|
39
|
+
|
|
40
|
+
class StatWatcher : public HandleWrap {
|
|
41
|
+
public:
|
|
42
|
+
static void CreatePerIsolateProperties(IsolateData* isolate_data,
|
|
43
|
+
v8::Local<v8::ObjectTemplate> ctor);
|
|
44
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
45
|
+
|
|
46
|
+
protected:
|
|
47
|
+
StatWatcher(fs::BindingData* binding_data,
|
|
48
|
+
v8::Local<v8::Object> wrap,
|
|
49
|
+
bool use_bigint);
|
|
50
|
+
|
|
51
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
52
|
+
static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
53
|
+
|
|
54
|
+
SET_NO_MEMORY_INFO()
|
|
55
|
+
SET_MEMORY_INFO_NAME(StatWatcher)
|
|
56
|
+
SET_SELF_SIZE(StatWatcher)
|
|
57
|
+
|
|
58
|
+
private:
|
|
59
|
+
static void Callback(uv_fs_poll_t* handle,
|
|
60
|
+
int status,
|
|
61
|
+
const uv_stat_t* prev,
|
|
62
|
+
const uv_stat_t* curr);
|
|
63
|
+
|
|
64
|
+
uv_fs_poll_t watcher_;
|
|
65
|
+
const bool use_bigint_;
|
|
66
|
+
BaseObjectPtr<fs::BindingData> binding_data_;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace node
|
|
70
|
+
|
|
71
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
72
|
+
|
|
73
|
+
#endif // SRC_NODE_STAT_WATCHER_H_
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Bridges V8 Inspector generated code with the std::string used by the Node
|
|
2
|
+
// Compare to V8 counterpart - deps/v8/src/inspector/string-util.h
|
|
3
|
+
#ifndef SRC_INSPECTOR_NODE_STRING_H_
|
|
4
|
+
#define SRC_INSPECTOR_NODE_STRING_H_
|
|
5
|
+
|
|
6
|
+
#include <cstring>
|
|
7
|
+
#include <sstream>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include "crdtp/protocol_core.h"
|
|
10
|
+
#include "util.h"
|
|
11
|
+
#include "v8-inspector.h"
|
|
12
|
+
|
|
13
|
+
namespace node::inspector::protocol {
|
|
14
|
+
class Binary;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
namespace crdtp {
|
|
18
|
+
|
|
19
|
+
template <>
|
|
20
|
+
struct ProtocolTypeTraits<std::string> {
|
|
21
|
+
static bool Deserialize(DeserializerState* state, std::string* value);
|
|
22
|
+
static void Serialize(const std::string& value, std::vector<uint8_t>* bytes);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
template <>
|
|
26
|
+
struct ProtocolTypeTraits<node::inspector::protocol::Binary> {
|
|
27
|
+
static bool Deserialize(DeserializerState* state,
|
|
28
|
+
node::inspector::protocol::Binary* value);
|
|
29
|
+
static void Serialize(const node::inspector::protocol::Binary& value,
|
|
30
|
+
std::vector<uint8_t>* bytes);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
} // namespace crdtp
|
|
34
|
+
|
|
35
|
+
namespace node {
|
|
36
|
+
namespace inspector {
|
|
37
|
+
namespace protocol {
|
|
38
|
+
|
|
39
|
+
class Value;
|
|
40
|
+
|
|
41
|
+
using String = std::string;
|
|
42
|
+
using StringBuilder = std::ostringstream;
|
|
43
|
+
using ProtocolMessage = std::string;
|
|
44
|
+
|
|
45
|
+
// Implements StringUtil methods used in `inspector_protocol/lib/`.
|
|
46
|
+
// Refer to
|
|
47
|
+
// https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/inspector/v8_inspector_string.h;l=40;drc=2b15d6974a49d3a14d3d67ae099a649d523a828d
|
|
48
|
+
// for more details about the interface.
|
|
49
|
+
struct StringUtil {
|
|
50
|
+
// Convert Utf16 in local endianness to Utf8 if needed.
|
|
51
|
+
static String StringViewToUtf8(v8_inspector::StringView view);
|
|
52
|
+
static String fromUTF16(const uint16_t* data, size_t length);
|
|
53
|
+
|
|
54
|
+
static String fromUTF8(const uint8_t* data, size_t length);
|
|
55
|
+
static String fromUTF16LE(const uint16_t* data, size_t length);
|
|
56
|
+
static const uint8_t* CharactersUTF8(const std::string_view s);
|
|
57
|
+
static size_t CharacterCount(const std::string_view s);
|
|
58
|
+
|
|
59
|
+
// Unimplemented. The generated code will fall back to CharactersUTF8().
|
|
60
|
+
inline static uint8_t* CharactersLatin1(const std::string_view s) {
|
|
61
|
+
return nullptr;
|
|
62
|
+
}
|
|
63
|
+
inline static const uint16_t* CharactersUTF16(const std::string_view s) {
|
|
64
|
+
return nullptr;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// A read-only sequence of uninterpreted bytes with reference-counted storage.
|
|
69
|
+
class Binary {
|
|
70
|
+
public:
|
|
71
|
+
Binary() : bytes_(std::make_shared<std::vector<uint8_t>>()) {}
|
|
72
|
+
|
|
73
|
+
const uint8_t* data() const { return bytes_->data(); }
|
|
74
|
+
size_t size() const { return bytes_->size(); }
|
|
75
|
+
|
|
76
|
+
String toBase64() const;
|
|
77
|
+
|
|
78
|
+
static Binary concat(const std::vector<Binary>& binaries);
|
|
79
|
+
|
|
80
|
+
static Binary fromBase64(const String& base64, bool* success);
|
|
81
|
+
static Binary fromUint8Array(v8::Local<v8::Uint8Array> data);
|
|
82
|
+
static Binary fromSpan(const uint8_t* data, size_t size) {
|
|
83
|
+
return Binary::fromSpan(crdtp::span<uint8_t>(data, size));
|
|
84
|
+
}
|
|
85
|
+
static Binary fromSpan(crdtp::span<uint8_t> span) {
|
|
86
|
+
return Binary(
|
|
87
|
+
std::make_shared<std::vector<uint8_t>>(span.begin(), span.end()));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private:
|
|
91
|
+
std::shared_ptr<std::vector<uint8_t>> bytes_;
|
|
92
|
+
|
|
93
|
+
explicit Binary(std::shared_ptr<std::vector<uint8_t>> bytes)
|
|
94
|
+
: bytes_(bytes) {}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
} // namespace protocol
|
|
98
|
+
} // namespace inspector
|
|
99
|
+
} // namespace node
|
|
100
|
+
|
|
101
|
+
#endif // SRC_INSPECTOR_NODE_STRING_H_
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#ifndef SRC_NODE_TASK_RUNNER_H_
|
|
2
|
+
#define SRC_NODE_TASK_RUNNER_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "node_internals.h"
|
|
7
|
+
#include "simdjson.h"
|
|
8
|
+
#include "spawn_sync.h"
|
|
9
|
+
#include "uv.h"
|
|
10
|
+
|
|
11
|
+
#include <filesystem>
|
|
12
|
+
#include <optional>
|
|
13
|
+
#include <string_view>
|
|
14
|
+
#include <tuple>
|
|
15
|
+
|
|
16
|
+
namespace node::task_runner {
|
|
17
|
+
|
|
18
|
+
using PositionalArgs = std::vector<std::string_view>;
|
|
19
|
+
|
|
20
|
+
// ProcessRunner is the class responsible for running a process.
|
|
21
|
+
// A class instance is created for each process to be run.
|
|
22
|
+
// The class is responsible for spawning the process and handling its exit.
|
|
23
|
+
// The class also handles the environment variables and arguments.
|
|
24
|
+
class ProcessRunner {
|
|
25
|
+
public:
|
|
26
|
+
ProcessRunner(std::shared_ptr<InitializationResultImpl> result,
|
|
27
|
+
const std::filesystem::path& package_json_path,
|
|
28
|
+
std::string_view script_name,
|
|
29
|
+
std::string_view command,
|
|
30
|
+
std::string_view path_env_var,
|
|
31
|
+
const PositionalArgs& positional_args);
|
|
32
|
+
void Run();
|
|
33
|
+
static void ExitCallback(uv_process_t* req,
|
|
34
|
+
int64_t exit_status,
|
|
35
|
+
int term_signal);
|
|
36
|
+
|
|
37
|
+
private:
|
|
38
|
+
uv_loop_t* loop_ = uv_default_loop();
|
|
39
|
+
uv_process_t process_{};
|
|
40
|
+
uv_process_options_t options_{};
|
|
41
|
+
uv_stdio_container_t child_stdio[3]{};
|
|
42
|
+
std::shared_ptr<InitializationResultImpl> init_result;
|
|
43
|
+
std::vector<std::string> command_args_{};
|
|
44
|
+
std::vector<std::string> env_vars_{};
|
|
45
|
+
std::unique_ptr<char* []> env {}; // memory for options_.env
|
|
46
|
+
std::unique_ptr<char* []> arg {}; // memory for options_.args
|
|
47
|
+
std::string cwd;
|
|
48
|
+
|
|
49
|
+
// OnExit is the callback function that is called when the process exits.
|
|
50
|
+
void OnExit(int64_t exit_status, int term_signal);
|
|
51
|
+
void SetEnvironmentVariables();
|
|
52
|
+
|
|
53
|
+
#ifdef _WIN32
|
|
54
|
+
std::string file_ = "cmd.exe";
|
|
55
|
+
#else
|
|
56
|
+
std::string file_ = "/bin/sh";
|
|
57
|
+
#endif // _WIN32
|
|
58
|
+
|
|
59
|
+
// Represents the absolute path to the package.json file.
|
|
60
|
+
std::filesystem::path package_json_path_;
|
|
61
|
+
// Represents the name of the script that is being run.
|
|
62
|
+
std::string script_name_;
|
|
63
|
+
// Represents PATH environment variable that contains
|
|
64
|
+
// all subdirectory paths appended with node_modules/.bin suffix.
|
|
65
|
+
std::string path_env_var_;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// This function traverses up to the root directory.
|
|
69
|
+
// While traversing up, if it finds a package.json file, it reads its content.
|
|
70
|
+
// If it cannot find a package.json file, it returns std::nullopt.
|
|
71
|
+
// Otherwise, it returns a tuple of:
|
|
72
|
+
// - the path to the package.json file
|
|
73
|
+
// - package.json file content
|
|
74
|
+
// - `path_env_var` variable
|
|
75
|
+
//
|
|
76
|
+
// For example, on POSIX, it returns the following for `path_env_var`,
|
|
77
|
+
// if the current directory is `/anonrig`:
|
|
78
|
+
// `/anonrig/node_modules/.bin:/node_modules/.bin`
|
|
79
|
+
std::optional<std::tuple<std::filesystem::path, std::string, std::string>>
|
|
80
|
+
FindPackageJson(const std::filesystem::path& cwd);
|
|
81
|
+
|
|
82
|
+
void RunTask(const std::shared_ptr<InitializationResultImpl>& result,
|
|
83
|
+
std::string_view command_id,
|
|
84
|
+
const PositionalArgs& positional_args);
|
|
85
|
+
PositionalArgs GetPositionalArgs(const std::vector<std::string>& args);
|
|
86
|
+
std::string EscapeShell(std::string_view command);
|
|
87
|
+
|
|
88
|
+
} // namespace node::task_runner
|
|
89
|
+
|
|
90
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
91
|
+
|
|
92
|
+
#endif // SRC_NODE_TASK_RUNNER_H_
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#ifndef SRC_NODE_THREADSAFE_COW_INL_H_
|
|
2
|
+
#define SRC_NODE_THREADSAFE_COW_INL_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
namespace node {
|
|
7
|
+
|
|
8
|
+
template <typename T>
|
|
9
|
+
T* CopyOnWrite<T>::write() {
|
|
10
|
+
if (data_.use_count() > 1l) {
|
|
11
|
+
data_ = std::make_shared<T>(*data_);
|
|
12
|
+
}
|
|
13
|
+
return data_.get();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
template <typename T>
|
|
17
|
+
ThreadsafeCopyOnWrite<T>::Read::Read(const ThreadsafeCopyOnWrite<T>* cow)
|
|
18
|
+
: cow_(cow), lock_(cow->impl_->mutex) {}
|
|
19
|
+
|
|
20
|
+
template <typename T>
|
|
21
|
+
const T& ThreadsafeCopyOnWrite<T>::Read::operator*() const {
|
|
22
|
+
return cow_->impl_->data;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
template <typename T>
|
|
26
|
+
const T* ThreadsafeCopyOnWrite<T>::Read::operator->() const {
|
|
27
|
+
return &cow_->impl_->data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
template <typename T>
|
|
31
|
+
ThreadsafeCopyOnWrite<T>::Write::Write(ThreadsafeCopyOnWrite<T>* cow)
|
|
32
|
+
: cow_(cow), impl_(cow->impl_.write()), lock_(impl_->mutex) {}
|
|
33
|
+
|
|
34
|
+
template <typename T>
|
|
35
|
+
T& ThreadsafeCopyOnWrite<T>::Write::operator*() {
|
|
36
|
+
return impl_->data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
template <typename T>
|
|
40
|
+
T* ThreadsafeCopyOnWrite<T>::Write::operator->() {
|
|
41
|
+
return &impl_->data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
template <typename T>
|
|
45
|
+
ThreadsafeCopyOnWrite<T>::Impl::Impl(const Impl& other) {
|
|
46
|
+
RwLock::ScopedReadLock lock(other.mutex);
|
|
47
|
+
data = other.data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
} // namespace node
|
|
51
|
+
|
|
52
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
53
|
+
|
|
54
|
+
#endif // SRC_NODE_THREADSAFE_COW_INL_H_
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#ifndef SRC_NODE_THREADSAFE_COW_H_
|
|
2
|
+
#define SRC_NODE_THREADSAFE_COW_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "util.h"
|
|
7
|
+
#include "uv.h"
|
|
8
|
+
|
|
9
|
+
#include <memory> // std::shared_ptr<T>
|
|
10
|
+
#include <utility> // std::forward<T>
|
|
11
|
+
|
|
12
|
+
namespace node {
|
|
13
|
+
|
|
14
|
+
// Copy-on-write utility. Not threadsafe, i.e. there is no synchronization
|
|
15
|
+
// of the copy operation with other operations.
|
|
16
|
+
template <typename T>
|
|
17
|
+
class CopyOnWrite final {
|
|
18
|
+
public:
|
|
19
|
+
template <typename... Args>
|
|
20
|
+
explicit CopyOnWrite(Args&&... args)
|
|
21
|
+
: data_(std::make_shared<T>(std::forward<Args>(args)...)) {}
|
|
22
|
+
|
|
23
|
+
CopyOnWrite(const CopyOnWrite<T>& other) = default;
|
|
24
|
+
CopyOnWrite& operator=(const CopyOnWrite<T>& other) = default;
|
|
25
|
+
CopyOnWrite(CopyOnWrite<T>&& other) = default;
|
|
26
|
+
CopyOnWrite& operator=(CopyOnWrite<T>&& other) = default;
|
|
27
|
+
|
|
28
|
+
const T* read() const { return data_.get(); }
|
|
29
|
+
T* write();
|
|
30
|
+
|
|
31
|
+
const T& operator*() const { return *read(); }
|
|
32
|
+
const T* operator->() const { return read(); }
|
|
33
|
+
|
|
34
|
+
private:
|
|
35
|
+
std::shared_ptr<T> data_;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Threadsafe copy-on-write utility. Consumers need to use the Read and
|
|
39
|
+
// Write helpers to access the target data structure.
|
|
40
|
+
template <typename T>
|
|
41
|
+
class ThreadsafeCopyOnWrite final {
|
|
42
|
+
private:
|
|
43
|
+
// Define this early since some of the public members depend on it
|
|
44
|
+
// and some compilers need it to be defined first in that case.
|
|
45
|
+
struct Impl {
|
|
46
|
+
explicit Impl(const T& data) : data(data) {}
|
|
47
|
+
explicit Impl(T&& data) : data(std::move(data)) {}
|
|
48
|
+
|
|
49
|
+
Impl(const Impl& other);
|
|
50
|
+
Impl& operator=(const Impl& other) = delete;
|
|
51
|
+
Impl(Impl&& other) = delete;
|
|
52
|
+
Impl& operator=(Impl&& other) = delete;
|
|
53
|
+
|
|
54
|
+
RwLock mutex;
|
|
55
|
+
T data;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
template <typename... Args>
|
|
60
|
+
ThreadsafeCopyOnWrite(Args&&... args)
|
|
61
|
+
: impl_(T(std::forward<Args>(args)...)) {}
|
|
62
|
+
|
|
63
|
+
ThreadsafeCopyOnWrite(const ThreadsafeCopyOnWrite<T>& other) = default;
|
|
64
|
+
ThreadsafeCopyOnWrite& operator=(const ThreadsafeCopyOnWrite<T>& other) =
|
|
65
|
+
default;
|
|
66
|
+
ThreadsafeCopyOnWrite(ThreadsafeCopyOnWrite<T>&& other) = default;
|
|
67
|
+
ThreadsafeCopyOnWrite& operator=(ThreadsafeCopyOnWrite<T>&& other) = default;
|
|
68
|
+
|
|
69
|
+
class Read {
|
|
70
|
+
public:
|
|
71
|
+
explicit Read(const ThreadsafeCopyOnWrite<T>* cow);
|
|
72
|
+
|
|
73
|
+
const T& operator*() const;
|
|
74
|
+
const T* operator->() const;
|
|
75
|
+
|
|
76
|
+
private:
|
|
77
|
+
const ThreadsafeCopyOnWrite<T>* cow_;
|
|
78
|
+
RwLock::ScopedReadLock lock_;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
class Write {
|
|
82
|
+
public:
|
|
83
|
+
explicit Write(ThreadsafeCopyOnWrite<T>* cow);
|
|
84
|
+
|
|
85
|
+
T& operator*();
|
|
86
|
+
T* operator->();
|
|
87
|
+
|
|
88
|
+
private:
|
|
89
|
+
ThreadsafeCopyOnWrite<T>* cow_;
|
|
90
|
+
typename ThreadsafeCopyOnWrite<T>::Impl* impl_;
|
|
91
|
+
RwLock::ScopedLock lock_;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
Read read() const { return Read(this); }
|
|
95
|
+
Write write() { return Write(this); }
|
|
96
|
+
|
|
97
|
+
private:
|
|
98
|
+
CopyOnWrite<Impl> impl_;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
} // namespace node
|
|
102
|
+
|
|
103
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
104
|
+
|
|
105
|
+
#endif // SRC_NODE_THREADSAFE_COW_H_
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#ifndef SRC_TRACING_NODE_TRACE_BUFFER_H_
|
|
2
|
+
#define SRC_TRACING_NODE_TRACE_BUFFER_H_
|
|
3
|
+
|
|
4
|
+
#include "tracing/agent.h"
|
|
5
|
+
#include "node_mutex.h"
|
|
6
|
+
#include "libplatform/v8-tracing.h"
|
|
7
|
+
|
|
8
|
+
#include <atomic>
|
|
9
|
+
|
|
10
|
+
namespace node {
|
|
11
|
+
namespace tracing {
|
|
12
|
+
|
|
13
|
+
using v8::platform::tracing::TraceBuffer;
|
|
14
|
+
using v8::platform::tracing::TraceBufferChunk;
|
|
15
|
+
using v8::platform::tracing::TraceObject;
|
|
16
|
+
|
|
17
|
+
// forward declaration
|
|
18
|
+
class NodeTraceBuffer;
|
|
19
|
+
|
|
20
|
+
class InternalTraceBuffer {
|
|
21
|
+
public:
|
|
22
|
+
InternalTraceBuffer(size_t max_chunks, uint32_t id, Agent* agent);
|
|
23
|
+
|
|
24
|
+
TraceObject* AddTraceEvent(uint64_t* handle);
|
|
25
|
+
TraceObject* GetEventByHandle(uint64_t handle);
|
|
26
|
+
void Flush(bool blocking);
|
|
27
|
+
bool IsFull() const {
|
|
28
|
+
return total_chunks_ == max_chunks_ && chunks_[total_chunks_ - 1]->IsFull();
|
|
29
|
+
}
|
|
30
|
+
bool IsFlushing() const {
|
|
31
|
+
return flushing_;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private:
|
|
35
|
+
uint64_t MakeHandle(size_t chunk_index, uint32_t chunk_seq,
|
|
36
|
+
size_t event_index) const;
|
|
37
|
+
void ExtractHandle(uint64_t handle, uint32_t* buffer_id, size_t* chunk_index,
|
|
38
|
+
uint32_t* chunk_seq, size_t* event_index) const;
|
|
39
|
+
size_t Capacity() const { return max_chunks_ * TraceBufferChunk::kChunkSize; }
|
|
40
|
+
|
|
41
|
+
Mutex mutex_;
|
|
42
|
+
bool flushing_;
|
|
43
|
+
size_t max_chunks_;
|
|
44
|
+
Agent* agent_;
|
|
45
|
+
std::vector<std::unique_ptr<TraceBufferChunk>> chunks_;
|
|
46
|
+
size_t total_chunks_ = 0;
|
|
47
|
+
uint32_t current_chunk_seq_ = 1;
|
|
48
|
+
uint32_t id_;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
class NodeTraceBuffer : public TraceBuffer {
|
|
52
|
+
public:
|
|
53
|
+
NodeTraceBuffer(size_t max_chunks, Agent* agent, uv_loop_t* tracing_loop);
|
|
54
|
+
~NodeTraceBuffer() override;
|
|
55
|
+
|
|
56
|
+
TraceObject* AddTraceEvent(uint64_t* handle) override;
|
|
57
|
+
TraceObject* GetEventByHandle(uint64_t handle) override;
|
|
58
|
+
bool Flush() override;
|
|
59
|
+
|
|
60
|
+
static const size_t kBufferChunks = 1024;
|
|
61
|
+
|
|
62
|
+
private:
|
|
63
|
+
bool TryLoadAvailableBuffer();
|
|
64
|
+
static void NonBlockingFlushSignalCb(uv_async_t* signal);
|
|
65
|
+
static void ExitSignalCb(uv_async_t* signal);
|
|
66
|
+
|
|
67
|
+
uv_loop_t* tracing_loop_;
|
|
68
|
+
uv_async_t flush_signal_;
|
|
69
|
+
uv_async_t exit_signal_;
|
|
70
|
+
bool exited_ = false;
|
|
71
|
+
// Used exclusively for exit logic.
|
|
72
|
+
Mutex exit_mutex_;
|
|
73
|
+
// Used to wait until async handles have been closed.
|
|
74
|
+
ConditionVariable exit_cond_;
|
|
75
|
+
std::atomic<InternalTraceBuffer*> current_buf_;
|
|
76
|
+
InternalTraceBuffer buffer1_;
|
|
77
|
+
InternalTraceBuffer buffer2_;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace tracing
|
|
81
|
+
} // namespace node
|
|
82
|
+
|
|
83
|
+
#endif // SRC_TRACING_NODE_TRACE_BUFFER_H_
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#ifndef SRC_TRACING_NODE_TRACE_WRITER_H_
|
|
2
|
+
#define SRC_TRACING_NODE_TRACE_WRITER_H_
|
|
3
|
+
|
|
4
|
+
#include <sstream>
|
|
5
|
+
#include <queue>
|
|
6
|
+
|
|
7
|
+
#include "libplatform/v8-tracing.h"
|
|
8
|
+
#include "tracing/agent.h"
|
|
9
|
+
#include "uv.h"
|
|
10
|
+
|
|
11
|
+
namespace node {
|
|
12
|
+
namespace tracing {
|
|
13
|
+
|
|
14
|
+
using v8::platform::tracing::TraceObject;
|
|
15
|
+
using v8::platform::tracing::TraceWriter;
|
|
16
|
+
|
|
17
|
+
class NodeTraceWriter : public AsyncTraceWriter {
|
|
18
|
+
public:
|
|
19
|
+
explicit NodeTraceWriter(const std::string& log_file_pattern);
|
|
20
|
+
~NodeTraceWriter() override;
|
|
21
|
+
|
|
22
|
+
void InitializeOnThread(uv_loop_t* loop) override;
|
|
23
|
+
void AppendTraceEvent(TraceObject* trace_event) override;
|
|
24
|
+
void Flush(bool blocking) override;
|
|
25
|
+
|
|
26
|
+
static const int kTracesPerFile = 1 << 19;
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
struct WriteRequest {
|
|
30
|
+
std::string str;
|
|
31
|
+
int highest_request_id;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
void AfterWrite();
|
|
35
|
+
void StartWrite(uv_buf_t buf);
|
|
36
|
+
void OpenNewFileForStreaming();
|
|
37
|
+
void WriteToFile(std::string&& str, int highest_request_id);
|
|
38
|
+
void WriteSuffix();
|
|
39
|
+
void FlushPrivate();
|
|
40
|
+
static void ExitSignalCb(uv_async_t* signal);
|
|
41
|
+
|
|
42
|
+
uv_loop_t* tracing_loop_ = nullptr;
|
|
43
|
+
// Triggers callback to initiate writing the contents of stream_ to disk.
|
|
44
|
+
uv_async_t flush_signal_;
|
|
45
|
+
// Triggers callback to close async objects, ending the tracing thread.
|
|
46
|
+
uv_async_t exit_signal_;
|
|
47
|
+
// Prevents concurrent R/W on state related to serialized trace data
|
|
48
|
+
// before it's written to disk, namely stream_ and total_traces_
|
|
49
|
+
// as well as json_trace_writer_.
|
|
50
|
+
Mutex stream_mutex_;
|
|
51
|
+
// Prevents concurrent R/W on state related to write requests.
|
|
52
|
+
// If both mutexes are locked, request_mutex_ has to be locked first.
|
|
53
|
+
Mutex request_mutex_;
|
|
54
|
+
// Allows blocking calls to Flush() to wait on a condition for
|
|
55
|
+
// trace events to be written to disk.
|
|
56
|
+
ConditionVariable request_cond_;
|
|
57
|
+
// Used to wait until async handles have been closed.
|
|
58
|
+
ConditionVariable exit_cond_;
|
|
59
|
+
int fd_ = -1;
|
|
60
|
+
uv_fs_t write_req_;
|
|
61
|
+
std::queue<WriteRequest> write_req_queue_;
|
|
62
|
+
int num_write_requests_ = 0;
|
|
63
|
+
int highest_request_id_completed_ = 0;
|
|
64
|
+
int total_traces_ = 0;
|
|
65
|
+
int file_num_ = 0;
|
|
66
|
+
std::string log_file_pattern_;
|
|
67
|
+
std::ostringstream stream_;
|
|
68
|
+
std::unique_ptr<TraceWriter> json_trace_writer_;
|
|
69
|
+
bool exited_ = false;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
} // namespace tracing
|
|
73
|
+
} // namespace node
|
|
74
|
+
|
|
75
|
+
#endif // SRC_TRACING_NODE_TRACE_WRITER_H_
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef SRC_NODE_UNION_BYTES_H_
|
|
3
|
+
#define SRC_NODE_UNION_BYTES_H_
|
|
4
|
+
|
|
5
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
6
|
+
|
|
7
|
+
#include "v8.h"
|
|
8
|
+
|
|
9
|
+
namespace node {
|
|
10
|
+
|
|
11
|
+
// An external resource intended to be used with static lifetime.
|
|
12
|
+
template <typename Char, typename IChar, typename Base>
|
|
13
|
+
class StaticExternalByteResource : public Base {
|
|
14
|
+
static_assert(sizeof(IChar) == sizeof(Char),
|
|
15
|
+
"incompatible interface and internal pointers");
|
|
16
|
+
|
|
17
|
+
public:
|
|
18
|
+
explicit StaticExternalByteResource(const Char* data,
|
|
19
|
+
size_t length,
|
|
20
|
+
std::shared_ptr<void> owning_ptr)
|
|
21
|
+
: data_(data), length_(length), owning_ptr_(owning_ptr) {}
|
|
22
|
+
|
|
23
|
+
const IChar* data() const override {
|
|
24
|
+
return reinterpret_cast<const IChar*>(data_);
|
|
25
|
+
}
|
|
26
|
+
size_t length() const override { return length_; }
|
|
27
|
+
|
|
28
|
+
void Dispose() override {
|
|
29
|
+
// We ignore Dispose calls from V8, even if we "own" a resource via
|
|
30
|
+
// owning_ptr_. All instantiations of this class are static or owned by a
|
|
31
|
+
// static map, and will be destructed when static variables are destructed.
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
StaticExternalByteResource(const StaticExternalByteResource&) = delete;
|
|
35
|
+
StaticExternalByteResource& operator=(const StaticExternalByteResource&) =
|
|
36
|
+
delete;
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
const Char* data_;
|
|
40
|
+
const size_t length_;
|
|
41
|
+
std::shared_ptr<void> owning_ptr_;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
using StaticExternalOneByteResource =
|
|
45
|
+
StaticExternalByteResource<uint8_t,
|
|
46
|
+
char,
|
|
47
|
+
v8::String::ExternalOneByteStringResource>;
|
|
48
|
+
using StaticExternalTwoByteResource =
|
|
49
|
+
StaticExternalByteResource<uint16_t,
|
|
50
|
+
uint16_t,
|
|
51
|
+
v8::String::ExternalStringResource>;
|
|
52
|
+
|
|
53
|
+
// Similar to a v8::String, but it's independent from Isolates
|
|
54
|
+
// and can be materialized in Isolates as external Strings
|
|
55
|
+
// via ToStringChecked.
|
|
56
|
+
class UnionBytes {
|
|
57
|
+
public:
|
|
58
|
+
explicit UnionBytes(StaticExternalOneByteResource* one_byte_resource)
|
|
59
|
+
: one_byte_resource_(one_byte_resource), two_byte_resource_(nullptr) {}
|
|
60
|
+
explicit UnionBytes(StaticExternalTwoByteResource* two_byte_resource)
|
|
61
|
+
: one_byte_resource_(nullptr), two_byte_resource_(two_byte_resource) {}
|
|
62
|
+
|
|
63
|
+
UnionBytes(const UnionBytes&) = default;
|
|
64
|
+
UnionBytes& operator=(const UnionBytes&) = default;
|
|
65
|
+
UnionBytes(UnionBytes&&) = default;
|
|
66
|
+
UnionBytes& operator=(UnionBytes&&) = default;
|
|
67
|
+
|
|
68
|
+
bool is_one_byte() const { return one_byte_resource_ != nullptr; }
|
|
69
|
+
|
|
70
|
+
v8::Local<v8::String> ToStringChecked(v8::Isolate* isolate) const;
|
|
71
|
+
|
|
72
|
+
private:
|
|
73
|
+
StaticExternalOneByteResource* one_byte_resource_;
|
|
74
|
+
StaticExternalTwoByteResource* two_byte_resource_;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
} // namespace node
|
|
78
|
+
|
|
79
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
80
|
+
|
|
81
|
+
#endif // SRC_NODE_UNION_BYTES_H_
|