@emnapi/runtime 0.40.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/emnapi.cjs.js +58 -31
- package/dist/emnapi.cjs.min.d.ts +606 -0
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.mts +606 -0
- package/dist/emnapi.d.ts +15 -13
- package/dist/emnapi.esm-bundler.js +58 -32
- package/dist/emnapi.iife.d.ts +13 -12
- package/dist/emnapi.iife.js +65 -34
- package/dist/emnapi.js +65 -34
- package/dist/emnapi.min.d.mts +606 -0
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +57 -30
- package/package.json +11 -7
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
export declare type Ptr = number | bigint
|
|
2
|
+
|
|
3
|
+
export declare interface IBuffer extends Uint8Array {}
|
|
4
|
+
export declare interface BufferCtor {
|
|
5
|
+
readonly prototype: IBuffer
|
|
6
|
+
/** @deprecated */
|
|
7
|
+
new (...args: any[]): IBuffer
|
|
8
|
+
from: {
|
|
9
|
+
(buffer: ArrayBufferLike): IBuffer
|
|
10
|
+
(buffer: ArrayBufferLike, byteOffset: number, length: number): IBuffer
|
|
11
|
+
}
|
|
12
|
+
alloc: (size: number) => IBuffer
|
|
13
|
+
isBuffer: (obj: unknown) => obj is IBuffer
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare const enum GlobalHandle {
|
|
17
|
+
UNDEFINED = 1,
|
|
18
|
+
NULL,
|
|
19
|
+
FALSE,
|
|
20
|
+
TRUE,
|
|
21
|
+
GLOBAL
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare const enum Ownership {
|
|
25
|
+
kRuntime,
|
|
26
|
+
kUserland
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export declare const enum Version {
|
|
30
|
+
NODE_API_SUPPORTED_VERSION_MIN = 1,
|
|
31
|
+
NODE_API_DEFAULT_MODULE_API_VERSION = 8,
|
|
32
|
+
NODE_API_SUPPORTED_VERSION_MAX = 9,
|
|
33
|
+
NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
|
|
34
|
+
}
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
|
+
export declare type Pointer<T> = number
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
38
|
+
export declare type PointerPointer<T> = number
|
|
39
|
+
export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T>
|
|
40
|
+
export declare type Const<T> = T
|
|
41
|
+
|
|
42
|
+
export declare type void_p = Pointer<void>
|
|
43
|
+
export declare type void_pp = Pointer<void_p>
|
|
44
|
+
export declare type bool = number
|
|
45
|
+
export declare type char = number
|
|
46
|
+
export declare type char_p = Pointer<char>
|
|
47
|
+
export declare type unsigned_char = number
|
|
48
|
+
export declare type const_char = Const<char>
|
|
49
|
+
export declare type const_char_p = Pointer<const_char>
|
|
50
|
+
export declare type char16_t_p = number
|
|
51
|
+
export declare type const_char16_t_p = number
|
|
52
|
+
|
|
53
|
+
export declare type short = number
|
|
54
|
+
export declare type unsigned_short = number
|
|
55
|
+
export declare type int = number
|
|
56
|
+
export declare type unsigned_int = number
|
|
57
|
+
export declare type long = number
|
|
58
|
+
export declare type unsigned_long = number
|
|
59
|
+
export declare type long_long = bigint
|
|
60
|
+
export declare type unsigned_long_long = bigint
|
|
61
|
+
export declare type float = number
|
|
62
|
+
export declare type double = number
|
|
63
|
+
export declare type long_double = number
|
|
64
|
+
export declare type size_t = number
|
|
65
|
+
|
|
66
|
+
export declare type int8_t = number
|
|
67
|
+
export declare type uint8_t = number
|
|
68
|
+
export declare type int16_t = number
|
|
69
|
+
export declare type uint16_t = number
|
|
70
|
+
export declare type int32_t = number
|
|
71
|
+
export declare type uint32_t = number
|
|
72
|
+
export declare type int64_t = bigint
|
|
73
|
+
export declare type uint64_t = bigint
|
|
74
|
+
export declare type napi_env = Pointer<unknown>
|
|
75
|
+
|
|
76
|
+
export declare type napi_value = Pointer<unknown>
|
|
77
|
+
export declare type napi_ref = Pointer<unknown>
|
|
78
|
+
export declare type napi_deferred = Pointer<unknown>
|
|
79
|
+
export declare type napi_handle_scope = Pointer<unknown>
|
|
80
|
+
export declare type napi_escapable_handle_scope = Pointer<unknown>
|
|
81
|
+
|
|
82
|
+
export declare type napi_addon_register_func = FunctionPointer<(env: napi_env, exports: napi_value) => napi_value>
|
|
83
|
+
|
|
84
|
+
export declare type napi_callback_info = Pointer<unknown>
|
|
85
|
+
export declare type napi_callback = FunctionPointer<(env: napi_env, info: napi_callback_info) => napi_value>
|
|
86
|
+
|
|
87
|
+
export declare interface napi_extended_error_info {
|
|
88
|
+
error_message: const_char_p
|
|
89
|
+
engine_reserved: void_p
|
|
90
|
+
engine_error_code: uint32_t
|
|
91
|
+
error_code: napi_status
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export declare interface napi_property_descriptor {
|
|
95
|
+
// One of utf8name or name should be NULL.
|
|
96
|
+
utf8name: const_char_p
|
|
97
|
+
name: napi_value
|
|
98
|
+
|
|
99
|
+
method: napi_callback
|
|
100
|
+
getter: napi_callback
|
|
101
|
+
setter: napi_callback
|
|
102
|
+
value: napi_value
|
|
103
|
+
/* napi_property_attributes */
|
|
104
|
+
attributes: number
|
|
105
|
+
data: void_p
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export declare type napi_finalize = FunctionPointer<(
|
|
109
|
+
env: napi_env,
|
|
110
|
+
finalize_data: void_p,
|
|
111
|
+
finalize_hint: void_p
|
|
112
|
+
) => void>
|
|
113
|
+
|
|
114
|
+
export declare interface node_module {
|
|
115
|
+
nm_version: int32_t
|
|
116
|
+
nm_flags: uint32_t
|
|
117
|
+
nm_filename: Pointer<const_char>
|
|
118
|
+
nm_register_func: napi_addon_register_func
|
|
119
|
+
nm_modname: Pointer<const_char>
|
|
120
|
+
nm_priv: Pointer<void>
|
|
121
|
+
reserved: PointerPointer<void>
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export declare interface napi_node_version {
|
|
125
|
+
major: uint32_t
|
|
126
|
+
minor: uint32_t
|
|
127
|
+
patch: uint32_t
|
|
128
|
+
release: const_char_p
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export declare interface emnapi_emscripten_version {
|
|
132
|
+
major: uint32_t
|
|
133
|
+
minor: uint32_t
|
|
134
|
+
patch: uint32_t
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export declare const enum napi_status {
|
|
138
|
+
napi_ok,
|
|
139
|
+
napi_invalid_arg,
|
|
140
|
+
napi_object_expected,
|
|
141
|
+
napi_string_expected,
|
|
142
|
+
napi_name_expected,
|
|
143
|
+
napi_function_expected,
|
|
144
|
+
napi_number_expected,
|
|
145
|
+
napi_boolean_expected,
|
|
146
|
+
napi_array_expected,
|
|
147
|
+
napi_generic_failure,
|
|
148
|
+
napi_pending_exception,
|
|
149
|
+
napi_cancelled,
|
|
150
|
+
napi_escape_called_twice,
|
|
151
|
+
napi_handle_scope_mismatch,
|
|
152
|
+
napi_callback_scope_mismatch,
|
|
153
|
+
napi_queue_full,
|
|
154
|
+
napi_closing,
|
|
155
|
+
napi_bigint_expected,
|
|
156
|
+
napi_date_expected,
|
|
157
|
+
napi_arraybuffer_expected,
|
|
158
|
+
napi_detachable_arraybuffer_expected,
|
|
159
|
+
napi_would_deadlock, // unused
|
|
160
|
+
napi_no_external_buffers_allowed,
|
|
161
|
+
napi_cannot_run_js
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export declare const enum napi_property_attributes {
|
|
165
|
+
napi_default = 0,
|
|
166
|
+
napi_writable = 1 << 0,
|
|
167
|
+
napi_enumerable = 1 << 1,
|
|
168
|
+
napi_configurable = 1 << 2,
|
|
169
|
+
|
|
170
|
+
// Used with napi_define_class to distinguish static properties
|
|
171
|
+
// from instance properties. Ignored by napi_define_properties.
|
|
172
|
+
napi_static = 1 << 10,
|
|
173
|
+
|
|
174
|
+
/// #ifdef NAPI_EXPERIMENTAL
|
|
175
|
+
// Default for class methods.
|
|
176
|
+
napi_default_method = napi_writable | napi_configurable,
|
|
177
|
+
|
|
178
|
+
// Default for object properties, like in JS obj[prop].
|
|
179
|
+
napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable
|
|
180
|
+
/// #endif // NAPI_EXPERIMENTAL
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export declare const enum napi_valuetype {
|
|
184
|
+
napi_undefined,
|
|
185
|
+
napi_null,
|
|
186
|
+
napi_boolean,
|
|
187
|
+
napi_number,
|
|
188
|
+
napi_string,
|
|
189
|
+
napi_symbol,
|
|
190
|
+
napi_object,
|
|
191
|
+
napi_function,
|
|
192
|
+
napi_external,
|
|
193
|
+
napi_bigint
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export declare const enum napi_typedarray_type {
|
|
197
|
+
napi_int8_array,
|
|
198
|
+
napi_uint8_array,
|
|
199
|
+
napi_uint8_clamped_array,
|
|
200
|
+
napi_int16_array,
|
|
201
|
+
napi_uint16_array,
|
|
202
|
+
napi_int32_array,
|
|
203
|
+
napi_uint32_array,
|
|
204
|
+
napi_float32_array,
|
|
205
|
+
napi_float64_array,
|
|
206
|
+
napi_bigint64_array,
|
|
207
|
+
napi_biguint64_array
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export declare const enum napi_key_collection_mode {
|
|
211
|
+
napi_key_include_prototypes,
|
|
212
|
+
napi_key_own_only
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export declare const enum napi_key_filter {
|
|
216
|
+
napi_key_all_properties = 0,
|
|
217
|
+
napi_key_writable = 1,
|
|
218
|
+
napi_key_enumerable = 1 << 1,
|
|
219
|
+
napi_key_configurable = 1 << 2,
|
|
220
|
+
napi_key_skip_strings = 1 << 3,
|
|
221
|
+
napi_key_skip_symbols = 1 << 4
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export declare const enum napi_key_conversion {
|
|
225
|
+
napi_key_keep_numbers,
|
|
226
|
+
napi_key_numbers_to_strings
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export declare const enum emnapi_memory_view_type {
|
|
230
|
+
emnapi_int8_array,
|
|
231
|
+
emnapi_uint8_array,
|
|
232
|
+
emnapi_uint8_clamped_array,
|
|
233
|
+
emnapi_int16_array,
|
|
234
|
+
emnapi_uint16_array,
|
|
235
|
+
emnapi_int32_array,
|
|
236
|
+
emnapi_uint32_array,
|
|
237
|
+
emnapi_float32_array,
|
|
238
|
+
emnapi_float64_array,
|
|
239
|
+
emnapi_bigint64_array,
|
|
240
|
+
emnapi_biguint64_array,
|
|
241
|
+
emnapi_data_view = -1,
|
|
242
|
+
emnapi_buffer = -2
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export declare const enum napi_threadsafe_function_call_mode {
|
|
246
|
+
napi_tsfn_nonblocking,
|
|
247
|
+
napi_tsfn_blocking
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export declare const enum napi_threadsafe_function_release_mode {
|
|
251
|
+
napi_tsfn_release,
|
|
252
|
+
napi_tsfn_abort
|
|
253
|
+
}
|
|
254
|
+
export declare class CallbackInfo {
|
|
255
|
+
id: number;
|
|
256
|
+
parent: CallbackInfo;
|
|
257
|
+
child: CallbackInfo | null;
|
|
258
|
+
thiz: any;
|
|
259
|
+
data: void_p;
|
|
260
|
+
args: ArrayLike<any>;
|
|
261
|
+
fn: Function;
|
|
262
|
+
constructor(id: number, parent: CallbackInfo, child: CallbackInfo | null, thiz: any, data: void_p, args: ArrayLike<any>, fn: Function);
|
|
263
|
+
getNewTarget(envObject: Env): number;
|
|
264
|
+
dispose(): void;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export declare class CallbackInfoStack {
|
|
268
|
+
current: CallbackInfo;
|
|
269
|
+
get(id: number): CallbackInfo | null;
|
|
270
|
+
pop(): void;
|
|
271
|
+
push(thiz: any, data: void_p, args: ArrayLike<any>, fn: Function): number;
|
|
272
|
+
dispose(): void;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export declare type CleanupHookCallbackFunction = number | ((arg: number) => void);
|
|
276
|
+
|
|
277
|
+
export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> {
|
|
278
|
+
constructor(id: number, value: S);
|
|
279
|
+
dispose(): void;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export declare class Context {
|
|
283
|
+
private _isStopping;
|
|
284
|
+
private _canCallIntoJs;
|
|
285
|
+
envStore: Store<Env>;
|
|
286
|
+
scopeStore: ScopeStore;
|
|
287
|
+
refStore: Store<Reference>;
|
|
288
|
+
deferredStore: Store<Deferred<any>>;
|
|
289
|
+
handleStore: HandleStore;
|
|
290
|
+
cbinfoStack: CallbackInfoStack;
|
|
291
|
+
private readonly refCounter?;
|
|
292
|
+
private readonly cleanupQueue;
|
|
293
|
+
feature: {
|
|
294
|
+
supportReflect: boolean;
|
|
295
|
+
supportFinalizer: boolean;
|
|
296
|
+
supportWeakSymbol: boolean;
|
|
297
|
+
supportBigInt: boolean;
|
|
298
|
+
supportNewFunction: boolean;
|
|
299
|
+
canSetFunctionName: boolean;
|
|
300
|
+
setImmediate: (callback: () => void) => void;
|
|
301
|
+
Buffer: BufferCtor | undefined;
|
|
302
|
+
MessageChannel: {
|
|
303
|
+
new (): MessageChannel;
|
|
304
|
+
prototype: MessageChannel;
|
|
305
|
+
} | undefined;
|
|
306
|
+
};
|
|
307
|
+
constructor();
|
|
308
|
+
getRuntimeVersions(): {
|
|
309
|
+
version: string;
|
|
310
|
+
NODE_API_SUPPORTED_VERSION_MAX: Version;
|
|
311
|
+
NAPI_VERSION_EXPERIMENTAL: Version;
|
|
312
|
+
NODE_API_DEFAULT_MODULE_API_VERSION: Version;
|
|
313
|
+
};
|
|
314
|
+
createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
|
|
315
|
+
createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
|
|
316
|
+
createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
|
|
317
|
+
createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
|
|
318
|
+
createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
|
|
319
|
+
getCurrentScope(): HandleScope | null;
|
|
320
|
+
addToCurrentScope<V>(value: V): Handle<V>;
|
|
321
|
+
openScope(envObject: Env): HandleScope;
|
|
322
|
+
closeScope(envObject: Env, _scope?: HandleScope): void;
|
|
323
|
+
ensureHandle<S>(value: S): Handle<S>;
|
|
324
|
+
addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
|
|
325
|
+
removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
|
|
326
|
+
runCleanup(): void;
|
|
327
|
+
increaseWaitingRequestCounter(): void;
|
|
328
|
+
decreaseWaitingRequestCounter(): void;
|
|
329
|
+
setCanCallIntoJs(value: boolean): void;
|
|
330
|
+
setStopping(value: boolean): void;
|
|
331
|
+
canCallIntoJs(): boolean;
|
|
332
|
+
destroy(): void;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export declare function createContext(): Context;
|
|
336
|
+
|
|
337
|
+
export declare class Deferred<T = any> implements IStoreValue {
|
|
338
|
+
static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
|
|
339
|
+
id: number;
|
|
340
|
+
ctx: Context;
|
|
341
|
+
value: IDeferrdValue<T>;
|
|
342
|
+
constructor(ctx: Context, value: IDeferrdValue<T>);
|
|
343
|
+
resolve(value: T): void;
|
|
344
|
+
reject(reason?: any): void;
|
|
345
|
+
dispose(): void;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export declare class EmnapiError extends Error {
|
|
349
|
+
constructor(message?: string);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export declare class Env implements IStoreValue {
|
|
353
|
+
readonly ctx: Context;
|
|
354
|
+
moduleApiVersion: number;
|
|
355
|
+
makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
|
|
356
|
+
makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
|
|
357
|
+
abort: (msg?: string) => never;
|
|
358
|
+
id: number;
|
|
359
|
+
openHandleScopes: number;
|
|
360
|
+
instanceData: RefBase | null;
|
|
361
|
+
tryCatch: TryCatch;
|
|
362
|
+
refs: number;
|
|
363
|
+
reflist: RefTracker;
|
|
364
|
+
finalizing_reflist: RefTracker;
|
|
365
|
+
pendingFinalizers: RefTracker[];
|
|
366
|
+
lastError: {
|
|
367
|
+
errorCode: napi_status;
|
|
368
|
+
engineErrorCode: number;
|
|
369
|
+
engineReserved: Ptr;
|
|
370
|
+
};
|
|
371
|
+
constructor(ctx: Context, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never);
|
|
372
|
+
canCallIntoJs(): boolean;
|
|
373
|
+
terminatedOrTerminating(): boolean;
|
|
374
|
+
ref(): void;
|
|
375
|
+
unref(): void;
|
|
376
|
+
ensureHandle<S>(value: S): Handle<S>;
|
|
377
|
+
ensureHandleId(value: any): napi_value;
|
|
378
|
+
clearLastError(): napi_status;
|
|
379
|
+
setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
|
|
380
|
+
getReturnStatus(): napi_status;
|
|
381
|
+
callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
|
|
382
|
+
callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
|
|
383
|
+
enqueueFinalizer(finalizer: RefTracker): void;
|
|
384
|
+
dequeueFinalizer(finalizer: RefTracker): void;
|
|
385
|
+
deleteMe(): void;
|
|
386
|
+
dispose(): void;
|
|
387
|
+
private readonly _bindingMap;
|
|
388
|
+
initObjectBinding<S extends object>(value: S): IReferenceBinding;
|
|
389
|
+
getObjectBinding<S extends object>(value: S): IReferenceBinding;
|
|
390
|
+
setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void;
|
|
391
|
+
getInstanceData(): number;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export declare class Finalizer {
|
|
395
|
+
envObject: Env;
|
|
396
|
+
protected _finalizeCallback: napi_finalize;
|
|
397
|
+
protected _finalizeData: void_p;
|
|
398
|
+
protected _finalizeHint: void_p;
|
|
399
|
+
constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
|
|
400
|
+
callback(): napi_finalize;
|
|
401
|
+
data(): void_p;
|
|
402
|
+
hint(): void_p;
|
|
403
|
+
resetFinalizer(): void;
|
|
404
|
+
dispose(): void;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export declare function getDefaultContext(): Context;
|
|
408
|
+
|
|
409
|
+
export declare class Handle<S> {
|
|
410
|
+
id: number;
|
|
411
|
+
value: S;
|
|
412
|
+
constructor(id: number, value: S);
|
|
413
|
+
data(envObject: Env): void_p;
|
|
414
|
+
isNumber(): boolean;
|
|
415
|
+
isBigInt(): boolean;
|
|
416
|
+
isString(): boolean;
|
|
417
|
+
isFunction(): boolean;
|
|
418
|
+
isExternal(): boolean;
|
|
419
|
+
isObject(): boolean;
|
|
420
|
+
isArray(): boolean;
|
|
421
|
+
isArrayBuffer(): boolean;
|
|
422
|
+
isTypedArray(): boolean;
|
|
423
|
+
isBuffer(): boolean;
|
|
424
|
+
isDataView(): boolean;
|
|
425
|
+
isDate(): boolean;
|
|
426
|
+
isPromise(): boolean;
|
|
427
|
+
isBoolean(): boolean;
|
|
428
|
+
isUndefined(): boolean;
|
|
429
|
+
isSymbol(): boolean;
|
|
430
|
+
isNull(): boolean;
|
|
431
|
+
dispose(): void;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export declare class HandleScope {
|
|
435
|
+
handleStore: HandleStore;
|
|
436
|
+
id: number;
|
|
437
|
+
parent: HandleScope | null;
|
|
438
|
+
child: HandleScope | null;
|
|
439
|
+
start: number;
|
|
440
|
+
end: number;
|
|
441
|
+
_escapeCalled: boolean;
|
|
442
|
+
constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number);
|
|
443
|
+
add<V>(value: V): Handle<V>;
|
|
444
|
+
addExternal(envObject: Env, data: void_p): Handle<object>;
|
|
445
|
+
dispose(): void;
|
|
446
|
+
escape(handle: number): Handle<any> | null;
|
|
447
|
+
escapeCalled(): boolean;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export declare class HandleStore {
|
|
451
|
+
static UNDEFINED: ConstHandle<undefined>;
|
|
452
|
+
static NULL: ConstHandle<null>;
|
|
453
|
+
static FALSE: ConstHandle<false>;
|
|
454
|
+
static TRUE: ConstHandle<true>;
|
|
455
|
+
static GLOBAL: ConstHandle<typeof globalThis>;
|
|
456
|
+
static MIN_ID: 6;
|
|
457
|
+
private readonly _values;
|
|
458
|
+
private _next;
|
|
459
|
+
push<S>(value: S): Handle<S>;
|
|
460
|
+
erase(start: number, end: number): void;
|
|
461
|
+
get(id: Ptr): Handle<any> | undefined;
|
|
462
|
+
swap(a: number, b: number): void;
|
|
463
|
+
dispose(): void;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export declare interface IDeferrdValue<T = any> {
|
|
467
|
+
resolve: (value: T) => void;
|
|
468
|
+
reject: (reason?: any) => void;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export declare interface IReferenceBinding {
|
|
472
|
+
wrapped: number;
|
|
473
|
+
tag: [number, number, number, number] | null;
|
|
474
|
+
data: void_p;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export declare function isReferenceType(v: any): v is object;
|
|
478
|
+
|
|
479
|
+
export declare interface IStoreValue {
|
|
480
|
+
id: number;
|
|
481
|
+
dispose(): void;
|
|
482
|
+
[x: string]: any;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL;
|
|
486
|
+
|
|
487
|
+
export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION;
|
|
488
|
+
|
|
489
|
+
export declare const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX;
|
|
490
|
+
|
|
491
|
+
export declare const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN;
|
|
492
|
+
|
|
493
|
+
export declare class NodeEnv extends Env {
|
|
494
|
+
filename: string;
|
|
495
|
+
private readonly nodeBinding?;
|
|
496
|
+
destructing: boolean;
|
|
497
|
+
finalizationScheduled: boolean;
|
|
498
|
+
constructor(ctx: Context, filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any);
|
|
499
|
+
deleteMe(): void;
|
|
500
|
+
canCallIntoJs(): boolean;
|
|
501
|
+
triggerFatalException(err: any): void;
|
|
502
|
+
callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T;
|
|
503
|
+
callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
|
|
504
|
+
callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void;
|
|
505
|
+
enqueueFinalizer(finalizer: RefTracker): void;
|
|
506
|
+
drainFinalizerQueue(): void;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export declare class NotSupportBufferError extends EmnapiError {
|
|
510
|
+
constructor(api: string, message: string);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export declare class NotSupportWeakRefError extends EmnapiError {
|
|
514
|
+
constructor(api: string, message: string);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
export declare class Persistent<T> {
|
|
518
|
+
private _ref;
|
|
519
|
+
private _param;
|
|
520
|
+
private _callback;
|
|
521
|
+
private static readonly _registry;
|
|
522
|
+
constructor(value: T);
|
|
523
|
+
setWeak<P>(param: P, callback: (param: P) => void): void;
|
|
524
|
+
clearWeak(): void;
|
|
525
|
+
reset(): void;
|
|
526
|
+
isEmpty(): boolean;
|
|
527
|
+
deref(): T | undefined;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export declare interface RefBase extends Finalizer, RefTracker {
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export declare class RefBase extends Finalizer {
|
|
534
|
+
static finalizeAll(list: RefTracker): void;
|
|
535
|
+
link(list: RefTracker): void;
|
|
536
|
+
unlink(): void;
|
|
537
|
+
private _refcount;
|
|
538
|
+
private readonly _ownership;
|
|
539
|
+
constructor(envObject: Env, initial_refcount: uint32_t, ownership: number, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
|
|
540
|
+
dispose(): void;
|
|
541
|
+
data(): void_p;
|
|
542
|
+
ref(): uint32_t;
|
|
543
|
+
unref(): uint32_t;
|
|
544
|
+
refCount(): uint32_t;
|
|
545
|
+
ownership(): number;
|
|
546
|
+
finalize(): void;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export declare class Reference extends RefBase implements IStoreValue {
|
|
550
|
+
id: number;
|
|
551
|
+
private canBeWeak;
|
|
552
|
+
static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
|
|
553
|
+
persistent: Persistent<object>;
|
|
554
|
+
private constructor();
|
|
555
|
+
ref(): number;
|
|
556
|
+
unref(): number;
|
|
557
|
+
get(): napi_value;
|
|
558
|
+
private _setWeak;
|
|
559
|
+
finalize(): void;
|
|
560
|
+
dispose(): void;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export declare class RefTracker {
|
|
564
|
+
finalize(): void;
|
|
565
|
+
private _next;
|
|
566
|
+
private _prev;
|
|
567
|
+
link(list: RefTracker): void;
|
|
568
|
+
unlink(): void;
|
|
569
|
+
static finalizeAll(list: RefTracker): void;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export declare class ScopeStore {
|
|
573
|
+
private readonly _rootScope;
|
|
574
|
+
currentScope: HandleScope;
|
|
575
|
+
constructor();
|
|
576
|
+
get(id: number): HandleScope | undefined;
|
|
577
|
+
openScope(envObject: Env): HandleScope;
|
|
578
|
+
closeScope(envObject: Env): void;
|
|
579
|
+
dispose(): void;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export declare class Store<V extends IStoreValue> {
|
|
583
|
+
protected _values: Array<V | undefined>;
|
|
584
|
+
private _freeList;
|
|
585
|
+
private _size;
|
|
586
|
+
constructor();
|
|
587
|
+
add(value: V): void;
|
|
588
|
+
get(id: Ptr): V | undefined;
|
|
589
|
+
has(id: Ptr): boolean;
|
|
590
|
+
remove(id: Ptr): void;
|
|
591
|
+
dispose(): void;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
export declare class TryCatch {
|
|
595
|
+
private _exception;
|
|
596
|
+
private _caught;
|
|
597
|
+
hasCaught(): boolean;
|
|
598
|
+
exception(): any;
|
|
599
|
+
setError(err: any): void;
|
|
600
|
+
reset(): void;
|
|
601
|
+
extractException(): any;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
export declare const version: string;
|
|
605
|
+
|
|
606
|
+
export { }
|
package/dist/emnapi.cjs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class e{constructor(e,t,n,s,i){this.parent=e,this.thiz=t,this.data=n,this.args=s,this.fn=i}getNewTarget(e){const t=this.thiz;return null==t||null==t.constructor?0:t instanceof this.fn?e.ensureHandleId(t.constructor):0}}class t{constructor(){this.current=null}pop(){const e=this.current;null!==e&&(this.current=e.parent)}push(t,n,s,i){const r=new e(this.current,t,n,s,i);return this.current=r,r}dispose(){this.current=null}}const n=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),s=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&n)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}();class i{constructor(){this._exception=void 0,this._caught=!1}hasCaught(){return this._caught}exception(){return this._exception}setError(e){this._caught=!0,this._exception=e}reset(){this._caught=!1,this._exception=void 0}extractException(){const e=this._exception;return this.reset(),e}}const r=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),o="object"==typeof Reflect,a="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,l=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),c="undefined"!=typeof BigInt;function u(e){return"object"==typeof e&&null!==e||"function"==typeof e}const h=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),p="function"==typeof MessageChannel?MessageChannel:function(){try{return h("worker_threads").MessageChannel}catch(e){}}(),d="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(p){let t=new p;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},f="function"==typeof Buffer?Buffer:function(){try{return h("buffer").Buffer}catch(e){}}(),_="0.40.0",v=9,g=2147483647;class y{constructor(e,t){this.id=e,this.value=t}data(e){return e.getObjectBinding(this.value).data}isNumber(){return"number"==typeof this.value}isBigInt(){return"bigint"==typeof this.value}isString(){return"string"==typeof this.value}isFunction(){return"function"==typeof this.value}isExternal(){return u(this.value)&&null===Object.getPrototypeOf(this.value)}isObject(){return"object"==typeof this.value&&null!==this.value}isArray(){return Array.isArray(this.value)}isArrayBuffer(){return this.value instanceof ArrayBuffer}isTypedArray(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(){return"function"==typeof f&&f.isBuffer(this.value)}isDataView(){return this.value instanceof DataView}isDate(){return this.value instanceof Date}isPromise(){return this.value instanceof Promise}isBoolean(){return"boolean"==typeof this.value}isUndefined(){return void 0===this.value}isSymbol(){return"symbol"==typeof this.value}isNull(){return null===this.value}dispose(){this.value=void 0}}class x extends y{constructor(e,t){super(e,t)}dispose(){}}function b(){Object.setPrototypeOf(this,null)}b.prototype=null;class S{constructor(){this._values=[void 0,S.UNDEFINED,S.NULL,S.FALSE,S.TRUE,S.GLOBAL],this._next=S.MIN_ID}push(e){let t;const n=this._next,s=this._values;return n<s.length?(t=s[n],t.value=e):(t=new y(n,e),s[n]=t),this._next++,t}erase(e,t){this._next=e;const n=this._values;for(let s=e;s<t;++s)n[s].dispose()}get(e){return this._values[e]}swap(e,t){const n=this._values,s=n[e];n[e]=n[t],n[e].id=Number(e),n[t]=s,s.id=Number(t)}dispose(){this._values.length=S.MIN_ID,this._next=S.MIN_ID}}S.UNDEFINED=new x(1,void 0),S.NULL=new x(2,null),S.FALSE=new x(3,!1),S.TRUE=new x(4,!0),S.GLOBAL=new x(5,s),S.MIN_ID=6;class w{constructor(e,t,n,s,i=s){this.handleStore=e,this.id=t,this.parent=n,this.child=null,null!==n&&(n.child=this),this.start=s,this.end=i,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const n=new b,s=e.ctx.handleStore.push(n);return e.initObjectBinding(n).data=t,this.end++,s}dispose(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class k{constructor(){this._rootScope=new w(null,0,null,1,S.MIN_ID),this.currentScope=this._rootScope}get(e){e=Number(e);let t=this.currentScope;for(;t!==this._rootScope;){if(t.id===e)return t;t=t.parent}}openScope(e){const t=this.currentScope;let n=t.child;return null!==n?(n.start=n.end=t.end,n._escapeCalled=!1):n=new w(e.ctx.handleStore,t.id+1,t,t.end),this.currentScope=n,e.openHandleScopes++,n}closeScope(e){if(0===e.openHandleScopes)return;const t=this.currentScope;this.currentScope=t.parent,t.dispose(),e.openHandleScopes--}dispose(){let e=this.currentScope;for(;null!==e;){e.handleStore=null,e.id=0,e.parent=null,e.start=S.MIN_ID,e.end=S.MIN_ID,e._escapeCalled=!1;const t=e.child;e.child=null,e=t}this.currentScope=null}}class E{constructor(){this._next=null,this._prev=null}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class C{constructor(e,t=0,n=0,s=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=n,this._finalizeHint=s}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}dispose(){this.envObject=void 0}}class m extends C{static finalizeAll(e){E.finalizeAll(e)}link(e){E.prototype.link.call(this,e)}unlink(){E.prototype.unlink.call(this)}constructor(e,t,n,s,i,r){super(e,s,i,r),this._next=null,this._prev=null,this._refcount=t,this._ownership=n,this.link(s?e.finalizing_reflist:e.reflist)}dispose(){this.unlink(),this.envObject.dequeueFinalizer(this),super.dispose()}data(){return this._finalizeData}ref(){return++this._refcount}unref(){return 0===this._refcount?0:--this._refcount}refCount(){return this._refcount}ownership(){return this._ownership}finalize(){const e=this._ownership,t=this._finalizeCallback,n=this._finalizeData,s=this._finalizeHint;let i;this.resetFinalizer(),this.unlink();let r=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,n,s)}catch(e){r=!0,i=e}}if(0===e&&this.dispose(),r)throw i}}function I(e,t){if(!e.terminatedOrTerminating())throw t}class z{constructor(e,t,n,s,r){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=n,this.makeDynCall_vp=s,this.abort=r,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new i,this.refs=1,this.reflist=new E,this.finalizing_reflist=new E,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this._bindingMap=new WeakMap,this.id=0}canCallIntoJs(){return!0}terminatedOrTerminating(){return!this.canCallIntoJs()}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return 0!==e.errorCode&&(e.errorCode=0),0!==e.engineErrorCode&&(e.engineErrorCode=0),0!==e.engineReserved&&(e.engineReserved=0),0}setLastError(e,t=0,n=0){const s=this.lastError;return s.errorCode!==e&&(s.errorCode=e),s.engineErrorCode!==t&&(s.engineErrorCode=t),s.engineReserved!==n&&(s.engineReserved=n),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=I){const n=this.openHandleScopes;this.clearLastError();const s=e(this);if(n!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return s}callFinalizer(e,t,n){const s=this.makeDynCall_vppp(e),i=this.id,r=this.ctx.openScope(this);try{this.callIntoModule((()=>{s(i,t,n)}))}finally{this.ctx.closeScope(this,r)}}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e)}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}deleteMe(){m.finalizeAll(this.finalizing_reflist),m.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null,data:0};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,n){this.instanceData&&this.instanceData.dispose(),this.instanceData=new m(this,0,0,t,e,n)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class N extends z{constructor(e,t,n,s,i,r,o){super(e,n,s,i,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return this.ctx.canCallIntoJs()}triggerFatalException(e){if(this.nodeBinding)this.nodeBinding.napi.fatalException(e);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw e;process._fatalException(e)||(console.error(e),process.exit(1))}}callbackIntoModule(e,t){return this.callIntoModule(t,((t,n)=>{if(t.terminatedOrTerminating())return;const s="object"==typeof process&&null!==process;if(!(!!s&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy")))&&!e){if(!s||"function"!=typeof process.emitWarning)throw n;process.emitWarning("Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168")}t.triggerFatalException(n)}))}callFinalizer(e,t,n){this.callFinalizerInternal(1,e,t,n)}callFinalizerInternal(e,t,n,s){const i=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),(()=>{i(r,n,s)}))}finally{this.ctx.closeScope(this,o)}}enqueueFinalizer(e){super.enqueueFinalizer(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),d((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}}function O(e,t,n,s,i,r,o){(n="number"!=typeof n?8:n)<8?n=8:n>v&&n!==g&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version ${v} add-ons.`)}(t,n);const a=new N(e,t,n,s,i,r,o);return e.envStore.add(a),e.addCleanupHook(a,(()=>{a.unref()}),0),a}class D extends Error{constructor(e){super(e);const t=new.target,n=t.prototype;if(!(this instanceof D)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,n):this.__proto__=n,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(D.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class F extends D{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(F.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class H extends D{constructor(e,t){super(`${e}: The current runtime does not support "BigInt".${t?` ${t}`:""}`)}}Object.defineProperty(H.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBigIntError"});class B extends D{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(B.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class R{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class j{constructor(e){this._ref=new R(e)}setWeak(e,t){if(!a||void 0===this._ref||this._ref instanceof WeakRef)return;const n=this._ref.deref();try{j._registry.register(n,this,this);const s=new WeakRef(n);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof n)throw e}}clearWeak(){if(a&&void 0!==this._ref&&this._ref instanceof WeakRef){try{j._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new R(e)}}reset(){if(a)try{j._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof R&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}function A(e){e.persistent.reset(),e.envObject.enqueueFinalizer(e)}j._registry=a?new FinalizationRegistry((e=>{e._ref=void 0;const t=e._callback,n=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(n)})):void 0;class M extends m{static create(e,t,n,s,i=0,r=0,o=0){const a=e.ctx.handleStore.get(t),l=new M(e,n,s,i,r,o);var c;return e.ctx.refStore.add(l),l.canBeWeak=(c=a).isObject()||c.isFunction()||c.isSymbol(),l.persistent=new j(a.value),0===n&&l._setWeak(),l}constructor(e,t,n,s=0,i=0,r=0){super(e,t>>>0,n,s,i,r),this.id=0}ref(){if(this.persistent.isEmpty())return 0;const e=super.ref();return 1===e&&this.canBeWeak&&this.persistent.clearWeak(),e}unref(){if(this.persistent.isEmpty())return 0;const e=this.refCount(),t=super.unref();return 1===e&&0===t&&this._setWeak(),t}get(){if(this.persistent.isEmpty())return 0;const e=this.persistent.deref();return this.envObject.ensureHandle(e).id}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,A):this.persistent.reset()}finalize(){this.persistent.reset(),super.finalize()}dispose(){0!==this.id&&(this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.id=0)}}class L{static create(e,t){const n=new L(e,t);return e.deferredStore.add(n),n}constructor(e,t){this.id=0,this.ctx=e,this.value=t}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class T{constructor(){this._values=[void 0],this._values.length=4,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=e+(e>>1)+16)}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}class W{constructor(e,t,n,s){this.envObject=e,this.fn=t,this.arg=n,this.order=s}}class P{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,n){if(this._cleanupHooks.filter((s=>s.envObject===e&&s.fn===t&&s.arg===n)).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new W(e,t,n,this._cleanupHookCounter++))}remove(e,t,n){for(let s=0;s<this._cleanupHooks.length;++s){const i=this._cleanupHooks[s];if(i.envObject===e&&i.fn===t&&i.arg===n)return void this._cleanupHooks.splice(s,1)}}drain(){const e=this._cleanupHooks.slice();e.sort(((e,t)=>t.order-e.order));for(let t=0;t<e.length;++t){const n=e[t];"number"==typeof n.fn?n.envObject.makeDynCall_vp(n.fn)(n.arg):n.fn(n.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(n),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class U{constructor(){this.refHandle=(new p).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref(),this.count--)}}class q{constructor(){this._isStopping=!1,this._canCallIntoJs=!0,this.envStore=new T,this.scopeStore=new k,this.refStore=new T,this.deferredStore=new T,this.handleStore=new S,this.cbinfoStack=new t,this.feature={supportReflect:o,supportFinalizer:a,supportWeakSymbol:l,supportBigInt:c,supportNewFunction:n,canSetFunctionName:r,setImmediate:d,Buffer:f,MessageChannel:p},this.cleanupQueue=new P,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new U,process.once("beforeExit",(()=>{this.destroy()})))}getRuntimeVersions(){return{version:_,NAPI_VERSION:v,NAPI_VERSION_EXPERIMENTAL:g,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new F(e,t)}createNotSupportBigIntError(e,t){return new H(e,t)}createNotSupportBufferError(e,t){return new B(e,t)}createReference(e,t,n,s,i=0,r=0,o=0){return M.create(e,t,n,s,i,r,o)}createDeferred(e){return L.create(this,e)}createEnv(e,t,n,s,i,r){return O(this,e,t,n,s,i,r)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){return this.scopeStore.openScope(e)}closeScope(e,t){this.scopeStore.closeScope(e)}ensureHandle(e){switch(e){case void 0:return S.UNDEFINED;case null:return S.NULL;case!0:return S.TRUE;case!1:return S.FALSE;case s:return S.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,n){this.cleanupQueue.add(e,t,n)}removeCleanupHook(e,t,n){this.cleanupQueue.remove(e,t,n)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}setCanCallIntoJs(e){this._canCallIntoJs=e}setStopping(e){this._isStopping=e}canCallIntoJs(){return this._canCallIntoJs&&!this._isStopping}destroy(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()}}let V;function $(){return new q}exports.CallbackInfo=e,exports.CallbackInfoStack=t,exports.ConstHandle=x,exports.Context=q,exports.Deferred=L,exports.EmnapiError=D,exports.Env=z,exports.Finalizer=C,exports.Handle=y,exports.HandleScope=w,exports.HandleStore=S,exports.NAPI_VERSION=v,exports.NAPI_VERSION_EXPERIMENTAL=g,exports.NODE_API_DEFAULT_MODULE_API_VERSION=8,exports.NodeEnv=N,exports.NotSupportBigIntError=H,exports.NotSupportBufferError=B,exports.NotSupportWeakRefError=F,exports.Persistent=j,exports.RefBase=m,exports.RefTracker=E,exports.Reference=M,exports.ScopeStore=k,exports.Store=T,exports.TryCatch=i,exports.createContext=$,exports.getDefaultContext=function(){return V||(V=$()),V},exports.isReferenceType=u,exports.version=_;
|
|
1
|
+
const e=[];class t{constructor(e,t,n,i,s,r,o){this.id=e,this.parent=t,this.child=n,this.thiz=i,this.data=s,this.args=r,this.fn=o}getNewTarget(e){const t=this.thiz;return null==t||null==t.constructor?0:t instanceof this.fn?e.ensureHandleId(t.constructor):0}dispose(){void 0!==this.thiz&&(this.thiz=void 0),this.args=e,this.fn=null}}const n=new t(0,null,null,null,0,null,null);class i{constructor(){this.current=n}get(e){if(1===e)return n.child;let t=n;for(let n=0;n<e;++n)if(t=t.child,null===t)return null;return t===n?null:t}pop(){const e=this.current;e!==n&&(this.current=e.parent,e.dispose())}push(e,n,i,s){let r=this.current.child;return r?(r.thiz=e,r.data=n,r.args=i,r.fn=s):(r=new t(this.current.id+1,this.current,null,e,n,i,s),this.current.child=r),this.current=r,r.id}dispose(){this.current=null}}const s=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),r=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&s)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}();class o{constructor(){this._exception=void 0,this._caught=!1}hasCaught(){return this._caught}exception(){return this._exception}setError(e){this._caught=!0,this._exception=e}reset(){this._caught=!1,this._exception=void 0}extractException(){const e=this._exception;return this.reset(),e}}const a=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),l="object"==typeof Reflect,c="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,u=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),h="undefined"!=typeof BigInt;function p(e){return"object"==typeof e&&null!==e||"function"==typeof e}const d=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),f="function"==typeof MessageChannel?MessageChannel:function(){try{return d("worker_threads").MessageChannel}catch(e){}}(),_="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(f){let t=new f;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},v="function"==typeof Buffer?Buffer:function(){try{return d("buffer").Buffer}catch(e){}}(),g="0.42.0",y=9,x=2147483647;class S{constructor(e,t){this.id=e,this.value=t}data(e){return e.getObjectBinding(this.value).data}isNumber(){return"number"==typeof this.value}isBigInt(){return"bigint"==typeof this.value}isString(){return"string"==typeof this.value}isFunction(){return"function"==typeof this.value}isExternal(){return p(this.value)&&null===Object.getPrototypeOf(this.value)}isObject(){return"object"==typeof this.value&&null!==this.value}isArray(){return Array.isArray(this.value)}isArrayBuffer(){return this.value instanceof ArrayBuffer}isTypedArray(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(){return"function"==typeof v&&v.isBuffer(this.value)}isDataView(){return this.value instanceof DataView}isDate(){return this.value instanceof Date}isPromise(){return this.value instanceof Promise}isBoolean(){return"boolean"==typeof this.value}isUndefined(){return void 0===this.value}isSymbol(){return"symbol"==typeof this.value}isNull(){return null===this.value}dispose(){this.value=void 0}}class b extends S{constructor(e,t){super(e,t)}dispose(){}}function E(){Object.setPrototypeOf(this,null)}E.prototype=null;class w{constructor(){this._values=[void 0,w.UNDEFINED,w.NULL,w.FALSE,w.TRUE,w.GLOBAL],this._next=w.MIN_ID}push(e){let t;const n=this._next,i=this._values;return n<i.length?(t=i[n],t.value=e):(t=new S(n,e),i[n]=t),this._next++,t}erase(e,t){this._next=e;const n=this._values;for(let i=e;i<t;++i)n[i].dispose()}get(e){return this._values[e]}swap(e,t){const n=this._values,i=n[e];n[e]=n[t],n[e].id=Number(e),n[t]=i,i.id=Number(t)}dispose(){this._values.length=w.MIN_ID,this._next=w.MIN_ID}}w.UNDEFINED=new b(1,void 0),w.NULL=new b(2,null),w.FALSE=new b(3,!1),w.TRUE=new b(4,!0),w.GLOBAL=new b(5,r),w.MIN_ID=6;class k{constructor(e,t,n,i,s=i){this.handleStore=e,this.id=t,this.parent=n,this.child=null,null!==n&&(n.child=this),this.start=i,this.end=s,this._escapeCalled=!1}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e,t){const n=new E,i=e.ctx.handleStore.push(n);return e.initObjectBinding(n).data=t,this.end++,i}dispose(){this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class C{constructor(){this._rootScope=new k(null,0,null,1,w.MIN_ID),this.currentScope=this._rootScope}get(e){e=Number(e);let t=this.currentScope;for(;t!==this._rootScope;){if(t.id===e)return t;t=t.parent}}openScope(e){const t=this.currentScope;let n=t.child;return null!==n?(n.start=n.end=t.end,n._escapeCalled=!1):n=new k(e.ctx.handleStore,t.id+1,t,t.end),this.currentScope=n,e.openHandleScopes++,n}closeScope(e){if(0===e.openHandleScopes)return;const t=this.currentScope;this.currentScope=t.parent,t.dispose(),e.openHandleScopes--}dispose(){let e=this.currentScope;for(;null!==e;){e.handleStore=null,e.id=0,e.parent=null,e.start=w.MIN_ID,e.end=w.MIN_ID,e._escapeCalled=!1;const t=e.child;e.child=null,e=t}this.currentScope=null}}class m{constructor(){this._next=null,this._prev=null}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class z{constructor(e,t=0,n=0,i=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=n,this._finalizeHint=i}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}dispose(){this.envObject=void 0}}class I extends z{static finalizeAll(e){m.finalizeAll(e)}link(e){m.prototype.link.call(this,e)}unlink(){m.prototype.unlink.call(this)}constructor(e,t,n,i,s,r){super(e,i,s,r),this._next=null,this._prev=null,this._refcount=t,this._ownership=n,this.link(i?e.finalizing_reflist:e.reflist)}dispose(){this.unlink(),this.envObject.dequeueFinalizer(this),super.dispose()}data(){return this._finalizeData}ref(){return++this._refcount}unref(){return 0===this._refcount?0:--this._refcount}refCount(){return this._refcount}ownership(){return this._ownership}finalize(){const e=this._ownership,t=this._finalizeCallback,n=this._finalizeData,i=this._finalizeHint;let s;this.resetFinalizer(),this.unlink();let r=!1;if(t){const e=Number(t);try{this.envObject.callFinalizer(e,n,i)}catch(e){r=!0,s=e}}if(0===e&&this.dispose(),r)throw s}}function O(e,t){if(!e.terminatedOrTerminating())throw t}class D{constructor(e,t,n,i,s){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=n,this.makeDynCall_vp=i,this.abort=s,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new o,this.refs=1,this.reflist=new m,this.finalizing_reflist=new m,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this._bindingMap=new WeakMap,this.id=0}canCallIntoJs(){return!0}terminatedOrTerminating(){return!this.canCallIntoJs()}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return 0!==e.errorCode&&(e.errorCode=0),0!==e.engineErrorCode&&(e.engineErrorCode=0),0!==e.engineReserved&&(e.engineReserved=0),0}setLastError(e,t=0,n=0){const i=this.lastError;return i.errorCode!==e&&(i.errorCode=e),i.engineErrorCode!==t&&(i.engineErrorCode=t),i.engineReserved!==n&&(i.engineReserved=n),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=O){const n=this.openHandleScopes;this.clearLastError();const i=e(this);if(n!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return i}callFinalizer(e,t,n){const i=this.makeDynCall_vppp(e),s=this.id,r=this.ctx.openScope(this);try{this.callIntoModule((()=>{i(s,t,n)}))}finally{this.ctx.closeScope(this,r)}}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e)}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}deleteMe(){I.finalizeAll(this.finalizing_reflist),I.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null,data:0};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,n){this.instanceData&&this.instanceData.dispose(),this.instanceData=new I(this,0,0,t,e,n)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class N extends D{constructor(e,t,n,i,s,r,o){super(e,n,i,s,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return this.ctx.canCallIntoJs()}triggerFatalException(e){if(this.nodeBinding)this.nodeBinding.napi.fatalException(e);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw e;process._fatalException(e)||(console.error(e),process.exit(1))}}callbackIntoModule(e,t){return this.callIntoModule(t,((t,n)=>{if(t.terminatedOrTerminating())return;const i="object"==typeof process&&null!==process;if(!!i&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"))||e)t.triggerFatalException(n);else{(i&&"function"==typeof process.emitWarning?process.emitWarning:function(e,t,n){if(e instanceof Error)console.warn(e.toString());else{const i=n?`[${n}] `:"";console.warn(`${i}${t||"Warning"}: ${e}`)}})("Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168")}}))}callFinalizer(e,t,n){this.callFinalizerInternal(1,e,t,n)}callFinalizerInternal(e,t,n,i){const s=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),(()=>{s(r,n,i)}))}finally{this.ctx.closeScope(this,o)}}enqueueFinalizer(e){super.enqueueFinalizer(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),_((()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()})))}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}}function F(e,t,n,i,s,r,o){(n="number"!=typeof n?8:n)<8?n=8:n>y&&n!==x&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version ${y} add-ons.`)}(t,n);const a=new N(e,t,n,i,s,r,o);return e.envStore.add(a),e.addCleanupHook(a,(()=>{a.unref()}),0),a}class R extends Error{constructor(e){super(e);const t=new.target,n=t.prototype;if(!(this instanceof R)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,n):this.__proto__=n,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(R.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class H extends R{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(H.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class A extends R{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(A.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class B{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class j{constructor(e){this._ref=new B(e)}setWeak(e,t){if(!c||void 0===this._ref||this._ref instanceof WeakRef)return;const n=this._ref.deref();try{j._registry.register(n,this,this);const i=new WeakRef(n);this._ref.dispose(),this._ref=i,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof n)throw e}}clearWeak(){if(c&&void 0!==this._ref&&this._ref instanceof WeakRef){try{j._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new B(e)}}reset(){if(c)try{j._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof B&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}function M(e){e.persistent.reset(),e.envObject.enqueueFinalizer(e)}j._registry=c?new FinalizationRegistry((e=>{e._ref=void 0;const t=e._callback,n=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(n)})):void 0;class L extends I{static create(e,t,n,i,s=0,r=0,o=0){const a=e.ctx.handleStore.get(t),l=new L(e,n,i,s,r,o);var c;return e.ctx.refStore.add(l),l.canBeWeak=(c=a).isObject()||c.isFunction()||c.isSymbol(),l.persistent=new j(a.value),0===n&&l._setWeak(),l}constructor(e,t,n,i=0,s=0,r=0){super(e,t>>>0,n,i,s,r),this.id=0}ref(){if(this.persistent.isEmpty())return 0;const e=super.ref();return 1===e&&this.canBeWeak&&this.persistent.clearWeak(),e}unref(){if(this.persistent.isEmpty())return 0;const e=this.refCount(),t=super.unref();return 1===e&&0===t&&this._setWeak(),t}get(){if(this.persistent.isEmpty())return 0;const e=this.persistent.deref();return this.envObject.ensureHandle(e).id}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,M):this.persistent.reset()}finalize(){this.persistent.reset(),super.finalize()}dispose(){0!==this.id&&(this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.id=0)}}class P{static create(e,t){const n=new P(e,t);return e.deferredStore.add(n),n}constructor(e,t){this.id=0,this.ctx=e,this.value=t}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class T{constructor(){this._values=[void 0],this._values.length=4,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=e+(e>>1)+16)}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}class W{constructor(e,t,n,i){this.envObject=e,this.fn=t,this.arg=n,this.order=i}}class U{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,n){if(this._cleanupHooks.filter((i=>i.envObject===e&&i.fn===t&&i.arg===n)).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new W(e,t,n,this._cleanupHookCounter++))}remove(e,t,n){for(let i=0;i<this._cleanupHooks.length;++i){const s=this._cleanupHooks[i];if(s.envObject===e&&s.fn===t&&s.arg===n)return void this._cleanupHooks.splice(i,1)}}drain(){const e=this._cleanupHooks.slice();e.sort(((e,t)=>t.order-e.order));for(let t=0;t<e.length;++t){const n=e[t];"number"==typeof n.fn?n.envObject.makeDynCall_vp(n.fn)(n.arg):n.fn(n.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(n),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class q{constructor(){this.refHandle=(new f).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref(),this.count--)}}class V{constructor(){this._isStopping=!1,this._canCallIntoJs=!0,this.envStore=new T,this.scopeStore=new C,this.refStore=new T,this.deferredStore=new T,this.handleStore=new w,this.cbinfoStack=new i,this.feature={supportReflect:l,supportFinalizer:c,supportWeakSymbol:u,supportBigInt:h,supportNewFunction:s,canSetFunctionName:a,setImmediate:_,Buffer:v,MessageChannel:f},this.cleanupQueue=new U,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new q,process.once("beforeExit",(()=>{this.destroy()})))}getRuntimeVersions(){return{version:g,NODE_API_SUPPORTED_VERSION_MAX:y,NAPI_VERSION_EXPERIMENTAL:x,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new H(e,t)}createNotSupportBufferError(e,t){return new A(e,t)}createReference(e,t,n,i,s=0,r=0,o=0){return L.create(e,t,n,i,s,r,o)}createDeferred(e){return P.create(this,e)}createEnv(e,t,n,i,s,r){return F(this,e,t,n,i,s,r)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){return this.scopeStore.openScope(e)}closeScope(e,t){this.scopeStore.closeScope(e)}ensureHandle(e){switch(e){case void 0:return w.UNDEFINED;case null:return w.NULL;case!0:return w.TRUE;case!1:return w.FALSE;case r:return w.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,n){this.cleanupQueue.add(e,t,n)}removeCleanupHook(e,t,n){this.cleanupQueue.remove(e,t,n)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}setCanCallIntoJs(e){this._canCallIntoJs=e}setStopping(e){this._isStopping=e}canCallIntoJs(){return this._canCallIntoJs&&!this._isStopping}destroy(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()}}let $;function J(){return new V}exports.CallbackInfo=t,exports.CallbackInfoStack=i,exports.ConstHandle=b,exports.Context=V,exports.Deferred=P,exports.EmnapiError=R,exports.Env=D,exports.Finalizer=z,exports.Handle=S,exports.HandleScope=k,exports.HandleStore=w,exports.NAPI_VERSION_EXPERIMENTAL=x,exports.NODE_API_DEFAULT_MODULE_API_VERSION=8,exports.NODE_API_SUPPORTED_VERSION_MAX=y,exports.NODE_API_SUPPORTED_VERSION_MIN=1,exports.NodeEnv=N,exports.NotSupportBufferError=A,exports.NotSupportWeakRefError=H,exports.Persistent=j,exports.RefBase=I,exports.RefTracker=m,exports.Reference=L,exports.ScopeStore=C,exports.Store=T,exports.TryCatch=o,exports.createContext=J,exports.getDefaultContext=function(){return $||($=J()),$},exports.isReferenceType=p,exports.version=g;
|