@emnapi/runtime 0.41.0 → 0.42.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.
@@ -1,8 +1,11 @@
1
1
  import { __extends } from 'tslib';
2
2
 
3
+ var EMPTY_ARGS = [];
3
4
  var CallbackInfo = /*#__PURE__*/ (function () {
4
- function CallbackInfo(parent, thiz, data, args, fn) {
5
+ function CallbackInfo(id, parent, child, thiz, data, args, fn) {
6
+ this.id = id;
5
7
  this.parent = parent;
8
+ this.child = child;
6
9
  this.thiz = thiz;
7
10
  this.data = data;
8
11
  this.args = args;
@@ -14,22 +17,51 @@ var CallbackInfo = /*#__PURE__*/ (function () {
14
17
  return 0;
15
18
  return thiz instanceof this.fn ? envObject.ensureHandleId(thiz.constructor) : 0;
16
19
  };
20
+ CallbackInfo.prototype.dispose = function () {
21
+ if (this.thiz !== undefined)
22
+ this.thiz = undefined;
23
+ this.args = EMPTY_ARGS;
24
+ this.fn = null;
25
+ };
17
26
  return CallbackInfo;
18
27
  }());
28
+ var ROOT_CBINFO = new CallbackInfo(0, null, null, null, 0, null, null);
19
29
  var CallbackInfoStack = /*#__PURE__*/ (function () {
20
30
  function CallbackInfoStack() {
21
- this.current = null;
31
+ this.current = ROOT_CBINFO;
22
32
  }
33
+ CallbackInfoStack.prototype.get = function (id) {
34
+ if (id === 1)
35
+ return ROOT_CBINFO.child;
36
+ var info = ROOT_CBINFO;
37
+ for (var i = 0; i < id; ++i) {
38
+ info = info.child;
39
+ if (info === null)
40
+ return null;
41
+ }
42
+ return info === ROOT_CBINFO ? null : info;
43
+ };
23
44
  CallbackInfoStack.prototype.pop = function () {
24
45
  var current = this.current;
25
- if (current === null)
46
+ if (current === ROOT_CBINFO)
26
47
  return;
27
48
  this.current = current.parent;
49
+ current.dispose();
28
50
  };
29
51
  CallbackInfoStack.prototype.push = function (thiz, data, args, fn) {
30
- var info = new CallbackInfo(this.current, thiz, data, args, fn);
52
+ var info = this.current.child;
53
+ if (info) {
54
+ info.thiz = thiz;
55
+ info.data = data;
56
+ info.args = args;
57
+ info.fn = fn;
58
+ }
59
+ else {
60
+ info = new CallbackInfo(this.current.id + 1, this.current, null, thiz, data, args, fn);
61
+ this.current.child = info;
62
+ }
31
63
  this.current = info;
32
- return info;
64
+ return info.id;
33
65
  };
34
66
  CallbackInfoStack.prototype.dispose = function () {
35
67
  this.current = null;
@@ -174,8 +206,9 @@ var _Buffer = typeof Buffer === 'function'
174
206
  catch (_) { }
175
207
  return undefined;
176
208
  })();
177
- var version = "0.41.0";
178
- var NAPI_VERSION = 9 /* Version.NAPI_VERSION */;
209
+ var version = "0.42.0";
210
+ var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
211
+ var NODE_API_SUPPORTED_VERSION_MAX = 9 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
179
212
  var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
180
213
  var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */;
181
214
 
@@ -551,7 +584,7 @@ var RefBase = /*#__PURE__*/ (function (_super) {
551
584
  }(Finalizer));
552
585
 
553
586
  function throwNodeApiVersionError(moduleName, moduleApiVersion) {
554
- var errorMessage = "".concat(moduleName, " requires Node-API version ").concat(moduleApiVersion, ", but this version of Node.js only supports version ").concat(NAPI_VERSION, " add-ons.");
587
+ 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.");
555
588
  throw new Error(errorMessage);
556
589
  }
557
590
  function handleThrow(envObject, value) {
@@ -750,12 +783,20 @@ var NodeEnv = /*#__PURE__*/ (function (_super) {
750
783
  var hasProcess = typeof process === 'object' && process !== null;
751
784
  var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
752
785
  if (!hasForceFlag && !enforceUncaughtExceptionPolicy) {
753
- if (hasProcess && typeof process.emitWarning === 'function') {
754
- 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');
755
- }
756
- else {
757
- throw err;
758
- }
786
+ var warn = hasProcess && typeof process.emitWarning === 'function'
787
+ ? process.emitWarning
788
+ : function (warning, type, code) {
789
+ if (warning instanceof Error) {
790
+ console.warn(warning.toString());
791
+ }
792
+ else {
793
+ var prefix = code ? "[".concat(code, "] ") : '';
794
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
795
+ console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
796
+ }
797
+ };
798
+ warn('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');
799
+ return;
759
800
  }
760
801
  envObject.triggerFatalException(err);
761
802
  });
@@ -801,7 +842,7 @@ function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_v
801
842
  if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
802
843
  moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
803
844
  }
804
- else if (moduleApiVersion > NAPI_VERSION && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
845
+ else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
805
846
  throwNodeApiVersionError(filename, moduleApiVersion);
806
847
  }
807
848
  var env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
@@ -851,18 +892,6 @@ Object.defineProperty(NotSupportWeakRefError.prototype, 'name', {
851
892
  writable: true,
852
893
  value: 'NotSupportWeakRefError'
853
894
  });
854
- var NotSupportBigIntError = /*#__PURE__*/ (function (_super) {
855
- __extends(NotSupportBigIntError, _super);
856
- function NotSupportBigIntError(api, message) {
857
- return _super.call(this, "".concat(api, ": The current runtime does not support \"BigInt\".").concat(message ? " ".concat(message) : '')) || this;
858
- }
859
- return NotSupportBigIntError;
860
- }(EmnapiError));
861
- Object.defineProperty(NotSupportBigIntError.prototype, 'name', {
862
- configurable: true,
863
- writable: true,
864
- value: 'NotSupportBigIntError'
865
- });
866
895
  var NotSupportBufferError = /*#__PURE__*/ (function (_super) {
867
896
  __extends(NotSupportBufferError, _super);
868
897
  function NotSupportBufferError(api, message) {
@@ -1234,7 +1263,7 @@ var Context = /*#__PURE__*/ (function () {
1234
1263
  Context.prototype.getRuntimeVersions = function () {
1235
1264
  return {
1236
1265
  version: version,
1237
- NAPI_VERSION: NAPI_VERSION,
1266
+ NODE_API_SUPPORTED_VERSION_MAX: NODE_API_SUPPORTED_VERSION_MAX,
1238
1267
  NAPI_VERSION_EXPERIMENTAL: NAPI_VERSION_EXPERIMENTAL,
1239
1268
  NODE_API_DEFAULT_MODULE_API_VERSION: NODE_API_DEFAULT_MODULE_API_VERSION
1240
1269
  };
@@ -1242,9 +1271,6 @@ var Context = /*#__PURE__*/ (function () {
1242
1271
  Context.prototype.createNotSupportWeakRefError = function (api, message) {
1243
1272
  return new NotSupportWeakRefError(api, message);
1244
1273
  };
1245
- Context.prototype.createNotSupportBigIntError = function (api, message) {
1246
- return new NotSupportBigIntError(api, message);
1247
- };
1248
1274
  Context.prototype.createNotSupportBufferError = function (api, message) {
1249
1275
  return new NotSupportBufferError(api, message);
1250
1276
  };
@@ -1328,4 +1354,4 @@ function getDefaultContext() {
1328
1354
  return defaultContext;
1329
1355
  }
1330
1356
 
1331
- export { CallbackInfo, CallbackInfoStack, ConstHandle, Context, Deferred, EmnapiError, Env, Finalizer, Handle, HandleScope, HandleStore, NAPI_VERSION, NAPI_VERSION_EXPERIMENTAL, NODE_API_DEFAULT_MODULE_API_VERSION, NodeEnv, NotSupportBigIntError, NotSupportBufferError, NotSupportWeakRefError, Persistent, RefBase, RefTracker, Reference, ScopeStore, Store, TryCatch, createContext, getDefaultContext, isReferenceType, version };
1357
+ export { CallbackInfo, CallbackInfoStack, ConstHandle, Context, Deferred, EmnapiError, Env, Finalizer, Handle, HandleScope, HandleStore, NAPI_VERSION_EXPERIMENTAL, NODE_API_DEFAULT_MODULE_API_VERSION, NODE_API_SUPPORTED_VERSION_MAX, NODE_API_SUPPORTED_VERSION_MIN, NodeEnv, NotSupportBufferError, NotSupportWeakRefError, Persistent, RefBase, RefTracker, Reference, ScopeStore, Store, TryCatch, createContext, getDefaultContext, isReferenceType, version };
@@ -1,19 +1,23 @@
1
1
  declare namespace emnapi {
2
2
 
3
3
  export class CallbackInfo {
4
- parent: CallbackInfo | null;
4
+ id: number;
5
+ parent: CallbackInfo;
6
+ child: CallbackInfo | null;
5
7
  thiz: any;
6
8
  data: void_p;
7
9
  args: ArrayLike<any>;
8
10
  fn: Function;
9
- constructor(parent: CallbackInfo | null, thiz: any, data: void_p, args: ArrayLike<any>, fn: Function);
11
+ constructor(id: number, parent: CallbackInfo, child: CallbackInfo | null, thiz: any, data: void_p, args: ArrayLike<any>, fn: Function);
10
12
  getNewTarget(envObject: Env): number;
13
+ dispose(): void;
11
14
  }
12
15
 
13
16
  export class CallbackInfoStack {
14
- current: CallbackInfo | null;
17
+ current: CallbackInfo;
18
+ get(id: number): CallbackInfo | null;
15
19
  pop(): void;
16
- push(thiz: any, data: void_p, args: ArrayLike<any>, fn: Function): CallbackInfo;
20
+ push(thiz: any, data: void_p, args: ArrayLike<any>, fn: Function): number;
17
21
  dispose(): void;
18
22
  }
19
23
 
@@ -52,12 +56,11 @@ export class Context {
52
56
  constructor();
53
57
  getRuntimeVersions(): {
54
58
  version: string;
55
- NAPI_VERSION: Version;
59
+ NODE_API_SUPPORTED_VERSION_MAX: Version;
56
60
  NAPI_VERSION_EXPERIMENTAL: Version;
57
61
  NODE_API_DEFAULT_MODULE_API_VERSION: Version;
58
62
  };
59
63
  createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
60
- createNotSupportBigIntError(api: string, message: string): NotSupportBigIntError;
61
64
  createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
62
65
  createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: 0 | 1, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
63
66
  createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
@@ -228,12 +231,14 @@ export interface IStoreValue {
228
231
  [x: string]: any;
229
232
  }
230
233
 
231
- export const NAPI_VERSION = Version.NAPI_VERSION;
232
-
233
234
  export const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL;
234
235
 
235
236
  export const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION;
236
237
 
238
+ export const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX;
239
+
240
+ export const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN;
241
+
237
242
  export class NodeEnv extends Env {
238
243
  filename: string;
239
244
  private readonly nodeBinding?;
@@ -250,10 +255,6 @@ export class NodeEnv extends Env {
250
255
  drainFinalizerQueue(): void;
251
256
  }
252
257
 
253
- export class NotSupportBigIntError extends EmnapiError {
254
- constructor(api: string, message: string);
255
- }
256
-
257
258
  export class NotSupportBufferError extends EmnapiError {
258
259
  constructor(api: string, message: string);
259
260
  }
@@ -1,8 +1,11 @@
1
1
  var emnapi = (function (exports) {
2
2
 
3
+ var EMPTY_ARGS = [];
3
4
  var CallbackInfo = /*#__PURE__*/ (function () {
4
- function CallbackInfo(parent, thiz, data, args, fn) {
5
+ function CallbackInfo(id, parent, child, thiz, data, args, fn) {
6
+ this.id = id;
5
7
  this.parent = parent;
8
+ this.child = child;
6
9
  this.thiz = thiz;
7
10
  this.data = data;
8
11
  this.args = args;
@@ -14,22 +17,51 @@ var emnapi = (function (exports) {
14
17
  return 0;
15
18
  return thiz instanceof this.fn ? envObject.ensureHandleId(thiz.constructor) : 0;
16
19
  };
20
+ CallbackInfo.prototype.dispose = function () {
21
+ if (this.thiz !== undefined)
22
+ this.thiz = undefined;
23
+ this.args = EMPTY_ARGS;
24
+ this.fn = null;
25
+ };
17
26
  return CallbackInfo;
18
27
  }());
28
+ var ROOT_CBINFO = new CallbackInfo(0, null, null, null, 0, null, null);
19
29
  var CallbackInfoStack = /*#__PURE__*/ (function () {
20
30
  function CallbackInfoStack() {
21
- this.current = null;
31
+ this.current = ROOT_CBINFO;
22
32
  }
33
+ CallbackInfoStack.prototype.get = function (id) {
34
+ if (id === 1)
35
+ return ROOT_CBINFO.child;
36
+ var info = ROOT_CBINFO;
37
+ for (var i = 0; i < id; ++i) {
38
+ info = info.child;
39
+ if (info === null)
40
+ return null;
41
+ }
42
+ return info === ROOT_CBINFO ? null : info;
43
+ };
23
44
  CallbackInfoStack.prototype.pop = function () {
24
45
  var current = this.current;
25
- if (current === null)
46
+ if (current === ROOT_CBINFO)
26
47
  return;
27
48
  this.current = current.parent;
49
+ current.dispose();
28
50
  };
29
51
  CallbackInfoStack.prototype.push = function (thiz, data, args, fn) {
30
- var info = new CallbackInfo(this.current, thiz, data, args, fn);
52
+ var info = this.current.child;
53
+ if (info) {
54
+ info.thiz = thiz;
55
+ info.data = data;
56
+ info.args = args;
57
+ info.fn = fn;
58
+ }
59
+ else {
60
+ info = new CallbackInfo(this.current.id + 1, this.current, null, thiz, data, args, fn);
61
+ this.current.child = info;
62
+ }
31
63
  this.current = info;
32
- return info;
64
+ return info.id;
33
65
  };
34
66
  CallbackInfoStack.prototype.dispose = function () {
35
67
  this.current = null;
@@ -51,7 +83,7 @@ var emnapi = (function (exports) {
51
83
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
52
84
  PERFORMANCE OF THIS SOFTWARE.
53
85
  ***************************************************************************** */
54
- /* global Reflect, Promise */
86
+ /* global Reflect, Promise, SuppressedError, Symbol */
55
87
 
56
88
  var extendStatics = function(d, b) {
57
89
  extendStatics = Object.setPrototypeOf ||
@@ -68,6 +100,11 @@ var emnapi = (function (exports) {
68
100
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
69
101
  }
70
102
 
103
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
104
+ var e = new Error(message);
105
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
106
+ };
107
+
71
108
  var supportNewFunction = /*#__PURE__*/ (function () {
72
109
  var f;
73
110
  try {
@@ -205,8 +242,9 @@ var emnapi = (function (exports) {
205
242
  catch (_) { }
206
243
  return undefined;
207
244
  })();
208
- var version = "0.41.0";
209
- var NAPI_VERSION = 9 /* Version.NAPI_VERSION */;
245
+ var version = "0.42.0";
246
+ var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
247
+ var NODE_API_SUPPORTED_VERSION_MAX = 9 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
210
248
  var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
211
249
  var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */;
212
250
 
@@ -582,7 +620,7 @@ var emnapi = (function (exports) {
582
620
  }(Finalizer));
583
621
 
584
622
  function throwNodeApiVersionError(moduleName, moduleApiVersion) {
585
- var errorMessage = "".concat(moduleName, " requires Node-API version ").concat(moduleApiVersion, ", but this version of Node.js only supports version ").concat(NAPI_VERSION, " add-ons.");
623
+ 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.");
586
624
  throw new Error(errorMessage);
587
625
  }
588
626
  function handleThrow(envObject, value) {
@@ -781,12 +819,20 @@ var emnapi = (function (exports) {
781
819
  var hasProcess = typeof process === 'object' && process !== null;
782
820
  var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
783
821
  if (!hasForceFlag && !enforceUncaughtExceptionPolicy) {
784
- if (hasProcess && typeof process.emitWarning === 'function') {
785
- 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');
786
- }
787
- else {
788
- throw err;
789
- }
822
+ var warn = hasProcess && typeof process.emitWarning === 'function'
823
+ ? process.emitWarning
824
+ : function (warning, type, code) {
825
+ if (warning instanceof Error) {
826
+ console.warn(warning.toString());
827
+ }
828
+ else {
829
+ var prefix = code ? "[".concat(code, "] ") : '';
830
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
831
+ console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
832
+ }
833
+ };
834
+ warn('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');
835
+ return;
790
836
  }
791
837
  envObject.triggerFatalException(err);
792
838
  });
@@ -832,7 +878,7 @@ var emnapi = (function (exports) {
832
878
  if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
833
879
  moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
834
880
  }
835
- else if (moduleApiVersion > NAPI_VERSION && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
881
+ else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
836
882
  throwNodeApiVersionError(filename, moduleApiVersion);
837
883
  }
838
884
  var env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
@@ -882,18 +928,6 @@ var emnapi = (function (exports) {
882
928
  writable: true,
883
929
  value: 'NotSupportWeakRefError'
884
930
  });
885
- var NotSupportBigIntError = /*#__PURE__*/ (function (_super) {
886
- __extends(NotSupportBigIntError, _super);
887
- function NotSupportBigIntError(api, message) {
888
- return _super.call(this, "".concat(api, ": The current runtime does not support \"BigInt\".").concat(message ? " ".concat(message) : '')) || this;
889
- }
890
- return NotSupportBigIntError;
891
- }(EmnapiError));
892
- Object.defineProperty(NotSupportBigIntError.prototype, 'name', {
893
- configurable: true,
894
- writable: true,
895
- value: 'NotSupportBigIntError'
896
- });
897
931
  var NotSupportBufferError = /*#__PURE__*/ (function (_super) {
898
932
  __extends(NotSupportBufferError, _super);
899
933
  function NotSupportBufferError(api, message) {
@@ -1265,7 +1299,7 @@ var emnapi = (function (exports) {
1265
1299
  Context.prototype.getRuntimeVersions = function () {
1266
1300
  return {
1267
1301
  version: version,
1268
- NAPI_VERSION: NAPI_VERSION,
1302
+ NODE_API_SUPPORTED_VERSION_MAX: NODE_API_SUPPORTED_VERSION_MAX,
1269
1303
  NAPI_VERSION_EXPERIMENTAL: NAPI_VERSION_EXPERIMENTAL,
1270
1304
  NODE_API_DEFAULT_MODULE_API_VERSION: NODE_API_DEFAULT_MODULE_API_VERSION
1271
1305
  };
@@ -1273,9 +1307,6 @@ var emnapi = (function (exports) {
1273
1307
  Context.prototype.createNotSupportWeakRefError = function (api, message) {
1274
1308
  return new NotSupportWeakRefError(api, message);
1275
1309
  };
1276
- Context.prototype.createNotSupportBigIntError = function (api, message) {
1277
- return new NotSupportBigIntError(api, message);
1278
- };
1279
1310
  Context.prototype.createNotSupportBufferError = function (api, message) {
1280
1311
  return new NotSupportBufferError(api, message);
1281
1312
  };
@@ -1370,11 +1401,11 @@ var emnapi = (function (exports) {
1370
1401
  exports.Handle = Handle;
1371
1402
  exports.HandleScope = HandleScope;
1372
1403
  exports.HandleStore = HandleStore;
1373
- exports.NAPI_VERSION = NAPI_VERSION;
1374
1404
  exports.NAPI_VERSION_EXPERIMENTAL = NAPI_VERSION_EXPERIMENTAL;
1375
1405
  exports.NODE_API_DEFAULT_MODULE_API_VERSION = NODE_API_DEFAULT_MODULE_API_VERSION;
1406
+ exports.NODE_API_SUPPORTED_VERSION_MAX = NODE_API_SUPPORTED_VERSION_MAX;
1407
+ exports.NODE_API_SUPPORTED_VERSION_MIN = NODE_API_SUPPORTED_VERSION_MIN;
1376
1408
  exports.NodeEnv = NodeEnv;
1377
- exports.NotSupportBigIntError = NotSupportBigIntError;
1378
1409
  exports.NotSupportBufferError = NotSupportBufferError;
1379
1410
  exports.NotSupportWeakRefError = NotSupportWeakRefError;
1380
1411
  exports.Persistent = Persistent;
package/dist/emnapi.js CHANGED
@@ -3,9 +3,12 @@
3
3
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.emnapi = {}));
5
5
  })(this, (function (exports) {
6
+ var EMPTY_ARGS = [];
6
7
  var CallbackInfo = /*#__PURE__*/ (function () {
7
- function CallbackInfo(parent, thiz, data, args, fn) {
8
+ function CallbackInfo(id, parent, child, thiz, data, args, fn) {
9
+ this.id = id;
8
10
  this.parent = parent;
11
+ this.child = child;
9
12
  this.thiz = thiz;
10
13
  this.data = data;
11
14
  this.args = args;
@@ -17,22 +20,51 @@
17
20
  return 0;
18
21
  return thiz instanceof this.fn ? envObject.ensureHandleId(thiz.constructor) : 0;
19
22
  };
23
+ CallbackInfo.prototype.dispose = function () {
24
+ if (this.thiz !== undefined)
25
+ this.thiz = undefined;
26
+ this.args = EMPTY_ARGS;
27
+ this.fn = null;
28
+ };
20
29
  return CallbackInfo;
21
30
  }());
31
+ var ROOT_CBINFO = new CallbackInfo(0, null, null, null, 0, null, null);
22
32
  var CallbackInfoStack = /*#__PURE__*/ (function () {
23
33
  function CallbackInfoStack() {
24
- this.current = null;
34
+ this.current = ROOT_CBINFO;
25
35
  }
36
+ CallbackInfoStack.prototype.get = function (id) {
37
+ if (id === 1)
38
+ return ROOT_CBINFO.child;
39
+ var info = ROOT_CBINFO;
40
+ for (var i = 0; i < id; ++i) {
41
+ info = info.child;
42
+ if (info === null)
43
+ return null;
44
+ }
45
+ return info === ROOT_CBINFO ? null : info;
46
+ };
26
47
  CallbackInfoStack.prototype.pop = function () {
27
48
  var current = this.current;
28
- if (current === null)
49
+ if (current === ROOT_CBINFO)
29
50
  return;
30
51
  this.current = current.parent;
52
+ current.dispose();
31
53
  };
32
54
  CallbackInfoStack.prototype.push = function (thiz, data, args, fn) {
33
- var info = new CallbackInfo(this.current, thiz, data, args, fn);
55
+ var info = this.current.child;
56
+ if (info) {
57
+ info.thiz = thiz;
58
+ info.data = data;
59
+ info.args = args;
60
+ info.fn = fn;
61
+ }
62
+ else {
63
+ info = new CallbackInfo(this.current.id + 1, this.current, null, thiz, data, args, fn);
64
+ this.current.child = info;
65
+ }
34
66
  this.current = info;
35
- return info;
67
+ return info.id;
36
68
  };
37
69
  CallbackInfoStack.prototype.dispose = function () {
38
70
  this.current = null;
@@ -54,7 +86,7 @@
54
86
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
55
87
  PERFORMANCE OF THIS SOFTWARE.
56
88
  ***************************************************************************** */
57
- /* global Reflect, Promise */
89
+ /* global Reflect, Promise, SuppressedError, Symbol */
58
90
 
59
91
  var extendStatics = function(d, b) {
60
92
  extendStatics = Object.setPrototypeOf ||
@@ -71,6 +103,11 @@
71
103
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
72
104
  }
73
105
 
106
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
107
+ var e = new Error(message);
108
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
109
+ };
110
+
74
111
  var supportNewFunction = /*#__PURE__*/ (function () {
75
112
  var f;
76
113
  try {
@@ -208,8 +245,9 @@
208
245
  catch (_) { }
209
246
  return undefined;
210
247
  })();
211
- var version = "0.41.0";
212
- var NAPI_VERSION = 9 /* Version.NAPI_VERSION */;
248
+ var version = "0.42.0";
249
+ var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
250
+ var NODE_API_SUPPORTED_VERSION_MAX = 9 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
213
251
  var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
214
252
  var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */;
215
253
 
@@ -585,7 +623,7 @@
585
623
  }(Finalizer));
586
624
 
587
625
  function throwNodeApiVersionError(moduleName, moduleApiVersion) {
588
- var errorMessage = "".concat(moduleName, " requires Node-API version ").concat(moduleApiVersion, ", but this version of Node.js only supports version ").concat(NAPI_VERSION, " add-ons.");
626
+ 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.");
589
627
  throw new Error(errorMessage);
590
628
  }
591
629
  function handleThrow(envObject, value) {
@@ -784,12 +822,20 @@
784
822
  var hasProcess = typeof process === 'object' && process !== null;
785
823
  var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
786
824
  if (!hasForceFlag && !enforceUncaughtExceptionPolicy) {
787
- if (hasProcess && typeof process.emitWarning === 'function') {
788
- 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');
789
- }
790
- else {
791
- throw err;
792
- }
825
+ var warn = hasProcess && typeof process.emitWarning === 'function'
826
+ ? process.emitWarning
827
+ : function (warning, type, code) {
828
+ if (warning instanceof Error) {
829
+ console.warn(warning.toString());
830
+ }
831
+ else {
832
+ var prefix = code ? "[".concat(code, "] ") : '';
833
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
834
+ console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
835
+ }
836
+ };
837
+ warn('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');
838
+ return;
793
839
  }
794
840
  envObject.triggerFatalException(err);
795
841
  });
@@ -835,7 +881,7 @@
835
881
  if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
836
882
  moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
837
883
  }
838
- else if (moduleApiVersion > NAPI_VERSION && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
884
+ else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
839
885
  throwNodeApiVersionError(filename, moduleApiVersion);
840
886
  }
841
887
  var env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
@@ -885,18 +931,6 @@
885
931
  writable: true,
886
932
  value: 'NotSupportWeakRefError'
887
933
  });
888
- var NotSupportBigIntError = /*#__PURE__*/ (function (_super) {
889
- __extends(NotSupportBigIntError, _super);
890
- function NotSupportBigIntError(api, message) {
891
- return _super.call(this, "".concat(api, ": The current runtime does not support \"BigInt\".").concat(message ? " ".concat(message) : '')) || this;
892
- }
893
- return NotSupportBigIntError;
894
- }(EmnapiError));
895
- Object.defineProperty(NotSupportBigIntError.prototype, 'name', {
896
- configurable: true,
897
- writable: true,
898
- value: 'NotSupportBigIntError'
899
- });
900
934
  var NotSupportBufferError = /*#__PURE__*/ (function (_super) {
901
935
  __extends(NotSupportBufferError, _super);
902
936
  function NotSupportBufferError(api, message) {
@@ -1268,7 +1302,7 @@
1268
1302
  Context.prototype.getRuntimeVersions = function () {
1269
1303
  return {
1270
1304
  version: version,
1271
- NAPI_VERSION: NAPI_VERSION,
1305
+ NODE_API_SUPPORTED_VERSION_MAX: NODE_API_SUPPORTED_VERSION_MAX,
1272
1306
  NAPI_VERSION_EXPERIMENTAL: NAPI_VERSION_EXPERIMENTAL,
1273
1307
  NODE_API_DEFAULT_MODULE_API_VERSION: NODE_API_DEFAULT_MODULE_API_VERSION
1274
1308
  };
@@ -1276,9 +1310,6 @@
1276
1310
  Context.prototype.createNotSupportWeakRefError = function (api, message) {
1277
1311
  return new NotSupportWeakRefError(api, message);
1278
1312
  };
1279
- Context.prototype.createNotSupportBigIntError = function (api, message) {
1280
- return new NotSupportBigIntError(api, message);
1281
- };
1282
1313
  Context.prototype.createNotSupportBufferError = function (api, message) {
1283
1314
  return new NotSupportBufferError(api, message);
1284
1315
  };
@@ -1373,11 +1404,11 @@
1373
1404
  exports.Handle = Handle;
1374
1405
  exports.HandleScope = HandleScope;
1375
1406
  exports.HandleStore = HandleStore;
1376
- exports.NAPI_VERSION = NAPI_VERSION;
1377
1407
  exports.NAPI_VERSION_EXPERIMENTAL = NAPI_VERSION_EXPERIMENTAL;
1378
1408
  exports.NODE_API_DEFAULT_MODULE_API_VERSION = NODE_API_DEFAULT_MODULE_API_VERSION;
1409
+ exports.NODE_API_SUPPORTED_VERSION_MAX = NODE_API_SUPPORTED_VERSION_MAX;
1410
+ exports.NODE_API_SUPPORTED_VERSION_MIN = NODE_API_SUPPORTED_VERSION_MIN;
1379
1411
  exports.NodeEnv = NodeEnv;
1380
- exports.NotSupportBigIntError = NotSupportBigIntError;
1381
1412
  exports.NotSupportBufferError = NotSupportBufferError;
1382
1413
  exports.NotSupportWeakRefError = NotSupportWeakRefError;
1383
1414
  exports.Persistent = Persistent;