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