@emnapi/runtime 1.1.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -202,7 +202,7 @@ const _Buffer = typeof Buffer === 'function'
202
202
  catch (_) { }
203
203
  return undefined;
204
204
  })();
205
- const version = "1.1.1";
205
+ const version = "1.3.0";
206
206
  const NODE_API_SUPPORTED_VERSION_MIN = 1;
207
207
  const NODE_API_SUPPORTED_VERSION_MAX = 9;
208
208
  const NAPI_VERSION_EXPERIMENTAL = 2147483647;
@@ -243,8 +243,9 @@ class Handle {
243
243
  isTypedArray() {
244
244
  return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
245
245
  }
246
- isBuffer() {
247
- return typeof _Buffer === 'function' && _Buffer.isBuffer(this.value);
246
+ isBuffer(BufferConstructor) {
247
+ BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer);
248
+ return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value);
248
249
  }
249
250
  isDataView() {
250
251
  return (this.value instanceof DataView);
@@ -446,6 +447,7 @@ class RefTracker {
446
447
  this._next = null;
447
448
  this._prev = null;
448
449
  }
450
+ dispose() { }
449
451
  finalize() { }
450
452
  link(list) {
451
453
  this._prev = list;
@@ -478,103 +480,80 @@ class Finalizer {
478
480
  this._finalizeCallback = _finalizeCallback;
479
481
  this._finalizeData = _finalizeData;
480
482
  this._finalizeHint = _finalizeHint;
483
+ this._makeDynCall_vppp = envObject.makeDynCall_vppp;
481
484
  }
482
485
  callback() { return this._finalizeCallback; }
483
486
  data() { return this._finalizeData; }
484
487
  hint() { return this._finalizeHint; }
488
+ resetEnv() {
489
+ this.envObject = undefined;
490
+ }
485
491
  resetFinalizer() {
486
492
  this._finalizeCallback = 0;
487
493
  this._finalizeData = 0;
488
494
  this._finalizeHint = 0;
489
495
  }
496
+ callFinalizer() {
497
+ const finalize_callback = this._finalizeCallback;
498
+ const finalize_data = this._finalizeData;
499
+ const finalize_hint = this._finalizeHint;
500
+ this.resetFinalizer();
501
+ if (!finalize_callback)
502
+ return;
503
+ const fini = Number(finalize_callback);
504
+ if (!this.envObject) {
505
+ this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
506
+ }
507
+ else {
508
+ this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
509
+ }
510
+ }
490
511
  dispose() {
491
512
  this.envObject = undefined;
513
+ this._makeDynCall_vppp = undefined;
492
514
  }
493
515
  }
494
516
 
495
- class TrackedFinalizer extends Finalizer {
496
- static finalizeAll(list) {
497
- RefTracker.finalizeAll(list);
498
- }
499
- link(list) {
500
- RefTracker.prototype.link.call(this, list);
501
- }
502
- unlink() {
503
- RefTracker.prototype.unlink.call(this);
504
- }
517
+ class TrackedFinalizer extends RefTracker {
505
518
  static create(envObject, finalize_callback, finalize_data, finalize_hint) {
506
- return new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
519
+ const finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
520
+ finalizer.link(envObject.finalizing_reflist);
521
+ return finalizer;
507
522
  }
508
523
  constructor(envObject, finalize_callback, finalize_data, finalize_hint) {
509
- super(envObject, finalize_callback, finalize_data, finalize_hint);
510
- this._next = null;
511
- this._prev = null;
512
- this.link(!finalize_callback ? envObject.reflist : envObject.finalizing_reflist);
524
+ super();
525
+ this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
526
+ }
527
+ data() {
528
+ return this._finalizer.data();
513
529
  }
514
530
  dispose() {
531
+ if (!this._finalizer)
532
+ return;
515
533
  this.unlink();
516
- this.envObject.dequeueFinalizer(this);
534
+ this._finalizer.envObject.dequeueFinalizer(this);
535
+ this._finalizer.dispose();
536
+ this._finalizer = undefined;
517
537
  super.dispose();
518
538
  }
519
539
  finalize() {
520
- this.finalizeCore(true);
521
- }
522
- finalizeCore(deleteMe) {
523
- const finalize_callback = this._finalizeCallback;
524
- const finalize_data = this._finalizeData;
525
- const finalize_hint = this._finalizeHint;
526
- this.resetFinalizer();
527
540
  this.unlink();
528
541
  let error;
529
542
  let caught = false;
530
- if (finalize_callback) {
531
- const fini = Number(finalize_callback);
532
- try {
533
- this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
534
- }
535
- catch (err) {
536
- caught = true;
537
- error = err;
538
- }
543
+ try {
544
+ this._finalizer.callFinalizer();
539
545
  }
540
- if (deleteMe) {
541
- this.dispose();
546
+ catch (err) {
547
+ caught = true;
548
+ error = err;
542
549
  }
550
+ this.dispose();
543
551
  if (caught) {
544
552
  throw error;
545
553
  }
546
554
  }
547
555
  }
548
556
 
549
- class RefBase extends TrackedFinalizer {
550
- constructor(envObject, initial_refcount, ownership, finalize_callback, finalize_data, finalize_hint) {
551
- super(envObject, finalize_callback, finalize_data, finalize_hint);
552
- this._refcount = initial_refcount;
553
- this._ownership = ownership;
554
- }
555
- data() {
556
- return this._finalizeData;
557
- }
558
- ref() {
559
- return ++this._refcount;
560
- }
561
- unref() {
562
- if (this._refcount === 0) {
563
- return 0;
564
- }
565
- return --this._refcount;
566
- }
567
- refCount() {
568
- return this._refcount;
569
- }
570
- ownership() {
571
- return this._ownership;
572
- }
573
- finalize() {
574
- this.finalizeCore(this._ownership === 0);
575
- }
576
- }
577
-
578
557
  function throwNodeApiVersionError(moduleName, moduleApiVersion) {
579
558
  const errorMessage = `${moduleName} requires Node-API version ${moduleApiVersion}, but this version of Node.js only supports version ${NODE_API_SUPPORTED_VERSION_MAX} add-ons.`;
580
559
  throw new Error(errorMessage);
@@ -665,17 +644,6 @@ class Env {
665
644
  }
666
645
  return r;
667
646
  }
668
- callFinalizer(cb, data, hint) {
669
- const f = this.makeDynCall_vppp(cb);
670
- const env = this.id;
671
- const scope = this.ctx.openScope(this);
672
- try {
673
- this.callIntoModule(() => { f(env, data, hint); });
674
- }
675
- finally {
676
- this.ctx.closeScope(this, scope);
677
- }
678
- }
679
647
  invokeFinalizerFromGC(finalizer) {
680
648
  if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
681
649
  this.enqueueFinalizer(finalizer);
@@ -713,8 +681,8 @@ class Env {
713
681
  }
714
682
  }
715
683
  deleteMe() {
716
- RefBase.finalizeAll(this.finalizing_reflist);
717
- RefBase.finalizeAll(this.reflist);
684
+ RefTracker.finalizeAll(this.finalizing_reflist);
685
+ RefTracker.finalizeAll(this.reflist);
718
686
  this.tryCatch.extractException();
719
687
  this.ctx.envStore.remove(this.id);
720
688
  }
@@ -722,6 +690,8 @@ class Env {
722
690
  if (this.id === 0)
723
691
  return;
724
692
  this.deleteMe();
693
+ this.finalizing_reflist.dispose();
694
+ this.reflist.dispose();
725
695
  this.id = 0;
726
696
  }
727
697
  initObjectBinding(value) {
@@ -743,7 +713,7 @@ class Env {
743
713
  if (this.instanceData) {
744
714
  this.instanceData.dispose();
745
715
  }
746
- this.instanceData = new RefBase(this, 0, 0, finalize_cb, data, finalize_hint);
716
+ this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
747
717
  }
748
718
  getInstanceData() {
749
719
  return this.instanceData ? this.instanceData.data() : 0;
@@ -988,61 +958,75 @@ Persistent._registry = supportFinalizer
988
958
  })
989
959
  : undefined;
990
960
 
991
- function weakCallback(ref) {
992
- ref.persistent.reset();
993
- ref.envObject.invokeFinalizerFromGC(ref);
994
- }
961
+ exports.ReferenceOwnership = void 0;
962
+ (function (ReferenceOwnership) {
963
+ ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
964
+ ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
965
+ })(exports.ReferenceOwnership || (exports.ReferenceOwnership = {}));
995
966
  function canBeHeldWeakly(value) {
996
967
  return value.isObject() || value.isFunction() || value.isSymbol();
997
968
  }
998
- class Reference extends RefBase {
999
- static create(envObject, handle_id, initialRefcount, ownership, finalize_callback = 0, finalize_data = 0, finalize_hint = 0) {
1000
- const handle = envObject.ctx.handleStore.get(handle_id);
1001
- const ref = new Reference(envObject, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
969
+ class Reference extends RefTracker {
970
+ static weakCallback(ref) {
971
+ ref.persistent.reset();
972
+ ref.invokeFinalizerFromGC();
973
+ }
974
+ static create(envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
975
+ const ref = new Reference(envObject, handle_id, initialRefcount, ownership);
1002
976
  envObject.ctx.refStore.add(ref);
1003
- ref.canBeWeak = canBeHeldWeakly(handle);
1004
- ref.persistent = new Persistent(handle.value);
1005
- if (initialRefcount === 0) {
1006
- ref._setWeak();
1007
- }
977
+ ref.link(envObject.reflist);
1008
978
  return ref;
1009
979
  }
1010
- constructor(envObject, initialRefcount, ownership, finalize_callback = 0, finalize_data = 0, finalize_hint = 0) {
1011
- super(envObject, initialRefcount >>> 0, ownership, finalize_callback, finalize_data, finalize_hint);
980
+ constructor(envObject, handle_id, initialRefcount, ownership) {
981
+ super();
982
+ this.envObject = envObject;
983
+ this._refcount = initialRefcount;
984
+ this._ownership = ownership;
985
+ const handle = envObject.ctx.handleStore.get(handle_id);
986
+ this.canBeWeak = canBeHeldWeakly(handle);
987
+ this.persistent = new Persistent(handle.value);
1012
988
  this.id = 0;
989
+ if (initialRefcount === 0) {
990
+ this._setWeak();
991
+ }
1013
992
  }
1014
993
  ref() {
1015
994
  if (this.persistent.isEmpty()) {
1016
995
  return 0;
1017
996
  }
1018
- const count = super.ref();
1019
- if (count === 1 && this.canBeWeak) {
997
+ if (++this._refcount === 1 && this.canBeWeak) {
1020
998
  this.persistent.clearWeak();
1021
999
  }
1022
- return count;
1000
+ return this._refcount;
1023
1001
  }
1024
1002
  unref() {
1025
- if (this.persistent.isEmpty()) {
1003
+ if (this.persistent.isEmpty() || this._refcount === 0) {
1026
1004
  return 0;
1027
1005
  }
1028
- const oldRefcount = this.refCount();
1029
- const refcount = super.unref();
1030
- if (oldRefcount === 1 && refcount === 0) {
1006
+ if (--this._refcount === 0) {
1031
1007
  this._setWeak();
1032
1008
  }
1033
- return refcount;
1009
+ return this._refcount;
1034
1010
  }
1035
- get() {
1011
+ get(envObject = this.envObject) {
1036
1012
  if (this.persistent.isEmpty()) {
1037
1013
  return 0;
1038
1014
  }
1039
1015
  const obj = this.persistent.deref();
1040
- const handle = this.envObject.ensureHandle(obj);
1016
+ const handle = envObject.ensureHandle(obj);
1041
1017
  return handle.id;
1042
1018
  }
1019
+ resetFinalizer() { }
1020
+ data() { return 0; }
1021
+ refcount() { return this._refcount; }
1022
+ ownership() { return this._ownership; }
1023
+ callUserFinalizer() { }
1024
+ invokeFinalizerFromGC() {
1025
+ this.finalize();
1026
+ }
1043
1027
  _setWeak() {
1044
1028
  if (this.canBeWeak) {
1045
- this.persistent.setWeak(this, weakCallback);
1029
+ this.persistent.setWeak(this, Reference.weakCallback);
1046
1030
  }
1047
1031
  else {
1048
1032
  this.persistent.reset();
@@ -1050,17 +1034,71 @@ class Reference extends RefBase {
1050
1034
  }
1051
1035
  finalize() {
1052
1036
  this.persistent.reset();
1053
- super.finalize();
1037
+ const deleteMe = this._ownership === exports.ReferenceOwnership.kRuntime;
1038
+ this.unlink();
1039
+ this.callUserFinalizer();
1040
+ if (deleteMe) {
1041
+ this.dispose();
1042
+ }
1054
1043
  }
1055
1044
  dispose() {
1056
1045
  if (this.id === 0)
1057
1046
  return;
1047
+ this.unlink();
1058
1048
  this.persistent.reset();
1059
1049
  this.envObject.ctx.refStore.remove(this.id);
1060
1050
  super.dispose();
1051
+ this.envObject = undefined;
1061
1052
  this.id = 0;
1062
1053
  }
1063
1054
  }
1055
+ class ReferenceWithData extends Reference {
1056
+ static create(envObject, value, initialRefcount, ownership, data) {
1057
+ const reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
1058
+ envObject.ctx.refStore.add(reference);
1059
+ reference.link(envObject.reflist);
1060
+ return reference;
1061
+ }
1062
+ constructor(envObject, value, initialRefcount, ownership, _data) {
1063
+ super(envObject, value, initialRefcount, ownership);
1064
+ this._data = _data;
1065
+ }
1066
+ data() {
1067
+ return this._data;
1068
+ }
1069
+ }
1070
+ class ReferenceWithFinalizer extends Reference {
1071
+ static create(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1072
+ const reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1073
+ envObject.ctx.refStore.add(reference);
1074
+ reference.link(envObject.finalizing_reflist);
1075
+ return reference;
1076
+ }
1077
+ constructor(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1078
+ super(envObject, value, initialRefcount, ownership);
1079
+ this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
1080
+ }
1081
+ resetFinalizer() {
1082
+ this._finalizer.resetFinalizer();
1083
+ }
1084
+ data() {
1085
+ return this._finalizer.data();
1086
+ }
1087
+ callUserFinalizer() {
1088
+ this._finalizer.callFinalizer();
1089
+ }
1090
+ invokeFinalizerFromGC() {
1091
+ this._finalizer.envObject.invokeFinalizerFromGC(this);
1092
+ }
1093
+ dispose() {
1094
+ if (!this._finalizer)
1095
+ return;
1096
+ this._finalizer.envObject.dequeueFinalizer(this);
1097
+ this._finalizer.dispose();
1098
+ super.dispose();
1099
+ this._finalizer = undefined;
1100
+ }
1101
+ }
1064
1102
 
1065
1103
  class Deferred {
1066
1104
  static create(ctx, value) {
@@ -1211,6 +1249,7 @@ class Context {
1211
1249
  constructor() {
1212
1250
  this._isStopping = false;
1213
1251
  this._canCallIntoJs = true;
1252
+ this._suppressDestroy = false;
1214
1253
  this.envStore = new Store();
1215
1254
  this.scopeStore = new ScopeStore();
1216
1255
  this.refStore = new Store();
@@ -1232,10 +1271,15 @@ class Context {
1232
1271
  if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1233
1272
  this.refCounter = new NodejsWaitingRequestCounter();
1234
1273
  process.once('beforeExit', () => {
1235
- this.destroy();
1274
+ if (!this._suppressDestroy) {
1275
+ this.destroy();
1276
+ }
1236
1277
  });
1237
1278
  }
1238
1279
  }
1280
+ suppressDestroy() {
1281
+ this._suppressDestroy = true;
1282
+ }
1239
1283
  getRuntimeVersions() {
1240
1284
  return {
1241
1285
  version,
@@ -1250,8 +1294,14 @@ class Context {
1250
1294
  createNotSupportBufferError(api, message) {
1251
1295
  return new NotSupportBufferError(api, message);
1252
1296
  }
1253
- createReference(envObject, handle_id, initialRefcount, ownership, finalize_callback = 0, finalize_data = 0, finalize_hint = 0) {
1254
- return Reference.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1297
+ createReference(envObject, handle_id, initialRefcount, ownership) {
1298
+ return Reference.create(envObject, handle_id, initialRefcount, ownership);
1299
+ }
1300
+ createReferenceWithData(envObject, handle_id, initialRefcount, ownership, data) {
1301
+ return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
1302
+ }
1303
+ createReferenceWithFinalizer(envObject, handle_id, initialRefcount, ownership, finalize_callback = 0, finalize_data = 0, finalize_hint = 0) {
1304
+ return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1255
1305
  }
1256
1306
  createDeferred(value) {
1257
1307
  return Deferred.create(this, value);
@@ -1348,9 +1398,10 @@ exports.NodeEnv = NodeEnv;
1348
1398
  exports.NotSupportBufferError = NotSupportBufferError;
1349
1399
  exports.NotSupportWeakRefError = NotSupportWeakRefError;
1350
1400
  exports.Persistent = Persistent;
1351
- exports.RefBase = RefBase;
1352
1401
  exports.RefTracker = RefTracker;
1353
1402
  exports.Reference = Reference;
1403
+ exports.ReferenceWithData = ReferenceWithData;
1404
+ exports.ReferenceWithFinalizer = ReferenceWithFinalizer;
1354
1405
  exports.ScopeStore = ScopeStore;
1355
1406
  exports.Store = Store;
1356
1407
  exports.TrackedFinalizer = TrackedFinalizer;
@@ -21,11 +21,6 @@ export declare const enum GlobalHandle {
21
21
  GLOBAL
22
22
  }
23
23
 
24
- export declare const enum Ownership {
25
- kRuntime,
26
- kUserland
27
- }
28
-
29
24
  export declare const enum Version {
30
25
  NODE_API_SUPPORTED_VERSION_MIN = 1,
31
26
  NODE_API_DEFAULT_MODULE_API_VERSION = 8,
@@ -282,6 +277,7 @@ export declare class ConstHandle<S extends undefined | null | boolean | typeof g
282
277
  export declare class Context {
283
278
  private _isStopping;
284
279
  private _canCallIntoJs;
280
+ private _suppressDestroy;
285
281
  envStore: Store<Env>;
286
282
  scopeStore: ScopeStore;
287
283
  refStore: Store<Reference>;
@@ -305,6 +301,15 @@ export declare class Context {
305
301
  } | undefined;
306
302
  };
307
303
  constructor();
304
+ /**
305
+ * Suppress the destroy on `beforeExit` event in Node.js.
306
+ * Call this method if you want to keep the context and
307
+ * all associated {@link Env | Env} alive,
308
+ * this also means that cleanup hooks will not be called.
309
+ * After call this method, you should call
310
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
311
+ */
312
+ suppressDestroy(): void;
308
313
  getRuntimeVersions(): {
309
314
  version: string;
310
315
  NODE_API_SUPPORTED_VERSION_MAX: Version;
@@ -313,7 +318,9 @@ export declare class Context {
313
318
  };
314
319
  createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
315
320
  createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
316
- createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
321
+ createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference;
322
+ createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
323
+ 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;
317
324
  createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
318
325
  createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
319
326
  createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
@@ -330,6 +337,10 @@ export declare class Context {
330
337
  setCanCallIntoJs(value: boolean): void;
331
338
  setStopping(value: boolean): void;
332
339
  canCallIntoJs(): boolean;
340
+ /**
341
+ * Destroy the context and call cleanup hooks.
342
+ * Associated {@link Env | Env} will be destroyed.
343
+ */
333
344
  destroy(): void;
334
345
  }
335
346
 
@@ -350,7 +361,7 @@ export declare class EmnapiError extends Error {
350
361
  constructor(message?: string);
351
362
  }
352
363
 
353
- export declare class Env implements IStoreValue {
364
+ export declare abstract class Env implements IStoreValue {
354
365
  readonly ctx: Context;
355
366
  moduleApiVersion: number;
356
367
  makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
@@ -358,7 +369,7 @@ export declare class Env implements IStoreValue {
358
369
  abort: (msg?: string) => never;
359
370
  id: number;
360
371
  openHandleScopes: number;
361
- instanceData: RefBase | null;
372
+ instanceData: TrackedFinalizer | null;
362
373
  tryCatch: TryCatch;
363
374
  refs: number;
364
375
  reflist: RefTracker;
@@ -383,7 +394,7 @@ export declare class Env implements IStoreValue {
383
394
  getReturnStatus(): napi_status;
384
395
  callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
385
396
  /** @virtual */
386
- callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
397
+ abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
387
398
  invokeFinalizerFromGC(finalizer: RefTracker): void;
388
399
  checkGCAccess(): void;
389
400
  /** @virtual */
@@ -402,14 +413,17 @@ export declare class Env implements IStoreValue {
402
413
 
403
414
  export declare class Finalizer {
404
415
  envObject: Env;
405
- protected _finalizeCallback: napi_finalize;
406
- protected _finalizeData: void_p;
407
- protected _finalizeHint: void_p;
416
+ private _finalizeCallback;
417
+ private _finalizeData;
418
+ private _finalizeHint;
419
+ private _makeDynCall_vppp;
408
420
  constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
409
421
  callback(): napi_finalize;
410
422
  data(): void_p;
411
423
  hint(): void_p;
424
+ resetEnv(): void;
412
425
  resetFinalizer(): void;
426
+ callFinalizer(): void;
413
427
  dispose(): void;
414
428
  }
415
429
 
@@ -429,7 +443,7 @@ export declare class Handle<S> {
429
443
  isArray(): boolean;
430
444
  isArrayBuffer(): boolean;
431
445
  isTypedArray(): boolean;
432
- isBuffer(): boolean;
446
+ isBuffer(BufferConstructor?: BufferCtor): boolean;
433
447
  isDataView(): boolean;
434
448
  isDate(): boolean;
435
449
  isPromise(): boolean;
@@ -536,33 +550,60 @@ export declare class Persistent<T> {
536
550
  deref(): T | undefined;
537
551
  }
538
552
 
539
- export declare class RefBase extends TrackedFinalizer {
553
+ export declare class Reference extends RefTracker implements IStoreValue {
554
+ private static weakCallback;
555
+ id: number;
556
+ envObject: Env;
557
+ private readonly canBeWeak;
540
558
  private _refcount;
541
559
  private readonly _ownership;
542
- constructor(envObject: Env, initial_refcount: uint32_t, ownership: number, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
543
- data(): void_p;
544
- ref(): uint32_t;
545
- unref(): uint32_t;
546
- refCount(): uint32_t;
547
- ownership(): number;
548
- finalize(): void;
549
- }
550
-
551
- export declare class Reference extends RefBase implements IStoreValue {
552
- id: number;
553
- private canBeWeak;
554
- static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
555
560
  persistent: Persistent<object>;
556
- private constructor();
561
+ static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference;
562
+ protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
557
563
  ref(): number;
558
564
  unref(): number;
559
- get(): napi_value;
565
+ get(envObject?: Env): napi_value;
566
+ /** @virtual */
567
+ resetFinalizer(): void;
568
+ /** @virtual */
569
+ data(): void_p;
570
+ refcount(): number;
571
+ ownership(): ReferenceOwnership;
572
+ /** @virtual */
573
+ protected callUserFinalizer(): void;
574
+ /** @virtual */
575
+ protected invokeFinalizerFromGC(): void;
560
576
  private _setWeak;
561
577
  finalize(): void;
562
578
  dispose(): void;
563
579
  }
564
580
 
581
+ export declare enum ReferenceOwnership {
582
+ kRuntime = 0,
583
+ kUserland = 1
584
+ }
585
+
586
+ export declare class ReferenceWithData extends Reference {
587
+ private readonly _data;
588
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
589
+ private constructor();
590
+ data(): void_p;
591
+ }
592
+
593
+ export declare class ReferenceWithFinalizer extends Reference {
594
+ private _finalizer;
595
+ 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;
596
+ private constructor();
597
+ resetFinalizer(): void;
598
+ data(): void_p;
599
+ protected callUserFinalizer(): void;
600
+ protected invokeFinalizerFromGC(): void;
601
+ dispose(): void;
602
+ }
603
+
565
604
  export declare class RefTracker {
605
+ /** @virtual */
606
+ dispose(): void;
566
607
  /** @virtual */
567
608
  finalize(): void;
568
609
  private _next;
@@ -594,18 +635,13 @@ export declare class Store<V extends IStoreValue> {
594
635
  dispose(): void;
595
636
  }
596
637
 
597
- export declare interface TrackedFinalizer extends Finalizer, RefTracker {
598
- }
599
-
600
- export declare class TrackedFinalizer extends Finalizer {
601
- static finalizeAll(list: RefTracker): void;
602
- link(list: RefTracker): void;
603
- unlink(): void;
638
+ export declare class TrackedFinalizer extends RefTracker {
639
+ private _finalizer;
604
640
  static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
605
- protected constructor(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p);
641
+ private constructor();
642
+ data(): void_p;
606
643
  dispose(): void;
607
644
  finalize(): void;
608
- protected finalizeCore(deleteMe: boolean): void;
609
645
  }
610
646
 
611
647
  export declare class TryCatch {