@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.
- package/dist/emnapi.cjs.js +162 -111
- package/dist/emnapi.cjs.min.d.ts +74 -38
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.mts +74 -38
- package/dist/emnapi.d.ts +74 -38
- package/dist/emnapi.esm-bundler.js +185 -121
- package/dist/emnapi.iife.d.ts +74 -33
- package/dist/emnapi.iife.js +187 -122
- package/dist/emnapi.js +187 -122
- package/dist/emnapi.min.d.mts +74 -38
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +161 -111
- package/package.json +2 -3
|
@@ -210,7 +210,7 @@ var _Buffer = typeof Buffer === 'function'
|
|
|
210
210
|
catch (_) { }
|
|
211
211
|
return undefined;
|
|
212
212
|
})();
|
|
213
|
-
var version = "1.
|
|
213
|
+
var version = "1.3.0";
|
|
214
214
|
var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
|
|
215
215
|
var NODE_API_SUPPORTED_VERSION_MAX = 9 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
|
|
216
216
|
var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
|
|
@@ -251,8 +251,9 @@ var Handle = /*#__PURE__*/ (function () {
|
|
|
251
251
|
Handle.prototype.isTypedArray = function () {
|
|
252
252
|
return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
|
|
253
253
|
};
|
|
254
|
-
Handle.prototype.isBuffer = function () {
|
|
255
|
-
|
|
254
|
+
Handle.prototype.isBuffer = function (BufferConstructor) {
|
|
255
|
+
BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer);
|
|
256
|
+
return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value);
|
|
256
257
|
};
|
|
257
258
|
Handle.prototype.isDataView = function () {
|
|
258
259
|
return (this.value instanceof DataView);
|
|
@@ -462,6 +463,8 @@ var RefTracker = /*#__PURE__*/ (function () {
|
|
|
462
463
|
this._prev = null;
|
|
463
464
|
}
|
|
464
465
|
/** @virtual */
|
|
466
|
+
RefTracker.prototype.dispose = function () { };
|
|
467
|
+
/** @virtual */
|
|
465
468
|
RefTracker.prototype.finalize = function () { };
|
|
466
469
|
RefTracker.prototype.link = function (list) {
|
|
467
470
|
this._prev = list;
|
|
@@ -498,17 +501,37 @@ var Finalizer = /*#__PURE__*/ (function () {
|
|
|
498
501
|
this._finalizeCallback = _finalizeCallback;
|
|
499
502
|
this._finalizeData = _finalizeData;
|
|
500
503
|
this._finalizeHint = _finalizeHint;
|
|
504
|
+
this._makeDynCall_vppp = envObject.makeDynCall_vppp;
|
|
501
505
|
}
|
|
502
506
|
Finalizer.prototype.callback = function () { return this._finalizeCallback; };
|
|
503
507
|
Finalizer.prototype.data = function () { return this._finalizeData; };
|
|
504
508
|
Finalizer.prototype.hint = function () { return this._finalizeHint; };
|
|
509
|
+
Finalizer.prototype.resetEnv = function () {
|
|
510
|
+
this.envObject = undefined;
|
|
511
|
+
};
|
|
505
512
|
Finalizer.prototype.resetFinalizer = function () {
|
|
506
513
|
this._finalizeCallback = 0;
|
|
507
514
|
this._finalizeData = 0;
|
|
508
515
|
this._finalizeHint = 0;
|
|
509
516
|
};
|
|
517
|
+
Finalizer.prototype.callFinalizer = function () {
|
|
518
|
+
var finalize_callback = this._finalizeCallback;
|
|
519
|
+
var finalize_data = this._finalizeData;
|
|
520
|
+
var finalize_hint = this._finalizeHint;
|
|
521
|
+
this.resetFinalizer();
|
|
522
|
+
if (!finalize_callback)
|
|
523
|
+
return;
|
|
524
|
+
var fini = Number(finalize_callback);
|
|
525
|
+
if (!this.envObject) {
|
|
526
|
+
this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
|
|
530
|
+
}
|
|
531
|
+
};
|
|
510
532
|
Finalizer.prototype.dispose = function () {
|
|
511
533
|
this.envObject = undefined;
|
|
534
|
+
this._makeDynCall_vppp = undefined;
|
|
512
535
|
};
|
|
513
536
|
return Finalizer;
|
|
514
537
|
}());
|
|
@@ -516,91 +539,45 @@ var Finalizer = /*#__PURE__*/ (function () {
|
|
|
516
539
|
var TrackedFinalizer = /*#__PURE__*/ (function (_super) {
|
|
517
540
|
__extends(TrackedFinalizer, _super);
|
|
518
541
|
function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
519
|
-
var _this = _super.call(this
|
|
520
|
-
_this.
|
|
521
|
-
_this._prev = null;
|
|
522
|
-
_this.link(!finalize_callback ? envObject.reflist : envObject.finalizing_reflist);
|
|
542
|
+
var _this = _super.call(this) || this;
|
|
543
|
+
_this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
523
544
|
return _this;
|
|
524
545
|
}
|
|
525
|
-
TrackedFinalizer.finalizeAll = function (list) {
|
|
526
|
-
RefTracker.finalizeAll(list);
|
|
527
|
-
};
|
|
528
|
-
TrackedFinalizer.prototype.link = function (list) {
|
|
529
|
-
RefTracker.prototype.link.call(this, list);
|
|
530
|
-
};
|
|
531
|
-
TrackedFinalizer.prototype.unlink = function () {
|
|
532
|
-
RefTracker.prototype.unlink.call(this);
|
|
533
|
-
};
|
|
534
546
|
TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
535
|
-
|
|
547
|
+
var finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
548
|
+
finalizer.link(envObject.finalizing_reflist);
|
|
549
|
+
return finalizer;
|
|
550
|
+
};
|
|
551
|
+
TrackedFinalizer.prototype.data = function () {
|
|
552
|
+
return this._finalizer.data();
|
|
536
553
|
};
|
|
537
554
|
TrackedFinalizer.prototype.dispose = function () {
|
|
555
|
+
if (!this._finalizer)
|
|
556
|
+
return;
|
|
538
557
|
this.unlink();
|
|
539
|
-
this.envObject.dequeueFinalizer(this);
|
|
558
|
+
this._finalizer.envObject.dequeueFinalizer(this);
|
|
559
|
+
this._finalizer.dispose();
|
|
560
|
+
this._finalizer = undefined;
|
|
540
561
|
_super.prototype.dispose.call(this);
|
|
541
562
|
};
|
|
542
563
|
TrackedFinalizer.prototype.finalize = function () {
|
|
543
|
-
this.finalizeCore(true);
|
|
544
|
-
};
|
|
545
|
-
TrackedFinalizer.prototype.finalizeCore = function (deleteMe) {
|
|
546
|
-
var finalize_callback = this._finalizeCallback;
|
|
547
|
-
var finalize_data = this._finalizeData;
|
|
548
|
-
var finalize_hint = this._finalizeHint;
|
|
549
|
-
this.resetFinalizer();
|
|
550
564
|
this.unlink();
|
|
551
565
|
var error;
|
|
552
566
|
var caught = false;
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
try {
|
|
556
|
-
this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
|
|
557
|
-
}
|
|
558
|
-
catch (err) {
|
|
559
|
-
caught = true;
|
|
560
|
-
error = err;
|
|
561
|
-
}
|
|
567
|
+
try {
|
|
568
|
+
this._finalizer.callFinalizer();
|
|
562
569
|
}
|
|
563
|
-
|
|
564
|
-
|
|
570
|
+
catch (err) {
|
|
571
|
+
caught = true;
|
|
572
|
+
error = err;
|
|
565
573
|
}
|
|
574
|
+
this.dispose();
|
|
566
575
|
if (caught) {
|
|
567
576
|
throw error;
|
|
568
577
|
}
|
|
569
578
|
};
|
|
570
579
|
return TrackedFinalizer;
|
|
571
|
-
}(
|
|
572
|
-
|
|
573
|
-
var RefBase = /*#__PURE__*/ (function (_super) {
|
|
574
|
-
__extends(RefBase, _super);
|
|
575
|
-
function RefBase(envObject, initial_refcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
576
|
-
var _this = _super.call(this, envObject, finalize_callback, finalize_data, finalize_hint) || this;
|
|
577
|
-
_this._refcount = initial_refcount;
|
|
578
|
-
_this._ownership = ownership;
|
|
579
|
-
return _this;
|
|
580
|
-
}
|
|
581
|
-
RefBase.prototype.data = function () {
|
|
582
|
-
return this._finalizeData;
|
|
583
|
-
};
|
|
584
|
-
RefBase.prototype.ref = function () {
|
|
585
|
-
return ++this._refcount;
|
|
586
|
-
};
|
|
587
|
-
RefBase.prototype.unref = function () {
|
|
588
|
-
if (this._refcount === 0) {
|
|
589
|
-
return 0;
|
|
590
|
-
}
|
|
591
|
-
return --this._refcount;
|
|
592
|
-
};
|
|
593
|
-
RefBase.prototype.refCount = function () {
|
|
594
|
-
return this._refcount;
|
|
595
|
-
};
|
|
596
|
-
RefBase.prototype.ownership = function () {
|
|
597
|
-
return this._ownership;
|
|
598
|
-
};
|
|
599
|
-
RefBase.prototype.finalize = function () {
|
|
600
|
-
this.finalizeCore(this._ownership === 0 /* Ownership.kRuntime */);
|
|
601
|
-
};
|
|
602
|
-
return RefBase;
|
|
603
|
-
}(TrackedFinalizer));
|
|
580
|
+
}(RefTracker));
|
|
604
581
|
|
|
605
582
|
function throwNodeApiVersionError(moduleName, moduleApiVersion) {
|
|
606
583
|
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.");
|
|
@@ -696,18 +673,6 @@ var Env = /*#__PURE__*/ (function () {
|
|
|
696
673
|
}
|
|
697
674
|
return r;
|
|
698
675
|
};
|
|
699
|
-
/** @virtual */
|
|
700
|
-
Env.prototype.callFinalizer = function (cb, data, hint) {
|
|
701
|
-
var f = this.makeDynCall_vppp(cb);
|
|
702
|
-
var env = this.id;
|
|
703
|
-
var scope = this.ctx.openScope(this);
|
|
704
|
-
try {
|
|
705
|
-
this.callIntoModule(function () { f(env, data, hint); });
|
|
706
|
-
}
|
|
707
|
-
finally {
|
|
708
|
-
this.ctx.closeScope(this, scope);
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
676
|
Env.prototype.invokeFinalizerFromGC = function (finalizer) {
|
|
712
677
|
if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
|
|
713
678
|
this.enqueueFinalizer(finalizer);
|
|
@@ -748,8 +713,8 @@ var Env = /*#__PURE__*/ (function () {
|
|
|
748
713
|
};
|
|
749
714
|
/** @virtual */
|
|
750
715
|
Env.prototype.deleteMe = function () {
|
|
751
|
-
|
|
752
|
-
|
|
716
|
+
RefTracker.finalizeAll(this.finalizing_reflist);
|
|
717
|
+
RefTracker.finalizeAll(this.reflist);
|
|
753
718
|
this.tryCatch.extractException();
|
|
754
719
|
this.ctx.envStore.remove(this.id);
|
|
755
720
|
};
|
|
@@ -757,6 +722,8 @@ var Env = /*#__PURE__*/ (function () {
|
|
|
757
722
|
if (this.id === 0)
|
|
758
723
|
return;
|
|
759
724
|
this.deleteMe();
|
|
725
|
+
this.finalizing_reflist.dispose();
|
|
726
|
+
this.reflist.dispose();
|
|
760
727
|
this.id = 0;
|
|
761
728
|
};
|
|
762
729
|
Env.prototype.initObjectBinding = function (value) {
|
|
@@ -778,7 +745,7 @@ var Env = /*#__PURE__*/ (function () {
|
|
|
778
745
|
if (this.instanceData) {
|
|
779
746
|
this.instanceData.dispose();
|
|
780
747
|
}
|
|
781
|
-
this.instanceData =
|
|
748
|
+
this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
|
|
782
749
|
};
|
|
783
750
|
Env.prototype.getInstanceData = function () {
|
|
784
751
|
return this.instanceData ? this.instanceData.data() : 0;
|
|
@@ -1041,69 +1008,82 @@ var Persistent = /*#__PURE__*/ (function () {
|
|
|
1041
1008
|
return Persistent;
|
|
1042
1009
|
}());
|
|
1043
1010
|
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1011
|
+
var ReferenceOwnership;
|
|
1012
|
+
(function (ReferenceOwnership) {
|
|
1013
|
+
ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
|
|
1014
|
+
ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
|
|
1015
|
+
})(ReferenceOwnership || (ReferenceOwnership = {}));
|
|
1048
1016
|
function canBeHeldWeakly(value) {
|
|
1049
1017
|
return value.isObject() || value.isFunction() || value.isSymbol();
|
|
1050
1018
|
}
|
|
1051
1019
|
var Reference = /*#__PURE__*/ (function (_super) {
|
|
1052
1020
|
__extends(Reference, _super);
|
|
1053
|
-
function Reference(envObject, initialRefcount, ownership
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1021
|
+
function Reference(envObject, handle_id, initialRefcount, ownership) {
|
|
1022
|
+
var _this = _super.call(this) || this;
|
|
1023
|
+
_this.envObject = envObject;
|
|
1024
|
+
_this._refcount = initialRefcount;
|
|
1025
|
+
_this._ownership = ownership;
|
|
1026
|
+
var handle = envObject.ctx.handleStore.get(handle_id);
|
|
1027
|
+
_this.canBeWeak = canBeHeldWeakly(handle);
|
|
1028
|
+
_this.persistent = new Persistent(handle.value);
|
|
1058
1029
|
_this.id = 0;
|
|
1030
|
+
if (initialRefcount === 0) {
|
|
1031
|
+
_this._setWeak();
|
|
1032
|
+
}
|
|
1059
1033
|
return _this;
|
|
1060
1034
|
}
|
|
1061
|
-
Reference.
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
var ref = new Reference(envObject, initialRefcount, ownership
|
|
1035
|
+
Reference.weakCallback = function (ref) {
|
|
1036
|
+
ref.persistent.reset();
|
|
1037
|
+
ref.invokeFinalizerFromGC();
|
|
1038
|
+
};
|
|
1039
|
+
Reference.create = function (envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
|
|
1040
|
+
var ref = new Reference(envObject, handle_id, initialRefcount, ownership);
|
|
1067
1041
|
envObject.ctx.refStore.add(ref);
|
|
1068
|
-
ref.
|
|
1069
|
-
ref.persistent = new Persistent(handle.value);
|
|
1070
|
-
if (initialRefcount === 0) {
|
|
1071
|
-
ref._setWeak();
|
|
1072
|
-
}
|
|
1042
|
+
ref.link(envObject.reflist);
|
|
1073
1043
|
return ref;
|
|
1074
1044
|
};
|
|
1075
1045
|
Reference.prototype.ref = function () {
|
|
1076
1046
|
if (this.persistent.isEmpty()) {
|
|
1077
1047
|
return 0;
|
|
1078
1048
|
}
|
|
1079
|
-
|
|
1080
|
-
if (count === 1 && this.canBeWeak) {
|
|
1049
|
+
if (++this._refcount === 1 && this.canBeWeak) {
|
|
1081
1050
|
this.persistent.clearWeak();
|
|
1082
1051
|
}
|
|
1083
|
-
return
|
|
1052
|
+
return this._refcount;
|
|
1084
1053
|
};
|
|
1085
1054
|
Reference.prototype.unref = function () {
|
|
1086
|
-
if (this.persistent.isEmpty()) {
|
|
1055
|
+
if (this.persistent.isEmpty() || this._refcount === 0) {
|
|
1087
1056
|
return 0;
|
|
1088
1057
|
}
|
|
1089
|
-
|
|
1090
|
-
var refcount = _super.prototype.unref.call(this);
|
|
1091
|
-
if (oldRefcount === 1 && refcount === 0) {
|
|
1058
|
+
if (--this._refcount === 0) {
|
|
1092
1059
|
this._setWeak();
|
|
1093
1060
|
}
|
|
1094
|
-
return
|
|
1061
|
+
return this._refcount;
|
|
1095
1062
|
};
|
|
1096
|
-
Reference.prototype.get = function () {
|
|
1063
|
+
Reference.prototype.get = function (envObject) {
|
|
1064
|
+
if (envObject === void 0) { envObject = this.envObject; }
|
|
1097
1065
|
if (this.persistent.isEmpty()) {
|
|
1098
1066
|
return 0;
|
|
1099
1067
|
}
|
|
1100
1068
|
var obj = this.persistent.deref();
|
|
1101
|
-
var handle =
|
|
1069
|
+
var handle = envObject.ensureHandle(obj);
|
|
1102
1070
|
return handle.id;
|
|
1103
1071
|
};
|
|
1072
|
+
/** @virtual */
|
|
1073
|
+
Reference.prototype.resetFinalizer = function () { };
|
|
1074
|
+
/** @virtual */
|
|
1075
|
+
Reference.prototype.data = function () { return 0; };
|
|
1076
|
+
Reference.prototype.refcount = function () { return this._refcount; };
|
|
1077
|
+
Reference.prototype.ownership = function () { return this._ownership; };
|
|
1078
|
+
/** @virtual */
|
|
1079
|
+
Reference.prototype.callUserFinalizer = function () { };
|
|
1080
|
+
/** @virtual */
|
|
1081
|
+
Reference.prototype.invokeFinalizerFromGC = function () {
|
|
1082
|
+
this.finalize();
|
|
1083
|
+
};
|
|
1104
1084
|
Reference.prototype._setWeak = function () {
|
|
1105
1085
|
if (this.canBeWeak) {
|
|
1106
|
-
this.persistent.setWeak(this, weakCallback);
|
|
1086
|
+
this.persistent.setWeak(this, Reference.weakCallback);
|
|
1107
1087
|
}
|
|
1108
1088
|
else {
|
|
1109
1089
|
this.persistent.reset();
|
|
@@ -1111,18 +1091,78 @@ var Reference = /*#__PURE__*/ (function (_super) {
|
|
|
1111
1091
|
};
|
|
1112
1092
|
Reference.prototype.finalize = function () {
|
|
1113
1093
|
this.persistent.reset();
|
|
1114
|
-
|
|
1094
|
+
var deleteMe = this._ownership === ReferenceOwnership.kRuntime;
|
|
1095
|
+
this.unlink();
|
|
1096
|
+
this.callUserFinalizer();
|
|
1097
|
+
if (deleteMe) {
|
|
1098
|
+
this.dispose();
|
|
1099
|
+
}
|
|
1115
1100
|
};
|
|
1116
1101
|
Reference.prototype.dispose = function () {
|
|
1117
1102
|
if (this.id === 0)
|
|
1118
1103
|
return;
|
|
1104
|
+
this.unlink();
|
|
1119
1105
|
this.persistent.reset();
|
|
1120
1106
|
this.envObject.ctx.refStore.remove(this.id);
|
|
1121
1107
|
_super.prototype.dispose.call(this);
|
|
1108
|
+
this.envObject = undefined;
|
|
1122
1109
|
this.id = 0;
|
|
1123
1110
|
};
|
|
1124
1111
|
return Reference;
|
|
1125
|
-
}(
|
|
1112
|
+
}(RefTracker));
|
|
1113
|
+
var ReferenceWithData = /*#__PURE__*/ (function (_super) {
|
|
1114
|
+
__extends(ReferenceWithData, _super);
|
|
1115
|
+
function ReferenceWithData(envObject, value, initialRefcount, ownership, _data) {
|
|
1116
|
+
var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
|
|
1117
|
+
_this._data = _data;
|
|
1118
|
+
return _this;
|
|
1119
|
+
}
|
|
1120
|
+
ReferenceWithData.create = function (envObject, value, initialRefcount, ownership, data) {
|
|
1121
|
+
var reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
|
|
1122
|
+
envObject.ctx.refStore.add(reference);
|
|
1123
|
+
reference.link(envObject.reflist);
|
|
1124
|
+
return reference;
|
|
1125
|
+
};
|
|
1126
|
+
ReferenceWithData.prototype.data = function () {
|
|
1127
|
+
return this._data;
|
|
1128
|
+
};
|
|
1129
|
+
return ReferenceWithData;
|
|
1130
|
+
}(Reference));
|
|
1131
|
+
var ReferenceWithFinalizer = /*#__PURE__*/ (function (_super) {
|
|
1132
|
+
__extends(ReferenceWithFinalizer, _super);
|
|
1133
|
+
function ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1134
|
+
var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
|
|
1135
|
+
_this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
1136
|
+
return _this;
|
|
1137
|
+
}
|
|
1138
|
+
ReferenceWithFinalizer.create = function (envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1139
|
+
var reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
|
|
1140
|
+
envObject.ctx.refStore.add(reference);
|
|
1141
|
+
reference.link(envObject.finalizing_reflist);
|
|
1142
|
+
return reference;
|
|
1143
|
+
};
|
|
1144
|
+
ReferenceWithFinalizer.prototype.resetFinalizer = function () {
|
|
1145
|
+
this._finalizer.resetFinalizer();
|
|
1146
|
+
};
|
|
1147
|
+
ReferenceWithFinalizer.prototype.data = function () {
|
|
1148
|
+
return this._finalizer.data();
|
|
1149
|
+
};
|
|
1150
|
+
ReferenceWithFinalizer.prototype.callUserFinalizer = function () {
|
|
1151
|
+
this._finalizer.callFinalizer();
|
|
1152
|
+
};
|
|
1153
|
+
ReferenceWithFinalizer.prototype.invokeFinalizerFromGC = function () {
|
|
1154
|
+
this._finalizer.envObject.invokeFinalizerFromGC(this);
|
|
1155
|
+
};
|
|
1156
|
+
ReferenceWithFinalizer.prototype.dispose = function () {
|
|
1157
|
+
if (!this._finalizer)
|
|
1158
|
+
return;
|
|
1159
|
+
this._finalizer.envObject.dequeueFinalizer(this);
|
|
1160
|
+
this._finalizer.dispose();
|
|
1161
|
+
_super.prototype.dispose.call(this);
|
|
1162
|
+
this._finalizer = undefined;
|
|
1163
|
+
};
|
|
1164
|
+
return ReferenceWithFinalizer;
|
|
1165
|
+
}(Reference));
|
|
1126
1166
|
|
|
1127
1167
|
var Deferred = /*#__PURE__*/ (function () {
|
|
1128
1168
|
function Deferred(ctx, value) {
|
|
@@ -1279,6 +1319,7 @@ var Context = /*#__PURE__*/ (function () {
|
|
|
1279
1319
|
var _this = this;
|
|
1280
1320
|
this._isStopping = false;
|
|
1281
1321
|
this._canCallIntoJs = true;
|
|
1322
|
+
this._suppressDestroy = false;
|
|
1282
1323
|
this.envStore = new Store();
|
|
1283
1324
|
this.scopeStore = new ScopeStore();
|
|
1284
1325
|
this.refStore = new Store();
|
|
@@ -1300,10 +1341,23 @@ var Context = /*#__PURE__*/ (function () {
|
|
|
1300
1341
|
if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
|
|
1301
1342
|
this.refCounter = new NodejsWaitingRequestCounter();
|
|
1302
1343
|
process.once('beforeExit', function () {
|
|
1303
|
-
_this.
|
|
1344
|
+
if (!_this._suppressDestroy) {
|
|
1345
|
+
_this.destroy();
|
|
1346
|
+
}
|
|
1304
1347
|
});
|
|
1305
1348
|
}
|
|
1306
1349
|
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Suppress the destroy on `beforeExit` event in Node.js.
|
|
1352
|
+
* Call this method if you want to keep the context and
|
|
1353
|
+
* all associated {@link Env | Env} alive,
|
|
1354
|
+
* this also means that cleanup hooks will not be called.
|
|
1355
|
+
* After call this method, you should call
|
|
1356
|
+
* {@link Context.destroy | `Context.prototype.destroy`} method manually.
|
|
1357
|
+
*/
|
|
1358
|
+
Context.prototype.suppressDestroy = function () {
|
|
1359
|
+
this._suppressDestroy = true;
|
|
1360
|
+
};
|
|
1307
1361
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1308
1362
|
Context.prototype.getRuntimeVersions = function () {
|
|
1309
1363
|
return {
|
|
@@ -1319,11 +1373,17 @@ var Context = /*#__PURE__*/ (function () {
|
|
|
1319
1373
|
Context.prototype.createNotSupportBufferError = function (api, message) {
|
|
1320
1374
|
return new NotSupportBufferError(api, message);
|
|
1321
1375
|
};
|
|
1322
|
-
Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership
|
|
1376
|
+
Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership) {
|
|
1377
|
+
return Reference.create(envObject, handle_id, initialRefcount, ownership);
|
|
1378
|
+
};
|
|
1379
|
+
Context.prototype.createReferenceWithData = function (envObject, handle_id, initialRefcount, ownership, data) {
|
|
1380
|
+
return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
|
|
1381
|
+
};
|
|
1382
|
+
Context.prototype.createReferenceWithFinalizer = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1323
1383
|
if (finalize_callback === void 0) { finalize_callback = 0; }
|
|
1324
1384
|
if (finalize_data === void 0) { finalize_data = 0; }
|
|
1325
1385
|
if (finalize_hint === void 0) { finalize_hint = 0; }
|
|
1326
|
-
return
|
|
1386
|
+
return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
|
|
1327
1387
|
};
|
|
1328
1388
|
Context.prototype.createDeferred = function (value) {
|
|
1329
1389
|
return Deferred.create(this, value);
|
|
@@ -1384,6 +1444,10 @@ var Context = /*#__PURE__*/ (function () {
|
|
|
1384
1444
|
Context.prototype.canCallIntoJs = function () {
|
|
1385
1445
|
return this._canCallIntoJs && !this._isStopping;
|
|
1386
1446
|
};
|
|
1447
|
+
/**
|
|
1448
|
+
* Destroy the context and call cleanup hooks.
|
|
1449
|
+
* Associated {@link Env | Env} will be destroyed.
|
|
1450
|
+
*/
|
|
1387
1451
|
Context.prototype.destroy = function () {
|
|
1388
1452
|
this.setStopping(true);
|
|
1389
1453
|
this.setCanCallIntoJs(false);
|
|
@@ -1402,4 +1466,4 @@ function getDefaultContext() {
|
|
|
1402
1466
|
return defaultContext;
|
|
1403
1467
|
}
|
|
1404
1468
|
|
|
1405
|
-
export { CallbackInfo, CallbackInfoStack, ConstHandle, Context, Deferred, EmnapiError, Env, 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,
|
|
1469
|
+
export { CallbackInfo, CallbackInfoStack, ConstHandle, Context, Deferred, EmnapiError, Env, 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, isReferenceType, version };
|