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