@emnapi/runtime
Advanced tools
Sorry, the diff of this file is too big to display
| import { defineConfig } from '@emnapi/shared' | ||
| import fs from 'fs' | ||
| import path from 'path' | ||
| import { EOL } from 'os' | ||
| import pkg from './package.json' with { type: 'json' } | ||
| export default defineConfig({ | ||
| outputName: 'emnapi', | ||
| outputFile: 'emnapi', | ||
| sourcemap: true, | ||
| defines: { | ||
| __VERSION__: JSON.stringify(pkg.version) | ||
| }, | ||
| apiExtractorCallback: (result) => { | ||
| if (result.succeeded) { | ||
| let dts = '' | ||
| dts += '/// <reference lib="esnext.disposable" />' + EOL + EOL | ||
| dts += fs.readFileSync(path.join(import.meta.dirname, 'src/typings/common.d.ts'), 'utf8').replace(/declare/g, 'export declare') | ||
| dts += fs.readFileSync(path.join(import.meta.dirname, 'src/typings/ctype.d.ts'), 'utf8').replace(/declare/g, 'export declare') | ||
| dts += fs.readFileSync(path.join(import.meta.dirname, 'src/typings/napi.d.ts'), 'utf8').replace(/declare/g, 'export declare') | ||
| dts += fs.readFileSync(result.extractorConfig.publicTrimmedFilePath, 'utf8') | ||
| fs.writeFileSync(result.extractorConfig.publicTrimmedFilePath, dts, 'utf8') | ||
| } | ||
| } | ||
| }) |
+337
-182
@@ -0,4 +1,9 @@ | ||
| /// <reference lib="esnext.disposable" /> | ||
| export declare type Ptr = number | bigint | ||
| export declare interface IBuffer extends Uint8Array {} | ||
| export declare interface IBuffer extends Uint8Array { | ||
| toString (encoding?: string, start?: number, end?: number): string | ||
| } | ||
| export declare interface BufferCtor { | ||
@@ -16,8 +21,11 @@ readonly prototype: IBuffer | ||
| export declare const enum GlobalHandle { | ||
| UNDEFINED = 1, | ||
| export declare const enum Constant { | ||
| HOLE, | ||
| EMPTY, | ||
| UNDEFINED, | ||
| NULL, | ||
| FALSE, | ||
| TRUE, | ||
| GLOBAL | ||
| GLOBAL, | ||
| EMPTY_STRING, | ||
| } | ||
@@ -29,6 +37,7 @@ | ||
| NODE_API_SUPPORTED_VERSION_MAX = 10, | ||
| NODE_MODULE_VERSION = 127, | ||
| NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export declare type Pointer<T> = number | ||
| export declare type Pointer<T> = number | bigint | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
@@ -47,4 +56,6 @@ export declare type PointerPointer<T> = number | ||
| export declare type const_char_p = Pointer<const_char> | ||
| export declare type char16_t_p = number | ||
| export declare type const_char16_t_p = number | ||
| export declare type char16_t = number | ||
| export declare type const_char16_t = number | ||
| export declare type char16_t_p = Pointer<char16_t> | ||
| export declare type const_char16_t_p = Pointer<const_char16_t> | ||
@@ -254,9 +265,24 @@ export declare type short = number | ||
| } | ||
| export declare type CleanupHookCallbackFunction = number | ((arg: number) => void); | ||
| export declare class ArrayStore<T extends { | ||
| id: number | bigint; | ||
| }> extends BaseArrayStore<T> { | ||
| protected _allocator: IdAllocator; | ||
| constructor(initialCapacity?: number); | ||
| insert(value: T): void; | ||
| alloc<P extends any[]>(factory: (...args: P) => T, ...args: P): T; | ||
| dealloc(id: number | bigint): void; | ||
| } | ||
| export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> { | ||
| constructor(id: number, value: S); | ||
| export declare class BaseArrayStore<T> extends Disposable_2 implements ObjectAllocator<T> { | ||
| protected _values: [undefined, ...(T | undefined)[]]; | ||
| constructor(initialCapacity?: number); | ||
| assign(id: number | bigint, value: T): T; | ||
| deref<R extends T = T>(id: number | bigint): R | undefined; | ||
| alloc<P extends any[]>(factory: (...args: P) => T, ...args: P): T; | ||
| dealloc(id: number | bigint): void; | ||
| dispose(): void; | ||
| } | ||
| export declare type CleanupHookCallbackFunction = number | ((arg: number) => void); | ||
| export declare class Context { | ||
@@ -266,33 +292,10 @@ private _isStopping; | ||
| private _suppressDestroy; | ||
| envStore: Store<Env>; | ||
| scopeStore: ScopeStore; | ||
| refStore: Store<Reference>; | ||
| deferredStore: Store<Deferred<any>>; | ||
| handleStore: HandleStore; | ||
| private envStore; | ||
| refStore: Map<number, Reference>; | ||
| private readonly refCounter?; | ||
| private readonly cleanupQueue; | ||
| private readonly _externalMemory; | ||
| feature: { | ||
| supportReflect: boolean; | ||
| supportFinalizer: boolean; | ||
| supportWeakSymbol: boolean; | ||
| supportBigInt: boolean; | ||
| supportNewFunction: boolean; | ||
| canSetFunctionName: boolean; | ||
| setImmediate: (callback: () => void) => void; | ||
| Buffer: BufferCtor | undefined; | ||
| MessageChannel: { | ||
| new (): MessageChannel; | ||
| prototype: MessageChannel; | ||
| } | undefined; | ||
| }; | ||
| readonly features: Features; | ||
| readonly isolate: Isolate; | ||
| constructor(options?: ContextOptions); | ||
| /** | ||
| * Suppress the destroy on `beforeExit` event in Node.js. | ||
| * Call this method if you want to keep the context and | ||
| * all associated {@link Env | Env} alive, | ||
| * this also means that cleanup hooks will not be called. | ||
| * After call this method, you should call | ||
| * {@link Context.destroy | `Context.prototype.destroy`} method manually. | ||
| */ | ||
| getIsolate(): Isolate; | ||
| suppressDestroy(): void; | ||
@@ -304,2 +307,3 @@ getRuntimeVersions(): { | ||
| NODE_API_DEFAULT_MODULE_API_VERSION: Version; | ||
| NODE_MODULE_VERSION: Version; | ||
| }; | ||
@@ -311,11 +315,19 @@ createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError; | ||
| createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference; | ||
| createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>; | ||
| createResolver<T>(): Resolver<T>; | ||
| adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint; | ||
| 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; | ||
| createEnv(filename: string, moduleApiVersion: number, bridge: EnvNativeBridge, nodeBinding?: any): Env; | ||
| createFunction(envObject: Env, napiCallback: (env: napi_env, info: napi_callback_info) => void_p, data: number | bigint, name: string, dynamicExecution: boolean): Function; | ||
| createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer; | ||
| getCurrentScope(): HandleScope | null; | ||
| addToCurrentScope<V>(value: V): Handle<V>; | ||
| openScope(envObject?: Env): HandleScope; | ||
| closeScope(envObject?: Env, _scope?: HandleScope): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| getCurrentScope(): HandleScope; | ||
| openScope(envObject: Env): HandleScope; | ||
| closeScope(envObject: Env, scope?: HandleScope): void; | ||
| getEnv(env: napi_env): Env | undefined; | ||
| getRef(ref: napi_ref): Reference | undefined; | ||
| getHandleScope(scope: napi_handle_scope): HandleScope | undefined; | ||
| getCallbackInfo(info: napi_callback_info): ICallbackInfo; | ||
| napiValueFromJsValue(value: unknown): number | bigint; | ||
| jsValueFromNapiValue<T = any>(napiValue: number | bigint): T | undefined; | ||
| createExternal(data: number | bigint): External_2; | ||
| getExternalValue(external: External_2): number | bigint; | ||
| isExternal(value: unknown): boolean; | ||
| addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
@@ -329,26 +341,45 @@ removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
| canCallIntoJs(): boolean; | ||
| /** | ||
| * Destroy the context and call cleanup hooks. | ||
| * Associated {@link Env | Env} will be destroyed. | ||
| */ | ||
| getDylinkMetadata(binary: WebAssembly.Module | Uint8Array): DylinkMetadata; | ||
| destroy(): void; | ||
| } | ||
| export declare interface ContextOptions { | ||
| onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any; | ||
| export declare interface ContextOptions extends IsolateOptions { | ||
| } | ||
| export declare function createContext(options?: ContextOptions): Context; | ||
| export declare class CountIdAllocator extends Disposable_2 implements IdAllocator { | ||
| next: number; | ||
| constructor(initialNext?: number); | ||
| aquire(): number; | ||
| release(_: number): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class Deferred<T = any> implements IStoreValue { | ||
| static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred; | ||
| id: number; | ||
| ctx: Context; | ||
| value: IDeferrdValue<T>; | ||
| constructor(ctx: Context, value: IDeferrdValue<T>); | ||
| resolve(value: T): void; | ||
| reject(reason?: any): void; | ||
| export declare class CountIdReuseAllocator extends CountIdAllocator implements IdAllocator { | ||
| private _freeList; | ||
| aquire(): number; | ||
| release(id: number): void; | ||
| dispose(): void; | ||
| } | ||
| export declare function createContext(options?: ContextOptions): Context; | ||
| export declare function deletePrivate(obj: any, key: Private): boolean; | ||
| declare abstract class Disposable_2 implements globalThis.Disposable { | ||
| abstract dispose(): void; | ||
| [Symbol.dispose](): void; | ||
| } | ||
| export { Disposable_2 as Disposable } | ||
| export declare interface DylinkMetadata { | ||
| neededDynlibs: string[]; | ||
| tlsExports: Set<string>; | ||
| weakImports: Set<string>; | ||
| runtimePaths: string[]; | ||
| memorySize: number; | ||
| memoryAlign: number; | ||
| tableSize: number; | ||
| tableAlign: number; | ||
| } | ||
| export declare class EmnapiError extends Error { | ||
@@ -358,12 +389,7 @@ constructor(message?: string); | ||
| export declare abstract class Env implements IStoreValue { | ||
| readonly 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; | ||
| id: number; | ||
| export declare abstract class Env extends Disposable_2 { | ||
| id: number | bigint; | ||
| openHandleScopes: number; | ||
| instanceData: TrackedFinalizer | null; | ||
| tryCatch: TryCatch; | ||
| lastException: Persistent<any>; | ||
| refs: number; | ||
@@ -373,10 +399,10 @@ reflist: RefTracker; | ||
| pendingFinalizers: RefTracker[]; | ||
| lastError: { | ||
| errorCode: napi_status; | ||
| engineErrorCode: number; | ||
| engineReserved: Ptr; | ||
| }; | ||
| moduleApiVersion: number; | ||
| filename: string; | ||
| nodeBinding?: any; | ||
| inGcFinalizer: boolean; | ||
| 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); | ||
| /** @virtual */ | ||
| bridge: EnvNativeBridge; | ||
| readonly ctx: Context; | ||
| private store; | ||
| constructor(ctx: Context, store: ArrayStore<Env>, bridge: EnvNativeBridge); | ||
| canCallIntoJs(): boolean; | ||
@@ -386,17 +412,10 @@ terminatedOrTerminating(): boolean; | ||
| unref(): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| ensureHandleId(value: any): napi_value; | ||
| clearLastError(): napi_status; | ||
| setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status; | ||
| getReturnStatus(): napi_status; | ||
| setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: number): napi_status; | ||
| callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T; | ||
| /** @virtual */ | ||
| abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| invokeFinalizerFromGC(finalizer: RefTracker): void; | ||
| checkGCAccess(): void; | ||
| /** @virtual */ | ||
| enqueueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| dequeueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| deleteMe(): void; | ||
@@ -408,10 +427,18 @@ dispose(): void; | ||
| setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void; | ||
| getInstanceData(): number; | ||
| getInstanceData(): number | bigint; | ||
| } | ||
| /** @public */ | ||
| export declare interface EnvNativeBridge { | ||
| address: number; | ||
| deleteEnv: (ptr: number) => void; | ||
| setLastError: (env: napi_env, error_code: napi_status, engine_error_code: uint32_t, engine_reserved: number) => void; | ||
| makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void; | ||
| makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void; | ||
| abort: (msg?: string) => never; | ||
| wasm64?: boolean; | ||
| } | ||
| declare interface External_2 extends Record<any, any> { | ||
| } | ||
| /** @public */ | ||
| declare const External_2: { | ||
@@ -423,2 +450,16 @@ new (value: number | bigint): External_2; | ||
| export declare interface Features { | ||
| makeDynamicFunction: ((...args: any[]) => Function) | undefined; | ||
| getGlobalThis: () => typeof globalThis; | ||
| setFunctionName: ((fn: Function, name: string) => void) | undefined; | ||
| Reflect: typeof Reflect | undefined; | ||
| finalizer: boolean; | ||
| weakSymbol: boolean; | ||
| BigInt: typeof BigInt | undefined; | ||
| MessageChannel: typeof MessageChannel | undefined; | ||
| Buffer: BufferCtor | undefined; | ||
| setImmediate: (callback: () => void) => any; | ||
| withResolvers: <T>(this: PromiseConstructor) => Resolver<T>; | ||
| } | ||
| export declare class Finalizer { | ||
@@ -431,2 +472,4 @@ envObject: Env; | ||
| constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p); | ||
| copy(): Finalizer; | ||
| move(target: Finalizer): void; | ||
| callback(): napi_finalize; | ||
@@ -441,35 +484,31 @@ data(): void_p; | ||
| export declare class FunctionTemplate extends Template { | ||
| callback: (info: napi_callback_info, v8FunctionCallback: Ptr) => Ptr; | ||
| v8FunctionCallback: Ptr; | ||
| data: any; | ||
| className: string | undefined; | ||
| signature: Signature | undefined; | ||
| private _instanceTemplate; | ||
| private _prototypeTemplate; | ||
| private _cached; | ||
| constructor(ctx: Isolate, callback: (info: napi_callback_info, v8FunctionCallback: Ptr) => Ptr, v8FunctionCallback: Ptr, data: any, signature?: Signature); | ||
| setClassName(name: string): void; | ||
| instanceTemplate(): ObjectTemplate; | ||
| prototypeTemplate(): ObjectTemplate; | ||
| getFunction(): (...args: any[]) => any; | ||
| } | ||
| export declare function getDefaultContext(): Context; | ||
| /** @public */ | ||
| export declare function getDylinkMetadata(binary: WebAssembly.Module | Uint8Array): DylinkMetadata; | ||
| export declare function getExternalValue(external: External_2): number | bigint; | ||
| export declare class Handle<S> { | ||
| id: number; | ||
| value: S; | ||
| constructor(id: number, value: S); | ||
| data(): void_p; | ||
| isNumber(): boolean; | ||
| isBigInt(): boolean; | ||
| isString(): boolean; | ||
| isFunction(): boolean; | ||
| isExternal(): boolean; | ||
| isObject(): boolean; | ||
| isArray(): boolean; | ||
| isArrayBuffer(): boolean; | ||
| isTypedArray(): boolean; | ||
| isBuffer(BufferConstructor?: BufferCtor): boolean; | ||
| isDataView(): boolean; | ||
| isDate(): boolean; | ||
| isPromise(): boolean; | ||
| isBoolean(): boolean; | ||
| isUndefined(): boolean; | ||
| isSymbol(): boolean; | ||
| isNull(): boolean; | ||
| dispose(): void; | ||
| } | ||
| export declare function getInternalField(instance: object, index: number): any; | ||
| export declare class HandleScope { | ||
| export declare function getPrivate(obj: any, key: Private): any; | ||
| export declare class HandleScope extends Disposable_2 { | ||
| handleStore: HandleStore; | ||
| id: number; | ||
| id: number | bigint; | ||
| parent: HandleScope | null; | ||
@@ -481,28 +520,32 @@ child: HandleScope | null; | ||
| callbackInfo: ICallbackInfo; | ||
| constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number); | ||
| add<V>(value: V): Handle<V>; | ||
| addExternal(data: void_p): Handle<object>; | ||
| static create(parentScope: HandleScope | null, handleStore: HandleStore, start?: number, end?: number): HandleScope; | ||
| constructor(parentScope: HandleScope | null, handleStore: HandleStore, start?: number, end?: number); | ||
| reuse(parentScope: HandleScope): void; | ||
| add<V>(value: V): number; | ||
| addExternal(data: number | bigint): number; | ||
| dispose(): void; | ||
| escape(handle: number): Handle<any> | null; | ||
| escape(handle: number): number; | ||
| escapeCalled(): boolean; | ||
| } | ||
| export declare class HandleStore { | ||
| static UNDEFINED: ConstHandle<undefined>; | ||
| static NULL: ConstHandle<null>; | ||
| static FALSE: ConstHandle<false>; | ||
| static TRUE: ConstHandle<true>; | ||
| static GLOBAL: ConstHandle<typeof globalThis>; | ||
| static MIN_ID: 6; | ||
| private readonly _values; | ||
| private _next; | ||
| push<S>(value: S): Handle<S>; | ||
| erase(start: number, end: number): void; | ||
| get(id: Ptr): Handle<any> | undefined; | ||
| export declare class HandleStore extends BaseArrayStore<any> { | ||
| static MIN_ID: 8; | ||
| private _allocator; | ||
| private _features; | ||
| readonly refValues: Map<number, PersistentValueType<any>>; | ||
| private _erase; | ||
| private _deref; | ||
| constructor(features: Features); | ||
| isOutOfScope(id: number): boolean; | ||
| deepDeref<R = any>(id: number | bigint): R | undefined; | ||
| push<S>(value: S): number; | ||
| erase(start: number, end: number, weak: boolean): void; | ||
| swap(a: number, b: number): void; | ||
| dispose(): void; | ||
| } | ||
| export declare function hasPrivate(obj: any, key: Private): boolean; | ||
| export declare interface ICallbackInfo { | ||
| thiz: any; | ||
| holder: any; | ||
| data: void_p; | ||
@@ -513,5 +556,5 @@ args: ArrayLike<any>; | ||
| export declare interface IDeferrdValue<T = any> { | ||
| resolve: (value: T) => void; | ||
| reject: (reason?: any) => void; | ||
| export declare interface IdAllocator extends Disposable_2 { | ||
| aquire(): number; | ||
| release(id: number): void; | ||
| } | ||
@@ -524,13 +567,61 @@ | ||
| /** @public */ | ||
| export declare function isExternal(object: unknown): object is External_2; | ||
| export declare function isReferenceType(v: any): v is object; | ||
| export declare class Isolate { | ||
| private _lastException; | ||
| private _globalThis; | ||
| private _scopeStore; | ||
| private _handleStore; | ||
| private _externalMemory; | ||
| globalHandleStore: PersistentStore; | ||
| readonly features: Features; | ||
| constructor(options?: IsolateOptions); | ||
| napiValueFromJsValue(value: unknown): number | bigint; | ||
| jsValueFromNapiValue<T = any>(napiValue: number | bigint): T | undefined; | ||
| deleteRefSlotValue(id: number | bigint): void; | ||
| getRefSlotValue(id: number | bigint): PersistentValueType<any>; | ||
| setRefSlotValue(id: number | bigint, ref: PersistentValueType<any>): void; | ||
| createReference<T>(...args: [T] | []): Persistent<T>; | ||
| insertRef<T>(persistent: Persistent<T>): void; | ||
| getRef<T = any>(ref: napi_ref): Persistent<T> | undefined; | ||
| removeRef(ref: napi_ref, force?: boolean): void; | ||
| getTryCatch(address: number | bigint): TryCatch | undefined; | ||
| pushTryCatch(address: number | bigint): TryCatch; | ||
| popTryCatch(address: number | bigint): void; | ||
| setLastException(err: any): void; | ||
| throwException(err: any): any; | ||
| hasPendingException(): boolean; | ||
| getAndClearLastException(): any; | ||
| adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint; | ||
| createSignature(template: FunctionTemplate): Signature; | ||
| createObjectTemplate(constructor: any): ObjectTemplate; | ||
| setInternalField(obj: any, index: number, value: any): void; | ||
| getInternalField(obj: any, index: number): any; | ||
| getInternalFieldCount(obj: any): number; | ||
| createFunctionTemplate(callback: (info: napi_callback_info, v8FunctionCallback: Ptr) => Ptr, v8FunctionCallback: Ptr, data: any, signature?: Signature): FunctionTemplate; | ||
| isScopeEmpty(): boolean; | ||
| getCurrentScope(): HandleScope; | ||
| openScope(): HandleScope; | ||
| closeScope(_scope?: HandleScope): void; | ||
| getHandleScope(scope: napi_handle_scope): HandleScope | undefined; | ||
| getCallbackInfo(info: napi_callback_info): ICallbackInfo; | ||
| createExternal(data: number | bigint): External_2; | ||
| getExternalValue(external: External_2): number | bigint; | ||
| isExternal(value: unknown): boolean; | ||
| createResolver<T>(): Resolver<T>; | ||
| createPrivate(name: string): Private; | ||
| getOrCreateGlobalPrivate(name: string): Private; | ||
| setPrivate(obj: any, key: Private, value: any): void; | ||
| getPrivate(obj: any, key: Private): any; | ||
| hasPrivate(obj: any, key: Private): boolean; | ||
| deletePrivate(obj: any, key: Private): boolean; | ||
| } | ||
| export declare interface IStoreValue { | ||
| id: number; | ||
| dispose(): void; | ||
| [x: string]: any; | ||
| export declare interface IsolateOptions { | ||
| features?: Partial<Features>; | ||
| onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any; | ||
| } | ||
| export declare function isReferenceType(v: any): v is object; | ||
| export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL; | ||
@@ -545,7 +636,5 @@ | ||
| export declare class NodeEnv extends Env { | ||
| filename: string; | ||
| private readonly nodeBinding?; | ||
| destructing: boolean; | ||
| finalizationScheduled: boolean; | ||
| 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); | ||
| constructor(ctx: Context, store: ArrayStore<Env>, bridge: EnvNativeBridge); | ||
| deleteMe(): void; | ||
@@ -569,11 +658,37 @@ canCallIntoJs(): boolean; | ||
| export declare class Persistent<T> { | ||
| private _ref; | ||
| export declare interface ObjectAllocator<T> extends Disposable_2 { | ||
| deref<R extends T = T>(id: number | bigint): R | undefined; | ||
| alloc<P extends any[]>(factory: (...args: P) => T, ...args: P): T; | ||
| dealloc(id: number | bigint): void; | ||
| } | ||
| export declare class ObjectTemplate extends Template { | ||
| Ctor: any; | ||
| internalFieldCount: number; | ||
| private _accessors; | ||
| constructor(ctx: Isolate, Ctor?: any); | ||
| setAccessor(name: string | symbol, getterWrap: (property: Ptr, info: Ptr, getter: Ptr) => Ptr, setterWrap: (property: Ptr, value: Ptr, info: Ptr, setter: Ptr) => Ptr, getter: Ptr, setter: Ptr, data: any, attribute: number, getterSideEffectType: number, setterSideEffectType: number): void; | ||
| setInternalFieldCount(value: number): void; | ||
| applyToInstance(instance: any): void; | ||
| newInstance(_context: any): any; | ||
| } | ||
| export declare class Persistent<T> extends Disposable_2 { | ||
| private _param; | ||
| private _callback; | ||
| private _isolate; | ||
| id: number; | ||
| private static readonly _registry; | ||
| constructor(value: T); | ||
| constructor(isolate: Isolate, ...args: [T] | []); | ||
| dispose(): void; | ||
| copy(): Persistent<T>; | ||
| move(to: Persistent<T>): void; | ||
| slot(): number; | ||
| getSlot(): PersistentValueType<T>; | ||
| setSlot(ref: PersistentValueType<T>): void; | ||
| deleteSlot(): void; | ||
| setWeak<P>(param: P, callback: (param: P) => void): void; | ||
| clearWeak(): void; | ||
| reset(): void; | ||
| resetTo(value: T): void; | ||
| isEmpty(): boolean; | ||
@@ -583,26 +698,42 @@ deref(): T | undefined; | ||
| export declare class Reference extends RefTracker implements IStoreValue { | ||
| export declare class PersistentStore extends ArrayStore<Persistent<any>> { | ||
| private _recyleList; | ||
| constructor(initialCapacity?: number); | ||
| markUnused(id: number | bigint): void; | ||
| recycle(): void; | ||
| } | ||
| export declare type PersistentValueType<T> = StrongRef<T> | WeakRef<T extends object ? T : never> | undefined; | ||
| export declare class Private { | ||
| private _name; | ||
| constructor(name: string); | ||
| name(): string; | ||
| static forApi(name: string): Private; | ||
| } | ||
| export declare class Reference extends RefTracker { | ||
| private static weakCallback; | ||
| id: number; | ||
| envObject: Env; | ||
| private readonly canBeWeak; | ||
| envObject: Env | undefined; | ||
| private ctx; | ||
| private canBeWeak; | ||
| private _refcount; | ||
| private readonly _ownership; | ||
| persistent: Persistent<object>; | ||
| static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference; | ||
| protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership); | ||
| private _ownership; | ||
| static create(ctx: Context, envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference; | ||
| constructor(ctx: Context, envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership); | ||
| getPersistent(): Persistent<any>; | ||
| ref(): number; | ||
| unref(): number; | ||
| get(envObject?: Env): napi_value; | ||
| /** @virtual */ | ||
| deref(): any; | ||
| get(): napi_value; | ||
| resetFinalizer(): void; | ||
| /** @virtual */ | ||
| data(): void_p; | ||
| refcount(): number; | ||
| ownership(): ReferenceOwnership; | ||
| /** @virtual */ | ||
| protected callUserFinalizer(): void; | ||
| /** @virtual */ | ||
| protected invokeFinalizerFromGC(): void; | ||
| private _setWeak; | ||
| setWeakWithData<T>(data: T, callback: (data: T) => void): void; | ||
| clearWeak(): void; | ||
| finalize(): void; | ||
@@ -618,5 +749,5 @@ dispose(): void; | ||
| export declare class ReferenceWithData extends Reference { | ||
| private readonly _data; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData; | ||
| private constructor(); | ||
| private _data; | ||
| static create(ctx: Context, envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData; | ||
| constructor(ctx: Context, envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p); | ||
| data(): void_p; | ||
@@ -627,4 +758,4 @@ } | ||
| private _finalizer; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer; | ||
| private constructor(); | ||
| static create(ctx: Context, envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer; | ||
| constructor(ctx: Context, envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p); | ||
| resetFinalizer(): void; | ||
@@ -637,9 +768,7 @@ data(): void_p; | ||
| export declare class RefTracker { | ||
| /** @virtual */ | ||
| export declare class RefTracker extends Disposable_2 { | ||
| dispose(): void; | ||
| /** @virtual */ | ||
| finalize(): void; | ||
| private _next; | ||
| private _prev; | ||
| protected _next: RefTracker | null; | ||
| protected _prev: RefTracker | null; | ||
| link(list: RefTracker): void; | ||
@@ -650,25 +779,45 @@ unlink(): void; | ||
| export declare class ScopeStore { | ||
| export declare interface Resolver<T> { | ||
| promise: Promise<T>; | ||
| resolve: (value: T | PromiseLike<T>) => void; | ||
| reject: (reason?: any) => void; | ||
| } | ||
| export declare interface ReusableStoreValue extends Disposable_2 { | ||
| reuse(...args: any[]): void; | ||
| } | ||
| export declare class ScopeStore extends BaseArrayStore<HandleScope> { | ||
| private readonly _rootScope; | ||
| currentScope: HandleScope; | ||
| private readonly _values; | ||
| constructor(); | ||
| get(id: number): HandleScope | undefined; | ||
| openScope(handleStore: HandleStore): HandleScope; | ||
| closeScope(): void; | ||
| dispose(): void; | ||
| isEmpty(): boolean; | ||
| } | ||
| export declare class Store<V extends IStoreValue> { | ||
| protected _values: Array<V | undefined>; | ||
| private _freeList; | ||
| private _size; | ||
| constructor(); | ||
| add(value: V): void; | ||
| get(id: Ptr): V | undefined; | ||
| has(id: Ptr): boolean; | ||
| remove(id: Ptr): void; | ||
| export declare function setInternalField(instance: object, index: number, value: any): void; | ||
| export declare function setPrivate(obj: any, key: Private, value: any): void; | ||
| export declare class Signature { | ||
| receiver: FunctionTemplate | undefined; | ||
| constructor(receiver: FunctionTemplate | undefined); | ||
| } | ||
| export declare class StrongRef<T> extends Disposable_2 { | ||
| private _value; | ||
| constructor(value: T); | ||
| deref(): T; | ||
| dispose(): void; | ||
| } | ||
| export declare class Template { | ||
| protected ctx: Isolate; | ||
| protected _properties: Map<string | symbol, [any, number]>; | ||
| constructor(ctx: Isolate); | ||
| set(name: string | symbol, value: any, attr: number): void; | ||
| protected _addPropertiesToInstance(instance: any): void; | ||
| } | ||
| export declare class TrackedFinalizer extends RefTracker { | ||
@@ -684,7 +833,15 @@ private _finalizer; | ||
| export declare class TryCatch { | ||
| static top: TryCatch | null; | ||
| private static _map; | ||
| id: number | bigint; | ||
| private _exception; | ||
| private _caught; | ||
| private _next; | ||
| constructor(id: number | bigint); | ||
| static deref(id: number | bigint): TryCatch | undefined; | ||
| static pop(): void; | ||
| isEmpty(): boolean; | ||
| hasCaught(): boolean; | ||
| exception(): any; | ||
| rethrow(ctx: Isolate): any; | ||
| setError(err: any): void; | ||
@@ -698,3 +855,1 @@ reset(): void; | ||
| export { } | ||
| export as namespace emnapi; |
+7
-22
| { | ||
| "name": "@emnapi/runtime", | ||
| "version": "1.10.0", | ||
| "version": "2.0.0-alpha.1", | ||
| "description": "emnapi runtime", | ||
| "main": "index.js", | ||
| "module": "./dist/emnapi.esm-bundler.js", | ||
| "type": "module", | ||
| "main": "./dist/emnapi.js", | ||
| "module": "./dist/emnapi.js", | ||
| "types": "./dist/emnapi.d.ts", | ||
| "sideEffects": false, | ||
| "exports": { | ||
| ".": { | ||
| "types": { | ||
| "module": "./dist/emnapi.d.ts", | ||
| "import": "./dist/emnapi.d.mts", | ||
| "default": "./dist/emnapi.d.ts" | ||
| }, | ||
| "module": "./dist/emnapi.esm-bundler.js", | ||
| "import": "./dist/emnapi.mjs", | ||
| "default": "./index.js" | ||
| }, | ||
| "./dist/emnapi.cjs.min": { | ||
| "types": "./dist/emnapi.d.ts", | ||
| "default": "./dist/emnapi.cjs.min.js" | ||
| }, | ||
| "./dist/emnapi.min.mjs": { | ||
| "types": "./dist/emnapi.d.mts", | ||
| "default": "./dist/emnapi.min.mjs" | ||
| } | ||
| ".": "./dist/emnapi.js", | ||
| "./package.json": "./package.json" | ||
| }, | ||
@@ -33,3 +18,3 @@ "dependencies": { | ||
| "scripts": { | ||
| "build": "node ./script/build.js" | ||
| "build": "rollup -c" | ||
| }, | ||
@@ -36,0 +21,0 @@ "repository": { |
-1381
| const externalValue = new WeakMap(); | ||
| function isExternal(object) { | ||
| return externalValue.has(object); | ||
| } | ||
| const External = (() => { | ||
| function External(value) { | ||
| Object.setPrototypeOf(this, null); | ||
| externalValue.set(this, value); | ||
| } | ||
| External.prototype = null; | ||
| return External; | ||
| })(); | ||
| function getExternalValue(external) { | ||
| if (!isExternal(external)) { | ||
| throw new TypeError('not external'); | ||
| } | ||
| return externalValue.get(external); | ||
| } | ||
| const supportNewFunction = (function () { | ||
| let f; | ||
| try { | ||
| f = new Function(); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| return typeof f === 'function'; | ||
| })(); | ||
| const _global = (function () { | ||
| if (typeof globalThis !== 'undefined') | ||
| return globalThis; | ||
| let g = (function () { return this; })(); | ||
| if (!g && supportNewFunction) { | ||
| try { | ||
| g = new Function('return this')(); | ||
| } | ||
| catch (_) { } | ||
| } | ||
| if (!g) { | ||
| if (typeof __webpack_public_path__ === 'undefined') { | ||
| if (typeof global !== 'undefined') | ||
| return global; | ||
| } | ||
| if (typeof window !== 'undefined') | ||
| return window; | ||
| if (typeof self !== 'undefined') | ||
| return self; | ||
| } | ||
| return g; | ||
| })(); | ||
| class TryCatch { | ||
| constructor() { | ||
| this._exception = undefined; | ||
| this._caught = false; | ||
| } | ||
| isEmpty() { | ||
| return !this._caught; | ||
| } | ||
| hasCaught() { | ||
| return this._caught; | ||
| } | ||
| exception() { | ||
| return this._exception; | ||
| } | ||
| setError(err) { | ||
| this._caught = true; | ||
| this._exception = err; | ||
| } | ||
| reset() { | ||
| this._caught = false; | ||
| this._exception = undefined; | ||
| } | ||
| extractException() { | ||
| const e = this._exception; | ||
| this.reset(); | ||
| return e; | ||
| } | ||
| } | ||
| const canSetFunctionName = (function () { | ||
| var _a; | ||
| try { | ||
| return Boolean((_a = Object.getOwnPropertyDescriptor(Function.prototype, 'name')) === null || _a === void 0 ? void 0 : _a.configurable); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| })(); | ||
| const supportReflect = typeof Reflect === 'object'; | ||
| const supportFinalizer = (typeof FinalizationRegistry !== 'undefined') && (typeof WeakRef !== 'undefined'); | ||
| const supportWeakSymbol = (function () { | ||
| try { | ||
| const sym = Symbol(); | ||
| new WeakRef(sym); | ||
| new WeakMap().set(sym, undefined); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| return true; | ||
| })(); | ||
| const supportBigInt = typeof BigInt !== 'undefined'; | ||
| function isReferenceType(v) { | ||
| return (typeof v === 'object' && v !== null) || typeof v === 'function'; | ||
| } | ||
| const _require = (function () { | ||
| let nativeRequire; | ||
| if (typeof __webpack_public_path__ !== 'undefined') { | ||
| nativeRequire = (function () { | ||
| return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined; | ||
| })(); | ||
| } | ||
| else { | ||
| nativeRequire = (function () { | ||
| return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined); | ||
| })(); | ||
| } | ||
| return nativeRequire; | ||
| })(); | ||
| const _MessageChannel = typeof MessageChannel === 'function' | ||
| ? MessageChannel | ||
| : (function () { | ||
| try { | ||
| return _require('worker_threads').MessageChannel; | ||
| } | ||
| catch (_) { } | ||
| return undefined; | ||
| })(); | ||
| const _setImmediate = typeof setImmediate === 'function' | ||
| ? setImmediate | ||
| : function (callback) { | ||
| if (typeof callback !== 'function') { | ||
| throw new TypeError('The "callback" argument must be of type function'); | ||
| } | ||
| if (_MessageChannel) { | ||
| let channel = new _MessageChannel(); | ||
| channel.port1.onmessage = function () { | ||
| channel.port1.onmessage = null; | ||
| channel = undefined; | ||
| callback(); | ||
| }; | ||
| channel.port2.postMessage(null); | ||
| } | ||
| else { | ||
| setTimeout(callback, 0); | ||
| } | ||
| }; | ||
| const _Buffer = typeof Buffer === 'function' | ||
| ? Buffer | ||
| : (function () { | ||
| try { | ||
| return _require('buffer').Buffer; | ||
| } | ||
| catch (_) { } | ||
| return undefined; | ||
| })(); | ||
| const version = "1.10.0"; | ||
| const NODE_API_SUPPORTED_VERSION_MIN = 1; | ||
| const NODE_API_SUPPORTED_VERSION_MAX = 10; | ||
| const NAPI_VERSION_EXPERIMENTAL = 2147483647; | ||
| const NODE_API_DEFAULT_MODULE_API_VERSION = 8; | ||
| class Handle { | ||
| constructor(id, value) { | ||
| this.id = id; | ||
| this.value = value; | ||
| } | ||
| data() { | ||
| return getExternalValue(this.value); | ||
| } | ||
| isNumber() { | ||
| return typeof this.value === 'number'; | ||
| } | ||
| isBigInt() { | ||
| return typeof this.value === 'bigint'; | ||
| } | ||
| isString() { | ||
| return typeof this.value === 'string'; | ||
| } | ||
| isFunction() { | ||
| return typeof this.value === 'function'; | ||
| } | ||
| isExternal() { | ||
| return isExternal(this.value); | ||
| } | ||
| isObject() { | ||
| return typeof this.value === 'object' && this.value !== null; | ||
| } | ||
| isArray() { | ||
| return Array.isArray(this.value); | ||
| } | ||
| isArrayBuffer() { | ||
| return (this.value instanceof ArrayBuffer); | ||
| } | ||
| isTypedArray() { | ||
| return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView); | ||
| } | ||
| isBuffer(BufferConstructor) { | ||
| if (ArrayBuffer.isView(this.value)) | ||
| return true; | ||
| BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer); | ||
| return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value); | ||
| } | ||
| isDataView() { | ||
| return (this.value instanceof DataView); | ||
| } | ||
| isDate() { | ||
| return (this.value instanceof Date); | ||
| } | ||
| isPromise() { | ||
| return (this.value instanceof Promise); | ||
| } | ||
| isBoolean() { | ||
| return typeof this.value === 'boolean'; | ||
| } | ||
| isUndefined() { | ||
| return this.value === undefined; | ||
| } | ||
| isSymbol() { | ||
| return typeof this.value === 'symbol'; | ||
| } | ||
| isNull() { | ||
| return this.value === null; | ||
| } | ||
| dispose() { | ||
| this.value = undefined; | ||
| } | ||
| } | ||
| class ConstHandle extends Handle { | ||
| constructor(id, value) { | ||
| super(id, value); | ||
| } | ||
| dispose() { } | ||
| } | ||
| class HandleStore { | ||
| constructor() { | ||
| this._values = [ | ||
| undefined, | ||
| HandleStore.UNDEFINED, | ||
| HandleStore.NULL, | ||
| HandleStore.FALSE, | ||
| HandleStore.TRUE, | ||
| HandleStore.GLOBAL | ||
| ]; | ||
| this._next = HandleStore.MIN_ID; | ||
| } | ||
| push(value) { | ||
| let h; | ||
| const next = this._next; | ||
| const values = this._values; | ||
| if (next < values.length) { | ||
| h = values[next]; | ||
| h.value = value; | ||
| } | ||
| else { | ||
| h = new Handle(next, value); | ||
| values[next] = h; | ||
| } | ||
| this._next++; | ||
| return h; | ||
| } | ||
| erase(start, end) { | ||
| this._next = start; | ||
| const values = this._values; | ||
| for (let i = start; i < end; ++i) { | ||
| values[i].dispose(); | ||
| } | ||
| } | ||
| get(id) { | ||
| return this._values[id]; | ||
| } | ||
| swap(a, b) { | ||
| const values = this._values; | ||
| const h = values[a]; | ||
| values[a] = values[b]; | ||
| values[a].id = Number(a); | ||
| values[b] = h; | ||
| h.id = Number(b); | ||
| } | ||
| dispose() { | ||
| this._values.length = HandleStore.MIN_ID; | ||
| this._next = HandleStore.MIN_ID; | ||
| } | ||
| } | ||
| HandleStore.UNDEFINED = new ConstHandle(1, undefined); | ||
| HandleStore.NULL = new ConstHandle(2, null); | ||
| HandleStore.FALSE = new ConstHandle(3, false); | ||
| HandleStore.TRUE = new ConstHandle(4, true); | ||
| HandleStore.GLOBAL = new ConstHandle(5, _global); | ||
| HandleStore.MIN_ID = 6; | ||
| class HandleScope { | ||
| constructor(handleStore, id, parentScope, start, end = start) { | ||
| this.handleStore = handleStore; | ||
| this.id = id; | ||
| this.parent = parentScope; | ||
| this.child = null; | ||
| if (parentScope !== null) | ||
| parentScope.child = this; | ||
| this.start = start; | ||
| this.end = end; | ||
| this._escapeCalled = false; | ||
| this.callbackInfo = { | ||
| thiz: undefined, | ||
| data: 0, | ||
| args: undefined, | ||
| fn: undefined | ||
| }; | ||
| } | ||
| add(value) { | ||
| const h = this.handleStore.push(value); | ||
| this.end++; | ||
| return h; | ||
| } | ||
| addExternal(data) { | ||
| return this.add(new External(data)); | ||
| } | ||
| dispose() { | ||
| if (this._escapeCalled) | ||
| this._escapeCalled = false; | ||
| if (this.start === this.end) | ||
| return; | ||
| this.handleStore.erase(this.start, this.end); | ||
| } | ||
| escape(handle) { | ||
| if (this._escapeCalled) | ||
| return null; | ||
| this._escapeCalled = true; | ||
| if (handle < this.start || handle >= this.end) { | ||
| return null; | ||
| } | ||
| this.handleStore.swap(handle, this.start); | ||
| const h = this.handleStore.get(this.start); | ||
| this.start++; | ||
| this.parent.end++; | ||
| return h; | ||
| } | ||
| escapeCalled() { | ||
| return this._escapeCalled; | ||
| } | ||
| } | ||
| class ScopeStore { | ||
| constructor() { | ||
| this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID); | ||
| this.currentScope = this._rootScope; | ||
| this._values = [undefined]; | ||
| } | ||
| get(id) { | ||
| return this._values[id]; | ||
| } | ||
| openScope(handleStore) { | ||
| const currentScope = this.currentScope; | ||
| let scope = currentScope.child; | ||
| if (scope !== null) { | ||
| scope.start = scope.end = currentScope.end; | ||
| } | ||
| else { | ||
| const id = currentScope.id + 1; | ||
| scope = new HandleScope(handleStore, id, currentScope, currentScope.end); | ||
| this._values[id] = scope; | ||
| } | ||
| this.currentScope = scope; | ||
| return scope; | ||
| } | ||
| closeScope() { | ||
| const scope = this.currentScope; | ||
| this.currentScope = scope.parent; | ||
| scope.dispose(); | ||
| } | ||
| dispose() { | ||
| this.currentScope = this._rootScope; | ||
| this._values.length = 1; | ||
| } | ||
| } | ||
| class RefTracker { | ||
| constructor() { | ||
| this._next = null; | ||
| this._prev = null; | ||
| } | ||
| dispose() { } | ||
| finalize() { } | ||
| link(list) { | ||
| this._prev = list; | ||
| this._next = list._next; | ||
| if (this._next !== null) { | ||
| this._next._prev = this; | ||
| } | ||
| list._next = this; | ||
| } | ||
| unlink() { | ||
| if (this._prev !== null) { | ||
| this._prev._next = this._next; | ||
| } | ||
| if (this._next !== null) { | ||
| this._next._prev = this._prev; | ||
| } | ||
| this._prev = null; | ||
| this._next = null; | ||
| } | ||
| static finalizeAll(list) { | ||
| while (list._next !== null) { | ||
| list._next.finalize(); | ||
| } | ||
| } | ||
| } | ||
| class Finalizer { | ||
| constructor(envObject, _finalizeCallback = 0, _finalizeData = 0, _finalizeHint = 0) { | ||
| this.envObject = envObject; | ||
| this._finalizeCallback = _finalizeCallback; | ||
| this._finalizeData = _finalizeData; | ||
| this._finalizeHint = _finalizeHint; | ||
| this._makeDynCall_vppp = envObject.makeDynCall_vppp; | ||
| } | ||
| callback() { return this._finalizeCallback; } | ||
| data() { return this._finalizeData; } | ||
| hint() { return this._finalizeHint; } | ||
| resetEnv() { | ||
| this.envObject = undefined; | ||
| } | ||
| resetFinalizer() { | ||
| this._finalizeCallback = 0; | ||
| this._finalizeData = 0; | ||
| this._finalizeHint = 0; | ||
| } | ||
| callFinalizer() { | ||
| const finalize_callback = this._finalizeCallback; | ||
| const finalize_data = this._finalizeData; | ||
| const finalize_hint = this._finalizeHint; | ||
| this.resetFinalizer(); | ||
| if (!finalize_callback) | ||
| return; | ||
| const fini = Number(finalize_callback); | ||
| if (!this.envObject) { | ||
| this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint); | ||
| } | ||
| else { | ||
| this.envObject.callFinalizer(fini, finalize_data, finalize_hint); | ||
| } | ||
| } | ||
| dispose() { | ||
| this.envObject = undefined; | ||
| this._makeDynCall_vppp = undefined; | ||
| } | ||
| } | ||
| class TrackedFinalizer extends RefTracker { | ||
| static create(envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| const finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| finalizer.link(envObject.finalizing_reflist); | ||
| return finalizer; | ||
| } | ||
| constructor(envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| super(); | ||
| this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| } | ||
| data() { | ||
| return this._finalizer.data(); | ||
| } | ||
| dispose() { | ||
| if (!this._finalizer) | ||
| return; | ||
| this.unlink(); | ||
| this._finalizer.envObject.dequeueFinalizer(this); | ||
| this._finalizer.dispose(); | ||
| this._finalizer = undefined; | ||
| super.dispose(); | ||
| } | ||
| finalize() { | ||
| this.unlink(); | ||
| let error; | ||
| let caught = false; | ||
| try { | ||
| this._finalizer.callFinalizer(); | ||
| } | ||
| catch (err) { | ||
| caught = true; | ||
| error = err; | ||
| } | ||
| this.dispose(); | ||
| if (caught) { | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
| function throwNodeApiVersionError(moduleName, moduleApiVersion) { | ||
| const errorMessage = `${moduleName} requires Node-API version ${moduleApiVersion}, but this version of Node.js only supports version ${NODE_API_SUPPORTED_VERSION_MAX} add-ons.`; | ||
| throw new Error(errorMessage); | ||
| } | ||
| function handleThrow(envObject, value) { | ||
| if (envObject.terminatedOrTerminating()) { | ||
| return; | ||
| } | ||
| throw value; | ||
| } | ||
| class Env { | ||
| constructor(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) { | ||
| this.ctx = ctx; | ||
| this.moduleApiVersion = moduleApiVersion; | ||
| this.makeDynCall_vppp = makeDynCall_vppp; | ||
| this.makeDynCall_vp = makeDynCall_vp; | ||
| this.abort = abort; | ||
| this.openHandleScopes = 0; | ||
| this.instanceData = null; | ||
| this.tryCatch = new TryCatch(); | ||
| this.refs = 1; | ||
| this.reflist = new RefTracker(); | ||
| this.finalizing_reflist = new RefTracker(); | ||
| this.pendingFinalizers = []; | ||
| this.lastError = { | ||
| errorCode: 0, | ||
| engineErrorCode: 0, | ||
| engineReserved: 0 | ||
| }; | ||
| this.inGcFinalizer = false; | ||
| this._bindingMap = new WeakMap(); | ||
| this.id = 0; | ||
| } | ||
| canCallIntoJs() { | ||
| return true; | ||
| } | ||
| terminatedOrTerminating() { | ||
| return !this.canCallIntoJs(); | ||
| } | ||
| ref() { | ||
| this.refs++; | ||
| } | ||
| unref() { | ||
| this.refs--; | ||
| if (this.refs === 0) { | ||
| this.dispose(); | ||
| } | ||
| } | ||
| ensureHandle(value) { | ||
| return this.ctx.ensureHandle(value); | ||
| } | ||
| ensureHandleId(value) { | ||
| return this.ensureHandle(value).id; | ||
| } | ||
| clearLastError() { | ||
| const lastError = this.lastError; | ||
| if (lastError.errorCode !== 0) | ||
| lastError.errorCode = 0; | ||
| if (lastError.engineErrorCode !== 0) | ||
| lastError.engineErrorCode = 0; | ||
| if (lastError.engineReserved !== 0) | ||
| lastError.engineReserved = 0; | ||
| return 0; | ||
| } | ||
| setLastError(error_code, engine_error_code = 0, engine_reserved = 0) { | ||
| const lastError = this.lastError; | ||
| if (lastError.errorCode !== error_code) | ||
| lastError.errorCode = error_code; | ||
| if (lastError.engineErrorCode !== engine_error_code) | ||
| lastError.engineErrorCode = engine_error_code; | ||
| if (lastError.engineReserved !== engine_reserved) | ||
| lastError.engineReserved = engine_reserved; | ||
| return error_code; | ||
| } | ||
| getReturnStatus() { | ||
| return !this.tryCatch.hasCaught() ? 0 : this.setLastError(10); | ||
| } | ||
| callIntoModule(fn, handleException = handleThrow) { | ||
| const openHandleScopesBefore = this.openHandleScopes; | ||
| this.clearLastError(); | ||
| const r = fn(this); | ||
| if (openHandleScopesBefore !== this.openHandleScopes) { | ||
| this.abort('open_handle_scopes != open_handle_scopes_before'); | ||
| } | ||
| if (this.tryCatch.hasCaught()) { | ||
| const err = this.tryCatch.extractException(); | ||
| handleException(this, err); | ||
| } | ||
| return r; | ||
| } | ||
| invokeFinalizerFromGC(finalizer) { | ||
| if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) { | ||
| this.enqueueFinalizer(finalizer); | ||
| } | ||
| else { | ||
| const saved = this.inGcFinalizer; | ||
| this.inGcFinalizer = true; | ||
| try { | ||
| finalizer.finalize(); | ||
| } | ||
| finally { | ||
| this.inGcFinalizer = saved; | ||
| } | ||
| } | ||
| } | ||
| checkGCAccess() { | ||
| if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) { | ||
| this.abort('Finalizer is calling a function that may affect GC state.\n' + | ||
| 'The finalizers are run directly from GC and must not affect GC ' + | ||
| 'state.\n' + | ||
| 'Use `node_api_post_finalizer` from inside of the finalizer to work ' + | ||
| 'around this issue.\n' + | ||
| 'It schedules the call as a new task in the event loop.'); | ||
| } | ||
| } | ||
| enqueueFinalizer(finalizer) { | ||
| if (this.pendingFinalizers.indexOf(finalizer) === -1) { | ||
| this.pendingFinalizers.push(finalizer); | ||
| } | ||
| } | ||
| dequeueFinalizer(finalizer) { | ||
| const index = this.pendingFinalizers.indexOf(finalizer); | ||
| if (index !== -1) { | ||
| this.pendingFinalizers.splice(index, 1); | ||
| } | ||
| } | ||
| deleteMe() { | ||
| RefTracker.finalizeAll(this.finalizing_reflist); | ||
| RefTracker.finalizeAll(this.reflist); | ||
| this.tryCatch.extractException(); | ||
| this.ctx.envStore.remove(this.id); | ||
| } | ||
| dispose() { | ||
| if (this.id === 0) | ||
| return; | ||
| this.deleteMe(); | ||
| this.finalizing_reflist.dispose(); | ||
| this.reflist.dispose(); | ||
| this.id = 0; | ||
| } | ||
| initObjectBinding(value) { | ||
| const binding = { | ||
| wrapped: 0, | ||
| tag: null | ||
| }; | ||
| this._bindingMap.set(value, binding); | ||
| return binding; | ||
| } | ||
| getObjectBinding(value) { | ||
| if (this._bindingMap.has(value)) { | ||
| return this._bindingMap.get(value); | ||
| } | ||
| return this.initObjectBinding(value); | ||
| } | ||
| setInstanceData(data, finalize_cb, finalize_hint) { | ||
| if (this.instanceData) { | ||
| this.instanceData.dispose(); | ||
| } | ||
| this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint); | ||
| } | ||
| getInstanceData() { | ||
| return this.instanceData ? this.instanceData.data() : 0; | ||
| } | ||
| } | ||
| class NodeEnv extends Env { | ||
| constructor(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| super(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort); | ||
| this.filename = filename; | ||
| this.nodeBinding = nodeBinding; | ||
| this.destructing = false; | ||
| this.finalizationScheduled = false; | ||
| } | ||
| deleteMe() { | ||
| this.destructing = true; | ||
| this.drainFinalizerQueue(); | ||
| super.deleteMe(); | ||
| } | ||
| canCallIntoJs() { | ||
| return super.canCallIntoJs() && this.ctx.canCallIntoJs(); | ||
| } | ||
| triggerFatalException(err) { | ||
| if (this.nodeBinding) { | ||
| this.nodeBinding.napi.fatalException(err); | ||
| } | ||
| else { | ||
| if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') { | ||
| const handled = process._fatalException(err); | ||
| if (!handled) { | ||
| console.error(err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| else { | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
| callbackIntoModule(enforceUncaughtExceptionPolicy, fn) { | ||
| return this.callIntoModule(fn, (envObject, err) => { | ||
| if (envObject.terminatedOrTerminating()) { | ||
| return; | ||
| } | ||
| const hasProcess = typeof process === 'object' && process !== null; | ||
| const hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false; | ||
| if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) { | ||
| const warn = hasProcess && typeof process.emitWarning === 'function' | ||
| ? process.emitWarning | ||
| : function (warning, type, code) { | ||
| if (warning instanceof Error) { | ||
| console.warn(warning.toString()); | ||
| } | ||
| else { | ||
| const prefix = code ? `[${code}] ` : ''; | ||
| console.warn(`${prefix}${type || 'Warning'}: ${warning}`); | ||
| } | ||
| }; | ||
| warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168'); | ||
| return; | ||
| } | ||
| envObject.triggerFatalException(err); | ||
| }); | ||
| } | ||
| callFinalizer(cb, data, hint) { | ||
| this.callFinalizerInternal(1, cb, data, hint); | ||
| } | ||
| callFinalizerInternal(forceUncaught, cb, data, hint) { | ||
| const f = this.makeDynCall_vppp(cb); | ||
| const env = this.id; | ||
| const scope = this.ctx.openScope(this); | ||
| try { | ||
| this.callbackIntoModule(Boolean(forceUncaught), () => { f(env, data, hint); }); | ||
| } | ||
| finally { | ||
| this.ctx.closeScope(this, scope); | ||
| } | ||
| } | ||
| enqueueFinalizer(finalizer) { | ||
| super.enqueueFinalizer(finalizer); | ||
| if (!this.finalizationScheduled && !this.destructing) { | ||
| this.finalizationScheduled = true; | ||
| this.ref(); | ||
| _setImmediate(() => { | ||
| this.finalizationScheduled = false; | ||
| this.unref(); | ||
| this.drainFinalizerQueue(); | ||
| }); | ||
| } | ||
| } | ||
| drainFinalizerQueue() { | ||
| while (this.pendingFinalizers.length > 0) { | ||
| const refTracker = this.pendingFinalizers.shift(); | ||
| refTracker.finalize(); | ||
| } | ||
| } | ||
| } | ||
| function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion; | ||
| if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) { | ||
| moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| } | ||
| else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) { | ||
| throwNodeApiVersionError(filename, moduleApiVersion); | ||
| } | ||
| const env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding); | ||
| ctx.envStore.add(env); | ||
| ctx.addCleanupHook(env, () => { env.unref(); }, 0); | ||
| return env; | ||
| } | ||
| class EmnapiError extends Error { | ||
| constructor(message) { | ||
| super(message); | ||
| const ErrorConstructor = new.target; | ||
| const proto = ErrorConstructor.prototype; | ||
| if (!(this instanceof EmnapiError)) { | ||
| const setPrototypeOf = Object.setPrototypeOf; | ||
| if (typeof setPrototypeOf === 'function') { | ||
| setPrototypeOf.call(Object, this, proto); | ||
| } | ||
| else { | ||
| this.__proto__ = proto; | ||
| } | ||
| if (typeof Error.captureStackTrace === 'function') { | ||
| Error.captureStackTrace(this, ErrorConstructor); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Object.defineProperty(EmnapiError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'EmnapiError' | ||
| }); | ||
| class NotSupportWeakRefError extends EmnapiError { | ||
| constructor(api, message) { | ||
| super(`${api}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${message ? ` ${message}` : ''}`); | ||
| } | ||
| } | ||
| Object.defineProperty(NotSupportWeakRefError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'NotSupportWeakRefError' | ||
| }); | ||
| class NotSupportBufferError extends EmnapiError { | ||
| constructor(api, message) { | ||
| super(`${api}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${message ? ` ${message}` : ''}`); | ||
| } | ||
| } | ||
| Object.defineProperty(NotSupportBufferError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'NotSupportBufferError' | ||
| }); | ||
| class StrongRef { | ||
| constructor(value) { | ||
| this._value = value; | ||
| } | ||
| deref() { | ||
| return this._value; | ||
| } | ||
| dispose() { | ||
| this._value = undefined; | ||
| } | ||
| } | ||
| class Persistent { | ||
| constructor(value) { | ||
| this._ref = new StrongRef(value); | ||
| } | ||
| setWeak(param, callback) { | ||
| if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef) | ||
| return; | ||
| const value = this._ref.deref(); | ||
| try { | ||
| Persistent._registry.register(value, this, this); | ||
| const weakRef = new WeakRef(value); | ||
| this._ref.dispose(); | ||
| this._ref = weakRef; | ||
| this._param = param; | ||
| this._callback = callback; | ||
| } | ||
| catch (err) { | ||
| if (typeof value === 'symbol') ; | ||
| else { | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
| clearWeak() { | ||
| if (!supportFinalizer || this._ref === undefined) | ||
| return; | ||
| if (this._ref instanceof WeakRef) { | ||
| try { | ||
| Persistent._registry.unregister(this); | ||
| } | ||
| catch (_) { } | ||
| this._param = undefined; | ||
| this._callback = undefined; | ||
| const value = this._ref.deref(); | ||
| if (value === undefined) { | ||
| this._ref = value; | ||
| } | ||
| else { | ||
| this._ref = new StrongRef(value); | ||
| } | ||
| } | ||
| } | ||
| reset() { | ||
| if (supportFinalizer) { | ||
| try { | ||
| Persistent._registry.unregister(this); | ||
| } | ||
| catch (_) { } | ||
| } | ||
| this._param = undefined; | ||
| this._callback = undefined; | ||
| if (this._ref instanceof StrongRef) { | ||
| this._ref.dispose(); | ||
| } | ||
| this._ref = undefined; | ||
| } | ||
| isEmpty() { | ||
| return this._ref === undefined; | ||
| } | ||
| deref() { | ||
| if (this._ref === undefined) | ||
| return undefined; | ||
| return this._ref.deref(); | ||
| } | ||
| } | ||
| Persistent._registry = supportFinalizer | ||
| ? new FinalizationRegistry((value) => { | ||
| value._ref = undefined; | ||
| const callback = value._callback; | ||
| const param = value._param; | ||
| value._callback = undefined; | ||
| value._param = undefined; | ||
| if (typeof callback === 'function') { | ||
| callback(param); | ||
| } | ||
| }) | ||
| : undefined; | ||
| exports.ReferenceOwnership = void 0; | ||
| (function (ReferenceOwnership) { | ||
| ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime"; | ||
| ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland"; | ||
| })(exports.ReferenceOwnership || (exports.ReferenceOwnership = {})); | ||
| function canBeHeldWeakly(value) { | ||
| return value.isObject() || value.isFunction() || value.isSymbol(); | ||
| } | ||
| class Reference extends RefTracker { | ||
| static weakCallback(ref) { | ||
| ref.persistent.reset(); | ||
| ref.invokeFinalizerFromGC(); | ||
| } | ||
| static create(envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) { | ||
| const ref = new Reference(envObject, handle_id, initialRefcount, ownership); | ||
| envObject.ctx.refStore.add(ref); | ||
| ref.link(envObject.reflist); | ||
| return ref; | ||
| } | ||
| constructor(envObject, handle_id, initialRefcount, ownership) { | ||
| super(); | ||
| this.envObject = envObject; | ||
| this._refcount = initialRefcount; | ||
| this._ownership = ownership; | ||
| const handle = envObject.ctx.handleStore.get(handle_id); | ||
| this.canBeWeak = canBeHeldWeakly(handle); | ||
| this.persistent = new Persistent(handle.value); | ||
| this.id = 0; | ||
| if (initialRefcount === 0) { | ||
| this._setWeak(); | ||
| } | ||
| } | ||
| ref() { | ||
| if (this.persistent.isEmpty()) { | ||
| return 0; | ||
| } | ||
| if (++this._refcount === 1 && this.canBeWeak) { | ||
| this.persistent.clearWeak(); | ||
| } | ||
| return this._refcount; | ||
| } | ||
| unref() { | ||
| if (this.persistent.isEmpty() || this._refcount === 0) { | ||
| return 0; | ||
| } | ||
| if (--this._refcount === 0) { | ||
| this._setWeak(); | ||
| } | ||
| return this._refcount; | ||
| } | ||
| get(envObject = this.envObject) { | ||
| if (this.persistent.isEmpty()) { | ||
| return 0; | ||
| } | ||
| const obj = this.persistent.deref(); | ||
| const handle = envObject.ensureHandle(obj); | ||
| return handle.id; | ||
| } | ||
| resetFinalizer() { } | ||
| data() { return 0; } | ||
| refcount() { return this._refcount; } | ||
| ownership() { return this._ownership; } | ||
| callUserFinalizer() { } | ||
| invokeFinalizerFromGC() { | ||
| this.finalize(); | ||
| } | ||
| _setWeak() { | ||
| if (this.canBeWeak) { | ||
| this.persistent.setWeak(this, Reference.weakCallback); | ||
| } | ||
| else { | ||
| this.persistent.reset(); | ||
| } | ||
| } | ||
| finalize() { | ||
| this.persistent.reset(); | ||
| const deleteMe = this._ownership === exports.ReferenceOwnership.kRuntime; | ||
| this.unlink(); | ||
| this.callUserFinalizer(); | ||
| if (deleteMe) { | ||
| this.dispose(); | ||
| } | ||
| } | ||
| dispose() { | ||
| if (this.id === 0) | ||
| return; | ||
| this.unlink(); | ||
| this.persistent.reset(); | ||
| this.envObject.ctx.refStore.remove(this.id); | ||
| super.dispose(); | ||
| this.envObject = undefined; | ||
| this.id = 0; | ||
| } | ||
| } | ||
| class ReferenceWithData extends Reference { | ||
| static create(envObject, value, initialRefcount, ownership, data) { | ||
| const reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data); | ||
| envObject.ctx.refStore.add(reference); | ||
| reference.link(envObject.reflist); | ||
| return reference; | ||
| } | ||
| constructor(envObject, value, initialRefcount, ownership, _data) { | ||
| super(envObject, value, initialRefcount, ownership); | ||
| this._data = _data; | ||
| } | ||
| data() { | ||
| return this._data; | ||
| } | ||
| } | ||
| class ReferenceWithFinalizer extends Reference { | ||
| static create(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| const reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint); | ||
| envObject.ctx.refStore.add(reference); | ||
| reference.link(envObject.finalizing_reflist); | ||
| return reference; | ||
| } | ||
| constructor(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| super(envObject, value, initialRefcount, ownership); | ||
| this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| } | ||
| resetFinalizer() { | ||
| this._finalizer.resetFinalizer(); | ||
| } | ||
| data() { | ||
| return this._finalizer.data(); | ||
| } | ||
| callUserFinalizer() { | ||
| this._finalizer.callFinalizer(); | ||
| } | ||
| invokeFinalizerFromGC() { | ||
| this._finalizer.envObject.invokeFinalizerFromGC(this); | ||
| } | ||
| dispose() { | ||
| if (!this._finalizer) | ||
| return; | ||
| this._finalizer.envObject.dequeueFinalizer(this); | ||
| this._finalizer.dispose(); | ||
| super.dispose(); | ||
| this._finalizer = undefined; | ||
| } | ||
| } | ||
| class Deferred { | ||
| static create(ctx, value) { | ||
| const deferred = new Deferred(ctx, value); | ||
| ctx.deferredStore.add(deferred); | ||
| return deferred; | ||
| } | ||
| constructor(ctx, value) { | ||
| this.id = 0; | ||
| this.ctx = ctx; | ||
| this.value = value; | ||
| } | ||
| resolve(value) { | ||
| this.value.resolve(value); | ||
| this.dispose(); | ||
| } | ||
| reject(reason) { | ||
| this.value.reject(reason); | ||
| this.dispose(); | ||
| } | ||
| dispose() { | ||
| this.ctx.deferredStore.remove(this.id); | ||
| this.id = 0; | ||
| this.value = null; | ||
| this.ctx = null; | ||
| } | ||
| } | ||
| class Store { | ||
| constructor() { | ||
| this._values = [undefined]; | ||
| this._values.length = 4; | ||
| this._size = 1; | ||
| this._freeList = []; | ||
| } | ||
| add(value) { | ||
| let id; | ||
| if (this._freeList.length) { | ||
| id = this._freeList.shift(); | ||
| } | ||
| else { | ||
| id = this._size; | ||
| this._size++; | ||
| const capacity = this._values.length; | ||
| if (id >= capacity) { | ||
| this._values.length = capacity + (capacity >> 1) + 16; | ||
| } | ||
| } | ||
| value.id = id; | ||
| this._values[id] = value; | ||
| } | ||
| get(id) { | ||
| return this._values[id]; | ||
| } | ||
| has(id) { | ||
| return this._values[id] !== undefined; | ||
| } | ||
| remove(id) { | ||
| const value = this._values[id]; | ||
| if (value) { | ||
| value.id = 0; | ||
| this._values[id] = undefined; | ||
| this._freeList.push(Number(id)); | ||
| } | ||
| } | ||
| dispose() { | ||
| for (let i = 1; i < this._size; ++i) { | ||
| const value = this._values[i]; | ||
| value === null || value === void 0 ? void 0 : value.dispose(); | ||
| } | ||
| this._values = [undefined]; | ||
| this._size = 1; | ||
| this._freeList = []; | ||
| } | ||
| } | ||
| const kMaxReasonableBytes = BigInt(1) << BigInt(60); | ||
| const kMinReasonableBytes = -kMaxReasonableBytes; | ||
| class ExternalMemory { | ||
| constructor(onChange) { | ||
| this.total = BigInt(0); | ||
| this.onChange = onChange !== null && onChange !== void 0 ? onChange : null; | ||
| } | ||
| adjust(changeInBytes) { | ||
| changeInBytes = BigInt(changeInBytes); | ||
| if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) { | ||
| throw new RangeError(`changeInBytes ${changeInBytes} is out of reasonable range`); | ||
| } | ||
| const old = this.total; | ||
| this.total += changeInBytes; | ||
| const amount = this.total; | ||
| const onChange = this.onChange; | ||
| if (changeInBytes) { | ||
| onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes); | ||
| } | ||
| return amount; | ||
| } | ||
| } | ||
| class CleanupHookCallback { | ||
| constructor(envObject, fn, arg, order) { | ||
| this.envObject = envObject; | ||
| this.fn = fn; | ||
| this.arg = arg; | ||
| this.order = order; | ||
| } | ||
| } | ||
| class CleanupQueue { | ||
| constructor() { | ||
| this._cleanupHooks = []; | ||
| this._cleanupHookCounter = 0; | ||
| } | ||
| empty() { | ||
| return this._cleanupHooks.length === 0; | ||
| } | ||
| add(envObject, fn, arg) { | ||
| if (this._cleanupHooks.filter((hook) => (hook.envObject === envObject && hook.fn === fn && hook.arg === arg)).length > 0) { | ||
| throw new Error('Can not add same fn and arg twice'); | ||
| } | ||
| this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++)); | ||
| } | ||
| remove(envObject, fn, arg) { | ||
| for (let i = 0; i < this._cleanupHooks.length; ++i) { | ||
| const hook = this._cleanupHooks[i]; | ||
| if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) { | ||
| this._cleanupHooks.splice(i, 1); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| drain() { | ||
| const hooks = this._cleanupHooks.slice(); | ||
| hooks.sort((a, b) => (b.order - a.order)); | ||
| for (let i = 0; i < hooks.length; ++i) { | ||
| const cb = hooks[i]; | ||
| if (typeof cb.fn === 'number') { | ||
| cb.envObject.makeDynCall_vp(cb.fn)(cb.arg); | ||
| } | ||
| else { | ||
| cb.fn(cb.arg); | ||
| } | ||
| this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1); | ||
| } | ||
| } | ||
| dispose() { | ||
| this._cleanupHooks.length = 0; | ||
| this._cleanupHookCounter = 0; | ||
| } | ||
| } | ||
| class NodejsWaitingRequestCounter { | ||
| constructor() { | ||
| this.refHandle = new _MessageChannel().port1; | ||
| this.count = 0; | ||
| } | ||
| increase() { | ||
| if (this.count === 0) { | ||
| if (this.refHandle.ref) { | ||
| this.refHandle.ref(); | ||
| } | ||
| } | ||
| this.count++; | ||
| } | ||
| decrease() { | ||
| if (this.count === 0) | ||
| return; | ||
| if (this.count === 1) { | ||
| if (this.refHandle.unref) { | ||
| this.refHandle.unref(); | ||
| } | ||
| } | ||
| this.count--; | ||
| } | ||
| } | ||
| class Context { | ||
| constructor(options) { | ||
| this._isStopping = false; | ||
| this._canCallIntoJs = true; | ||
| this._suppressDestroy = false; | ||
| this.envStore = new Store(); | ||
| this.scopeStore = new ScopeStore(); | ||
| this.refStore = new Store(); | ||
| this.deferredStore = new Store(); | ||
| this.handleStore = new HandleStore(); | ||
| this.feature = { | ||
| supportReflect, | ||
| supportFinalizer, | ||
| supportWeakSymbol, | ||
| supportBigInt, | ||
| supportNewFunction, | ||
| canSetFunctionName, | ||
| setImmediate: _setImmediate, | ||
| Buffer: _Buffer, | ||
| MessageChannel: _MessageChannel | ||
| }; | ||
| this.cleanupQueue = new CleanupQueue(); | ||
| this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange); | ||
| if (typeof process === 'object' && process !== null && typeof process.once === 'function') { | ||
| this.refCounter = new NodejsWaitingRequestCounter(); | ||
| process.once('beforeExit', () => { | ||
| if (!this._suppressDestroy) { | ||
| this.destroy(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| suppressDestroy() { | ||
| this._suppressDestroy = true; | ||
| } | ||
| getRuntimeVersions() { | ||
| return { | ||
| version, | ||
| NODE_API_SUPPORTED_VERSION_MAX, | ||
| NAPI_VERSION_EXPERIMENTAL, | ||
| NODE_API_DEFAULT_MODULE_API_VERSION | ||
| }; | ||
| } | ||
| createNotSupportWeakRefError(api, message) { | ||
| return new NotSupportWeakRefError(api, message); | ||
| } | ||
| createNotSupportBufferError(api, message) { | ||
| return new NotSupportBufferError(api, message); | ||
| } | ||
| createReference(envObject, handle_id, initialRefcount, ownership) { | ||
| return Reference.create(envObject, handle_id, initialRefcount, ownership); | ||
| } | ||
| createReferenceWithData(envObject, handle_id, initialRefcount, ownership, data) { | ||
| return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data); | ||
| } | ||
| createReferenceWithFinalizer(envObject, handle_id, initialRefcount, ownership, finalize_callback = 0, finalize_data = 0, finalize_hint = 0) { | ||
| return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint); | ||
| } | ||
| createDeferred(value) { | ||
| return Deferred.create(this, value); | ||
| } | ||
| adjustAmountOfExternalAllocatedMemory(changeInBytes) { | ||
| return this._externalMemory.adjust(changeInBytes); | ||
| } | ||
| createEnv(filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding); | ||
| } | ||
| createTrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| } | ||
| getCurrentScope() { | ||
| return this.scopeStore.currentScope; | ||
| } | ||
| addToCurrentScope(value) { | ||
| return this.scopeStore.currentScope.add(value); | ||
| } | ||
| openScope(envObject) { | ||
| const scope = this.scopeStore.openScope(this.handleStore); | ||
| if (envObject) | ||
| envObject.openHandleScopes++; | ||
| return scope; | ||
| } | ||
| closeScope(envObject, _scope) { | ||
| if (envObject && envObject.openHandleScopes === 0) | ||
| return; | ||
| this.scopeStore.closeScope(); | ||
| if (envObject) | ||
| envObject.openHandleScopes--; | ||
| } | ||
| ensureHandle(value) { | ||
| switch (value) { | ||
| case undefined: return HandleStore.UNDEFINED; | ||
| case null: return HandleStore.NULL; | ||
| case true: return HandleStore.TRUE; | ||
| case false: return HandleStore.FALSE; | ||
| case _global: return HandleStore.GLOBAL; | ||
| } | ||
| return this.addToCurrentScope(value); | ||
| } | ||
| addCleanupHook(envObject, fn, arg) { | ||
| this.cleanupQueue.add(envObject, fn, arg); | ||
| } | ||
| removeCleanupHook(envObject, fn, arg) { | ||
| this.cleanupQueue.remove(envObject, fn, arg); | ||
| } | ||
| runCleanup() { | ||
| while (!this.cleanupQueue.empty()) { | ||
| this.cleanupQueue.drain(); | ||
| } | ||
| } | ||
| increaseWaitingRequestCounter() { | ||
| var _a; | ||
| (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase(); | ||
| } | ||
| decreaseWaitingRequestCounter() { | ||
| var _a; | ||
| (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease(); | ||
| } | ||
| setCanCallIntoJs(value) { | ||
| this._canCallIntoJs = value; | ||
| } | ||
| setStopping(value) { | ||
| this._isStopping = value; | ||
| } | ||
| canCallIntoJs() { | ||
| return this._canCallIntoJs && !this._isStopping; | ||
| } | ||
| destroy() { | ||
| this.setStopping(true); | ||
| this.setCanCallIntoJs(false); | ||
| this.runCleanup(); | ||
| } | ||
| } | ||
| let defaultContext; | ||
| function createContext(options) { | ||
| return new Context(options); | ||
| } | ||
| function getDefaultContext() { | ||
| if (!defaultContext) { | ||
| defaultContext = createContext(); | ||
| } | ||
| return defaultContext; | ||
| } | ||
| exports.ConstHandle = ConstHandle; | ||
| exports.Context = Context; | ||
| exports.Deferred = Deferred; | ||
| exports.EmnapiError = EmnapiError; | ||
| exports.Env = Env; | ||
| exports.External = External; | ||
| exports.Finalizer = Finalizer; | ||
| exports.Handle = Handle; | ||
| exports.HandleScope = HandleScope; | ||
| exports.HandleStore = HandleStore; | ||
| exports.NAPI_VERSION_EXPERIMENTAL = NAPI_VERSION_EXPERIMENTAL; | ||
| exports.NODE_API_DEFAULT_MODULE_API_VERSION = NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| exports.NODE_API_SUPPORTED_VERSION_MAX = NODE_API_SUPPORTED_VERSION_MAX; | ||
| exports.NODE_API_SUPPORTED_VERSION_MIN = NODE_API_SUPPORTED_VERSION_MIN; | ||
| exports.NodeEnv = NodeEnv; | ||
| exports.NotSupportBufferError = NotSupportBufferError; | ||
| exports.NotSupportWeakRefError = NotSupportWeakRefError; | ||
| exports.Persistent = Persistent; | ||
| exports.RefTracker = RefTracker; | ||
| exports.Reference = Reference; | ||
| exports.ReferenceWithData = ReferenceWithData; | ||
| exports.ReferenceWithFinalizer = ReferenceWithFinalizer; | ||
| exports.ScopeStore = ScopeStore; | ||
| exports.Store = Store; | ||
| exports.TrackedFinalizer = TrackedFinalizer; | ||
| exports.TryCatch = TryCatch; | ||
| exports.createContext = createContext; | ||
| exports.getDefaultContext = getDefaultContext; | ||
| exports.getExternalValue = getExternalValue; | ||
| exports.isExternal = isExternal; | ||
| exports.isReferenceType = isReferenceType; | ||
| exports.version = version; |
| export declare type Ptr = number | bigint | ||
| export declare interface IBuffer extends Uint8Array {} | ||
| export declare interface BufferCtor { | ||
| readonly prototype: IBuffer | ||
| /** @deprecated */ | ||
| new (...args: any[]): IBuffer | ||
| from: { | ||
| (buffer: ArrayBufferLike): IBuffer | ||
| (buffer: ArrayBufferLike, byteOffset: number, length: number): IBuffer | ||
| } | ||
| alloc: (size: number) => IBuffer | ||
| isBuffer: (obj: unknown) => obj is IBuffer | ||
| } | ||
| export declare const enum GlobalHandle { | ||
| UNDEFINED = 1, | ||
| NULL, | ||
| FALSE, | ||
| TRUE, | ||
| GLOBAL | ||
| } | ||
| export declare const enum Version { | ||
| NODE_API_SUPPORTED_VERSION_MIN = 1, | ||
| NODE_API_DEFAULT_MODULE_API_VERSION = 8, | ||
| NODE_API_SUPPORTED_VERSION_MAX = 10, | ||
| NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export declare type Pointer<T> = number | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export declare type PointerPointer<T> = number | ||
| export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T> | ||
| export declare type Const<T> = T | ||
| export declare type void_p = Pointer<void> | ||
| export declare type void_pp = Pointer<void_p> | ||
| export declare type bool = number | ||
| export declare type char = number | ||
| export declare type char_p = Pointer<char> | ||
| export declare type unsigned_char = number | ||
| export declare type const_char = Const<char> | ||
| export declare type const_char_p = Pointer<const_char> | ||
| export declare type char16_t_p = number | ||
| export declare type const_char16_t_p = number | ||
| export declare type short = number | ||
| export declare type unsigned_short = number | ||
| export declare type int = number | ||
| export declare type unsigned_int = number | ||
| export declare type long = number | ||
| export declare type unsigned_long = number | ||
| export declare type long_long = bigint | ||
| export declare type unsigned_long_long = bigint | ||
| export declare type float = number | ||
| export declare type double = number | ||
| export declare type long_double = number | ||
| export declare type size_t = number | ||
| export declare type int8_t = number | ||
| export declare type uint8_t = number | ||
| export declare type int16_t = number | ||
| export declare type uint16_t = number | ||
| export declare type int32_t = number | ||
| export declare type uint32_t = number | ||
| export declare type int64_t = bigint | ||
| export declare type uint64_t = bigint | ||
| export declare type napi_env = Pointer<unknown> | ||
| export declare type napi_value = Pointer<unknown> | ||
| export declare type napi_ref = Pointer<unknown> | ||
| export declare type napi_deferred = Pointer<unknown> | ||
| export declare type napi_handle_scope = Pointer<unknown> | ||
| export declare type napi_escapable_handle_scope = Pointer<unknown> | ||
| export declare type napi_addon_register_func = FunctionPointer<(env: napi_env, exports: napi_value) => napi_value> | ||
| export declare type napi_callback_info = Pointer<unknown> | ||
| export declare type napi_callback = FunctionPointer<(env: napi_env, info: napi_callback_info) => napi_value> | ||
| export declare interface napi_extended_error_info { | ||
| error_message: const_char_p | ||
| engine_reserved: void_p | ||
| engine_error_code: uint32_t | ||
| error_code: napi_status | ||
| } | ||
| export declare interface napi_property_descriptor { | ||
| // One of utf8name or name should be NULL. | ||
| utf8name: const_char_p | ||
| name: napi_value | ||
| method: napi_callback | ||
| getter: napi_callback | ||
| setter: napi_callback | ||
| value: napi_value | ||
| /* napi_property_attributes */ | ||
| attributes: number | ||
| data: void_p | ||
| } | ||
| export declare type napi_finalize = FunctionPointer<( | ||
| env: napi_env, | ||
| finalize_data: void_p, | ||
| finalize_hint: void_p | ||
| ) => void> | ||
| export declare interface node_module { | ||
| nm_version: int32_t | ||
| nm_flags: uint32_t | ||
| nm_filename: Pointer<const_char> | ||
| nm_register_func: napi_addon_register_func | ||
| nm_modname: Pointer<const_char> | ||
| nm_priv: Pointer<void> | ||
| reserved: PointerPointer<void> | ||
| } | ||
| export declare interface napi_node_version { | ||
| major: uint32_t | ||
| minor: uint32_t | ||
| patch: uint32_t | ||
| release: const_char_p | ||
| } | ||
| export declare interface emnapi_emscripten_version { | ||
| major: uint32_t | ||
| minor: uint32_t | ||
| patch: uint32_t | ||
| } | ||
| export declare const enum napi_status { | ||
| napi_ok, | ||
| napi_invalid_arg, | ||
| napi_object_expected, | ||
| napi_string_expected, | ||
| napi_name_expected, | ||
| napi_function_expected, | ||
| napi_number_expected, | ||
| napi_boolean_expected, | ||
| napi_array_expected, | ||
| napi_generic_failure, | ||
| napi_pending_exception, | ||
| napi_cancelled, | ||
| napi_escape_called_twice, | ||
| napi_handle_scope_mismatch, | ||
| napi_callback_scope_mismatch, | ||
| napi_queue_full, | ||
| napi_closing, | ||
| napi_bigint_expected, | ||
| napi_date_expected, | ||
| napi_arraybuffer_expected, | ||
| napi_detachable_arraybuffer_expected, | ||
| napi_would_deadlock, // unused | ||
| napi_no_external_buffers_allowed, | ||
| napi_cannot_run_js | ||
| } | ||
| export declare const enum napi_property_attributes { | ||
| napi_default = 0, | ||
| napi_writable = 1 << 0, | ||
| napi_enumerable = 1 << 1, | ||
| napi_configurable = 1 << 2, | ||
| // Used with napi_define_class to distinguish static properties | ||
| // from instance properties. Ignored by napi_define_properties. | ||
| napi_static = 1 << 10, | ||
| /// #ifdef NAPI_EXPERIMENTAL | ||
| // Default for class methods. | ||
| napi_default_method = napi_writable | napi_configurable, | ||
| // Default for object properties, like in JS obj[prop]. | ||
| napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable | ||
| /// #endif // NAPI_EXPERIMENTAL | ||
| } | ||
| export declare const enum napi_valuetype { | ||
| napi_undefined, | ||
| napi_null, | ||
| napi_boolean, | ||
| napi_number, | ||
| napi_string, | ||
| napi_symbol, | ||
| napi_object, | ||
| napi_function, | ||
| napi_external, | ||
| napi_bigint | ||
| } | ||
| export declare const enum napi_typedarray_type { | ||
| napi_int8_array, | ||
| napi_uint8_array, | ||
| napi_uint8_clamped_array, | ||
| napi_int16_array, | ||
| napi_uint16_array, | ||
| napi_int32_array, | ||
| napi_uint32_array, | ||
| napi_float32_array, | ||
| napi_float64_array, | ||
| napi_bigint64_array, | ||
| napi_biguint64_array, | ||
| napi_float16_array, | ||
| } | ||
| export declare const enum napi_key_collection_mode { | ||
| napi_key_include_prototypes, | ||
| napi_key_own_only | ||
| } | ||
| export declare const enum napi_key_filter { | ||
| napi_key_all_properties = 0, | ||
| napi_key_writable = 1, | ||
| napi_key_enumerable = 1 << 1, | ||
| napi_key_configurable = 1 << 2, | ||
| napi_key_skip_strings = 1 << 3, | ||
| napi_key_skip_symbols = 1 << 4 | ||
| } | ||
| export declare const enum napi_key_conversion { | ||
| napi_key_keep_numbers, | ||
| napi_key_numbers_to_strings | ||
| } | ||
| export declare const enum emnapi_memory_view_type { | ||
| emnapi_int8_array, | ||
| emnapi_uint8_array, | ||
| emnapi_uint8_clamped_array, | ||
| emnapi_int16_array, | ||
| emnapi_uint16_array, | ||
| emnapi_int32_array, | ||
| emnapi_uint32_array, | ||
| emnapi_float32_array, | ||
| emnapi_float64_array, | ||
| emnapi_bigint64_array, | ||
| emnapi_biguint64_array, | ||
| emnapi_float16_array, | ||
| emnapi_data_view = -1, | ||
| emnapi_buffer = -2 | ||
| } | ||
| export declare const enum napi_threadsafe_function_call_mode { | ||
| napi_tsfn_nonblocking, | ||
| napi_tsfn_blocking | ||
| } | ||
| export declare const enum napi_threadsafe_function_release_mode { | ||
| napi_tsfn_release, | ||
| napi_tsfn_abort | ||
| } | ||
| export declare type CleanupHookCallbackFunction = number | ((arg: number) => void); | ||
| export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> { | ||
| constructor(id: number, value: S); | ||
| dispose(): void; | ||
| } | ||
| export declare class Context { | ||
| private _isStopping; | ||
| private _canCallIntoJs; | ||
| private _suppressDestroy; | ||
| envStore: Store<Env>; | ||
| scopeStore: ScopeStore; | ||
| refStore: Store<Reference>; | ||
| deferredStore: Store<Deferred<any>>; | ||
| handleStore: HandleStore; | ||
| private readonly refCounter?; | ||
| private readonly cleanupQueue; | ||
| private readonly _externalMemory; | ||
| feature: { | ||
| supportReflect: boolean; | ||
| supportFinalizer: boolean; | ||
| supportWeakSymbol: boolean; | ||
| supportBigInt: boolean; | ||
| supportNewFunction: boolean; | ||
| canSetFunctionName: boolean; | ||
| setImmediate: (callback: () => void) => void; | ||
| Buffer: BufferCtor | undefined; | ||
| MessageChannel: { | ||
| new (): MessageChannel; | ||
| prototype: MessageChannel; | ||
| } | undefined; | ||
| }; | ||
| constructor(options?: ContextOptions); | ||
| /** | ||
| * Suppress the destroy on `beforeExit` event in Node.js. | ||
| * Call this method if you want to keep the context and | ||
| * all associated {@link Env | Env} alive, | ||
| * this also means that cleanup hooks will not be called. | ||
| * After call this method, you should call | ||
| * {@link Context.destroy | `Context.prototype.destroy`} method manually. | ||
| */ | ||
| suppressDestroy(): void; | ||
| getRuntimeVersions(): { | ||
| version: string; | ||
| NODE_API_SUPPORTED_VERSION_MAX: Version; | ||
| NAPI_VERSION_EXPERIMENTAL: Version; | ||
| NODE_API_DEFAULT_MODULE_API_VERSION: Version; | ||
| }; | ||
| createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError; | ||
| createNotSupportBufferError(api: string, message: string): NotSupportBufferError; | ||
| createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference; | ||
| createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference; | ||
| createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference; | ||
| createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>; | ||
| adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint; | ||
| 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; | ||
| createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer; | ||
| getCurrentScope(): HandleScope | null; | ||
| addToCurrentScope<V>(value: V): Handle<V>; | ||
| openScope(envObject?: Env): HandleScope; | ||
| closeScope(envObject?: Env, _scope?: HandleScope): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
| removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
| runCleanup(): void; | ||
| increaseWaitingRequestCounter(): void; | ||
| decreaseWaitingRequestCounter(): void; | ||
| setCanCallIntoJs(value: boolean): void; | ||
| setStopping(value: boolean): void; | ||
| canCallIntoJs(): boolean; | ||
| /** | ||
| * Destroy the context and call cleanup hooks. | ||
| * Associated {@link Env | Env} will be destroyed. | ||
| */ | ||
| destroy(): void; | ||
| } | ||
| export declare interface ContextOptions { | ||
| onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any; | ||
| } | ||
| export declare function createContext(options?: ContextOptions): Context; | ||
| export declare class Deferred<T = any> implements IStoreValue { | ||
| static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred; | ||
| id: number; | ||
| ctx: Context; | ||
| value: IDeferrdValue<T>; | ||
| constructor(ctx: Context, value: IDeferrdValue<T>); | ||
| resolve(value: T): void; | ||
| reject(reason?: any): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class EmnapiError extends Error { | ||
| constructor(message?: string); | ||
| } | ||
| export declare abstract class Env implements IStoreValue { | ||
| readonly 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; | ||
| id: number; | ||
| openHandleScopes: number; | ||
| instanceData: TrackedFinalizer | null; | ||
| tryCatch: TryCatch; | ||
| refs: number; | ||
| reflist: RefTracker; | ||
| finalizing_reflist: RefTracker; | ||
| pendingFinalizers: RefTracker[]; | ||
| lastError: { | ||
| errorCode: napi_status; | ||
| engineErrorCode: number; | ||
| engineReserved: Ptr; | ||
| }; | ||
| inGcFinalizer: boolean; | ||
| 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); | ||
| /** @virtual */ | ||
| canCallIntoJs(): boolean; | ||
| terminatedOrTerminating(): boolean; | ||
| ref(): void; | ||
| unref(): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| ensureHandleId(value: any): napi_value; | ||
| clearLastError(): napi_status; | ||
| setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status; | ||
| getReturnStatus(): napi_status; | ||
| callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T; | ||
| /** @virtual */ | ||
| abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| invokeFinalizerFromGC(finalizer: RefTracker): void; | ||
| checkGCAccess(): void; | ||
| /** @virtual */ | ||
| enqueueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| dequeueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| deleteMe(): void; | ||
| dispose(): void; | ||
| private readonly _bindingMap; | ||
| initObjectBinding<S extends object>(value: S): IReferenceBinding; | ||
| getObjectBinding<S extends object>(value: S): IReferenceBinding; | ||
| setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void; | ||
| getInstanceData(): number; | ||
| } | ||
| /** @public */ | ||
| declare interface External_2 extends Record<any, any> { | ||
| } | ||
| /** @public */ | ||
| declare const External_2: { | ||
| new (value: number | bigint): External_2; | ||
| prototype: null; | ||
| }; | ||
| export { External_2 as External } | ||
| export declare class Finalizer { | ||
| envObject: Env; | ||
| private _finalizeCallback; | ||
| private _finalizeData; | ||
| private _finalizeHint; | ||
| private _makeDynCall_vppp; | ||
| constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p); | ||
| callback(): napi_finalize; | ||
| data(): void_p; | ||
| hint(): void_p; | ||
| resetEnv(): void; | ||
| resetFinalizer(): void; | ||
| callFinalizer(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare function getDefaultContext(): Context; | ||
| /** @public */ | ||
| export declare function getExternalValue(external: External_2): number | bigint; | ||
| export declare class Handle<S> { | ||
| id: number; | ||
| value: S; | ||
| constructor(id: number, value: S); | ||
| data(): void_p; | ||
| isNumber(): boolean; | ||
| isBigInt(): boolean; | ||
| isString(): boolean; | ||
| isFunction(): boolean; | ||
| isExternal(): boolean; | ||
| isObject(): boolean; | ||
| isArray(): boolean; | ||
| isArrayBuffer(): boolean; | ||
| isTypedArray(): boolean; | ||
| isBuffer(BufferConstructor?: BufferCtor): boolean; | ||
| isDataView(): boolean; | ||
| isDate(): boolean; | ||
| isPromise(): boolean; | ||
| isBoolean(): boolean; | ||
| isUndefined(): boolean; | ||
| isSymbol(): boolean; | ||
| isNull(): boolean; | ||
| dispose(): void; | ||
| } | ||
| export declare class HandleScope { | ||
| handleStore: HandleStore; | ||
| id: number; | ||
| parent: HandleScope | null; | ||
| child: HandleScope | null; | ||
| start: number; | ||
| end: number; | ||
| private _escapeCalled; | ||
| callbackInfo: ICallbackInfo; | ||
| constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number); | ||
| add<V>(value: V): Handle<V>; | ||
| addExternal(data: void_p): Handle<object>; | ||
| dispose(): void; | ||
| escape(handle: number): Handle<any> | null; | ||
| escapeCalled(): boolean; | ||
| } | ||
| export declare class HandleStore { | ||
| static UNDEFINED: ConstHandle<undefined>; | ||
| static NULL: ConstHandle<null>; | ||
| static FALSE: ConstHandle<false>; | ||
| static TRUE: ConstHandle<true>; | ||
| static GLOBAL: ConstHandle<typeof globalThis>; | ||
| static MIN_ID: 6; | ||
| private readonly _values; | ||
| private _next; | ||
| push<S>(value: S): Handle<S>; | ||
| erase(start: number, end: number): void; | ||
| get(id: Ptr): Handle<any> | undefined; | ||
| swap(a: number, b: number): void; | ||
| dispose(): void; | ||
| } | ||
| export declare interface ICallbackInfo { | ||
| thiz: any; | ||
| data: void_p; | ||
| args: ArrayLike<any>; | ||
| fn: Function; | ||
| } | ||
| export declare interface IDeferrdValue<T = any> { | ||
| resolve: (value: T) => void; | ||
| reject: (reason?: any) => void; | ||
| } | ||
| export declare interface IReferenceBinding { | ||
| wrapped: number; | ||
| tag: Uint32Array | null; | ||
| } | ||
| /** @public */ | ||
| export declare function isExternal(object: unknown): object is External_2; | ||
| export declare function isReferenceType(v: any): v is object; | ||
| export declare interface IStoreValue { | ||
| id: number; | ||
| dispose(): void; | ||
| [x: string]: any; | ||
| } | ||
| export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL; | ||
| export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| export declare const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX; | ||
| export declare const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN; | ||
| export declare class NodeEnv extends Env { | ||
| filename: string; | ||
| private readonly nodeBinding?; | ||
| destructing: boolean; | ||
| finalizationScheduled: boolean; | ||
| 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); | ||
| deleteMe(): void; | ||
| canCallIntoJs(): boolean; | ||
| triggerFatalException(err: any): void; | ||
| callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T; | ||
| callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| enqueueFinalizer(finalizer: RefTracker): void; | ||
| drainFinalizerQueue(): void; | ||
| } | ||
| export declare class NotSupportBufferError extends EmnapiError { | ||
| constructor(api: string, message: string); | ||
| } | ||
| export declare class NotSupportWeakRefError extends EmnapiError { | ||
| constructor(api: string, message: string); | ||
| } | ||
| export declare class Persistent<T> { | ||
| private _ref; | ||
| private _param; | ||
| private _callback; | ||
| private static readonly _registry; | ||
| constructor(value: T); | ||
| setWeak<P>(param: P, callback: (param: P) => void): void; | ||
| clearWeak(): void; | ||
| reset(): void; | ||
| isEmpty(): boolean; | ||
| deref(): T | undefined; | ||
| } | ||
| export declare class Reference extends RefTracker implements IStoreValue { | ||
| private static weakCallback; | ||
| id: number; | ||
| envObject: Env; | ||
| private readonly canBeWeak; | ||
| private _refcount; | ||
| private readonly _ownership; | ||
| persistent: Persistent<object>; | ||
| static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference; | ||
| protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership); | ||
| ref(): number; | ||
| unref(): number; | ||
| get(envObject?: Env): napi_value; | ||
| /** @virtual */ | ||
| resetFinalizer(): void; | ||
| /** @virtual */ | ||
| data(): void_p; | ||
| refcount(): number; | ||
| ownership(): ReferenceOwnership; | ||
| /** @virtual */ | ||
| protected callUserFinalizer(): void; | ||
| /** @virtual */ | ||
| protected invokeFinalizerFromGC(): void; | ||
| private _setWeak; | ||
| finalize(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare enum ReferenceOwnership { | ||
| kRuntime = 0, | ||
| kUserland = 1 | ||
| } | ||
| export declare class ReferenceWithData extends Reference { | ||
| private readonly _data; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData; | ||
| private constructor(); | ||
| data(): void_p; | ||
| } | ||
| export declare class ReferenceWithFinalizer extends Reference { | ||
| private _finalizer; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer; | ||
| private constructor(); | ||
| resetFinalizer(): void; | ||
| data(): void_p; | ||
| protected callUserFinalizer(): void; | ||
| protected invokeFinalizerFromGC(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class RefTracker { | ||
| /** @virtual */ | ||
| dispose(): void; | ||
| /** @virtual */ | ||
| finalize(): void; | ||
| private _next; | ||
| private _prev; | ||
| link(list: RefTracker): void; | ||
| unlink(): void; | ||
| static finalizeAll(list: RefTracker): void; | ||
| } | ||
| export declare class ScopeStore { | ||
| private readonly _rootScope; | ||
| currentScope: HandleScope; | ||
| private readonly _values; | ||
| constructor(); | ||
| get(id: number): HandleScope | undefined; | ||
| openScope(handleStore: HandleStore): HandleScope; | ||
| closeScope(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class Store<V extends IStoreValue> { | ||
| protected _values: Array<V | undefined>; | ||
| private _freeList; | ||
| private _size; | ||
| constructor(); | ||
| add(value: V): void; | ||
| get(id: Ptr): V | undefined; | ||
| has(id: Ptr): boolean; | ||
| remove(id: Ptr): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class TrackedFinalizer extends RefTracker { | ||
| private _finalizer; | ||
| static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer; | ||
| private constructor(); | ||
| data(): void_p; | ||
| dispose(): void; | ||
| finalize(): void; | ||
| } | ||
| export declare class TryCatch { | ||
| private _exception; | ||
| private _caught; | ||
| isEmpty(): boolean; | ||
| hasCaught(): boolean; | ||
| exception(): any; | ||
| setError(err: any): void; | ||
| reset(): void; | ||
| extractException(): any; | ||
| } | ||
| export declare const version: string; | ||
| export { } |
| const e=new WeakMap;function t(t){return e.has(t)}const i=(()=>{function t(t){Object.setPrototypeOf(this,null),e.set(this,t)}return t.prototype=null,t})();function s(i){if(!t(i))throw new TypeError("not external");return e.get(i)}const n=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&&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 o{constructor(){this._exception=void 0,this._caught=!1}isEmpty(){return!this._caught}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,h=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),u="undefined"!=typeof BigInt;const p=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 p("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(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)},_="function"==typeof Buffer?Buffer:function(){try{return p("buffer").Buffer}catch(e){}}(),v="1.10.0",g=2147483647;class y{constructor(e,t){this.id=e,this.value=t}data(){return s(this.value)}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 t(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(e){return!!ArrayBuffer.isView(this.value)||(null!=e||(e=_),"function"==typeof e&&e.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(){}}class z{constructor(){this._values=[void 0,z.UNDEFINED,z.NULL,z.FALSE,z.TRUE,z.GLOBAL],this._next=z.MIN_ID}push(e){let t;const i=this._next,s=this._values;return i<s.length?(t=s[i],t.value=e):(t=new y(i,e),s[i]=t),this._next++,t}erase(e,t){this._next=e;const i=this._values;for(let s=e;s<t;++s)i[s].dispose()}get(e){return this._values[e]}swap(e,t){const i=this._values,s=i[e];i[e]=i[t],i[e].id=Number(e),i[t]=s,s.id=Number(t)}dispose(){this._values.length=z.MIN_ID,this._next=z.MIN_ID}}z.UNDEFINED=new x(1,void 0),z.NULL=new x(2,null),z.FALSE=new x(3,!1),z.TRUE=new x(4,!0),z.GLOBAL=new x(5,r),z.MIN_ID=6;class k{constructor(e,t,i,s,n=s){this.handleStore=e,this.id=t,this.parent=i,this.child=null,null!==i&&(i.child=this),this.start=s,this.end=n,this._escapeCalled=!1,this.callbackInfo={thiz:void 0,data:0,args:void 0,fn:void 0}}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e){return this.add(new i(e))}dispose(){this._escapeCalled&&(this._escapeCalled=!1),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 b{constructor(){this._rootScope=new k(null,0,null,1,z.MIN_ID),this.currentScope=this._rootScope,this._values=[void 0]}get(e){return this._values[e]}openScope(e){const t=this.currentScope;let i=t.child;if(null!==i)i.start=i.end=t.end;else{const s=t.id+1;i=new k(e,s,t,t.end),this._values[s]=i}return this.currentScope=i,i}closeScope(){const e=this.currentScope;this.currentScope=e.parent,e.dispose()}dispose(){this.currentScope=this._rootScope,this._values.length=1}}class w{constructor(){this._next=null,this._prev=null}dispose(){}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 m{constructor(e,t=0,i=0,s=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=i,this._finalizeHint=s,this._makeDynCall_vppp=e.makeDynCall_vppp}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetEnv(){this.envObject=void 0}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}callFinalizer(){const e=this._finalizeCallback,t=this._finalizeData,i=this._finalizeHint;if(this.resetFinalizer(),!e)return;const s=Number(e);this.envObject?this.envObject.callFinalizer(s,t,i):this._makeDynCall_vppp(s)(0,t,i)}dispose(){this.envObject=void 0,this._makeDynCall_vppp=void 0}}class E extends w{static create(e,t,i,s){const n=new E(e,t,i,s);return n.link(e.finalizing_reflist),n}constructor(e,t,i,s){super(),this._finalizer=new m(e,t,i,s)}data(){return this._finalizer.data()}dispose(){this._finalizer&&(this.unlink(),this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),this._finalizer=void 0,super.dispose())}finalize(){let e;this.unlink();let t=!1;try{this._finalizer.callFinalizer()}catch(i){t=!0,e=i}if(this.dispose(),t)throw e}}function S(e,t){if(!e.terminatedOrTerminating())throw t}class C{constructor(e,t,i,s,n){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=i,this.makeDynCall_vp=s,this.abort=n,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new o,this.refs=1,this.reflist=new w,this.finalizing_reflist=new w,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,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,i=0){const s=this.lastError;return s.errorCode!==e&&(s.errorCode=e),s.engineErrorCode!==t&&(s.engineErrorCode=t),s.engineReserved!==i&&(s.engineReserved=i),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=S){const i=this.openHandleScopes;this.clearLastError();const s=e(this);if(i!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return s}invokeFinalizerFromGC(e){if(this.moduleApiVersion!==g)this.enqueueFinalizer(e);else{const t=this.inGcFinalizer;this.inGcFinalizer=!0;try{e.finalize()}finally{this.inGcFinalizer=t}}}checkGCAccess(){this.moduleApiVersion===g&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")}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(){w.finalizeAll(this.finalizing_reflist),w.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),this.finalizing_reflist.dispose(),this.reflist.dispose(),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,i){this.instanceData&&this.instanceData.dispose(),this.instanceData=E.create(this,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class F extends C{constructor(e,t,i,s,n,r,o){super(e,i,s,n,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return super.canCallIntoJs()&&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,i)=>{if(t.terminatedOrTerminating())return;const s="object"==typeof process&&null!==process,n=!!s&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(t.moduleApiVersion<10&&!n&&!e){return void(s&&"function"==typeof process.emitWarning?process.emitWarning:function(e,t,i){if(e instanceof Error)console.warn(e.toString());else{const s=i?`[${i}] `:"";console.warn(`${s}${t||"Warning"}: ${e}`)}})("Uncaught Node-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(i)})}callFinalizer(e,t,i){this.callFinalizerInternal(1,e,t,i)}callFinalizerInternal(e,t,i,s){const n=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),()=>{n(r,i,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 I(e,t,i,s,n,r,o){(i="number"!=typeof i?8:i)<8?i=8:i>10&&i!==g&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version 10 add-ons.`)}(t,i);const a=new F(e,t,i,s,n,r,o);return e.envStore.add(a),e.addCleanupHook(a,()=>{a.unref()},0),a}class O extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof O)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,i):this.__proto__=i,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(O.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class D extends O{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(D.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class R extends O{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(R.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class N{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class A{constructor(e){this._ref=new N(e)}setWeak(e,t){if(!c||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{A._registry.register(i,this,this);const s=new WeakRef(i);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof i)throw e}}clearWeak(){if(c&&void 0!==this._ref&&this._ref instanceof WeakRef){try{A._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 N(e)}}reset(){if(c)try{A._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof N&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}var H;A._registry=c?new FinalizationRegistry(e=>{e._ref=void 0;const t=e._callback,i=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(i)}):void 0,exports.ReferenceOwnership=void 0,(H=exports.ReferenceOwnership||(exports.ReferenceOwnership={}))[H.kRuntime=0]="kRuntime",H[H.kUserland=1]="kUserland";class j extends w{static weakCallback(e){e.persistent.reset(),e.invokeFinalizerFromGC()}static create(e,t,i,s,n,r,o){const a=new j(e,t,i,s);return e.ctx.refStore.add(a),a.link(e.reflist),a}constructor(e,t,i,s){super(),this.envObject=e,this._refcount=i,this._ownership=s;const n=e.ctx.handleStore.get(t);var r;this.canBeWeak=(r=n).isObject()||r.isFunction()||r.isSymbol(),this.persistent=new A(n.value),this.id=0,0===i&&this._setWeak()}ref(){return this.persistent.isEmpty()?0:(1===++this._refcount&&this.canBeWeak&&this.persistent.clearWeak(),this._refcount)}unref(){return this.persistent.isEmpty()||0===this._refcount?0:(0===--this._refcount&&this._setWeak(),this._refcount)}get(e=this.envObject){if(this.persistent.isEmpty())return 0;const t=this.persistent.deref();return e.ensureHandle(t).id}resetFinalizer(){}data(){return 0}refcount(){return this._refcount}ownership(){return this._ownership}callUserFinalizer(){}invokeFinalizerFromGC(){this.finalize()}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,j.weakCallback):this.persistent.reset()}finalize(){this.persistent.reset();const e=this._ownership===exports.ReferenceOwnership.kRuntime;this.unlink(),this.callUserFinalizer(),e&&this.dispose()}dispose(){0!==this.id&&(this.unlink(),this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.envObject=void 0,this.id=0)}}class B extends j{static create(e,t,i,s,n){const r=new B(e,t,i,s,n);return e.ctx.refStore.add(r),r.link(e.reflist),r}constructor(e,t,i,s,n){super(e,t,i,s),this._data=n}data(){return this._data}}class M extends j{static create(e,t,i,s,n,r,o){const a=new M(e,t,i,s,n,r,o);return e.ctx.refStore.add(a),a.link(e.finalizing_reflist),a}constructor(e,t,i,s,n,r,o){super(e,t,i,s),this._finalizer=new m(e,n,r,o)}resetFinalizer(){this._finalizer.resetFinalizer()}data(){return this._finalizer.data()}callUserFinalizer(){this._finalizer.callFinalizer()}invokeFinalizerFromGC(){this._finalizer.envObject.invokeFinalizerFromGC(this)}dispose(){this._finalizer&&(this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),super.dispose(),this._finalizer=void 0)}}class T{static create(e,t){const i=new T(e,t);return e.deferredStore.add(i),i}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 W{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=[]}}const L=BigInt(1)<<BigInt(60),P=-L;class U{constructor(e){this.total=BigInt(0),this.onChange=null!=e?e:null}adjust(e){if(e=BigInt(e),!(P<=e&&e<L))throw new RangeError(`changeInBytes ${e} is out of reasonable range`);const t=this.total;this.total+=e;const i=this.total,s=this.onChange;return e&&(null==s||s(i,t,e)),i}}class V{constructor(e,t,i,s){this.envObject=e,this.fn=t,this.arg=i,this.order=s}}class G{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,i){if(this._cleanupHooks.filter(s=>s.envObject===e&&s.fn===t&&s.arg===i).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new V(e,t,i,this._cleanupHookCounter++))}remove(e,t,i){for(let s=0;s<this._cleanupHooks.length;++s){const n=this._cleanupHooks[s];if(n.envObject===e&&n.fn===t&&n.arg===i)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 i=e[t];"number"==typeof i.fn?i.envObject.makeDynCall_vp(i.fn)(i.arg):i.fn(i.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(i),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.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref&&this.refHandle.unref(),this.count--)}}class ${constructor(e){this._isStopping=!1,this._canCallIntoJs=!0,this._suppressDestroy=!1,this.envStore=new W,this.scopeStore=new b,this.refStore=new W,this.deferredStore=new W,this.handleStore=new z,this.feature={supportReflect:l,supportFinalizer:c,supportWeakSymbol:h,supportBigInt:u,supportNewFunction:n,canSetFunctionName:a,setImmediate:d,Buffer:_,MessageChannel:f},this.cleanupQueue=new G,this._externalMemory=new U(null==e?void 0:e.onExternalMemoryChange),"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new q,process.once("beforeExit",()=>{this._suppressDestroy||this.destroy()}))}suppressDestroy(){this._suppressDestroy=!0}getRuntimeVersions(){return{version:v,NODE_API_SUPPORTED_VERSION_MAX:10,NAPI_VERSION_EXPERIMENTAL:g,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new D(e,t)}createNotSupportBufferError(e,t){return new R(e,t)}createReference(e,t,i,s){return j.create(e,t,i,s)}createReferenceWithData(e,t,i,s,n){return B.create(e,t,i,s,n)}createReferenceWithFinalizer(e,t,i,s,n=0,r=0,o=0){return M.create(e,t,i,s,n,r,o)}createDeferred(e){return T.create(this,e)}adjustAmountOfExternalAllocatedMemory(e){return this._externalMemory.adjust(e)}createEnv(e,t,i,s,n,r){return I(this,e,t,i,s,n,r)}createTrackedFinalizer(e,t,i,s){return E.create(e,t,i,s)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){const t=this.scopeStore.openScope(this.handleStore);return e&&e.openHandleScopes++,t}closeScope(e,t){e&&0===e.openHandleScopes||(this.scopeStore.closeScope(),e&&e.openHandleScopes--)}ensureHandle(e){switch(e){case void 0:return z.UNDEFINED;case null:return z.NULL;case!0:return z.TRUE;case!1:return z.FALSE;case r:return z.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,i){this.cleanupQueue.add(e,t,i)}removeCleanupHook(e,t,i){this.cleanupQueue.remove(e,t,i)}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 J;function Q(e){return new $(e)}exports.ConstHandle=x,exports.Context=$,exports.Deferred=T,exports.EmnapiError=O,exports.Env=C,exports.External=i,exports.Finalizer=m,exports.Handle=y,exports.HandleScope=k,exports.HandleStore=z,exports.NAPI_VERSION_EXPERIMENTAL=g,exports.NODE_API_DEFAULT_MODULE_API_VERSION=8,exports.NODE_API_SUPPORTED_VERSION_MAX=10,exports.NODE_API_SUPPORTED_VERSION_MIN=1,exports.NodeEnv=F,exports.NotSupportBufferError=R,exports.NotSupportWeakRefError=D,exports.Persistent=A,exports.RefTracker=w,exports.Reference=j,exports.ReferenceWithData=B,exports.ReferenceWithFinalizer=M,exports.ScopeStore=b,exports.Store=W,exports.TrackedFinalizer=E,exports.TryCatch=o,exports.createContext=Q,exports.getDefaultContext=function(){return J||(J=Q()),J},exports.getExternalValue=s,exports.isExternal=t,exports.isReferenceType=function(e){return"object"==typeof e&&null!==e||"function"==typeof e},exports.version=v; |
| export declare type Ptr = number | bigint | ||
| export declare interface IBuffer extends Uint8Array {} | ||
| export declare interface BufferCtor { | ||
| readonly prototype: IBuffer | ||
| /** @deprecated */ | ||
| new (...args: any[]): IBuffer | ||
| from: { | ||
| (buffer: ArrayBufferLike): IBuffer | ||
| (buffer: ArrayBufferLike, byteOffset: number, length: number): IBuffer | ||
| } | ||
| alloc: (size: number) => IBuffer | ||
| isBuffer: (obj: unknown) => obj is IBuffer | ||
| } | ||
| export declare const enum GlobalHandle { | ||
| UNDEFINED = 1, | ||
| NULL, | ||
| FALSE, | ||
| TRUE, | ||
| GLOBAL | ||
| } | ||
| export declare const enum Version { | ||
| NODE_API_SUPPORTED_VERSION_MIN = 1, | ||
| NODE_API_DEFAULT_MODULE_API_VERSION = 8, | ||
| NODE_API_SUPPORTED_VERSION_MAX = 10, | ||
| NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export declare type Pointer<T> = number | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export declare type PointerPointer<T> = number | ||
| export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T> | ||
| export declare type Const<T> = T | ||
| export declare type void_p = Pointer<void> | ||
| export declare type void_pp = Pointer<void_p> | ||
| export declare type bool = number | ||
| export declare type char = number | ||
| export declare type char_p = Pointer<char> | ||
| export declare type unsigned_char = number | ||
| export declare type const_char = Const<char> | ||
| export declare type const_char_p = Pointer<const_char> | ||
| export declare type char16_t_p = number | ||
| export declare type const_char16_t_p = number | ||
| export declare type short = number | ||
| export declare type unsigned_short = number | ||
| export declare type int = number | ||
| export declare type unsigned_int = number | ||
| export declare type long = number | ||
| export declare type unsigned_long = number | ||
| export declare type long_long = bigint | ||
| export declare type unsigned_long_long = bigint | ||
| export declare type float = number | ||
| export declare type double = number | ||
| export declare type long_double = number | ||
| export declare type size_t = number | ||
| export declare type int8_t = number | ||
| export declare type uint8_t = number | ||
| export declare type int16_t = number | ||
| export declare type uint16_t = number | ||
| export declare type int32_t = number | ||
| export declare type uint32_t = number | ||
| export declare type int64_t = bigint | ||
| export declare type uint64_t = bigint | ||
| export declare type napi_env = Pointer<unknown> | ||
| export declare type napi_value = Pointer<unknown> | ||
| export declare type napi_ref = Pointer<unknown> | ||
| export declare type napi_deferred = Pointer<unknown> | ||
| export declare type napi_handle_scope = Pointer<unknown> | ||
| export declare type napi_escapable_handle_scope = Pointer<unknown> | ||
| export declare type napi_addon_register_func = FunctionPointer<(env: napi_env, exports: napi_value) => napi_value> | ||
| export declare type napi_callback_info = Pointer<unknown> | ||
| export declare type napi_callback = FunctionPointer<(env: napi_env, info: napi_callback_info) => napi_value> | ||
| export declare interface napi_extended_error_info { | ||
| error_message: const_char_p | ||
| engine_reserved: void_p | ||
| engine_error_code: uint32_t | ||
| error_code: napi_status | ||
| } | ||
| export declare interface napi_property_descriptor { | ||
| // One of utf8name or name should be NULL. | ||
| utf8name: const_char_p | ||
| name: napi_value | ||
| method: napi_callback | ||
| getter: napi_callback | ||
| setter: napi_callback | ||
| value: napi_value | ||
| /* napi_property_attributes */ | ||
| attributes: number | ||
| data: void_p | ||
| } | ||
| export declare type napi_finalize = FunctionPointer<( | ||
| env: napi_env, | ||
| finalize_data: void_p, | ||
| finalize_hint: void_p | ||
| ) => void> | ||
| export declare interface node_module { | ||
| nm_version: int32_t | ||
| nm_flags: uint32_t | ||
| nm_filename: Pointer<const_char> | ||
| nm_register_func: napi_addon_register_func | ||
| nm_modname: Pointer<const_char> | ||
| nm_priv: Pointer<void> | ||
| reserved: PointerPointer<void> | ||
| } | ||
| export declare interface napi_node_version { | ||
| major: uint32_t | ||
| minor: uint32_t | ||
| patch: uint32_t | ||
| release: const_char_p | ||
| } | ||
| export declare interface emnapi_emscripten_version { | ||
| major: uint32_t | ||
| minor: uint32_t | ||
| patch: uint32_t | ||
| } | ||
| export declare const enum napi_status { | ||
| napi_ok, | ||
| napi_invalid_arg, | ||
| napi_object_expected, | ||
| napi_string_expected, | ||
| napi_name_expected, | ||
| napi_function_expected, | ||
| napi_number_expected, | ||
| napi_boolean_expected, | ||
| napi_array_expected, | ||
| napi_generic_failure, | ||
| napi_pending_exception, | ||
| napi_cancelled, | ||
| napi_escape_called_twice, | ||
| napi_handle_scope_mismatch, | ||
| napi_callback_scope_mismatch, | ||
| napi_queue_full, | ||
| napi_closing, | ||
| napi_bigint_expected, | ||
| napi_date_expected, | ||
| napi_arraybuffer_expected, | ||
| napi_detachable_arraybuffer_expected, | ||
| napi_would_deadlock, // unused | ||
| napi_no_external_buffers_allowed, | ||
| napi_cannot_run_js | ||
| } | ||
| export declare const enum napi_property_attributes { | ||
| napi_default = 0, | ||
| napi_writable = 1 << 0, | ||
| napi_enumerable = 1 << 1, | ||
| napi_configurable = 1 << 2, | ||
| // Used with napi_define_class to distinguish static properties | ||
| // from instance properties. Ignored by napi_define_properties. | ||
| napi_static = 1 << 10, | ||
| /// #ifdef NAPI_EXPERIMENTAL | ||
| // Default for class methods. | ||
| napi_default_method = napi_writable | napi_configurable, | ||
| // Default for object properties, like in JS obj[prop]. | ||
| napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable | ||
| /// #endif // NAPI_EXPERIMENTAL | ||
| } | ||
| export declare const enum napi_valuetype { | ||
| napi_undefined, | ||
| napi_null, | ||
| napi_boolean, | ||
| napi_number, | ||
| napi_string, | ||
| napi_symbol, | ||
| napi_object, | ||
| napi_function, | ||
| napi_external, | ||
| napi_bigint | ||
| } | ||
| export declare const enum napi_typedarray_type { | ||
| napi_int8_array, | ||
| napi_uint8_array, | ||
| napi_uint8_clamped_array, | ||
| napi_int16_array, | ||
| napi_uint16_array, | ||
| napi_int32_array, | ||
| napi_uint32_array, | ||
| napi_float32_array, | ||
| napi_float64_array, | ||
| napi_bigint64_array, | ||
| napi_biguint64_array, | ||
| napi_float16_array, | ||
| } | ||
| export declare const enum napi_key_collection_mode { | ||
| napi_key_include_prototypes, | ||
| napi_key_own_only | ||
| } | ||
| export declare const enum napi_key_filter { | ||
| napi_key_all_properties = 0, | ||
| napi_key_writable = 1, | ||
| napi_key_enumerable = 1 << 1, | ||
| napi_key_configurable = 1 << 2, | ||
| napi_key_skip_strings = 1 << 3, | ||
| napi_key_skip_symbols = 1 << 4 | ||
| } | ||
| export declare const enum napi_key_conversion { | ||
| napi_key_keep_numbers, | ||
| napi_key_numbers_to_strings | ||
| } | ||
| export declare const enum emnapi_memory_view_type { | ||
| emnapi_int8_array, | ||
| emnapi_uint8_array, | ||
| emnapi_uint8_clamped_array, | ||
| emnapi_int16_array, | ||
| emnapi_uint16_array, | ||
| emnapi_int32_array, | ||
| emnapi_uint32_array, | ||
| emnapi_float32_array, | ||
| emnapi_float64_array, | ||
| emnapi_bigint64_array, | ||
| emnapi_biguint64_array, | ||
| emnapi_float16_array, | ||
| emnapi_data_view = -1, | ||
| emnapi_buffer = -2 | ||
| } | ||
| export declare const enum napi_threadsafe_function_call_mode { | ||
| napi_tsfn_nonblocking, | ||
| napi_tsfn_blocking | ||
| } | ||
| export declare const enum napi_threadsafe_function_release_mode { | ||
| napi_tsfn_release, | ||
| napi_tsfn_abort | ||
| } | ||
| export declare type CleanupHookCallbackFunction = number | ((arg: number) => void); | ||
| export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> { | ||
| constructor(id: number, value: S); | ||
| dispose(): void; | ||
| } | ||
| export declare class Context { | ||
| private _isStopping; | ||
| private _canCallIntoJs; | ||
| private _suppressDestroy; | ||
| envStore: Store<Env>; | ||
| scopeStore: ScopeStore; | ||
| refStore: Store<Reference>; | ||
| deferredStore: Store<Deferred<any>>; | ||
| handleStore: HandleStore; | ||
| private readonly refCounter?; | ||
| private readonly cleanupQueue; | ||
| private readonly _externalMemory; | ||
| feature: { | ||
| supportReflect: boolean; | ||
| supportFinalizer: boolean; | ||
| supportWeakSymbol: boolean; | ||
| supportBigInt: boolean; | ||
| supportNewFunction: boolean; | ||
| canSetFunctionName: boolean; | ||
| setImmediate: (callback: () => void) => void; | ||
| Buffer: BufferCtor | undefined; | ||
| MessageChannel: { | ||
| new (): MessageChannel; | ||
| prototype: MessageChannel; | ||
| } | undefined; | ||
| }; | ||
| constructor(options?: ContextOptions); | ||
| /** | ||
| * Suppress the destroy on `beforeExit` event in Node.js. | ||
| * Call this method if you want to keep the context and | ||
| * all associated {@link Env | Env} alive, | ||
| * this also means that cleanup hooks will not be called. | ||
| * After call this method, you should call | ||
| * {@link Context.destroy | `Context.prototype.destroy`} method manually. | ||
| */ | ||
| suppressDestroy(): void; | ||
| getRuntimeVersions(): { | ||
| version: string; | ||
| NODE_API_SUPPORTED_VERSION_MAX: Version; | ||
| NAPI_VERSION_EXPERIMENTAL: Version; | ||
| NODE_API_DEFAULT_MODULE_API_VERSION: Version; | ||
| }; | ||
| createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError; | ||
| createNotSupportBufferError(api: string, message: string): NotSupportBufferError; | ||
| createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference; | ||
| createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference; | ||
| createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference; | ||
| createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>; | ||
| adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint; | ||
| 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; | ||
| createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer; | ||
| getCurrentScope(): HandleScope | null; | ||
| addToCurrentScope<V>(value: V): Handle<V>; | ||
| openScope(envObject?: Env): HandleScope; | ||
| closeScope(envObject?: Env, _scope?: HandleScope): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
| removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
| runCleanup(): void; | ||
| increaseWaitingRequestCounter(): void; | ||
| decreaseWaitingRequestCounter(): void; | ||
| setCanCallIntoJs(value: boolean): void; | ||
| setStopping(value: boolean): void; | ||
| canCallIntoJs(): boolean; | ||
| /** | ||
| * Destroy the context and call cleanup hooks. | ||
| * Associated {@link Env | Env} will be destroyed. | ||
| */ | ||
| destroy(): void; | ||
| } | ||
| export declare interface ContextOptions { | ||
| onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any; | ||
| } | ||
| export declare function createContext(options?: ContextOptions): Context; | ||
| export declare class Deferred<T = any> implements IStoreValue { | ||
| static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred; | ||
| id: number; | ||
| ctx: Context; | ||
| value: IDeferrdValue<T>; | ||
| constructor(ctx: Context, value: IDeferrdValue<T>); | ||
| resolve(value: T): void; | ||
| reject(reason?: any): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class EmnapiError extends Error { | ||
| constructor(message?: string); | ||
| } | ||
| export declare abstract class Env implements IStoreValue { | ||
| readonly 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; | ||
| id: number; | ||
| openHandleScopes: number; | ||
| instanceData: TrackedFinalizer | null; | ||
| tryCatch: TryCatch; | ||
| refs: number; | ||
| reflist: RefTracker; | ||
| finalizing_reflist: RefTracker; | ||
| pendingFinalizers: RefTracker[]; | ||
| lastError: { | ||
| errorCode: napi_status; | ||
| engineErrorCode: number; | ||
| engineReserved: Ptr; | ||
| }; | ||
| inGcFinalizer: boolean; | ||
| 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); | ||
| /** @virtual */ | ||
| canCallIntoJs(): boolean; | ||
| terminatedOrTerminating(): boolean; | ||
| ref(): void; | ||
| unref(): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| ensureHandleId(value: any): napi_value; | ||
| clearLastError(): napi_status; | ||
| setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status; | ||
| getReturnStatus(): napi_status; | ||
| callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T; | ||
| /** @virtual */ | ||
| abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| invokeFinalizerFromGC(finalizer: RefTracker): void; | ||
| checkGCAccess(): void; | ||
| /** @virtual */ | ||
| enqueueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| dequeueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| deleteMe(): void; | ||
| dispose(): void; | ||
| private readonly _bindingMap; | ||
| initObjectBinding<S extends object>(value: S): IReferenceBinding; | ||
| getObjectBinding<S extends object>(value: S): IReferenceBinding; | ||
| setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void; | ||
| getInstanceData(): number; | ||
| } | ||
| /** @public */ | ||
| declare interface External_2 extends Record<any, any> { | ||
| } | ||
| /** @public */ | ||
| declare const External_2: { | ||
| new (value: number | bigint): External_2; | ||
| prototype: null; | ||
| }; | ||
| export { External_2 as External } | ||
| export declare class Finalizer { | ||
| envObject: Env; | ||
| private _finalizeCallback; | ||
| private _finalizeData; | ||
| private _finalizeHint; | ||
| private _makeDynCall_vppp; | ||
| constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p); | ||
| callback(): napi_finalize; | ||
| data(): void_p; | ||
| hint(): void_p; | ||
| resetEnv(): void; | ||
| resetFinalizer(): void; | ||
| callFinalizer(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare function getDefaultContext(): Context; | ||
| /** @public */ | ||
| export declare function getExternalValue(external: External_2): number | bigint; | ||
| export declare class Handle<S> { | ||
| id: number; | ||
| value: S; | ||
| constructor(id: number, value: S); | ||
| data(): void_p; | ||
| isNumber(): boolean; | ||
| isBigInt(): boolean; | ||
| isString(): boolean; | ||
| isFunction(): boolean; | ||
| isExternal(): boolean; | ||
| isObject(): boolean; | ||
| isArray(): boolean; | ||
| isArrayBuffer(): boolean; | ||
| isTypedArray(): boolean; | ||
| isBuffer(BufferConstructor?: BufferCtor): boolean; | ||
| isDataView(): boolean; | ||
| isDate(): boolean; | ||
| isPromise(): boolean; | ||
| isBoolean(): boolean; | ||
| isUndefined(): boolean; | ||
| isSymbol(): boolean; | ||
| isNull(): boolean; | ||
| dispose(): void; | ||
| } | ||
| export declare class HandleScope { | ||
| handleStore: HandleStore; | ||
| id: number; | ||
| parent: HandleScope | null; | ||
| child: HandleScope | null; | ||
| start: number; | ||
| end: number; | ||
| private _escapeCalled; | ||
| callbackInfo: ICallbackInfo; | ||
| constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number); | ||
| add<V>(value: V): Handle<V>; | ||
| addExternal(data: void_p): Handle<object>; | ||
| dispose(): void; | ||
| escape(handle: number): Handle<any> | null; | ||
| escapeCalled(): boolean; | ||
| } | ||
| export declare class HandleStore { | ||
| static UNDEFINED: ConstHandle<undefined>; | ||
| static NULL: ConstHandle<null>; | ||
| static FALSE: ConstHandle<false>; | ||
| static TRUE: ConstHandle<true>; | ||
| static GLOBAL: ConstHandle<typeof globalThis>; | ||
| static MIN_ID: 6; | ||
| private readonly _values; | ||
| private _next; | ||
| push<S>(value: S): Handle<S>; | ||
| erase(start: number, end: number): void; | ||
| get(id: Ptr): Handle<any> | undefined; | ||
| swap(a: number, b: number): void; | ||
| dispose(): void; | ||
| } | ||
| export declare interface ICallbackInfo { | ||
| thiz: any; | ||
| data: void_p; | ||
| args: ArrayLike<any>; | ||
| fn: Function; | ||
| } | ||
| export declare interface IDeferrdValue<T = any> { | ||
| resolve: (value: T) => void; | ||
| reject: (reason?: any) => void; | ||
| } | ||
| export declare interface IReferenceBinding { | ||
| wrapped: number; | ||
| tag: Uint32Array | null; | ||
| } | ||
| /** @public */ | ||
| export declare function isExternal(object: unknown): object is External_2; | ||
| export declare function isReferenceType(v: any): v is object; | ||
| export declare interface IStoreValue { | ||
| id: number; | ||
| dispose(): void; | ||
| [x: string]: any; | ||
| } | ||
| export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL; | ||
| export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| export declare const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX; | ||
| export declare const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN; | ||
| export declare class NodeEnv extends Env { | ||
| filename: string; | ||
| private readonly nodeBinding?; | ||
| destructing: boolean; | ||
| finalizationScheduled: boolean; | ||
| 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); | ||
| deleteMe(): void; | ||
| canCallIntoJs(): boolean; | ||
| triggerFatalException(err: any): void; | ||
| callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T; | ||
| callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| enqueueFinalizer(finalizer: RefTracker): void; | ||
| drainFinalizerQueue(): void; | ||
| } | ||
| export declare class NotSupportBufferError extends EmnapiError { | ||
| constructor(api: string, message: string); | ||
| } | ||
| export declare class NotSupportWeakRefError extends EmnapiError { | ||
| constructor(api: string, message: string); | ||
| } | ||
| export declare class Persistent<T> { | ||
| private _ref; | ||
| private _param; | ||
| private _callback; | ||
| private static readonly _registry; | ||
| constructor(value: T); | ||
| setWeak<P>(param: P, callback: (param: P) => void): void; | ||
| clearWeak(): void; | ||
| reset(): void; | ||
| isEmpty(): boolean; | ||
| deref(): T | undefined; | ||
| } | ||
| export declare class Reference extends RefTracker implements IStoreValue { | ||
| private static weakCallback; | ||
| id: number; | ||
| envObject: Env; | ||
| private readonly canBeWeak; | ||
| private _refcount; | ||
| private readonly _ownership; | ||
| persistent: Persistent<object>; | ||
| static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference; | ||
| protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership); | ||
| ref(): number; | ||
| unref(): number; | ||
| get(envObject?: Env): napi_value; | ||
| /** @virtual */ | ||
| resetFinalizer(): void; | ||
| /** @virtual */ | ||
| data(): void_p; | ||
| refcount(): number; | ||
| ownership(): ReferenceOwnership; | ||
| /** @virtual */ | ||
| protected callUserFinalizer(): void; | ||
| /** @virtual */ | ||
| protected invokeFinalizerFromGC(): void; | ||
| private _setWeak; | ||
| finalize(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare enum ReferenceOwnership { | ||
| kRuntime = 0, | ||
| kUserland = 1 | ||
| } | ||
| export declare class ReferenceWithData extends Reference { | ||
| private readonly _data; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData; | ||
| private constructor(); | ||
| data(): void_p; | ||
| } | ||
| export declare class ReferenceWithFinalizer extends Reference { | ||
| private _finalizer; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer; | ||
| private constructor(); | ||
| resetFinalizer(): void; | ||
| data(): void_p; | ||
| protected callUserFinalizer(): void; | ||
| protected invokeFinalizerFromGC(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class RefTracker { | ||
| /** @virtual */ | ||
| dispose(): void; | ||
| /** @virtual */ | ||
| finalize(): void; | ||
| private _next; | ||
| private _prev; | ||
| link(list: RefTracker): void; | ||
| unlink(): void; | ||
| static finalizeAll(list: RefTracker): void; | ||
| } | ||
| export declare class ScopeStore { | ||
| private readonly _rootScope; | ||
| currentScope: HandleScope; | ||
| private readonly _values; | ||
| constructor(); | ||
| get(id: number): HandleScope | undefined; | ||
| openScope(handleStore: HandleStore): HandleScope; | ||
| closeScope(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class Store<V extends IStoreValue> { | ||
| protected _values: Array<V | undefined>; | ||
| private _freeList; | ||
| private _size; | ||
| constructor(); | ||
| add(value: V): void; | ||
| get(id: Ptr): V | undefined; | ||
| has(id: Ptr): boolean; | ||
| remove(id: Ptr): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class TrackedFinalizer extends RefTracker { | ||
| private _finalizer; | ||
| static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer; | ||
| private constructor(); | ||
| data(): void_p; | ||
| dispose(): void; | ||
| finalize(): void; | ||
| } | ||
| export declare class TryCatch { | ||
| private _exception; | ||
| private _caught; | ||
| isEmpty(): boolean; | ||
| hasCaught(): boolean; | ||
| exception(): any; | ||
| setError(err: any): void; | ||
| reset(): void; | ||
| extractException(): any; | ||
| } | ||
| export declare const version: string; | ||
| export { } |
| import { __extends } from 'tslib'; | ||
| var externalValue = new WeakMap(); | ||
| /** @public */ | ||
| function isExternal(object) { | ||
| return externalValue.has(object); | ||
| } | ||
| /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare | ||
| var External = (function () { | ||
| function External(value) { | ||
| Object.setPrototypeOf(this, null); | ||
| externalValue.set(this, value); | ||
| } | ||
| External.prototype = null; | ||
| return External; | ||
| })(); | ||
| /** @public */ | ||
| function getExternalValue(external) { | ||
| if (!isExternal(external)) { | ||
| throw new TypeError('not external'); | ||
| } | ||
| return externalValue.get(external); | ||
| } | ||
| var supportNewFunction = /*#__PURE__*/ (function () { | ||
| var f; | ||
| try { | ||
| f = new Function(); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| return typeof f === 'function'; | ||
| })(); | ||
| var _global = /*#__PURE__*/ (function () { | ||
| if (typeof globalThis !== 'undefined') | ||
| return globalThis; | ||
| var g = (function () { return this; })(); | ||
| if (!g && supportNewFunction) { | ||
| try { | ||
| g = new Function('return this')(); | ||
| } | ||
| catch (_) { } | ||
| } | ||
| if (!g) { | ||
| if (typeof __webpack_public_path__ === 'undefined') { | ||
| if (typeof global !== 'undefined') | ||
| return global; | ||
| } | ||
| if (typeof window !== 'undefined') | ||
| return window; | ||
| if (typeof self !== 'undefined') | ||
| return self; | ||
| } | ||
| return g; | ||
| })(); | ||
| var TryCatch = /*#__PURE__*/ (function () { | ||
| function TryCatch() { | ||
| this._exception = undefined; | ||
| this._caught = false; | ||
| } | ||
| TryCatch.prototype.isEmpty = function () { | ||
| return !this._caught; | ||
| }; | ||
| TryCatch.prototype.hasCaught = function () { | ||
| return this._caught; | ||
| }; | ||
| TryCatch.prototype.exception = function () { | ||
| return this._exception; | ||
| }; | ||
| TryCatch.prototype.setError = function (err) { | ||
| this._caught = true; | ||
| this._exception = err; | ||
| }; | ||
| TryCatch.prototype.reset = function () { | ||
| this._caught = false; | ||
| this._exception = undefined; | ||
| }; | ||
| TryCatch.prototype.extractException = function () { | ||
| var e = this._exception; | ||
| this.reset(); | ||
| return e; | ||
| }; | ||
| return TryCatch; | ||
| }()); | ||
| var canSetFunctionName = /*#__PURE__*/ (function () { | ||
| var _a; | ||
| try { | ||
| return Boolean((_a = Object.getOwnPropertyDescriptor(Function.prototype, 'name')) === null || _a === void 0 ? void 0 : _a.configurable); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| })(); | ||
| var supportReflect = typeof Reflect === 'object'; | ||
| var supportFinalizer = (typeof FinalizationRegistry !== 'undefined') && (typeof WeakRef !== 'undefined'); | ||
| var supportWeakSymbol = /*#__PURE__*/ (function () { | ||
| try { | ||
| // eslint-disable-next-line symbol-description | ||
| var sym = Symbol(); | ||
| // eslint-disable-next-line no-new | ||
| new WeakRef(sym); | ||
| new WeakMap().set(sym, undefined); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| return true; | ||
| })(); | ||
| var supportBigInt = typeof BigInt !== 'undefined'; | ||
| function isReferenceType(v) { | ||
| return (typeof v === 'object' && v !== null) || typeof v === 'function'; | ||
| } | ||
| var _require = /*#__PURE__*/ (function () { | ||
| var nativeRequire; | ||
| if (typeof __webpack_public_path__ !== 'undefined') { | ||
| nativeRequire = (function () { | ||
| return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined; | ||
| })(); | ||
| } | ||
| else { | ||
| nativeRequire = (function () { | ||
| return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined); | ||
| })(); | ||
| } | ||
| return nativeRequire; | ||
| })(); | ||
| var _MessageChannel = typeof MessageChannel === 'function' | ||
| ? MessageChannel | ||
| : /*#__PURE__*/ (function () { | ||
| try { | ||
| return _require('worker_threads').MessageChannel; | ||
| } | ||
| catch (_) { } | ||
| return undefined; | ||
| })(); | ||
| var _setImmediate = typeof setImmediate === 'function' | ||
| ? setImmediate | ||
| : function (callback) { | ||
| if (typeof callback !== 'function') { | ||
| throw new TypeError('The "callback" argument must be of type function'); | ||
| } | ||
| if (_MessageChannel) { | ||
| var channel_1 = new _MessageChannel(); | ||
| channel_1.port1.onmessage = function () { | ||
| channel_1.port1.onmessage = null; | ||
| channel_1 = undefined; | ||
| callback(); | ||
| }; | ||
| channel_1.port2.postMessage(null); | ||
| } | ||
| else { | ||
| setTimeout(callback, 0); | ||
| } | ||
| }; | ||
| var _Buffer = typeof Buffer === 'function' | ||
| ? Buffer | ||
| : /*#__PURE__*/ (function () { | ||
| try { | ||
| return _require('buffer').Buffer; | ||
| } | ||
| catch (_) { } | ||
| return undefined; | ||
| })(); | ||
| var version = "1.10.0"; | ||
| var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */; | ||
| var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */; | ||
| var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */; | ||
| var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */; | ||
| var Handle = /*#__PURE__*/ (function () { | ||
| function Handle(id, value) { | ||
| this.id = id; | ||
| this.value = value; | ||
| } | ||
| Handle.prototype.data = function () { | ||
| return getExternalValue(this.value); | ||
| }; | ||
| Handle.prototype.isNumber = function () { | ||
| return typeof this.value === 'number'; | ||
| }; | ||
| Handle.prototype.isBigInt = function () { | ||
| return typeof this.value === 'bigint'; | ||
| }; | ||
| Handle.prototype.isString = function () { | ||
| return typeof this.value === 'string'; | ||
| }; | ||
| Handle.prototype.isFunction = function () { | ||
| return typeof this.value === 'function'; | ||
| }; | ||
| Handle.prototype.isExternal = function () { | ||
| return isExternal(this.value); | ||
| }; | ||
| Handle.prototype.isObject = function () { | ||
| return typeof this.value === 'object' && this.value !== null; | ||
| }; | ||
| Handle.prototype.isArray = function () { | ||
| return Array.isArray(this.value); | ||
| }; | ||
| Handle.prototype.isArrayBuffer = function () { | ||
| return (this.value instanceof ArrayBuffer); | ||
| }; | ||
| Handle.prototype.isTypedArray = function () { | ||
| return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView); | ||
| }; | ||
| Handle.prototype.isBuffer = function (BufferConstructor) { | ||
| if (ArrayBuffer.isView(this.value)) | ||
| return true; | ||
| BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer); | ||
| return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value); | ||
| }; | ||
| Handle.prototype.isDataView = function () { | ||
| return (this.value instanceof DataView); | ||
| }; | ||
| Handle.prototype.isDate = function () { | ||
| return (this.value instanceof Date); | ||
| }; | ||
| Handle.prototype.isPromise = function () { | ||
| return (this.value instanceof Promise); | ||
| }; | ||
| Handle.prototype.isBoolean = function () { | ||
| return typeof this.value === 'boolean'; | ||
| }; | ||
| Handle.prototype.isUndefined = function () { | ||
| return this.value === undefined; | ||
| }; | ||
| Handle.prototype.isSymbol = function () { | ||
| return typeof this.value === 'symbol'; | ||
| }; | ||
| Handle.prototype.isNull = function () { | ||
| return this.value === null; | ||
| }; | ||
| Handle.prototype.dispose = function () { | ||
| this.value = undefined; | ||
| }; | ||
| return Handle; | ||
| }()); | ||
| var ConstHandle = /*#__PURE__*/ (function (_super) { | ||
| __extends(ConstHandle, _super); | ||
| function ConstHandle(id, value) { | ||
| return _super.call(this, id, value) || this; | ||
| } | ||
| ConstHandle.prototype.dispose = function () { }; | ||
| return ConstHandle; | ||
| }(Handle)); | ||
| var HandleStore = /*#__PURE__*/ (function () { | ||
| function HandleStore() { | ||
| this._values = [ | ||
| undefined, | ||
| HandleStore.UNDEFINED, | ||
| HandleStore.NULL, | ||
| HandleStore.FALSE, | ||
| HandleStore.TRUE, | ||
| HandleStore.GLOBAL | ||
| ]; | ||
| this._next = HandleStore.MIN_ID; | ||
| } | ||
| HandleStore.prototype.push = function (value) { | ||
| var h; | ||
| var next = this._next; | ||
| var values = this._values; | ||
| if (next < values.length) { | ||
| h = values[next]; | ||
| h.value = value; | ||
| } | ||
| else { | ||
| h = new Handle(next, value); | ||
| values[next] = h; | ||
| } | ||
| this._next++; | ||
| return h; | ||
| }; | ||
| HandleStore.prototype.erase = function (start, end) { | ||
| this._next = start; | ||
| var values = this._values; | ||
| for (var i = start; i < end; ++i) { | ||
| values[i].dispose(); | ||
| } | ||
| }; | ||
| HandleStore.prototype.get = function (id) { | ||
| return this._values[id]; | ||
| }; | ||
| HandleStore.prototype.swap = function (a, b) { | ||
| var values = this._values; | ||
| var h = values[a]; | ||
| values[a] = values[b]; | ||
| values[a].id = Number(a); | ||
| values[b] = h; | ||
| h.id = Number(b); | ||
| }; | ||
| HandleStore.prototype.dispose = function () { | ||
| this._values.length = HandleStore.MIN_ID; | ||
| this._next = HandleStore.MIN_ID; | ||
| }; | ||
| HandleStore.UNDEFINED = new ConstHandle(1 /* GlobalHandle.UNDEFINED */, undefined); | ||
| HandleStore.NULL = new ConstHandle(2 /* GlobalHandle.NULL */, null); | ||
| HandleStore.FALSE = new ConstHandle(3 /* GlobalHandle.FALSE */, false); | ||
| HandleStore.TRUE = new ConstHandle(4 /* GlobalHandle.TRUE */, true); | ||
| HandleStore.GLOBAL = new ConstHandle(5 /* GlobalHandle.GLOBAL */, _global); | ||
| HandleStore.MIN_ID = 6; | ||
| return HandleStore; | ||
| }()); | ||
| var HandleScope = /*#__PURE__*/ (function () { | ||
| function HandleScope(handleStore, id, parentScope, start, end) { | ||
| if (end === void 0) { end = start; } | ||
| this.handleStore = handleStore; | ||
| this.id = id; | ||
| this.parent = parentScope; | ||
| this.child = null; | ||
| if (parentScope !== null) | ||
| parentScope.child = this; | ||
| this.start = start; | ||
| this.end = end; | ||
| this._escapeCalled = false; | ||
| this.callbackInfo = { | ||
| thiz: undefined, | ||
| data: 0, | ||
| args: undefined, | ||
| fn: undefined | ||
| }; | ||
| } | ||
| HandleScope.prototype.add = function (value) { | ||
| var h = this.handleStore.push(value); | ||
| this.end++; | ||
| return h; | ||
| }; | ||
| HandleScope.prototype.addExternal = function (data) { | ||
| return this.add(new External(data)); | ||
| }; | ||
| HandleScope.prototype.dispose = function () { | ||
| if (this._escapeCalled) | ||
| this._escapeCalled = false; | ||
| if (this.start === this.end) | ||
| return; | ||
| this.handleStore.erase(this.start, this.end); | ||
| }; | ||
| HandleScope.prototype.escape = function (handle) { | ||
| if (this._escapeCalled) | ||
| return null; | ||
| this._escapeCalled = true; | ||
| if (handle < this.start || handle >= this.end) { | ||
| return null; | ||
| } | ||
| this.handleStore.swap(handle, this.start); | ||
| var h = this.handleStore.get(this.start); | ||
| this.start++; | ||
| this.parent.end++; | ||
| return h; | ||
| }; | ||
| HandleScope.prototype.escapeCalled = function () { | ||
| return this._escapeCalled; | ||
| }; | ||
| return HandleScope; | ||
| }()); | ||
| var ScopeStore = /*#__PURE__*/ (function () { | ||
| function ScopeStore() { | ||
| this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID); | ||
| this.currentScope = this._rootScope; | ||
| this._values = [undefined]; | ||
| } | ||
| ScopeStore.prototype.get = function (id) { | ||
| return this._values[id]; | ||
| }; | ||
| ScopeStore.prototype.openScope = function (handleStore) { | ||
| var currentScope = this.currentScope; | ||
| var scope = currentScope.child; | ||
| if (scope !== null) { | ||
| scope.start = scope.end = currentScope.end; | ||
| } | ||
| else { | ||
| var id = currentScope.id + 1; | ||
| scope = new HandleScope(handleStore, id, currentScope, currentScope.end); | ||
| this._values[id] = scope; | ||
| } | ||
| this.currentScope = scope; | ||
| return scope; | ||
| }; | ||
| ScopeStore.prototype.closeScope = function () { | ||
| var scope = this.currentScope; | ||
| this.currentScope = scope.parent; | ||
| scope.dispose(); | ||
| }; | ||
| ScopeStore.prototype.dispose = function () { | ||
| this.currentScope = this._rootScope; | ||
| this._values.length = 1; | ||
| }; | ||
| return ScopeStore; | ||
| }()); | ||
| var RefTracker = /*#__PURE__*/ (function () { | ||
| function RefTracker() { | ||
| this._next = null; | ||
| this._prev = null; | ||
| } | ||
| /** @virtual */ | ||
| RefTracker.prototype.dispose = function () { }; | ||
| /** @virtual */ | ||
| RefTracker.prototype.finalize = function () { }; | ||
| RefTracker.prototype.link = function (list) { | ||
| this._prev = list; | ||
| this._next = list._next; | ||
| if (this._next !== null) { | ||
| this._next._prev = this; | ||
| } | ||
| list._next = this; | ||
| }; | ||
| RefTracker.prototype.unlink = function () { | ||
| if (this._prev !== null) { | ||
| this._prev._next = this._next; | ||
| } | ||
| if (this._next !== null) { | ||
| this._next._prev = this._prev; | ||
| } | ||
| this._prev = null; | ||
| this._next = null; | ||
| }; | ||
| RefTracker.finalizeAll = function (list) { | ||
| while (list._next !== null) { | ||
| list._next.finalize(); | ||
| } | ||
| }; | ||
| return RefTracker; | ||
| }()); | ||
| var Finalizer = /*#__PURE__*/ (function () { | ||
| function Finalizer(envObject, _finalizeCallback, _finalizeData, _finalizeHint) { | ||
| if (_finalizeCallback === void 0) { _finalizeCallback = 0; } | ||
| if (_finalizeData === void 0) { _finalizeData = 0; } | ||
| if (_finalizeHint === void 0) { _finalizeHint = 0; } | ||
| this.envObject = envObject; | ||
| this._finalizeCallback = _finalizeCallback; | ||
| this._finalizeData = _finalizeData; | ||
| this._finalizeHint = _finalizeHint; | ||
| this._makeDynCall_vppp = envObject.makeDynCall_vppp; | ||
| } | ||
| Finalizer.prototype.callback = function () { return this._finalizeCallback; }; | ||
| Finalizer.prototype.data = function () { return this._finalizeData; }; | ||
| Finalizer.prototype.hint = function () { return this._finalizeHint; }; | ||
| Finalizer.prototype.resetEnv = function () { | ||
| this.envObject = undefined; | ||
| }; | ||
| Finalizer.prototype.resetFinalizer = function () { | ||
| this._finalizeCallback = 0; | ||
| this._finalizeData = 0; | ||
| this._finalizeHint = 0; | ||
| }; | ||
| Finalizer.prototype.callFinalizer = function () { | ||
| var finalize_callback = this._finalizeCallback; | ||
| var finalize_data = this._finalizeData; | ||
| var finalize_hint = this._finalizeHint; | ||
| this.resetFinalizer(); | ||
| if (!finalize_callback) | ||
| return; | ||
| var fini = Number(finalize_callback); | ||
| if (!this.envObject) { | ||
| this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint); | ||
| } | ||
| else { | ||
| this.envObject.callFinalizer(fini, finalize_data, finalize_hint); | ||
| } | ||
| }; | ||
| Finalizer.prototype.dispose = function () { | ||
| this.envObject = undefined; | ||
| this._makeDynCall_vppp = undefined; | ||
| }; | ||
| return Finalizer; | ||
| }()); | ||
| var TrackedFinalizer = /*#__PURE__*/ (function (_super) { | ||
| __extends(TrackedFinalizer, _super); | ||
| function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| var _this = _super.call(this) || this; | ||
| _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| return _this; | ||
| } | ||
| TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| var finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| finalizer.link(envObject.finalizing_reflist); | ||
| return finalizer; | ||
| }; | ||
| TrackedFinalizer.prototype.data = function () { | ||
| return this._finalizer.data(); | ||
| }; | ||
| TrackedFinalizer.prototype.dispose = function () { | ||
| if (!this._finalizer) | ||
| return; | ||
| this.unlink(); | ||
| this._finalizer.envObject.dequeueFinalizer(this); | ||
| this._finalizer.dispose(); | ||
| this._finalizer = undefined; | ||
| _super.prototype.dispose.call(this); | ||
| }; | ||
| TrackedFinalizer.prototype.finalize = function () { | ||
| this.unlink(); | ||
| var error; | ||
| var caught = false; | ||
| try { | ||
| this._finalizer.callFinalizer(); | ||
| } | ||
| catch (err) { | ||
| caught = true; | ||
| error = err; | ||
| } | ||
| this.dispose(); | ||
| if (caught) { | ||
| throw error; | ||
| } | ||
| }; | ||
| return TrackedFinalizer; | ||
| }(RefTracker)); | ||
| function throwNodeApiVersionError(moduleName, moduleApiVersion) { | ||
| var errorMessage = "".concat(moduleName, " requires Node-API version ").concat(moduleApiVersion, ", but this version of Node.js only supports version ").concat(NODE_API_SUPPORTED_VERSION_MAX, " add-ons."); | ||
| throw new Error(errorMessage); | ||
| } | ||
| function handleThrow(envObject, value) { | ||
| if (envObject.terminatedOrTerminating()) { | ||
| return; | ||
| } | ||
| throw value; | ||
| } | ||
| var Env = /*#__PURE__*/ (function () { | ||
| function Env(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) { | ||
| this.ctx = ctx; | ||
| this.moduleApiVersion = moduleApiVersion; | ||
| this.makeDynCall_vppp = makeDynCall_vppp; | ||
| this.makeDynCall_vp = makeDynCall_vp; | ||
| this.abort = abort; | ||
| this.openHandleScopes = 0; | ||
| this.instanceData = null; | ||
| this.tryCatch = new TryCatch(); | ||
| this.refs = 1; | ||
| this.reflist = new RefTracker(); | ||
| this.finalizing_reflist = new RefTracker(); | ||
| this.pendingFinalizers = []; | ||
| this.lastError = { | ||
| errorCode: 0 /* napi_status.napi_ok */, | ||
| engineErrorCode: 0, | ||
| engineReserved: 0 | ||
| }; | ||
| this.inGcFinalizer = false; | ||
| this._bindingMap = new WeakMap(); | ||
| this.id = 0; | ||
| } | ||
| /** @virtual */ | ||
| Env.prototype.canCallIntoJs = function () { | ||
| return true; | ||
| }; | ||
| Env.prototype.terminatedOrTerminating = function () { | ||
| return !this.canCallIntoJs(); | ||
| }; | ||
| Env.prototype.ref = function () { | ||
| this.refs++; | ||
| }; | ||
| Env.prototype.unref = function () { | ||
| this.refs--; | ||
| if (this.refs === 0) { | ||
| this.dispose(); | ||
| } | ||
| }; | ||
| Env.prototype.ensureHandle = function (value) { | ||
| return this.ctx.ensureHandle(value); | ||
| }; | ||
| Env.prototype.ensureHandleId = function (value) { | ||
| return this.ensureHandle(value).id; | ||
| }; | ||
| Env.prototype.clearLastError = function () { | ||
| var lastError = this.lastError; | ||
| if (lastError.errorCode !== 0 /* napi_status.napi_ok */) | ||
| lastError.errorCode = 0 /* napi_status.napi_ok */; | ||
| if (lastError.engineErrorCode !== 0) | ||
| lastError.engineErrorCode = 0; | ||
| if (lastError.engineReserved !== 0) | ||
| lastError.engineReserved = 0; | ||
| return 0 /* napi_status.napi_ok */; | ||
| }; | ||
| Env.prototype.setLastError = function (error_code, engine_error_code, engine_reserved) { | ||
| if (engine_error_code === void 0) { engine_error_code = 0; } | ||
| if (engine_reserved === void 0) { engine_reserved = 0; } | ||
| var lastError = this.lastError; | ||
| if (lastError.errorCode !== error_code) | ||
| lastError.errorCode = error_code; | ||
| if (lastError.engineErrorCode !== engine_error_code) | ||
| lastError.engineErrorCode = engine_error_code; | ||
| if (lastError.engineReserved !== engine_reserved) | ||
| lastError.engineReserved = engine_reserved; | ||
| return error_code; | ||
| }; | ||
| Env.prototype.getReturnStatus = function () { | ||
| return !this.tryCatch.hasCaught() ? 0 /* napi_status.napi_ok */ : this.setLastError(10 /* napi_status.napi_pending_exception */); | ||
| }; | ||
| Env.prototype.callIntoModule = function (fn, handleException) { | ||
| if (handleException === void 0) { handleException = handleThrow; } | ||
| var openHandleScopesBefore = this.openHandleScopes; | ||
| this.clearLastError(); | ||
| var r = fn(this); | ||
| if (openHandleScopesBefore !== this.openHandleScopes) { | ||
| this.abort('open_handle_scopes != open_handle_scopes_before'); | ||
| } | ||
| if (this.tryCatch.hasCaught()) { | ||
| var err = this.tryCatch.extractException(); | ||
| handleException(this, err); | ||
| } | ||
| return r; | ||
| }; | ||
| Env.prototype.invokeFinalizerFromGC = function (finalizer) { | ||
| if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) { | ||
| this.enqueueFinalizer(finalizer); | ||
| } | ||
| else { | ||
| var saved = this.inGcFinalizer; | ||
| this.inGcFinalizer = true; | ||
| try { | ||
| finalizer.finalize(); | ||
| } | ||
| finally { | ||
| this.inGcFinalizer = saved; | ||
| } | ||
| } | ||
| }; | ||
| Env.prototype.checkGCAccess = function () { | ||
| if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) { | ||
| this.abort('Finalizer is calling a function that may affect GC state.\n' + | ||
| 'The finalizers are run directly from GC and must not affect GC ' + | ||
| 'state.\n' + | ||
| 'Use `node_api_post_finalizer` from inside of the finalizer to work ' + | ||
| 'around this issue.\n' + | ||
| 'It schedules the call as a new task in the event loop.'); | ||
| } | ||
| }; | ||
| /** @virtual */ | ||
| Env.prototype.enqueueFinalizer = function (finalizer) { | ||
| if (this.pendingFinalizers.indexOf(finalizer) === -1) { | ||
| this.pendingFinalizers.push(finalizer); | ||
| } | ||
| }; | ||
| /** @virtual */ | ||
| Env.prototype.dequeueFinalizer = function (finalizer) { | ||
| var index = this.pendingFinalizers.indexOf(finalizer); | ||
| if (index !== -1) { | ||
| this.pendingFinalizers.splice(index, 1); | ||
| } | ||
| }; | ||
| /** @virtual */ | ||
| Env.prototype.deleteMe = function () { | ||
| RefTracker.finalizeAll(this.finalizing_reflist); | ||
| RefTracker.finalizeAll(this.reflist); | ||
| this.tryCatch.extractException(); | ||
| this.ctx.envStore.remove(this.id); | ||
| }; | ||
| Env.prototype.dispose = function () { | ||
| if (this.id === 0) | ||
| return; | ||
| this.deleteMe(); | ||
| this.finalizing_reflist.dispose(); | ||
| this.reflist.dispose(); | ||
| this.id = 0; | ||
| }; | ||
| Env.prototype.initObjectBinding = function (value) { | ||
| var binding = { | ||
| wrapped: 0, | ||
| tag: null | ||
| }; | ||
| this._bindingMap.set(value, binding); | ||
| return binding; | ||
| }; | ||
| Env.prototype.getObjectBinding = function (value) { | ||
| if (this._bindingMap.has(value)) { | ||
| return this._bindingMap.get(value); | ||
| } | ||
| return this.initObjectBinding(value); | ||
| }; | ||
| Env.prototype.setInstanceData = function (data, finalize_cb, finalize_hint) { | ||
| if (this.instanceData) { | ||
| this.instanceData.dispose(); | ||
| } | ||
| this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint); | ||
| }; | ||
| Env.prototype.getInstanceData = function () { | ||
| return this.instanceData ? this.instanceData.data() : 0; | ||
| }; | ||
| return Env; | ||
| }()); | ||
| var NodeEnv = /*#__PURE__*/ (function (_super) { | ||
| __extends(NodeEnv, _super); | ||
| function NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| var _this = _super.call(this, ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) || this; | ||
| _this.filename = filename; | ||
| _this.nodeBinding = nodeBinding; | ||
| _this.destructing = false; | ||
| _this.finalizationScheduled = false; | ||
| return _this; | ||
| } | ||
| NodeEnv.prototype.deleteMe = function () { | ||
| this.destructing = true; | ||
| this.drainFinalizerQueue(); | ||
| _super.prototype.deleteMe.call(this); | ||
| }; | ||
| NodeEnv.prototype.canCallIntoJs = function () { | ||
| return _super.prototype.canCallIntoJs.call(this) && this.ctx.canCallIntoJs(); | ||
| }; | ||
| NodeEnv.prototype.triggerFatalException = function (err) { | ||
| if (this.nodeBinding) { | ||
| this.nodeBinding.napi.fatalException(err); | ||
| } | ||
| else { | ||
| if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') { | ||
| var handled = process._fatalException(err); | ||
| if (!handled) { | ||
| console.error(err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| else { | ||
| throw err; | ||
| } | ||
| } | ||
| }; | ||
| NodeEnv.prototype.callbackIntoModule = function (enforceUncaughtExceptionPolicy, fn) { | ||
| return this.callIntoModule(fn, function (envObject, err) { | ||
| if (envObject.terminatedOrTerminating()) { | ||
| return; | ||
| } | ||
| var hasProcess = typeof process === 'object' && process !== null; | ||
| var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false; | ||
| if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) { | ||
| var warn = hasProcess && typeof process.emitWarning === 'function' | ||
| ? process.emitWarning | ||
| : function (warning, type, code) { | ||
| if (warning instanceof Error) { | ||
| console.warn(warning.toString()); | ||
| } | ||
| else { | ||
| var prefix = code ? "[".concat(code, "] ") : ''; | ||
| // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
| console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning)); | ||
| } | ||
| }; | ||
| warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168'); | ||
| return; | ||
| } | ||
| envObject.triggerFatalException(err); | ||
| }); | ||
| }; | ||
| NodeEnv.prototype.callFinalizer = function (cb, data, hint) { | ||
| this.callFinalizerInternal(1, cb, data, hint); | ||
| }; | ||
| NodeEnv.prototype.callFinalizerInternal = function (forceUncaught, cb, data, hint) { | ||
| var f = this.makeDynCall_vppp(cb); | ||
| var env = this.id; | ||
| var scope = this.ctx.openScope(this); | ||
| try { | ||
| this.callbackIntoModule(Boolean(forceUncaught), function () { f(env, data, hint); }); | ||
| } | ||
| finally { | ||
| this.ctx.closeScope(this, scope); | ||
| } | ||
| }; | ||
| NodeEnv.prototype.enqueueFinalizer = function (finalizer) { | ||
| var _this = this; | ||
| _super.prototype.enqueueFinalizer.call(this, finalizer); | ||
| if (!this.finalizationScheduled && !this.destructing) { | ||
| this.finalizationScheduled = true; | ||
| this.ref(); | ||
| _setImmediate(function () { | ||
| _this.finalizationScheduled = false; | ||
| _this.unref(); | ||
| _this.drainFinalizerQueue(); | ||
| }); | ||
| } | ||
| }; | ||
| NodeEnv.prototype.drainFinalizerQueue = function () { | ||
| while (this.pendingFinalizers.length > 0) { | ||
| var refTracker = this.pendingFinalizers.shift(); | ||
| refTracker.finalize(); | ||
| } | ||
| }; | ||
| return NodeEnv; | ||
| }(Env)); | ||
| function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion; | ||
| // Validate module_api_version. | ||
| if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) { | ||
| moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| } | ||
| else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) { | ||
| throwNodeApiVersionError(filename, moduleApiVersion); | ||
| } | ||
| var env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding); | ||
| ctx.envStore.add(env); | ||
| ctx.addCleanupHook(env, function () { env.unref(); }, 0); | ||
| return env; | ||
| } | ||
| var EmnapiError = /*#__PURE__*/ (function (_super) { | ||
| __extends(EmnapiError, _super); | ||
| function EmnapiError(message) { | ||
| var _newTarget = this.constructor; | ||
| var _this = _super.call(this, message) || this; | ||
| var ErrorConstructor = _newTarget; | ||
| var proto = ErrorConstructor.prototype; | ||
| if (!(_this instanceof EmnapiError)) { | ||
| var setPrototypeOf = Object.setPrototypeOf; | ||
| if (typeof setPrototypeOf === 'function') { | ||
| setPrototypeOf.call(Object, _this, proto); | ||
| } | ||
| else { | ||
| // eslint-disable-next-line no-proto | ||
| _this.__proto__ = proto; | ||
| } | ||
| if (typeof Error.captureStackTrace === 'function') { | ||
| Error.captureStackTrace(_this, ErrorConstructor); | ||
| } | ||
| } | ||
| return _this; | ||
| } | ||
| return EmnapiError; | ||
| }(Error)); | ||
| Object.defineProperty(EmnapiError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'EmnapiError' | ||
| }); | ||
| var NotSupportWeakRefError = /*#__PURE__*/ (function (_super) { | ||
| __extends(NotSupportWeakRefError, _super); | ||
| function NotSupportWeakRefError(api, message) { | ||
| return _super.call(this, "".concat(api, ": The current runtime does not support \"FinalizationRegistry\" and \"WeakRef\".").concat(message ? " ".concat(message) : '')) || this; | ||
| } | ||
| return NotSupportWeakRefError; | ||
| }(EmnapiError)); | ||
| Object.defineProperty(NotSupportWeakRefError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'NotSupportWeakRefError' | ||
| }); | ||
| var NotSupportBufferError = /*#__PURE__*/ (function (_super) { | ||
| __extends(NotSupportBufferError, _super); | ||
| function NotSupportBufferError(api, message) { | ||
| return _super.call(this, "".concat(api, ": The current runtime does not support \"Buffer\". Consider using buffer polyfill to make sure `globalThis.Buffer` is defined.").concat(message ? " ".concat(message) : '')) || this; | ||
| } | ||
| return NotSupportBufferError; | ||
| }(EmnapiError)); | ||
| Object.defineProperty(NotSupportBufferError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'NotSupportBufferError' | ||
| }); | ||
| var StrongRef = /*#__PURE__*/ (function () { | ||
| function StrongRef(value) { | ||
| this._value = value; | ||
| } | ||
| StrongRef.prototype.deref = function () { | ||
| return this._value; | ||
| }; | ||
| StrongRef.prototype.dispose = function () { | ||
| this._value = undefined; | ||
| }; | ||
| return StrongRef; | ||
| }()); | ||
| var Persistent = /*#__PURE__*/ (function () { | ||
| function Persistent(value) { | ||
| this._ref = new StrongRef(value); | ||
| } | ||
| Persistent.prototype.setWeak = function (param, callback) { | ||
| if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef) | ||
| return; | ||
| var value = this._ref.deref(); | ||
| try { | ||
| Persistent._registry.register(value, this, this); | ||
| var weakRef = new WeakRef(value); | ||
| this._ref.dispose(); | ||
| this._ref = weakRef; | ||
| this._param = param; | ||
| this._callback = callback; | ||
| } | ||
| catch (err) { | ||
| if (typeof value === 'symbol') ; | ||
| else { | ||
| throw err; | ||
| } | ||
| } | ||
| }; | ||
| Persistent.prototype.clearWeak = function () { | ||
| if (!supportFinalizer || this._ref === undefined) | ||
| return; | ||
| if (this._ref instanceof WeakRef) { | ||
| try { | ||
| Persistent._registry.unregister(this); | ||
| } | ||
| catch (_) { } | ||
| this._param = undefined; | ||
| this._callback = undefined; | ||
| var value = this._ref.deref(); | ||
| if (value === undefined) { | ||
| this._ref = value; | ||
| } | ||
| else { | ||
| this._ref = new StrongRef(value); | ||
| } | ||
| } | ||
| }; | ||
| Persistent.prototype.reset = function () { | ||
| if (supportFinalizer) { | ||
| try { | ||
| Persistent._registry.unregister(this); | ||
| } | ||
| catch (_) { } | ||
| } | ||
| this._param = undefined; | ||
| this._callback = undefined; | ||
| if (this._ref instanceof StrongRef) { | ||
| this._ref.dispose(); | ||
| } | ||
| this._ref = undefined; | ||
| }; | ||
| Persistent.prototype.isEmpty = function () { | ||
| return this._ref === undefined; | ||
| }; | ||
| Persistent.prototype.deref = function () { | ||
| if (this._ref === undefined) | ||
| return undefined; | ||
| return this._ref.deref(); | ||
| }; | ||
| Persistent._registry = supportFinalizer | ||
| ? new FinalizationRegistry(function (value) { | ||
| value._ref = undefined; | ||
| var callback = value._callback; | ||
| var param = value._param; | ||
| value._callback = undefined; | ||
| value._param = undefined; | ||
| if (typeof callback === 'function') { | ||
| callback(param); | ||
| } | ||
| }) | ||
| : undefined; | ||
| return Persistent; | ||
| }()); | ||
| var ReferenceOwnership; | ||
| (function (ReferenceOwnership) { | ||
| ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime"; | ||
| ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland"; | ||
| })(ReferenceOwnership || (ReferenceOwnership = {})); | ||
| function canBeHeldWeakly(value) { | ||
| return value.isObject() || value.isFunction() || value.isSymbol(); | ||
| } | ||
| var Reference = /*#__PURE__*/ (function (_super) { | ||
| __extends(Reference, _super); | ||
| function Reference(envObject, handle_id, initialRefcount, ownership) { | ||
| var _this = _super.call(this) || this; | ||
| _this.envObject = envObject; | ||
| _this._refcount = initialRefcount; | ||
| _this._ownership = ownership; | ||
| var handle = envObject.ctx.handleStore.get(handle_id); | ||
| _this.canBeWeak = canBeHeldWeakly(handle); | ||
| _this.persistent = new Persistent(handle.value); | ||
| _this.id = 0; | ||
| if (initialRefcount === 0) { | ||
| _this._setWeak(); | ||
| } | ||
| return _this; | ||
| } | ||
| Reference.weakCallback = function (ref) { | ||
| ref.persistent.reset(); | ||
| ref.invokeFinalizerFromGC(); | ||
| }; | ||
| Reference.create = function (envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) { | ||
| var ref = new Reference(envObject, handle_id, initialRefcount, ownership); | ||
| envObject.ctx.refStore.add(ref); | ||
| ref.link(envObject.reflist); | ||
| return ref; | ||
| }; | ||
| Reference.prototype.ref = function () { | ||
| if (this.persistent.isEmpty()) { | ||
| return 0; | ||
| } | ||
| if (++this._refcount === 1 && this.canBeWeak) { | ||
| this.persistent.clearWeak(); | ||
| } | ||
| return this._refcount; | ||
| }; | ||
| Reference.prototype.unref = function () { | ||
| if (this.persistent.isEmpty() || this._refcount === 0) { | ||
| return 0; | ||
| } | ||
| if (--this._refcount === 0) { | ||
| this._setWeak(); | ||
| } | ||
| return this._refcount; | ||
| }; | ||
| Reference.prototype.get = function (envObject) { | ||
| if (envObject === void 0) { envObject = this.envObject; } | ||
| if (this.persistent.isEmpty()) { | ||
| return 0; | ||
| } | ||
| var obj = this.persistent.deref(); | ||
| var handle = envObject.ensureHandle(obj); | ||
| return handle.id; | ||
| }; | ||
| /** @virtual */ | ||
| Reference.prototype.resetFinalizer = function () { }; | ||
| /** @virtual */ | ||
| Reference.prototype.data = function () { return 0; }; | ||
| Reference.prototype.refcount = function () { return this._refcount; }; | ||
| Reference.prototype.ownership = function () { return this._ownership; }; | ||
| /** @virtual */ | ||
| Reference.prototype.callUserFinalizer = function () { }; | ||
| /** @virtual */ | ||
| Reference.prototype.invokeFinalizerFromGC = function () { | ||
| this.finalize(); | ||
| }; | ||
| Reference.prototype._setWeak = function () { | ||
| if (this.canBeWeak) { | ||
| this.persistent.setWeak(this, Reference.weakCallback); | ||
| } | ||
| else { | ||
| this.persistent.reset(); | ||
| } | ||
| }; | ||
| Reference.prototype.finalize = function () { | ||
| this.persistent.reset(); | ||
| var deleteMe = this._ownership === ReferenceOwnership.kRuntime; | ||
| this.unlink(); | ||
| this.callUserFinalizer(); | ||
| if (deleteMe) { | ||
| this.dispose(); | ||
| } | ||
| }; | ||
| Reference.prototype.dispose = function () { | ||
| if (this.id === 0) | ||
| return; | ||
| this.unlink(); | ||
| this.persistent.reset(); | ||
| this.envObject.ctx.refStore.remove(this.id); | ||
| _super.prototype.dispose.call(this); | ||
| this.envObject = undefined; | ||
| this.id = 0; | ||
| }; | ||
| return Reference; | ||
| }(RefTracker)); | ||
| var ReferenceWithData = /*#__PURE__*/ (function (_super) { | ||
| __extends(ReferenceWithData, _super); | ||
| function ReferenceWithData(envObject, value, initialRefcount, ownership, _data) { | ||
| var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this; | ||
| _this._data = _data; | ||
| return _this; | ||
| } | ||
| ReferenceWithData.create = function (envObject, value, initialRefcount, ownership, data) { | ||
| var reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data); | ||
| envObject.ctx.refStore.add(reference); | ||
| reference.link(envObject.reflist); | ||
| return reference; | ||
| }; | ||
| ReferenceWithData.prototype.data = function () { | ||
| return this._data; | ||
| }; | ||
| return ReferenceWithData; | ||
| }(Reference)); | ||
| var ReferenceWithFinalizer = /*#__PURE__*/ (function (_super) { | ||
| __extends(ReferenceWithFinalizer, _super); | ||
| function ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this; | ||
| _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| return _this; | ||
| } | ||
| ReferenceWithFinalizer.create = function (envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| var reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint); | ||
| envObject.ctx.refStore.add(reference); | ||
| reference.link(envObject.finalizing_reflist); | ||
| return reference; | ||
| }; | ||
| ReferenceWithFinalizer.prototype.resetFinalizer = function () { | ||
| this._finalizer.resetFinalizer(); | ||
| }; | ||
| ReferenceWithFinalizer.prototype.data = function () { | ||
| return this._finalizer.data(); | ||
| }; | ||
| ReferenceWithFinalizer.prototype.callUserFinalizer = function () { | ||
| this._finalizer.callFinalizer(); | ||
| }; | ||
| ReferenceWithFinalizer.prototype.invokeFinalizerFromGC = function () { | ||
| this._finalizer.envObject.invokeFinalizerFromGC(this); | ||
| }; | ||
| ReferenceWithFinalizer.prototype.dispose = function () { | ||
| if (!this._finalizer) | ||
| return; | ||
| this._finalizer.envObject.dequeueFinalizer(this); | ||
| this._finalizer.dispose(); | ||
| _super.prototype.dispose.call(this); | ||
| this._finalizer = undefined; | ||
| }; | ||
| return ReferenceWithFinalizer; | ||
| }(Reference)); | ||
| var Deferred = /*#__PURE__*/ (function () { | ||
| function Deferred(ctx, value) { | ||
| this.id = 0; | ||
| this.ctx = ctx; | ||
| this.value = value; | ||
| } | ||
| Deferred.create = function (ctx, value) { | ||
| var deferred = new Deferred(ctx, value); | ||
| ctx.deferredStore.add(deferred); | ||
| return deferred; | ||
| }; | ||
| Deferred.prototype.resolve = function (value) { | ||
| this.value.resolve(value); | ||
| this.dispose(); | ||
| }; | ||
| Deferred.prototype.reject = function (reason) { | ||
| this.value.reject(reason); | ||
| this.dispose(); | ||
| }; | ||
| Deferred.prototype.dispose = function () { | ||
| this.ctx.deferredStore.remove(this.id); | ||
| this.id = 0; | ||
| this.value = null; | ||
| this.ctx = null; | ||
| }; | ||
| return Deferred; | ||
| }()); | ||
| var Store = /*#__PURE__*/ (function () { | ||
| function Store() { | ||
| this._values = [undefined]; | ||
| this._values.length = 4; | ||
| this._size = 1; | ||
| this._freeList = []; | ||
| } | ||
| Store.prototype.add = function (value) { | ||
| var id; | ||
| if (this._freeList.length) { | ||
| id = this._freeList.shift(); | ||
| } | ||
| else { | ||
| id = this._size; | ||
| this._size++; | ||
| var capacity = this._values.length; | ||
| if (id >= capacity) { | ||
| this._values.length = capacity + (capacity >> 1) + 16; | ||
| } | ||
| } | ||
| value.id = id; | ||
| this._values[id] = value; | ||
| }; | ||
| Store.prototype.get = function (id) { | ||
| return this._values[id]; | ||
| }; | ||
| Store.prototype.has = function (id) { | ||
| return this._values[id] !== undefined; | ||
| }; | ||
| Store.prototype.remove = function (id) { | ||
| var value = this._values[id]; | ||
| if (value) { | ||
| value.id = 0; | ||
| this._values[id] = undefined; | ||
| this._freeList.push(Number(id)); | ||
| } | ||
| }; | ||
| Store.prototype.dispose = function () { | ||
| for (var i = 1; i < this._size; ++i) { | ||
| var value = this._values[i]; | ||
| value === null || value === void 0 ? void 0 : value.dispose(); | ||
| } | ||
| this._values = [undefined]; | ||
| this._size = 1; | ||
| this._freeList = []; | ||
| }; | ||
| return Store; | ||
| }()); | ||
| var kMaxReasonableBytes = BigInt(1) << BigInt(60); | ||
| var kMinReasonableBytes = -kMaxReasonableBytes; | ||
| var ExternalMemory = /*#__PURE__*/ (function () { | ||
| function ExternalMemory(onChange) { | ||
| this.total = BigInt(0); | ||
| this.onChange = onChange !== null && onChange !== void 0 ? onChange : null; | ||
| } | ||
| ExternalMemory.prototype.adjust = function (changeInBytes) { | ||
| changeInBytes = BigInt(changeInBytes); | ||
| if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) { | ||
| throw new RangeError("changeInBytes ".concat(changeInBytes, " is out of reasonable range")); | ||
| } | ||
| var old = this.total; | ||
| this.total += changeInBytes; | ||
| var amount = this.total; | ||
| var onChange = this.onChange; | ||
| if (changeInBytes) { | ||
| onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes); | ||
| } | ||
| return amount; | ||
| }; | ||
| return ExternalMemory; | ||
| }()); | ||
| var CleanupHookCallback = /*#__PURE__*/ (function () { | ||
| function CleanupHookCallback(envObject, fn, arg, order) { | ||
| this.envObject = envObject; | ||
| this.fn = fn; | ||
| this.arg = arg; | ||
| this.order = order; | ||
| } | ||
| return CleanupHookCallback; | ||
| }()); | ||
| var CleanupQueue = /*#__PURE__*/ (function () { | ||
| function CleanupQueue() { | ||
| this._cleanupHooks = []; | ||
| this._cleanupHookCounter = 0; | ||
| } | ||
| CleanupQueue.prototype.empty = function () { | ||
| return this._cleanupHooks.length === 0; | ||
| }; | ||
| CleanupQueue.prototype.add = function (envObject, fn, arg) { | ||
| if (this._cleanupHooks.filter(function (hook) { return (hook.envObject === envObject && hook.fn === fn && hook.arg === arg); }).length > 0) { | ||
| throw new Error('Can not add same fn and arg twice'); | ||
| } | ||
| this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++)); | ||
| }; | ||
| CleanupQueue.prototype.remove = function (envObject, fn, arg) { | ||
| for (var i = 0; i < this._cleanupHooks.length; ++i) { | ||
| var hook = this._cleanupHooks[i]; | ||
| if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) { | ||
| this._cleanupHooks.splice(i, 1); | ||
| return; | ||
| } | ||
| } | ||
| }; | ||
| CleanupQueue.prototype.drain = function () { | ||
| var hooks = this._cleanupHooks.slice(); | ||
| hooks.sort(function (a, b) { return (b.order - a.order); }); | ||
| for (var i = 0; i < hooks.length; ++i) { | ||
| var cb = hooks[i]; | ||
| if (typeof cb.fn === 'number') { | ||
| cb.envObject.makeDynCall_vp(cb.fn)(cb.arg); | ||
| } | ||
| else { | ||
| cb.fn(cb.arg); | ||
| } | ||
| this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1); | ||
| } | ||
| }; | ||
| CleanupQueue.prototype.dispose = function () { | ||
| this._cleanupHooks.length = 0; | ||
| this._cleanupHookCounter = 0; | ||
| }; | ||
| return CleanupQueue; | ||
| }()); | ||
| var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () { | ||
| function NodejsWaitingRequestCounter() { | ||
| this.refHandle = new _MessageChannel().port1; | ||
| this.count = 0; | ||
| } | ||
| NodejsWaitingRequestCounter.prototype.increase = function () { | ||
| if (this.count === 0) { | ||
| if (this.refHandle.ref) { | ||
| this.refHandle.ref(); | ||
| } | ||
| } | ||
| this.count++; | ||
| }; | ||
| NodejsWaitingRequestCounter.prototype.decrease = function () { | ||
| if (this.count === 0) | ||
| return; | ||
| if (this.count === 1) { | ||
| if (this.refHandle.unref) { | ||
| this.refHandle.unref(); | ||
| } | ||
| } | ||
| this.count--; | ||
| }; | ||
| return NodejsWaitingRequestCounter; | ||
| }()); | ||
| var Context = /*#__PURE__*/ (function () { | ||
| function Context(options) { | ||
| var _this = this; | ||
| this._isStopping = false; | ||
| this._canCallIntoJs = true; | ||
| this._suppressDestroy = false; | ||
| this.envStore = new Store(); | ||
| this.scopeStore = new ScopeStore(); | ||
| this.refStore = new Store(); | ||
| this.deferredStore = new Store(); | ||
| this.handleStore = new HandleStore(); | ||
| this.feature = { | ||
| supportReflect: supportReflect, | ||
| supportFinalizer: supportFinalizer, | ||
| supportWeakSymbol: supportWeakSymbol, | ||
| supportBigInt: supportBigInt, | ||
| supportNewFunction: supportNewFunction, | ||
| canSetFunctionName: canSetFunctionName, | ||
| setImmediate: _setImmediate, | ||
| Buffer: _Buffer, | ||
| MessageChannel: _MessageChannel | ||
| }; | ||
| this.cleanupQueue = new CleanupQueue(); | ||
| this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange); | ||
| if (typeof process === 'object' && process !== null && typeof process.once === 'function') { | ||
| this.refCounter = new NodejsWaitingRequestCounter(); | ||
| process.once('beforeExit', function () { | ||
| if (!_this._suppressDestroy) { | ||
| _this.destroy(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| /** | ||
| * Suppress the destroy on `beforeExit` event in Node.js. | ||
| * Call this method if you want to keep the context and | ||
| * all associated {@link Env | Env} alive, | ||
| * this also means that cleanup hooks will not be called. | ||
| * After call this method, you should call | ||
| * {@link Context.destroy | `Context.prototype.destroy`} method manually. | ||
| */ | ||
| Context.prototype.suppressDestroy = function () { | ||
| this._suppressDestroy = true; | ||
| }; | ||
| // eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
| Context.prototype.getRuntimeVersions = function () { | ||
| return { | ||
| version: version, | ||
| NODE_API_SUPPORTED_VERSION_MAX: NODE_API_SUPPORTED_VERSION_MAX, | ||
| NAPI_VERSION_EXPERIMENTAL: NAPI_VERSION_EXPERIMENTAL, | ||
| NODE_API_DEFAULT_MODULE_API_VERSION: NODE_API_DEFAULT_MODULE_API_VERSION | ||
| }; | ||
| }; | ||
| Context.prototype.createNotSupportWeakRefError = function (api, message) { | ||
| return new NotSupportWeakRefError(api, message); | ||
| }; | ||
| Context.prototype.createNotSupportBufferError = function (api, message) { | ||
| return new NotSupportBufferError(api, message); | ||
| }; | ||
| Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership) { | ||
| return Reference.create(envObject, handle_id, initialRefcount, ownership); | ||
| }; | ||
| Context.prototype.createReferenceWithData = function (envObject, handle_id, initialRefcount, ownership, data) { | ||
| return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data); | ||
| }; | ||
| Context.prototype.createReferenceWithFinalizer = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| if (finalize_callback === void 0) { finalize_callback = 0; } | ||
| if (finalize_data === void 0) { finalize_data = 0; } | ||
| if (finalize_hint === void 0) { finalize_hint = 0; } | ||
| return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint); | ||
| }; | ||
| Context.prototype.createDeferred = function (value) { | ||
| return Deferred.create(this, value); | ||
| }; | ||
| Context.prototype.adjustAmountOfExternalAllocatedMemory = function (changeInBytes) { | ||
| return this._externalMemory.adjust(changeInBytes); | ||
| }; | ||
| Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding); | ||
| }; | ||
| Context.prototype.createTrackedFinalizer = function (envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| }; | ||
| Context.prototype.getCurrentScope = function () { | ||
| return this.scopeStore.currentScope; | ||
| }; | ||
| Context.prototype.addToCurrentScope = function (value) { | ||
| return this.scopeStore.currentScope.add(value); | ||
| }; | ||
| Context.prototype.openScope = function (envObject) { | ||
| var scope = this.scopeStore.openScope(this.handleStore); | ||
| if (envObject) | ||
| envObject.openHandleScopes++; | ||
| return scope; | ||
| }; | ||
| Context.prototype.closeScope = function (envObject, _scope) { | ||
| if (envObject && envObject.openHandleScopes === 0) | ||
| return; | ||
| this.scopeStore.closeScope(); | ||
| if (envObject) | ||
| envObject.openHandleScopes--; | ||
| }; | ||
| Context.prototype.ensureHandle = function (value) { | ||
| switch (value) { | ||
| case undefined: return HandleStore.UNDEFINED; | ||
| case null: return HandleStore.NULL; | ||
| case true: return HandleStore.TRUE; | ||
| case false: return HandleStore.FALSE; | ||
| case _global: return HandleStore.GLOBAL; | ||
| } | ||
| return this.addToCurrentScope(value); | ||
| }; | ||
| Context.prototype.addCleanupHook = function (envObject, fn, arg) { | ||
| this.cleanupQueue.add(envObject, fn, arg); | ||
| }; | ||
| Context.prototype.removeCleanupHook = function (envObject, fn, arg) { | ||
| this.cleanupQueue.remove(envObject, fn, arg); | ||
| }; | ||
| Context.prototype.runCleanup = function () { | ||
| while (!this.cleanupQueue.empty()) { | ||
| this.cleanupQueue.drain(); | ||
| } | ||
| }; | ||
| Context.prototype.increaseWaitingRequestCounter = function () { | ||
| var _a; | ||
| (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase(); | ||
| }; | ||
| Context.prototype.decreaseWaitingRequestCounter = function () { | ||
| var _a; | ||
| (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease(); | ||
| }; | ||
| Context.prototype.setCanCallIntoJs = function (value) { | ||
| this._canCallIntoJs = value; | ||
| }; | ||
| Context.prototype.setStopping = function (value) { | ||
| this._isStopping = value; | ||
| }; | ||
| Context.prototype.canCallIntoJs = function () { | ||
| return this._canCallIntoJs && !this._isStopping; | ||
| }; | ||
| /** | ||
| * Destroy the context and call cleanup hooks. | ||
| * Associated {@link Env | Env} will be destroyed. | ||
| */ | ||
| Context.prototype.destroy = function () { | ||
| this.setStopping(true); | ||
| this.setCanCallIntoJs(false); | ||
| this.runCleanup(); | ||
| }; | ||
| return Context; | ||
| }()); | ||
| var defaultContext; | ||
| function createContext(options) { | ||
| return new Context(options); | ||
| } | ||
| function getDefaultContext() { | ||
| if (!defaultContext) { | ||
| defaultContext = createContext(); | ||
| } | ||
| return defaultContext; | ||
| } | ||
| export { ConstHandle, Context, Deferred, EmnapiError, Env, External, Finalizer, Handle, HandleScope, HandleStore, NAPI_VERSION_EXPERIMENTAL, NODE_API_DEFAULT_MODULE_API_VERSION, NODE_API_SUPPORTED_VERSION_MAX, NODE_API_SUPPORTED_VERSION_MIN, NodeEnv, NotSupportBufferError, NotSupportWeakRefError, Persistent, RefTracker, Reference, ReferenceOwnership, ReferenceWithData, ReferenceWithFinalizer, ScopeStore, Store, TrackedFinalizer, TryCatch, createContext, getDefaultContext, getExternalValue, isExternal, isReferenceType, version }; |
| declare namespace emnapi { | ||
| export type CleanupHookCallbackFunction = number | ((arg: number) => void); | ||
| export class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> { | ||
| constructor(id: number, value: S); | ||
| dispose(): void; | ||
| } | ||
| export class Context { | ||
| private _isStopping; | ||
| private _canCallIntoJs; | ||
| private _suppressDestroy; | ||
| envStore: Store<Env>; | ||
| scopeStore: ScopeStore; | ||
| refStore: Store<Reference>; | ||
| deferredStore: Store<Deferred<any>>; | ||
| handleStore: HandleStore; | ||
| private readonly refCounter?; | ||
| private readonly cleanupQueue; | ||
| private readonly _externalMemory; | ||
| feature: { | ||
| supportReflect: boolean; | ||
| supportFinalizer: boolean; | ||
| supportWeakSymbol: boolean; | ||
| supportBigInt: boolean; | ||
| supportNewFunction: boolean; | ||
| canSetFunctionName: boolean; | ||
| setImmediate: (callback: () => void) => void; | ||
| Buffer: BufferCtor | undefined; | ||
| MessageChannel: { | ||
| new (): MessageChannel; | ||
| prototype: MessageChannel; | ||
| } | undefined; | ||
| }; | ||
| constructor(options?: ContextOptions); | ||
| /** | ||
| * Suppress the destroy on `beforeExit` event in Node.js. | ||
| * Call this method if you want to keep the context and | ||
| * all associated {@link Env | Env} alive, | ||
| * this also means that cleanup hooks will not be called. | ||
| * After call this method, you should call | ||
| * {@link Context.destroy | `Context.prototype.destroy`} method manually. | ||
| */ | ||
| suppressDestroy(): void; | ||
| getRuntimeVersions(): { | ||
| version: string; | ||
| NODE_API_SUPPORTED_VERSION_MAX: Version; | ||
| NAPI_VERSION_EXPERIMENTAL: Version; | ||
| NODE_API_DEFAULT_MODULE_API_VERSION: Version; | ||
| }; | ||
| createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError; | ||
| createNotSupportBufferError(api: string, message: string): NotSupportBufferError; | ||
| createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference; | ||
| createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference; | ||
| createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference; | ||
| createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>; | ||
| adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint; | ||
| 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; | ||
| createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer; | ||
| getCurrentScope(): HandleScope | null; | ||
| addToCurrentScope<V>(value: V): Handle<V>; | ||
| openScope(envObject?: Env): HandleScope; | ||
| closeScope(envObject?: Env, _scope?: HandleScope): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
| removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
| runCleanup(): void; | ||
| increaseWaitingRequestCounter(): void; | ||
| decreaseWaitingRequestCounter(): void; | ||
| setCanCallIntoJs(value: boolean): void; | ||
| setStopping(value: boolean): void; | ||
| canCallIntoJs(): boolean; | ||
| /** | ||
| * Destroy the context and call cleanup hooks. | ||
| * Associated {@link Env | Env} will be destroyed. | ||
| */ | ||
| destroy(): void; | ||
| } | ||
| export interface ContextOptions { | ||
| onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any; | ||
| } | ||
| export function createContext(options?: ContextOptions): Context; | ||
| export class Deferred<T = any> implements IStoreValue { | ||
| static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred; | ||
| id: number; | ||
| ctx: Context; | ||
| value: IDeferrdValue<T>; | ||
| constructor(ctx: Context, value: IDeferrdValue<T>); | ||
| resolve(value: T): void; | ||
| reject(reason?: any): void; | ||
| dispose(): void; | ||
| } | ||
| export class EmnapiError extends Error { | ||
| constructor(message?: string); | ||
| } | ||
| export abstract class Env implements IStoreValue { | ||
| readonly 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; | ||
| id: number; | ||
| openHandleScopes: number; | ||
| instanceData: TrackedFinalizer | null; | ||
| tryCatch: TryCatch; | ||
| refs: number; | ||
| reflist: RefTracker; | ||
| finalizing_reflist: RefTracker; | ||
| pendingFinalizers: RefTracker[]; | ||
| lastError: { | ||
| errorCode: napi_status; | ||
| engineErrorCode: number; | ||
| engineReserved: Ptr; | ||
| }; | ||
| inGcFinalizer: boolean; | ||
| 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); | ||
| /** @virtual */ | ||
| canCallIntoJs(): boolean; | ||
| terminatedOrTerminating(): boolean; | ||
| ref(): void; | ||
| unref(): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| ensureHandleId(value: any): napi_value; | ||
| clearLastError(): napi_status; | ||
| setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status; | ||
| getReturnStatus(): napi_status; | ||
| callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T; | ||
| /** @virtual */ | ||
| abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| invokeFinalizerFromGC(finalizer: RefTracker): void; | ||
| checkGCAccess(): void; | ||
| /** @virtual */ | ||
| enqueueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| dequeueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| deleteMe(): void; | ||
| dispose(): void; | ||
| private readonly _bindingMap; | ||
| initObjectBinding<S extends object>(value: S): IReferenceBinding; | ||
| getObjectBinding<S extends object>(value: S): IReferenceBinding; | ||
| setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void; | ||
| getInstanceData(): number; | ||
| } | ||
| /** @public */ | ||
| interface External_2 extends Record<any, any> { | ||
| } | ||
| /** @public */ | ||
| const External_2: { | ||
| new (value: number | bigint): External_2; | ||
| prototype: null; | ||
| }; | ||
| export { External_2 as External } | ||
| export class Finalizer { | ||
| envObject: Env; | ||
| private _finalizeCallback; | ||
| private _finalizeData; | ||
| private _finalizeHint; | ||
| private _makeDynCall_vppp; | ||
| constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p); | ||
| callback(): napi_finalize; | ||
| data(): void_p; | ||
| hint(): void_p; | ||
| resetEnv(): void; | ||
| resetFinalizer(): void; | ||
| callFinalizer(): void; | ||
| dispose(): void; | ||
| } | ||
| export function getDefaultContext(): Context; | ||
| /** @public */ | ||
| export function getExternalValue(external: External_2): number | bigint; | ||
| export class Handle<S> { | ||
| id: number; | ||
| value: S; | ||
| constructor(id: number, value: S); | ||
| data(): void_p; | ||
| isNumber(): boolean; | ||
| isBigInt(): boolean; | ||
| isString(): boolean; | ||
| isFunction(): boolean; | ||
| isExternal(): boolean; | ||
| isObject(): boolean; | ||
| isArray(): boolean; | ||
| isArrayBuffer(): boolean; | ||
| isTypedArray(): boolean; | ||
| isBuffer(BufferConstructor?: BufferCtor): boolean; | ||
| isDataView(): boolean; | ||
| isDate(): boolean; | ||
| isPromise(): boolean; | ||
| isBoolean(): boolean; | ||
| isUndefined(): boolean; | ||
| isSymbol(): boolean; | ||
| isNull(): boolean; | ||
| dispose(): void; | ||
| } | ||
| export class HandleScope { | ||
| handleStore: HandleStore; | ||
| id: number; | ||
| parent: HandleScope | null; | ||
| child: HandleScope | null; | ||
| start: number; | ||
| end: number; | ||
| private _escapeCalled; | ||
| callbackInfo: ICallbackInfo; | ||
| constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number); | ||
| add<V>(value: V): Handle<V>; | ||
| addExternal(data: void_p): Handle<object>; | ||
| dispose(): void; | ||
| escape(handle: number): Handle<any> | null; | ||
| escapeCalled(): boolean; | ||
| } | ||
| export class HandleStore { | ||
| static UNDEFINED: ConstHandle<undefined>; | ||
| static NULL: ConstHandle<null>; | ||
| static FALSE: ConstHandle<false>; | ||
| static TRUE: ConstHandle<true>; | ||
| static GLOBAL: ConstHandle<typeof globalThis>; | ||
| static MIN_ID: 6; | ||
| private readonly _values; | ||
| private _next; | ||
| push<S>(value: S): Handle<S>; | ||
| erase(start: number, end: number): void; | ||
| get(id: Ptr): Handle<any> | undefined; | ||
| swap(a: number, b: number): void; | ||
| dispose(): void; | ||
| } | ||
| export interface ICallbackInfo { | ||
| thiz: any; | ||
| data: void_p; | ||
| args: ArrayLike<any>; | ||
| fn: Function; | ||
| } | ||
| export interface IDeferrdValue<T = any> { | ||
| resolve: (value: T) => void; | ||
| reject: (reason?: any) => void; | ||
| } | ||
| export interface IReferenceBinding { | ||
| wrapped: number; | ||
| tag: Uint32Array | null; | ||
| } | ||
| /** @public */ | ||
| export function isExternal(object: unknown): object is External_2; | ||
| export function isReferenceType(v: any): v is object; | ||
| export interface IStoreValue { | ||
| id: number; | ||
| dispose(): void; | ||
| [x: string]: any; | ||
| } | ||
| export const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL; | ||
| export const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| export const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX; | ||
| export const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN; | ||
| export class NodeEnv extends Env { | ||
| filename: string; | ||
| private readonly nodeBinding?; | ||
| destructing: boolean; | ||
| finalizationScheduled: boolean; | ||
| 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); | ||
| deleteMe(): void; | ||
| canCallIntoJs(): boolean; | ||
| triggerFatalException(err: any): void; | ||
| callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T; | ||
| callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| enqueueFinalizer(finalizer: RefTracker): void; | ||
| drainFinalizerQueue(): void; | ||
| } | ||
| export class NotSupportBufferError extends EmnapiError { | ||
| constructor(api: string, message: string); | ||
| } | ||
| export class NotSupportWeakRefError extends EmnapiError { | ||
| constructor(api: string, message: string); | ||
| } | ||
| export class Persistent<T> { | ||
| private _ref; | ||
| private _param; | ||
| private _callback; | ||
| private static readonly _registry; | ||
| constructor(value: T); | ||
| setWeak<P>(param: P, callback: (param: P) => void): void; | ||
| clearWeak(): void; | ||
| reset(): void; | ||
| isEmpty(): boolean; | ||
| deref(): T | undefined; | ||
| } | ||
| export class Reference extends RefTracker implements IStoreValue { | ||
| private static weakCallback; | ||
| id: number; | ||
| envObject: Env; | ||
| private readonly canBeWeak; | ||
| private _refcount; | ||
| private readonly _ownership; | ||
| persistent: Persistent<object>; | ||
| static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference; | ||
| protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership); | ||
| ref(): number; | ||
| unref(): number; | ||
| get(envObject?: Env): napi_value; | ||
| /** @virtual */ | ||
| resetFinalizer(): void; | ||
| /** @virtual */ | ||
| data(): void_p; | ||
| refcount(): number; | ||
| ownership(): ReferenceOwnership; | ||
| /** @virtual */ | ||
| protected callUserFinalizer(): void; | ||
| /** @virtual */ | ||
| protected invokeFinalizerFromGC(): void; | ||
| private _setWeak; | ||
| finalize(): void; | ||
| dispose(): void; | ||
| } | ||
| export enum ReferenceOwnership { | ||
| kRuntime = 0, | ||
| kUserland = 1 | ||
| } | ||
| export class ReferenceWithData extends Reference { | ||
| private readonly _data; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData; | ||
| private constructor(); | ||
| data(): void_p; | ||
| } | ||
| export class ReferenceWithFinalizer extends Reference { | ||
| private _finalizer; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer; | ||
| private constructor(); | ||
| resetFinalizer(): void; | ||
| data(): void_p; | ||
| protected callUserFinalizer(): void; | ||
| protected invokeFinalizerFromGC(): void; | ||
| dispose(): void; | ||
| } | ||
| export class RefTracker { | ||
| /** @virtual */ | ||
| dispose(): void; | ||
| /** @virtual */ | ||
| finalize(): void; | ||
| private _next; | ||
| private _prev; | ||
| link(list: RefTracker): void; | ||
| unlink(): void; | ||
| static finalizeAll(list: RefTracker): void; | ||
| } | ||
| export class ScopeStore { | ||
| private readonly _rootScope; | ||
| currentScope: HandleScope; | ||
| private readonly _values; | ||
| constructor(); | ||
| get(id: number): HandleScope | undefined; | ||
| openScope(handleStore: HandleStore): HandleScope; | ||
| closeScope(): void; | ||
| dispose(): void; | ||
| } | ||
| export class Store<V extends IStoreValue> { | ||
| protected _values: Array<V | undefined>; | ||
| private _freeList; | ||
| private _size; | ||
| constructor(); | ||
| add(value: V): void; | ||
| get(id: Ptr): V | undefined; | ||
| has(id: Ptr): boolean; | ||
| remove(id: Ptr): void; | ||
| dispose(): void; | ||
| } | ||
| export class TrackedFinalizer extends RefTracker { | ||
| private _finalizer; | ||
| static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer; | ||
| private constructor(); | ||
| data(): void_p; | ||
| dispose(): void; | ||
| finalize(): void; | ||
| } | ||
| export class TryCatch { | ||
| private _exception; | ||
| private _caught; | ||
| isEmpty(): boolean; | ||
| hasCaught(): boolean; | ||
| exception(): any; | ||
| setError(err: any): void; | ||
| reset(): void; | ||
| extractException(): any; | ||
| } | ||
| export const version: string; | ||
| } |
-1509
| var emnapi = (function (exports) { | ||
| /****************************************************************************** | ||
| Copyright (c) Microsoft Corporation. | ||
| Permission to use, copy, modify, and/or distribute this software for any | ||
| purpose with or without fee is hereby granted. | ||
| THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
| REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
| INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
| LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
| OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
| PERFORMANCE OF THIS SOFTWARE. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ | ||
| var extendStatics = function(d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| function __extends(d, b) { | ||
| if (typeof b !== "function" && b !== null) | ||
| throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| } | ||
| typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { | ||
| var e = new Error(message); | ||
| return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; | ||
| }; | ||
| var externalValue = new WeakMap(); | ||
| /** @public */ | ||
| function isExternal(object) { | ||
| return externalValue.has(object); | ||
| } | ||
| /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare | ||
| var External = (function () { | ||
| function External(value) { | ||
| Object.setPrototypeOf(this, null); | ||
| externalValue.set(this, value); | ||
| } | ||
| External.prototype = null; | ||
| return External; | ||
| })(); | ||
| /** @public */ | ||
| function getExternalValue(external) { | ||
| if (!isExternal(external)) { | ||
| throw new TypeError('not external'); | ||
| } | ||
| return externalValue.get(external); | ||
| } | ||
| var supportNewFunction = /*#__PURE__*/ (function () { | ||
| var f; | ||
| try { | ||
| f = new Function(); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| return typeof f === 'function'; | ||
| })(); | ||
| var _global = /*#__PURE__*/ (function () { | ||
| if (typeof globalThis !== 'undefined') | ||
| return globalThis; | ||
| var g = (function () { return this; })(); | ||
| if (!g && supportNewFunction) { | ||
| try { | ||
| g = new Function('return this')(); | ||
| } | ||
| catch (_) { } | ||
| } | ||
| if (!g) { | ||
| if (typeof __webpack_public_path__ === 'undefined') { | ||
| if (typeof global !== 'undefined') | ||
| return global; | ||
| } | ||
| if (typeof window !== 'undefined') | ||
| return window; | ||
| if (typeof self !== 'undefined') | ||
| return self; | ||
| } | ||
| return g; | ||
| })(); | ||
| var TryCatch = /*#__PURE__*/ (function () { | ||
| function TryCatch() { | ||
| this._exception = undefined; | ||
| this._caught = false; | ||
| } | ||
| TryCatch.prototype.isEmpty = function () { | ||
| return !this._caught; | ||
| }; | ||
| TryCatch.prototype.hasCaught = function () { | ||
| return this._caught; | ||
| }; | ||
| TryCatch.prototype.exception = function () { | ||
| return this._exception; | ||
| }; | ||
| TryCatch.prototype.setError = function (err) { | ||
| this._caught = true; | ||
| this._exception = err; | ||
| }; | ||
| TryCatch.prototype.reset = function () { | ||
| this._caught = false; | ||
| this._exception = undefined; | ||
| }; | ||
| TryCatch.prototype.extractException = function () { | ||
| var e = this._exception; | ||
| this.reset(); | ||
| return e; | ||
| }; | ||
| return TryCatch; | ||
| }()); | ||
| var canSetFunctionName = /*#__PURE__*/ (function () { | ||
| var _a; | ||
| try { | ||
| return Boolean((_a = Object.getOwnPropertyDescriptor(Function.prototype, 'name')) === null || _a === void 0 ? void 0 : _a.configurable); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| })(); | ||
| var supportReflect = typeof Reflect === 'object'; | ||
| var supportFinalizer = (typeof FinalizationRegistry !== 'undefined') && (typeof WeakRef !== 'undefined'); | ||
| var supportWeakSymbol = /*#__PURE__*/ (function () { | ||
| try { | ||
| // eslint-disable-next-line symbol-description | ||
| var sym = Symbol(); | ||
| // eslint-disable-next-line no-new | ||
| new WeakRef(sym); | ||
| new WeakMap().set(sym, undefined); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| return true; | ||
| })(); | ||
| var supportBigInt = typeof BigInt !== 'undefined'; | ||
| function isReferenceType(v) { | ||
| return (typeof v === 'object' && v !== null) || typeof v === 'function'; | ||
| } | ||
| var _require = /*#__PURE__*/ (function () { | ||
| var nativeRequire; | ||
| if (typeof __webpack_public_path__ !== 'undefined') { | ||
| nativeRequire = (function () { | ||
| return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined; | ||
| })(); | ||
| } | ||
| else { | ||
| nativeRequire = (function () { | ||
| return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined); | ||
| })(); | ||
| } | ||
| return nativeRequire; | ||
| })(); | ||
| var _MessageChannel = typeof MessageChannel === 'function' | ||
| ? MessageChannel | ||
| : /*#__PURE__*/ (function () { | ||
| try { | ||
| return _require('worker_threads').MessageChannel; | ||
| } | ||
| catch (_) { } | ||
| return undefined; | ||
| })(); | ||
| var _setImmediate = typeof setImmediate === 'function' | ||
| ? setImmediate | ||
| : function (callback) { | ||
| if (typeof callback !== 'function') { | ||
| throw new TypeError('The "callback" argument must be of type function'); | ||
| } | ||
| if (_MessageChannel) { | ||
| var channel_1 = new _MessageChannel(); | ||
| channel_1.port1.onmessage = function () { | ||
| channel_1.port1.onmessage = null; | ||
| channel_1 = undefined; | ||
| callback(); | ||
| }; | ||
| channel_1.port2.postMessage(null); | ||
| } | ||
| else { | ||
| setTimeout(callback, 0); | ||
| } | ||
| }; | ||
| var _Buffer = typeof Buffer === 'function' | ||
| ? Buffer | ||
| : /*#__PURE__*/ (function () { | ||
| try { | ||
| return _require('buffer').Buffer; | ||
| } | ||
| catch (_) { } | ||
| return undefined; | ||
| })(); | ||
| var version = "1.10.0"; | ||
| var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */; | ||
| var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */; | ||
| var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */; | ||
| var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */; | ||
| var Handle = /*#__PURE__*/ (function () { | ||
| function Handle(id, value) { | ||
| this.id = id; | ||
| this.value = value; | ||
| } | ||
| Handle.prototype.data = function () { | ||
| return getExternalValue(this.value); | ||
| }; | ||
| Handle.prototype.isNumber = function () { | ||
| return typeof this.value === 'number'; | ||
| }; | ||
| Handle.prototype.isBigInt = function () { | ||
| return typeof this.value === 'bigint'; | ||
| }; | ||
| Handle.prototype.isString = function () { | ||
| return typeof this.value === 'string'; | ||
| }; | ||
| Handle.prototype.isFunction = function () { | ||
| return typeof this.value === 'function'; | ||
| }; | ||
| Handle.prototype.isExternal = function () { | ||
| return isExternal(this.value); | ||
| }; | ||
| Handle.prototype.isObject = function () { | ||
| return typeof this.value === 'object' && this.value !== null; | ||
| }; | ||
| Handle.prototype.isArray = function () { | ||
| return Array.isArray(this.value); | ||
| }; | ||
| Handle.prototype.isArrayBuffer = function () { | ||
| return (this.value instanceof ArrayBuffer); | ||
| }; | ||
| Handle.prototype.isTypedArray = function () { | ||
| return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView); | ||
| }; | ||
| Handle.prototype.isBuffer = function (BufferConstructor) { | ||
| if (ArrayBuffer.isView(this.value)) | ||
| return true; | ||
| BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer); | ||
| return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value); | ||
| }; | ||
| Handle.prototype.isDataView = function () { | ||
| return (this.value instanceof DataView); | ||
| }; | ||
| Handle.prototype.isDate = function () { | ||
| return (this.value instanceof Date); | ||
| }; | ||
| Handle.prototype.isPromise = function () { | ||
| return (this.value instanceof Promise); | ||
| }; | ||
| Handle.prototype.isBoolean = function () { | ||
| return typeof this.value === 'boolean'; | ||
| }; | ||
| Handle.prototype.isUndefined = function () { | ||
| return this.value === undefined; | ||
| }; | ||
| Handle.prototype.isSymbol = function () { | ||
| return typeof this.value === 'symbol'; | ||
| }; | ||
| Handle.prototype.isNull = function () { | ||
| return this.value === null; | ||
| }; | ||
| Handle.prototype.dispose = function () { | ||
| this.value = undefined; | ||
| }; | ||
| return Handle; | ||
| }()); | ||
| var ConstHandle = /*#__PURE__*/ (function (_super) { | ||
| __extends(ConstHandle, _super); | ||
| function ConstHandle(id, value) { | ||
| return _super.call(this, id, value) || this; | ||
| } | ||
| ConstHandle.prototype.dispose = function () { }; | ||
| return ConstHandle; | ||
| }(Handle)); | ||
| var HandleStore = /*#__PURE__*/ (function () { | ||
| function HandleStore() { | ||
| this._values = [ | ||
| undefined, | ||
| HandleStore.UNDEFINED, | ||
| HandleStore.NULL, | ||
| HandleStore.FALSE, | ||
| HandleStore.TRUE, | ||
| HandleStore.GLOBAL | ||
| ]; | ||
| this._next = HandleStore.MIN_ID; | ||
| } | ||
| HandleStore.prototype.push = function (value) { | ||
| var h; | ||
| var next = this._next; | ||
| var values = this._values; | ||
| if (next < values.length) { | ||
| h = values[next]; | ||
| h.value = value; | ||
| } | ||
| else { | ||
| h = new Handle(next, value); | ||
| values[next] = h; | ||
| } | ||
| this._next++; | ||
| return h; | ||
| }; | ||
| HandleStore.prototype.erase = function (start, end) { | ||
| this._next = start; | ||
| var values = this._values; | ||
| for (var i = start; i < end; ++i) { | ||
| values[i].dispose(); | ||
| } | ||
| }; | ||
| HandleStore.prototype.get = function (id) { | ||
| return this._values[id]; | ||
| }; | ||
| HandleStore.prototype.swap = function (a, b) { | ||
| var values = this._values; | ||
| var h = values[a]; | ||
| values[a] = values[b]; | ||
| values[a].id = Number(a); | ||
| values[b] = h; | ||
| h.id = Number(b); | ||
| }; | ||
| HandleStore.prototype.dispose = function () { | ||
| this._values.length = HandleStore.MIN_ID; | ||
| this._next = HandleStore.MIN_ID; | ||
| }; | ||
| HandleStore.UNDEFINED = new ConstHandle(1 /* GlobalHandle.UNDEFINED */, undefined); | ||
| HandleStore.NULL = new ConstHandle(2 /* GlobalHandle.NULL */, null); | ||
| HandleStore.FALSE = new ConstHandle(3 /* GlobalHandle.FALSE */, false); | ||
| HandleStore.TRUE = new ConstHandle(4 /* GlobalHandle.TRUE */, true); | ||
| HandleStore.GLOBAL = new ConstHandle(5 /* GlobalHandle.GLOBAL */, _global); | ||
| HandleStore.MIN_ID = 6; | ||
| return HandleStore; | ||
| }()); | ||
| var HandleScope = /*#__PURE__*/ (function () { | ||
| function HandleScope(handleStore, id, parentScope, start, end) { | ||
| if (end === void 0) { end = start; } | ||
| this.handleStore = handleStore; | ||
| this.id = id; | ||
| this.parent = parentScope; | ||
| this.child = null; | ||
| if (parentScope !== null) | ||
| parentScope.child = this; | ||
| this.start = start; | ||
| this.end = end; | ||
| this._escapeCalled = false; | ||
| this.callbackInfo = { | ||
| thiz: undefined, | ||
| data: 0, | ||
| args: undefined, | ||
| fn: undefined | ||
| }; | ||
| } | ||
| HandleScope.prototype.add = function (value) { | ||
| var h = this.handleStore.push(value); | ||
| this.end++; | ||
| return h; | ||
| }; | ||
| HandleScope.prototype.addExternal = function (data) { | ||
| return this.add(new External(data)); | ||
| }; | ||
| HandleScope.prototype.dispose = function () { | ||
| if (this._escapeCalled) | ||
| this._escapeCalled = false; | ||
| if (this.start === this.end) | ||
| return; | ||
| this.handleStore.erase(this.start, this.end); | ||
| }; | ||
| HandleScope.prototype.escape = function (handle) { | ||
| if (this._escapeCalled) | ||
| return null; | ||
| this._escapeCalled = true; | ||
| if (handle < this.start || handle >= this.end) { | ||
| return null; | ||
| } | ||
| this.handleStore.swap(handle, this.start); | ||
| var h = this.handleStore.get(this.start); | ||
| this.start++; | ||
| this.parent.end++; | ||
| return h; | ||
| }; | ||
| HandleScope.prototype.escapeCalled = function () { | ||
| return this._escapeCalled; | ||
| }; | ||
| return HandleScope; | ||
| }()); | ||
| var ScopeStore = /*#__PURE__*/ (function () { | ||
| function ScopeStore() { | ||
| this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID); | ||
| this.currentScope = this._rootScope; | ||
| this._values = [undefined]; | ||
| } | ||
| ScopeStore.prototype.get = function (id) { | ||
| return this._values[id]; | ||
| }; | ||
| ScopeStore.prototype.openScope = function (handleStore) { | ||
| var currentScope = this.currentScope; | ||
| var scope = currentScope.child; | ||
| if (scope !== null) { | ||
| scope.start = scope.end = currentScope.end; | ||
| } | ||
| else { | ||
| var id = currentScope.id + 1; | ||
| scope = new HandleScope(handleStore, id, currentScope, currentScope.end); | ||
| this._values[id] = scope; | ||
| } | ||
| this.currentScope = scope; | ||
| return scope; | ||
| }; | ||
| ScopeStore.prototype.closeScope = function () { | ||
| var scope = this.currentScope; | ||
| this.currentScope = scope.parent; | ||
| scope.dispose(); | ||
| }; | ||
| ScopeStore.prototype.dispose = function () { | ||
| this.currentScope = this._rootScope; | ||
| this._values.length = 1; | ||
| }; | ||
| return ScopeStore; | ||
| }()); | ||
| var RefTracker = /*#__PURE__*/ (function () { | ||
| function RefTracker() { | ||
| this._next = null; | ||
| this._prev = null; | ||
| } | ||
| /** @virtual */ | ||
| RefTracker.prototype.dispose = function () { }; | ||
| /** @virtual */ | ||
| RefTracker.prototype.finalize = function () { }; | ||
| RefTracker.prototype.link = function (list) { | ||
| this._prev = list; | ||
| this._next = list._next; | ||
| if (this._next !== null) { | ||
| this._next._prev = this; | ||
| } | ||
| list._next = this; | ||
| }; | ||
| RefTracker.prototype.unlink = function () { | ||
| if (this._prev !== null) { | ||
| this._prev._next = this._next; | ||
| } | ||
| if (this._next !== null) { | ||
| this._next._prev = this._prev; | ||
| } | ||
| this._prev = null; | ||
| this._next = null; | ||
| }; | ||
| RefTracker.finalizeAll = function (list) { | ||
| while (list._next !== null) { | ||
| list._next.finalize(); | ||
| } | ||
| }; | ||
| return RefTracker; | ||
| }()); | ||
| var Finalizer = /*#__PURE__*/ (function () { | ||
| function Finalizer(envObject, _finalizeCallback, _finalizeData, _finalizeHint) { | ||
| if (_finalizeCallback === void 0) { _finalizeCallback = 0; } | ||
| if (_finalizeData === void 0) { _finalizeData = 0; } | ||
| if (_finalizeHint === void 0) { _finalizeHint = 0; } | ||
| this.envObject = envObject; | ||
| this._finalizeCallback = _finalizeCallback; | ||
| this._finalizeData = _finalizeData; | ||
| this._finalizeHint = _finalizeHint; | ||
| this._makeDynCall_vppp = envObject.makeDynCall_vppp; | ||
| } | ||
| Finalizer.prototype.callback = function () { return this._finalizeCallback; }; | ||
| Finalizer.prototype.data = function () { return this._finalizeData; }; | ||
| Finalizer.prototype.hint = function () { return this._finalizeHint; }; | ||
| Finalizer.prototype.resetEnv = function () { | ||
| this.envObject = undefined; | ||
| }; | ||
| Finalizer.prototype.resetFinalizer = function () { | ||
| this._finalizeCallback = 0; | ||
| this._finalizeData = 0; | ||
| this._finalizeHint = 0; | ||
| }; | ||
| Finalizer.prototype.callFinalizer = function () { | ||
| var finalize_callback = this._finalizeCallback; | ||
| var finalize_data = this._finalizeData; | ||
| var finalize_hint = this._finalizeHint; | ||
| this.resetFinalizer(); | ||
| if (!finalize_callback) | ||
| return; | ||
| var fini = Number(finalize_callback); | ||
| if (!this.envObject) { | ||
| this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint); | ||
| } | ||
| else { | ||
| this.envObject.callFinalizer(fini, finalize_data, finalize_hint); | ||
| } | ||
| }; | ||
| Finalizer.prototype.dispose = function () { | ||
| this.envObject = undefined; | ||
| this._makeDynCall_vppp = undefined; | ||
| }; | ||
| return Finalizer; | ||
| }()); | ||
| var TrackedFinalizer = /*#__PURE__*/ (function (_super) { | ||
| __extends(TrackedFinalizer, _super); | ||
| function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| var _this = _super.call(this) || this; | ||
| _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| return _this; | ||
| } | ||
| TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| var finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| finalizer.link(envObject.finalizing_reflist); | ||
| return finalizer; | ||
| }; | ||
| TrackedFinalizer.prototype.data = function () { | ||
| return this._finalizer.data(); | ||
| }; | ||
| TrackedFinalizer.prototype.dispose = function () { | ||
| if (!this._finalizer) | ||
| return; | ||
| this.unlink(); | ||
| this._finalizer.envObject.dequeueFinalizer(this); | ||
| this._finalizer.dispose(); | ||
| this._finalizer = undefined; | ||
| _super.prototype.dispose.call(this); | ||
| }; | ||
| TrackedFinalizer.prototype.finalize = function () { | ||
| this.unlink(); | ||
| var error; | ||
| var caught = false; | ||
| try { | ||
| this._finalizer.callFinalizer(); | ||
| } | ||
| catch (err) { | ||
| caught = true; | ||
| error = err; | ||
| } | ||
| this.dispose(); | ||
| if (caught) { | ||
| throw error; | ||
| } | ||
| }; | ||
| return TrackedFinalizer; | ||
| }(RefTracker)); | ||
| function throwNodeApiVersionError(moduleName, moduleApiVersion) { | ||
| var errorMessage = "".concat(moduleName, " requires Node-API version ").concat(moduleApiVersion, ", but this version of Node.js only supports version ").concat(NODE_API_SUPPORTED_VERSION_MAX, " add-ons."); | ||
| throw new Error(errorMessage); | ||
| } | ||
| function handleThrow(envObject, value) { | ||
| if (envObject.terminatedOrTerminating()) { | ||
| return; | ||
| } | ||
| throw value; | ||
| } | ||
| var Env = /*#__PURE__*/ (function () { | ||
| function Env(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) { | ||
| this.ctx = ctx; | ||
| this.moduleApiVersion = moduleApiVersion; | ||
| this.makeDynCall_vppp = makeDynCall_vppp; | ||
| this.makeDynCall_vp = makeDynCall_vp; | ||
| this.abort = abort; | ||
| this.openHandleScopes = 0; | ||
| this.instanceData = null; | ||
| this.tryCatch = new TryCatch(); | ||
| this.refs = 1; | ||
| this.reflist = new RefTracker(); | ||
| this.finalizing_reflist = new RefTracker(); | ||
| this.pendingFinalizers = []; | ||
| this.lastError = { | ||
| errorCode: 0 /* napi_status.napi_ok */, | ||
| engineErrorCode: 0, | ||
| engineReserved: 0 | ||
| }; | ||
| this.inGcFinalizer = false; | ||
| this._bindingMap = new WeakMap(); | ||
| this.id = 0; | ||
| } | ||
| /** @virtual */ | ||
| Env.prototype.canCallIntoJs = function () { | ||
| return true; | ||
| }; | ||
| Env.prototype.terminatedOrTerminating = function () { | ||
| return !this.canCallIntoJs(); | ||
| }; | ||
| Env.prototype.ref = function () { | ||
| this.refs++; | ||
| }; | ||
| Env.prototype.unref = function () { | ||
| this.refs--; | ||
| if (this.refs === 0) { | ||
| this.dispose(); | ||
| } | ||
| }; | ||
| Env.prototype.ensureHandle = function (value) { | ||
| return this.ctx.ensureHandle(value); | ||
| }; | ||
| Env.prototype.ensureHandleId = function (value) { | ||
| return this.ensureHandle(value).id; | ||
| }; | ||
| Env.prototype.clearLastError = function () { | ||
| var lastError = this.lastError; | ||
| if (lastError.errorCode !== 0 /* napi_status.napi_ok */) | ||
| lastError.errorCode = 0 /* napi_status.napi_ok */; | ||
| if (lastError.engineErrorCode !== 0) | ||
| lastError.engineErrorCode = 0; | ||
| if (lastError.engineReserved !== 0) | ||
| lastError.engineReserved = 0; | ||
| return 0 /* napi_status.napi_ok */; | ||
| }; | ||
| Env.prototype.setLastError = function (error_code, engine_error_code, engine_reserved) { | ||
| if (engine_error_code === void 0) { engine_error_code = 0; } | ||
| if (engine_reserved === void 0) { engine_reserved = 0; } | ||
| var lastError = this.lastError; | ||
| if (lastError.errorCode !== error_code) | ||
| lastError.errorCode = error_code; | ||
| if (lastError.engineErrorCode !== engine_error_code) | ||
| lastError.engineErrorCode = engine_error_code; | ||
| if (lastError.engineReserved !== engine_reserved) | ||
| lastError.engineReserved = engine_reserved; | ||
| return error_code; | ||
| }; | ||
| Env.prototype.getReturnStatus = function () { | ||
| return !this.tryCatch.hasCaught() ? 0 /* napi_status.napi_ok */ : this.setLastError(10 /* napi_status.napi_pending_exception */); | ||
| }; | ||
| Env.prototype.callIntoModule = function (fn, handleException) { | ||
| if (handleException === void 0) { handleException = handleThrow; } | ||
| var openHandleScopesBefore = this.openHandleScopes; | ||
| this.clearLastError(); | ||
| var r = fn(this); | ||
| if (openHandleScopesBefore !== this.openHandleScopes) { | ||
| this.abort('open_handle_scopes != open_handle_scopes_before'); | ||
| } | ||
| if (this.tryCatch.hasCaught()) { | ||
| var err = this.tryCatch.extractException(); | ||
| handleException(this, err); | ||
| } | ||
| return r; | ||
| }; | ||
| Env.prototype.invokeFinalizerFromGC = function (finalizer) { | ||
| if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) { | ||
| this.enqueueFinalizer(finalizer); | ||
| } | ||
| else { | ||
| var saved = this.inGcFinalizer; | ||
| this.inGcFinalizer = true; | ||
| try { | ||
| finalizer.finalize(); | ||
| } | ||
| finally { | ||
| this.inGcFinalizer = saved; | ||
| } | ||
| } | ||
| }; | ||
| Env.prototype.checkGCAccess = function () { | ||
| if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) { | ||
| this.abort('Finalizer is calling a function that may affect GC state.\n' + | ||
| 'The finalizers are run directly from GC and must not affect GC ' + | ||
| 'state.\n' + | ||
| 'Use `node_api_post_finalizer` from inside of the finalizer to work ' + | ||
| 'around this issue.\n' + | ||
| 'It schedules the call as a new task in the event loop.'); | ||
| } | ||
| }; | ||
| /** @virtual */ | ||
| Env.prototype.enqueueFinalizer = function (finalizer) { | ||
| if (this.pendingFinalizers.indexOf(finalizer) === -1) { | ||
| this.pendingFinalizers.push(finalizer); | ||
| } | ||
| }; | ||
| /** @virtual */ | ||
| Env.prototype.dequeueFinalizer = function (finalizer) { | ||
| var index = this.pendingFinalizers.indexOf(finalizer); | ||
| if (index !== -1) { | ||
| this.pendingFinalizers.splice(index, 1); | ||
| } | ||
| }; | ||
| /** @virtual */ | ||
| Env.prototype.deleteMe = function () { | ||
| RefTracker.finalizeAll(this.finalizing_reflist); | ||
| RefTracker.finalizeAll(this.reflist); | ||
| this.tryCatch.extractException(); | ||
| this.ctx.envStore.remove(this.id); | ||
| }; | ||
| Env.prototype.dispose = function () { | ||
| if (this.id === 0) | ||
| return; | ||
| this.deleteMe(); | ||
| this.finalizing_reflist.dispose(); | ||
| this.reflist.dispose(); | ||
| this.id = 0; | ||
| }; | ||
| Env.prototype.initObjectBinding = function (value) { | ||
| var binding = { | ||
| wrapped: 0, | ||
| tag: null | ||
| }; | ||
| this._bindingMap.set(value, binding); | ||
| return binding; | ||
| }; | ||
| Env.prototype.getObjectBinding = function (value) { | ||
| if (this._bindingMap.has(value)) { | ||
| return this._bindingMap.get(value); | ||
| } | ||
| return this.initObjectBinding(value); | ||
| }; | ||
| Env.prototype.setInstanceData = function (data, finalize_cb, finalize_hint) { | ||
| if (this.instanceData) { | ||
| this.instanceData.dispose(); | ||
| } | ||
| this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint); | ||
| }; | ||
| Env.prototype.getInstanceData = function () { | ||
| return this.instanceData ? this.instanceData.data() : 0; | ||
| }; | ||
| return Env; | ||
| }()); | ||
| var NodeEnv = /*#__PURE__*/ (function (_super) { | ||
| __extends(NodeEnv, _super); | ||
| function NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| var _this = _super.call(this, ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) || this; | ||
| _this.filename = filename; | ||
| _this.nodeBinding = nodeBinding; | ||
| _this.destructing = false; | ||
| _this.finalizationScheduled = false; | ||
| return _this; | ||
| } | ||
| NodeEnv.prototype.deleteMe = function () { | ||
| this.destructing = true; | ||
| this.drainFinalizerQueue(); | ||
| _super.prototype.deleteMe.call(this); | ||
| }; | ||
| NodeEnv.prototype.canCallIntoJs = function () { | ||
| return _super.prototype.canCallIntoJs.call(this) && this.ctx.canCallIntoJs(); | ||
| }; | ||
| NodeEnv.prototype.triggerFatalException = function (err) { | ||
| if (this.nodeBinding) { | ||
| this.nodeBinding.napi.fatalException(err); | ||
| } | ||
| else { | ||
| if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') { | ||
| var handled = process._fatalException(err); | ||
| if (!handled) { | ||
| console.error(err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| else { | ||
| throw err; | ||
| } | ||
| } | ||
| }; | ||
| NodeEnv.prototype.callbackIntoModule = function (enforceUncaughtExceptionPolicy, fn) { | ||
| return this.callIntoModule(fn, function (envObject, err) { | ||
| if (envObject.terminatedOrTerminating()) { | ||
| return; | ||
| } | ||
| var hasProcess = typeof process === 'object' && process !== null; | ||
| var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false; | ||
| if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) { | ||
| var warn = hasProcess && typeof process.emitWarning === 'function' | ||
| ? process.emitWarning | ||
| : function (warning, type, code) { | ||
| if (warning instanceof Error) { | ||
| console.warn(warning.toString()); | ||
| } | ||
| else { | ||
| var prefix = code ? "[".concat(code, "] ") : ''; | ||
| // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
| console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning)); | ||
| } | ||
| }; | ||
| warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168'); | ||
| return; | ||
| } | ||
| envObject.triggerFatalException(err); | ||
| }); | ||
| }; | ||
| NodeEnv.prototype.callFinalizer = function (cb, data, hint) { | ||
| this.callFinalizerInternal(1, cb, data, hint); | ||
| }; | ||
| NodeEnv.prototype.callFinalizerInternal = function (forceUncaught, cb, data, hint) { | ||
| var f = this.makeDynCall_vppp(cb); | ||
| var env = this.id; | ||
| var scope = this.ctx.openScope(this); | ||
| try { | ||
| this.callbackIntoModule(Boolean(forceUncaught), function () { f(env, data, hint); }); | ||
| } | ||
| finally { | ||
| this.ctx.closeScope(this, scope); | ||
| } | ||
| }; | ||
| NodeEnv.prototype.enqueueFinalizer = function (finalizer) { | ||
| var _this = this; | ||
| _super.prototype.enqueueFinalizer.call(this, finalizer); | ||
| if (!this.finalizationScheduled && !this.destructing) { | ||
| this.finalizationScheduled = true; | ||
| this.ref(); | ||
| _setImmediate(function () { | ||
| _this.finalizationScheduled = false; | ||
| _this.unref(); | ||
| _this.drainFinalizerQueue(); | ||
| }); | ||
| } | ||
| }; | ||
| NodeEnv.prototype.drainFinalizerQueue = function () { | ||
| while (this.pendingFinalizers.length > 0) { | ||
| var refTracker = this.pendingFinalizers.shift(); | ||
| refTracker.finalize(); | ||
| } | ||
| }; | ||
| return NodeEnv; | ||
| }(Env)); | ||
| function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion; | ||
| // Validate module_api_version. | ||
| if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) { | ||
| moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| } | ||
| else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) { | ||
| throwNodeApiVersionError(filename, moduleApiVersion); | ||
| } | ||
| var env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding); | ||
| ctx.envStore.add(env); | ||
| ctx.addCleanupHook(env, function () { env.unref(); }, 0); | ||
| return env; | ||
| } | ||
| var EmnapiError = /*#__PURE__*/ (function (_super) { | ||
| __extends(EmnapiError, _super); | ||
| function EmnapiError(message) { | ||
| var _newTarget = this.constructor; | ||
| var _this = _super.call(this, message) || this; | ||
| var ErrorConstructor = _newTarget; | ||
| var proto = ErrorConstructor.prototype; | ||
| if (!(_this instanceof EmnapiError)) { | ||
| var setPrototypeOf = Object.setPrototypeOf; | ||
| if (typeof setPrototypeOf === 'function') { | ||
| setPrototypeOf.call(Object, _this, proto); | ||
| } | ||
| else { | ||
| // eslint-disable-next-line no-proto | ||
| _this.__proto__ = proto; | ||
| } | ||
| if (typeof Error.captureStackTrace === 'function') { | ||
| Error.captureStackTrace(_this, ErrorConstructor); | ||
| } | ||
| } | ||
| return _this; | ||
| } | ||
| return EmnapiError; | ||
| }(Error)); | ||
| Object.defineProperty(EmnapiError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'EmnapiError' | ||
| }); | ||
| var NotSupportWeakRefError = /*#__PURE__*/ (function (_super) { | ||
| __extends(NotSupportWeakRefError, _super); | ||
| function NotSupportWeakRefError(api, message) { | ||
| return _super.call(this, "".concat(api, ": The current runtime does not support \"FinalizationRegistry\" and \"WeakRef\".").concat(message ? " ".concat(message) : '')) || this; | ||
| } | ||
| return NotSupportWeakRefError; | ||
| }(EmnapiError)); | ||
| Object.defineProperty(NotSupportWeakRefError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'NotSupportWeakRefError' | ||
| }); | ||
| var NotSupportBufferError = /*#__PURE__*/ (function (_super) { | ||
| __extends(NotSupportBufferError, _super); | ||
| function NotSupportBufferError(api, message) { | ||
| return _super.call(this, "".concat(api, ": The current runtime does not support \"Buffer\". Consider using buffer polyfill to make sure `globalThis.Buffer` is defined.").concat(message ? " ".concat(message) : '')) || this; | ||
| } | ||
| return NotSupportBufferError; | ||
| }(EmnapiError)); | ||
| Object.defineProperty(NotSupportBufferError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'NotSupportBufferError' | ||
| }); | ||
| var StrongRef = /*#__PURE__*/ (function () { | ||
| function StrongRef(value) { | ||
| this._value = value; | ||
| } | ||
| StrongRef.prototype.deref = function () { | ||
| return this._value; | ||
| }; | ||
| StrongRef.prototype.dispose = function () { | ||
| this._value = undefined; | ||
| }; | ||
| return StrongRef; | ||
| }()); | ||
| var Persistent = /*#__PURE__*/ (function () { | ||
| function Persistent(value) { | ||
| this._ref = new StrongRef(value); | ||
| } | ||
| Persistent.prototype.setWeak = function (param, callback) { | ||
| if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef) | ||
| return; | ||
| var value = this._ref.deref(); | ||
| try { | ||
| Persistent._registry.register(value, this, this); | ||
| var weakRef = new WeakRef(value); | ||
| this._ref.dispose(); | ||
| this._ref = weakRef; | ||
| this._param = param; | ||
| this._callback = callback; | ||
| } | ||
| catch (err) { | ||
| if (typeof value === 'symbol') ; | ||
| else { | ||
| throw err; | ||
| } | ||
| } | ||
| }; | ||
| Persistent.prototype.clearWeak = function () { | ||
| if (!supportFinalizer || this._ref === undefined) | ||
| return; | ||
| if (this._ref instanceof WeakRef) { | ||
| try { | ||
| Persistent._registry.unregister(this); | ||
| } | ||
| catch (_) { } | ||
| this._param = undefined; | ||
| this._callback = undefined; | ||
| var value = this._ref.deref(); | ||
| if (value === undefined) { | ||
| this._ref = value; | ||
| } | ||
| else { | ||
| this._ref = new StrongRef(value); | ||
| } | ||
| } | ||
| }; | ||
| Persistent.prototype.reset = function () { | ||
| if (supportFinalizer) { | ||
| try { | ||
| Persistent._registry.unregister(this); | ||
| } | ||
| catch (_) { } | ||
| } | ||
| this._param = undefined; | ||
| this._callback = undefined; | ||
| if (this._ref instanceof StrongRef) { | ||
| this._ref.dispose(); | ||
| } | ||
| this._ref = undefined; | ||
| }; | ||
| Persistent.prototype.isEmpty = function () { | ||
| return this._ref === undefined; | ||
| }; | ||
| Persistent.prototype.deref = function () { | ||
| if (this._ref === undefined) | ||
| return undefined; | ||
| return this._ref.deref(); | ||
| }; | ||
| Persistent._registry = supportFinalizer | ||
| ? new FinalizationRegistry(function (value) { | ||
| value._ref = undefined; | ||
| var callback = value._callback; | ||
| var param = value._param; | ||
| value._callback = undefined; | ||
| value._param = undefined; | ||
| if (typeof callback === 'function') { | ||
| callback(param); | ||
| } | ||
| }) | ||
| : undefined; | ||
| return Persistent; | ||
| }()); | ||
| exports.ReferenceOwnership = void 0; | ||
| (function (ReferenceOwnership) { | ||
| ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime"; | ||
| ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland"; | ||
| })(exports.ReferenceOwnership || (exports.ReferenceOwnership = {})); | ||
| function canBeHeldWeakly(value) { | ||
| return value.isObject() || value.isFunction() || value.isSymbol(); | ||
| } | ||
| var Reference = /*#__PURE__*/ (function (_super) { | ||
| __extends(Reference, _super); | ||
| function Reference(envObject, handle_id, initialRefcount, ownership) { | ||
| var _this = _super.call(this) || this; | ||
| _this.envObject = envObject; | ||
| _this._refcount = initialRefcount; | ||
| _this._ownership = ownership; | ||
| var handle = envObject.ctx.handleStore.get(handle_id); | ||
| _this.canBeWeak = canBeHeldWeakly(handle); | ||
| _this.persistent = new Persistent(handle.value); | ||
| _this.id = 0; | ||
| if (initialRefcount === 0) { | ||
| _this._setWeak(); | ||
| } | ||
| return _this; | ||
| } | ||
| Reference.weakCallback = function (ref) { | ||
| ref.persistent.reset(); | ||
| ref.invokeFinalizerFromGC(); | ||
| }; | ||
| Reference.create = function (envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) { | ||
| var ref = new Reference(envObject, handle_id, initialRefcount, ownership); | ||
| envObject.ctx.refStore.add(ref); | ||
| ref.link(envObject.reflist); | ||
| return ref; | ||
| }; | ||
| Reference.prototype.ref = function () { | ||
| if (this.persistent.isEmpty()) { | ||
| return 0; | ||
| } | ||
| if (++this._refcount === 1 && this.canBeWeak) { | ||
| this.persistent.clearWeak(); | ||
| } | ||
| return this._refcount; | ||
| }; | ||
| Reference.prototype.unref = function () { | ||
| if (this.persistent.isEmpty() || this._refcount === 0) { | ||
| return 0; | ||
| } | ||
| if (--this._refcount === 0) { | ||
| this._setWeak(); | ||
| } | ||
| return this._refcount; | ||
| }; | ||
| Reference.prototype.get = function (envObject) { | ||
| if (envObject === void 0) { envObject = this.envObject; } | ||
| if (this.persistent.isEmpty()) { | ||
| return 0; | ||
| } | ||
| var obj = this.persistent.deref(); | ||
| var handle = envObject.ensureHandle(obj); | ||
| return handle.id; | ||
| }; | ||
| /** @virtual */ | ||
| Reference.prototype.resetFinalizer = function () { }; | ||
| /** @virtual */ | ||
| Reference.prototype.data = function () { return 0; }; | ||
| Reference.prototype.refcount = function () { return this._refcount; }; | ||
| Reference.prototype.ownership = function () { return this._ownership; }; | ||
| /** @virtual */ | ||
| Reference.prototype.callUserFinalizer = function () { }; | ||
| /** @virtual */ | ||
| Reference.prototype.invokeFinalizerFromGC = function () { | ||
| this.finalize(); | ||
| }; | ||
| Reference.prototype._setWeak = function () { | ||
| if (this.canBeWeak) { | ||
| this.persistent.setWeak(this, Reference.weakCallback); | ||
| } | ||
| else { | ||
| this.persistent.reset(); | ||
| } | ||
| }; | ||
| Reference.prototype.finalize = function () { | ||
| this.persistent.reset(); | ||
| var deleteMe = this._ownership === exports.ReferenceOwnership.kRuntime; | ||
| this.unlink(); | ||
| this.callUserFinalizer(); | ||
| if (deleteMe) { | ||
| this.dispose(); | ||
| } | ||
| }; | ||
| Reference.prototype.dispose = function () { | ||
| if (this.id === 0) | ||
| return; | ||
| this.unlink(); | ||
| this.persistent.reset(); | ||
| this.envObject.ctx.refStore.remove(this.id); | ||
| _super.prototype.dispose.call(this); | ||
| this.envObject = undefined; | ||
| this.id = 0; | ||
| }; | ||
| return Reference; | ||
| }(RefTracker)); | ||
| var ReferenceWithData = /*#__PURE__*/ (function (_super) { | ||
| __extends(ReferenceWithData, _super); | ||
| function ReferenceWithData(envObject, value, initialRefcount, ownership, _data) { | ||
| var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this; | ||
| _this._data = _data; | ||
| return _this; | ||
| } | ||
| ReferenceWithData.create = function (envObject, value, initialRefcount, ownership, data) { | ||
| var reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data); | ||
| envObject.ctx.refStore.add(reference); | ||
| reference.link(envObject.reflist); | ||
| return reference; | ||
| }; | ||
| ReferenceWithData.prototype.data = function () { | ||
| return this._data; | ||
| }; | ||
| return ReferenceWithData; | ||
| }(Reference)); | ||
| var ReferenceWithFinalizer = /*#__PURE__*/ (function (_super) { | ||
| __extends(ReferenceWithFinalizer, _super); | ||
| function ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this; | ||
| _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| return _this; | ||
| } | ||
| ReferenceWithFinalizer.create = function (envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| var reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint); | ||
| envObject.ctx.refStore.add(reference); | ||
| reference.link(envObject.finalizing_reflist); | ||
| return reference; | ||
| }; | ||
| ReferenceWithFinalizer.prototype.resetFinalizer = function () { | ||
| this._finalizer.resetFinalizer(); | ||
| }; | ||
| ReferenceWithFinalizer.prototype.data = function () { | ||
| return this._finalizer.data(); | ||
| }; | ||
| ReferenceWithFinalizer.prototype.callUserFinalizer = function () { | ||
| this._finalizer.callFinalizer(); | ||
| }; | ||
| ReferenceWithFinalizer.prototype.invokeFinalizerFromGC = function () { | ||
| this._finalizer.envObject.invokeFinalizerFromGC(this); | ||
| }; | ||
| ReferenceWithFinalizer.prototype.dispose = function () { | ||
| if (!this._finalizer) | ||
| return; | ||
| this._finalizer.envObject.dequeueFinalizer(this); | ||
| this._finalizer.dispose(); | ||
| _super.prototype.dispose.call(this); | ||
| this._finalizer = undefined; | ||
| }; | ||
| return ReferenceWithFinalizer; | ||
| }(Reference)); | ||
| var Deferred = /*#__PURE__*/ (function () { | ||
| function Deferred(ctx, value) { | ||
| this.id = 0; | ||
| this.ctx = ctx; | ||
| this.value = value; | ||
| } | ||
| Deferred.create = function (ctx, value) { | ||
| var deferred = new Deferred(ctx, value); | ||
| ctx.deferredStore.add(deferred); | ||
| return deferred; | ||
| }; | ||
| Deferred.prototype.resolve = function (value) { | ||
| this.value.resolve(value); | ||
| this.dispose(); | ||
| }; | ||
| Deferred.prototype.reject = function (reason) { | ||
| this.value.reject(reason); | ||
| this.dispose(); | ||
| }; | ||
| Deferred.prototype.dispose = function () { | ||
| this.ctx.deferredStore.remove(this.id); | ||
| this.id = 0; | ||
| this.value = null; | ||
| this.ctx = null; | ||
| }; | ||
| return Deferred; | ||
| }()); | ||
| var Store = /*#__PURE__*/ (function () { | ||
| function Store() { | ||
| this._values = [undefined]; | ||
| this._values.length = 4; | ||
| this._size = 1; | ||
| this._freeList = []; | ||
| } | ||
| Store.prototype.add = function (value) { | ||
| var id; | ||
| if (this._freeList.length) { | ||
| id = this._freeList.shift(); | ||
| } | ||
| else { | ||
| id = this._size; | ||
| this._size++; | ||
| var capacity = this._values.length; | ||
| if (id >= capacity) { | ||
| this._values.length = capacity + (capacity >> 1) + 16; | ||
| } | ||
| } | ||
| value.id = id; | ||
| this._values[id] = value; | ||
| }; | ||
| Store.prototype.get = function (id) { | ||
| return this._values[id]; | ||
| }; | ||
| Store.prototype.has = function (id) { | ||
| return this._values[id] !== undefined; | ||
| }; | ||
| Store.prototype.remove = function (id) { | ||
| var value = this._values[id]; | ||
| if (value) { | ||
| value.id = 0; | ||
| this._values[id] = undefined; | ||
| this._freeList.push(Number(id)); | ||
| } | ||
| }; | ||
| Store.prototype.dispose = function () { | ||
| for (var i = 1; i < this._size; ++i) { | ||
| var value = this._values[i]; | ||
| value === null || value === void 0 ? void 0 : value.dispose(); | ||
| } | ||
| this._values = [undefined]; | ||
| this._size = 1; | ||
| this._freeList = []; | ||
| }; | ||
| return Store; | ||
| }()); | ||
| var kMaxReasonableBytes = BigInt(1) << BigInt(60); | ||
| var kMinReasonableBytes = -kMaxReasonableBytes; | ||
| var ExternalMemory = /*#__PURE__*/ (function () { | ||
| function ExternalMemory(onChange) { | ||
| this.total = BigInt(0); | ||
| this.onChange = onChange !== null && onChange !== void 0 ? onChange : null; | ||
| } | ||
| ExternalMemory.prototype.adjust = function (changeInBytes) { | ||
| changeInBytes = BigInt(changeInBytes); | ||
| if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) { | ||
| throw new RangeError("changeInBytes ".concat(changeInBytes, " is out of reasonable range")); | ||
| } | ||
| var old = this.total; | ||
| this.total += changeInBytes; | ||
| var amount = this.total; | ||
| var onChange = this.onChange; | ||
| if (changeInBytes) { | ||
| onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes); | ||
| } | ||
| return amount; | ||
| }; | ||
| return ExternalMemory; | ||
| }()); | ||
| var CleanupHookCallback = /*#__PURE__*/ (function () { | ||
| function CleanupHookCallback(envObject, fn, arg, order) { | ||
| this.envObject = envObject; | ||
| this.fn = fn; | ||
| this.arg = arg; | ||
| this.order = order; | ||
| } | ||
| return CleanupHookCallback; | ||
| }()); | ||
| var CleanupQueue = /*#__PURE__*/ (function () { | ||
| function CleanupQueue() { | ||
| this._cleanupHooks = []; | ||
| this._cleanupHookCounter = 0; | ||
| } | ||
| CleanupQueue.prototype.empty = function () { | ||
| return this._cleanupHooks.length === 0; | ||
| }; | ||
| CleanupQueue.prototype.add = function (envObject, fn, arg) { | ||
| if (this._cleanupHooks.filter(function (hook) { return (hook.envObject === envObject && hook.fn === fn && hook.arg === arg); }).length > 0) { | ||
| throw new Error('Can not add same fn and arg twice'); | ||
| } | ||
| this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++)); | ||
| }; | ||
| CleanupQueue.prototype.remove = function (envObject, fn, arg) { | ||
| for (var i = 0; i < this._cleanupHooks.length; ++i) { | ||
| var hook = this._cleanupHooks[i]; | ||
| if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) { | ||
| this._cleanupHooks.splice(i, 1); | ||
| return; | ||
| } | ||
| } | ||
| }; | ||
| CleanupQueue.prototype.drain = function () { | ||
| var hooks = this._cleanupHooks.slice(); | ||
| hooks.sort(function (a, b) { return (b.order - a.order); }); | ||
| for (var i = 0; i < hooks.length; ++i) { | ||
| var cb = hooks[i]; | ||
| if (typeof cb.fn === 'number') { | ||
| cb.envObject.makeDynCall_vp(cb.fn)(cb.arg); | ||
| } | ||
| else { | ||
| cb.fn(cb.arg); | ||
| } | ||
| this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1); | ||
| } | ||
| }; | ||
| CleanupQueue.prototype.dispose = function () { | ||
| this._cleanupHooks.length = 0; | ||
| this._cleanupHookCounter = 0; | ||
| }; | ||
| return CleanupQueue; | ||
| }()); | ||
| var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () { | ||
| function NodejsWaitingRequestCounter() { | ||
| this.refHandle = new _MessageChannel().port1; | ||
| this.count = 0; | ||
| } | ||
| NodejsWaitingRequestCounter.prototype.increase = function () { | ||
| if (this.count === 0) { | ||
| if (this.refHandle.ref) { | ||
| this.refHandle.ref(); | ||
| } | ||
| } | ||
| this.count++; | ||
| }; | ||
| NodejsWaitingRequestCounter.prototype.decrease = function () { | ||
| if (this.count === 0) | ||
| return; | ||
| if (this.count === 1) { | ||
| if (this.refHandle.unref) { | ||
| this.refHandle.unref(); | ||
| } | ||
| } | ||
| this.count--; | ||
| }; | ||
| return NodejsWaitingRequestCounter; | ||
| }()); | ||
| var Context = /*#__PURE__*/ (function () { | ||
| function Context(options) { | ||
| var _this = this; | ||
| this._isStopping = false; | ||
| this._canCallIntoJs = true; | ||
| this._suppressDestroy = false; | ||
| this.envStore = new Store(); | ||
| this.scopeStore = new ScopeStore(); | ||
| this.refStore = new Store(); | ||
| this.deferredStore = new Store(); | ||
| this.handleStore = new HandleStore(); | ||
| this.feature = { | ||
| supportReflect: supportReflect, | ||
| supportFinalizer: supportFinalizer, | ||
| supportWeakSymbol: supportWeakSymbol, | ||
| supportBigInt: supportBigInt, | ||
| supportNewFunction: supportNewFunction, | ||
| canSetFunctionName: canSetFunctionName, | ||
| setImmediate: _setImmediate, | ||
| Buffer: _Buffer, | ||
| MessageChannel: _MessageChannel | ||
| }; | ||
| this.cleanupQueue = new CleanupQueue(); | ||
| this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange); | ||
| if (typeof process === 'object' && process !== null && typeof process.once === 'function') { | ||
| this.refCounter = new NodejsWaitingRequestCounter(); | ||
| process.once('beforeExit', function () { | ||
| if (!_this._suppressDestroy) { | ||
| _this.destroy(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| /** | ||
| * Suppress the destroy on `beforeExit` event in Node.js. | ||
| * Call this method if you want to keep the context and | ||
| * all associated {@link Env | Env} alive, | ||
| * this also means that cleanup hooks will not be called. | ||
| * After call this method, you should call | ||
| * {@link Context.destroy | `Context.prototype.destroy`} method manually. | ||
| */ | ||
| Context.prototype.suppressDestroy = function () { | ||
| this._suppressDestroy = true; | ||
| }; | ||
| // eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
| Context.prototype.getRuntimeVersions = function () { | ||
| return { | ||
| version: version, | ||
| NODE_API_SUPPORTED_VERSION_MAX: NODE_API_SUPPORTED_VERSION_MAX, | ||
| NAPI_VERSION_EXPERIMENTAL: NAPI_VERSION_EXPERIMENTAL, | ||
| NODE_API_DEFAULT_MODULE_API_VERSION: NODE_API_DEFAULT_MODULE_API_VERSION | ||
| }; | ||
| }; | ||
| Context.prototype.createNotSupportWeakRefError = function (api, message) { | ||
| return new NotSupportWeakRefError(api, message); | ||
| }; | ||
| Context.prototype.createNotSupportBufferError = function (api, message) { | ||
| return new NotSupportBufferError(api, message); | ||
| }; | ||
| Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership) { | ||
| return Reference.create(envObject, handle_id, initialRefcount, ownership); | ||
| }; | ||
| Context.prototype.createReferenceWithData = function (envObject, handle_id, initialRefcount, ownership, data) { | ||
| return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data); | ||
| }; | ||
| Context.prototype.createReferenceWithFinalizer = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| if (finalize_callback === void 0) { finalize_callback = 0; } | ||
| if (finalize_data === void 0) { finalize_data = 0; } | ||
| if (finalize_hint === void 0) { finalize_hint = 0; } | ||
| return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint); | ||
| }; | ||
| Context.prototype.createDeferred = function (value) { | ||
| return Deferred.create(this, value); | ||
| }; | ||
| Context.prototype.adjustAmountOfExternalAllocatedMemory = function (changeInBytes) { | ||
| return this._externalMemory.adjust(changeInBytes); | ||
| }; | ||
| Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding); | ||
| }; | ||
| Context.prototype.createTrackedFinalizer = function (envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| }; | ||
| Context.prototype.getCurrentScope = function () { | ||
| return this.scopeStore.currentScope; | ||
| }; | ||
| Context.prototype.addToCurrentScope = function (value) { | ||
| return this.scopeStore.currentScope.add(value); | ||
| }; | ||
| Context.prototype.openScope = function (envObject) { | ||
| var scope = this.scopeStore.openScope(this.handleStore); | ||
| if (envObject) | ||
| envObject.openHandleScopes++; | ||
| return scope; | ||
| }; | ||
| Context.prototype.closeScope = function (envObject, _scope) { | ||
| if (envObject && envObject.openHandleScopes === 0) | ||
| return; | ||
| this.scopeStore.closeScope(); | ||
| if (envObject) | ||
| envObject.openHandleScopes--; | ||
| }; | ||
| Context.prototype.ensureHandle = function (value) { | ||
| switch (value) { | ||
| case undefined: return HandleStore.UNDEFINED; | ||
| case null: return HandleStore.NULL; | ||
| case true: return HandleStore.TRUE; | ||
| case false: return HandleStore.FALSE; | ||
| case _global: return HandleStore.GLOBAL; | ||
| } | ||
| return this.addToCurrentScope(value); | ||
| }; | ||
| Context.prototype.addCleanupHook = function (envObject, fn, arg) { | ||
| this.cleanupQueue.add(envObject, fn, arg); | ||
| }; | ||
| Context.prototype.removeCleanupHook = function (envObject, fn, arg) { | ||
| this.cleanupQueue.remove(envObject, fn, arg); | ||
| }; | ||
| Context.prototype.runCleanup = function () { | ||
| while (!this.cleanupQueue.empty()) { | ||
| this.cleanupQueue.drain(); | ||
| } | ||
| }; | ||
| Context.prototype.increaseWaitingRequestCounter = function () { | ||
| var _a; | ||
| (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase(); | ||
| }; | ||
| Context.prototype.decreaseWaitingRequestCounter = function () { | ||
| var _a; | ||
| (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease(); | ||
| }; | ||
| Context.prototype.setCanCallIntoJs = function (value) { | ||
| this._canCallIntoJs = value; | ||
| }; | ||
| Context.prototype.setStopping = function (value) { | ||
| this._isStopping = value; | ||
| }; | ||
| Context.prototype.canCallIntoJs = function () { | ||
| return this._canCallIntoJs && !this._isStopping; | ||
| }; | ||
| /** | ||
| * Destroy the context and call cleanup hooks. | ||
| * Associated {@link Env | Env} will be destroyed. | ||
| */ | ||
| Context.prototype.destroy = function () { | ||
| this.setStopping(true); | ||
| this.setCanCallIntoJs(false); | ||
| this.runCleanup(); | ||
| }; | ||
| return Context; | ||
| }()); | ||
| var defaultContext; | ||
| function createContext(options) { | ||
| return new Context(options); | ||
| } | ||
| function getDefaultContext() { | ||
| if (!defaultContext) { | ||
| defaultContext = createContext(); | ||
| } | ||
| return defaultContext; | ||
| } | ||
| exports.ConstHandle = ConstHandle; | ||
| exports.Context = Context; | ||
| exports.Deferred = Deferred; | ||
| exports.EmnapiError = EmnapiError; | ||
| exports.Env = Env; | ||
| exports.External = External; | ||
| exports.Finalizer = Finalizer; | ||
| exports.Handle = Handle; | ||
| exports.HandleScope = HandleScope; | ||
| exports.HandleStore = HandleStore; | ||
| exports.NAPI_VERSION_EXPERIMENTAL = NAPI_VERSION_EXPERIMENTAL; | ||
| exports.NODE_API_DEFAULT_MODULE_API_VERSION = NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| exports.NODE_API_SUPPORTED_VERSION_MAX = NODE_API_SUPPORTED_VERSION_MAX; | ||
| exports.NODE_API_SUPPORTED_VERSION_MIN = NODE_API_SUPPORTED_VERSION_MIN; | ||
| exports.NodeEnv = NodeEnv; | ||
| exports.NotSupportBufferError = NotSupportBufferError; | ||
| exports.NotSupportWeakRefError = NotSupportWeakRefError; | ||
| exports.Persistent = Persistent; | ||
| exports.RefTracker = RefTracker; | ||
| exports.Reference = Reference; | ||
| exports.ReferenceWithData = ReferenceWithData; | ||
| exports.ReferenceWithFinalizer = ReferenceWithFinalizer; | ||
| exports.ScopeStore = ScopeStore; | ||
| exports.Store = Store; | ||
| exports.TrackedFinalizer = TrackedFinalizer; | ||
| exports.TryCatch = TryCatch; | ||
| exports.createContext = createContext; | ||
| exports.getDefaultContext = getDefaultContext; | ||
| exports.getExternalValue = getExternalValue; | ||
| exports.isExternal = isExternal; | ||
| exports.isReferenceType = isReferenceType; | ||
| exports.version = version; | ||
| return exports; | ||
| })({}); |
| export declare type Ptr = number | bigint | ||
| export declare interface IBuffer extends Uint8Array {} | ||
| export declare interface BufferCtor { | ||
| readonly prototype: IBuffer | ||
| /** @deprecated */ | ||
| new (...args: any[]): IBuffer | ||
| from: { | ||
| (buffer: ArrayBufferLike): IBuffer | ||
| (buffer: ArrayBufferLike, byteOffset: number, length: number): IBuffer | ||
| } | ||
| alloc: (size: number) => IBuffer | ||
| isBuffer: (obj: unknown) => obj is IBuffer | ||
| } | ||
| export declare const enum GlobalHandle { | ||
| UNDEFINED = 1, | ||
| NULL, | ||
| FALSE, | ||
| TRUE, | ||
| GLOBAL | ||
| } | ||
| export declare const enum Version { | ||
| NODE_API_SUPPORTED_VERSION_MIN = 1, | ||
| NODE_API_DEFAULT_MODULE_API_VERSION = 8, | ||
| NODE_API_SUPPORTED_VERSION_MAX = 10, | ||
| NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export declare type Pointer<T> = number | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export declare type PointerPointer<T> = number | ||
| export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T> | ||
| export declare type Const<T> = T | ||
| export declare type void_p = Pointer<void> | ||
| export declare type void_pp = Pointer<void_p> | ||
| export declare type bool = number | ||
| export declare type char = number | ||
| export declare type char_p = Pointer<char> | ||
| export declare type unsigned_char = number | ||
| export declare type const_char = Const<char> | ||
| export declare type const_char_p = Pointer<const_char> | ||
| export declare type char16_t_p = number | ||
| export declare type const_char16_t_p = number | ||
| export declare type short = number | ||
| export declare type unsigned_short = number | ||
| export declare type int = number | ||
| export declare type unsigned_int = number | ||
| export declare type long = number | ||
| export declare type unsigned_long = number | ||
| export declare type long_long = bigint | ||
| export declare type unsigned_long_long = bigint | ||
| export declare type float = number | ||
| export declare type double = number | ||
| export declare type long_double = number | ||
| export declare type size_t = number | ||
| export declare type int8_t = number | ||
| export declare type uint8_t = number | ||
| export declare type int16_t = number | ||
| export declare type uint16_t = number | ||
| export declare type int32_t = number | ||
| export declare type uint32_t = number | ||
| export declare type int64_t = bigint | ||
| export declare type uint64_t = bigint | ||
| export declare type napi_env = Pointer<unknown> | ||
| export declare type napi_value = Pointer<unknown> | ||
| export declare type napi_ref = Pointer<unknown> | ||
| export declare type napi_deferred = Pointer<unknown> | ||
| export declare type napi_handle_scope = Pointer<unknown> | ||
| export declare type napi_escapable_handle_scope = Pointer<unknown> | ||
| export declare type napi_addon_register_func = FunctionPointer<(env: napi_env, exports: napi_value) => napi_value> | ||
| export declare type napi_callback_info = Pointer<unknown> | ||
| export declare type napi_callback = FunctionPointer<(env: napi_env, info: napi_callback_info) => napi_value> | ||
| export declare interface napi_extended_error_info { | ||
| error_message: const_char_p | ||
| engine_reserved: void_p | ||
| engine_error_code: uint32_t | ||
| error_code: napi_status | ||
| } | ||
| export declare interface napi_property_descriptor { | ||
| // One of utf8name or name should be NULL. | ||
| utf8name: const_char_p | ||
| name: napi_value | ||
| method: napi_callback | ||
| getter: napi_callback | ||
| setter: napi_callback | ||
| value: napi_value | ||
| /* napi_property_attributes */ | ||
| attributes: number | ||
| data: void_p | ||
| } | ||
| export declare type napi_finalize = FunctionPointer<( | ||
| env: napi_env, | ||
| finalize_data: void_p, | ||
| finalize_hint: void_p | ||
| ) => void> | ||
| export declare interface node_module { | ||
| nm_version: int32_t | ||
| nm_flags: uint32_t | ||
| nm_filename: Pointer<const_char> | ||
| nm_register_func: napi_addon_register_func | ||
| nm_modname: Pointer<const_char> | ||
| nm_priv: Pointer<void> | ||
| reserved: PointerPointer<void> | ||
| } | ||
| export declare interface napi_node_version { | ||
| major: uint32_t | ||
| minor: uint32_t | ||
| patch: uint32_t | ||
| release: const_char_p | ||
| } | ||
| export declare interface emnapi_emscripten_version { | ||
| major: uint32_t | ||
| minor: uint32_t | ||
| patch: uint32_t | ||
| } | ||
| export declare const enum napi_status { | ||
| napi_ok, | ||
| napi_invalid_arg, | ||
| napi_object_expected, | ||
| napi_string_expected, | ||
| napi_name_expected, | ||
| napi_function_expected, | ||
| napi_number_expected, | ||
| napi_boolean_expected, | ||
| napi_array_expected, | ||
| napi_generic_failure, | ||
| napi_pending_exception, | ||
| napi_cancelled, | ||
| napi_escape_called_twice, | ||
| napi_handle_scope_mismatch, | ||
| napi_callback_scope_mismatch, | ||
| napi_queue_full, | ||
| napi_closing, | ||
| napi_bigint_expected, | ||
| napi_date_expected, | ||
| napi_arraybuffer_expected, | ||
| napi_detachable_arraybuffer_expected, | ||
| napi_would_deadlock, // unused | ||
| napi_no_external_buffers_allowed, | ||
| napi_cannot_run_js | ||
| } | ||
| export declare const enum napi_property_attributes { | ||
| napi_default = 0, | ||
| napi_writable = 1 << 0, | ||
| napi_enumerable = 1 << 1, | ||
| napi_configurable = 1 << 2, | ||
| // Used with napi_define_class to distinguish static properties | ||
| // from instance properties. Ignored by napi_define_properties. | ||
| napi_static = 1 << 10, | ||
| /// #ifdef NAPI_EXPERIMENTAL | ||
| // Default for class methods. | ||
| napi_default_method = napi_writable | napi_configurable, | ||
| // Default for object properties, like in JS obj[prop]. | ||
| napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable | ||
| /// #endif // NAPI_EXPERIMENTAL | ||
| } | ||
| export declare const enum napi_valuetype { | ||
| napi_undefined, | ||
| napi_null, | ||
| napi_boolean, | ||
| napi_number, | ||
| napi_string, | ||
| napi_symbol, | ||
| napi_object, | ||
| napi_function, | ||
| napi_external, | ||
| napi_bigint | ||
| } | ||
| export declare const enum napi_typedarray_type { | ||
| napi_int8_array, | ||
| napi_uint8_array, | ||
| napi_uint8_clamped_array, | ||
| napi_int16_array, | ||
| napi_uint16_array, | ||
| napi_int32_array, | ||
| napi_uint32_array, | ||
| napi_float32_array, | ||
| napi_float64_array, | ||
| napi_bigint64_array, | ||
| napi_biguint64_array, | ||
| napi_float16_array, | ||
| } | ||
| export declare const enum napi_key_collection_mode { | ||
| napi_key_include_prototypes, | ||
| napi_key_own_only | ||
| } | ||
| export declare const enum napi_key_filter { | ||
| napi_key_all_properties = 0, | ||
| napi_key_writable = 1, | ||
| napi_key_enumerable = 1 << 1, | ||
| napi_key_configurable = 1 << 2, | ||
| napi_key_skip_strings = 1 << 3, | ||
| napi_key_skip_symbols = 1 << 4 | ||
| } | ||
| export declare const enum napi_key_conversion { | ||
| napi_key_keep_numbers, | ||
| napi_key_numbers_to_strings | ||
| } | ||
| export declare const enum emnapi_memory_view_type { | ||
| emnapi_int8_array, | ||
| emnapi_uint8_array, | ||
| emnapi_uint8_clamped_array, | ||
| emnapi_int16_array, | ||
| emnapi_uint16_array, | ||
| emnapi_int32_array, | ||
| emnapi_uint32_array, | ||
| emnapi_float32_array, | ||
| emnapi_float64_array, | ||
| emnapi_bigint64_array, | ||
| emnapi_biguint64_array, | ||
| emnapi_float16_array, | ||
| emnapi_data_view = -1, | ||
| emnapi_buffer = -2 | ||
| } | ||
| export declare const enum napi_threadsafe_function_call_mode { | ||
| napi_tsfn_nonblocking, | ||
| napi_tsfn_blocking | ||
| } | ||
| export declare const enum napi_threadsafe_function_release_mode { | ||
| napi_tsfn_release, | ||
| napi_tsfn_abort | ||
| } | ||
| export declare type CleanupHookCallbackFunction = number | ((arg: number) => void); | ||
| export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> { | ||
| constructor(id: number, value: S); | ||
| dispose(): void; | ||
| } | ||
| export declare class Context { | ||
| private _isStopping; | ||
| private _canCallIntoJs; | ||
| private _suppressDestroy; | ||
| envStore: Store<Env>; | ||
| scopeStore: ScopeStore; | ||
| refStore: Store<Reference>; | ||
| deferredStore: Store<Deferred<any>>; | ||
| handleStore: HandleStore; | ||
| private readonly refCounter?; | ||
| private readonly cleanupQueue; | ||
| private readonly _externalMemory; | ||
| feature: { | ||
| supportReflect: boolean; | ||
| supportFinalizer: boolean; | ||
| supportWeakSymbol: boolean; | ||
| supportBigInt: boolean; | ||
| supportNewFunction: boolean; | ||
| canSetFunctionName: boolean; | ||
| setImmediate: (callback: () => void) => void; | ||
| Buffer: BufferCtor | undefined; | ||
| MessageChannel: { | ||
| new (): MessageChannel; | ||
| prototype: MessageChannel; | ||
| } | undefined; | ||
| }; | ||
| constructor(options?: ContextOptions); | ||
| /** | ||
| * Suppress the destroy on `beforeExit` event in Node.js. | ||
| * Call this method if you want to keep the context and | ||
| * all associated {@link Env | Env} alive, | ||
| * this also means that cleanup hooks will not be called. | ||
| * After call this method, you should call | ||
| * {@link Context.destroy | `Context.prototype.destroy`} method manually. | ||
| */ | ||
| suppressDestroy(): void; | ||
| getRuntimeVersions(): { | ||
| version: string; | ||
| NODE_API_SUPPORTED_VERSION_MAX: Version; | ||
| NAPI_VERSION_EXPERIMENTAL: Version; | ||
| NODE_API_DEFAULT_MODULE_API_VERSION: Version; | ||
| }; | ||
| createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError; | ||
| createNotSupportBufferError(api: string, message: string): NotSupportBufferError; | ||
| createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference; | ||
| createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference; | ||
| createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference; | ||
| createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>; | ||
| adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint; | ||
| 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; | ||
| createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer; | ||
| getCurrentScope(): HandleScope | null; | ||
| addToCurrentScope<V>(value: V): Handle<V>; | ||
| openScope(envObject?: Env): HandleScope; | ||
| closeScope(envObject?: Env, _scope?: HandleScope): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
| removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void; | ||
| runCleanup(): void; | ||
| increaseWaitingRequestCounter(): void; | ||
| decreaseWaitingRequestCounter(): void; | ||
| setCanCallIntoJs(value: boolean): void; | ||
| setStopping(value: boolean): void; | ||
| canCallIntoJs(): boolean; | ||
| /** | ||
| * Destroy the context and call cleanup hooks. | ||
| * Associated {@link Env | Env} will be destroyed. | ||
| */ | ||
| destroy(): void; | ||
| } | ||
| export declare interface ContextOptions { | ||
| onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any; | ||
| } | ||
| export declare function createContext(options?: ContextOptions): Context; | ||
| export declare class Deferred<T = any> implements IStoreValue { | ||
| static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred; | ||
| id: number; | ||
| ctx: Context; | ||
| value: IDeferrdValue<T>; | ||
| constructor(ctx: Context, value: IDeferrdValue<T>); | ||
| resolve(value: T): void; | ||
| reject(reason?: any): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class EmnapiError extends Error { | ||
| constructor(message?: string); | ||
| } | ||
| export declare abstract class Env implements IStoreValue { | ||
| readonly 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; | ||
| id: number; | ||
| openHandleScopes: number; | ||
| instanceData: TrackedFinalizer | null; | ||
| tryCatch: TryCatch; | ||
| refs: number; | ||
| reflist: RefTracker; | ||
| finalizing_reflist: RefTracker; | ||
| pendingFinalizers: RefTracker[]; | ||
| lastError: { | ||
| errorCode: napi_status; | ||
| engineErrorCode: number; | ||
| engineReserved: Ptr; | ||
| }; | ||
| inGcFinalizer: boolean; | ||
| 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); | ||
| /** @virtual */ | ||
| canCallIntoJs(): boolean; | ||
| terminatedOrTerminating(): boolean; | ||
| ref(): void; | ||
| unref(): void; | ||
| ensureHandle<S>(value: S): Handle<S>; | ||
| ensureHandleId(value: any): napi_value; | ||
| clearLastError(): napi_status; | ||
| setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status; | ||
| getReturnStatus(): napi_status; | ||
| callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T; | ||
| /** @virtual */ | ||
| abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| invokeFinalizerFromGC(finalizer: RefTracker): void; | ||
| checkGCAccess(): void; | ||
| /** @virtual */ | ||
| enqueueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| dequeueFinalizer(finalizer: RefTracker): void; | ||
| /** @virtual */ | ||
| deleteMe(): void; | ||
| dispose(): void; | ||
| private readonly _bindingMap; | ||
| initObjectBinding<S extends object>(value: S): IReferenceBinding; | ||
| getObjectBinding<S extends object>(value: S): IReferenceBinding; | ||
| setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void; | ||
| getInstanceData(): number; | ||
| } | ||
| /** @public */ | ||
| declare interface External_2 extends Record<any, any> { | ||
| } | ||
| /** @public */ | ||
| declare const External_2: { | ||
| new (value: number | bigint): External_2; | ||
| prototype: null; | ||
| }; | ||
| export { External_2 as External } | ||
| export declare class Finalizer { | ||
| envObject: Env; | ||
| private _finalizeCallback; | ||
| private _finalizeData; | ||
| private _finalizeHint; | ||
| private _makeDynCall_vppp; | ||
| constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p); | ||
| callback(): napi_finalize; | ||
| data(): void_p; | ||
| hint(): void_p; | ||
| resetEnv(): void; | ||
| resetFinalizer(): void; | ||
| callFinalizer(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare function getDefaultContext(): Context; | ||
| /** @public */ | ||
| export declare function getExternalValue(external: External_2): number | bigint; | ||
| export declare class Handle<S> { | ||
| id: number; | ||
| value: S; | ||
| constructor(id: number, value: S); | ||
| data(): void_p; | ||
| isNumber(): boolean; | ||
| isBigInt(): boolean; | ||
| isString(): boolean; | ||
| isFunction(): boolean; | ||
| isExternal(): boolean; | ||
| isObject(): boolean; | ||
| isArray(): boolean; | ||
| isArrayBuffer(): boolean; | ||
| isTypedArray(): boolean; | ||
| isBuffer(BufferConstructor?: BufferCtor): boolean; | ||
| isDataView(): boolean; | ||
| isDate(): boolean; | ||
| isPromise(): boolean; | ||
| isBoolean(): boolean; | ||
| isUndefined(): boolean; | ||
| isSymbol(): boolean; | ||
| isNull(): boolean; | ||
| dispose(): void; | ||
| } | ||
| export declare class HandleScope { | ||
| handleStore: HandleStore; | ||
| id: number; | ||
| parent: HandleScope | null; | ||
| child: HandleScope | null; | ||
| start: number; | ||
| end: number; | ||
| private _escapeCalled; | ||
| callbackInfo: ICallbackInfo; | ||
| constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number); | ||
| add<V>(value: V): Handle<V>; | ||
| addExternal(data: void_p): Handle<object>; | ||
| dispose(): void; | ||
| escape(handle: number): Handle<any> | null; | ||
| escapeCalled(): boolean; | ||
| } | ||
| export declare class HandleStore { | ||
| static UNDEFINED: ConstHandle<undefined>; | ||
| static NULL: ConstHandle<null>; | ||
| static FALSE: ConstHandle<false>; | ||
| static TRUE: ConstHandle<true>; | ||
| static GLOBAL: ConstHandle<typeof globalThis>; | ||
| static MIN_ID: 6; | ||
| private readonly _values; | ||
| private _next; | ||
| push<S>(value: S): Handle<S>; | ||
| erase(start: number, end: number): void; | ||
| get(id: Ptr): Handle<any> | undefined; | ||
| swap(a: number, b: number): void; | ||
| dispose(): void; | ||
| } | ||
| export declare interface ICallbackInfo { | ||
| thiz: any; | ||
| data: void_p; | ||
| args: ArrayLike<any>; | ||
| fn: Function; | ||
| } | ||
| export declare interface IDeferrdValue<T = any> { | ||
| resolve: (value: T) => void; | ||
| reject: (reason?: any) => void; | ||
| } | ||
| export declare interface IReferenceBinding { | ||
| wrapped: number; | ||
| tag: Uint32Array | null; | ||
| } | ||
| /** @public */ | ||
| export declare function isExternal(object: unknown): object is External_2; | ||
| export declare function isReferenceType(v: any): v is object; | ||
| export declare interface IStoreValue { | ||
| id: number; | ||
| dispose(): void; | ||
| [x: string]: any; | ||
| } | ||
| export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL; | ||
| export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| export declare const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX; | ||
| export declare const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN; | ||
| export declare class NodeEnv extends Env { | ||
| filename: string; | ||
| private readonly nodeBinding?; | ||
| destructing: boolean; | ||
| finalizationScheduled: boolean; | ||
| 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); | ||
| deleteMe(): void; | ||
| canCallIntoJs(): boolean; | ||
| triggerFatalException(err: any): void; | ||
| callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T; | ||
| callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void; | ||
| enqueueFinalizer(finalizer: RefTracker): void; | ||
| drainFinalizerQueue(): void; | ||
| } | ||
| export declare class NotSupportBufferError extends EmnapiError { | ||
| constructor(api: string, message: string); | ||
| } | ||
| export declare class NotSupportWeakRefError extends EmnapiError { | ||
| constructor(api: string, message: string); | ||
| } | ||
| export declare class Persistent<T> { | ||
| private _ref; | ||
| private _param; | ||
| private _callback; | ||
| private static readonly _registry; | ||
| constructor(value: T); | ||
| setWeak<P>(param: P, callback: (param: P) => void): void; | ||
| clearWeak(): void; | ||
| reset(): void; | ||
| isEmpty(): boolean; | ||
| deref(): T | undefined; | ||
| } | ||
| export declare class Reference extends RefTracker implements IStoreValue { | ||
| private static weakCallback; | ||
| id: number; | ||
| envObject: Env; | ||
| private readonly canBeWeak; | ||
| private _refcount; | ||
| private readonly _ownership; | ||
| persistent: Persistent<object>; | ||
| static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference; | ||
| protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership); | ||
| ref(): number; | ||
| unref(): number; | ||
| get(envObject?: Env): napi_value; | ||
| /** @virtual */ | ||
| resetFinalizer(): void; | ||
| /** @virtual */ | ||
| data(): void_p; | ||
| refcount(): number; | ||
| ownership(): ReferenceOwnership; | ||
| /** @virtual */ | ||
| protected callUserFinalizer(): void; | ||
| /** @virtual */ | ||
| protected invokeFinalizerFromGC(): void; | ||
| private _setWeak; | ||
| finalize(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare enum ReferenceOwnership { | ||
| kRuntime = 0, | ||
| kUserland = 1 | ||
| } | ||
| export declare class ReferenceWithData extends Reference { | ||
| private readonly _data; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData; | ||
| private constructor(); | ||
| data(): void_p; | ||
| } | ||
| export declare class ReferenceWithFinalizer extends Reference { | ||
| private _finalizer; | ||
| static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer; | ||
| private constructor(); | ||
| resetFinalizer(): void; | ||
| data(): void_p; | ||
| protected callUserFinalizer(): void; | ||
| protected invokeFinalizerFromGC(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class RefTracker { | ||
| /** @virtual */ | ||
| dispose(): void; | ||
| /** @virtual */ | ||
| finalize(): void; | ||
| private _next; | ||
| private _prev; | ||
| link(list: RefTracker): void; | ||
| unlink(): void; | ||
| static finalizeAll(list: RefTracker): void; | ||
| } | ||
| export declare class ScopeStore { | ||
| private readonly _rootScope; | ||
| currentScope: HandleScope; | ||
| private readonly _values; | ||
| constructor(); | ||
| get(id: number): HandleScope | undefined; | ||
| openScope(handleStore: HandleStore): HandleScope; | ||
| closeScope(): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class Store<V extends IStoreValue> { | ||
| protected _values: Array<V | undefined>; | ||
| private _freeList; | ||
| private _size; | ||
| constructor(); | ||
| add(value: V): void; | ||
| get(id: Ptr): V | undefined; | ||
| has(id: Ptr): boolean; | ||
| remove(id: Ptr): void; | ||
| dispose(): void; | ||
| } | ||
| export declare class TrackedFinalizer extends RefTracker { | ||
| private _finalizer; | ||
| static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer; | ||
| private constructor(); | ||
| data(): void_p; | ||
| dispose(): void; | ||
| finalize(): void; | ||
| } | ||
| export declare class TryCatch { | ||
| private _exception; | ||
| private _caught; | ||
| isEmpty(): boolean; | ||
| hasCaught(): boolean; | ||
| exception(): any; | ||
| setError(err: any): void; | ||
| reset(): void; | ||
| extractException(): any; | ||
| } | ||
| export declare const version: string; | ||
| export { } |
| !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).emnapi={})}(this,function(t){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}"function"==typeof SuppressedError&&SuppressedError;var i=new WeakMap;function r(t){return i.has(t)}var o=function(){function t(t){Object.setPrototypeOf(this,null),i.set(this,t)}return t.prototype=null,t}();function s(t){if(!r(t))throw new TypeError("not external");return i.get(t)}var a=function(){var t;try{t=new Function}catch(t){return!1}return"function"==typeof t}(),u=function(){if("undefined"!=typeof globalThis)return globalThis;var t=function(){return this}();if(!t&&a)try{t=new Function("return this")()}catch(t){}if(!t){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return t}(),c=function(){function t(){this._exception=void 0,this._caught=!1}return t.prototype.isEmpty=function(){return!this._caught},t.prototype.hasCaught=function(){return this._caught},t.prototype.exception=function(){return this._exception},t.prototype.setError=function(t){this._caught=!0,this._exception=t},t.prototype.reset=function(){this._caught=!1,this._exception=void 0},t.prototype.extractException=function(){var t=this._exception;return this.reset(),t},t}(),p=function(){var t;try{return Boolean(null===(t=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===t?void 0:t.configurable)}catch(t){return!1}}(),l="object"==typeof Reflect,f="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,h=function(){try{var t=Symbol();new WeakRef(t),(new WeakMap).set(t,void 0)}catch(t){return!1}return!0}(),d="undefined"!=typeof BigInt;var y=function(){return"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}(),_="function"==typeof MessageChannel?MessageChannel:function(){try{return y("worker_threads").MessageChannel}catch(t){}}(),v="function"==typeof setImmediate?setImmediate:function(t){if("function"!=typeof t)throw new TypeError('The "callback" argument must be of type function');if(_){var e=new _;e.port1.onmessage=function(){e.port1.onmessage=null,e=void 0,t()},e.port2.postMessage(null)}else setTimeout(t,0)},g="function"==typeof Buffer?Buffer:function(){try{return y("buffer").Buffer}catch(t){}}(),z="1.10.0",b=2147483647,w=function(){function t(t,e){this.id=t,this.value=e}return t.prototype.data=function(){return s(this.value)},t.prototype.isNumber=function(){return"number"==typeof this.value},t.prototype.isBigInt=function(){return"bigint"==typeof this.value},t.prototype.isString=function(){return"string"==typeof this.value},t.prototype.isFunction=function(){return"function"==typeof this.value},t.prototype.isExternal=function(){return r(this.value)},t.prototype.isObject=function(){return"object"==typeof this.value&&null!==this.value},t.prototype.isArray=function(){return Array.isArray(this.value)},t.prototype.isArrayBuffer=function(){return this.value instanceof ArrayBuffer},t.prototype.isTypedArray=function(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)},t.prototype.isBuffer=function(t){return!!ArrayBuffer.isView(this.value)||(null!=t||(t=g),"function"==typeof t&&t.isBuffer(this.value))},t.prototype.isDataView=function(){return this.value instanceof DataView},t.prototype.isDate=function(){return this.value instanceof Date},t.prototype.isPromise=function(){return this.value instanceof Promise},t.prototype.isBoolean=function(){return"boolean"==typeof this.value},t.prototype.isUndefined=function(){return void 0===this.value},t.prototype.isSymbol=function(){return"symbol"==typeof this.value},t.prototype.isNull=function(){return null===this.value},t.prototype.dispose=function(){this.value=void 0},t}(),k=function(t){function e(e,n){return t.call(this,e,n)||this}return n(e,t),e.prototype.dispose=function(){},e}(w),m=function(){function t(){this._values=[void 0,t.UNDEFINED,t.NULL,t.FALSE,t.TRUE,t.GLOBAL],this._next=t.MIN_ID}return t.prototype.push=function(t){var e,n=this._next,i=this._values;return n<i.length?(e=i[n]).value=t:(e=new w(n,t),i[n]=e),this._next++,e},t.prototype.erase=function(t,e){this._next=t;for(var n=this._values,i=t;i<e;++i)n[i].dispose()},t.prototype.get=function(t){return this._values[t]},t.prototype.swap=function(t,e){var n=this._values,i=n[t];n[t]=n[e],n[t].id=Number(t),n[e]=i,i.id=Number(e)},t.prototype.dispose=function(){this._values.length=t.MIN_ID,this._next=t.MIN_ID},t.UNDEFINED=new k(1,void 0),t.NULL=new k(2,null),t.FALSE=new k(3,!1),t.TRUE=new k(4,!0),t.GLOBAL=new k(5,u),t.MIN_ID=6,t}(),E=function(){function t(t,e,n,i,r){void 0===r&&(r=i),this.handleStore=t,this.id=e,this.parent=n,this.child=null,null!==n&&(n.child=this),this.start=i,this.end=r,this._escapeCalled=!1,this.callbackInfo={thiz:void 0,data:0,args:void 0,fn:void 0}}return t.prototype.add=function(t){var e=this.handleStore.push(t);return this.end++,e},t.prototype.addExternal=function(t){return this.add(new o(t))},t.prototype.dispose=function(){this._escapeCalled&&(this._escapeCalled=!1),this.start!==this.end&&this.handleStore.erase(this.start,this.end)},t.prototype.escape=function(t){if(this._escapeCalled)return null;if(this._escapeCalled=!0,t<this.start||t>=this.end)return null;this.handleStore.swap(t,this.start);var e=this.handleStore.get(this.start);return this.start++,this.parent.end++,e},t.prototype.escapeCalled=function(){return this._escapeCalled},t}(),S=function(){function t(){this._rootScope=new E(null,0,null,1,m.MIN_ID),this.currentScope=this._rootScope,this._values=[void 0]}return t.prototype.get=function(t){return this._values[t]},t.prototype.openScope=function(t){var e=this.currentScope,n=e.child;if(null!==n)n.start=n.end=e.end;else{var i=e.id+1;n=new E(t,i,e,e.end),this._values[i]=n}return this.currentScope=n,n},t.prototype.closeScope=function(){var t=this.currentScope;this.currentScope=t.parent,t.dispose()},t.prototype.dispose=function(){this.currentScope=this._rootScope,this._values.length=1},t}(),C=function(){function t(){this._next=null,this._prev=null}return t.prototype.dispose=function(){},t.prototype.finalize=function(){},t.prototype.link=function(t){this._prev=t,this._next=t._next,null!==this._next&&(this._next._prev=this),t._next=this},t.prototype.unlink=function(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null},t.finalizeAll=function(t){for(;null!==t._next;)t._next.finalize()},t}(),x=function(){function t(t,e,n,i){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.envObject=t,this._finalizeCallback=e,this._finalizeData=n,this._finalizeHint=i,this._makeDynCall_vppp=t.makeDynCall_vppp}return t.prototype.callback=function(){return this._finalizeCallback},t.prototype.data=function(){return this._finalizeData},t.prototype.hint=function(){return this._finalizeHint},t.prototype.resetEnv=function(){this.envObject=void 0},t.prototype.resetFinalizer=function(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0},t.prototype.callFinalizer=function(){var t=this._finalizeCallback,e=this._finalizeData,n=this._finalizeHint;if(this.resetFinalizer(),t){var i=Number(t);this.envObject?this.envObject.callFinalizer(i,e,n):this._makeDynCall_vppp(i)(0,e,n)}},t.prototype.dispose=function(){this.envObject=void 0,this._makeDynCall_vppp=void 0},t}(),F=function(t){function e(e,n,i,r){var o=t.call(this)||this;return o._finalizer=new x(e,n,i,r),o}return n(e,t),e.create=function(t,n,i,r){var o=new e(t,n,i,r);return o.link(t.finalizing_reflist),o},e.prototype.data=function(){return this._finalizer.data()},e.prototype.dispose=function(){this._finalizer&&(this.unlink(),this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),this._finalizer=void 0,t.prototype.dispose.call(this))},e.prototype.finalize=function(){var t;this.unlink();var e=!1;try{this._finalizer.callFinalizer()}catch(n){e=!0,t=n}if(this.dispose(),e)throw t},e}(C);function O(t,e){if(!t.terminatedOrTerminating())throw e}var I=function(){function t(t,e,n,i,r){this.ctx=t,this.moduleApiVersion=e,this.makeDynCall_vppp=n,this.makeDynCall_vp=i,this.abort=r,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new c,this.refs=1,this.reflist=new C,this.finalizing_reflist=new C,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,this._bindingMap=new WeakMap,this.id=0}return t.prototype.canCallIntoJs=function(){return!0},t.prototype.terminatedOrTerminating=function(){return!this.canCallIntoJs()},t.prototype.ref=function(){this.refs++},t.prototype.unref=function(){this.refs--,0===this.refs&&this.dispose()},t.prototype.ensureHandle=function(t){return this.ctx.ensureHandle(t)},t.prototype.ensureHandleId=function(t){return this.ensureHandle(t).id},t.prototype.clearLastError=function(){var t=this.lastError;return 0!==t.errorCode&&(t.errorCode=0),0!==t.engineErrorCode&&(t.engineErrorCode=0),0!==t.engineReserved&&(t.engineReserved=0),0},t.prototype.setLastError=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n=0);var i=this.lastError;return i.errorCode!==t&&(i.errorCode=t),i.engineErrorCode!==e&&(i.engineErrorCode=e),i.engineReserved!==n&&(i.engineReserved=n),t},t.prototype.getReturnStatus=function(){return this.tryCatch.hasCaught()?this.setLastError(10):0},t.prototype.callIntoModule=function(t,e){void 0===e&&(e=O);var n=this.openHandleScopes;this.clearLastError();var i=t(this);(n!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught())&&e(this,this.tryCatch.extractException());return i},t.prototype.invokeFinalizerFromGC=function(t){if(this.moduleApiVersion!==b)this.enqueueFinalizer(t);else{var e=this.inGcFinalizer;this.inGcFinalizer=!0;try{t.finalize()}finally{this.inGcFinalizer=e}}},t.prototype.checkGCAccess=function(){this.moduleApiVersion===b&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")},t.prototype.enqueueFinalizer=function(t){-1===this.pendingFinalizers.indexOf(t)&&this.pendingFinalizers.push(t)},t.prototype.dequeueFinalizer=function(t){var e=this.pendingFinalizers.indexOf(t);-1!==e&&this.pendingFinalizers.splice(e,1)},t.prototype.deleteMe=function(){C.finalizeAll(this.finalizing_reflist),C.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)},t.prototype.dispose=function(){0!==this.id&&(this.deleteMe(),this.finalizing_reflist.dispose(),this.reflist.dispose(),this.id=0)},t.prototype.initObjectBinding=function(t){var e={wrapped:0,tag:null};return this._bindingMap.set(t,e),e},t.prototype.getObjectBinding=function(t){return this._bindingMap.has(t)?this._bindingMap.get(t):this.initObjectBinding(t)},t.prototype.setInstanceData=function(t,e,n){this.instanceData&&this.instanceData.dispose(),this.instanceData=F.create(this,e,t,n)},t.prototype.getInstanceData=function(){return this.instanceData?this.instanceData.data():0},t}(),D=function(t){function e(e,n,i,r,o,s,a){var u=t.call(this,e,i,r,o,s)||this;return u.filename=n,u.nodeBinding=a,u.destructing=!1,u.finalizationScheduled=!1,u}return n(e,t),e.prototype.deleteMe=function(){this.destructing=!0,this.drainFinalizerQueue(),t.prototype.deleteMe.call(this)},e.prototype.canCallIntoJs=function(){return t.prototype.canCallIntoJs.call(this)&&this.ctx.canCallIntoJs()},e.prototype.triggerFatalException=function(t){if(this.nodeBinding)this.nodeBinding.napi.fatalException(t);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw t;process._fatalException(t)||(console.error(t),process.exit(1))}},e.prototype.callbackIntoModule=function(t,e){return this.callIntoModule(e,function(e,n){if(!e.terminatedOrTerminating()){var i="object"==typeof process&&null!==process,r=!!i&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(e.moduleApiVersion<10&&!r&&!t)(i&&"function"==typeof process.emitWarning?process.emitWarning:function(t,e,n){if(t instanceof Error)console.warn(t.toString());else{var i=n?"[".concat(n,"] "):"";console.warn("".concat(i).concat(e||"Warning",": ").concat(t))}})("Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168");else e.triggerFatalException(n)}})},e.prototype.callFinalizer=function(t,e,n){this.callFinalizerInternal(1,t,e,n)},e.prototype.callFinalizerInternal=function(t,e,n,i){var r=this.makeDynCall_vppp(e),o=this.id,s=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(t),function(){r(o,n,i)})}finally{this.ctx.closeScope(this,s)}},e.prototype.enqueueFinalizer=function(e){var n=this;t.prototype.enqueueFinalizer.call(this,e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),v(function(){n.finalizationScheduled=!1,n.unref(),n.drainFinalizerQueue()}))},e.prototype.drainFinalizerQueue=function(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}},e}(I);function R(t,e,n,i,r,o,s){(n="number"!=typeof n?8:n)<8?n=8:n>10&&n!==b&&function(t,e){var n="".concat(t," requires Node-API version ").concat(e,", but this version of Node.js only supports version ").concat(10," add-ons.");throw new Error(n)}(e,n);var a=new D(t,e,n,i,r,o,s);return t.envStore.add(a),t.addCleanupHook(a,function(){a.unref()},0),a}var N=function(t){function e(n){var i=this.constructor,r=t.call(this,n)||this,o=i,s=o.prototype;if(!(r instanceof e)){var a=Object.setPrototypeOf;"function"==typeof a?a.call(Object,r,s):r.__proto__=s,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(r,o)}return r}return n(e,t),e}(Error);Object.defineProperty(N.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});var j=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "FinalizationRegistry" and "WeakRef".').concat(n?" ".concat(n):""))||this}return n(e,t),e}(N);Object.defineProperty(j.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});var A=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "Buffer". Consider using buffer polyfill to make sure `globalThis.Buffer` is defined.').concat(n?" ".concat(n):""))||this}return n(e,t),e}(N);Object.defineProperty(A.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});var H,B=function(){function t(t){this._value=t}return t.prototype.deref=function(){return this._value},t.prototype.dispose=function(){this._value=void 0},t}(),M=function(){function t(t){this._ref=new B(t)}return t.prototype.setWeak=function(e,n){if(f&&void 0!==this._ref&&!(this._ref instanceof WeakRef)){var i=this._ref.deref();try{t._registry.register(i,this,this);var r=new WeakRef(i);this._ref.dispose(),this._ref=r,this._param=e,this._callback=n}catch(t){if("symbol"!=typeof i)throw t}}},t.prototype.clearWeak=function(){if(f&&void 0!==this._ref&&this._ref instanceof WeakRef){try{t._registry.unregister(this)}catch(t){}this._param=void 0,this._callback=void 0;var e=this._ref.deref();this._ref=void 0===e?e:new B(e)}},t.prototype.reset=function(){if(f)try{t._registry.unregister(this)}catch(t){}this._param=void 0,this._callback=void 0,this._ref instanceof B&&this._ref.dispose(),this._ref=void 0},t.prototype.isEmpty=function(){return void 0===this._ref},t.prototype.deref=function(){if(void 0!==this._ref)return this._ref.deref()},t._registry=f?new FinalizationRegistry(function(t){t._ref=void 0;var e=t._callback,n=t._param;t._callback=void 0,t._param=void 0,"function"==typeof e&&e(n)}):void 0,t}();t.ReferenceOwnership=void 0,(H=t.ReferenceOwnership||(t.ReferenceOwnership={}))[H.kRuntime=0]="kRuntime",H[H.kUserland=1]="kUserland";var T,W=function(e){function i(t,n,i,r){var o=e.call(this)||this;o.envObject=t,o._refcount=i,o._ownership=r;var s,a=t.ctx.handleStore.get(n);return o.canBeWeak=(s=a).isObject()||s.isFunction()||s.isSymbol(),o.persistent=new M(a.value),o.id=0,0===i&&o._setWeak(),o}return n(i,e),i.weakCallback=function(t){t.persistent.reset(),t.invokeFinalizerFromGC()},i.create=function(t,e,n,r,o,s,a){var u=new i(t,e,n,r);return t.ctx.refStore.add(u),u.link(t.reflist),u},i.prototype.ref=function(){return this.persistent.isEmpty()?0:(1===++this._refcount&&this.canBeWeak&&this.persistent.clearWeak(),this._refcount)},i.prototype.unref=function(){return this.persistent.isEmpty()||0===this._refcount?0:(0===--this._refcount&&this._setWeak(),this._refcount)},i.prototype.get=function(t){if(void 0===t&&(t=this.envObject),this.persistent.isEmpty())return 0;var e=this.persistent.deref();return t.ensureHandle(e).id},i.prototype.resetFinalizer=function(){},i.prototype.data=function(){return 0},i.prototype.refcount=function(){return this._refcount},i.prototype.ownership=function(){return this._ownership},i.prototype.callUserFinalizer=function(){},i.prototype.invokeFinalizerFromGC=function(){this.finalize()},i.prototype._setWeak=function(){this.canBeWeak?this.persistent.setWeak(this,i.weakCallback):this.persistent.reset()},i.prototype.finalize=function(){this.persistent.reset();var e=this._ownership===t.ReferenceOwnership.kRuntime;this.unlink(),this.callUserFinalizer(),e&&this.dispose()},i.prototype.dispose=function(){0!==this.id&&(this.unlink(),this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),e.prototype.dispose.call(this),this.envObject=void 0,this.id=0)},i}(C),P=function(t){function e(e,n,i,r,o){var s=t.call(this,e,n,i,r)||this;return s._data=o,s}return n(e,t),e.create=function(t,n,i,r,o){var s=new e(t,n,i,r,o);return t.ctx.refStore.add(s),s.link(t.reflist),s},e.prototype.data=function(){return this._data},e}(W),L=function(t){function e(e,n,i,r,o,s,a){var u=t.call(this,e,n,i,r)||this;return u._finalizer=new x(e,o,s,a),u}return n(e,t),e.create=function(t,n,i,r,o,s,a){var u=new e(t,n,i,r,o,s,a);return t.ctx.refStore.add(u),u.link(t.finalizing_reflist),u},e.prototype.resetFinalizer=function(){this._finalizer.resetFinalizer()},e.prototype.data=function(){return this._finalizer.data()},e.prototype.callUserFinalizer=function(){this._finalizer.callFinalizer()},e.prototype.invokeFinalizerFromGC=function(){this._finalizer.envObject.invokeFinalizerFromGC(this)},e.prototype.dispose=function(){this._finalizer&&(this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),t.prototype.dispose.call(this),this._finalizer=void 0)},e}(W),U=function(){function t(t,e){this.id=0,this.ctx=t,this.value=e}return t.create=function(e,n){var i=new t(e,n);return e.deferredStore.add(i),i},t.prototype.resolve=function(t){this.value.resolve(t),this.dispose()},t.prototype.reject=function(t){this.value.reject(t),this.dispose()},t.prototype.dispose=function(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null},t}(),V=function(){function t(){this._values=[void 0],this._values.length=4,this._size=1,this._freeList=[]}return t.prototype.add=function(t){var e;if(this._freeList.length)e=this._freeList.shift();else{e=this._size,this._size++;var n=this._values.length;e>=n&&(this._values.length=n+(n>>1)+16)}t.id=e,this._values[e]=t},t.prototype.get=function(t){return this._values[t]},t.prototype.has=function(t){return void 0!==this._values[t]},t.prototype.remove=function(t){var e=this._values[t];e&&(e.id=0,this._values[t]=void 0,this._freeList.push(Number(t)))},t.prototype.dispose=function(){for(var t=1;t<this._size;++t){var e=this._values[t];null==e||e.dispose()}this._values=[void 0],this._size=1,this._freeList=[]},t}(),G=BigInt(1)<<BigInt(60),q=-G,J=function(){function t(t){this.total=BigInt(0),this.onChange=null!=t?t:null}return t.prototype.adjust=function(t){if(t=BigInt(t),!(q<=t&&t<G))throw new RangeError("changeInBytes ".concat(t," is out of reasonable range"));var e=this.total;this.total+=t;var n=this.total,i=this.onChange;return t&&(null==i||i(n,e,t)),n},t}(),Q=function(){return function(t,e,n,i){this.envObject=t,this.fn=e,this.arg=n,this.order=i}}(),X=function(){function t(){this._cleanupHooks=[],this._cleanupHookCounter=0}return t.prototype.empty=function(){return 0===this._cleanupHooks.length},t.prototype.add=function(t,e,n){if(this._cleanupHooks.filter(function(i){return i.envObject===t&&i.fn===e&&i.arg===n}).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new Q(t,e,n,this._cleanupHookCounter++))},t.prototype.remove=function(t,e,n){for(var i=0;i<this._cleanupHooks.length;++i){var r=this._cleanupHooks[i];if(r.envObject===t&&r.fn===e&&r.arg===n)return void this._cleanupHooks.splice(i,1)}},t.prototype.drain=function(){var t=this._cleanupHooks.slice();t.sort(function(t,e){return e.order-t.order});for(var e=0;e<t.length;++e){var n=t[e];"number"==typeof n.fn?n.envObject.makeDynCall_vp(n.fn)(n.arg):n.fn(n.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(n),1)}},t.prototype.dispose=function(){this._cleanupHooks.length=0,this._cleanupHookCounter=0},t}(),K=function(){function t(){this.refHandle=(new _).port1,this.count=0}return t.prototype.increase=function(){0===this.count&&this.refHandle.ref&&this.refHandle.ref(),this.count++},t.prototype.decrease=function(){0!==this.count&&(1===this.count&&this.refHandle.unref&&this.refHandle.unref(),this.count--)},t}(),Y=function(){function t(t){var e=this;this._isStopping=!1,this._canCallIntoJs=!0,this._suppressDestroy=!1,this.envStore=new V,this.scopeStore=new S,this.refStore=new V,this.deferredStore=new V,this.handleStore=new m,this.feature={supportReflect:l,supportFinalizer:f,supportWeakSymbol:h,supportBigInt:d,supportNewFunction:a,canSetFunctionName:p,setImmediate:v,Buffer:g,MessageChannel:_},this.cleanupQueue=new X,this._externalMemory=new J(null==t?void 0:t.onExternalMemoryChange),"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new K,process.once("beforeExit",function(){e._suppressDestroy||e.destroy()}))}return t.prototype.suppressDestroy=function(){this._suppressDestroy=!0},t.prototype.getRuntimeVersions=function(){return{version:z,NODE_API_SUPPORTED_VERSION_MAX:10,NAPI_VERSION_EXPERIMENTAL:b,NODE_API_DEFAULT_MODULE_API_VERSION:8}},t.prototype.createNotSupportWeakRefError=function(t,e){return new j(t,e)},t.prototype.createNotSupportBufferError=function(t,e){return new A(t,e)},t.prototype.createReference=function(t,e,n,i){return W.create(t,e,n,i)},t.prototype.createReferenceWithData=function(t,e,n,i,r){return P.create(t,e,n,i,r)},t.prototype.createReferenceWithFinalizer=function(t,e,n,i,r,o,s){return void 0===r&&(r=0),void 0===o&&(o=0),void 0===s&&(s=0),L.create(t,e,n,i,r,o,s)},t.prototype.createDeferred=function(t){return U.create(this,t)},t.prototype.adjustAmountOfExternalAllocatedMemory=function(t){return this._externalMemory.adjust(t)},t.prototype.createEnv=function(t,e,n,i,r,o){return R(this,t,e,n,i,r,o)},t.prototype.createTrackedFinalizer=function(t,e,n,i){return F.create(t,e,n,i)},t.prototype.getCurrentScope=function(){return this.scopeStore.currentScope},t.prototype.addToCurrentScope=function(t){return this.scopeStore.currentScope.add(t)},t.prototype.openScope=function(t){var e=this.scopeStore.openScope(this.handleStore);return t&&t.openHandleScopes++,e},t.prototype.closeScope=function(t,e){t&&0===t.openHandleScopes||(this.scopeStore.closeScope(),t&&t.openHandleScopes--)},t.prototype.ensureHandle=function(t){switch(t){case void 0:return m.UNDEFINED;case null:return m.NULL;case!0:return m.TRUE;case!1:return m.FALSE;case u:return m.GLOBAL}return this.addToCurrentScope(t)},t.prototype.addCleanupHook=function(t,e,n){this.cleanupQueue.add(t,e,n)},t.prototype.removeCleanupHook=function(t,e,n){this.cleanupQueue.remove(t,e,n)},t.prototype.runCleanup=function(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()},t.prototype.increaseWaitingRequestCounter=function(){var t;null===(t=this.refCounter)||void 0===t||t.increase()},t.prototype.decreaseWaitingRequestCounter=function(){var t;null===(t=this.refCounter)||void 0===t||t.decrease()},t.prototype.setCanCallIntoJs=function(t){this._canCallIntoJs=t},t.prototype.setStopping=function(t){this._isStopping=t},t.prototype.canCallIntoJs=function(){return this._canCallIntoJs&&!this._isStopping},t.prototype.destroy=function(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()},t}();function Z(t){return new Y(t)}t.ConstHandle=k,t.Context=Y,t.Deferred=U,t.EmnapiError=N,t.Env=I,t.External=o,t.Finalizer=x,t.Handle=w,t.HandleScope=E,t.HandleStore=m,t.NAPI_VERSION_EXPERIMENTAL=b,t.NODE_API_DEFAULT_MODULE_API_VERSION=8,t.NODE_API_SUPPORTED_VERSION_MAX=10,t.NODE_API_SUPPORTED_VERSION_MIN=1,t.NodeEnv=D,t.NotSupportBufferError=A,t.NotSupportWeakRefError=j,t.Persistent=M,t.RefTracker=C,t.Reference=W,t.ReferenceWithData=P,t.ReferenceWithFinalizer=L,t.ScopeStore=S,t.Store=V,t.TrackedFinalizer=F,t.TryCatch=c,t.createContext=Z,t.getDefaultContext=function(){return T||(T=Z()),T},t.getExternalValue=s,t.isExternal=r,t.isReferenceType=function(t){return"object"==typeof t&&null!==t||"function"==typeof t},t.version=z}); |
| const e=new WeakMap;function t(t){return e.has(t)}const i=(()=>{function t(t){Object.setPrototypeOf(this,null),e.set(this,t)}return t.prototype=null,t})();function s(i){if(!t(i))throw new TypeError("not external");return e.get(i)}const n=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&&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 o{constructor(){this._exception=void 0,this._caught=!1}isEmpty(){return!this._caught}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,h=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),u="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="1.10.0",y=1,z=10,b=2147483647,k=8;class w{constructor(e,t){this.id=e,this.value=t}data(){return s(this.value)}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 t(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(e){return!!ArrayBuffer.isView(this.value)||(null!=e||(e=v),"function"==typeof e&&e.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 m extends w{constructor(e,t){super(e,t)}dispose(){}}class C{constructor(){this._values=[void 0,C.UNDEFINED,C.NULL,C.FALSE,C.TRUE,C.GLOBAL],this._next=C.MIN_ID}push(e){let t;const i=this._next,s=this._values;return i<s.length?(t=s[i],t.value=e):(t=new w(i,e),s[i]=t),this._next++,t}erase(e,t){this._next=e;const i=this._values;for(let s=e;s<t;++s)i[s].dispose()}get(e){return this._values[e]}swap(e,t){const i=this._values,s=i[e];i[e]=i[t],i[e].id=Number(e),i[t]=s,s.id=Number(t)}dispose(){this._values.length=C.MIN_ID,this._next=C.MIN_ID}}C.UNDEFINED=new m(1,void 0),C.NULL=new m(2,null),C.FALSE=new m(3,!1),C.TRUE=new m(4,!0),C.GLOBAL=new m(5,r),C.MIN_ID=6;class S{constructor(e,t,i,s,n=s){this.handleStore=e,this.id=t,this.parent=i,this.child=null,null!==i&&(i.child=this),this.start=s,this.end=n,this._escapeCalled=!1,this.callbackInfo={thiz:void 0,data:0,args:void 0,fn:void 0}}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e){return this.add(new i(e))}dispose(){this._escapeCalled&&(this._escapeCalled=!1),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 x{constructor(){this._rootScope=new S(null,0,null,1,C.MIN_ID),this.currentScope=this._rootScope,this._values=[void 0]}get(e){return this._values[e]}openScope(e){const t=this.currentScope;let i=t.child;if(null!==i)i.start=i.end=t.end;else{const s=t.id+1;i=new S(e,s,t,t.end),this._values[s]=i}return this.currentScope=i,i}closeScope(){const e=this.currentScope;this.currentScope=e.parent,e.dispose()}dispose(){this.currentScope=this._rootScope,this._values.length=1}}class E{constructor(){this._next=null,this._prev=null}dispose(){}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 F{constructor(e,t=0,i=0,s=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=i,this._finalizeHint=s,this._makeDynCall_vppp=e.makeDynCall_vppp}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetEnv(){this.envObject=void 0}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}callFinalizer(){const e=this._finalizeCallback,t=this._finalizeData,i=this._finalizeHint;if(this.resetFinalizer(),!e)return;const s=Number(e);this.envObject?this.envObject.callFinalizer(s,t,i):this._makeDynCall_vppp(s)(0,t,i)}dispose(){this.envObject=void 0,this._makeDynCall_vppp=void 0}}class I extends E{static create(e,t,i,s){const n=new I(e,t,i,s);return n.link(e.finalizing_reflist),n}constructor(e,t,i,s){super(),this._finalizer=new F(e,t,i,s)}data(){return this._finalizer.data()}dispose(){this._finalizer&&(this.unlink(),this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),this._finalizer=void 0,super.dispose())}finalize(){let e;this.unlink();let t=!1;try{this._finalizer.callFinalizer()}catch(i){t=!0,e=i}if(this.dispose(),t)throw e}}function D(e,t){if(!e.terminatedOrTerminating())throw t}class O{constructor(e,t,i,s,n){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=i,this.makeDynCall_vp=s,this.abort=n,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new o,this.refs=1,this.reflist=new E,this.finalizing_reflist=new E,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,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,i=0){const s=this.lastError;return s.errorCode!==e&&(s.errorCode=e),s.engineErrorCode!==t&&(s.engineErrorCode=t),s.engineReserved!==i&&(s.engineReserved=i),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=D){const i=this.openHandleScopes;this.clearLastError();const s=e(this);if(i!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return s}invokeFinalizerFromGC(e){if(this.moduleApiVersion!==b)this.enqueueFinalizer(e);else{const t=this.inGcFinalizer;this.inGcFinalizer=!0;try{e.finalize()}finally{this.inGcFinalizer=t}}}checkGCAccess(){this.moduleApiVersion===b&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")}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(){E.finalizeAll(this.finalizing_reflist),E.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),this.finalizing_reflist.dispose(),this.reflist.dispose(),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,i){this.instanceData&&this.instanceData.dispose(),this.instanceData=I.create(this,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class j extends O{constructor(e,t,i,s,n,r,o){super(e,i,s,n,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return super.canCallIntoJs()&&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,i)=>{if(t.terminatedOrTerminating())return;const s="object"==typeof process&&null!==process,n=!!s&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(t.moduleApiVersion<10&&!n&&!e){return void(s&&"function"==typeof process.emitWarning?process.emitWarning:function(e,t,i){if(e instanceof Error)console.warn(e.toString());else{const s=i?`[${i}] `:"";console.warn(`${s}${t||"Warning"}: ${e}`)}})("Uncaught Node-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(i)})}callFinalizer(e,t,i){this.callFinalizerInternal(1,e,t,i)}callFinalizerInternal(e,t,i,s){const n=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),()=>{n(r,i,s)})}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 B(e,t,i,s,n,r,o){(i="number"!=typeof i?8:i)<8?i=8:i>10&&i!==b&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version 10 add-ons.`)}(t,i);const a=new j(e,t,i,s,n,r,o);return e.envStore.add(a),e.addCleanupHook(a,()=>{a.unref()},0),a}class H extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof H)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,i):this.__proto__=i,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(H.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class R extends H{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(R.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class N extends H{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(N.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class A{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class M{constructor(e){this._ref=new A(e)}setWeak(e,t){if(!c||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{M._registry.register(i,this,this);const s=new WeakRef(i);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof i)throw e}}clearWeak(){if(c&&void 0!==this._ref&&this._ref instanceof WeakRef){try{M._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 A(e)}}reset(){if(c)try{M._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof A&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}var W;M._registry=c?new FinalizationRegistry(e=>{e._ref=void 0;const t=e._callback,i=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(i)}):void 0,function(e){e[e.kRuntime=0]="kRuntime",e[e.kUserland=1]="kUserland"}(W||(W={}));class L extends E{static weakCallback(e){e.persistent.reset(),e.invokeFinalizerFromGC()}static create(e,t,i,s,n,r,o){const a=new L(e,t,i,s);return e.ctx.refStore.add(a),a.link(e.reflist),a}constructor(e,t,i,s){super(),this.envObject=e,this._refcount=i,this._ownership=s;const n=e.ctx.handleStore.get(t);var r;this.canBeWeak=(r=n).isObject()||r.isFunction()||r.isSymbol(),this.persistent=new M(n.value),this.id=0,0===i&&this._setWeak()}ref(){return this.persistent.isEmpty()?0:(1===++this._refcount&&this.canBeWeak&&this.persistent.clearWeak(),this._refcount)}unref(){return this.persistent.isEmpty()||0===this._refcount?0:(0===--this._refcount&&this._setWeak(),this._refcount)}get(e=this.envObject){if(this.persistent.isEmpty())return 0;const t=this.persistent.deref();return e.ensureHandle(t).id}resetFinalizer(){}data(){return 0}refcount(){return this._refcount}ownership(){return this._ownership}callUserFinalizer(){}invokeFinalizerFromGC(){this.finalize()}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,L.weakCallback):this.persistent.reset()}finalize(){this.persistent.reset();const e=this._ownership===W.kRuntime;this.unlink(),this.callUserFinalizer(),e&&this.dispose()}dispose(){0!==this.id&&(this.unlink(),this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.envObject=void 0,this.id=0)}}class T extends L{static create(e,t,i,s,n){const r=new T(e,t,i,s,n);return e.ctx.refStore.add(r),r.link(e.reflist),r}constructor(e,t,i,s,n){super(e,t,i,s),this._data=n}data(){return this._data}}class U extends L{static create(e,t,i,s,n,r,o){const a=new U(e,t,i,s,n,r,o);return e.ctx.refStore.add(a),a.link(e.finalizing_reflist),a}constructor(e,t,i,s,n,r,o){super(e,t,i,s),this._finalizer=new F(e,n,r,o)}resetFinalizer(){this._finalizer.resetFinalizer()}data(){return this._finalizer.data()}callUserFinalizer(){this._finalizer.callFinalizer()}invokeFinalizerFromGC(){this._finalizer.envObject.invokeFinalizerFromGC(this)}dispose(){this._finalizer&&(this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),super.dispose(),this._finalizer=void 0)}}class P{static create(e,t){const i=new P(e,t);return e.deferredStore.add(i),i}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 G{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=[]}}const q=BigInt(1)<<BigInt(60),V=-q;class ${constructor(e){this.total=BigInt(0),this.onChange=null!=e?e:null}adjust(e){if(e=BigInt(e),!(V<=e&&e<q))throw new RangeError(`changeInBytes ${e} is out of reasonable range`);const t=this.total;this.total+=e;const i=this.total,s=this.onChange;return e&&(null==s||s(i,t,e)),i}}class J{constructor(e,t,i,s){this.envObject=e,this.fn=t,this.arg=i,this.order=s}}class Q{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,i){if(this._cleanupHooks.filter(s=>s.envObject===e&&s.fn===t&&s.arg===i).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new J(e,t,i,this._cleanupHookCounter++))}remove(e,t,i){for(let s=0;s<this._cleanupHooks.length;++s){const n=this._cleanupHooks[s];if(n.envObject===e&&n.fn===t&&n.arg===i)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 i=e[t];"number"==typeof i.fn?i.envObject.makeDynCall_vp(i.fn)(i.arg):i.fn(i.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(i),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class X{constructor(){this.refHandle=(new f).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref&&this.refHandle.unref(),this.count--)}}class K{constructor(e){this._isStopping=!1,this._canCallIntoJs=!0,this._suppressDestroy=!1,this.envStore=new G,this.scopeStore=new x,this.refStore=new G,this.deferredStore=new G,this.handleStore=new C,this.feature={supportReflect:l,supportFinalizer:c,supportWeakSymbol:h,supportBigInt:u,supportNewFunction:n,canSetFunctionName:a,setImmediate:_,Buffer:v,MessageChannel:f},this.cleanupQueue=new Q,this._externalMemory=new $(null==e?void 0:e.onExternalMemoryChange),"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new X,process.once("beforeExit",()=>{this._suppressDestroy||this.destroy()}))}suppressDestroy(){this._suppressDestroy=!0}getRuntimeVersions(){return{version:g,NODE_API_SUPPORTED_VERSION_MAX:10,NAPI_VERSION_EXPERIMENTAL:b,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new R(e,t)}createNotSupportBufferError(e,t){return new N(e,t)}createReference(e,t,i,s){return L.create(e,t,i,s)}createReferenceWithData(e,t,i,s,n){return T.create(e,t,i,s,n)}createReferenceWithFinalizer(e,t,i,s,n=0,r=0,o=0){return U.create(e,t,i,s,n,r,o)}createDeferred(e){return P.create(this,e)}adjustAmountOfExternalAllocatedMemory(e){return this._externalMemory.adjust(e)}createEnv(e,t,i,s,n,r){return B(this,e,t,i,s,n,r)}createTrackedFinalizer(e,t,i,s){return I.create(e,t,i,s)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){const t=this.scopeStore.openScope(this.handleStore);return e&&e.openHandleScopes++,t}closeScope(e,t){e&&0===e.openHandleScopes||(this.scopeStore.closeScope(),e&&e.openHandleScopes--)}ensureHandle(e){switch(e){case void 0:return C.UNDEFINED;case null:return C.NULL;case!0:return C.TRUE;case!1:return C.FALSE;case r:return C.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,i){this.cleanupQueue.add(e,t,i)}removeCleanupHook(e,t,i){this.cleanupQueue.remove(e,t,i)}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 Y;function Z(e){return new K(e)}function ee(){return Y||(Y=Z()),Y}export{m as ConstHandle,K as Context,P as Deferred,H as EmnapiError,O as Env,i as External,F as Finalizer,w as Handle,S as HandleScope,C as HandleStore,b as NAPI_VERSION_EXPERIMENTAL,k as NODE_API_DEFAULT_MODULE_API_VERSION,z as NODE_API_SUPPORTED_VERSION_MAX,y as NODE_API_SUPPORTED_VERSION_MIN,j as NodeEnv,N as NotSupportBufferError,R as NotSupportWeakRefError,M as Persistent,E as RefTracker,L as Reference,W as ReferenceOwnership,T as ReferenceWithData,U as ReferenceWithFinalizer,x as ScopeStore,G as Store,I as TrackedFinalizer,o as TryCatch,Z as createContext,ee as getDefaultContext,s as getExternalValue,t as isExternal,p as isReferenceType,g as version}; |
-1350
| const externalValue = new WeakMap(); | ||
| function isExternal(object) { | ||
| return externalValue.has(object); | ||
| } | ||
| const External = (() => { | ||
| function External(value) { | ||
| Object.setPrototypeOf(this, null); | ||
| externalValue.set(this, value); | ||
| } | ||
| External.prototype = null; | ||
| return External; | ||
| })(); | ||
| function getExternalValue(external) { | ||
| if (!isExternal(external)) { | ||
| throw new TypeError('not external'); | ||
| } | ||
| return externalValue.get(external); | ||
| } | ||
| const supportNewFunction = (function () { | ||
| let f; | ||
| try { | ||
| f = new Function(); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| return typeof f === 'function'; | ||
| })(); | ||
| const _global = (function () { | ||
| if (typeof globalThis !== 'undefined') | ||
| return globalThis; | ||
| let g = (function () { return this; })(); | ||
| if (!g && supportNewFunction) { | ||
| try { | ||
| g = new Function('return this')(); | ||
| } | ||
| catch (_) { } | ||
| } | ||
| if (!g) { | ||
| if (typeof __webpack_public_path__ === 'undefined') { | ||
| if (typeof global !== 'undefined') | ||
| return global; | ||
| } | ||
| if (typeof window !== 'undefined') | ||
| return window; | ||
| if (typeof self !== 'undefined') | ||
| return self; | ||
| } | ||
| return g; | ||
| })(); | ||
| class TryCatch { | ||
| constructor() { | ||
| this._exception = undefined; | ||
| this._caught = false; | ||
| } | ||
| isEmpty() { | ||
| return !this._caught; | ||
| } | ||
| hasCaught() { | ||
| return this._caught; | ||
| } | ||
| exception() { | ||
| return this._exception; | ||
| } | ||
| setError(err) { | ||
| this._caught = true; | ||
| this._exception = err; | ||
| } | ||
| reset() { | ||
| this._caught = false; | ||
| this._exception = undefined; | ||
| } | ||
| extractException() { | ||
| const e = this._exception; | ||
| this.reset(); | ||
| return e; | ||
| } | ||
| } | ||
| const canSetFunctionName = (function () { | ||
| var _a; | ||
| try { | ||
| return Boolean((_a = Object.getOwnPropertyDescriptor(Function.prototype, 'name')) === null || _a === void 0 ? void 0 : _a.configurable); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| })(); | ||
| const supportReflect = typeof Reflect === 'object'; | ||
| const supportFinalizer = (typeof FinalizationRegistry !== 'undefined') && (typeof WeakRef !== 'undefined'); | ||
| const supportWeakSymbol = (function () { | ||
| try { | ||
| const sym = Symbol(); | ||
| new WeakRef(sym); | ||
| new WeakMap().set(sym, undefined); | ||
| } | ||
| catch (_) { | ||
| return false; | ||
| } | ||
| return true; | ||
| })(); | ||
| const supportBigInt = typeof BigInt !== 'undefined'; | ||
| function isReferenceType(v) { | ||
| return (typeof v === 'object' && v !== null) || typeof v === 'function'; | ||
| } | ||
| const _require = (function () { | ||
| let nativeRequire; | ||
| if (typeof __webpack_public_path__ !== 'undefined') { | ||
| nativeRequire = (function () { | ||
| return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined; | ||
| })(); | ||
| } | ||
| else { | ||
| nativeRequire = (function () { | ||
| return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined); | ||
| })(); | ||
| } | ||
| return nativeRequire; | ||
| })(); | ||
| const _MessageChannel = typeof MessageChannel === 'function' | ||
| ? MessageChannel | ||
| : (function () { | ||
| try { | ||
| return _require('worker_threads').MessageChannel; | ||
| } | ||
| catch (_) { } | ||
| return undefined; | ||
| })(); | ||
| const _setImmediate = typeof setImmediate === 'function' | ||
| ? setImmediate | ||
| : function (callback) { | ||
| if (typeof callback !== 'function') { | ||
| throw new TypeError('The "callback" argument must be of type function'); | ||
| } | ||
| if (_MessageChannel) { | ||
| let channel = new _MessageChannel(); | ||
| channel.port1.onmessage = function () { | ||
| channel.port1.onmessage = null; | ||
| channel = undefined; | ||
| callback(); | ||
| }; | ||
| channel.port2.postMessage(null); | ||
| } | ||
| else { | ||
| setTimeout(callback, 0); | ||
| } | ||
| }; | ||
| const _Buffer = typeof Buffer === 'function' | ||
| ? Buffer | ||
| : (function () { | ||
| try { | ||
| return _require('buffer').Buffer; | ||
| } | ||
| catch (_) { } | ||
| return undefined; | ||
| })(); | ||
| const version = "1.10.0"; | ||
| const NODE_API_SUPPORTED_VERSION_MIN = 1; | ||
| const NODE_API_SUPPORTED_VERSION_MAX = 10; | ||
| const NAPI_VERSION_EXPERIMENTAL = 2147483647; | ||
| const NODE_API_DEFAULT_MODULE_API_VERSION = 8; | ||
| class Handle { | ||
| constructor(id, value) { | ||
| this.id = id; | ||
| this.value = value; | ||
| } | ||
| data() { | ||
| return getExternalValue(this.value); | ||
| } | ||
| isNumber() { | ||
| return typeof this.value === 'number'; | ||
| } | ||
| isBigInt() { | ||
| return typeof this.value === 'bigint'; | ||
| } | ||
| isString() { | ||
| return typeof this.value === 'string'; | ||
| } | ||
| isFunction() { | ||
| return typeof this.value === 'function'; | ||
| } | ||
| isExternal() { | ||
| return isExternal(this.value); | ||
| } | ||
| isObject() { | ||
| return typeof this.value === 'object' && this.value !== null; | ||
| } | ||
| isArray() { | ||
| return Array.isArray(this.value); | ||
| } | ||
| isArrayBuffer() { | ||
| return (this.value instanceof ArrayBuffer); | ||
| } | ||
| isTypedArray() { | ||
| return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView); | ||
| } | ||
| isBuffer(BufferConstructor) { | ||
| if (ArrayBuffer.isView(this.value)) | ||
| return true; | ||
| BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer); | ||
| return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value); | ||
| } | ||
| isDataView() { | ||
| return (this.value instanceof DataView); | ||
| } | ||
| isDate() { | ||
| return (this.value instanceof Date); | ||
| } | ||
| isPromise() { | ||
| return (this.value instanceof Promise); | ||
| } | ||
| isBoolean() { | ||
| return typeof this.value === 'boolean'; | ||
| } | ||
| isUndefined() { | ||
| return this.value === undefined; | ||
| } | ||
| isSymbol() { | ||
| return typeof this.value === 'symbol'; | ||
| } | ||
| isNull() { | ||
| return this.value === null; | ||
| } | ||
| dispose() { | ||
| this.value = undefined; | ||
| } | ||
| } | ||
| class ConstHandle extends Handle { | ||
| constructor(id, value) { | ||
| super(id, value); | ||
| } | ||
| dispose() { } | ||
| } | ||
| class HandleStore { | ||
| constructor() { | ||
| this._values = [ | ||
| undefined, | ||
| HandleStore.UNDEFINED, | ||
| HandleStore.NULL, | ||
| HandleStore.FALSE, | ||
| HandleStore.TRUE, | ||
| HandleStore.GLOBAL | ||
| ]; | ||
| this._next = HandleStore.MIN_ID; | ||
| } | ||
| push(value) { | ||
| let h; | ||
| const next = this._next; | ||
| const values = this._values; | ||
| if (next < values.length) { | ||
| h = values[next]; | ||
| h.value = value; | ||
| } | ||
| else { | ||
| h = new Handle(next, value); | ||
| values[next] = h; | ||
| } | ||
| this._next++; | ||
| return h; | ||
| } | ||
| erase(start, end) { | ||
| this._next = start; | ||
| const values = this._values; | ||
| for (let i = start; i < end; ++i) { | ||
| values[i].dispose(); | ||
| } | ||
| } | ||
| get(id) { | ||
| return this._values[id]; | ||
| } | ||
| swap(a, b) { | ||
| const values = this._values; | ||
| const h = values[a]; | ||
| values[a] = values[b]; | ||
| values[a].id = Number(a); | ||
| values[b] = h; | ||
| h.id = Number(b); | ||
| } | ||
| dispose() { | ||
| this._values.length = HandleStore.MIN_ID; | ||
| this._next = HandleStore.MIN_ID; | ||
| } | ||
| } | ||
| HandleStore.UNDEFINED = new ConstHandle(1, undefined); | ||
| HandleStore.NULL = new ConstHandle(2, null); | ||
| HandleStore.FALSE = new ConstHandle(3, false); | ||
| HandleStore.TRUE = new ConstHandle(4, true); | ||
| HandleStore.GLOBAL = new ConstHandle(5, _global); | ||
| HandleStore.MIN_ID = 6; | ||
| class HandleScope { | ||
| constructor(handleStore, id, parentScope, start, end = start) { | ||
| this.handleStore = handleStore; | ||
| this.id = id; | ||
| this.parent = parentScope; | ||
| this.child = null; | ||
| if (parentScope !== null) | ||
| parentScope.child = this; | ||
| this.start = start; | ||
| this.end = end; | ||
| this._escapeCalled = false; | ||
| this.callbackInfo = { | ||
| thiz: undefined, | ||
| data: 0, | ||
| args: undefined, | ||
| fn: undefined | ||
| }; | ||
| } | ||
| add(value) { | ||
| const h = this.handleStore.push(value); | ||
| this.end++; | ||
| return h; | ||
| } | ||
| addExternal(data) { | ||
| return this.add(new External(data)); | ||
| } | ||
| dispose() { | ||
| if (this._escapeCalled) | ||
| this._escapeCalled = false; | ||
| if (this.start === this.end) | ||
| return; | ||
| this.handleStore.erase(this.start, this.end); | ||
| } | ||
| escape(handle) { | ||
| if (this._escapeCalled) | ||
| return null; | ||
| this._escapeCalled = true; | ||
| if (handle < this.start || handle >= this.end) { | ||
| return null; | ||
| } | ||
| this.handleStore.swap(handle, this.start); | ||
| const h = this.handleStore.get(this.start); | ||
| this.start++; | ||
| this.parent.end++; | ||
| return h; | ||
| } | ||
| escapeCalled() { | ||
| return this._escapeCalled; | ||
| } | ||
| } | ||
| class ScopeStore { | ||
| constructor() { | ||
| this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID); | ||
| this.currentScope = this._rootScope; | ||
| this._values = [undefined]; | ||
| } | ||
| get(id) { | ||
| return this._values[id]; | ||
| } | ||
| openScope(handleStore) { | ||
| const currentScope = this.currentScope; | ||
| let scope = currentScope.child; | ||
| if (scope !== null) { | ||
| scope.start = scope.end = currentScope.end; | ||
| } | ||
| else { | ||
| const id = currentScope.id + 1; | ||
| scope = new HandleScope(handleStore, id, currentScope, currentScope.end); | ||
| this._values[id] = scope; | ||
| } | ||
| this.currentScope = scope; | ||
| return scope; | ||
| } | ||
| closeScope() { | ||
| const scope = this.currentScope; | ||
| this.currentScope = scope.parent; | ||
| scope.dispose(); | ||
| } | ||
| dispose() { | ||
| this.currentScope = this._rootScope; | ||
| this._values.length = 1; | ||
| } | ||
| } | ||
| class RefTracker { | ||
| constructor() { | ||
| this._next = null; | ||
| this._prev = null; | ||
| } | ||
| dispose() { } | ||
| finalize() { } | ||
| link(list) { | ||
| this._prev = list; | ||
| this._next = list._next; | ||
| if (this._next !== null) { | ||
| this._next._prev = this; | ||
| } | ||
| list._next = this; | ||
| } | ||
| unlink() { | ||
| if (this._prev !== null) { | ||
| this._prev._next = this._next; | ||
| } | ||
| if (this._next !== null) { | ||
| this._next._prev = this._prev; | ||
| } | ||
| this._prev = null; | ||
| this._next = null; | ||
| } | ||
| static finalizeAll(list) { | ||
| while (list._next !== null) { | ||
| list._next.finalize(); | ||
| } | ||
| } | ||
| } | ||
| class Finalizer { | ||
| constructor(envObject, _finalizeCallback = 0, _finalizeData = 0, _finalizeHint = 0) { | ||
| this.envObject = envObject; | ||
| this._finalizeCallback = _finalizeCallback; | ||
| this._finalizeData = _finalizeData; | ||
| this._finalizeHint = _finalizeHint; | ||
| this._makeDynCall_vppp = envObject.makeDynCall_vppp; | ||
| } | ||
| callback() { return this._finalizeCallback; } | ||
| data() { return this._finalizeData; } | ||
| hint() { return this._finalizeHint; } | ||
| resetEnv() { | ||
| this.envObject = undefined; | ||
| } | ||
| resetFinalizer() { | ||
| this._finalizeCallback = 0; | ||
| this._finalizeData = 0; | ||
| this._finalizeHint = 0; | ||
| } | ||
| callFinalizer() { | ||
| const finalize_callback = this._finalizeCallback; | ||
| const finalize_data = this._finalizeData; | ||
| const finalize_hint = this._finalizeHint; | ||
| this.resetFinalizer(); | ||
| if (!finalize_callback) | ||
| return; | ||
| const fini = Number(finalize_callback); | ||
| if (!this.envObject) { | ||
| this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint); | ||
| } | ||
| else { | ||
| this.envObject.callFinalizer(fini, finalize_data, finalize_hint); | ||
| } | ||
| } | ||
| dispose() { | ||
| this.envObject = undefined; | ||
| this._makeDynCall_vppp = undefined; | ||
| } | ||
| } | ||
| class TrackedFinalizer extends RefTracker { | ||
| static create(envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| const finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| finalizer.link(envObject.finalizing_reflist); | ||
| return finalizer; | ||
| } | ||
| constructor(envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| super(); | ||
| this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| } | ||
| data() { | ||
| return this._finalizer.data(); | ||
| } | ||
| dispose() { | ||
| if (!this._finalizer) | ||
| return; | ||
| this.unlink(); | ||
| this._finalizer.envObject.dequeueFinalizer(this); | ||
| this._finalizer.dispose(); | ||
| this._finalizer = undefined; | ||
| super.dispose(); | ||
| } | ||
| finalize() { | ||
| this.unlink(); | ||
| let error; | ||
| let caught = false; | ||
| try { | ||
| this._finalizer.callFinalizer(); | ||
| } | ||
| catch (err) { | ||
| caught = true; | ||
| error = err; | ||
| } | ||
| this.dispose(); | ||
| if (caught) { | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
| function throwNodeApiVersionError(moduleName, moduleApiVersion) { | ||
| const errorMessage = `${moduleName} requires Node-API version ${moduleApiVersion}, but this version of Node.js only supports version ${NODE_API_SUPPORTED_VERSION_MAX} add-ons.`; | ||
| throw new Error(errorMessage); | ||
| } | ||
| function handleThrow(envObject, value) { | ||
| if (envObject.terminatedOrTerminating()) { | ||
| return; | ||
| } | ||
| throw value; | ||
| } | ||
| class Env { | ||
| constructor(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) { | ||
| this.ctx = ctx; | ||
| this.moduleApiVersion = moduleApiVersion; | ||
| this.makeDynCall_vppp = makeDynCall_vppp; | ||
| this.makeDynCall_vp = makeDynCall_vp; | ||
| this.abort = abort; | ||
| this.openHandleScopes = 0; | ||
| this.instanceData = null; | ||
| this.tryCatch = new TryCatch(); | ||
| this.refs = 1; | ||
| this.reflist = new RefTracker(); | ||
| this.finalizing_reflist = new RefTracker(); | ||
| this.pendingFinalizers = []; | ||
| this.lastError = { | ||
| errorCode: 0, | ||
| engineErrorCode: 0, | ||
| engineReserved: 0 | ||
| }; | ||
| this.inGcFinalizer = false; | ||
| this._bindingMap = new WeakMap(); | ||
| this.id = 0; | ||
| } | ||
| canCallIntoJs() { | ||
| return true; | ||
| } | ||
| terminatedOrTerminating() { | ||
| return !this.canCallIntoJs(); | ||
| } | ||
| ref() { | ||
| this.refs++; | ||
| } | ||
| unref() { | ||
| this.refs--; | ||
| if (this.refs === 0) { | ||
| this.dispose(); | ||
| } | ||
| } | ||
| ensureHandle(value) { | ||
| return this.ctx.ensureHandle(value); | ||
| } | ||
| ensureHandleId(value) { | ||
| return this.ensureHandle(value).id; | ||
| } | ||
| clearLastError() { | ||
| const lastError = this.lastError; | ||
| if (lastError.errorCode !== 0) | ||
| lastError.errorCode = 0; | ||
| if (lastError.engineErrorCode !== 0) | ||
| lastError.engineErrorCode = 0; | ||
| if (lastError.engineReserved !== 0) | ||
| lastError.engineReserved = 0; | ||
| return 0; | ||
| } | ||
| setLastError(error_code, engine_error_code = 0, engine_reserved = 0) { | ||
| const lastError = this.lastError; | ||
| if (lastError.errorCode !== error_code) | ||
| lastError.errorCode = error_code; | ||
| if (lastError.engineErrorCode !== engine_error_code) | ||
| lastError.engineErrorCode = engine_error_code; | ||
| if (lastError.engineReserved !== engine_reserved) | ||
| lastError.engineReserved = engine_reserved; | ||
| return error_code; | ||
| } | ||
| getReturnStatus() { | ||
| return !this.tryCatch.hasCaught() ? 0 : this.setLastError(10); | ||
| } | ||
| callIntoModule(fn, handleException = handleThrow) { | ||
| const openHandleScopesBefore = this.openHandleScopes; | ||
| this.clearLastError(); | ||
| const r = fn(this); | ||
| if (openHandleScopesBefore !== this.openHandleScopes) { | ||
| this.abort('open_handle_scopes != open_handle_scopes_before'); | ||
| } | ||
| if (this.tryCatch.hasCaught()) { | ||
| const err = this.tryCatch.extractException(); | ||
| handleException(this, err); | ||
| } | ||
| return r; | ||
| } | ||
| invokeFinalizerFromGC(finalizer) { | ||
| if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) { | ||
| this.enqueueFinalizer(finalizer); | ||
| } | ||
| else { | ||
| const saved = this.inGcFinalizer; | ||
| this.inGcFinalizer = true; | ||
| try { | ||
| finalizer.finalize(); | ||
| } | ||
| finally { | ||
| this.inGcFinalizer = saved; | ||
| } | ||
| } | ||
| } | ||
| checkGCAccess() { | ||
| if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) { | ||
| this.abort('Finalizer is calling a function that may affect GC state.\n' + | ||
| 'The finalizers are run directly from GC and must not affect GC ' + | ||
| 'state.\n' + | ||
| 'Use `node_api_post_finalizer` from inside of the finalizer to work ' + | ||
| 'around this issue.\n' + | ||
| 'It schedules the call as a new task in the event loop.'); | ||
| } | ||
| } | ||
| enqueueFinalizer(finalizer) { | ||
| if (this.pendingFinalizers.indexOf(finalizer) === -1) { | ||
| this.pendingFinalizers.push(finalizer); | ||
| } | ||
| } | ||
| dequeueFinalizer(finalizer) { | ||
| const index = this.pendingFinalizers.indexOf(finalizer); | ||
| if (index !== -1) { | ||
| this.pendingFinalizers.splice(index, 1); | ||
| } | ||
| } | ||
| deleteMe() { | ||
| RefTracker.finalizeAll(this.finalizing_reflist); | ||
| RefTracker.finalizeAll(this.reflist); | ||
| this.tryCatch.extractException(); | ||
| this.ctx.envStore.remove(this.id); | ||
| } | ||
| dispose() { | ||
| if (this.id === 0) | ||
| return; | ||
| this.deleteMe(); | ||
| this.finalizing_reflist.dispose(); | ||
| this.reflist.dispose(); | ||
| this.id = 0; | ||
| } | ||
| initObjectBinding(value) { | ||
| const binding = { | ||
| wrapped: 0, | ||
| tag: null | ||
| }; | ||
| this._bindingMap.set(value, binding); | ||
| return binding; | ||
| } | ||
| getObjectBinding(value) { | ||
| if (this._bindingMap.has(value)) { | ||
| return this._bindingMap.get(value); | ||
| } | ||
| return this.initObjectBinding(value); | ||
| } | ||
| setInstanceData(data, finalize_cb, finalize_hint) { | ||
| if (this.instanceData) { | ||
| this.instanceData.dispose(); | ||
| } | ||
| this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint); | ||
| } | ||
| getInstanceData() { | ||
| return this.instanceData ? this.instanceData.data() : 0; | ||
| } | ||
| } | ||
| class NodeEnv extends Env { | ||
| constructor(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| super(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort); | ||
| this.filename = filename; | ||
| this.nodeBinding = nodeBinding; | ||
| this.destructing = false; | ||
| this.finalizationScheduled = false; | ||
| } | ||
| deleteMe() { | ||
| this.destructing = true; | ||
| this.drainFinalizerQueue(); | ||
| super.deleteMe(); | ||
| } | ||
| canCallIntoJs() { | ||
| return super.canCallIntoJs() && this.ctx.canCallIntoJs(); | ||
| } | ||
| triggerFatalException(err) { | ||
| if (this.nodeBinding) { | ||
| this.nodeBinding.napi.fatalException(err); | ||
| } | ||
| else { | ||
| if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') { | ||
| const handled = process._fatalException(err); | ||
| if (!handled) { | ||
| console.error(err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| else { | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
| callbackIntoModule(enforceUncaughtExceptionPolicy, fn) { | ||
| return this.callIntoModule(fn, (envObject, err) => { | ||
| if (envObject.terminatedOrTerminating()) { | ||
| return; | ||
| } | ||
| const hasProcess = typeof process === 'object' && process !== null; | ||
| const hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false; | ||
| if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) { | ||
| const warn = hasProcess && typeof process.emitWarning === 'function' | ||
| ? process.emitWarning | ||
| : function (warning, type, code) { | ||
| if (warning instanceof Error) { | ||
| console.warn(warning.toString()); | ||
| } | ||
| else { | ||
| const prefix = code ? `[${code}] ` : ''; | ||
| console.warn(`${prefix}${type || 'Warning'}: ${warning}`); | ||
| } | ||
| }; | ||
| warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168'); | ||
| return; | ||
| } | ||
| envObject.triggerFatalException(err); | ||
| }); | ||
| } | ||
| callFinalizer(cb, data, hint) { | ||
| this.callFinalizerInternal(1, cb, data, hint); | ||
| } | ||
| callFinalizerInternal(forceUncaught, cb, data, hint) { | ||
| const f = this.makeDynCall_vppp(cb); | ||
| const env = this.id; | ||
| const scope = this.ctx.openScope(this); | ||
| try { | ||
| this.callbackIntoModule(Boolean(forceUncaught), () => { f(env, data, hint); }); | ||
| } | ||
| finally { | ||
| this.ctx.closeScope(this, scope); | ||
| } | ||
| } | ||
| enqueueFinalizer(finalizer) { | ||
| super.enqueueFinalizer(finalizer); | ||
| if (!this.finalizationScheduled && !this.destructing) { | ||
| this.finalizationScheduled = true; | ||
| this.ref(); | ||
| _setImmediate(() => { | ||
| this.finalizationScheduled = false; | ||
| this.unref(); | ||
| this.drainFinalizerQueue(); | ||
| }); | ||
| } | ||
| } | ||
| drainFinalizerQueue() { | ||
| while (this.pendingFinalizers.length > 0) { | ||
| const refTracker = this.pendingFinalizers.shift(); | ||
| refTracker.finalize(); | ||
| } | ||
| } | ||
| } | ||
| function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion; | ||
| if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) { | ||
| moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION; | ||
| } | ||
| else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) { | ||
| throwNodeApiVersionError(filename, moduleApiVersion); | ||
| } | ||
| const env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding); | ||
| ctx.envStore.add(env); | ||
| ctx.addCleanupHook(env, () => { env.unref(); }, 0); | ||
| return env; | ||
| } | ||
| class EmnapiError extends Error { | ||
| constructor(message) { | ||
| super(message); | ||
| const ErrorConstructor = new.target; | ||
| const proto = ErrorConstructor.prototype; | ||
| if (!(this instanceof EmnapiError)) { | ||
| const setPrototypeOf = Object.setPrototypeOf; | ||
| if (typeof setPrototypeOf === 'function') { | ||
| setPrototypeOf.call(Object, this, proto); | ||
| } | ||
| else { | ||
| this.__proto__ = proto; | ||
| } | ||
| if (typeof Error.captureStackTrace === 'function') { | ||
| Error.captureStackTrace(this, ErrorConstructor); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Object.defineProperty(EmnapiError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'EmnapiError' | ||
| }); | ||
| class NotSupportWeakRefError extends EmnapiError { | ||
| constructor(api, message) { | ||
| super(`${api}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${message ? ` ${message}` : ''}`); | ||
| } | ||
| } | ||
| Object.defineProperty(NotSupportWeakRefError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'NotSupportWeakRefError' | ||
| }); | ||
| class NotSupportBufferError extends EmnapiError { | ||
| constructor(api, message) { | ||
| super(`${api}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${message ? ` ${message}` : ''}`); | ||
| } | ||
| } | ||
| Object.defineProperty(NotSupportBufferError.prototype, 'name', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: 'NotSupportBufferError' | ||
| }); | ||
| class StrongRef { | ||
| constructor(value) { | ||
| this._value = value; | ||
| } | ||
| deref() { | ||
| return this._value; | ||
| } | ||
| dispose() { | ||
| this._value = undefined; | ||
| } | ||
| } | ||
| class Persistent { | ||
| constructor(value) { | ||
| this._ref = new StrongRef(value); | ||
| } | ||
| setWeak(param, callback) { | ||
| if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef) | ||
| return; | ||
| const value = this._ref.deref(); | ||
| try { | ||
| Persistent._registry.register(value, this, this); | ||
| const weakRef = new WeakRef(value); | ||
| this._ref.dispose(); | ||
| this._ref = weakRef; | ||
| this._param = param; | ||
| this._callback = callback; | ||
| } | ||
| catch (err) { | ||
| if (typeof value === 'symbol') ; | ||
| else { | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
| clearWeak() { | ||
| if (!supportFinalizer || this._ref === undefined) | ||
| return; | ||
| if (this._ref instanceof WeakRef) { | ||
| try { | ||
| Persistent._registry.unregister(this); | ||
| } | ||
| catch (_) { } | ||
| this._param = undefined; | ||
| this._callback = undefined; | ||
| const value = this._ref.deref(); | ||
| if (value === undefined) { | ||
| this._ref = value; | ||
| } | ||
| else { | ||
| this._ref = new StrongRef(value); | ||
| } | ||
| } | ||
| } | ||
| reset() { | ||
| if (supportFinalizer) { | ||
| try { | ||
| Persistent._registry.unregister(this); | ||
| } | ||
| catch (_) { } | ||
| } | ||
| this._param = undefined; | ||
| this._callback = undefined; | ||
| if (this._ref instanceof StrongRef) { | ||
| this._ref.dispose(); | ||
| } | ||
| this._ref = undefined; | ||
| } | ||
| isEmpty() { | ||
| return this._ref === undefined; | ||
| } | ||
| deref() { | ||
| if (this._ref === undefined) | ||
| return undefined; | ||
| return this._ref.deref(); | ||
| } | ||
| } | ||
| Persistent._registry = supportFinalizer | ||
| ? new FinalizationRegistry((value) => { | ||
| value._ref = undefined; | ||
| const callback = value._callback; | ||
| const param = value._param; | ||
| value._callback = undefined; | ||
| value._param = undefined; | ||
| if (typeof callback === 'function') { | ||
| callback(param); | ||
| } | ||
| }) | ||
| : undefined; | ||
| var ReferenceOwnership; | ||
| (function (ReferenceOwnership) { | ||
| ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime"; | ||
| ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland"; | ||
| })(ReferenceOwnership || (ReferenceOwnership = {})); | ||
| function canBeHeldWeakly(value) { | ||
| return value.isObject() || value.isFunction() || value.isSymbol(); | ||
| } | ||
| class Reference extends RefTracker { | ||
| static weakCallback(ref) { | ||
| ref.persistent.reset(); | ||
| ref.invokeFinalizerFromGC(); | ||
| } | ||
| static create(envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) { | ||
| const ref = new Reference(envObject, handle_id, initialRefcount, ownership); | ||
| envObject.ctx.refStore.add(ref); | ||
| ref.link(envObject.reflist); | ||
| return ref; | ||
| } | ||
| constructor(envObject, handle_id, initialRefcount, ownership) { | ||
| super(); | ||
| this.envObject = envObject; | ||
| this._refcount = initialRefcount; | ||
| this._ownership = ownership; | ||
| const handle = envObject.ctx.handleStore.get(handle_id); | ||
| this.canBeWeak = canBeHeldWeakly(handle); | ||
| this.persistent = new Persistent(handle.value); | ||
| this.id = 0; | ||
| if (initialRefcount === 0) { | ||
| this._setWeak(); | ||
| } | ||
| } | ||
| ref() { | ||
| if (this.persistent.isEmpty()) { | ||
| return 0; | ||
| } | ||
| if (++this._refcount === 1 && this.canBeWeak) { | ||
| this.persistent.clearWeak(); | ||
| } | ||
| return this._refcount; | ||
| } | ||
| unref() { | ||
| if (this.persistent.isEmpty() || this._refcount === 0) { | ||
| return 0; | ||
| } | ||
| if (--this._refcount === 0) { | ||
| this._setWeak(); | ||
| } | ||
| return this._refcount; | ||
| } | ||
| get(envObject = this.envObject) { | ||
| if (this.persistent.isEmpty()) { | ||
| return 0; | ||
| } | ||
| const obj = this.persistent.deref(); | ||
| const handle = envObject.ensureHandle(obj); | ||
| return handle.id; | ||
| } | ||
| resetFinalizer() { } | ||
| data() { return 0; } | ||
| refcount() { return this._refcount; } | ||
| ownership() { return this._ownership; } | ||
| callUserFinalizer() { } | ||
| invokeFinalizerFromGC() { | ||
| this.finalize(); | ||
| } | ||
| _setWeak() { | ||
| if (this.canBeWeak) { | ||
| this.persistent.setWeak(this, Reference.weakCallback); | ||
| } | ||
| else { | ||
| this.persistent.reset(); | ||
| } | ||
| } | ||
| finalize() { | ||
| this.persistent.reset(); | ||
| const deleteMe = this._ownership === ReferenceOwnership.kRuntime; | ||
| this.unlink(); | ||
| this.callUserFinalizer(); | ||
| if (deleteMe) { | ||
| this.dispose(); | ||
| } | ||
| } | ||
| dispose() { | ||
| if (this.id === 0) | ||
| return; | ||
| this.unlink(); | ||
| this.persistent.reset(); | ||
| this.envObject.ctx.refStore.remove(this.id); | ||
| super.dispose(); | ||
| this.envObject = undefined; | ||
| this.id = 0; | ||
| } | ||
| } | ||
| class ReferenceWithData extends Reference { | ||
| static create(envObject, value, initialRefcount, ownership, data) { | ||
| const reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data); | ||
| envObject.ctx.refStore.add(reference); | ||
| reference.link(envObject.reflist); | ||
| return reference; | ||
| } | ||
| constructor(envObject, value, initialRefcount, ownership, _data) { | ||
| super(envObject, value, initialRefcount, ownership); | ||
| this._data = _data; | ||
| } | ||
| data() { | ||
| return this._data; | ||
| } | ||
| } | ||
| class ReferenceWithFinalizer extends Reference { | ||
| static create(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| const reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint); | ||
| envObject.ctx.refStore.add(reference); | ||
| reference.link(envObject.finalizing_reflist); | ||
| return reference; | ||
| } | ||
| constructor(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) { | ||
| super(envObject, value, initialRefcount, ownership); | ||
| this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| } | ||
| resetFinalizer() { | ||
| this._finalizer.resetFinalizer(); | ||
| } | ||
| data() { | ||
| return this._finalizer.data(); | ||
| } | ||
| callUserFinalizer() { | ||
| this._finalizer.callFinalizer(); | ||
| } | ||
| invokeFinalizerFromGC() { | ||
| this._finalizer.envObject.invokeFinalizerFromGC(this); | ||
| } | ||
| dispose() { | ||
| if (!this._finalizer) | ||
| return; | ||
| this._finalizer.envObject.dequeueFinalizer(this); | ||
| this._finalizer.dispose(); | ||
| super.dispose(); | ||
| this._finalizer = undefined; | ||
| } | ||
| } | ||
| class Deferred { | ||
| static create(ctx, value) { | ||
| const deferred = new Deferred(ctx, value); | ||
| ctx.deferredStore.add(deferred); | ||
| return deferred; | ||
| } | ||
| constructor(ctx, value) { | ||
| this.id = 0; | ||
| this.ctx = ctx; | ||
| this.value = value; | ||
| } | ||
| resolve(value) { | ||
| this.value.resolve(value); | ||
| this.dispose(); | ||
| } | ||
| reject(reason) { | ||
| this.value.reject(reason); | ||
| this.dispose(); | ||
| } | ||
| dispose() { | ||
| this.ctx.deferredStore.remove(this.id); | ||
| this.id = 0; | ||
| this.value = null; | ||
| this.ctx = null; | ||
| } | ||
| } | ||
| class Store { | ||
| constructor() { | ||
| this._values = [undefined]; | ||
| this._values.length = 4; | ||
| this._size = 1; | ||
| this._freeList = []; | ||
| } | ||
| add(value) { | ||
| let id; | ||
| if (this._freeList.length) { | ||
| id = this._freeList.shift(); | ||
| } | ||
| else { | ||
| id = this._size; | ||
| this._size++; | ||
| const capacity = this._values.length; | ||
| if (id >= capacity) { | ||
| this._values.length = capacity + (capacity >> 1) + 16; | ||
| } | ||
| } | ||
| value.id = id; | ||
| this._values[id] = value; | ||
| } | ||
| get(id) { | ||
| return this._values[id]; | ||
| } | ||
| has(id) { | ||
| return this._values[id] !== undefined; | ||
| } | ||
| remove(id) { | ||
| const value = this._values[id]; | ||
| if (value) { | ||
| value.id = 0; | ||
| this._values[id] = undefined; | ||
| this._freeList.push(Number(id)); | ||
| } | ||
| } | ||
| dispose() { | ||
| for (let i = 1; i < this._size; ++i) { | ||
| const value = this._values[i]; | ||
| value === null || value === void 0 ? void 0 : value.dispose(); | ||
| } | ||
| this._values = [undefined]; | ||
| this._size = 1; | ||
| this._freeList = []; | ||
| } | ||
| } | ||
| const kMaxReasonableBytes = BigInt(1) << BigInt(60); | ||
| const kMinReasonableBytes = -kMaxReasonableBytes; | ||
| class ExternalMemory { | ||
| constructor(onChange) { | ||
| this.total = BigInt(0); | ||
| this.onChange = onChange !== null && onChange !== void 0 ? onChange : null; | ||
| } | ||
| adjust(changeInBytes) { | ||
| changeInBytes = BigInt(changeInBytes); | ||
| if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) { | ||
| throw new RangeError(`changeInBytes ${changeInBytes} is out of reasonable range`); | ||
| } | ||
| const old = this.total; | ||
| this.total += changeInBytes; | ||
| const amount = this.total; | ||
| const onChange = this.onChange; | ||
| if (changeInBytes) { | ||
| onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes); | ||
| } | ||
| return amount; | ||
| } | ||
| } | ||
| class CleanupHookCallback { | ||
| constructor(envObject, fn, arg, order) { | ||
| this.envObject = envObject; | ||
| this.fn = fn; | ||
| this.arg = arg; | ||
| this.order = order; | ||
| } | ||
| } | ||
| class CleanupQueue { | ||
| constructor() { | ||
| this._cleanupHooks = []; | ||
| this._cleanupHookCounter = 0; | ||
| } | ||
| empty() { | ||
| return this._cleanupHooks.length === 0; | ||
| } | ||
| add(envObject, fn, arg) { | ||
| if (this._cleanupHooks.filter((hook) => (hook.envObject === envObject && hook.fn === fn && hook.arg === arg)).length > 0) { | ||
| throw new Error('Can not add same fn and arg twice'); | ||
| } | ||
| this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++)); | ||
| } | ||
| remove(envObject, fn, arg) { | ||
| for (let i = 0; i < this._cleanupHooks.length; ++i) { | ||
| const hook = this._cleanupHooks[i]; | ||
| if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) { | ||
| this._cleanupHooks.splice(i, 1); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| drain() { | ||
| const hooks = this._cleanupHooks.slice(); | ||
| hooks.sort((a, b) => (b.order - a.order)); | ||
| for (let i = 0; i < hooks.length; ++i) { | ||
| const cb = hooks[i]; | ||
| if (typeof cb.fn === 'number') { | ||
| cb.envObject.makeDynCall_vp(cb.fn)(cb.arg); | ||
| } | ||
| else { | ||
| cb.fn(cb.arg); | ||
| } | ||
| this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1); | ||
| } | ||
| } | ||
| dispose() { | ||
| this._cleanupHooks.length = 0; | ||
| this._cleanupHookCounter = 0; | ||
| } | ||
| } | ||
| class NodejsWaitingRequestCounter { | ||
| constructor() { | ||
| this.refHandle = new _MessageChannel().port1; | ||
| this.count = 0; | ||
| } | ||
| increase() { | ||
| if (this.count === 0) { | ||
| if (this.refHandle.ref) { | ||
| this.refHandle.ref(); | ||
| } | ||
| } | ||
| this.count++; | ||
| } | ||
| decrease() { | ||
| if (this.count === 0) | ||
| return; | ||
| if (this.count === 1) { | ||
| if (this.refHandle.unref) { | ||
| this.refHandle.unref(); | ||
| } | ||
| } | ||
| this.count--; | ||
| } | ||
| } | ||
| class Context { | ||
| constructor(options) { | ||
| this._isStopping = false; | ||
| this._canCallIntoJs = true; | ||
| this._suppressDestroy = false; | ||
| this.envStore = new Store(); | ||
| this.scopeStore = new ScopeStore(); | ||
| this.refStore = new Store(); | ||
| this.deferredStore = new Store(); | ||
| this.handleStore = new HandleStore(); | ||
| this.feature = { | ||
| supportReflect, | ||
| supportFinalizer, | ||
| supportWeakSymbol, | ||
| supportBigInt, | ||
| supportNewFunction, | ||
| canSetFunctionName, | ||
| setImmediate: _setImmediate, | ||
| Buffer: _Buffer, | ||
| MessageChannel: _MessageChannel | ||
| }; | ||
| this.cleanupQueue = new CleanupQueue(); | ||
| this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange); | ||
| if (typeof process === 'object' && process !== null && typeof process.once === 'function') { | ||
| this.refCounter = new NodejsWaitingRequestCounter(); | ||
| process.once('beforeExit', () => { | ||
| if (!this._suppressDestroy) { | ||
| this.destroy(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| suppressDestroy() { | ||
| this._suppressDestroy = true; | ||
| } | ||
| getRuntimeVersions() { | ||
| return { | ||
| version, | ||
| NODE_API_SUPPORTED_VERSION_MAX, | ||
| NAPI_VERSION_EXPERIMENTAL, | ||
| NODE_API_DEFAULT_MODULE_API_VERSION | ||
| }; | ||
| } | ||
| createNotSupportWeakRefError(api, message) { | ||
| return new NotSupportWeakRefError(api, message); | ||
| } | ||
| createNotSupportBufferError(api, message) { | ||
| return new NotSupportBufferError(api, message); | ||
| } | ||
| createReference(envObject, handle_id, initialRefcount, ownership) { | ||
| return Reference.create(envObject, handle_id, initialRefcount, ownership); | ||
| } | ||
| createReferenceWithData(envObject, handle_id, initialRefcount, ownership, data) { | ||
| return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data); | ||
| } | ||
| createReferenceWithFinalizer(envObject, handle_id, initialRefcount, ownership, finalize_callback = 0, finalize_data = 0, finalize_hint = 0) { | ||
| return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint); | ||
| } | ||
| createDeferred(value) { | ||
| return Deferred.create(this, value); | ||
| } | ||
| adjustAmountOfExternalAllocatedMemory(changeInBytes) { | ||
| return this._externalMemory.adjust(changeInBytes); | ||
| } | ||
| createEnv(filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) { | ||
| return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding); | ||
| } | ||
| createTrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) { | ||
| return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint); | ||
| } | ||
| getCurrentScope() { | ||
| return this.scopeStore.currentScope; | ||
| } | ||
| addToCurrentScope(value) { | ||
| return this.scopeStore.currentScope.add(value); | ||
| } | ||
| openScope(envObject) { | ||
| const scope = this.scopeStore.openScope(this.handleStore); | ||
| if (envObject) | ||
| envObject.openHandleScopes++; | ||
| return scope; | ||
| } | ||
| closeScope(envObject, _scope) { | ||
| if (envObject && envObject.openHandleScopes === 0) | ||
| return; | ||
| this.scopeStore.closeScope(); | ||
| if (envObject) | ||
| envObject.openHandleScopes--; | ||
| } | ||
| ensureHandle(value) { | ||
| switch (value) { | ||
| case undefined: return HandleStore.UNDEFINED; | ||
| case null: return HandleStore.NULL; | ||
| case true: return HandleStore.TRUE; | ||
| case false: return HandleStore.FALSE; | ||
| case _global: return HandleStore.GLOBAL; | ||
| } | ||
| return this.addToCurrentScope(value); | ||
| } | ||
| addCleanupHook(envObject, fn, arg) { | ||
| this.cleanupQueue.add(envObject, fn, arg); | ||
| } | ||
| removeCleanupHook(envObject, fn, arg) { | ||
| this.cleanupQueue.remove(envObject, fn, arg); | ||
| } | ||
| runCleanup() { | ||
| while (!this.cleanupQueue.empty()) { | ||
| this.cleanupQueue.drain(); | ||
| } | ||
| } | ||
| increaseWaitingRequestCounter() { | ||
| var _a; | ||
| (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase(); | ||
| } | ||
| decreaseWaitingRequestCounter() { | ||
| var _a; | ||
| (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease(); | ||
| } | ||
| setCanCallIntoJs(value) { | ||
| this._canCallIntoJs = value; | ||
| } | ||
| setStopping(value) { | ||
| this._isStopping = value; | ||
| } | ||
| canCallIntoJs() { | ||
| return this._canCallIntoJs && !this._isStopping; | ||
| } | ||
| destroy() { | ||
| this.setStopping(true); | ||
| this.setCanCallIntoJs(false); | ||
| this.runCleanup(); | ||
| } | ||
| } | ||
| let defaultContext; | ||
| function createContext(options) { | ||
| return new Context(options); | ||
| } | ||
| function getDefaultContext() { | ||
| if (!defaultContext) { | ||
| defaultContext = createContext(); | ||
| } | ||
| return defaultContext; | ||
| } | ||
| export { ConstHandle, Context, Deferred, EmnapiError, Env, External, Finalizer, Handle, HandleScope, HandleStore, NAPI_VERSION_EXPERIMENTAL, NODE_API_DEFAULT_MODULE_API_VERSION, NODE_API_SUPPORTED_VERSION_MAX, NODE_API_SUPPORTED_VERSION_MIN, NodeEnv, NotSupportBufferError, NotSupportWeakRefError, Persistent, RefTracker, Reference, ReferenceOwnership, ReferenceWithData, ReferenceWithFinalizer, ScopeStore, Store, TrackedFinalizer, TryCatch, createContext, getDefaultContext, getExternalValue, isExternal, isReferenceType, version }; |
-5
| if (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') { | ||
| module.exports = require('./dist/emnapi.cjs.min.js') | ||
| } else { | ||
| module.exports = require('./dist/emnapi.cjs.js') | ||
| } |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
-66.67%4
-69.23%Yes
NaN254728
-41.24%7
-58.82%2941
-67.13%