@emnapi/runtime 1.11.0 → 2.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/emnapi.d.ts CHANGED
@@ -1,6 +1,11 @@
1
+ /// <reference lib="esnext.disposable" />
2
+
1
3
  export declare type Ptr = number | bigint
2
4
 
3
- export declare interface IBuffer extends Uint8Array {}
5
+ export declare interface IBuffer extends Uint8Array {
6
+ toString (encoding?: string, start?: number, end?: number): string
7
+ }
8
+
4
9
  export declare interface BufferCtor {
5
10
  readonly prototype: IBuffer
6
11
  /** @deprecated */
@@ -13,22 +18,26 @@ export declare interface BufferCtor {
13
18
  isBuffer: (obj: unknown) => obj is IBuffer
14
19
  }
15
20
 
16
- export declare const enum GlobalHandle {
17
- UNDEFINED = 1,
21
+ export declare const enum Constant {
22
+ HOLE,
23
+ EMPTY,
24
+ UNDEFINED,
18
25
  NULL,
19
26
  FALSE,
20
27
  TRUE,
21
- GLOBAL
28
+ GLOBAL,
29
+ EMPTY_STRING,
22
30
  }
23
31
 
24
32
  export declare const enum Version {
25
33
  NODE_API_SUPPORTED_VERSION_MIN = 1,
26
34
  NODE_API_DEFAULT_MODULE_API_VERSION = 8,
27
35
  NODE_API_SUPPORTED_VERSION_MAX = 10,
36
+ NODE_MODULE_VERSION = 127,
28
37
  NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
29
38
  }
30
39
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
- export declare type Pointer<T> = number
40
+ export declare type Pointer<T> = number | bigint
32
41
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
42
  export declare type PointerPointer<T> = number
34
43
  export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T>
@@ -42,8 +51,10 @@ export declare type char_p = Pointer<char>
42
51
  export declare type unsigned_char = number
43
52
  export declare type const_char = Const<char>
44
53
  export declare type const_char_p = Pointer<const_char>
45
- export declare type char16_t_p = number
46
- export declare type const_char16_t_p = number
54
+ export declare type char16_t = number
55
+ export declare type const_char16_t = number
56
+ export declare type char16_t_p = Pointer<char16_t>
57
+ export declare type const_char16_t_p = Pointer<const_char16_t>
47
58
 
48
59
  export declare type short = number
49
60
  export declare type unsigned_short = number
@@ -248,69 +259,70 @@ export declare const enum napi_threadsafe_function_release_mode {
248
259
  napi_tsfn_release,
249
260
  napi_tsfn_abort
250
261
  }
251
- export declare type CleanupHookCallbackFunction = number | ((arg: number) => void);
262
+ export declare class ArrayStore<T extends {
263
+ id: number | bigint;
264
+ }> extends BaseArrayStore<T> {
265
+ protected _allocator: IdAllocator;
266
+ constructor(initialCapacity?: number);
267
+ insert(value: T): void;
268
+ alloc<P extends any[]>(factory: (...args: P) => T, ...args: P): T;
269
+ dealloc(id: number | bigint): void;
270
+ }
252
271
 
253
- export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> {
254
- constructor(id: number, value: S);
272
+ export declare class BaseArrayStore<T> extends Disposable_2 implements ObjectAllocator<T> {
273
+ protected _values: [undefined, ...(T | undefined)[]];
274
+ constructor(initialCapacity?: number);
275
+ assign(id: number | bigint, value: T): T;
276
+ deref<R extends T = T>(id: number | bigint): R | undefined;
277
+ alloc<P extends any[]>(factory: (...args: P) => T, ...args: P): T;
278
+ dealloc(id: number | bigint): void;
255
279
  dispose(): void;
256
280
  }
257
281
 
282
+ export declare type CleanupHookCallbackFunction = number | ((arg: number) => void);
283
+
258
284
  export declare class Context {
259
285
  private _isStopping;
260
286
  private _canCallIntoJs;
261
287
  private _suppressDestroy;
262
- envStore: Store<Env>;
263
- scopeStore: ScopeStore;
264
- refStore: Store<Reference>;
265
- deferredStore: Store<Deferred<any>>;
266
- handleStore: HandleStore;
288
+ private envStore;
289
+ refStore: Map<number, Reference>;
267
290
  private readonly refCounter?;
268
291
  private readonly cleanupQueue;
269
- private readonly _externalMemory;
270
- feature: {
271
- supportReflect: boolean;
272
- supportFinalizer: boolean;
273
- supportWeakSymbol: boolean;
274
- supportBigInt: boolean;
275
- supportNewFunction: boolean;
276
- canSetFunctionName: boolean;
277
- setImmediate: (callback: () => void) => void;
278
- Buffer: BufferCtor | undefined;
279
- MessageChannel: {
280
- new (): MessageChannel;
281
- prototype: MessageChannel;
282
- } | undefined;
283
- };
292
+ readonly features: Features;
293
+ readonly isolate: Isolate;
284
294
  constructor(options?: ContextOptions);
285
- /**
286
- * Suppress the destroy on `beforeExit` event in Node.js.
287
- * Call this method if you want to keep the context and
288
- * all associated {@link Env | Env} alive,
289
- * this also means that cleanup hooks will not be called.
290
- * After call this method, you should call
291
- * {@link Context.destroy | `Context.prototype.destroy`} method manually.
292
- */
295
+ getIsolate(): Isolate;
293
296
  suppressDestroy(): void;
294
297
  getRuntimeVersions(): {
295
298
  version: string;
296
299
  NODE_API_SUPPORTED_VERSION_MAX: Version;
297
300
  NAPI_VERSION_EXPERIMENTAL: Version;
298
301
  NODE_API_DEFAULT_MODULE_API_VERSION: Version;
302
+ NODE_MODULE_VERSION: Version;
299
303
  };
300
304
  createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
301
305
  createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
302
306
  createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference;
303
307
  createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
304
308
  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;
305
- createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
309
+ createResolver<T>(): Resolver<T>;
306
310
  adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
307
- 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;
311
+ createEnv(filename: string, moduleApiVersion: number, bridge: EnvNativeBridge, nodeBinding?: any): Env;
312
+ createFunction(envObject: Env, napiCallback: (env: napi_env, info: napi_callback_info) => void_p, data: number | bigint, name: string, dynamicExecution: boolean): Function;
308
313
  createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
309
- getCurrentScope(): HandleScope | null;
310
- addToCurrentScope<V>(value: V): Handle<V>;
311
- openScope(envObject?: Env): HandleScope;
312
- closeScope(envObject?: Env, _scope?: HandleScope): void;
313
- ensureHandle<S>(value: S): Handle<S>;
314
+ getCurrentScope(): HandleScope;
315
+ openScope(envObject: Env): HandleScope;
316
+ closeScope(envObject: Env, scope?: HandleScope): void;
317
+ getEnv(env: napi_env): Env | undefined;
318
+ getRef(ref: napi_ref): Reference | undefined;
319
+ getHandleScope(scope: napi_handle_scope): HandleScope | undefined;
320
+ getCallbackInfo(info: napi_callback_info): ICallbackInfo;
321
+ napiValueFromJsValue(value: unknown): number | bigint;
322
+ jsValueFromNapiValue<T = any>(napiValue: number | bigint): T | undefined;
323
+ createExternal(data: number | bigint): External_2;
324
+ getExternalValue(external: External_2): number | bigint;
325
+ isExternal(value: unknown): boolean;
314
326
  addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
315
327
  removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
316
328
  runCleanup(): void;
@@ -319,95 +331,124 @@ export declare class Context {
319
331
  setCanCallIntoJs(value: boolean): void;
320
332
  setStopping(value: boolean): void;
321
333
  canCallIntoJs(): boolean;
322
- /**
323
- * Destroy the context and call cleanup hooks.
324
- * Associated {@link Env | Env} will be destroyed.
325
- */
334
+ getDylinkMetadata(binary: WebAssembly.Module | Uint8Array): DylinkMetadata;
326
335
  destroy(): void;
327
336
  }
328
337
 
329
- export declare interface ContextOptions {
330
- onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
338
+ export declare interface ContextOptions extends IsolateOptions {
331
339
  }
332
340
 
333
- export declare function createContext(options?: ContextOptions): Context;
341
+ export declare class CountIdAllocator extends Disposable_2 implements IdAllocator {
342
+ next: number;
343
+ constructor(initialNext?: number);
344
+ aquire(): number;
345
+ release(_: number): void;
346
+ dispose(): void;
347
+ }
334
348
 
335
- export declare class Deferred<T = any> implements IStoreValue {
336
- static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
337
- id: number;
338
- ctx: Context;
339
- value: IDeferrdValue<T>;
340
- constructor(ctx: Context, value: IDeferrdValue<T>);
341
- resolve(value: T): void;
342
- reject(reason?: any): void;
349
+ export declare class CountIdReuseAllocator extends CountIdAllocator implements IdAllocator {
350
+ private _freeList;
351
+ aquire(): number;
352
+ release(id: number): void;
343
353
  dispose(): void;
344
354
  }
345
355
 
356
+ export declare function createContext(options?: ContextOptions): Context;
357
+
358
+ export declare function deletePrivate(obj: any, key: Private): boolean;
359
+
360
+ declare abstract class Disposable_2 implements globalThis.Disposable {
361
+ abstract dispose(): void;
362
+ [Symbol.dispose](): void;
363
+ }
364
+ export { Disposable_2 as Disposable }
365
+
366
+ export declare interface DylinkMetadata {
367
+ neededDynlibs: string[];
368
+ tlsExports: Set<string>;
369
+ weakImports: Set<string>;
370
+ runtimePaths: string[];
371
+ memorySize: number;
372
+ memoryAlign: number;
373
+ tableSize: number;
374
+ tableAlign: number;
375
+ }
376
+
346
377
  export declare class EmnapiError extends Error {
347
378
  constructor(message?: string);
348
379
  }
349
380
 
350
- export declare abstract class Env implements IStoreValue {
351
- readonly ctx: Context;
352
- moduleApiVersion: number;
353
- makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
354
- makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
355
- abort: (msg?: string) => never;
356
- id: number;
381
+ export declare abstract class Env extends Disposable_2 {
382
+ id: number | bigint;
357
383
  openHandleScopes: number;
358
384
  instanceData: TrackedFinalizer | null;
359
- tryCatch: TryCatch;
385
+ lastException: Persistent<any>;
360
386
  refs: number;
361
387
  reflist: RefTracker;
362
388
  finalizing_reflist: RefTracker;
363
389
  pendingFinalizers: RefTracker[];
364
- lastError: {
365
- errorCode: napi_status;
366
- engineErrorCode: number;
367
- engineReserved: Ptr;
368
- };
390
+ moduleApiVersion: number;
391
+ filename: string;
392
+ nodeBinding?: any;
369
393
  inGcFinalizer: boolean;
370
- 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);
371
- /** @virtual */
394
+ bridge: EnvNativeBridge;
395
+ readonly ctx: Context;
396
+ private store;
397
+ constructor(ctx: Context, store: ArrayStore<Env>, bridge: EnvNativeBridge);
372
398
  canCallIntoJs(): boolean;
373
399
  terminatedOrTerminating(): boolean;
374
400
  ref(): void;
375
401
  unref(): void;
376
- ensureHandle<S>(value: S): Handle<S>;
377
- ensureHandleId(value: any): napi_value;
378
402
  clearLastError(): napi_status;
379
- setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
380
- getReturnStatus(): napi_status;
403
+ setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: number): napi_status;
381
404
  callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
382
- /** @virtual */
383
405
  abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
384
406
  invokeFinalizerFromGC(finalizer: RefTracker): void;
385
407
  checkGCAccess(): void;
386
- /** @virtual */
387
408
  enqueueFinalizer(finalizer: RefTracker): void;
388
- /** @virtual */
389
409
  dequeueFinalizer(finalizer: RefTracker): void;
390
- /** @virtual */
391
410
  deleteMe(): void;
392
411
  dispose(): void;
393
412
  private readonly _bindingMap;
394
413
  initObjectBinding<S extends object>(value: S): IReferenceBinding;
395
414
  getObjectBinding<S extends object>(value: S): IReferenceBinding;
396
415
  setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void;
397
- getInstanceData(): number;
416
+ getInstanceData(): number | bigint;
417
+ }
418
+
419
+ export declare interface EnvNativeBridge {
420
+ address: number;
421
+ deleteEnv: (ptr: number) => void;
422
+ setLastError: (env: napi_env, error_code: napi_status, engine_error_code: uint32_t, engine_reserved: number) => void;
423
+ makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
424
+ makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
425
+ abort: (msg?: string) => never;
426
+ wasm64?: boolean;
398
427
  }
399
428
 
400
- /** @public */
401
429
  declare interface External_2 extends Record<any, any> {
402
430
  }
403
431
 
404
- /** @public */
405
432
  declare const External_2: {
406
433
  new (value: number | bigint): External_2;
407
434
  prototype: null;
408
435
  };
409
436
  export { External_2 as External }
410
437
 
438
+ export declare interface Features {
439
+ makeDynamicFunction: ((...args: any[]) => Function) | undefined;
440
+ getGlobalThis: () => typeof globalThis;
441
+ setFunctionName: ((fn: Function, name: string) => void) | undefined;
442
+ Reflect: typeof Reflect | undefined;
443
+ finalizer: boolean;
444
+ weakSymbol: boolean;
445
+ BigInt: typeof BigInt | undefined;
446
+ MessageChannel: typeof MessageChannel | undefined;
447
+ Buffer: BufferCtor | undefined;
448
+ setImmediate: (callback: () => void) => any;
449
+ withResolvers: <T>(this: PromiseConstructor) => Resolver<T>;
450
+ }
451
+
411
452
  export declare class Finalizer {
412
453
  envObject: Env;
413
454
  private _finalizeCallback;
@@ -415,6 +456,8 @@ export declare class Finalizer {
415
456
  private _finalizeHint;
416
457
  private _makeDynCall_vppp;
417
458
  constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
459
+ copy(): Finalizer;
460
+ move(target: Finalizer): void;
418
461
  callback(): napi_finalize;
419
462
  data(): void_p;
420
463
  hint(): void_p;
@@ -424,79 +467,79 @@ export declare class Finalizer {
424
467
  dispose(): void;
425
468
  }
426
469
 
470
+ export declare class FunctionTemplate extends Template {
471
+ callback: (info: napi_callback_info, v8FunctionCallback: Ptr) => Ptr;
472
+ v8FunctionCallback: Ptr;
473
+ data: any;
474
+ className: string | undefined;
475
+ signature: Signature | undefined;
476
+ private _instanceTemplate;
477
+ private _prototypeTemplate;
478
+ private _cached;
479
+ constructor(ctx: Isolate, callback: (info: napi_callback_info, v8FunctionCallback: Ptr) => Ptr, v8FunctionCallback: Ptr, data: any, signature?: Signature);
480
+ setClassName(name: string): void;
481
+ instanceTemplate(): ObjectTemplate;
482
+ prototypeTemplate(): ObjectTemplate;
483
+ getFunction(): (...args: any[]) => any;
484
+ }
485
+
427
486
  export declare function getDefaultContext(): Context;
428
487
 
429
- /** @public */
488
+ export declare function getDylinkMetadata(binary: WebAssembly.Module | Uint8Array): DylinkMetadata;
489
+
430
490
  export declare function getExternalValue(external: External_2): number | bigint;
431
491
 
432
- export declare class Handle<S> {
433
- id: number;
434
- value: S;
435
- constructor(id: number, value: S);
436
- data(): void_p;
437
- isNumber(): boolean;
438
- isBigInt(): boolean;
439
- isString(): boolean;
440
- isFunction(): boolean;
441
- isExternal(): boolean;
442
- isObject(): boolean;
443
- isArray(): boolean;
444
- isArrayBuffer(): boolean;
445
- isTypedArray(): boolean;
446
- isBuffer(BufferConstructor?: BufferCtor): boolean;
447
- isDataView(): boolean;
448
- isDate(): boolean;
449
- isPromise(): boolean;
450
- isBoolean(): boolean;
451
- isUndefined(): boolean;
452
- isSymbol(): boolean;
453
- isNull(): boolean;
454
- dispose(): void;
455
- }
492
+ export declare function getInternalField(instance: object, index: number): any;
456
493
 
457
- export declare class HandleScope {
494
+ export declare function getPrivate(obj: any, key: Private): any;
495
+
496
+ export declare class HandleScope extends Disposable_2 {
458
497
  handleStore: HandleStore;
459
- id: number;
498
+ id: number | bigint;
460
499
  parent: HandleScope | null;
461
500
  child: HandleScope | null;
462
501
  start: number;
463
502
  end: number;
464
503
  private _escapeCalled;
465
504
  callbackInfo: ICallbackInfo;
466
- constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number);
467
- add<V>(value: V): Handle<V>;
468
- addExternal(data: void_p): Handle<object>;
505
+ static create(parentScope: HandleScope | null, handleStore: HandleStore, start?: number, end?: number): HandleScope;
506
+ constructor(parentScope: HandleScope | null, handleStore: HandleStore, start?: number, end?: number);
507
+ reuse(parentScope: HandleScope): void;
508
+ add<V>(value: V): number;
509
+ addExternal(data: number | bigint): number;
469
510
  dispose(): void;
470
- escape(handle: number): Handle<any> | null;
511
+ escape(handle: number): number;
471
512
  escapeCalled(): boolean;
472
513
  }
473
514
 
474
- export declare class HandleStore {
475
- static UNDEFINED: ConstHandle<undefined>;
476
- static NULL: ConstHandle<null>;
477
- static FALSE: ConstHandle<false>;
478
- static TRUE: ConstHandle<true>;
479
- static GLOBAL: ConstHandle<typeof globalThis>;
480
- static MIN_ID: 6;
481
- private readonly _values;
482
- private _next;
483
- push<S>(value: S): Handle<S>;
484
- erase(start: number, end: number): void;
485
- get(id: Ptr): Handle<any> | undefined;
515
+ export declare class HandleStore extends BaseArrayStore<any> {
516
+ static MIN_ID: 8;
517
+ private _allocator;
518
+ private _features;
519
+ readonly refValues: Map<number, PersistentValueType<any>>;
520
+ private _erase;
521
+ private _deref;
522
+ constructor(features: Features);
523
+ isOutOfScope(id: number): boolean;
524
+ deepDeref<R = any>(id: number | bigint): R | undefined;
525
+ push<S>(value: S): number;
526
+ erase(start: number, end: number, weak: boolean): void;
486
527
  swap(a: number, b: number): void;
487
- dispose(): void;
488
528
  }
489
529
 
530
+ export declare function hasPrivate(obj: any, key: Private): boolean;
531
+
490
532
  export declare interface ICallbackInfo {
491
533
  thiz: any;
534
+ holder: any;
492
535
  data: void_p;
493
536
  args: ArrayLike<any>;
494
537
  fn: Function;
495
538
  }
496
539
 
497
- export declare interface IDeferrdValue<T = any> {
498
- resolve: (value: T) => void;
499
- reject: (reason?: any) => void;
540
+ export declare interface IdAllocator extends Disposable_2 {
541
+ aquire(): number;
542
+ release(id: number): void;
500
543
  }
501
544
 
502
545
  export declare interface IReferenceBinding {
@@ -504,17 +547,65 @@ export declare interface IReferenceBinding {
504
547
  tag: Uint32Array | null;
505
548
  }
506
549
 
507
- /** @public */
508
550
  export declare function isExternal(object: unknown): object is External_2;
509
551
 
510
- export declare function isReferenceType(v: any): v is object;
552
+ export declare class Isolate {
553
+ private _lastException;
554
+ private _globalThis;
555
+ private _scopeStore;
556
+ private _handleStore;
557
+ private _externalMemory;
558
+ globalHandleStore: PersistentStore;
559
+ readonly features: Features;
560
+ constructor(options?: IsolateOptions);
561
+ napiValueFromJsValue(value: unknown): number | bigint;
562
+ jsValueFromNapiValue<T = any>(napiValue: number | bigint): T | undefined;
563
+ deleteRefSlotValue(id: number | bigint): void;
564
+ getRefSlotValue(id: number | bigint): PersistentValueType<any>;
565
+ setRefSlotValue(id: number | bigint, ref: PersistentValueType<any>): void;
566
+ createReference<T>(...args: [T] | []): Persistent<T>;
567
+ insertRef<T>(persistent: Persistent<T>): void;
568
+ getRef<T = any>(ref: napi_ref): Persistent<T> | undefined;
569
+ removeRef(ref: napi_ref, force?: boolean): void;
570
+ getTryCatch(address: number | bigint): TryCatch | undefined;
571
+ pushTryCatch(address: number | bigint): TryCatch;
572
+ popTryCatch(address: number | bigint): void;
573
+ setLastException(err: any): void;
574
+ throwException(err: any): any;
575
+ hasPendingException(): boolean;
576
+ getAndClearLastException(): any;
577
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
578
+ createSignature(template: FunctionTemplate): Signature;
579
+ createObjectTemplate(constructor: any): ObjectTemplate;
580
+ setInternalField(obj: any, index: number, value: any): void;
581
+ getInternalField(obj: any, index: number): any;
582
+ getInternalFieldCount(obj: any): number;
583
+ createFunctionTemplate(callback: (info: napi_callback_info, v8FunctionCallback: Ptr) => Ptr, v8FunctionCallback: Ptr, data: any, signature?: Signature): FunctionTemplate;
584
+ isScopeEmpty(): boolean;
585
+ getCurrentScope(): HandleScope;
586
+ openScope(): HandleScope;
587
+ closeScope(_scope?: HandleScope): void;
588
+ getHandleScope(scope: napi_handle_scope): HandleScope | undefined;
589
+ getCallbackInfo(info: napi_callback_info): ICallbackInfo;
590
+ createExternal(data: number | bigint): External_2;
591
+ getExternalValue(external: External_2): number | bigint;
592
+ isExternal(value: unknown): boolean;
593
+ createResolver<T>(): Resolver<T>;
594
+ createPrivate(name: string): Private;
595
+ getOrCreateGlobalPrivate(name: string): Private;
596
+ setPrivate(obj: any, key: Private, value: any): void;
597
+ getPrivate(obj: any, key: Private): any;
598
+ hasPrivate(obj: any, key: Private): boolean;
599
+ deletePrivate(obj: any, key: Private): boolean;
600
+ }
511
601
 
512
- export declare interface IStoreValue {
513
- id: number;
514
- dispose(): void;
515
- [x: string]: any;
602
+ export declare interface IsolateOptions {
603
+ features?: Partial<Features>;
604
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
516
605
  }
517
606
 
607
+ export declare function isReferenceType(v: any): v is object;
608
+
518
609
  export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL;
519
610
 
520
611
  export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION;
@@ -524,11 +615,9 @@ export declare const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED
524
615
  export declare const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN;
525
616
 
526
617
  export declare class NodeEnv extends Env {
527
- filename: string;
528
- private readonly nodeBinding?;
529
618
  destructing: boolean;
530
619
  finalizationScheduled: boolean;
531
- 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);
620
+ constructor(ctx: Context, store: ArrayStore<Env>, bridge: EnvNativeBridge);
532
621
  deleteMe(): void;
533
622
  canCallIntoJs(): boolean;
534
623
  triggerFatalException(err: any): void;
@@ -547,43 +636,85 @@ export declare class NotSupportWeakRefError extends EmnapiError {
547
636
  constructor(api: string, message: string);
548
637
  }
549
638
 
550
- export declare class Persistent<T> {
551
- private _ref;
639
+ export declare interface ObjectAllocator<T> extends Disposable_2 {
640
+ deref<R extends T = T>(id: number | bigint): R | undefined;
641
+ alloc<P extends any[]>(factory: (...args: P) => T, ...args: P): T;
642
+ dealloc(id: number | bigint): void;
643
+ }
644
+
645
+ export declare class ObjectTemplate extends Template {
646
+ Ctor: any;
647
+ internalFieldCount: number;
648
+ private _accessors;
649
+ constructor(ctx: Isolate, Ctor?: any);
650
+ 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;
651
+ setInternalFieldCount(value: number): void;
652
+ applyToInstance(instance: any): void;
653
+ newInstance(_context: any): any;
654
+ }
655
+
656
+ export declare class Persistent<T> extends Disposable_2 {
552
657
  private _param;
553
658
  private _callback;
659
+ private _isolate;
660
+ id: number;
554
661
  private static readonly _registry;
555
- constructor(value: T);
662
+ constructor(isolate: Isolate, ...args: [T] | []);
663
+ dispose(): void;
664
+ copy(): Persistent<T>;
665
+ move(to: Persistent<T>): void;
666
+ slot(): number;
667
+ getSlot(): PersistentValueType<T>;
668
+ setSlot(ref: PersistentValueType<T>): void;
669
+ deleteSlot(): void;
556
670
  setWeak<P>(param: P, callback: (param: P) => void): void;
557
671
  clearWeak(): void;
558
672
  reset(): void;
673
+ resetTo(value: T): void;
559
674
  isEmpty(): boolean;
560
675
  deref(): T | undefined;
561
676
  }
562
677
 
563
- export declare class Reference extends RefTracker implements IStoreValue {
678
+ export declare class PersistentStore extends ArrayStore<Persistent<any>> {
679
+ private _recyleList;
680
+ constructor(initialCapacity?: number);
681
+ markUnused(id: number | bigint): void;
682
+ recycle(): void;
683
+ }
684
+
685
+ export declare type PersistentValueType<T> = StrongRef<T> | WeakRef<T extends object ? T : never> | undefined;
686
+
687
+ export declare class Private {
688
+ private _name;
689
+ constructor(name: string);
690
+ name(): string;
691
+ static forApi(name: string): Private;
692
+ }
693
+
694
+ export declare class Reference extends RefTracker {
564
695
  private static weakCallback;
565
696
  id: number;
566
- envObject: Env;
567
- private readonly canBeWeak;
697
+ envObject: Env | undefined;
698
+ private ctx;
699
+ private canBeWeak;
568
700
  private _refcount;
569
- private readonly _ownership;
570
- persistent: Persistent<object>;
571
- static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference;
572
- protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
701
+ private _ownership;
702
+ 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;
703
+ constructor(ctx: Context, envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
704
+ getPersistent(): Persistent<any>;
573
705
  ref(): number;
574
706
  unref(): number;
575
- get(envObject?: Env): napi_value;
576
- /** @virtual */
707
+ deref(): any;
708
+ get(): napi_value;
577
709
  resetFinalizer(): void;
578
- /** @virtual */
579
710
  data(): void_p;
580
711
  refcount(): number;
581
712
  ownership(): ReferenceOwnership;
582
- /** @virtual */
583
713
  protected callUserFinalizer(): void;
584
- /** @virtual */
585
714
  protected invokeFinalizerFromGC(): void;
586
715
  private _setWeak;
716
+ setWeakWithData<T>(data: T, callback: (data: T) => void): void;
717
+ clearWeak(): void;
587
718
  finalize(): void;
588
719
  dispose(): void;
589
720
  }
@@ -594,16 +725,16 @@ export declare enum ReferenceOwnership {
594
725
  }
595
726
 
596
727
  export declare class ReferenceWithData extends Reference {
597
- private readonly _data;
598
- static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
599
- private constructor();
728
+ private _data;
729
+ static create(ctx: Context, envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
730
+ constructor(ctx: Context, envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p);
600
731
  data(): void_p;
601
732
  }
602
733
 
603
734
  export declare class ReferenceWithFinalizer extends Reference {
604
735
  private _finalizer;
605
- 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;
606
- private constructor();
736
+ 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;
737
+ 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);
607
738
  resetFinalizer(): void;
608
739
  data(): void_p;
609
740
  protected callUserFinalizer(): void;
@@ -611,41 +742,59 @@ export declare class ReferenceWithFinalizer extends Reference {
611
742
  dispose(): void;
612
743
  }
613
744
 
614
- export declare class RefTracker {
615
- /** @virtual */
745
+ export declare class RefTracker extends Disposable_2 {
616
746
  dispose(): void;
617
- /** @virtual */
618
747
  finalize(): void;
619
- private _next;
620
- private _prev;
748
+ protected _next: RefTracker | null;
749
+ protected _prev: RefTracker | null;
621
750
  link(list: RefTracker): void;
622
751
  unlink(): void;
623
752
  static finalizeAll(list: RefTracker): void;
624
753
  }
625
754
 
626
- export declare class ScopeStore {
755
+ export declare interface Resolver<T> {
756
+ promise: Promise<T>;
757
+ resolve: (value: T | PromiseLike<T>) => void;
758
+ reject: (reason?: any) => void;
759
+ }
760
+
761
+ export declare interface ReusableStoreValue extends Disposable_2 {
762
+ reuse(...args: any[]): void;
763
+ }
764
+
765
+ export declare class ScopeStore extends BaseArrayStore<HandleScope> {
627
766
  private readonly _rootScope;
628
767
  currentScope: HandleScope;
629
- private readonly _values;
630
768
  constructor();
631
- get(id: number): HandleScope | undefined;
632
769
  openScope(handleStore: HandleStore): HandleScope;
633
770
  closeScope(): void;
634
- dispose(): void;
771
+ isEmpty(): boolean;
635
772
  }
636
773
 
637
- export declare class Store<V extends IStoreValue> {
638
- protected _values: Array<V | undefined>;
639
- private _freeList;
640
- private _size;
641
- constructor();
642
- add(value: V): void;
643
- get(id: Ptr): V | undefined;
644
- has(id: Ptr): boolean;
645
- remove(id: Ptr): void;
774
+ export declare function setInternalField(instance: object, index: number, value: any): void;
775
+
776
+ export declare function setPrivate(obj: any, key: Private, value: any): void;
777
+
778
+ export declare class Signature {
779
+ receiver: FunctionTemplate | undefined;
780
+ constructor(receiver: FunctionTemplate | undefined);
781
+ }
782
+
783
+ export declare class StrongRef<T> extends Disposable_2 {
784
+ private _value;
785
+ constructor(value: T);
786
+ deref(): T;
646
787
  dispose(): void;
647
788
  }
648
789
 
790
+ export declare class Template {
791
+ protected ctx: Isolate;
792
+ protected _properties: Map<string | symbol, [any, number]>;
793
+ constructor(ctx: Isolate);
794
+ set(name: string | symbol, value: any, attr: number): void;
795
+ protected _addPropertiesToInstance(instance: any): void;
796
+ }
797
+
649
798
  export declare class TrackedFinalizer extends RefTracker {
650
799
  private _finalizer;
651
800
  static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
@@ -656,11 +805,19 @@ export declare class TrackedFinalizer extends RefTracker {
656
805
  }
657
806
 
658
807
  export declare class TryCatch {
808
+ static top: TryCatch | null;
809
+ private static _map;
810
+ id: number | bigint;
659
811
  private _exception;
660
812
  private _caught;
813
+ private _next;
814
+ constructor(id: number | bigint);
815
+ static deref(id: number | bigint): TryCatch | undefined;
816
+ static pop(): void;
661
817
  isEmpty(): boolean;
662
818
  hasCaught(): boolean;
663
819
  exception(): any;
820
+ rethrow(ctx: Isolate): any;
664
821
  setError(err: any): void;
665
822
  reset(): void;
666
823
  extractException(): any;
@@ -669,5 +826,3 @@ export declare class TryCatch {
669
826
  export declare const version: string;
670
827
 
671
828
  export { }
672
-
673
- export as namespace emnapi;