@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,45 @@
|
|
|
1
|
+
#ifndef SRC_JS_NATIVE_API_V8_INTERNALS_H_
|
|
2
|
+
#define SRC_JS_NATIVE_API_V8_INTERNALS_H_
|
|
3
|
+
|
|
4
|
+
// The V8 implementation of N-API, including `js_native_api_v8.h` uses certain
|
|
5
|
+
// idioms which require definition here. For example, it uses a variant of
|
|
6
|
+
// persistent references which need not be reset in the constructor. It is the
|
|
7
|
+
// responsibility of this file to define these idioms. Optionally, this file
|
|
8
|
+
// may also define `NAPI_VERSION` and set it to the version of N-API to be
|
|
9
|
+
// exposed.
|
|
10
|
+
|
|
11
|
+
// In the case of the Node.js implementation of N-API some of the idioms are
|
|
12
|
+
// imported directly from Node.js by including `node_internals.h` below. Others
|
|
13
|
+
// are bridged to remove references to the `node` namespace. `node_version.h`,
|
|
14
|
+
// included below, defines `NAPI_VERSION`.
|
|
15
|
+
|
|
16
|
+
#include "node_version.h"
|
|
17
|
+
|
|
18
|
+
#include "env.h"
|
|
19
|
+
#include "gtest/gtest_prod.h"
|
|
20
|
+
#include "node_errors.h"
|
|
21
|
+
#include "node_internals.h"
|
|
22
|
+
|
|
23
|
+
#define NAPI_ARRAYSIZE(array) node::arraysize((array))
|
|
24
|
+
|
|
25
|
+
#define NAPI_FIXED_ONE_BYTE_STRING(isolate, string) \
|
|
26
|
+
node::FIXED_ONE_BYTE_STRING((isolate), (string))
|
|
27
|
+
|
|
28
|
+
#define NAPI_PRIVATE_KEY(context, suffix) \
|
|
29
|
+
(node::Environment::GetCurrent((context))->napi_##suffix())
|
|
30
|
+
|
|
31
|
+
namespace v8impl {
|
|
32
|
+
|
|
33
|
+
template <typename T>
|
|
34
|
+
using Persistent = v8::Global<T>;
|
|
35
|
+
|
|
36
|
+
using PersistentToLocal = node::PersistentToLocal;
|
|
37
|
+
|
|
38
|
+
[[noreturn]] inline void OnFatalError(const char* location,
|
|
39
|
+
const char* message) {
|
|
40
|
+
node::OnFatalError(location, message);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
} // end of namespace v8impl
|
|
44
|
+
|
|
45
|
+
#endif // SRC_JS_NATIVE_API_V8_INTERNALS_H_
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#ifndef SRC_JS_STREAM_H_
|
|
2
|
+
#define SRC_JS_STREAM_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "async_wrap.h"
|
|
7
|
+
#include "stream_base.h"
|
|
8
|
+
|
|
9
|
+
namespace node {
|
|
10
|
+
|
|
11
|
+
class Environment;
|
|
12
|
+
|
|
13
|
+
class JSStream : public AsyncWrap, public StreamBase {
|
|
14
|
+
public:
|
|
15
|
+
static void Initialize(v8::Local<v8::Object> target,
|
|
16
|
+
v8::Local<v8::Value> unused,
|
|
17
|
+
v8::Local<v8::Context> context,
|
|
18
|
+
void* priv);
|
|
19
|
+
|
|
20
|
+
bool IsAlive() override;
|
|
21
|
+
bool IsClosing() override;
|
|
22
|
+
int ReadStart() override;
|
|
23
|
+
int ReadStop() override;
|
|
24
|
+
|
|
25
|
+
int DoShutdown(ShutdownWrap* req_wrap) override;
|
|
26
|
+
int DoWrite(WriteWrap* w,
|
|
27
|
+
uv_buf_t* bufs,
|
|
28
|
+
size_t count,
|
|
29
|
+
uv_stream_t* send_handle) override;
|
|
30
|
+
|
|
31
|
+
SET_NO_MEMORY_INFO()
|
|
32
|
+
SET_MEMORY_INFO_NAME(JSStream)
|
|
33
|
+
SET_SELF_SIZE(JSStream)
|
|
34
|
+
|
|
35
|
+
protected:
|
|
36
|
+
JSStream(Environment* env, v8::Local<v8::Object> obj);
|
|
37
|
+
|
|
38
|
+
AsyncWrap* GetAsyncWrap() override;
|
|
39
|
+
|
|
40
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
41
|
+
static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
42
|
+
static void EmitEOF(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
43
|
+
|
|
44
|
+
template <class Wrap>
|
|
45
|
+
static void Finish(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
} // namespace node
|
|
49
|
+
|
|
50
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
51
|
+
|
|
52
|
+
#endif // SRC_JS_STREAM_H_
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#ifndef SRC_JSON_PARSER_H_
|
|
2
|
+
#define SRC_JSON_PARSER_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <optional>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <unordered_map>
|
|
10
|
+
#include "util.h"
|
|
11
|
+
#include "v8.h"
|
|
12
|
+
|
|
13
|
+
namespace node {
|
|
14
|
+
// This is intended to be used to get some top-level fields out of a JSON
|
|
15
|
+
// without having to spin up a full Node.js environment that unnecessarily
|
|
16
|
+
// complicates things.
|
|
17
|
+
class JSONParser {
|
|
18
|
+
public:
|
|
19
|
+
using StringDict = std::unordered_map<std::string, std::string>;
|
|
20
|
+
JSONParser();
|
|
21
|
+
~JSONParser() = default;
|
|
22
|
+
bool Parse(const std::string& content);
|
|
23
|
+
std::optional<std::string> GetTopLevelStringField(std::string_view field);
|
|
24
|
+
std::optional<bool> GetTopLevelBoolField(std::string_view field);
|
|
25
|
+
std::optional<StringDict> GetTopLevelStringDict(std::string_view field);
|
|
26
|
+
|
|
27
|
+
private:
|
|
28
|
+
// We might want a lighter-weight JSON parser for this use case. But for now
|
|
29
|
+
// using V8 is good enough.
|
|
30
|
+
RAIIIsolateWithoutEntering isolate_;
|
|
31
|
+
|
|
32
|
+
v8::Global<v8::Context> context_;
|
|
33
|
+
v8::Global<v8::Object> content_;
|
|
34
|
+
bool parsed_ = false;
|
|
35
|
+
};
|
|
36
|
+
} // namespace node
|
|
37
|
+
|
|
38
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
39
|
+
|
|
40
|
+
#endif // SRC_JSON_PARSER_H_
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#ifndef SRC_JSON_UTILS_H_
|
|
2
|
+
#define SRC_JSON_UTILS_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <iomanip>
|
|
7
|
+
#include <limits>
|
|
8
|
+
#include <ostream>
|
|
9
|
+
#include <string>
|
|
10
|
+
#include <string_view>
|
|
11
|
+
|
|
12
|
+
namespace node {
|
|
13
|
+
|
|
14
|
+
constexpr bool NeedsJsonEscape(std::string_view str) {
|
|
15
|
+
for (const char c : str) {
|
|
16
|
+
if (c == '\\' || c == '"' || c < 0x20) return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
std::string EscapeJsonChars(std::string_view str);
|
|
22
|
+
std::string Reindent(const std::string& str, int indentation);
|
|
23
|
+
|
|
24
|
+
// JSON compiler definitions.
|
|
25
|
+
class JSONWriter {
|
|
26
|
+
public:
|
|
27
|
+
JSONWriter(std::ostream& out, bool compact)
|
|
28
|
+
: out_(out), compact_(compact) {}
|
|
29
|
+
|
|
30
|
+
private:
|
|
31
|
+
inline void indent() { indent_ += 2; }
|
|
32
|
+
inline void deindent() { indent_ -= 2; }
|
|
33
|
+
inline void advance() {
|
|
34
|
+
if (compact_) return;
|
|
35
|
+
for (int i = 0; i < indent_; i++) out_ << ' ';
|
|
36
|
+
}
|
|
37
|
+
inline void write_one_space() {
|
|
38
|
+
if (compact_) return;
|
|
39
|
+
out_ << ' ';
|
|
40
|
+
}
|
|
41
|
+
inline void write_new_line() {
|
|
42
|
+
if (compact_) return;
|
|
43
|
+
out_ << '\n';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline void json_start() {
|
|
48
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
49
|
+
write_new_line();
|
|
50
|
+
advance();
|
|
51
|
+
out_ << '{';
|
|
52
|
+
indent();
|
|
53
|
+
state_ = kObjectStart;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
inline void json_end() {
|
|
57
|
+
write_new_line();
|
|
58
|
+
deindent();
|
|
59
|
+
advance();
|
|
60
|
+
out_ << '}';
|
|
61
|
+
state_ = kAfterValue;
|
|
62
|
+
}
|
|
63
|
+
template <typename T>
|
|
64
|
+
inline void json_objectstart(T key) {
|
|
65
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
66
|
+
write_new_line();
|
|
67
|
+
advance();
|
|
68
|
+
write_string(key);
|
|
69
|
+
out_ << ':';
|
|
70
|
+
write_one_space();
|
|
71
|
+
out_ << '{';
|
|
72
|
+
indent();
|
|
73
|
+
state_ = kObjectStart;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
template <typename T>
|
|
77
|
+
inline void json_arraystart(T key) {
|
|
78
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
79
|
+
write_new_line();
|
|
80
|
+
advance();
|
|
81
|
+
write_string(key);
|
|
82
|
+
out_ << ':';
|
|
83
|
+
write_one_space();
|
|
84
|
+
out_ << '[';
|
|
85
|
+
indent();
|
|
86
|
+
state_ = kObjectStart;
|
|
87
|
+
}
|
|
88
|
+
inline void json_objectend() {
|
|
89
|
+
write_new_line();
|
|
90
|
+
deindent();
|
|
91
|
+
advance();
|
|
92
|
+
out_ << '}';
|
|
93
|
+
if (indent_ == 0) {
|
|
94
|
+
// Top-level object is complete, so end the line.
|
|
95
|
+
out_ << '\n';
|
|
96
|
+
}
|
|
97
|
+
state_ = kAfterValue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
inline void json_arrayend() {
|
|
101
|
+
write_new_line();
|
|
102
|
+
deindent();
|
|
103
|
+
advance();
|
|
104
|
+
out_ << ']';
|
|
105
|
+
state_ = kAfterValue;
|
|
106
|
+
}
|
|
107
|
+
template <typename T, typename U>
|
|
108
|
+
inline void json_keyvalue(const T& key, const U& value) {
|
|
109
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
110
|
+
write_new_line();
|
|
111
|
+
advance();
|
|
112
|
+
write_string(key);
|
|
113
|
+
out_ << ':';
|
|
114
|
+
write_one_space();
|
|
115
|
+
write_value(value);
|
|
116
|
+
state_ = kAfterValue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
template <typename U>
|
|
120
|
+
inline void json_element(const U& value) {
|
|
121
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
122
|
+
write_new_line();
|
|
123
|
+
advance();
|
|
124
|
+
write_value(value);
|
|
125
|
+
state_ = kAfterValue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
struct Null {}; // Usable as a JSON value.
|
|
129
|
+
|
|
130
|
+
struct ForeignJSON {
|
|
131
|
+
std::string as_string;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
private:
|
|
135
|
+
template <typename T,
|
|
136
|
+
typename test_for_number = typename std::
|
|
137
|
+
enable_if<std::numeric_limits<T>::is_specialized, bool>::type>
|
|
138
|
+
inline void write_value(T number) {
|
|
139
|
+
if constexpr (std::is_same<T, bool>::value)
|
|
140
|
+
out_ << (number ? "true" : "false");
|
|
141
|
+
else
|
|
142
|
+
out_ << number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
inline void write_value(Null null) { out_ << "null"; }
|
|
146
|
+
inline void write_value(std::string_view str) { write_string(str); }
|
|
147
|
+
|
|
148
|
+
inline void write_value(const ForeignJSON& json) {
|
|
149
|
+
out_ << Reindent(json.as_string, indent_);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
inline void write_string(std::string_view str) {
|
|
153
|
+
out_ << '"';
|
|
154
|
+
if (NeedsJsonEscape(str)) // only create temporary std::string if necessary
|
|
155
|
+
out_ << EscapeJsonChars(str);
|
|
156
|
+
else
|
|
157
|
+
out_ << str;
|
|
158
|
+
out_ << '"';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
enum JSONState { kObjectStart, kAfterValue };
|
|
162
|
+
std::ostream& out_;
|
|
163
|
+
bool compact_;
|
|
164
|
+
int indent_ = 0;
|
|
165
|
+
int state_ = kObjectStart;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
} // namespace node
|
|
169
|
+
|
|
170
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
171
|
+
|
|
172
|
+
#endif // SRC_JSON_UTILS_H_
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
4
|
+
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
|
5
|
+
|
|
6
|
+
#include <async_wrap.h>
|
|
7
|
+
#include <base_object.h>
|
|
8
|
+
#include <env.h>
|
|
9
|
+
#include <stream_base.h>
|
|
10
|
+
#include <deque>
|
|
11
|
+
|
|
12
|
+
namespace node::quic {
|
|
13
|
+
|
|
14
|
+
// The LogStream is a utility that the QUIC impl uses to publish both QLog
|
|
15
|
+
// and Keylog diagnostic data (one instance for each).
|
|
16
|
+
class LogStream : public AsyncWrap, public StreamBase {
|
|
17
|
+
public:
|
|
18
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
19
|
+
Environment* env);
|
|
20
|
+
|
|
21
|
+
static BaseObjectPtr<LogStream> Create(Environment* env);
|
|
22
|
+
|
|
23
|
+
LogStream(Environment* env, v8::Local<v8::Object> obj);
|
|
24
|
+
|
|
25
|
+
enum class EmitOption {
|
|
26
|
+
NONE,
|
|
27
|
+
FIN,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
void Emit(const uint8_t* data,
|
|
31
|
+
size_t len,
|
|
32
|
+
EmitOption option = EmitOption::NONE);
|
|
33
|
+
|
|
34
|
+
void Emit(const std::string_view line, EmitOption option = EmitOption::NONE);
|
|
35
|
+
|
|
36
|
+
void End();
|
|
37
|
+
|
|
38
|
+
int ReadStart() override;
|
|
39
|
+
|
|
40
|
+
int ReadStop() override;
|
|
41
|
+
|
|
42
|
+
// We do not use either of these.
|
|
43
|
+
int DoShutdown(ShutdownWrap* req_wrap) override;
|
|
44
|
+
int DoWrite(WriteWrap* w,
|
|
45
|
+
uv_buf_t* bufs,
|
|
46
|
+
size_t count,
|
|
47
|
+
uv_stream_t* send_handle) override;
|
|
48
|
+
|
|
49
|
+
bool IsAlive() override;
|
|
50
|
+
bool IsClosing() override;
|
|
51
|
+
AsyncWrap* GetAsyncWrap() override;
|
|
52
|
+
|
|
53
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
54
|
+
SET_MEMORY_INFO_NAME(LogStream)
|
|
55
|
+
SET_SELF_SIZE(LogStream)
|
|
56
|
+
|
|
57
|
+
private:
|
|
58
|
+
struct Chunk {
|
|
59
|
+
// len will be <= buf.len
|
|
60
|
+
size_t len;
|
|
61
|
+
uv_buf_t buf;
|
|
62
|
+
};
|
|
63
|
+
size_t total_ = 0;
|
|
64
|
+
bool fin_seen_ = false;
|
|
65
|
+
bool ended_ = false;
|
|
66
|
+
bool reading_ = false;
|
|
67
|
+
std::deque<Chunk> buffer_;
|
|
68
|
+
|
|
69
|
+
// The value here is fairly arbitrary. Once we get everything
|
|
70
|
+
// fully implemented and start working with this, we might
|
|
71
|
+
// tune this number further.
|
|
72
|
+
static constexpr size_t kMaxLogStreamBuffer = 1024 * 10;
|
|
73
|
+
|
|
74
|
+
// The LogStream buffer enforces a maximum size of kMaxLogStreamBuffer.
|
|
75
|
+
void ensure_space(size_t amt);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace node::quic
|
|
79
|
+
|
|
80
|
+
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
|
81
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#ifndef SRC_INSPECTOR_MAIN_THREAD_INTERFACE_H_
|
|
2
|
+
#define SRC_INSPECTOR_MAIN_THREAD_INTERFACE_H_
|
|
3
|
+
|
|
4
|
+
#if !HAVE_INSPECTOR
|
|
5
|
+
#error("This header can only be used when inspector is enabled")
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include "inspector_agent.h"
|
|
9
|
+
#include "node_mutex.h"
|
|
10
|
+
|
|
11
|
+
#include <atomic>
|
|
12
|
+
#include <deque>
|
|
13
|
+
#include <memory>
|
|
14
|
+
#include <unordered_map>
|
|
15
|
+
|
|
16
|
+
namespace v8_inspector {
|
|
17
|
+
class StringBuffer;
|
|
18
|
+
class StringView;
|
|
19
|
+
} // namespace v8_inspector
|
|
20
|
+
|
|
21
|
+
namespace node {
|
|
22
|
+
namespace inspector {
|
|
23
|
+
class MainThreadInterface;
|
|
24
|
+
|
|
25
|
+
class Request {
|
|
26
|
+
public:
|
|
27
|
+
virtual void Call(MainThreadInterface*) = 0;
|
|
28
|
+
virtual ~Request() = default;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
class Deletable {
|
|
32
|
+
public:
|
|
33
|
+
virtual ~Deletable() = default;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
std::unique_ptr<v8_inspector::StringBuffer> Utf8ToStringView(
|
|
37
|
+
const std::string_view message);
|
|
38
|
+
|
|
39
|
+
using MessageQueue = std::deque<std::unique_ptr<Request>>;
|
|
40
|
+
|
|
41
|
+
class MainThreadHandle : public std::enable_shared_from_this<MainThreadHandle> {
|
|
42
|
+
public:
|
|
43
|
+
explicit MainThreadHandle(MainThreadInterface* main_thread)
|
|
44
|
+
: main_thread_(main_thread) {
|
|
45
|
+
}
|
|
46
|
+
~MainThreadHandle() {
|
|
47
|
+
Mutex::ScopedLock scoped_lock(block_lock_);
|
|
48
|
+
CHECK_NULL(main_thread_); // main_thread_ should have called Reset
|
|
49
|
+
}
|
|
50
|
+
std::unique_ptr<InspectorSession> Connect(
|
|
51
|
+
std::unique_ptr<InspectorSessionDelegate> delegate,
|
|
52
|
+
bool prevent_shutdown);
|
|
53
|
+
int newObjectId() {
|
|
54
|
+
return ++next_object_id_;
|
|
55
|
+
}
|
|
56
|
+
bool Post(std::unique_ptr<Request> request);
|
|
57
|
+
std::unique_ptr<InspectorSessionDelegate> MakeDelegateThreadSafe(
|
|
58
|
+
std::unique_ptr<InspectorSessionDelegate> delegate);
|
|
59
|
+
bool Expired();
|
|
60
|
+
void SetTargetSessionId(int target_session_id) {
|
|
61
|
+
target_session_id_ = target_session_id;
|
|
62
|
+
}
|
|
63
|
+
std::optional<int> GetTargetSessionId() { return target_session_id_; }
|
|
64
|
+
|
|
65
|
+
private:
|
|
66
|
+
void Reset();
|
|
67
|
+
|
|
68
|
+
MainThreadInterface* main_thread_;
|
|
69
|
+
Mutex block_lock_;
|
|
70
|
+
int next_session_id_ = 0;
|
|
71
|
+
std::atomic_int next_object_id_ = {1};
|
|
72
|
+
std::optional<int> target_session_id_ = std::nullopt;
|
|
73
|
+
|
|
74
|
+
friend class MainThreadInterface;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
class MainThreadInterface :
|
|
78
|
+
public std::enable_shared_from_this<MainThreadInterface> {
|
|
79
|
+
public:
|
|
80
|
+
explicit MainThreadInterface(Agent* agent);
|
|
81
|
+
~MainThreadInterface();
|
|
82
|
+
|
|
83
|
+
void DispatchMessages();
|
|
84
|
+
void Post(std::unique_ptr<Request> request);
|
|
85
|
+
bool WaitForFrontendEvent();
|
|
86
|
+
void StopWaitingForFrontendEvent();
|
|
87
|
+
std::shared_ptr<MainThreadHandle> GetHandle();
|
|
88
|
+
Agent* inspector_agent() {
|
|
89
|
+
return agent_;
|
|
90
|
+
}
|
|
91
|
+
void AddObject(int handle, std::unique_ptr<Deletable> object);
|
|
92
|
+
Deletable* GetObject(int id);
|
|
93
|
+
Deletable* GetObjectIfExists(int id);
|
|
94
|
+
void RemoveObject(int handle);
|
|
95
|
+
|
|
96
|
+
private:
|
|
97
|
+
MessageQueue requests_;
|
|
98
|
+
Mutex requests_lock_; // requests_ live across threads
|
|
99
|
+
// This queue is to maintain the order of the messages for the cases
|
|
100
|
+
// when we reenter the DispatchMessages function.
|
|
101
|
+
MessageQueue dispatching_message_queue_;
|
|
102
|
+
bool dispatching_messages_ = false;
|
|
103
|
+
// This flag indicates an internal request to exit the loop in
|
|
104
|
+
// WaitForFrontendEvent(). It's set to true by calling
|
|
105
|
+
// StopWaitingForFrontendEvent().
|
|
106
|
+
bool stop_waiting_for_frontend_event_requested_ = false;
|
|
107
|
+
ConditionVariable incoming_message_cond_;
|
|
108
|
+
// Used from any thread
|
|
109
|
+
Agent* const agent_;
|
|
110
|
+
std::shared_ptr<MainThreadHandle> handle_;
|
|
111
|
+
std::unordered_map<int, std::unique_ptr<Deletable>> managed_objects_;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
} // namespace inspector
|
|
115
|
+
} // namespace node
|
|
116
|
+
#endif // SRC_INSPECTOR_MAIN_THREAD_INTERFACE_H_
|