@emnapi/runtime 1.2.0 → 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 +159 -109
- package/dist/emnapi.cjs.min.d.ts +73 -37
- package/dist/emnapi.cjs.min.js +1 -1
- package/dist/emnapi.d.mts +73 -37
- package/dist/emnapi.d.ts +73 -37
- package/dist/emnapi.esm-bundler.js +182 -119
- package/dist/emnapi.iife.d.ts +73 -32
- package/dist/emnapi.iife.js +184 -120
- package/dist/emnapi.js +184 -120
- package/dist/emnapi.min.d.mts +73 -37
- package/dist/emnapi.min.js +1 -1
- package/dist/emnapi.min.mjs +1 -1
- package/dist/emnapi.mjs +158 -109
- package/package.json +1 -1
package/dist/emnapi.iife.js
CHANGED
|
@@ -84,7 +84,7 @@ var emnapi = (function (exports) {
|
|
|
84
84
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
85
85
|
PERFORMANCE OF THIS SOFTWARE.
|
|
86
86
|
***************************************************************************** */
|
|
87
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
87
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
88
88
|
|
|
89
89
|
var extendStatics = function(d, b) {
|
|
90
90
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -246,7 +246,7 @@ var emnapi = (function (exports) {
|
|
|
246
246
|
catch (_) { }
|
|
247
247
|
return undefined;
|
|
248
248
|
})();
|
|
249
|
-
var version = "1.
|
|
249
|
+
var version = "1.3.0";
|
|
250
250
|
var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
|
|
251
251
|
var NODE_API_SUPPORTED_VERSION_MAX = 9 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
|
|
252
252
|
var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
|
|
@@ -499,6 +499,8 @@ var emnapi = (function (exports) {
|
|
|
499
499
|
this._prev = null;
|
|
500
500
|
}
|
|
501
501
|
/** @virtual */
|
|
502
|
+
RefTracker.prototype.dispose = function () { };
|
|
503
|
+
/** @virtual */
|
|
502
504
|
RefTracker.prototype.finalize = function () { };
|
|
503
505
|
RefTracker.prototype.link = function (list) {
|
|
504
506
|
this._prev = list;
|
|
@@ -535,17 +537,37 @@ var emnapi = (function (exports) {
|
|
|
535
537
|
this._finalizeCallback = _finalizeCallback;
|
|
536
538
|
this._finalizeData = _finalizeData;
|
|
537
539
|
this._finalizeHint = _finalizeHint;
|
|
540
|
+
this._makeDynCall_vppp = envObject.makeDynCall_vppp;
|
|
538
541
|
}
|
|
539
542
|
Finalizer.prototype.callback = function () { return this._finalizeCallback; };
|
|
540
543
|
Finalizer.prototype.data = function () { return this._finalizeData; };
|
|
541
544
|
Finalizer.prototype.hint = function () { return this._finalizeHint; };
|
|
545
|
+
Finalizer.prototype.resetEnv = function () {
|
|
546
|
+
this.envObject = undefined;
|
|
547
|
+
};
|
|
542
548
|
Finalizer.prototype.resetFinalizer = function () {
|
|
543
549
|
this._finalizeCallback = 0;
|
|
544
550
|
this._finalizeData = 0;
|
|
545
551
|
this._finalizeHint = 0;
|
|
546
552
|
};
|
|
553
|
+
Finalizer.prototype.callFinalizer = function () {
|
|
554
|
+
var finalize_callback = this._finalizeCallback;
|
|
555
|
+
var finalize_data = this._finalizeData;
|
|
556
|
+
var finalize_hint = this._finalizeHint;
|
|
557
|
+
this.resetFinalizer();
|
|
558
|
+
if (!finalize_callback)
|
|
559
|
+
return;
|
|
560
|
+
var fini = Number(finalize_callback);
|
|
561
|
+
if (!this.envObject) {
|
|
562
|
+
this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
|
|
566
|
+
}
|
|
567
|
+
};
|
|
547
568
|
Finalizer.prototype.dispose = function () {
|
|
548
569
|
this.envObject = undefined;
|
|
570
|
+
this._makeDynCall_vppp = undefined;
|
|
549
571
|
};
|
|
550
572
|
return Finalizer;
|
|
551
573
|
}());
|
|
@@ -553,91 +575,45 @@ var emnapi = (function (exports) {
|
|
|
553
575
|
var TrackedFinalizer = /*#__PURE__*/ (function (_super) {
|
|
554
576
|
__extends(TrackedFinalizer, _super);
|
|
555
577
|
function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
556
|
-
var _this = _super.call(this
|
|
557
|
-
_this.
|
|
558
|
-
_this._prev = null;
|
|
559
|
-
_this.link(!finalize_callback ? envObject.reflist : envObject.finalizing_reflist);
|
|
578
|
+
var _this = _super.call(this) || this;
|
|
579
|
+
_this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
560
580
|
return _this;
|
|
561
581
|
}
|
|
562
|
-
TrackedFinalizer.finalizeAll = function (list) {
|
|
563
|
-
RefTracker.finalizeAll(list);
|
|
564
|
-
};
|
|
565
|
-
TrackedFinalizer.prototype.link = function (list) {
|
|
566
|
-
RefTracker.prototype.link.call(this, list);
|
|
567
|
-
};
|
|
568
|
-
TrackedFinalizer.prototype.unlink = function () {
|
|
569
|
-
RefTracker.prototype.unlink.call(this);
|
|
570
|
-
};
|
|
571
582
|
TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) {
|
|
572
|
-
|
|
583
|
+
var finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
584
|
+
finalizer.link(envObject.finalizing_reflist);
|
|
585
|
+
return finalizer;
|
|
586
|
+
};
|
|
587
|
+
TrackedFinalizer.prototype.data = function () {
|
|
588
|
+
return this._finalizer.data();
|
|
573
589
|
};
|
|
574
590
|
TrackedFinalizer.prototype.dispose = function () {
|
|
591
|
+
if (!this._finalizer)
|
|
592
|
+
return;
|
|
575
593
|
this.unlink();
|
|
576
|
-
this.envObject.dequeueFinalizer(this);
|
|
594
|
+
this._finalizer.envObject.dequeueFinalizer(this);
|
|
595
|
+
this._finalizer.dispose();
|
|
596
|
+
this._finalizer = undefined;
|
|
577
597
|
_super.prototype.dispose.call(this);
|
|
578
598
|
};
|
|
579
599
|
TrackedFinalizer.prototype.finalize = function () {
|
|
580
|
-
this.finalizeCore(true);
|
|
581
|
-
};
|
|
582
|
-
TrackedFinalizer.prototype.finalizeCore = function (deleteMe) {
|
|
583
|
-
var finalize_callback = this._finalizeCallback;
|
|
584
|
-
var finalize_data = this._finalizeData;
|
|
585
|
-
var finalize_hint = this._finalizeHint;
|
|
586
|
-
this.resetFinalizer();
|
|
587
600
|
this.unlink();
|
|
588
601
|
var error;
|
|
589
602
|
var caught = false;
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
try {
|
|
593
|
-
this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
|
|
594
|
-
}
|
|
595
|
-
catch (err) {
|
|
596
|
-
caught = true;
|
|
597
|
-
error = err;
|
|
598
|
-
}
|
|
603
|
+
try {
|
|
604
|
+
this._finalizer.callFinalizer();
|
|
599
605
|
}
|
|
600
|
-
|
|
601
|
-
|
|
606
|
+
catch (err) {
|
|
607
|
+
caught = true;
|
|
608
|
+
error = err;
|
|
602
609
|
}
|
|
610
|
+
this.dispose();
|
|
603
611
|
if (caught) {
|
|
604
612
|
throw error;
|
|
605
613
|
}
|
|
606
614
|
};
|
|
607
615
|
return TrackedFinalizer;
|
|
608
|
-
}(
|
|
609
|
-
|
|
610
|
-
var RefBase = /*#__PURE__*/ (function (_super) {
|
|
611
|
-
__extends(RefBase, _super);
|
|
612
|
-
function RefBase(envObject, initial_refcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
613
|
-
var _this = _super.call(this, envObject, finalize_callback, finalize_data, finalize_hint) || this;
|
|
614
|
-
_this._refcount = initial_refcount;
|
|
615
|
-
_this._ownership = ownership;
|
|
616
|
-
return _this;
|
|
617
|
-
}
|
|
618
|
-
RefBase.prototype.data = function () {
|
|
619
|
-
return this._finalizeData;
|
|
620
|
-
};
|
|
621
|
-
RefBase.prototype.ref = function () {
|
|
622
|
-
return ++this._refcount;
|
|
623
|
-
};
|
|
624
|
-
RefBase.prototype.unref = function () {
|
|
625
|
-
if (this._refcount === 0) {
|
|
626
|
-
return 0;
|
|
627
|
-
}
|
|
628
|
-
return --this._refcount;
|
|
629
|
-
};
|
|
630
|
-
RefBase.prototype.refCount = function () {
|
|
631
|
-
return this._refcount;
|
|
632
|
-
};
|
|
633
|
-
RefBase.prototype.ownership = function () {
|
|
634
|
-
return this._ownership;
|
|
635
|
-
};
|
|
636
|
-
RefBase.prototype.finalize = function () {
|
|
637
|
-
this.finalizeCore(this._ownership === 0 /* Ownership.kRuntime */);
|
|
638
|
-
};
|
|
639
|
-
return RefBase;
|
|
640
|
-
}(TrackedFinalizer));
|
|
616
|
+
}(RefTracker));
|
|
641
617
|
|
|
642
618
|
function throwNodeApiVersionError(moduleName, moduleApiVersion) {
|
|
643
619
|
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.");
|
|
@@ -733,18 +709,6 @@ var emnapi = (function (exports) {
|
|
|
733
709
|
}
|
|
734
710
|
return r;
|
|
735
711
|
};
|
|
736
|
-
/** @virtual */
|
|
737
|
-
Env.prototype.callFinalizer = function (cb, data, hint) {
|
|
738
|
-
var f = this.makeDynCall_vppp(cb);
|
|
739
|
-
var env = this.id;
|
|
740
|
-
var scope = this.ctx.openScope(this);
|
|
741
|
-
try {
|
|
742
|
-
this.callIntoModule(function () { f(env, data, hint); });
|
|
743
|
-
}
|
|
744
|
-
finally {
|
|
745
|
-
this.ctx.closeScope(this, scope);
|
|
746
|
-
}
|
|
747
|
-
};
|
|
748
712
|
Env.prototype.invokeFinalizerFromGC = function (finalizer) {
|
|
749
713
|
if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
|
|
750
714
|
this.enqueueFinalizer(finalizer);
|
|
@@ -785,8 +749,8 @@ var emnapi = (function (exports) {
|
|
|
785
749
|
};
|
|
786
750
|
/** @virtual */
|
|
787
751
|
Env.prototype.deleteMe = function () {
|
|
788
|
-
|
|
789
|
-
|
|
752
|
+
RefTracker.finalizeAll(this.finalizing_reflist);
|
|
753
|
+
RefTracker.finalizeAll(this.reflist);
|
|
790
754
|
this.tryCatch.extractException();
|
|
791
755
|
this.ctx.envStore.remove(this.id);
|
|
792
756
|
};
|
|
@@ -794,6 +758,8 @@ var emnapi = (function (exports) {
|
|
|
794
758
|
if (this.id === 0)
|
|
795
759
|
return;
|
|
796
760
|
this.deleteMe();
|
|
761
|
+
this.finalizing_reflist.dispose();
|
|
762
|
+
this.reflist.dispose();
|
|
797
763
|
this.id = 0;
|
|
798
764
|
};
|
|
799
765
|
Env.prototype.initObjectBinding = function (value) {
|
|
@@ -815,7 +781,7 @@ var emnapi = (function (exports) {
|
|
|
815
781
|
if (this.instanceData) {
|
|
816
782
|
this.instanceData.dispose();
|
|
817
783
|
}
|
|
818
|
-
this.instanceData =
|
|
784
|
+
this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
|
|
819
785
|
};
|
|
820
786
|
Env.prototype.getInstanceData = function () {
|
|
821
787
|
return this.instanceData ? this.instanceData.data() : 0;
|
|
@@ -1078,69 +1044,82 @@ var emnapi = (function (exports) {
|
|
|
1078
1044
|
return Persistent;
|
|
1079
1045
|
}());
|
|
1080
1046
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1047
|
+
exports.ReferenceOwnership = void 0;
|
|
1048
|
+
(function (ReferenceOwnership) {
|
|
1049
|
+
ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
|
|
1050
|
+
ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
|
|
1051
|
+
})(exports.ReferenceOwnership || (exports.ReferenceOwnership = {}));
|
|
1085
1052
|
function canBeHeldWeakly(value) {
|
|
1086
1053
|
return value.isObject() || value.isFunction() || value.isSymbol();
|
|
1087
1054
|
}
|
|
1088
1055
|
var Reference = /*#__PURE__*/ (function (_super) {
|
|
1089
1056
|
__extends(Reference, _super);
|
|
1090
|
-
function Reference(envObject, initialRefcount, ownership
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1057
|
+
function Reference(envObject, handle_id, initialRefcount, ownership) {
|
|
1058
|
+
var _this = _super.call(this) || this;
|
|
1059
|
+
_this.envObject = envObject;
|
|
1060
|
+
_this._refcount = initialRefcount;
|
|
1061
|
+
_this._ownership = ownership;
|
|
1062
|
+
var handle = envObject.ctx.handleStore.get(handle_id);
|
|
1063
|
+
_this.canBeWeak = canBeHeldWeakly(handle);
|
|
1064
|
+
_this.persistent = new Persistent(handle.value);
|
|
1095
1065
|
_this.id = 0;
|
|
1066
|
+
if (initialRefcount === 0) {
|
|
1067
|
+
_this._setWeak();
|
|
1068
|
+
}
|
|
1096
1069
|
return _this;
|
|
1097
1070
|
}
|
|
1098
|
-
Reference.
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
var ref = new Reference(envObject, initialRefcount, ownership
|
|
1071
|
+
Reference.weakCallback = function (ref) {
|
|
1072
|
+
ref.persistent.reset();
|
|
1073
|
+
ref.invokeFinalizerFromGC();
|
|
1074
|
+
};
|
|
1075
|
+
Reference.create = function (envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
|
|
1076
|
+
var ref = new Reference(envObject, handle_id, initialRefcount, ownership);
|
|
1104
1077
|
envObject.ctx.refStore.add(ref);
|
|
1105
|
-
ref.
|
|
1106
|
-
ref.persistent = new Persistent(handle.value);
|
|
1107
|
-
if (initialRefcount === 0) {
|
|
1108
|
-
ref._setWeak();
|
|
1109
|
-
}
|
|
1078
|
+
ref.link(envObject.reflist);
|
|
1110
1079
|
return ref;
|
|
1111
1080
|
};
|
|
1112
1081
|
Reference.prototype.ref = function () {
|
|
1113
1082
|
if (this.persistent.isEmpty()) {
|
|
1114
1083
|
return 0;
|
|
1115
1084
|
}
|
|
1116
|
-
|
|
1117
|
-
if (count === 1 && this.canBeWeak) {
|
|
1085
|
+
if (++this._refcount === 1 && this.canBeWeak) {
|
|
1118
1086
|
this.persistent.clearWeak();
|
|
1119
1087
|
}
|
|
1120
|
-
return
|
|
1088
|
+
return this._refcount;
|
|
1121
1089
|
};
|
|
1122
1090
|
Reference.prototype.unref = function () {
|
|
1123
|
-
if (this.persistent.isEmpty()) {
|
|
1091
|
+
if (this.persistent.isEmpty() || this._refcount === 0) {
|
|
1124
1092
|
return 0;
|
|
1125
1093
|
}
|
|
1126
|
-
|
|
1127
|
-
var refcount = _super.prototype.unref.call(this);
|
|
1128
|
-
if (oldRefcount === 1 && refcount === 0) {
|
|
1094
|
+
if (--this._refcount === 0) {
|
|
1129
1095
|
this._setWeak();
|
|
1130
1096
|
}
|
|
1131
|
-
return
|
|
1097
|
+
return this._refcount;
|
|
1132
1098
|
};
|
|
1133
|
-
Reference.prototype.get = function () {
|
|
1099
|
+
Reference.prototype.get = function (envObject) {
|
|
1100
|
+
if (envObject === void 0) { envObject = this.envObject; }
|
|
1134
1101
|
if (this.persistent.isEmpty()) {
|
|
1135
1102
|
return 0;
|
|
1136
1103
|
}
|
|
1137
1104
|
var obj = this.persistent.deref();
|
|
1138
|
-
var handle =
|
|
1105
|
+
var handle = envObject.ensureHandle(obj);
|
|
1139
1106
|
return handle.id;
|
|
1140
1107
|
};
|
|
1108
|
+
/** @virtual */
|
|
1109
|
+
Reference.prototype.resetFinalizer = function () { };
|
|
1110
|
+
/** @virtual */
|
|
1111
|
+
Reference.prototype.data = function () { return 0; };
|
|
1112
|
+
Reference.prototype.refcount = function () { return this._refcount; };
|
|
1113
|
+
Reference.prototype.ownership = function () { return this._ownership; };
|
|
1114
|
+
/** @virtual */
|
|
1115
|
+
Reference.prototype.callUserFinalizer = function () { };
|
|
1116
|
+
/** @virtual */
|
|
1117
|
+
Reference.prototype.invokeFinalizerFromGC = function () {
|
|
1118
|
+
this.finalize();
|
|
1119
|
+
};
|
|
1141
1120
|
Reference.prototype._setWeak = function () {
|
|
1142
1121
|
if (this.canBeWeak) {
|
|
1143
|
-
this.persistent.setWeak(this, weakCallback);
|
|
1122
|
+
this.persistent.setWeak(this, Reference.weakCallback);
|
|
1144
1123
|
}
|
|
1145
1124
|
else {
|
|
1146
1125
|
this.persistent.reset();
|
|
@@ -1148,18 +1127,78 @@ var emnapi = (function (exports) {
|
|
|
1148
1127
|
};
|
|
1149
1128
|
Reference.prototype.finalize = function () {
|
|
1150
1129
|
this.persistent.reset();
|
|
1151
|
-
|
|
1130
|
+
var deleteMe = this._ownership === exports.ReferenceOwnership.kRuntime;
|
|
1131
|
+
this.unlink();
|
|
1132
|
+
this.callUserFinalizer();
|
|
1133
|
+
if (deleteMe) {
|
|
1134
|
+
this.dispose();
|
|
1135
|
+
}
|
|
1152
1136
|
};
|
|
1153
1137
|
Reference.prototype.dispose = function () {
|
|
1154
1138
|
if (this.id === 0)
|
|
1155
1139
|
return;
|
|
1140
|
+
this.unlink();
|
|
1156
1141
|
this.persistent.reset();
|
|
1157
1142
|
this.envObject.ctx.refStore.remove(this.id);
|
|
1158
1143
|
_super.prototype.dispose.call(this);
|
|
1144
|
+
this.envObject = undefined;
|
|
1159
1145
|
this.id = 0;
|
|
1160
1146
|
};
|
|
1161
1147
|
return Reference;
|
|
1162
|
-
}(
|
|
1148
|
+
}(RefTracker));
|
|
1149
|
+
var ReferenceWithData = /*#__PURE__*/ (function (_super) {
|
|
1150
|
+
__extends(ReferenceWithData, _super);
|
|
1151
|
+
function ReferenceWithData(envObject, value, initialRefcount, ownership, _data) {
|
|
1152
|
+
var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
|
|
1153
|
+
_this._data = _data;
|
|
1154
|
+
return _this;
|
|
1155
|
+
}
|
|
1156
|
+
ReferenceWithData.create = function (envObject, value, initialRefcount, ownership, data) {
|
|
1157
|
+
var reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
|
|
1158
|
+
envObject.ctx.refStore.add(reference);
|
|
1159
|
+
reference.link(envObject.reflist);
|
|
1160
|
+
return reference;
|
|
1161
|
+
};
|
|
1162
|
+
ReferenceWithData.prototype.data = function () {
|
|
1163
|
+
return this._data;
|
|
1164
|
+
};
|
|
1165
|
+
return ReferenceWithData;
|
|
1166
|
+
}(Reference));
|
|
1167
|
+
var ReferenceWithFinalizer = /*#__PURE__*/ (function (_super) {
|
|
1168
|
+
__extends(ReferenceWithFinalizer, _super);
|
|
1169
|
+
function ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1170
|
+
var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
|
|
1171
|
+
_this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
|
|
1172
|
+
return _this;
|
|
1173
|
+
}
|
|
1174
|
+
ReferenceWithFinalizer.create = function (envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1175
|
+
var reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
|
|
1176
|
+
envObject.ctx.refStore.add(reference);
|
|
1177
|
+
reference.link(envObject.finalizing_reflist);
|
|
1178
|
+
return reference;
|
|
1179
|
+
};
|
|
1180
|
+
ReferenceWithFinalizer.prototype.resetFinalizer = function () {
|
|
1181
|
+
this._finalizer.resetFinalizer();
|
|
1182
|
+
};
|
|
1183
|
+
ReferenceWithFinalizer.prototype.data = function () {
|
|
1184
|
+
return this._finalizer.data();
|
|
1185
|
+
};
|
|
1186
|
+
ReferenceWithFinalizer.prototype.callUserFinalizer = function () {
|
|
1187
|
+
this._finalizer.callFinalizer();
|
|
1188
|
+
};
|
|
1189
|
+
ReferenceWithFinalizer.prototype.invokeFinalizerFromGC = function () {
|
|
1190
|
+
this._finalizer.envObject.invokeFinalizerFromGC(this);
|
|
1191
|
+
};
|
|
1192
|
+
ReferenceWithFinalizer.prototype.dispose = function () {
|
|
1193
|
+
if (!this._finalizer)
|
|
1194
|
+
return;
|
|
1195
|
+
this._finalizer.envObject.dequeueFinalizer(this);
|
|
1196
|
+
this._finalizer.dispose();
|
|
1197
|
+
_super.prototype.dispose.call(this);
|
|
1198
|
+
this._finalizer = undefined;
|
|
1199
|
+
};
|
|
1200
|
+
return ReferenceWithFinalizer;
|
|
1201
|
+
}(Reference));
|
|
1163
1202
|
|
|
1164
1203
|
var Deferred = /*#__PURE__*/ (function () {
|
|
1165
1204
|
function Deferred(ctx, value) {
|
|
@@ -1316,6 +1355,7 @@ var emnapi = (function (exports) {
|
|
|
1316
1355
|
var _this = this;
|
|
1317
1356
|
this._isStopping = false;
|
|
1318
1357
|
this._canCallIntoJs = true;
|
|
1358
|
+
this._suppressDestroy = false;
|
|
1319
1359
|
this.envStore = new Store();
|
|
1320
1360
|
this.scopeStore = new ScopeStore();
|
|
1321
1361
|
this.refStore = new Store();
|
|
@@ -1337,10 +1377,23 @@ var emnapi = (function (exports) {
|
|
|
1337
1377
|
if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
|
|
1338
1378
|
this.refCounter = new NodejsWaitingRequestCounter();
|
|
1339
1379
|
process.once('beforeExit', function () {
|
|
1340
|
-
_this.
|
|
1380
|
+
if (!_this._suppressDestroy) {
|
|
1381
|
+
_this.destroy();
|
|
1382
|
+
}
|
|
1341
1383
|
});
|
|
1342
1384
|
}
|
|
1343
1385
|
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Suppress the destroy on `beforeExit` event in Node.js.
|
|
1388
|
+
* Call this method if you want to keep the context and
|
|
1389
|
+
* all associated {@link Env | Env} alive,
|
|
1390
|
+
* this also means that cleanup hooks will not be called.
|
|
1391
|
+
* After call this method, you should call
|
|
1392
|
+
* {@link Context.destroy | `Context.prototype.destroy`} method manually.
|
|
1393
|
+
*/
|
|
1394
|
+
Context.prototype.suppressDestroy = function () {
|
|
1395
|
+
this._suppressDestroy = true;
|
|
1396
|
+
};
|
|
1344
1397
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1345
1398
|
Context.prototype.getRuntimeVersions = function () {
|
|
1346
1399
|
return {
|
|
@@ -1356,11 +1409,17 @@ var emnapi = (function (exports) {
|
|
|
1356
1409
|
Context.prototype.createNotSupportBufferError = function (api, message) {
|
|
1357
1410
|
return new NotSupportBufferError(api, message);
|
|
1358
1411
|
};
|
|
1359
|
-
Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership
|
|
1412
|
+
Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership) {
|
|
1413
|
+
return Reference.create(envObject, handle_id, initialRefcount, ownership);
|
|
1414
|
+
};
|
|
1415
|
+
Context.prototype.createReferenceWithData = function (envObject, handle_id, initialRefcount, ownership, data) {
|
|
1416
|
+
return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
|
|
1417
|
+
};
|
|
1418
|
+
Context.prototype.createReferenceWithFinalizer = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1360
1419
|
if (finalize_callback === void 0) { finalize_callback = 0; }
|
|
1361
1420
|
if (finalize_data === void 0) { finalize_data = 0; }
|
|
1362
1421
|
if (finalize_hint === void 0) { finalize_hint = 0; }
|
|
1363
|
-
return
|
|
1422
|
+
return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
|
|
1364
1423
|
};
|
|
1365
1424
|
Context.prototype.createDeferred = function (value) {
|
|
1366
1425
|
return Deferred.create(this, value);
|
|
@@ -1421,6 +1480,10 @@ var emnapi = (function (exports) {
|
|
|
1421
1480
|
Context.prototype.canCallIntoJs = function () {
|
|
1422
1481
|
return this._canCallIntoJs && !this._isStopping;
|
|
1423
1482
|
};
|
|
1483
|
+
/**
|
|
1484
|
+
* Destroy the context and call cleanup hooks.
|
|
1485
|
+
* Associated {@link Env | Env} will be destroyed.
|
|
1486
|
+
*/
|
|
1424
1487
|
Context.prototype.destroy = function () {
|
|
1425
1488
|
this.setStopping(true);
|
|
1426
1489
|
this.setCanCallIntoJs(false);
|
|
@@ -1458,9 +1521,10 @@ var emnapi = (function (exports) {
|
|
|
1458
1521
|
exports.NotSupportBufferError = NotSupportBufferError;
|
|
1459
1522
|
exports.NotSupportWeakRefError = NotSupportWeakRefError;
|
|
1460
1523
|
exports.Persistent = Persistent;
|
|
1461
|
-
exports.RefBase = RefBase;
|
|
1462
1524
|
exports.RefTracker = RefTracker;
|
|
1463
1525
|
exports.Reference = Reference;
|
|
1526
|
+
exports.ReferenceWithData = ReferenceWithData;
|
|
1527
|
+
exports.ReferenceWithFinalizer = ReferenceWithFinalizer;
|
|
1464
1528
|
exports.ScopeStore = ScopeStore;
|
|
1465
1529
|
exports.Store = Store;
|
|
1466
1530
|
exports.TrackedFinalizer = TrackedFinalizer;
|