@emnapi/runtime 0.38.3 → 0.39.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.
@@ -35,60 +35,6 @@ class CallbackInfoStack {
35
35
  }
36
36
  }
37
37
 
38
- class Store {
39
- constructor(capacity) {
40
- this._values = [undefined];
41
- this._values.length = capacity;
42
- this._size = 1;
43
- this._freeList = [];
44
- }
45
- add(value) {
46
- let id;
47
- if (this._freeList.length) {
48
- id = this._freeList.shift();
49
- }
50
- else {
51
- id = this._size;
52
- this._size++;
53
- const capacity = this._values.length;
54
- if (id >= capacity) {
55
- this._values.length = Math.ceil(capacity * 1.5);
56
- }
57
- }
58
- value.id = id;
59
- this._values[id] = value;
60
- }
61
- get(id) {
62
- return this._values[id];
63
- }
64
- has(id) {
65
- return this._values[id] !== undefined;
66
- }
67
- remove(id) {
68
- const value = this._values[id];
69
- if (value) {
70
- value.id = 0;
71
- this._values[id] = undefined;
72
- this._freeList.push(Number(id));
73
- }
74
- }
75
- dispose() {
76
- for (let i = 1; i < this._size; ++i) {
77
- const value = this._values[i];
78
- value === null || value === void 0 ? void 0 : value.dispose();
79
- }
80
- this._values = [undefined];
81
- this._size = 1;
82
- this._freeList = [];
83
- }
84
- }
85
-
86
- class EnvStore extends Store {
87
- constructor() {
88
- super(2);
89
- }
90
- }
91
-
92
38
  const supportNewFunction = (function () {
93
39
  let f;
94
40
  try {
@@ -121,22 +67,24 @@ const _global = (function () {
121
67
  }
122
68
  return g;
123
69
  })();
124
- const emptyException = new Error();
125
70
  class TryCatch {
126
71
  constructor() {
127
- this._exception = emptyException;
72
+ this._exception = undefined;
73
+ this._caught = false;
128
74
  }
129
75
  hasCaught() {
130
- return this._exception !== emptyException;
76
+ return this._caught;
131
77
  }
132
78
  exception() {
133
79
  return this._exception;
134
80
  }
135
81
  setError(err) {
82
+ this._caught = true;
136
83
  this._exception = err;
137
84
  }
138
85
  reset() {
139
- this._exception = emptyException;
86
+ this._caught = false;
87
+ this._exception = undefined;
140
88
  }
141
89
  extractException() {
142
90
  const e = this._exception;
@@ -221,77 +169,71 @@ const _Buffer = typeof Buffer === 'function'
221
169
  catch (_) { }
222
170
  return undefined;
223
171
  })();
172
+ const version = "0.39.0";
173
+ const NAPI_VERSION = 9;
174
+ const NAPI_VERSION_EXPERIMENTAL = 2147483647;
175
+ const NODE_API_DEFAULT_MODULE_API_VERSION = 8;
224
176
 
225
177
  class Handle {
226
178
  constructor(id, value) {
227
179
  this.id = id;
228
180
  this.value = value;
229
181
  }
230
- init(id, value) {
231
- this.id = id;
232
- this.value = value;
233
- }
234
182
  data(envObject) {
235
183
  return envObject.getObjectBinding(this.value).data;
236
184
  }
237
- isEmpty() {
238
- return this.id === 0;
239
- }
240
185
  isNumber() {
241
- return !this.isEmpty() && typeof this.value === 'number';
186
+ return typeof this.value === 'number';
242
187
  }
243
188
  isBigInt() {
244
- return !this.isEmpty() && typeof this.value === 'bigint';
189
+ return typeof this.value === 'bigint';
245
190
  }
246
191
  isString() {
247
- return !this.isEmpty() && typeof this.value === 'string';
192
+ return typeof this.value === 'string';
248
193
  }
249
194
  isFunction() {
250
- return !this.isEmpty() && typeof this.value === 'function';
195
+ return typeof this.value === 'function';
251
196
  }
252
197
  isExternal() {
253
- return !this.isEmpty() && (isReferenceType(this.value) && Object.getPrototypeOf(this.value) === null);
198
+ return (isReferenceType(this.value) && Object.getPrototypeOf(this.value) === null);
254
199
  }
255
200
  isObject() {
256
- return !this.isEmpty() && typeof this.value === 'object' && this.value !== null;
201
+ return typeof this.value === 'object' && this.value !== null;
257
202
  }
258
203
  isArray() {
259
- return !this.isEmpty() && Array.isArray(this.value);
204
+ return Array.isArray(this.value);
260
205
  }
261
206
  isArrayBuffer() {
262
- return !this.isEmpty() && (this.value instanceof ArrayBuffer);
207
+ return (this.value instanceof ArrayBuffer);
263
208
  }
264
209
  isTypedArray() {
265
- return !this.isEmpty() && (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
210
+ return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
266
211
  }
267
212
  isBuffer() {
268
- return !this.isEmpty() && typeof _Buffer === 'function' && _Buffer.isBuffer(this.value);
213
+ return typeof _Buffer === 'function' && _Buffer.isBuffer(this.value);
269
214
  }
270
215
  isDataView() {
271
- return !this.isEmpty() && (this.value instanceof DataView);
216
+ return (this.value instanceof DataView);
272
217
  }
273
218
  isDate() {
274
- return !this.isEmpty() && (this.value instanceof Date);
219
+ return (this.value instanceof Date);
275
220
  }
276
221
  isPromise() {
277
- return !this.isEmpty() && (this.value instanceof Promise);
222
+ return (this.value instanceof Promise);
278
223
  }
279
224
  isBoolean() {
280
- return !this.isEmpty() && typeof this.value === 'boolean';
225
+ return typeof this.value === 'boolean';
281
226
  }
282
227
  isUndefined() {
283
- return !this.isEmpty() && this.value === undefined;
228
+ return this.value === undefined;
284
229
  }
285
230
  isSymbol() {
286
- return !this.isEmpty() && typeof this.value === 'symbol';
231
+ return typeof this.value === 'symbol';
287
232
  }
288
233
  isNull() {
289
- return !this.isEmpty() && this.value === null;
234
+ return this.value === null;
290
235
  }
291
236
  dispose() {
292
- if (this.id === 0)
293
- return;
294
- this.id = 0;
295
237
  this.value = undefined;
296
238
  }
297
239
  }
@@ -323,7 +265,7 @@ class HandleStore {
323
265
  const values = this._values;
324
266
  if (next < values.length) {
325
267
  h = values[next];
326
- h.init(next, value);
268
+ h.value = value;
327
269
  }
328
270
  else {
329
271
  h = new Handle(next, value);
@@ -465,18 +407,6 @@ class ScopeStore {
465
407
  }
466
408
  }
467
409
 
468
- class RefStore extends Store {
469
- constructor() {
470
- super(8);
471
- }
472
- }
473
-
474
- class DeferredStore extends Store {
475
- constructor() {
476
- super(8);
477
- }
478
- }
479
-
480
410
  class RefTracker {
481
411
  constructor() {
482
412
  this._next = null;
@@ -597,19 +527,29 @@ class RefBase extends Finalizer {
597
527
  }
598
528
  }
599
529
 
530
+ function throwNodeApiVersionError(moduleName, moduleApiVersion) {
531
+ const errorMessage = `${moduleName} requires Node-API version ${moduleApiVersion}, but this version of Node.js only supports version ${NAPI_VERSION} add-ons.`;
532
+ throw new Error(errorMessage);
533
+ }
534
+ function handleThrow(envObject, value) {
535
+ if (envObject.terminatedOrTerminating()) {
536
+ return;
537
+ }
538
+ throw value;
539
+ }
600
540
  class Env {
601
- constructor(ctx, makeDynCall_vppp, makeDynCall_vp) {
541
+ constructor(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) {
602
542
  this.ctx = ctx;
543
+ this.moduleApiVersion = moduleApiVersion;
603
544
  this.makeDynCall_vppp = makeDynCall_vppp;
604
545
  this.makeDynCall_vp = makeDynCall_vp;
546
+ this.abort = abort;
605
547
  this.openHandleScopes = 0;
606
548
  this.instanceData = null;
607
549
  this.tryCatch = new TryCatch();
608
550
  this.refs = 1;
609
551
  this.reflist = new RefTracker();
610
552
  this.finalizing_reflist = new RefTracker();
611
- this.destructing = false;
612
- this.finalizationScheduled = false;
613
553
  this.pendingFinalizers = [];
614
554
  this.lastError = {
615
555
  errorCode: 0,
@@ -619,11 +559,11 @@ class Env {
619
559
  this._bindingMap = new WeakMap();
620
560
  this.id = 0;
621
561
  }
622
- static create(ctx, makeDynCall_vppp, makeDynCall_vp) {
623
- const env = new Env(ctx, makeDynCall_vppp, makeDynCall_vp);
624
- ctx.envStore.add(env);
625
- ctx.addCleanupHook(env, () => { env.unref(); }, 0);
626
- return env;
562
+ canCallIntoJs() {
563
+ return true;
564
+ }
565
+ terminatedOrTerminating() {
566
+ return !this.canCallIntoJs();
627
567
  }
628
568
  ref() {
629
569
  this.refs++;
@@ -642,27 +582,37 @@ class Env {
642
582
  }
643
583
  clearLastError() {
644
584
  const lastError = this.lastError;
645
- lastError.errorCode = 0;
646
- lastError.engineErrorCode = 0;
647
- lastError.engineReserved = 0;
585
+ if (lastError.errorCode !== 0)
586
+ lastError.errorCode = 0;
587
+ if (lastError.engineErrorCode !== 0)
588
+ lastError.engineErrorCode = 0;
589
+ if (lastError.engineReserved !== 0)
590
+ lastError.engineReserved = 0;
648
591
  return 0;
649
592
  }
650
593
  setLastError(error_code, engine_error_code = 0, engine_reserved = 0) {
651
594
  const lastError = this.lastError;
652
- lastError.errorCode = error_code;
653
- lastError.engineErrorCode = engine_error_code;
654
- lastError.engineReserved = engine_reserved;
595
+ if (lastError.errorCode !== error_code)
596
+ lastError.errorCode = error_code;
597
+ if (lastError.engineErrorCode !== engine_error_code)
598
+ lastError.engineErrorCode = engine_error_code;
599
+ if (lastError.engineReserved !== engine_reserved)
600
+ lastError.engineReserved = engine_reserved;
655
601
  return error_code;
656
602
  }
657
603
  getReturnStatus() {
658
604
  return !this.tryCatch.hasCaught() ? 0 : this.setLastError(10);
659
605
  }
660
- callIntoModule(fn) {
606
+ callIntoModule(fn, handleException = handleThrow) {
607
+ const openHandleScopesBefore = this.openHandleScopes;
661
608
  this.clearLastError();
662
609
  const r = fn(this);
610
+ if (openHandleScopesBefore !== this.openHandleScopes) {
611
+ this.abort('open_handle_scopes != open_handle_scopes_before');
612
+ }
663
613
  if (this.tryCatch.hasCaught()) {
664
614
  const err = this.tryCatch.extractException();
665
- throw err;
615
+ handleException(this, err);
666
616
  }
667
617
  return r;
668
618
  }
@@ -681,15 +631,6 @@ class Env {
681
631
  if (this.pendingFinalizers.indexOf(finalizer) === -1) {
682
632
  this.pendingFinalizers.push(finalizer);
683
633
  }
684
- if (!this.finalizationScheduled && !this.destructing) {
685
- this.finalizationScheduled = true;
686
- this.ref();
687
- _setImmediate(() => {
688
- this.finalizationScheduled = false;
689
- this.unref();
690
- this.drainFinalizerQueue();
691
- });
692
- }
693
634
  }
694
635
  dequeueFinalizer(finalizer) {
695
636
  const index = this.pendingFinalizers.indexOf(finalizer);
@@ -697,21 +638,16 @@ class Env {
697
638
  this.pendingFinalizers.splice(index, 1);
698
639
  }
699
640
  }
700
- drainFinalizerQueue() {
701
- while (this.pendingFinalizers.length > 0) {
702
- const refTracker = this.pendingFinalizers.shift();
703
- refTracker.finalize();
704
- }
705
- }
706
- dispose() {
707
- if (this.id === 0)
708
- return;
709
- this.destructing = true;
710
- this.drainFinalizerQueue();
641
+ deleteMe() {
711
642
  RefBase.finalizeAll(this.finalizing_reflist);
712
643
  RefBase.finalizeAll(this.reflist);
713
644
  this.tryCatch.extractException();
714
645
  this.ctx.envStore.remove(this.id);
646
+ }
647
+ dispose() {
648
+ if (this.id === 0)
649
+ return;
650
+ this.deleteMe();
715
651
  this.id = 0;
716
652
  }
717
653
  initObjectBinding(value) {
@@ -739,6 +675,103 @@ class Env {
739
675
  return this.instanceData ? this.instanceData.data() : 0;
740
676
  }
741
677
  }
678
+ class NodeEnv extends Env {
679
+ constructor(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
680
+ super(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort);
681
+ this.filename = filename;
682
+ this.nodeBinding = nodeBinding;
683
+ this.destructing = false;
684
+ this.finalizationScheduled = false;
685
+ }
686
+ deleteMe() {
687
+ this.destructing = true;
688
+ this.drainFinalizerQueue();
689
+ super.deleteMe();
690
+ }
691
+ canCallIntoJs() {
692
+ return this.ctx.canCallIntoJs();
693
+ }
694
+ triggerFatalException(err) {
695
+ if (this.nodeBinding) {
696
+ this.nodeBinding.napi.fatalException(err);
697
+ }
698
+ else {
699
+ if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') {
700
+ const handled = process._fatalException(err);
701
+ if (!handled) {
702
+ console.error(err);
703
+ process.exit(1);
704
+ }
705
+ }
706
+ else {
707
+ throw err;
708
+ }
709
+ }
710
+ }
711
+ callbackIntoModule(enforceUncaughtExceptionPolicy, fn) {
712
+ return this.callIntoModule(fn, (envObject, err) => {
713
+ if (envObject.terminatedOrTerminating()) {
714
+ return;
715
+ }
716
+ const hasProcess = typeof process === 'object' && process !== null;
717
+ const hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
718
+ if (!hasForceFlag && !enforceUncaughtExceptionPolicy) {
719
+ if (hasProcess && typeof process.emitWarning === 'function') {
720
+ process.emitWarning('Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
721
+ }
722
+ else {
723
+ throw err;
724
+ }
725
+ }
726
+ envObject.triggerFatalException(err);
727
+ });
728
+ }
729
+ callFinalizer(cb, data, hint) {
730
+ this.callFinalizerInternal(1, cb, data, hint);
731
+ }
732
+ callFinalizerInternal(forceUncaught, cb, data, hint) {
733
+ const f = this.makeDynCall_vppp(cb);
734
+ const env = this.id;
735
+ const scope = this.ctx.openScope(this);
736
+ try {
737
+ this.callbackIntoModule(Boolean(forceUncaught), () => { f(env, data, hint); });
738
+ }
739
+ finally {
740
+ this.ctx.closeScope(this, scope);
741
+ }
742
+ }
743
+ enqueueFinalizer(finalizer) {
744
+ super.enqueueFinalizer(finalizer);
745
+ if (!this.finalizationScheduled && !this.destructing) {
746
+ this.finalizationScheduled = true;
747
+ this.ref();
748
+ _setImmediate(() => {
749
+ this.finalizationScheduled = false;
750
+ this.unref();
751
+ this.drainFinalizerQueue();
752
+ });
753
+ }
754
+ }
755
+ drainFinalizerQueue() {
756
+ while (this.pendingFinalizers.length > 0) {
757
+ const refTracker = this.pendingFinalizers.shift();
758
+ refTracker.finalize();
759
+ }
760
+ }
761
+ }
762
+ function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
763
+ moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion;
764
+ if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
765
+ moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
766
+ }
767
+ else if (moduleApiVersion > NAPI_VERSION && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
768
+ throwNodeApiVersionError(filename, moduleApiVersion);
769
+ }
770
+ const env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
771
+ ctx.envStore.add(env);
772
+ ctx.addCleanupHook(env, () => { env.unref(); }, 0);
773
+ return env;
774
+ }
742
775
 
743
776
  class EmnapiError extends Error {
744
777
  constructor(message) {
@@ -822,7 +855,12 @@ class Persistent {
822
855
  this._param = param;
823
856
  this._callback = callback;
824
857
  }
825
- catch (_) { }
858
+ catch (err) {
859
+ if (typeof value === 'symbol') ;
860
+ else {
861
+ throw err;
862
+ }
863
+ }
826
864
  }
827
865
  clearWeak() {
828
866
  if (!supportFinalizer || this._ref === undefined)
@@ -883,6 +921,9 @@ function weakCallback(ref) {
883
921
  ref.persistent.reset();
884
922
  ref.envObject.enqueueFinalizer(ref);
885
923
  }
924
+ function canBeHeldWeakly(value) {
925
+ return value.isObject() || value.isFunction() || value.isSymbol();
926
+ }
886
927
  class Reference extends RefBase {
887
928
  constructor(envObject, initialRefcount, ownership, finalize_callback = 0, finalize_data = 0, finalize_hint = 0) {
888
929
  super(envObject, initialRefcount >>> 0, ownership, finalize_callback, finalize_data, finalize_hint);
@@ -892,6 +933,7 @@ class Reference extends RefBase {
892
933
  const handle = envObject.ctx.handleStore.get(handle_id);
893
934
  const ref = new Reference(envObject, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
894
935
  envObject.ctx.refStore.add(ref);
936
+ ref.canBeWeak = canBeHeldWeakly(handle);
895
937
  ref.persistent = new Persistent(handle.value);
896
938
  if (initialRefcount === 0) {
897
939
  ref._setWeak();
@@ -903,11 +945,8 @@ class Reference extends RefBase {
903
945
  return 0;
904
946
  }
905
947
  const count = super.ref();
906
- if (count === 1) {
907
- const obj = this.persistent.deref();
908
- if (obj) {
909
- this.persistent.clearWeak();
910
- }
948
+ if (count === 1 && this.canBeWeak) {
949
+ this.persistent.clearWeak();
911
950
  }
912
951
  return count;
913
952
  }
@@ -918,23 +957,25 @@ class Reference extends RefBase {
918
957
  const oldRefcount = this.refCount();
919
958
  const refcount = super.unref();
920
959
  if (oldRefcount === 1 && refcount === 0) {
921
- const obj = this.persistent.deref();
922
- if (obj) {
923
- this._setWeak();
924
- }
960
+ this._setWeak();
925
961
  }
926
962
  return refcount;
927
963
  }
928
964
  get() {
929
- const obj = this.persistent.deref();
930
- if (obj) {
931
- const handle = this.envObject.ensureHandle(obj);
932
- return handle.id;
965
+ if (this.persistent.isEmpty()) {
966
+ return 0;
933
967
  }
934
- return 0;
968
+ const obj = this.persistent.deref();
969
+ const handle = this.envObject.ensureHandle(obj);
970
+ return handle.id;
935
971
  }
936
972
  _setWeak() {
937
- this.persistent.setWeak(this, weakCallback);
973
+ if (this.canBeWeak) {
974
+ this.persistent.setWeak(this, weakCallback);
975
+ }
976
+ else {
977
+ this.persistent.reset();
978
+ }
938
979
  }
939
980
  finalize() {
940
981
  this.persistent.reset();
@@ -977,6 +1018,54 @@ class Deferred {
977
1018
  }
978
1019
  }
979
1020
 
1021
+ class Store {
1022
+ constructor() {
1023
+ this._values = [undefined];
1024
+ this._values.length = 4;
1025
+ this._size = 1;
1026
+ this._freeList = [];
1027
+ }
1028
+ add(value) {
1029
+ let id;
1030
+ if (this._freeList.length) {
1031
+ id = this._freeList.shift();
1032
+ }
1033
+ else {
1034
+ id = this._size;
1035
+ this._size++;
1036
+ const capacity = this._values.length;
1037
+ if (id >= capacity) {
1038
+ this._values.length = capacity + (capacity >> 1) + 16;
1039
+ }
1040
+ }
1041
+ value.id = id;
1042
+ this._values[id] = value;
1043
+ }
1044
+ get(id) {
1045
+ return this._values[id];
1046
+ }
1047
+ has(id) {
1048
+ return this._values[id] !== undefined;
1049
+ }
1050
+ remove(id) {
1051
+ const value = this._values[id];
1052
+ if (value) {
1053
+ value.id = 0;
1054
+ this._values[id] = undefined;
1055
+ this._freeList.push(Number(id));
1056
+ }
1057
+ }
1058
+ dispose() {
1059
+ for (let i = 1; i < this._size; ++i) {
1060
+ const value = this._values[i];
1061
+ value === null || value === void 0 ? void 0 : value.dispose();
1062
+ }
1063
+ this._values = [undefined];
1064
+ this._size = 1;
1065
+ this._freeList = [];
1066
+ }
1067
+ }
1068
+
980
1069
  class CleanupHookCallback {
981
1070
  constructor(envObject, fn, arg, order) {
982
1071
  this.envObject = envObject;
@@ -1049,10 +1138,12 @@ class NodejsWaitingRequestCounter {
1049
1138
  }
1050
1139
  class Context {
1051
1140
  constructor() {
1052
- this.envStore = new EnvStore();
1141
+ this._isStopping = false;
1142
+ this._canCallIntoJs = true;
1143
+ this.envStore = new Store();
1053
1144
  this.scopeStore = new ScopeStore();
1054
- this.refStore = new RefStore();
1055
- this.deferredStore = new DeferredStore();
1145
+ this.refStore = new Store();
1146
+ this.deferredStore = new Store();
1056
1147
  this.handleStore = new HandleStore();
1057
1148
  this.cbinfoStack = new CallbackInfoStack();
1058
1149
  this.feature = {
@@ -1070,10 +1161,18 @@ class Context {
1070
1161
  if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1071
1162
  this.refCounter = new NodejsWaitingRequestCounter();
1072
1163
  process.once('beforeExit', () => {
1073
- this.runCleanup();
1164
+ this.destroy();
1074
1165
  });
1075
1166
  }
1076
1167
  }
1168
+ getRuntimeVersions() {
1169
+ return {
1170
+ version,
1171
+ NAPI_VERSION,
1172
+ NAPI_VERSION_EXPERIMENTAL,
1173
+ NODE_API_DEFAULT_MODULE_API_VERSION
1174
+ };
1175
+ }
1077
1176
  createNotSupportWeakRefError(api, message) {
1078
1177
  return new NotSupportWeakRefError(api, message);
1079
1178
  }
@@ -1089,8 +1188,8 @@ class Context {
1089
1188
  createDeferred(value) {
1090
1189
  return Deferred.create(this, value);
1091
1190
  }
1092
- createEnv(makeDynCall_vppp, makeDynCall_vp) {
1093
- return Env.create(this, makeDynCall_vppp, makeDynCall_vp);
1191
+ createEnv(filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1192
+ return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1094
1193
  }
1095
1194
  getCurrentScope() {
1096
1195
  return this.scopeStore.currentScope;
@@ -1133,7 +1232,18 @@ class Context {
1133
1232
  var _a;
1134
1233
  (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease();
1135
1234
  }
1136
- dispose() {
1235
+ setCanCallIntoJs(value) {
1236
+ this._canCallIntoJs = value;
1237
+ }
1238
+ setStopping(value) {
1239
+ this._isStopping = value;
1240
+ }
1241
+ canCallIntoJs() {
1242
+ return this._canCallIntoJs && !this._isStopping;
1243
+ }
1244
+ destroy() {
1245
+ this.setStopping(true);
1246
+ this.setCanCallIntoJs(false);
1137
1247
  this.runCleanup();
1138
1248
  }
1139
1249
  }
@@ -1148,27 +1258,26 @@ function getDefaultContext() {
1148
1258
  return defaultContext;
1149
1259
  }
1150
1260
 
1151
- const version = "0.38.3";
1152
-
1153
1261
  exports.CallbackInfo = CallbackInfo;
1154
1262
  exports.CallbackInfoStack = CallbackInfoStack;
1155
1263
  exports.ConstHandle = ConstHandle;
1156
1264
  exports.Context = Context;
1157
1265
  exports.Deferred = Deferred;
1158
- exports.DeferredStore = DeferredStore;
1159
1266
  exports.EmnapiError = EmnapiError;
1160
1267
  exports.Env = Env;
1161
- exports.EnvStore = EnvStore;
1162
1268
  exports.Finalizer = Finalizer;
1163
1269
  exports.Handle = Handle;
1164
1270
  exports.HandleScope = HandleScope;
1165
1271
  exports.HandleStore = HandleStore;
1272
+ exports.NAPI_VERSION = NAPI_VERSION;
1273
+ exports.NAPI_VERSION_EXPERIMENTAL = NAPI_VERSION_EXPERIMENTAL;
1274
+ exports.NODE_API_DEFAULT_MODULE_API_VERSION = NODE_API_DEFAULT_MODULE_API_VERSION;
1275
+ exports.NodeEnv = NodeEnv;
1166
1276
  exports.NotSupportBigIntError = NotSupportBigIntError;
1167
1277
  exports.NotSupportBufferError = NotSupportBufferError;
1168
1278
  exports.NotSupportWeakRefError = NotSupportWeakRefError;
1169
1279
  exports.Persistent = Persistent;
1170
1280
  exports.RefBase = RefBase;
1171
- exports.RefStore = RefStore;
1172
1281
  exports.RefTracker = RefTracker;
1173
1282
  exports.Reference = Reference;
1174
1283
  exports.ScopeStore = ScopeStore;