@encharm/cws 4.5.1 → 4.5.2
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/binding.gyp +1 -1
- package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
- package/dist/bindings/cws_linux_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 +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,211 @@
|
|
|
1
|
+
#ifndef SRC_JS_NATIVE_API_TYPES_H_
|
|
2
|
+
#define SRC_JS_NATIVE_API_TYPES_H_
|
|
3
|
+
|
|
4
|
+
// This file needs to be compatible with C compilers.
|
|
5
|
+
// This is a public include file, and these includes have essentially
|
|
6
|
+
// became part of it's API.
|
|
7
|
+
#include <stddef.h> // NOLINT(modernize-deprecated-headers)
|
|
8
|
+
#include <stdint.h> // NOLINT(modernize-deprecated-headers)
|
|
9
|
+
|
|
10
|
+
#if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900)
|
|
11
|
+
typedef uint16_t char16_t;
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#ifndef NAPI_CDECL
|
|
15
|
+
#ifdef _WIN32
|
|
16
|
+
#define NAPI_CDECL __cdecl
|
|
17
|
+
#else
|
|
18
|
+
#define NAPI_CDECL
|
|
19
|
+
#endif
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
// JSVM API types are all opaque pointers for ABI stability
|
|
23
|
+
// typedef undefined structs instead of void* for compile time type safety
|
|
24
|
+
typedef struct napi_env__* napi_env;
|
|
25
|
+
|
|
26
|
+
// We need to mark APIs which can be called during garbage collection (GC),
|
|
27
|
+
// meaning that they do not affect the state of the JS engine, and can
|
|
28
|
+
// therefore be called synchronously from a finalizer that itself runs
|
|
29
|
+
// synchronously during GC. Such APIs can receive either a `napi_env` or a
|
|
30
|
+
// `node_api_basic_env` as their first parameter, because we should be able to
|
|
31
|
+
// also call them during normal, non-garbage-collecting operations, whereas
|
|
32
|
+
// APIs that affect the state of the JS engine can only receive a `napi_env` as
|
|
33
|
+
// their first parameter, because we must not call them during GC. In lieu of
|
|
34
|
+
// inheritance, we use the properties of the const qualifier to accomplish
|
|
35
|
+
// this, because both a const and a non-const value can be passed to an API
|
|
36
|
+
// expecting a const value, but only a non-const value can be passed to an API
|
|
37
|
+
// expecting a non-const value.
|
|
38
|
+
//
|
|
39
|
+
// In conjunction with appropriate CFLAGS to warn us if we're passing a const
|
|
40
|
+
// (basic) environment into an API that expects a non-const environment, and
|
|
41
|
+
// the definition of basic finalizer function pointer types below, which
|
|
42
|
+
// receive a basic environment as their first parameter, and can thus only call
|
|
43
|
+
// basic APIs (unless the user explicitly casts the environment), we achieve
|
|
44
|
+
// the ability to ensure at compile time that we do not call APIs that affect
|
|
45
|
+
// the state of the JS engine from a synchronous (basic) finalizer.
|
|
46
|
+
#if !defined(NAPI_EXPERIMENTAL) || \
|
|
47
|
+
(defined(NAPI_EXPERIMENTAL) && \
|
|
48
|
+
(defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \
|
|
49
|
+
defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
|
|
50
|
+
typedef struct napi_env__* node_api_nogc_env;
|
|
51
|
+
#else
|
|
52
|
+
typedef const struct napi_env__* node_api_nogc_env;
|
|
53
|
+
#endif
|
|
54
|
+
typedef node_api_nogc_env node_api_basic_env;
|
|
55
|
+
|
|
56
|
+
typedef struct napi_value__* napi_value;
|
|
57
|
+
typedef struct napi_ref__* napi_ref;
|
|
58
|
+
typedef struct napi_handle_scope__* napi_handle_scope;
|
|
59
|
+
typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
|
|
60
|
+
typedef struct napi_callback_info__* napi_callback_info;
|
|
61
|
+
typedef struct napi_deferred__* napi_deferred;
|
|
62
|
+
|
|
63
|
+
typedef enum {
|
|
64
|
+
napi_default = 0,
|
|
65
|
+
napi_writable = 1 << 0,
|
|
66
|
+
napi_enumerable = 1 << 1,
|
|
67
|
+
napi_configurable = 1 << 2,
|
|
68
|
+
|
|
69
|
+
// Used with napi_define_class to distinguish static properties
|
|
70
|
+
// from instance properties. Ignored by napi_define_properties.
|
|
71
|
+
napi_static = 1 << 10,
|
|
72
|
+
|
|
73
|
+
#if NAPI_VERSION >= 8
|
|
74
|
+
// Default for class methods.
|
|
75
|
+
napi_default_method = napi_writable | napi_configurable,
|
|
76
|
+
|
|
77
|
+
// Default for object properties, like in JS obj[prop].
|
|
78
|
+
napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable,
|
|
79
|
+
#endif // NAPI_VERSION >= 8
|
|
80
|
+
} napi_property_attributes;
|
|
81
|
+
|
|
82
|
+
typedef enum {
|
|
83
|
+
// ES6 types (corresponds to typeof)
|
|
84
|
+
napi_undefined,
|
|
85
|
+
napi_null,
|
|
86
|
+
napi_boolean,
|
|
87
|
+
napi_number,
|
|
88
|
+
napi_string,
|
|
89
|
+
napi_symbol,
|
|
90
|
+
napi_object,
|
|
91
|
+
napi_function,
|
|
92
|
+
napi_external,
|
|
93
|
+
napi_bigint,
|
|
94
|
+
} napi_valuetype;
|
|
95
|
+
|
|
96
|
+
typedef enum {
|
|
97
|
+
napi_int8_array,
|
|
98
|
+
napi_uint8_array,
|
|
99
|
+
napi_uint8_clamped_array,
|
|
100
|
+
napi_int16_array,
|
|
101
|
+
napi_uint16_array,
|
|
102
|
+
napi_int32_array,
|
|
103
|
+
napi_uint32_array,
|
|
104
|
+
napi_float32_array,
|
|
105
|
+
napi_float64_array,
|
|
106
|
+
napi_bigint64_array,
|
|
107
|
+
napi_biguint64_array,
|
|
108
|
+
} napi_typedarray_type;
|
|
109
|
+
|
|
110
|
+
typedef enum {
|
|
111
|
+
napi_ok,
|
|
112
|
+
napi_invalid_arg,
|
|
113
|
+
napi_object_expected,
|
|
114
|
+
napi_string_expected,
|
|
115
|
+
napi_name_expected,
|
|
116
|
+
napi_function_expected,
|
|
117
|
+
napi_number_expected,
|
|
118
|
+
napi_boolean_expected,
|
|
119
|
+
napi_array_expected,
|
|
120
|
+
napi_generic_failure,
|
|
121
|
+
napi_pending_exception,
|
|
122
|
+
napi_cancelled,
|
|
123
|
+
napi_escape_called_twice,
|
|
124
|
+
napi_handle_scope_mismatch,
|
|
125
|
+
napi_callback_scope_mismatch,
|
|
126
|
+
napi_queue_full,
|
|
127
|
+
napi_closing,
|
|
128
|
+
napi_bigint_expected,
|
|
129
|
+
napi_date_expected,
|
|
130
|
+
napi_arraybuffer_expected,
|
|
131
|
+
napi_detachable_arraybuffer_expected,
|
|
132
|
+
napi_would_deadlock, // unused
|
|
133
|
+
napi_no_external_buffers_allowed,
|
|
134
|
+
napi_cannot_run_js,
|
|
135
|
+
} napi_status;
|
|
136
|
+
// Note: when adding a new enum value to `napi_status`, please also update
|
|
137
|
+
// * `const int last_status` in the definition of `napi_get_last_error_info()'
|
|
138
|
+
// in file js_native_api_v8.cc.
|
|
139
|
+
// * `const char* error_messages[]` in file js_native_api_v8.cc with a brief
|
|
140
|
+
// message explaining the error.
|
|
141
|
+
// * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
|
|
142
|
+
// added value(s).
|
|
143
|
+
|
|
144
|
+
typedef napi_value(NAPI_CDECL* napi_callback)(napi_env env,
|
|
145
|
+
napi_callback_info info);
|
|
146
|
+
typedef void(NAPI_CDECL* napi_finalize)(napi_env env,
|
|
147
|
+
void* finalize_data,
|
|
148
|
+
void* finalize_hint);
|
|
149
|
+
|
|
150
|
+
#if !defined(NAPI_EXPERIMENTAL) || \
|
|
151
|
+
(defined(NAPI_EXPERIMENTAL) && \
|
|
152
|
+
(defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \
|
|
153
|
+
defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
|
|
154
|
+
typedef napi_finalize node_api_nogc_finalize;
|
|
155
|
+
#else
|
|
156
|
+
typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env,
|
|
157
|
+
void* finalize_data,
|
|
158
|
+
void* finalize_hint);
|
|
159
|
+
#endif
|
|
160
|
+
typedef node_api_nogc_finalize node_api_basic_finalize;
|
|
161
|
+
|
|
162
|
+
typedef struct {
|
|
163
|
+
// One of utf8name or name should be NULL.
|
|
164
|
+
const char* utf8name;
|
|
165
|
+
napi_value name;
|
|
166
|
+
|
|
167
|
+
napi_callback method;
|
|
168
|
+
napi_callback getter;
|
|
169
|
+
napi_callback setter;
|
|
170
|
+
napi_value value;
|
|
171
|
+
|
|
172
|
+
napi_property_attributes attributes;
|
|
173
|
+
void* data;
|
|
174
|
+
} napi_property_descriptor;
|
|
175
|
+
|
|
176
|
+
typedef struct {
|
|
177
|
+
const char* error_message;
|
|
178
|
+
void* engine_reserved;
|
|
179
|
+
uint32_t engine_error_code;
|
|
180
|
+
napi_status error_code;
|
|
181
|
+
} napi_extended_error_info;
|
|
182
|
+
|
|
183
|
+
#if NAPI_VERSION >= 6
|
|
184
|
+
typedef enum {
|
|
185
|
+
napi_key_include_prototypes,
|
|
186
|
+
napi_key_own_only
|
|
187
|
+
} napi_key_collection_mode;
|
|
188
|
+
|
|
189
|
+
typedef enum {
|
|
190
|
+
napi_key_all_properties = 0,
|
|
191
|
+
napi_key_writable = 1,
|
|
192
|
+
napi_key_enumerable = 1 << 1,
|
|
193
|
+
napi_key_configurable = 1 << 2,
|
|
194
|
+
napi_key_skip_strings = 1 << 3,
|
|
195
|
+
napi_key_skip_symbols = 1 << 4
|
|
196
|
+
} napi_key_filter;
|
|
197
|
+
|
|
198
|
+
typedef enum {
|
|
199
|
+
napi_key_keep_numbers,
|
|
200
|
+
napi_key_numbers_to_strings
|
|
201
|
+
} napi_key_conversion;
|
|
202
|
+
#endif // NAPI_VERSION >= 6
|
|
203
|
+
|
|
204
|
+
#if NAPI_VERSION >= 8
|
|
205
|
+
typedef struct {
|
|
206
|
+
uint64_t lower;
|
|
207
|
+
uint64_t upper;
|
|
208
|
+
} napi_type_tag;
|
|
209
|
+
#endif // NAPI_VERSION >= 8
|
|
210
|
+
|
|
211
|
+
#endif // SRC_JS_NATIVE_API_TYPES_H_
|
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
#ifndef SRC_JS_NATIVE_API_V8_H_
|
|
2
|
+
#define SRC_JS_NATIVE_API_V8_H_
|
|
3
|
+
|
|
4
|
+
#include "js_native_api_types.h"
|
|
5
|
+
#include "js_native_api_v8_internals.h"
|
|
6
|
+
|
|
7
|
+
inline napi_status napi_clear_last_error(node_api_basic_env env);
|
|
8
|
+
|
|
9
|
+
namespace v8impl {
|
|
10
|
+
|
|
11
|
+
// Base class to track references and finalizers in a doubly linked list.
|
|
12
|
+
class RefTracker {
|
|
13
|
+
public:
|
|
14
|
+
using RefList = RefTracker;
|
|
15
|
+
|
|
16
|
+
RefTracker() = default;
|
|
17
|
+
virtual ~RefTracker() = default;
|
|
18
|
+
virtual void Finalize() {}
|
|
19
|
+
|
|
20
|
+
inline void Link(RefList* list) {
|
|
21
|
+
prev_ = list;
|
|
22
|
+
next_ = list->next_;
|
|
23
|
+
if (next_ != nullptr) {
|
|
24
|
+
next_->prev_ = this;
|
|
25
|
+
}
|
|
26
|
+
list->next_ = this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
inline void Unlink() {
|
|
30
|
+
if (prev_ != nullptr) {
|
|
31
|
+
prev_->next_ = next_;
|
|
32
|
+
}
|
|
33
|
+
if (next_ != nullptr) {
|
|
34
|
+
next_->prev_ = prev_;
|
|
35
|
+
}
|
|
36
|
+
prev_ = nullptr;
|
|
37
|
+
next_ = nullptr;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static void FinalizeAll(RefList* list) {
|
|
41
|
+
while (list->next_ != nullptr) {
|
|
42
|
+
list->next_->Finalize();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
RefList* next_ = nullptr;
|
|
48
|
+
RefList* prev_ = nullptr;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
} // end of namespace v8impl
|
|
52
|
+
|
|
53
|
+
struct napi_env__ {
|
|
54
|
+
explicit napi_env__(v8::Local<v8::Context> context,
|
|
55
|
+
int32_t module_api_version)
|
|
56
|
+
: isolate(context->GetIsolate()),
|
|
57
|
+
context_persistent(isolate, context),
|
|
58
|
+
module_api_version(module_api_version) {
|
|
59
|
+
napi_clear_last_error(this);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
inline v8::Local<v8::Context> context() const {
|
|
63
|
+
return v8impl::PersistentToLocal::Strong(context_persistent);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
inline void Ref() { refs++; }
|
|
67
|
+
inline void Unref() {
|
|
68
|
+
if (--refs == 0) DeleteMe();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
virtual bool can_call_into_js() const { return true; }
|
|
72
|
+
|
|
73
|
+
static inline void HandleThrow(napi_env env, v8::Local<v8::Value> value) {
|
|
74
|
+
if (env->terminatedOrTerminating()) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
env->isolate->ThrowException(value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// i.e. whether v8 exited or is about to exit
|
|
81
|
+
inline bool terminatedOrTerminating() {
|
|
82
|
+
return this->isolate->IsExecutionTerminating() || !can_call_into_js();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// v8 uses a special exception to indicate termination, the
|
|
86
|
+
// `handle_exception` callback should identify such case using
|
|
87
|
+
// terminatedOrTerminating() before actually handle the exception
|
|
88
|
+
template <typename T, typename U = decltype(HandleThrow)>
|
|
89
|
+
inline void CallIntoModule(T&& call, U&& handle_exception = HandleThrow) {
|
|
90
|
+
int open_handle_scopes_before = open_handle_scopes;
|
|
91
|
+
int open_callback_scopes_before = open_callback_scopes;
|
|
92
|
+
napi_clear_last_error(this);
|
|
93
|
+
call(this);
|
|
94
|
+
CHECK_EQ(open_handle_scopes, open_handle_scopes_before);
|
|
95
|
+
CHECK_EQ(open_callback_scopes, open_callback_scopes_before);
|
|
96
|
+
if (!last_exception.IsEmpty()) {
|
|
97
|
+
handle_exception(this, last_exception.Get(this->isolate));
|
|
98
|
+
last_exception.Reset();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
virtual void CallFinalizer(napi_finalize cb, void* data, void* hint) = 0;
|
|
103
|
+
|
|
104
|
+
// Invoke finalizer from V8 garbage collector.
|
|
105
|
+
void InvokeFinalizerFromGC(v8impl::RefTracker* finalizer);
|
|
106
|
+
|
|
107
|
+
// Enqueue the finalizer to the napi_env's own queue of the second pass
|
|
108
|
+
// weak callback.
|
|
109
|
+
// Implementation should drain the queue at the time it is safe to call
|
|
110
|
+
// into JavaScript.
|
|
111
|
+
virtual void EnqueueFinalizer(v8impl::RefTracker* finalizer) {
|
|
112
|
+
pending_finalizers.emplace(finalizer);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Remove the finalizer from the scheduled second pass weak callback queue.
|
|
116
|
+
// The finalizer can be deleted after this call.
|
|
117
|
+
virtual void DequeueFinalizer(v8impl::RefTracker* finalizer) {
|
|
118
|
+
pending_finalizers.erase(finalizer);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
virtual void DeleteMe() {
|
|
122
|
+
// First we must finalize those references that have `napi_finalizer`
|
|
123
|
+
// callbacks. The reason is that addons might store other references which
|
|
124
|
+
// they delete during their `napi_finalizer` callbacks. If we deleted such
|
|
125
|
+
// references here first, they would be doubly deleted when the
|
|
126
|
+
// `napi_finalizer` deleted them subsequently.
|
|
127
|
+
v8impl::RefTracker::FinalizeAll(&finalizing_reflist);
|
|
128
|
+
v8impl::RefTracker::FinalizeAll(&reflist);
|
|
129
|
+
delete this;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
void CheckGCAccess() {
|
|
133
|
+
if (module_api_version == NAPI_VERSION_EXPERIMENTAL && in_gc_finalizer) {
|
|
134
|
+
v8impl::OnFatalError(
|
|
135
|
+
nullptr,
|
|
136
|
+
"Finalizer is calling a function that may affect GC state.\n"
|
|
137
|
+
"The finalizers are run directly from GC and must not affect GC "
|
|
138
|
+
"state.\n"
|
|
139
|
+
"Use `node_api_post_finalizer` from inside of the finalizer to work "
|
|
140
|
+
"around this issue.\n"
|
|
141
|
+
"It schedules the call as a new task in the event loop.");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
v8::Isolate* const isolate; // Shortcut for context()->GetIsolate()
|
|
146
|
+
v8impl::Persistent<v8::Context> context_persistent;
|
|
147
|
+
|
|
148
|
+
v8impl::Persistent<v8::Value> last_exception;
|
|
149
|
+
|
|
150
|
+
// We store references in two different lists, depending on whether they have
|
|
151
|
+
// `napi_finalizer` callbacks, because we must first finalize the ones that
|
|
152
|
+
// have such a callback. See `~napi_env__()` above for details.
|
|
153
|
+
v8impl::RefTracker::RefList reflist;
|
|
154
|
+
v8impl::RefTracker::RefList finalizing_reflist;
|
|
155
|
+
// The invocation order of the finalizers is not determined.
|
|
156
|
+
std::unordered_set<v8impl::RefTracker*> pending_finalizers;
|
|
157
|
+
napi_extended_error_info last_error;
|
|
158
|
+
int open_handle_scopes = 0;
|
|
159
|
+
int open_callback_scopes = 0;
|
|
160
|
+
int refs = 1;
|
|
161
|
+
void* instance_data = nullptr;
|
|
162
|
+
int32_t module_api_version = NODE_API_DEFAULT_MODULE_API_VERSION;
|
|
163
|
+
bool in_gc_finalizer = false;
|
|
164
|
+
|
|
165
|
+
protected:
|
|
166
|
+
// Should not be deleted directly. Delete with `napi_env__::DeleteMe()`
|
|
167
|
+
// instead.
|
|
168
|
+
virtual ~napi_env__() = default;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
inline napi_status napi_clear_last_error(node_api_basic_env basic_env) {
|
|
172
|
+
napi_env env = const_cast<napi_env>(basic_env);
|
|
173
|
+
env->last_error.error_code = napi_ok;
|
|
174
|
+
env->last_error.engine_error_code = 0;
|
|
175
|
+
env->last_error.engine_reserved = nullptr;
|
|
176
|
+
env->last_error.error_message = nullptr;
|
|
177
|
+
return napi_ok;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
inline napi_status napi_set_last_error(node_api_basic_env basic_env,
|
|
181
|
+
napi_status error_code,
|
|
182
|
+
uint32_t engine_error_code = 0,
|
|
183
|
+
void* engine_reserved = nullptr) {
|
|
184
|
+
napi_env env = const_cast<napi_env>(basic_env);
|
|
185
|
+
env->last_error.error_code = error_code;
|
|
186
|
+
env->last_error.engine_error_code = engine_error_code;
|
|
187
|
+
env->last_error.engine_reserved = engine_reserved;
|
|
188
|
+
return error_code;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
#define RETURN_STATUS_IF_FALSE(env, condition, status) \
|
|
192
|
+
do { \
|
|
193
|
+
if (!(condition)) { \
|
|
194
|
+
return napi_set_last_error((env), (status)); \
|
|
195
|
+
} \
|
|
196
|
+
} while (0)
|
|
197
|
+
|
|
198
|
+
#define RETURN_STATUS_IF_FALSE_WITH_PREAMBLE(env, condition, status) \
|
|
199
|
+
do { \
|
|
200
|
+
if (!(condition)) { \
|
|
201
|
+
return napi_set_last_error( \
|
|
202
|
+
(env), try_catch.HasCaught() ? napi_pending_exception : (status)); \
|
|
203
|
+
} \
|
|
204
|
+
} while (0)
|
|
205
|
+
|
|
206
|
+
#define CHECK_ENV(env) \
|
|
207
|
+
do { \
|
|
208
|
+
if ((env) == nullptr) { \
|
|
209
|
+
return napi_invalid_arg; \
|
|
210
|
+
} \
|
|
211
|
+
} while (0)
|
|
212
|
+
|
|
213
|
+
#define CHECK_ENV_NOT_IN_GC(env) \
|
|
214
|
+
do { \
|
|
215
|
+
CHECK_ENV((env)); \
|
|
216
|
+
(env)->CheckGCAccess(); \
|
|
217
|
+
} while (0)
|
|
218
|
+
|
|
219
|
+
#define CHECK_ARG(env, arg) \
|
|
220
|
+
RETURN_STATUS_IF_FALSE((env), ((arg) != nullptr), napi_invalid_arg)
|
|
221
|
+
|
|
222
|
+
#define CHECK_ARG_WITH_PREAMBLE(env, arg) \
|
|
223
|
+
RETURN_STATUS_IF_FALSE_WITH_PREAMBLE( \
|
|
224
|
+
(env), ((arg) != nullptr), napi_invalid_arg)
|
|
225
|
+
|
|
226
|
+
#define CHECK_MAYBE_EMPTY(env, maybe, status) \
|
|
227
|
+
RETURN_STATUS_IF_FALSE((env), !((maybe).IsEmpty()), (status))
|
|
228
|
+
|
|
229
|
+
#define CHECK_MAYBE_EMPTY_WITH_PREAMBLE(env, maybe, status) \
|
|
230
|
+
RETURN_STATUS_IF_FALSE_WITH_PREAMBLE((env), !((maybe).IsEmpty()), (status))
|
|
231
|
+
|
|
232
|
+
// NAPI_PREAMBLE is not wrapped in do..while: try_catch must have function scope
|
|
233
|
+
#define NAPI_PREAMBLE(env) \
|
|
234
|
+
CHECK_ENV_NOT_IN_GC((env)); \
|
|
235
|
+
RETURN_STATUS_IF_FALSE( \
|
|
236
|
+
(env), (env)->last_exception.IsEmpty(), napi_pending_exception); \
|
|
237
|
+
RETURN_STATUS_IF_FALSE( \
|
|
238
|
+
(env), \
|
|
239
|
+
(env)->can_call_into_js(), \
|
|
240
|
+
(env->module_api_version >= 10 ? napi_cannot_run_js \
|
|
241
|
+
: napi_pending_exception)); \
|
|
242
|
+
napi_clear_last_error((env)); \
|
|
243
|
+
v8impl::TryCatch try_catch((env))
|
|
244
|
+
|
|
245
|
+
#define CHECK_TO_TYPE(env, type, context, result, src, status) \
|
|
246
|
+
do { \
|
|
247
|
+
CHECK_ARG((env), (src)); \
|
|
248
|
+
auto maybe = v8impl::V8LocalValueFromJsValue((src))->To##type((context)); \
|
|
249
|
+
CHECK_MAYBE_EMPTY((env), maybe, (status)); \
|
|
250
|
+
(result) = maybe.ToLocalChecked(); \
|
|
251
|
+
} while (0)
|
|
252
|
+
|
|
253
|
+
#define CHECK_TO_TYPE_WITH_PREAMBLE(env, type, context, result, src, status) \
|
|
254
|
+
do { \
|
|
255
|
+
CHECK_ARG_WITH_PREAMBLE((env), (src)); \
|
|
256
|
+
auto maybe = v8impl::V8LocalValueFromJsValue((src))->To##type((context)); \
|
|
257
|
+
CHECK_MAYBE_EMPTY_WITH_PREAMBLE((env), maybe, (status)); \
|
|
258
|
+
(result) = maybe.ToLocalChecked(); \
|
|
259
|
+
} while (0)
|
|
260
|
+
|
|
261
|
+
#define CHECK_TO_FUNCTION(env, result, src) \
|
|
262
|
+
do { \
|
|
263
|
+
CHECK_ARG((env), (src)); \
|
|
264
|
+
v8::Local<v8::Value> v8value = v8impl::V8LocalValueFromJsValue((src)); \
|
|
265
|
+
RETURN_STATUS_IF_FALSE((env), v8value->IsFunction(), napi_invalid_arg); \
|
|
266
|
+
(result) = v8value.As<v8::Function>(); \
|
|
267
|
+
} while (0)
|
|
268
|
+
|
|
269
|
+
#define CHECK_TO_OBJECT(env, context, result, src) \
|
|
270
|
+
CHECK_TO_TYPE((env), Object, (context), (result), (src), napi_object_expected)
|
|
271
|
+
|
|
272
|
+
#define CHECK_TO_OBJECT_WITH_PREAMBLE(env, context, result, src) \
|
|
273
|
+
CHECK_TO_TYPE_WITH_PREAMBLE( \
|
|
274
|
+
(env), Object, (context), (result), (src), napi_object_expected)
|
|
275
|
+
|
|
276
|
+
#define CHECK_TO_STRING(env, context, result, src) \
|
|
277
|
+
CHECK_TO_TYPE((env), String, (context), (result), (src), napi_string_expected)
|
|
278
|
+
|
|
279
|
+
#define GET_RETURN_STATUS(env) \
|
|
280
|
+
(!try_catch.HasCaught() \
|
|
281
|
+
? napi_ok \
|
|
282
|
+
: napi_set_last_error((env), napi_pending_exception))
|
|
283
|
+
|
|
284
|
+
#define THROW_RANGE_ERROR_IF_FALSE(env, condition, error, message) \
|
|
285
|
+
do { \
|
|
286
|
+
if (!(condition)) { \
|
|
287
|
+
napi_throw_range_error((env), (error), (message)); \
|
|
288
|
+
return napi_set_last_error((env), napi_generic_failure); \
|
|
289
|
+
} \
|
|
290
|
+
} while (0)
|
|
291
|
+
|
|
292
|
+
#define CHECK_MAYBE_EMPTY_WITH_PREAMBLE(env, maybe, status) \
|
|
293
|
+
RETURN_STATUS_IF_FALSE_WITH_PREAMBLE((env), !((maybe).IsEmpty()), (status))
|
|
294
|
+
|
|
295
|
+
#define STATUS_CALL(call) \
|
|
296
|
+
do { \
|
|
297
|
+
napi_status status = (call); \
|
|
298
|
+
if (status != napi_ok) return status; \
|
|
299
|
+
} while (0)
|
|
300
|
+
|
|
301
|
+
namespace v8impl {
|
|
302
|
+
|
|
303
|
+
//=== Conversion between V8 Handles and napi_value ========================
|
|
304
|
+
|
|
305
|
+
// This asserts v8::Local<> will always be implemented with a single
|
|
306
|
+
// pointer field so that we can pass it around as a void*.
|
|
307
|
+
static_assert(sizeof(v8::Local<v8::Value>) == sizeof(napi_value),
|
|
308
|
+
"Cannot convert between v8::Local<v8::Value> and napi_value");
|
|
309
|
+
|
|
310
|
+
inline napi_value JsValueFromV8LocalValue(v8::Local<v8::Value> local) {
|
|
311
|
+
return reinterpret_cast<napi_value>(*local);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
inline v8::Local<v8::Value> V8LocalValueFromJsValue(napi_value v) {
|
|
315
|
+
v8::Local<v8::Value> local;
|
|
316
|
+
memcpy(static_cast<void*>(&local), &v, sizeof(v));
|
|
317
|
+
return local;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Adapter for napi_finalize callbacks.
|
|
321
|
+
class Finalizer {
|
|
322
|
+
public:
|
|
323
|
+
Finalizer(napi_env env,
|
|
324
|
+
napi_finalize finalize_callback,
|
|
325
|
+
void* finalize_data,
|
|
326
|
+
void* finalize_hint)
|
|
327
|
+
: env_(env),
|
|
328
|
+
finalize_callback_(finalize_callback),
|
|
329
|
+
finalize_data_(finalize_data),
|
|
330
|
+
finalize_hint_(finalize_hint) {}
|
|
331
|
+
|
|
332
|
+
napi_env env() { return env_; }
|
|
333
|
+
void* data() { return finalize_data_; }
|
|
334
|
+
|
|
335
|
+
void ResetEnv();
|
|
336
|
+
void ResetFinalizer();
|
|
337
|
+
void CallFinalizer();
|
|
338
|
+
|
|
339
|
+
private:
|
|
340
|
+
napi_env env_;
|
|
341
|
+
napi_finalize finalize_callback_;
|
|
342
|
+
void* finalize_data_;
|
|
343
|
+
void* finalize_hint_;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
class TryCatch : public v8::TryCatch {
|
|
347
|
+
public:
|
|
348
|
+
explicit TryCatch(napi_env env) : v8::TryCatch(env->isolate), _env(env) {}
|
|
349
|
+
|
|
350
|
+
~TryCatch() {
|
|
351
|
+
if (HasCaught()) {
|
|
352
|
+
_env->last_exception.Reset(_env->isolate, Exception());
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
private:
|
|
357
|
+
napi_env _env;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// Wrapper around Finalizer that can be tracked.
|
|
361
|
+
class TrackedFinalizer final : public RefTracker {
|
|
362
|
+
public:
|
|
363
|
+
static TrackedFinalizer* New(napi_env env,
|
|
364
|
+
napi_finalize finalize_callback,
|
|
365
|
+
void* finalize_data,
|
|
366
|
+
void* finalize_hint);
|
|
367
|
+
~TrackedFinalizer() override;
|
|
368
|
+
|
|
369
|
+
void* data() { return finalizer_.data(); }
|
|
370
|
+
|
|
371
|
+
private:
|
|
372
|
+
TrackedFinalizer(napi_env env,
|
|
373
|
+
napi_finalize finalize_callback,
|
|
374
|
+
void* finalize_data,
|
|
375
|
+
void* finalize_hint);
|
|
376
|
+
void Finalize() override;
|
|
377
|
+
|
|
378
|
+
private:
|
|
379
|
+
Finalizer finalizer_;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// Ownership of a reference.
|
|
383
|
+
enum class ReferenceOwnership : uint8_t {
|
|
384
|
+
// The reference is owned by the runtime. No userland call is needed to
|
|
385
|
+
// destruct the reference.
|
|
386
|
+
kRuntime,
|
|
387
|
+
// The reference is owned by the userland. User code is responsible to delete
|
|
388
|
+
// the reference with appropriate node-api calls.
|
|
389
|
+
kUserland,
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// Wrapper around v8impl::Persistent.
|
|
393
|
+
class Reference : public RefTracker {
|
|
394
|
+
public:
|
|
395
|
+
static Reference* New(napi_env env,
|
|
396
|
+
v8::Local<v8::Value> value,
|
|
397
|
+
uint32_t initial_refcount,
|
|
398
|
+
ReferenceOwnership ownership);
|
|
399
|
+
~Reference() override;
|
|
400
|
+
|
|
401
|
+
uint32_t Ref();
|
|
402
|
+
uint32_t Unref();
|
|
403
|
+
v8::Local<v8::Value> Get(napi_env env);
|
|
404
|
+
|
|
405
|
+
virtual void ResetFinalizer() {}
|
|
406
|
+
virtual void* Data() { return nullptr; }
|
|
407
|
+
|
|
408
|
+
uint32_t refcount() const { return refcount_; }
|
|
409
|
+
ReferenceOwnership ownership() { return ownership_; }
|
|
410
|
+
|
|
411
|
+
protected:
|
|
412
|
+
Reference(napi_env env,
|
|
413
|
+
v8::Local<v8::Value> value,
|
|
414
|
+
uint32_t initial_refcount,
|
|
415
|
+
ReferenceOwnership ownership);
|
|
416
|
+
virtual void CallUserFinalizer() {}
|
|
417
|
+
virtual void InvokeFinalizerFromGC();
|
|
418
|
+
|
|
419
|
+
private:
|
|
420
|
+
static void WeakCallback(const v8::WeakCallbackInfo<Reference>& data);
|
|
421
|
+
void SetWeak();
|
|
422
|
+
void Finalize() override;
|
|
423
|
+
|
|
424
|
+
private:
|
|
425
|
+
v8impl::Persistent<v8::Value> persistent_;
|
|
426
|
+
uint32_t refcount_;
|
|
427
|
+
ReferenceOwnership ownership_;
|
|
428
|
+
bool can_be_weak_;
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// Reference that can store additional data.
|
|
432
|
+
class ReferenceWithData final : public Reference {
|
|
433
|
+
public:
|
|
434
|
+
static ReferenceWithData* New(napi_env env,
|
|
435
|
+
v8::Local<v8::Value> value,
|
|
436
|
+
uint32_t initial_refcount,
|
|
437
|
+
ReferenceOwnership ownership,
|
|
438
|
+
void* data);
|
|
439
|
+
|
|
440
|
+
void* Data() override { return data_; }
|
|
441
|
+
|
|
442
|
+
private:
|
|
443
|
+
ReferenceWithData(napi_env env,
|
|
444
|
+
v8::Local<v8::Value> value,
|
|
445
|
+
uint32_t initial_refcount,
|
|
446
|
+
ReferenceOwnership ownership,
|
|
447
|
+
void* data);
|
|
448
|
+
|
|
449
|
+
private:
|
|
450
|
+
void* data_;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
// Reference that has a user finalizer callback.
|
|
454
|
+
class ReferenceWithFinalizer final : public Reference {
|
|
455
|
+
public:
|
|
456
|
+
static ReferenceWithFinalizer* New(napi_env env,
|
|
457
|
+
v8::Local<v8::Value> value,
|
|
458
|
+
uint32_t initial_refcount,
|
|
459
|
+
ReferenceOwnership ownership,
|
|
460
|
+
napi_finalize finalize_callback,
|
|
461
|
+
void* finalize_data,
|
|
462
|
+
void* finalize_hint);
|
|
463
|
+
~ReferenceWithFinalizer() override;
|
|
464
|
+
|
|
465
|
+
void ResetFinalizer() override { finalizer_.ResetFinalizer(); }
|
|
466
|
+
void* Data() override { return finalizer_.data(); }
|
|
467
|
+
|
|
468
|
+
private:
|
|
469
|
+
ReferenceWithFinalizer(napi_env env,
|
|
470
|
+
v8::Local<v8::Value> value,
|
|
471
|
+
uint32_t initial_refcount,
|
|
472
|
+
ReferenceOwnership ownership,
|
|
473
|
+
napi_finalize finalize_callback,
|
|
474
|
+
void* finalize_data,
|
|
475
|
+
void* finalize_hint);
|
|
476
|
+
void CallUserFinalizer() override;
|
|
477
|
+
void InvokeFinalizerFromGC() override;
|
|
478
|
+
|
|
479
|
+
private:
|
|
480
|
+
Finalizer finalizer_;
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
} // end of namespace v8impl
|
|
484
|
+
|
|
485
|
+
#endif // SRC_JS_NATIVE_API_V8_H_
|