@encharm/cws 4.3.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -7
- package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
- package/dist/bindings/cws_darwin_x64_node108.node +0 -0
- package/dist/bindings/cws_darwin_x64_node115.node +0 -0
- package/dist/bindings/cws_darwin_x64_node83.node +0 -0
- package/dist/bindings/cws_darwin_x64_node93.node +0 -0
- package/dist/bindings/cws_linux_arm64_node108.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node83.node +0 -0
- package/dist/bindings/cws_linux_arm64_node93.node +0 -0
- package/dist/bindings/cws_linux_x64_node108.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node83.node +0 -0
- package/dist/bindings/cws_linux_x64_node93.node +0 -0
- package/dist/bindings/cws_win32_x64_node108.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node83.node +0 -0
- package/dist/bindings/cws_win32_x64_node93.node +0 -0
- package/dist/shared.js +1 -1
- package/package.json +5 -5
- package/src/Addon.cpp +4 -12
- package/src/Addon.h +67 -91
- package/src/Socket.h +1 -0
- package/src/cSNode.cpp +3 -8
- package/src/headers/20/acorn_version.h +6 -0
- package/src/headers/20/aliased_buffer-inl.h +243 -0
- package/src/headers/20/aliased_buffer.h +206 -0
- package/src/headers/20/aliased_struct-inl.h +54 -0
- package/src/headers/20/aliased_struct.h +63 -0
- package/src/headers/20/async_wrap-inl.h +93 -0
- package/src/headers/20/async_wrap.h +252 -0
- package/src/headers/20/base64-inl.h +193 -0
- package/src/headers/20/base64.h +53 -0
- package/src/headers/20/base64_version.h +6 -0
- package/src/headers/20/base_object-inl.h +316 -0
- package/src/headers/20/base_object.h +320 -0
- package/src/headers/20/base_object_types.h +73 -0
- package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
- package/src/headers/20/blob_serializer_deserializer.h +132 -0
- package/src/headers/20/callback_queue-inl.h +97 -0
- package/src/headers/20/callback_queue.h +79 -0
- package/src/headers/20/cares_wrap.h +524 -0
- package/src/headers/20/cjs_module_lexer_version.h +6 -0
- package/src/headers/20/cleanup_queue-inl.h +62 -0
- package/src/headers/20/cleanup_queue.h +85 -0
- package/src/headers/20/connect_wrap.h +26 -0
- package/src/headers/20/connection_wrap.h +30 -0
- package/src/headers/20/cppgc/DEPS +8 -0
- package/src/headers/20/cppgc/OWNERS +2 -0
- package/src/headers/20/cppgc/README.md +135 -0
- package/src/headers/20/cppgc/allocation.h +310 -0
- package/src/headers/20/cppgc/common.h +28 -0
- package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
- package/src/headers/20/cppgc/custom-space.h +97 -0
- package/src/headers/20/cppgc/default-platform.h +67 -0
- package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
- package/src/headers/20/cppgc/explicit-management.h +100 -0
- package/src/headers/20/cppgc/garbage-collected.h +106 -0
- package/src/headers/20/cppgc/heap-consistency.h +309 -0
- package/src/headers/20/cppgc/heap-handle.h +48 -0
- package/src/headers/20/cppgc/heap-state.h +82 -0
- package/src/headers/20/cppgc/heap-statistics.h +120 -0
- package/src/headers/20/cppgc/heap.h +202 -0
- package/src/headers/20/cppgc/internal/api-constants.h +68 -0
- package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
- package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
- package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
- package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
- package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
- package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
- package/src/headers/20/cppgc/internal/gc-info.h +157 -0
- package/src/headers/20/cppgc/internal/logging.h +50 -0
- package/src/headers/20/cppgc/internal/member-storage.h +248 -0
- package/src/headers/20/cppgc/internal/name-trait.h +137 -0
- package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
- package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
- package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
- package/src/headers/20/cppgc/liveness-broker.h +78 -0
- package/src/headers/20/cppgc/macros.h +35 -0
- package/src/headers/20/cppgc/member.h +604 -0
- package/src/headers/20/cppgc/name-provider.h +65 -0
- package/src/headers/20/cppgc/object-size-trait.h +58 -0
- package/src/headers/20/cppgc/persistent.h +373 -0
- package/src/headers/20/cppgc/platform.h +158 -0
- package/src/headers/20/cppgc/prefinalizer.h +75 -0
- package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
- package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
- package/src/headers/20/cppgc/source-location.h +92 -0
- package/src/headers/20/cppgc/testing.h +106 -0
- package/src/headers/20/cppgc/trace-trait.h +120 -0
- package/src/headers/20/cppgc/type-traits.h +250 -0
- package/src/headers/20/cppgc/visitor.h +426 -0
- package/src/headers/20/crypto/crypto_clienthello.h +131 -0
- package/src/headers/20/crypto/crypto_context.h +160 -0
- package/src/headers/20/crypto/crypto_keys.h +419 -0
- package/src/headers/20/crypto/crypto_tls.h +304 -0
- package/src/headers/20/crypto/crypto_util.h +806 -0
- package/src/headers/20/crypto_clienthello.h +131 -0
- package/src/headers/20/debug_utils-inl.h +226 -0
- package/src/headers/20/debug_utils.h +188 -0
- package/src/headers/20/diagnosticfilename-inl.h +33 -0
- package/src/headers/20/encoding_binding.h +59 -0
- package/src/headers/20/env-inl.h +923 -0
- package/src/headers/20/env.h +1193 -0
- package/src/headers/20/env_properties.h +446 -0
- package/src/headers/20/handle_wrap.h +123 -0
- package/src/headers/20/histogram-inl.h +107 -0
- package/src/headers/20/histogram.h +240 -0
- package/src/headers/20/inspector_agent.h +144 -0
- package/src/headers/20/inspector_io.h +78 -0
- package/src/headers/20/inspector_profiler.h +149 -0
- package/src/headers/20/inspector_socket.h +60 -0
- package/src/headers/20/inspector_socket_server.h +110 -0
- package/src/headers/20/js_native_api.h +601 -0
- package/src/headers/20/js_native_api_types.h +168 -0
- package/src/headers/20/js_native_api_v8.h +463 -0
- package/src/headers/20/js_native_api_v8_internals.h +45 -0
- package/src/headers/20/js_stream.h +52 -0
- package/src/headers/20/json_parser.h +38 -0
- package/src/headers/20/json_utils.h +172 -0
- package/src/headers/20/memory_tracker-inl.h +356 -0
- package/src/headers/20/memory_tracker.h +289 -0
- package/src/headers/20/module_wrap.h +117 -0
- package/src/headers/20/node.h +1516 -0
- package/src/headers/20/node_api.h +261 -0
- package/src/headers/20/node_api_internals.h +42 -0
- package/src/headers/20/node_api_types.h +52 -0
- package/src/headers/20/node_binding.h +142 -0
- package/src/headers/20/node_blob.h +159 -0
- package/src/headers/20/node_bob-inl.h +36 -0
- package/src/headers/20/node_bob.h +107 -0
- package/src/headers/20/node_buffer.h +92 -0
- package/src/headers/20/node_builtins.h +197 -0
- package/src/headers/20/node_constants.h +82 -0
- package/src/headers/20/node_context_data.h +98 -0
- package/src/headers/20/node_contextify.h +206 -0
- package/src/headers/20/node_crypto.h +56 -0
- package/src/headers/20/node_dir.h +52 -0
- package/src/headers/20/node_dotenv.h +37 -0
- package/src/headers/20/node_errors.h +313 -0
- package/src/headers/20/node_exit_code.h +54 -0
- package/src/headers/20/node_external_reference.h +172 -0
- package/src/headers/20/node_file-inl.h +389 -0
- package/src/headers/20/node_file.h +537 -0
- package/src/headers/20/node_http2.h +1146 -0
- package/src/headers/20/node_http2_state.h +147 -0
- package/src/headers/20/node_http_common-inl.h +201 -0
- package/src/headers/20/node_http_common.h +532 -0
- package/src/headers/20/node_i18n.h +145 -0
- package/src/headers/20/node_internals.h +443 -0
- package/src/headers/20/node_main_instance.h +67 -0
- package/src/headers/20/node_mem-inl.h +112 -0
- package/src/headers/20/node_mem.h +45 -0
- package/src/headers/20/node_messaging.h +377 -0
- package/src/headers/20/node_metadata.h +138 -0
- package/src/headers/20/node_mutex.h +323 -0
- package/src/headers/20/node_object_wrap.h +132 -0
- package/src/headers/20/node_options-inl.h +478 -0
- package/src/headers/20/node_options.h +538 -0
- package/src/headers/20/node_perf.h +166 -0
- package/src/headers/20/node_perf_common.h +98 -0
- package/src/headers/20/node_platform.h +195 -0
- package/src/headers/20/node_process-inl.h +26 -0
- package/src/headers/20/node_process.h +99 -0
- package/src/headers/20/node_realm-inl.h +139 -0
- package/src/headers/20/node_realm.h +184 -0
- package/src/headers/20/node_report.h +42 -0
- package/src/headers/20/node_revert.h +82 -0
- package/src/headers/20/node_root_certs.h +3443 -0
- package/src/headers/20/node_sea.h +56 -0
- package/src/headers/20/node_shadow_realm.h +46 -0
- package/src/headers/20/node_snapshot_builder.h +54 -0
- package/src/headers/20/node_snapshotable.h +164 -0
- package/src/headers/20/node_sockaddr-inl.h +266 -0
- package/src/headers/20/node_sockaddr.h +405 -0
- package/src/headers/20/node_stat_watcher.h +73 -0
- package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/20/node_threadsafe_cow.h +105 -0
- package/src/headers/20/node_union_bytes.h +81 -0
- package/src/headers/20/node_url.h +92 -0
- package/src/headers/20/node_v8.h +77 -0
- package/src/headers/20/node_v8_platform-inl.h +205 -0
- package/src/headers/20/node_version.h +109 -0
- package/src/headers/20/node_wasi.h +184 -0
- package/src/headers/20/node_wasm_web_api.h +55 -0
- package/src/headers/20/node_watchdog.h +154 -0
- package/src/headers/20/node_worker.h +151 -0
- package/src/headers/20/permission/child_process_permission.h +29 -0
- package/src/headers/20/permission/fs_permission.h +154 -0
- package/src/headers/20/permission/inspector_permission.h +29 -0
- package/src/headers/20/permission/permission.h +74 -0
- package/src/headers/20/permission/permission_base.h +53 -0
- package/src/headers/20/permission/worker_permission.h +29 -0
- package/src/headers/20/pipe_wrap.h +80 -0
- package/src/headers/20/req_wrap-inl.h +171 -0
- package/src/headers/20/req_wrap.h +77 -0
- package/src/headers/20/spawn_sync.h +242 -0
- package/src/headers/20/stream_base-inl.h +173 -0
- package/src/headers/20/stream_base.h +469 -0
- package/src/headers/20/stream_pipe.h +76 -0
- package/src/headers/20/stream_wrap.h +131 -0
- package/src/headers/20/string_bytes.h +120 -0
- package/src/headers/20/string_decoder-inl.h +37 -0
- package/src/headers/20/string_decoder.h +50 -0
- package/src/headers/20/string_search.h +638 -0
- package/src/headers/20/tcp_wrap.h +105 -0
- package/src/headers/20/threadpoolwork-inl.h +70 -0
- package/src/headers/20/timer_wrap-inl.h +32 -0
- package/src/headers/20/timer_wrap.h +85 -0
- package/src/headers/20/timers.h +70 -0
- package/src/headers/20/tracing/agent.h +195 -0
- package/src/headers/20/tracing/node_trace_buffer.h +83 -0
- package/src/headers/20/tracing/node_trace_writer.h +75 -0
- package/src/headers/20/tracing/trace_event.h +720 -0
- package/src/headers/20/tracing/trace_event_common.h +1109 -0
- package/src/headers/20/tracing/traced_value.h +70 -0
- package/src/headers/20/tty_wrap.h +65 -0
- package/src/headers/20/udp_wrap.h +227 -0
- package/src/headers/20/undici_version.h +6 -0
- package/src/headers/20/util-inl.h +623 -0
- package/src/headers/20/util.h +988 -0
- package/src/headers/20/v8-cppgc.h +245 -0
- package/src/headers/20/v8-fast-api-calls.h +957 -0
- package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
- package/dist/bindings/cws_darwin_x64_node64.node +0 -0
- package/dist/bindings/cws_darwin_x64_node72.node +0 -0
- package/dist/bindings/cws_darwin_x64_node79.node +0 -0
- package/dist/bindings/cws_linux_x64_node64.node +0 -0
- package/dist/bindings/cws_linux_x64_node72.node +0 -0
- package/dist/bindings/cws_linux_x64_node79.node +0 -0
- package/dist/bindings/cws_win32_x64_node64.node +0 -0
- package/dist/bindings/cws_win32_x64_node72.node +0 -0
- package/dist/bindings/cws_win32_x64_node79.node +0 -0
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
typedef struct napi_value__* napi_value;
|
|
26
|
+
typedef struct napi_ref__* napi_ref;
|
|
27
|
+
typedef struct napi_handle_scope__* napi_handle_scope;
|
|
28
|
+
typedef struct napi_escapable_handle_scope__* napi_escapable_handle_scope;
|
|
29
|
+
typedef struct napi_callback_info__* napi_callback_info;
|
|
30
|
+
typedef struct napi_deferred__* napi_deferred;
|
|
31
|
+
|
|
32
|
+
typedef enum {
|
|
33
|
+
napi_default = 0,
|
|
34
|
+
napi_writable = 1 << 0,
|
|
35
|
+
napi_enumerable = 1 << 1,
|
|
36
|
+
napi_configurable = 1 << 2,
|
|
37
|
+
|
|
38
|
+
// Used with napi_define_class to distinguish static properties
|
|
39
|
+
// from instance properties. Ignored by napi_define_properties.
|
|
40
|
+
napi_static = 1 << 10,
|
|
41
|
+
|
|
42
|
+
#if NAPI_VERSION >= 8
|
|
43
|
+
// Default for class methods.
|
|
44
|
+
napi_default_method = napi_writable | napi_configurable,
|
|
45
|
+
|
|
46
|
+
// Default for object properties, like in JS obj[prop].
|
|
47
|
+
napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable,
|
|
48
|
+
#endif // NAPI_VERSION >= 8
|
|
49
|
+
} napi_property_attributes;
|
|
50
|
+
|
|
51
|
+
typedef enum {
|
|
52
|
+
// ES6 types (corresponds to typeof)
|
|
53
|
+
napi_undefined,
|
|
54
|
+
napi_null,
|
|
55
|
+
napi_boolean,
|
|
56
|
+
napi_number,
|
|
57
|
+
napi_string,
|
|
58
|
+
napi_symbol,
|
|
59
|
+
napi_object,
|
|
60
|
+
napi_function,
|
|
61
|
+
napi_external,
|
|
62
|
+
napi_bigint,
|
|
63
|
+
} napi_valuetype;
|
|
64
|
+
|
|
65
|
+
typedef enum {
|
|
66
|
+
napi_int8_array,
|
|
67
|
+
napi_uint8_array,
|
|
68
|
+
napi_uint8_clamped_array,
|
|
69
|
+
napi_int16_array,
|
|
70
|
+
napi_uint16_array,
|
|
71
|
+
napi_int32_array,
|
|
72
|
+
napi_uint32_array,
|
|
73
|
+
napi_float32_array,
|
|
74
|
+
napi_float64_array,
|
|
75
|
+
napi_bigint64_array,
|
|
76
|
+
napi_biguint64_array,
|
|
77
|
+
} napi_typedarray_type;
|
|
78
|
+
|
|
79
|
+
typedef enum {
|
|
80
|
+
napi_ok,
|
|
81
|
+
napi_invalid_arg,
|
|
82
|
+
napi_object_expected,
|
|
83
|
+
napi_string_expected,
|
|
84
|
+
napi_name_expected,
|
|
85
|
+
napi_function_expected,
|
|
86
|
+
napi_number_expected,
|
|
87
|
+
napi_boolean_expected,
|
|
88
|
+
napi_array_expected,
|
|
89
|
+
napi_generic_failure,
|
|
90
|
+
napi_pending_exception,
|
|
91
|
+
napi_cancelled,
|
|
92
|
+
napi_escape_called_twice,
|
|
93
|
+
napi_handle_scope_mismatch,
|
|
94
|
+
napi_callback_scope_mismatch,
|
|
95
|
+
napi_queue_full,
|
|
96
|
+
napi_closing,
|
|
97
|
+
napi_bigint_expected,
|
|
98
|
+
napi_date_expected,
|
|
99
|
+
napi_arraybuffer_expected,
|
|
100
|
+
napi_detachable_arraybuffer_expected,
|
|
101
|
+
napi_would_deadlock, // unused
|
|
102
|
+
napi_no_external_buffers_allowed,
|
|
103
|
+
napi_cannot_run_js,
|
|
104
|
+
} napi_status;
|
|
105
|
+
// Note: when adding a new enum value to `napi_status`, please also update
|
|
106
|
+
// * `const int last_status` in the definition of `napi_get_last_error_info()'
|
|
107
|
+
// in file js_native_api_v8.cc.
|
|
108
|
+
// * `const char* error_messages[]` in file js_native_api_v8.cc with a brief
|
|
109
|
+
// message explaining the error.
|
|
110
|
+
// * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
|
|
111
|
+
// added value(s).
|
|
112
|
+
|
|
113
|
+
typedef napi_value(NAPI_CDECL* napi_callback)(napi_env env,
|
|
114
|
+
napi_callback_info info);
|
|
115
|
+
typedef void(NAPI_CDECL* napi_finalize)(napi_env env,
|
|
116
|
+
void* finalize_data,
|
|
117
|
+
void* finalize_hint);
|
|
118
|
+
|
|
119
|
+
typedef struct {
|
|
120
|
+
// One of utf8name or name should be NULL.
|
|
121
|
+
const char* utf8name;
|
|
122
|
+
napi_value name;
|
|
123
|
+
|
|
124
|
+
napi_callback method;
|
|
125
|
+
napi_callback getter;
|
|
126
|
+
napi_callback setter;
|
|
127
|
+
napi_value value;
|
|
128
|
+
|
|
129
|
+
napi_property_attributes attributes;
|
|
130
|
+
void* data;
|
|
131
|
+
} napi_property_descriptor;
|
|
132
|
+
|
|
133
|
+
typedef struct {
|
|
134
|
+
const char* error_message;
|
|
135
|
+
void* engine_reserved;
|
|
136
|
+
uint32_t engine_error_code;
|
|
137
|
+
napi_status error_code;
|
|
138
|
+
} napi_extended_error_info;
|
|
139
|
+
|
|
140
|
+
#if NAPI_VERSION >= 6
|
|
141
|
+
typedef enum {
|
|
142
|
+
napi_key_include_prototypes,
|
|
143
|
+
napi_key_own_only
|
|
144
|
+
} napi_key_collection_mode;
|
|
145
|
+
|
|
146
|
+
typedef enum {
|
|
147
|
+
napi_key_all_properties = 0,
|
|
148
|
+
napi_key_writable = 1,
|
|
149
|
+
napi_key_enumerable = 1 << 1,
|
|
150
|
+
napi_key_configurable = 1 << 2,
|
|
151
|
+
napi_key_skip_strings = 1 << 3,
|
|
152
|
+
napi_key_skip_symbols = 1 << 4
|
|
153
|
+
} napi_key_filter;
|
|
154
|
+
|
|
155
|
+
typedef enum {
|
|
156
|
+
napi_key_keep_numbers,
|
|
157
|
+
napi_key_numbers_to_strings
|
|
158
|
+
} napi_key_conversion;
|
|
159
|
+
#endif // NAPI_VERSION >= 6
|
|
160
|
+
|
|
161
|
+
#if NAPI_VERSION >= 8
|
|
162
|
+
typedef struct {
|
|
163
|
+
uint64_t lower;
|
|
164
|
+
uint64_t upper;
|
|
165
|
+
} napi_type_tag;
|
|
166
|
+
#endif // NAPI_VERSION >= 8
|
|
167
|
+
|
|
168
|
+
#endif // SRC_JS_NATIVE_API_TYPES_H_
|
|
@@ -0,0 +1,463 @@
|
|
|
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(napi_env env);
|
|
8
|
+
|
|
9
|
+
namespace v8impl {
|
|
10
|
+
|
|
11
|
+
class RefTracker {
|
|
12
|
+
public:
|
|
13
|
+
RefTracker() = default;
|
|
14
|
+
virtual ~RefTracker() = default;
|
|
15
|
+
virtual void Finalize() {}
|
|
16
|
+
|
|
17
|
+
typedef RefTracker RefList;
|
|
18
|
+
|
|
19
|
+
inline void Link(RefList* list) {
|
|
20
|
+
prev_ = list;
|
|
21
|
+
next_ = list->next_;
|
|
22
|
+
if (next_ != nullptr) {
|
|
23
|
+
next_->prev_ = this;
|
|
24
|
+
}
|
|
25
|
+
list->next_ = this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
inline void Unlink() {
|
|
29
|
+
if (prev_ != nullptr) {
|
|
30
|
+
prev_->next_ = next_;
|
|
31
|
+
}
|
|
32
|
+
if (next_ != nullptr) {
|
|
33
|
+
next_->prev_ = prev_;
|
|
34
|
+
}
|
|
35
|
+
prev_ = nullptr;
|
|
36
|
+
next_ = nullptr;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static void FinalizeAll(RefList* list) {
|
|
40
|
+
while (list->next_ != nullptr) {
|
|
41
|
+
list->next_->Finalize();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private:
|
|
46
|
+
RefList* next_ = nullptr;
|
|
47
|
+
RefList* prev_ = nullptr;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
class Finalizer;
|
|
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
|
+
// Call finalizer immediately.
|
|
103
|
+
virtual void CallFinalizer(napi_finalize cb, void* data, void* hint) {
|
|
104
|
+
v8::HandleScope handle_scope(isolate);
|
|
105
|
+
CallIntoModule([&](napi_env env) { cb(env, data, hint); });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Invoke finalizer from V8 garbage collector.
|
|
109
|
+
void InvokeFinalizerFromGC(v8impl::RefTracker* finalizer);
|
|
110
|
+
|
|
111
|
+
// Enqueue the finalizer to the napi_env's own queue of the second pass
|
|
112
|
+
// weak callback.
|
|
113
|
+
// Implementation should drain the queue at the time it is safe to call
|
|
114
|
+
// into JavaScript.
|
|
115
|
+
virtual void EnqueueFinalizer(v8impl::RefTracker* finalizer) {
|
|
116
|
+
pending_finalizers.emplace(finalizer);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Remove the finalizer from the scheduled second pass weak callback queue.
|
|
120
|
+
// The finalizer can be deleted after this call.
|
|
121
|
+
virtual void DequeueFinalizer(v8impl::RefTracker* finalizer) {
|
|
122
|
+
pending_finalizers.erase(finalizer);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
virtual void DeleteMe() {
|
|
126
|
+
// First we must finalize those references that have `napi_finalizer`
|
|
127
|
+
// callbacks. The reason is that addons might store other references which
|
|
128
|
+
// they delete during their `napi_finalizer` callbacks. If we deleted such
|
|
129
|
+
// references here first, they would be doubly deleted when the
|
|
130
|
+
// `napi_finalizer` deleted them subsequently.
|
|
131
|
+
v8impl::RefTracker::FinalizeAll(&finalizing_reflist);
|
|
132
|
+
v8impl::RefTracker::FinalizeAll(&reflist);
|
|
133
|
+
delete this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
void CheckGCAccess() {
|
|
137
|
+
if (module_api_version == NAPI_VERSION_EXPERIMENTAL && in_gc_finalizer) {
|
|
138
|
+
v8impl::OnFatalError(
|
|
139
|
+
nullptr,
|
|
140
|
+
"Finalizer is calling a function that may affect GC state.\n"
|
|
141
|
+
"The finalizers are run directly from GC and must not affect GC "
|
|
142
|
+
"state.\n"
|
|
143
|
+
"Use `node_api_post_finalizer` from inside of the finalizer to work "
|
|
144
|
+
"around this issue.\n"
|
|
145
|
+
"It schedules the call as a new task in the event loop.");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
v8::Isolate* const isolate; // Shortcut for context()->GetIsolate()
|
|
150
|
+
v8impl::Persistent<v8::Context> context_persistent;
|
|
151
|
+
|
|
152
|
+
v8impl::Persistent<v8::Value> last_exception;
|
|
153
|
+
|
|
154
|
+
// We store references in two different lists, depending on whether they have
|
|
155
|
+
// `napi_finalizer` callbacks, because we must first finalize the ones that
|
|
156
|
+
// have such a callback. See `~napi_env__()` above for details.
|
|
157
|
+
v8impl::RefTracker::RefList reflist;
|
|
158
|
+
v8impl::RefTracker::RefList finalizing_reflist;
|
|
159
|
+
// The invocation order of the finalizers is not determined.
|
|
160
|
+
std::unordered_set<v8impl::RefTracker*> pending_finalizers;
|
|
161
|
+
napi_extended_error_info last_error;
|
|
162
|
+
int open_handle_scopes = 0;
|
|
163
|
+
int open_callback_scopes = 0;
|
|
164
|
+
int refs = 1;
|
|
165
|
+
void* instance_data = nullptr;
|
|
166
|
+
int32_t module_api_version = NODE_API_DEFAULT_MODULE_API_VERSION;
|
|
167
|
+
bool in_gc_finalizer = false;
|
|
168
|
+
|
|
169
|
+
protected:
|
|
170
|
+
// Should not be deleted directly. Delete with `napi_env__::DeleteMe()`
|
|
171
|
+
// instead.
|
|
172
|
+
virtual ~napi_env__() = default;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
inline napi_status napi_clear_last_error(napi_env env) {
|
|
176
|
+
env->last_error.error_code = napi_ok;
|
|
177
|
+
env->last_error.engine_error_code = 0;
|
|
178
|
+
env->last_error.engine_reserved = nullptr;
|
|
179
|
+
env->last_error.error_message = nullptr;
|
|
180
|
+
return napi_ok;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
inline napi_status napi_set_last_error(napi_env env,
|
|
184
|
+
napi_status error_code,
|
|
185
|
+
uint32_t engine_error_code = 0,
|
|
186
|
+
void* engine_reserved = nullptr) {
|
|
187
|
+
env->last_error.error_code = error_code;
|
|
188
|
+
env->last_error.engine_error_code = engine_error_code;
|
|
189
|
+
env->last_error.engine_reserved = engine_reserved;
|
|
190
|
+
return error_code;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
#define RETURN_STATUS_IF_FALSE(env, condition, status) \
|
|
194
|
+
do { \
|
|
195
|
+
if (!(condition)) { \
|
|
196
|
+
return napi_set_last_error((env), (status)); \
|
|
197
|
+
} \
|
|
198
|
+
} while (0)
|
|
199
|
+
|
|
200
|
+
#define RETURN_STATUS_IF_FALSE_WITH_PREAMBLE(env, condition, status) \
|
|
201
|
+
do { \
|
|
202
|
+
if (!(condition)) { \
|
|
203
|
+
return napi_set_last_error( \
|
|
204
|
+
(env), try_catch.HasCaught() ? napi_pending_exception : (status)); \
|
|
205
|
+
} \
|
|
206
|
+
} while (0)
|
|
207
|
+
|
|
208
|
+
#define CHECK_ENV(env) \
|
|
209
|
+
do { \
|
|
210
|
+
if ((env) == nullptr) { \
|
|
211
|
+
return napi_invalid_arg; \
|
|
212
|
+
} \
|
|
213
|
+
} while (0)
|
|
214
|
+
|
|
215
|
+
#define CHECK_ARG(env, arg) \
|
|
216
|
+
RETURN_STATUS_IF_FALSE((env), ((arg) != nullptr), napi_invalid_arg)
|
|
217
|
+
|
|
218
|
+
#define CHECK_ARG_WITH_PREAMBLE(env, arg) \
|
|
219
|
+
RETURN_STATUS_IF_FALSE_WITH_PREAMBLE( \
|
|
220
|
+
(env), ((arg) != nullptr), napi_invalid_arg)
|
|
221
|
+
|
|
222
|
+
#define CHECK_MAYBE_EMPTY(env, maybe, status) \
|
|
223
|
+
RETURN_STATUS_IF_FALSE((env), !((maybe).IsEmpty()), (status))
|
|
224
|
+
|
|
225
|
+
#define CHECK_MAYBE_EMPTY_WITH_PREAMBLE(env, maybe, status) \
|
|
226
|
+
RETURN_STATUS_IF_FALSE_WITH_PREAMBLE((env), !((maybe).IsEmpty()), (status))
|
|
227
|
+
|
|
228
|
+
// NAPI_PREAMBLE is not wrapped in do..while: try_catch must have function scope
|
|
229
|
+
#define NAPI_PREAMBLE(env) \
|
|
230
|
+
CHECK_ENV((env)); \
|
|
231
|
+
(env)->CheckGCAccess(); \
|
|
232
|
+
RETURN_STATUS_IF_FALSE( \
|
|
233
|
+
(env), (env)->last_exception.IsEmpty(), napi_pending_exception); \
|
|
234
|
+
RETURN_STATUS_IF_FALSE((env), \
|
|
235
|
+
(env)->can_call_into_js(), \
|
|
236
|
+
(env->module_api_version == NAPI_VERSION_EXPERIMENTAL \
|
|
237
|
+
? napi_cannot_run_js \
|
|
238
|
+
: napi_pending_exception)); \
|
|
239
|
+
napi_clear_last_error((env)); \
|
|
240
|
+
v8impl::TryCatch try_catch((env))
|
|
241
|
+
|
|
242
|
+
#define CHECK_TO_TYPE(env, type, context, result, src, status) \
|
|
243
|
+
do { \
|
|
244
|
+
CHECK_ARG((env), (src)); \
|
|
245
|
+
auto maybe = v8impl::V8LocalValueFromJsValue((src))->To##type((context)); \
|
|
246
|
+
CHECK_MAYBE_EMPTY((env), maybe, (status)); \
|
|
247
|
+
(result) = maybe.ToLocalChecked(); \
|
|
248
|
+
} while (0)
|
|
249
|
+
|
|
250
|
+
#define CHECK_TO_TYPE_WITH_PREAMBLE(env, type, context, result, src, status) \
|
|
251
|
+
do { \
|
|
252
|
+
CHECK_ARG_WITH_PREAMBLE((env), (src)); \
|
|
253
|
+
auto maybe = v8impl::V8LocalValueFromJsValue((src))->To##type((context)); \
|
|
254
|
+
CHECK_MAYBE_EMPTY_WITH_PREAMBLE((env), maybe, (status)); \
|
|
255
|
+
(result) = maybe.ToLocalChecked(); \
|
|
256
|
+
} while (0)
|
|
257
|
+
|
|
258
|
+
#define CHECK_TO_FUNCTION(env, result, src) \
|
|
259
|
+
do { \
|
|
260
|
+
CHECK_ARG((env), (src)); \
|
|
261
|
+
v8::Local<v8::Value> v8value = v8impl::V8LocalValueFromJsValue((src)); \
|
|
262
|
+
RETURN_STATUS_IF_FALSE((env), v8value->IsFunction(), napi_invalid_arg); \
|
|
263
|
+
(result) = v8value.As<v8::Function>(); \
|
|
264
|
+
} while (0)
|
|
265
|
+
|
|
266
|
+
#define CHECK_TO_OBJECT(env, context, result, src) \
|
|
267
|
+
CHECK_TO_TYPE((env), Object, (context), (result), (src), napi_object_expected)
|
|
268
|
+
|
|
269
|
+
#define CHECK_TO_OBJECT_WITH_PREAMBLE(env, context, result, src) \
|
|
270
|
+
CHECK_TO_TYPE_WITH_PREAMBLE( \
|
|
271
|
+
(env), Object, (context), (result), (src), napi_object_expected)
|
|
272
|
+
|
|
273
|
+
#define CHECK_TO_STRING(env, context, result, src) \
|
|
274
|
+
CHECK_TO_TYPE((env), String, (context), (result), (src), napi_string_expected)
|
|
275
|
+
|
|
276
|
+
#define GET_RETURN_STATUS(env) \
|
|
277
|
+
(!try_catch.HasCaught() \
|
|
278
|
+
? napi_ok \
|
|
279
|
+
: napi_set_last_error((env), napi_pending_exception))
|
|
280
|
+
|
|
281
|
+
#define THROW_RANGE_ERROR_IF_FALSE(env, condition, error, message) \
|
|
282
|
+
do { \
|
|
283
|
+
if (!(condition)) { \
|
|
284
|
+
napi_throw_range_error((env), (error), (message)); \
|
|
285
|
+
return napi_set_last_error((env), napi_generic_failure); \
|
|
286
|
+
} \
|
|
287
|
+
} while (0)
|
|
288
|
+
|
|
289
|
+
#define CHECK_MAYBE_EMPTY_WITH_PREAMBLE(env, maybe, status) \
|
|
290
|
+
RETURN_STATUS_IF_FALSE_WITH_PREAMBLE((env), !((maybe).IsEmpty()), (status))
|
|
291
|
+
|
|
292
|
+
#define STATUS_CALL(call) \
|
|
293
|
+
do { \
|
|
294
|
+
napi_status status = (call); \
|
|
295
|
+
if (status != napi_ok) return status; \
|
|
296
|
+
} while (0)
|
|
297
|
+
|
|
298
|
+
namespace v8impl {
|
|
299
|
+
|
|
300
|
+
//=== Conversion between V8 Handles and napi_value ========================
|
|
301
|
+
|
|
302
|
+
// This asserts v8::Local<> will always be implemented with a single
|
|
303
|
+
// pointer field so that we can pass it around as a void*.
|
|
304
|
+
static_assert(sizeof(v8::Local<v8::Value>) == sizeof(napi_value),
|
|
305
|
+
"Cannot convert between v8::Local<v8::Value> and napi_value");
|
|
306
|
+
|
|
307
|
+
inline napi_value JsValueFromV8LocalValue(v8::Local<v8::Value> local) {
|
|
308
|
+
return reinterpret_cast<napi_value>(*local);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
inline v8::Local<v8::Value> V8LocalValueFromJsValue(napi_value v) {
|
|
312
|
+
v8::Local<v8::Value> local;
|
|
313
|
+
memcpy(static_cast<void*>(&local), &v, sizeof(v));
|
|
314
|
+
return local;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Adapter for napi_finalize callbacks.
|
|
318
|
+
class Finalizer {
|
|
319
|
+
protected:
|
|
320
|
+
Finalizer(napi_env env,
|
|
321
|
+
napi_finalize finalize_callback,
|
|
322
|
+
void* finalize_data,
|
|
323
|
+
void* finalize_hint)
|
|
324
|
+
: env_(env),
|
|
325
|
+
finalize_callback_(finalize_callback),
|
|
326
|
+
finalize_data_(finalize_data),
|
|
327
|
+
finalize_hint_(finalize_hint) {}
|
|
328
|
+
|
|
329
|
+
virtual ~Finalizer() = default;
|
|
330
|
+
|
|
331
|
+
public:
|
|
332
|
+
static Finalizer* New(napi_env env,
|
|
333
|
+
napi_finalize finalize_callback = nullptr,
|
|
334
|
+
void* finalize_data = nullptr,
|
|
335
|
+
void* finalize_hint = nullptr) {
|
|
336
|
+
return new Finalizer(env, finalize_callback, finalize_data, finalize_hint);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
napi_finalize callback() { return finalize_callback_; }
|
|
340
|
+
void* data() { return finalize_data_; }
|
|
341
|
+
void* hint() { return finalize_hint_; }
|
|
342
|
+
|
|
343
|
+
void ResetFinalizer();
|
|
344
|
+
|
|
345
|
+
protected:
|
|
346
|
+
napi_env env_;
|
|
347
|
+
napi_finalize finalize_callback_;
|
|
348
|
+
void* finalize_data_;
|
|
349
|
+
void* finalize_hint_;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
class TryCatch : public v8::TryCatch {
|
|
353
|
+
public:
|
|
354
|
+
explicit TryCatch(napi_env env) : v8::TryCatch(env->isolate), _env(env) {}
|
|
355
|
+
|
|
356
|
+
~TryCatch() {
|
|
357
|
+
if (HasCaught()) {
|
|
358
|
+
_env->last_exception.Reset(_env->isolate, Exception());
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
private:
|
|
363
|
+
napi_env _env;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// Ownership of a reference.
|
|
367
|
+
enum class Ownership {
|
|
368
|
+
// The reference is owned by the runtime. No userland call is needed to
|
|
369
|
+
// destruct the reference.
|
|
370
|
+
kRuntime,
|
|
371
|
+
// The reference is owned by the userland. User code is responsible to delete
|
|
372
|
+
// the reference with appropriate node-api calls.
|
|
373
|
+
kUserland,
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// Wrapper around Finalizer that can be tracked.
|
|
377
|
+
class TrackedFinalizer : public Finalizer, public RefTracker {
|
|
378
|
+
protected:
|
|
379
|
+
TrackedFinalizer(napi_env env,
|
|
380
|
+
napi_finalize finalize_callback,
|
|
381
|
+
void* finalize_data,
|
|
382
|
+
void* finalize_hint);
|
|
383
|
+
|
|
384
|
+
public:
|
|
385
|
+
static TrackedFinalizer* New(napi_env env,
|
|
386
|
+
napi_finalize finalize_callback,
|
|
387
|
+
void* finalize_data,
|
|
388
|
+
void* finalize_hint);
|
|
389
|
+
~TrackedFinalizer() override;
|
|
390
|
+
|
|
391
|
+
protected:
|
|
392
|
+
void Finalize() override;
|
|
393
|
+
void FinalizeCore(bool deleteMe);
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// Wrapper around TrackedFinalizer that implements reference counting.
|
|
397
|
+
class RefBase : public TrackedFinalizer {
|
|
398
|
+
protected:
|
|
399
|
+
RefBase(napi_env env,
|
|
400
|
+
uint32_t initial_refcount,
|
|
401
|
+
Ownership ownership,
|
|
402
|
+
napi_finalize finalize_callback,
|
|
403
|
+
void* finalize_data,
|
|
404
|
+
void* finalize_hint);
|
|
405
|
+
|
|
406
|
+
public:
|
|
407
|
+
static RefBase* New(napi_env env,
|
|
408
|
+
uint32_t initial_refcount,
|
|
409
|
+
Ownership ownership,
|
|
410
|
+
napi_finalize finalize_callback,
|
|
411
|
+
void* finalize_data,
|
|
412
|
+
void* finalize_hint);
|
|
413
|
+
|
|
414
|
+
void* Data();
|
|
415
|
+
uint32_t Ref();
|
|
416
|
+
uint32_t Unref();
|
|
417
|
+
uint32_t RefCount();
|
|
418
|
+
|
|
419
|
+
Ownership ownership() { return ownership_; }
|
|
420
|
+
|
|
421
|
+
protected:
|
|
422
|
+
void Finalize() override;
|
|
423
|
+
|
|
424
|
+
private:
|
|
425
|
+
uint32_t refcount_;
|
|
426
|
+
Ownership ownership_;
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// Wrapper around v8impl::Persistent.
|
|
430
|
+
class Reference : public RefBase {
|
|
431
|
+
protected:
|
|
432
|
+
template <typename... Args>
|
|
433
|
+
Reference(napi_env env, v8::Local<v8::Value> value, Args&&... args);
|
|
434
|
+
|
|
435
|
+
public:
|
|
436
|
+
static Reference* New(napi_env env,
|
|
437
|
+
v8::Local<v8::Value> value,
|
|
438
|
+
uint32_t initial_refcount,
|
|
439
|
+
Ownership ownership,
|
|
440
|
+
napi_finalize finalize_callback = nullptr,
|
|
441
|
+
void* finalize_data = nullptr,
|
|
442
|
+
void* finalize_hint = nullptr);
|
|
443
|
+
|
|
444
|
+
virtual ~Reference();
|
|
445
|
+
uint32_t Ref();
|
|
446
|
+
uint32_t Unref();
|
|
447
|
+
v8::Local<v8::Value> Get();
|
|
448
|
+
|
|
449
|
+
protected:
|
|
450
|
+
void Finalize() override;
|
|
451
|
+
|
|
452
|
+
private:
|
|
453
|
+
static void WeakCallback(const v8::WeakCallbackInfo<Reference>& data);
|
|
454
|
+
|
|
455
|
+
void SetWeak();
|
|
456
|
+
|
|
457
|
+
v8impl::Persistent<v8::Value> persistent_;
|
|
458
|
+
bool can_be_weak_;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
} // end of namespace v8impl
|
|
462
|
+
|
|
463
|
+
#endif // SRC_JS_NATIVE_API_V8_H_
|
|
@@ -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_
|