@tailwindcss/oxide-wasm32-wasi 0.0.0-insiders.d801d8d

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.
Files changed (113) hide show
  1. package/README.md +3 -0
  2. package/node_modules/@emnapi/core/LICENSE +21 -0
  3. package/node_modules/@emnapi/core/README.md +1 -0
  4. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.js +6661 -0
  5. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts +363 -0
  6. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.js +1 -0
  7. package/node_modules/@emnapi/core/dist/emnapi-core.d.mts +363 -0
  8. package/node_modules/@emnapi/core/dist/emnapi-core.d.ts +365 -0
  9. package/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js +7411 -0
  10. package/node_modules/@emnapi/core/dist/emnapi-core.js +8390 -0
  11. package/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts +363 -0
  12. package/node_modules/@emnapi/core/dist/emnapi-core.min.js +1 -0
  13. package/node_modules/@emnapi/core/dist/emnapi-core.min.mjs +1 -0
  14. package/node_modules/@emnapi/core/dist/emnapi-core.mjs +6650 -0
  15. package/node_modules/@emnapi/core/index.js +5 -0
  16. package/node_modules/@emnapi/core/package.json +49 -0
  17. package/node_modules/@emnapi/runtime/LICENSE +21 -0
  18. package/node_modules/@emnapi/runtime/README.md +1 -0
  19. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.js +1347 -0
  20. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts +663 -0
  21. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js +1 -0
  22. package/node_modules/@emnapi/runtime/dist/emnapi.d.mts +663 -0
  23. package/node_modules/@emnapi/runtime/dist/emnapi.d.ts +665 -0
  24. package/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js +1403 -0
  25. package/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts +420 -0
  26. package/node_modules/@emnapi/runtime/dist/emnapi.iife.js +1474 -0
  27. package/node_modules/@emnapi/runtime/dist/emnapi.js +1475 -0
  28. package/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts +663 -0
  29. package/node_modules/@emnapi/runtime/dist/emnapi.min.js +1 -0
  30. package/node_modules/@emnapi/runtime/dist/emnapi.min.mjs +1 -0
  31. package/node_modules/@emnapi/runtime/dist/emnapi.mjs +1316 -0
  32. package/node_modules/@emnapi/runtime/index.js +5 -0
  33. package/node_modules/@emnapi/runtime/package.json +48 -0
  34. package/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
  35. package/node_modules/@emnapi/wasi-threads/README.md +203 -0
  36. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js +881 -0
  37. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts +214 -0
  38. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.js +1 -0
  39. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.mts +214 -0
  40. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +216 -0
  41. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js +929 -0
  42. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +941 -0
  43. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts +214 -0
  44. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.js +1 -0
  45. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.mjs +1 -0
  46. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.mjs +876 -0
  47. package/node_modules/@emnapi/wasi-threads/index.js +5 -0
  48. package/node_modules/@emnapi/wasi-threads/package.json +50 -0
  49. package/node_modules/@napi-rs/wasm-runtime/LICENSE +43 -0
  50. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +23712 -0
  51. package/node_modules/@napi-rs/wasm-runtime/dist/runtime.js +12269 -0
  52. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.cjs +193 -0
  53. package/node_modules/@napi-rs/wasm-runtime/package.json +60 -0
  54. package/node_modules/@napi-rs/wasm-runtime/runtime.cjs +15 -0
  55. package/node_modules/@tybys/wasm-util/README.md +193 -0
  56. package/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
  57. package/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +417 -0
  58. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2738 -0
  59. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2738 -0
  60. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
  61. package/node_modules/@tybys/wasm-util/dist/wasm-util.js +2760 -0
  62. package/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
  63. package/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
  64. package/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
  65. package/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
  66. package/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
  67. package/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
  68. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
  69. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
  70. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
  71. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +194 -0
  72. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +174 -0
  73. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1544 -0
  74. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
  75. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
  76. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
  77. package/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
  78. package/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
  79. package/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
  80. package/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
  81. package/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
  82. package/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
  83. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
  84. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
  85. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
  86. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +188 -0
  87. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +168 -0
  88. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1539 -0
  89. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
  90. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
  91. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
  92. package/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
  93. package/node_modules/@tybys/wasm-util/package.json +58 -0
  94. package/node_modules/tslib/CopyrightNotice.txt +15 -0
  95. package/node_modules/tslib/LICENSE.txt +12 -0
  96. package/node_modules/tslib/README.md +164 -0
  97. package/node_modules/tslib/SECURITY.md +41 -0
  98. package/node_modules/tslib/modules/index.d.ts +38 -0
  99. package/node_modules/tslib/modules/index.js +70 -0
  100. package/node_modules/tslib/modules/package.json +3 -0
  101. package/node_modules/tslib/package.json +47 -0
  102. package/node_modules/tslib/tslib.d.ts +460 -0
  103. package/node_modules/tslib/tslib.es6.html +1 -0
  104. package/node_modules/tslib/tslib.es6.js +393 -0
  105. package/node_modules/tslib/tslib.es6.mjs +392 -0
  106. package/node_modules/tslib/tslib.html +1 -0
  107. package/node_modules/tslib/tslib.js +475 -0
  108. package/package.json +45 -0
  109. package/tailwindcss-oxide.wasi-browser.js +63 -0
  110. package/tailwindcss-oxide.wasi.cjs +88 -0
  111. package/tailwindcss-oxide.wasm32-wasi.wasm +0 -0
  112. package/wasi-worker-browser.mjs +39 -0
  113. package/wasi-worker.mjs +63 -0
@@ -0,0 +1,1403 @@
1
+ import { __extends } from 'tslib';
2
+
3
+ var externalValue = new WeakMap();
4
+ /** @public */
5
+ function isExternal(object) {
6
+ return externalValue.has(object);
7
+ }
8
+ /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare
9
+ var External = (function () {
10
+ function External(value) {
11
+ Object.setPrototypeOf(this, null);
12
+ externalValue.set(this, value);
13
+ }
14
+ External.prototype = null;
15
+ return External;
16
+ })();
17
+ /** @public */
18
+ function getExternalValue(external) {
19
+ if (!isExternal(external)) {
20
+ throw new TypeError('not external');
21
+ }
22
+ return externalValue.get(external);
23
+ }
24
+
25
+ var supportNewFunction = /*#__PURE__*/ (function () {
26
+ var f;
27
+ try {
28
+ f = new Function();
29
+ }
30
+ catch (_) {
31
+ return false;
32
+ }
33
+ return typeof f === 'function';
34
+ })();
35
+ var _global = /*#__PURE__*/ (function () {
36
+ if (typeof globalThis !== 'undefined')
37
+ return globalThis;
38
+ var g = (function () { return this; })();
39
+ if (!g && supportNewFunction) {
40
+ try {
41
+ g = new Function('return this')();
42
+ }
43
+ catch (_) { }
44
+ }
45
+ if (!g) {
46
+ if (typeof __webpack_public_path__ === 'undefined') {
47
+ if (typeof global !== 'undefined')
48
+ return global;
49
+ }
50
+ if (typeof window !== 'undefined')
51
+ return window;
52
+ if (typeof self !== 'undefined')
53
+ return self;
54
+ }
55
+ return g;
56
+ })();
57
+ var TryCatch = /*#__PURE__*/ (function () {
58
+ function TryCatch() {
59
+ this._exception = undefined;
60
+ this._caught = false;
61
+ }
62
+ TryCatch.prototype.isEmpty = function () {
63
+ return !this._caught;
64
+ };
65
+ TryCatch.prototype.hasCaught = function () {
66
+ return this._caught;
67
+ };
68
+ TryCatch.prototype.exception = function () {
69
+ return this._exception;
70
+ };
71
+ TryCatch.prototype.setError = function (err) {
72
+ this._caught = true;
73
+ this._exception = err;
74
+ };
75
+ TryCatch.prototype.reset = function () {
76
+ this._caught = false;
77
+ this._exception = undefined;
78
+ };
79
+ TryCatch.prototype.extractException = function () {
80
+ var e = this._exception;
81
+ this.reset();
82
+ return e;
83
+ };
84
+ return TryCatch;
85
+ }());
86
+ var canSetFunctionName = /*#__PURE__*/ (function () {
87
+ var _a;
88
+ try {
89
+ return Boolean((_a = Object.getOwnPropertyDescriptor(Function.prototype, 'name')) === null || _a === void 0 ? void 0 : _a.configurable);
90
+ }
91
+ catch (_) {
92
+ return false;
93
+ }
94
+ })();
95
+ var supportReflect = typeof Reflect === 'object';
96
+ var supportFinalizer = (typeof FinalizationRegistry !== 'undefined') && (typeof WeakRef !== 'undefined');
97
+ var supportWeakSymbol = /*#__PURE__*/ (function () {
98
+ try {
99
+ // eslint-disable-next-line symbol-description
100
+ var sym = Symbol();
101
+ // eslint-disable-next-line no-new
102
+ new WeakRef(sym);
103
+ new WeakMap().set(sym, undefined);
104
+ }
105
+ catch (_) {
106
+ return false;
107
+ }
108
+ return true;
109
+ })();
110
+ var supportBigInt = typeof BigInt !== 'undefined';
111
+ function isReferenceType(v) {
112
+ return (typeof v === 'object' && v !== null) || typeof v === 'function';
113
+ }
114
+ var _require = /*#__PURE__*/ (function () {
115
+ var nativeRequire;
116
+ if (typeof __webpack_public_path__ !== 'undefined') {
117
+ nativeRequire = (function () {
118
+ return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined;
119
+ })();
120
+ }
121
+ else {
122
+ nativeRequire = (function () {
123
+ return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined);
124
+ })();
125
+ }
126
+ return nativeRequire;
127
+ })();
128
+ var _MessageChannel = typeof MessageChannel === 'function'
129
+ ? MessageChannel
130
+ : /*#__PURE__*/ (function () {
131
+ try {
132
+ return _require('worker_threads').MessageChannel;
133
+ }
134
+ catch (_) { }
135
+ return undefined;
136
+ })();
137
+ var _setImmediate = typeof setImmediate === 'function'
138
+ ? setImmediate
139
+ : function (callback) {
140
+ if (typeof callback !== 'function') {
141
+ throw new TypeError('The "callback" argument must be of type function');
142
+ }
143
+ if (_MessageChannel) {
144
+ var channel_1 = new _MessageChannel();
145
+ channel_1.port1.onmessage = function () {
146
+ channel_1.port1.onmessage = null;
147
+ channel_1 = undefined;
148
+ callback();
149
+ };
150
+ channel_1.port2.postMessage(null);
151
+ }
152
+ else {
153
+ setTimeout(callback, 0);
154
+ }
155
+ };
156
+ var _Buffer = typeof Buffer === 'function'
157
+ ? Buffer
158
+ : /*#__PURE__*/ (function () {
159
+ try {
160
+ return _require('buffer').Buffer;
161
+ }
162
+ catch (_) { }
163
+ return undefined;
164
+ })();
165
+ var version = "1.4.0";
166
+ var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
167
+ var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
168
+ var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
169
+ var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */;
170
+
171
+ var Handle = /*#__PURE__*/ (function () {
172
+ function Handle(id, value) {
173
+ this.id = id;
174
+ this.value = value;
175
+ }
176
+ Handle.prototype.data = function () {
177
+ return getExternalValue(this.value);
178
+ };
179
+ Handle.prototype.isNumber = function () {
180
+ return typeof this.value === 'number';
181
+ };
182
+ Handle.prototype.isBigInt = function () {
183
+ return typeof this.value === 'bigint';
184
+ };
185
+ Handle.prototype.isString = function () {
186
+ return typeof this.value === 'string';
187
+ };
188
+ Handle.prototype.isFunction = function () {
189
+ return typeof this.value === 'function';
190
+ };
191
+ Handle.prototype.isExternal = function () {
192
+ return isExternal(this.value);
193
+ };
194
+ Handle.prototype.isObject = function () {
195
+ return typeof this.value === 'object' && this.value !== null;
196
+ };
197
+ Handle.prototype.isArray = function () {
198
+ return Array.isArray(this.value);
199
+ };
200
+ Handle.prototype.isArrayBuffer = function () {
201
+ return (this.value instanceof ArrayBuffer);
202
+ };
203
+ Handle.prototype.isTypedArray = function () {
204
+ return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
205
+ };
206
+ Handle.prototype.isBuffer = function (BufferConstructor) {
207
+ if (ArrayBuffer.isView(this.value))
208
+ return true;
209
+ BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer);
210
+ return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value);
211
+ };
212
+ Handle.prototype.isDataView = function () {
213
+ return (this.value instanceof DataView);
214
+ };
215
+ Handle.prototype.isDate = function () {
216
+ return (this.value instanceof Date);
217
+ };
218
+ Handle.prototype.isPromise = function () {
219
+ return (this.value instanceof Promise);
220
+ };
221
+ Handle.prototype.isBoolean = function () {
222
+ return typeof this.value === 'boolean';
223
+ };
224
+ Handle.prototype.isUndefined = function () {
225
+ return this.value === undefined;
226
+ };
227
+ Handle.prototype.isSymbol = function () {
228
+ return typeof this.value === 'symbol';
229
+ };
230
+ Handle.prototype.isNull = function () {
231
+ return this.value === null;
232
+ };
233
+ Handle.prototype.dispose = function () {
234
+ this.value = undefined;
235
+ };
236
+ return Handle;
237
+ }());
238
+ var ConstHandle = /*#__PURE__*/ (function (_super) {
239
+ __extends(ConstHandle, _super);
240
+ function ConstHandle(id, value) {
241
+ return _super.call(this, id, value) || this;
242
+ }
243
+ ConstHandle.prototype.dispose = function () { };
244
+ return ConstHandle;
245
+ }(Handle));
246
+ var HandleStore = /*#__PURE__*/ (function () {
247
+ function HandleStore() {
248
+ this._values = [
249
+ undefined,
250
+ HandleStore.UNDEFINED,
251
+ HandleStore.NULL,
252
+ HandleStore.FALSE,
253
+ HandleStore.TRUE,
254
+ HandleStore.GLOBAL
255
+ ];
256
+ this._next = HandleStore.MIN_ID;
257
+ }
258
+ HandleStore.prototype.push = function (value) {
259
+ var h;
260
+ var next = this._next;
261
+ var values = this._values;
262
+ if (next < values.length) {
263
+ h = values[next];
264
+ h.value = value;
265
+ }
266
+ else {
267
+ h = new Handle(next, value);
268
+ values[next] = h;
269
+ }
270
+ this._next++;
271
+ return h;
272
+ };
273
+ HandleStore.prototype.erase = function (start, end) {
274
+ this._next = start;
275
+ var values = this._values;
276
+ for (var i = start; i < end; ++i) {
277
+ values[i].dispose();
278
+ }
279
+ };
280
+ HandleStore.prototype.get = function (id) {
281
+ return this._values[id];
282
+ };
283
+ HandleStore.prototype.swap = function (a, b) {
284
+ var values = this._values;
285
+ var h = values[a];
286
+ values[a] = values[b];
287
+ values[a].id = Number(a);
288
+ values[b] = h;
289
+ h.id = Number(b);
290
+ };
291
+ HandleStore.prototype.dispose = function () {
292
+ this._values.length = HandleStore.MIN_ID;
293
+ this._next = HandleStore.MIN_ID;
294
+ };
295
+ HandleStore.UNDEFINED = new ConstHandle(1 /* GlobalHandle.UNDEFINED */, undefined);
296
+ HandleStore.NULL = new ConstHandle(2 /* GlobalHandle.NULL */, null);
297
+ HandleStore.FALSE = new ConstHandle(3 /* GlobalHandle.FALSE */, false);
298
+ HandleStore.TRUE = new ConstHandle(4 /* GlobalHandle.TRUE */, true);
299
+ HandleStore.GLOBAL = new ConstHandle(5 /* GlobalHandle.GLOBAL */, _global);
300
+ HandleStore.MIN_ID = 6;
301
+ return HandleStore;
302
+ }());
303
+
304
+ var HandleScope = /*#__PURE__*/ (function () {
305
+ function HandleScope(handleStore, id, parentScope, start, end) {
306
+ if (end === void 0) { end = start; }
307
+ this.handleStore = handleStore;
308
+ this.id = id;
309
+ this.parent = parentScope;
310
+ this.child = null;
311
+ if (parentScope !== null)
312
+ parentScope.child = this;
313
+ this.start = start;
314
+ this.end = end;
315
+ this._escapeCalled = false;
316
+ this.callbackInfo = {
317
+ thiz: undefined,
318
+ data: 0,
319
+ args: undefined,
320
+ fn: undefined
321
+ };
322
+ }
323
+ HandleScope.prototype.add = function (value) {
324
+ var h = this.handleStore.push(value);
325
+ this.end++;
326
+ return h;
327
+ };
328
+ HandleScope.prototype.addExternal = function (data) {
329
+ return this.add(new External(data));
330
+ };
331
+ HandleScope.prototype.dispose = function () {
332
+ if (this._escapeCalled)
333
+ this._escapeCalled = false;
334
+ if (this.start === this.end)
335
+ return;
336
+ this.handleStore.erase(this.start, this.end);
337
+ };
338
+ HandleScope.prototype.escape = function (handle) {
339
+ if (this._escapeCalled)
340
+ return null;
341
+ this._escapeCalled = true;
342
+ if (handle < this.start || handle >= this.end) {
343
+ return null;
344
+ }
345
+ this.handleStore.swap(handle, this.start);
346
+ var h = this.handleStore.get(this.start);
347
+ this.start++;
348
+ this.parent.end++;
349
+ return h;
350
+ };
351
+ HandleScope.prototype.escapeCalled = function () {
352
+ return this._escapeCalled;
353
+ };
354
+ return HandleScope;
355
+ }());
356
+
357
+ var ScopeStore = /*#__PURE__*/ (function () {
358
+ function ScopeStore() {
359
+ this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID);
360
+ this.currentScope = this._rootScope;
361
+ this._values = [undefined];
362
+ }
363
+ ScopeStore.prototype.get = function (id) {
364
+ return this._values[id];
365
+ };
366
+ ScopeStore.prototype.openScope = function (envObject) {
367
+ var currentScope = this.currentScope;
368
+ var scope = currentScope.child;
369
+ if (scope !== null) {
370
+ scope.start = scope.end = currentScope.end;
371
+ }
372
+ else {
373
+ var id = currentScope.id + 1;
374
+ scope = new HandleScope(envObject.ctx.handleStore, id, currentScope, currentScope.end);
375
+ this._values[id] = scope;
376
+ }
377
+ this.currentScope = scope;
378
+ envObject.openHandleScopes++;
379
+ return scope;
380
+ };
381
+ ScopeStore.prototype.closeScope = function (envObject) {
382
+ if (envObject.openHandleScopes === 0)
383
+ return;
384
+ var scope = this.currentScope;
385
+ this.currentScope = scope.parent;
386
+ scope.dispose();
387
+ envObject.openHandleScopes--;
388
+ };
389
+ ScopeStore.prototype.dispose = function () {
390
+ this.currentScope = this._rootScope;
391
+ this._values.length = 1;
392
+ };
393
+ return ScopeStore;
394
+ }());
395
+
396
+ var RefTracker = /*#__PURE__*/ (function () {
397
+ function RefTracker() {
398
+ this._next = null;
399
+ this._prev = null;
400
+ }
401
+ /** @virtual */
402
+ RefTracker.prototype.dispose = function () { };
403
+ /** @virtual */
404
+ RefTracker.prototype.finalize = function () { };
405
+ RefTracker.prototype.link = function (list) {
406
+ this._prev = list;
407
+ this._next = list._next;
408
+ if (this._next !== null) {
409
+ this._next._prev = this;
410
+ }
411
+ list._next = this;
412
+ };
413
+ RefTracker.prototype.unlink = function () {
414
+ if (this._prev !== null) {
415
+ this._prev._next = this._next;
416
+ }
417
+ if (this._next !== null) {
418
+ this._next._prev = this._prev;
419
+ }
420
+ this._prev = null;
421
+ this._next = null;
422
+ };
423
+ RefTracker.finalizeAll = function (list) {
424
+ while (list._next !== null) {
425
+ list._next.finalize();
426
+ }
427
+ };
428
+ return RefTracker;
429
+ }());
430
+
431
+ var Finalizer = /*#__PURE__*/ (function () {
432
+ function Finalizer(envObject, _finalizeCallback, _finalizeData, _finalizeHint) {
433
+ if (_finalizeCallback === void 0) { _finalizeCallback = 0; }
434
+ if (_finalizeData === void 0) { _finalizeData = 0; }
435
+ if (_finalizeHint === void 0) { _finalizeHint = 0; }
436
+ this.envObject = envObject;
437
+ this._finalizeCallback = _finalizeCallback;
438
+ this._finalizeData = _finalizeData;
439
+ this._finalizeHint = _finalizeHint;
440
+ this._makeDynCall_vppp = envObject.makeDynCall_vppp;
441
+ }
442
+ Finalizer.prototype.callback = function () { return this._finalizeCallback; };
443
+ Finalizer.prototype.data = function () { return this._finalizeData; };
444
+ Finalizer.prototype.hint = function () { return this._finalizeHint; };
445
+ Finalizer.prototype.resetEnv = function () {
446
+ this.envObject = undefined;
447
+ };
448
+ Finalizer.prototype.resetFinalizer = function () {
449
+ this._finalizeCallback = 0;
450
+ this._finalizeData = 0;
451
+ this._finalizeHint = 0;
452
+ };
453
+ Finalizer.prototype.callFinalizer = function () {
454
+ var finalize_callback = this._finalizeCallback;
455
+ var finalize_data = this._finalizeData;
456
+ var finalize_hint = this._finalizeHint;
457
+ this.resetFinalizer();
458
+ if (!finalize_callback)
459
+ return;
460
+ var fini = Number(finalize_callback);
461
+ if (!this.envObject) {
462
+ this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
463
+ }
464
+ else {
465
+ this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
466
+ }
467
+ };
468
+ Finalizer.prototype.dispose = function () {
469
+ this.envObject = undefined;
470
+ this._makeDynCall_vppp = undefined;
471
+ };
472
+ return Finalizer;
473
+ }());
474
+
475
+ var TrackedFinalizer = /*#__PURE__*/ (function (_super) {
476
+ __extends(TrackedFinalizer, _super);
477
+ function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
478
+ var _this = _super.call(this) || this;
479
+ _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
480
+ return _this;
481
+ }
482
+ TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) {
483
+ var finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
484
+ finalizer.link(envObject.finalizing_reflist);
485
+ return finalizer;
486
+ };
487
+ TrackedFinalizer.prototype.data = function () {
488
+ return this._finalizer.data();
489
+ };
490
+ TrackedFinalizer.prototype.dispose = function () {
491
+ if (!this._finalizer)
492
+ return;
493
+ this.unlink();
494
+ this._finalizer.envObject.dequeueFinalizer(this);
495
+ this._finalizer.dispose();
496
+ this._finalizer = undefined;
497
+ _super.prototype.dispose.call(this);
498
+ };
499
+ TrackedFinalizer.prototype.finalize = function () {
500
+ this.unlink();
501
+ var error;
502
+ var caught = false;
503
+ try {
504
+ this._finalizer.callFinalizer();
505
+ }
506
+ catch (err) {
507
+ caught = true;
508
+ error = err;
509
+ }
510
+ this.dispose();
511
+ if (caught) {
512
+ throw error;
513
+ }
514
+ };
515
+ return TrackedFinalizer;
516
+ }(RefTracker));
517
+
518
+ function throwNodeApiVersionError(moduleName, moduleApiVersion) {
519
+ 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.");
520
+ throw new Error(errorMessage);
521
+ }
522
+ function handleThrow(envObject, value) {
523
+ if (envObject.terminatedOrTerminating()) {
524
+ return;
525
+ }
526
+ throw value;
527
+ }
528
+ var Env = /*#__PURE__*/ (function () {
529
+ function Env(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) {
530
+ this.ctx = ctx;
531
+ this.moduleApiVersion = moduleApiVersion;
532
+ this.makeDynCall_vppp = makeDynCall_vppp;
533
+ this.makeDynCall_vp = makeDynCall_vp;
534
+ this.abort = abort;
535
+ this.openHandleScopes = 0;
536
+ this.instanceData = null;
537
+ this.tryCatch = new TryCatch();
538
+ this.refs = 1;
539
+ this.reflist = new RefTracker();
540
+ this.finalizing_reflist = new RefTracker();
541
+ this.pendingFinalizers = [];
542
+ this.lastError = {
543
+ errorCode: 0 /* napi_status.napi_ok */,
544
+ engineErrorCode: 0,
545
+ engineReserved: 0
546
+ };
547
+ this.inGcFinalizer = false;
548
+ this._bindingMap = new WeakMap();
549
+ this.id = 0;
550
+ }
551
+ /** @virtual */
552
+ Env.prototype.canCallIntoJs = function () {
553
+ return true;
554
+ };
555
+ Env.prototype.terminatedOrTerminating = function () {
556
+ return !this.canCallIntoJs();
557
+ };
558
+ Env.prototype.ref = function () {
559
+ this.refs++;
560
+ };
561
+ Env.prototype.unref = function () {
562
+ this.refs--;
563
+ if (this.refs === 0) {
564
+ this.dispose();
565
+ }
566
+ };
567
+ Env.prototype.ensureHandle = function (value) {
568
+ return this.ctx.ensureHandle(value);
569
+ };
570
+ Env.prototype.ensureHandleId = function (value) {
571
+ return this.ensureHandle(value).id;
572
+ };
573
+ Env.prototype.clearLastError = function () {
574
+ var lastError = this.lastError;
575
+ if (lastError.errorCode !== 0 /* napi_status.napi_ok */)
576
+ lastError.errorCode = 0 /* napi_status.napi_ok */;
577
+ if (lastError.engineErrorCode !== 0)
578
+ lastError.engineErrorCode = 0;
579
+ if (lastError.engineReserved !== 0)
580
+ lastError.engineReserved = 0;
581
+ return 0 /* napi_status.napi_ok */;
582
+ };
583
+ Env.prototype.setLastError = function (error_code, engine_error_code, engine_reserved) {
584
+ if (engine_error_code === void 0) { engine_error_code = 0; }
585
+ if (engine_reserved === void 0) { engine_reserved = 0; }
586
+ var lastError = this.lastError;
587
+ if (lastError.errorCode !== error_code)
588
+ lastError.errorCode = error_code;
589
+ if (lastError.engineErrorCode !== engine_error_code)
590
+ lastError.engineErrorCode = engine_error_code;
591
+ if (lastError.engineReserved !== engine_reserved)
592
+ lastError.engineReserved = engine_reserved;
593
+ return error_code;
594
+ };
595
+ Env.prototype.getReturnStatus = function () {
596
+ return !this.tryCatch.hasCaught() ? 0 /* napi_status.napi_ok */ : this.setLastError(10 /* napi_status.napi_pending_exception */);
597
+ };
598
+ Env.prototype.callIntoModule = function (fn, handleException) {
599
+ if (handleException === void 0) { handleException = handleThrow; }
600
+ var openHandleScopesBefore = this.openHandleScopes;
601
+ this.clearLastError();
602
+ var r = fn(this);
603
+ if (openHandleScopesBefore !== this.openHandleScopes) {
604
+ this.abort('open_handle_scopes != open_handle_scopes_before');
605
+ }
606
+ if (this.tryCatch.hasCaught()) {
607
+ var err = this.tryCatch.extractException();
608
+ handleException(this, err);
609
+ }
610
+ return r;
611
+ };
612
+ Env.prototype.invokeFinalizerFromGC = function (finalizer) {
613
+ if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
614
+ this.enqueueFinalizer(finalizer);
615
+ }
616
+ else {
617
+ var saved = this.inGcFinalizer;
618
+ this.inGcFinalizer = true;
619
+ try {
620
+ finalizer.finalize();
621
+ }
622
+ finally {
623
+ this.inGcFinalizer = saved;
624
+ }
625
+ }
626
+ };
627
+ Env.prototype.checkGCAccess = function () {
628
+ if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) {
629
+ this.abort('Finalizer is calling a function that may affect GC state.\n' +
630
+ 'The finalizers are run directly from GC and must not affect GC ' +
631
+ 'state.\n' +
632
+ 'Use `node_api_post_finalizer` from inside of the finalizer to work ' +
633
+ 'around this issue.\n' +
634
+ 'It schedules the call as a new task in the event loop.');
635
+ }
636
+ };
637
+ /** @virtual */
638
+ Env.prototype.enqueueFinalizer = function (finalizer) {
639
+ if (this.pendingFinalizers.indexOf(finalizer) === -1) {
640
+ this.pendingFinalizers.push(finalizer);
641
+ }
642
+ };
643
+ /** @virtual */
644
+ Env.prototype.dequeueFinalizer = function (finalizer) {
645
+ var index = this.pendingFinalizers.indexOf(finalizer);
646
+ if (index !== -1) {
647
+ this.pendingFinalizers.splice(index, 1);
648
+ }
649
+ };
650
+ /** @virtual */
651
+ Env.prototype.deleteMe = function () {
652
+ RefTracker.finalizeAll(this.finalizing_reflist);
653
+ RefTracker.finalizeAll(this.reflist);
654
+ this.tryCatch.extractException();
655
+ this.ctx.envStore.remove(this.id);
656
+ };
657
+ Env.prototype.dispose = function () {
658
+ if (this.id === 0)
659
+ return;
660
+ this.deleteMe();
661
+ this.finalizing_reflist.dispose();
662
+ this.reflist.dispose();
663
+ this.id = 0;
664
+ };
665
+ Env.prototype.initObjectBinding = function (value) {
666
+ var binding = {
667
+ wrapped: 0,
668
+ tag: null
669
+ };
670
+ this._bindingMap.set(value, binding);
671
+ return binding;
672
+ };
673
+ Env.prototype.getObjectBinding = function (value) {
674
+ if (this._bindingMap.has(value)) {
675
+ return this._bindingMap.get(value);
676
+ }
677
+ return this.initObjectBinding(value);
678
+ };
679
+ Env.prototype.setInstanceData = function (data, finalize_cb, finalize_hint) {
680
+ if (this.instanceData) {
681
+ this.instanceData.dispose();
682
+ }
683
+ this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
684
+ };
685
+ Env.prototype.getInstanceData = function () {
686
+ return this.instanceData ? this.instanceData.data() : 0;
687
+ };
688
+ return Env;
689
+ }());
690
+ var NodeEnv = /*#__PURE__*/ (function (_super) {
691
+ __extends(NodeEnv, _super);
692
+ function NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
693
+ var _this = _super.call(this, ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) || this;
694
+ _this.filename = filename;
695
+ _this.nodeBinding = nodeBinding;
696
+ _this.destructing = false;
697
+ _this.finalizationScheduled = false;
698
+ return _this;
699
+ }
700
+ NodeEnv.prototype.deleteMe = function () {
701
+ this.destructing = true;
702
+ this.drainFinalizerQueue();
703
+ _super.prototype.deleteMe.call(this);
704
+ };
705
+ NodeEnv.prototype.canCallIntoJs = function () {
706
+ return _super.prototype.canCallIntoJs.call(this) && this.ctx.canCallIntoJs();
707
+ };
708
+ NodeEnv.prototype.triggerFatalException = function (err) {
709
+ if (this.nodeBinding) {
710
+ this.nodeBinding.napi.fatalException(err);
711
+ }
712
+ else {
713
+ if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') {
714
+ var handled = process._fatalException(err);
715
+ if (!handled) {
716
+ console.error(err);
717
+ process.exit(1);
718
+ }
719
+ }
720
+ else {
721
+ throw err;
722
+ }
723
+ }
724
+ };
725
+ NodeEnv.prototype.callbackIntoModule = function (enforceUncaughtExceptionPolicy, fn) {
726
+ return this.callIntoModule(fn, function (envObject, err) {
727
+ if (envObject.terminatedOrTerminating()) {
728
+ return;
729
+ }
730
+ var hasProcess = typeof process === 'object' && process !== null;
731
+ var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
732
+ if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
733
+ var warn = hasProcess && typeof process.emitWarning === 'function'
734
+ ? process.emitWarning
735
+ : function (warning, type, code) {
736
+ if (warning instanceof Error) {
737
+ console.warn(warning.toString());
738
+ }
739
+ else {
740
+ var prefix = code ? "[".concat(code, "] ") : '';
741
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
742
+ console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
743
+ }
744
+ };
745
+ 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');
746
+ return;
747
+ }
748
+ envObject.triggerFatalException(err);
749
+ });
750
+ };
751
+ NodeEnv.prototype.callFinalizer = function (cb, data, hint) {
752
+ this.callFinalizerInternal(1, cb, data, hint);
753
+ };
754
+ NodeEnv.prototype.callFinalizerInternal = function (forceUncaught, cb, data, hint) {
755
+ var f = this.makeDynCall_vppp(cb);
756
+ var env = this.id;
757
+ var scope = this.ctx.openScope(this);
758
+ try {
759
+ this.callbackIntoModule(Boolean(forceUncaught), function () { f(env, data, hint); });
760
+ }
761
+ finally {
762
+ this.ctx.closeScope(this, scope);
763
+ }
764
+ };
765
+ NodeEnv.prototype.enqueueFinalizer = function (finalizer) {
766
+ var _this = this;
767
+ _super.prototype.enqueueFinalizer.call(this, finalizer);
768
+ if (!this.finalizationScheduled && !this.destructing) {
769
+ this.finalizationScheduled = true;
770
+ this.ref();
771
+ _setImmediate(function () {
772
+ _this.finalizationScheduled = false;
773
+ _this.unref();
774
+ _this.drainFinalizerQueue();
775
+ });
776
+ }
777
+ };
778
+ NodeEnv.prototype.drainFinalizerQueue = function () {
779
+ while (this.pendingFinalizers.length > 0) {
780
+ var refTracker = this.pendingFinalizers.shift();
781
+ refTracker.finalize();
782
+ }
783
+ };
784
+ return NodeEnv;
785
+ }(Env));
786
+ function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
787
+ moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion;
788
+ // Validate module_api_version.
789
+ if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
790
+ moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
791
+ }
792
+ else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
793
+ throwNodeApiVersionError(filename, moduleApiVersion);
794
+ }
795
+ var env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
796
+ ctx.envStore.add(env);
797
+ ctx.addCleanupHook(env, function () { env.unref(); }, 0);
798
+ return env;
799
+ }
800
+
801
+ var EmnapiError = /*#__PURE__*/ (function (_super) {
802
+ __extends(EmnapiError, _super);
803
+ function EmnapiError(message) {
804
+ var _newTarget = this.constructor;
805
+ var _this = _super.call(this, message) || this;
806
+ var ErrorConstructor = _newTarget;
807
+ var proto = ErrorConstructor.prototype;
808
+ if (!(_this instanceof EmnapiError)) {
809
+ var setPrototypeOf = Object.setPrototypeOf;
810
+ if (typeof setPrototypeOf === 'function') {
811
+ setPrototypeOf.call(Object, _this, proto);
812
+ }
813
+ else {
814
+ // eslint-disable-next-line no-proto
815
+ _this.__proto__ = proto;
816
+ }
817
+ if (typeof Error.captureStackTrace === 'function') {
818
+ Error.captureStackTrace(_this, ErrorConstructor);
819
+ }
820
+ }
821
+ return _this;
822
+ }
823
+ return EmnapiError;
824
+ }(Error));
825
+ Object.defineProperty(EmnapiError.prototype, 'name', {
826
+ configurable: true,
827
+ writable: true,
828
+ value: 'EmnapiError'
829
+ });
830
+ var NotSupportWeakRefError = /*#__PURE__*/ (function (_super) {
831
+ __extends(NotSupportWeakRefError, _super);
832
+ function NotSupportWeakRefError(api, message) {
833
+ return _super.call(this, "".concat(api, ": The current runtime does not support \"FinalizationRegistry\" and \"WeakRef\".").concat(message ? " ".concat(message) : '')) || this;
834
+ }
835
+ return NotSupportWeakRefError;
836
+ }(EmnapiError));
837
+ Object.defineProperty(NotSupportWeakRefError.prototype, 'name', {
838
+ configurable: true,
839
+ writable: true,
840
+ value: 'NotSupportWeakRefError'
841
+ });
842
+ var NotSupportBufferError = /*#__PURE__*/ (function (_super) {
843
+ __extends(NotSupportBufferError, _super);
844
+ function NotSupportBufferError(api, message) {
845
+ return _super.call(this, "".concat(api, ": The current runtime does not support \"Buffer\". Consider using buffer polyfill to make sure `globalThis.Buffer` is defined.").concat(message ? " ".concat(message) : '')) || this;
846
+ }
847
+ return NotSupportBufferError;
848
+ }(EmnapiError));
849
+ Object.defineProperty(NotSupportBufferError.prototype, 'name', {
850
+ configurable: true,
851
+ writable: true,
852
+ value: 'NotSupportBufferError'
853
+ });
854
+
855
+ var StrongRef = /*#__PURE__*/ (function () {
856
+ function StrongRef(value) {
857
+ this._value = value;
858
+ }
859
+ StrongRef.prototype.deref = function () {
860
+ return this._value;
861
+ };
862
+ StrongRef.prototype.dispose = function () {
863
+ this._value = undefined;
864
+ };
865
+ return StrongRef;
866
+ }());
867
+ var Persistent = /*#__PURE__*/ (function () {
868
+ function Persistent(value) {
869
+ this._ref = new StrongRef(value);
870
+ }
871
+ Persistent.prototype.setWeak = function (param, callback) {
872
+ if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef)
873
+ return;
874
+ var value = this._ref.deref();
875
+ try {
876
+ Persistent._registry.register(value, this, this);
877
+ var weakRef = new WeakRef(value);
878
+ this._ref.dispose();
879
+ this._ref = weakRef;
880
+ this._param = param;
881
+ this._callback = callback;
882
+ }
883
+ catch (err) {
884
+ if (typeof value === 'symbol') ;
885
+ else {
886
+ throw err;
887
+ }
888
+ }
889
+ };
890
+ Persistent.prototype.clearWeak = function () {
891
+ if (!supportFinalizer || this._ref === undefined)
892
+ return;
893
+ if (this._ref instanceof WeakRef) {
894
+ try {
895
+ Persistent._registry.unregister(this);
896
+ }
897
+ catch (_) { }
898
+ this._param = undefined;
899
+ this._callback = undefined;
900
+ var value = this._ref.deref();
901
+ if (value === undefined) {
902
+ this._ref = value;
903
+ }
904
+ else {
905
+ this._ref = new StrongRef(value);
906
+ }
907
+ }
908
+ };
909
+ Persistent.prototype.reset = function () {
910
+ if (supportFinalizer) {
911
+ try {
912
+ Persistent._registry.unregister(this);
913
+ }
914
+ catch (_) { }
915
+ }
916
+ this._param = undefined;
917
+ this._callback = undefined;
918
+ if (this._ref instanceof StrongRef) {
919
+ this._ref.dispose();
920
+ }
921
+ this._ref = undefined;
922
+ };
923
+ Persistent.prototype.isEmpty = function () {
924
+ return this._ref === undefined;
925
+ };
926
+ Persistent.prototype.deref = function () {
927
+ if (this._ref === undefined)
928
+ return undefined;
929
+ return this._ref.deref();
930
+ };
931
+ Persistent._registry = supportFinalizer
932
+ ? new FinalizationRegistry(function (value) {
933
+ value._ref = undefined;
934
+ var callback = value._callback;
935
+ var param = value._param;
936
+ value._callback = undefined;
937
+ value._param = undefined;
938
+ if (typeof callback === 'function') {
939
+ callback(param);
940
+ }
941
+ })
942
+ : undefined;
943
+ return Persistent;
944
+ }());
945
+
946
+ var ReferenceOwnership;
947
+ (function (ReferenceOwnership) {
948
+ ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
949
+ ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
950
+ })(ReferenceOwnership || (ReferenceOwnership = {}));
951
+ function canBeHeldWeakly(value) {
952
+ return value.isObject() || value.isFunction() || value.isSymbol();
953
+ }
954
+ var Reference = /*#__PURE__*/ (function (_super) {
955
+ __extends(Reference, _super);
956
+ function Reference(envObject, handle_id, initialRefcount, ownership) {
957
+ var _this = _super.call(this) || this;
958
+ _this.envObject = envObject;
959
+ _this._refcount = initialRefcount;
960
+ _this._ownership = ownership;
961
+ var handle = envObject.ctx.handleStore.get(handle_id);
962
+ _this.canBeWeak = canBeHeldWeakly(handle);
963
+ _this.persistent = new Persistent(handle.value);
964
+ _this.id = 0;
965
+ if (initialRefcount === 0) {
966
+ _this._setWeak();
967
+ }
968
+ return _this;
969
+ }
970
+ Reference.weakCallback = function (ref) {
971
+ ref.persistent.reset();
972
+ ref.invokeFinalizerFromGC();
973
+ };
974
+ Reference.create = function (envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
975
+ var ref = new Reference(envObject, handle_id, initialRefcount, ownership);
976
+ envObject.ctx.refStore.add(ref);
977
+ ref.link(envObject.reflist);
978
+ return ref;
979
+ };
980
+ Reference.prototype.ref = function () {
981
+ if (this.persistent.isEmpty()) {
982
+ return 0;
983
+ }
984
+ if (++this._refcount === 1 && this.canBeWeak) {
985
+ this.persistent.clearWeak();
986
+ }
987
+ return this._refcount;
988
+ };
989
+ Reference.prototype.unref = function () {
990
+ if (this.persistent.isEmpty() || this._refcount === 0) {
991
+ return 0;
992
+ }
993
+ if (--this._refcount === 0) {
994
+ this._setWeak();
995
+ }
996
+ return this._refcount;
997
+ };
998
+ Reference.prototype.get = function (envObject) {
999
+ if (envObject === void 0) { envObject = this.envObject; }
1000
+ if (this.persistent.isEmpty()) {
1001
+ return 0;
1002
+ }
1003
+ var obj = this.persistent.deref();
1004
+ var handle = envObject.ensureHandle(obj);
1005
+ return handle.id;
1006
+ };
1007
+ /** @virtual */
1008
+ Reference.prototype.resetFinalizer = function () { };
1009
+ /** @virtual */
1010
+ Reference.prototype.data = function () { return 0; };
1011
+ Reference.prototype.refcount = function () { return this._refcount; };
1012
+ Reference.prototype.ownership = function () { return this._ownership; };
1013
+ /** @virtual */
1014
+ Reference.prototype.callUserFinalizer = function () { };
1015
+ /** @virtual */
1016
+ Reference.prototype.invokeFinalizerFromGC = function () {
1017
+ this.finalize();
1018
+ };
1019
+ Reference.prototype._setWeak = function () {
1020
+ if (this.canBeWeak) {
1021
+ this.persistent.setWeak(this, Reference.weakCallback);
1022
+ }
1023
+ else {
1024
+ this.persistent.reset();
1025
+ }
1026
+ };
1027
+ Reference.prototype.finalize = function () {
1028
+ this.persistent.reset();
1029
+ var deleteMe = this._ownership === ReferenceOwnership.kRuntime;
1030
+ this.unlink();
1031
+ this.callUserFinalizer();
1032
+ if (deleteMe) {
1033
+ this.dispose();
1034
+ }
1035
+ };
1036
+ Reference.prototype.dispose = function () {
1037
+ if (this.id === 0)
1038
+ return;
1039
+ this.unlink();
1040
+ this.persistent.reset();
1041
+ this.envObject.ctx.refStore.remove(this.id);
1042
+ _super.prototype.dispose.call(this);
1043
+ this.envObject = undefined;
1044
+ this.id = 0;
1045
+ };
1046
+ return Reference;
1047
+ }(RefTracker));
1048
+ var ReferenceWithData = /*#__PURE__*/ (function (_super) {
1049
+ __extends(ReferenceWithData, _super);
1050
+ function ReferenceWithData(envObject, value, initialRefcount, ownership, _data) {
1051
+ var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
1052
+ _this._data = _data;
1053
+ return _this;
1054
+ }
1055
+ ReferenceWithData.create = function (envObject, value, initialRefcount, ownership, data) {
1056
+ var reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
1057
+ envObject.ctx.refStore.add(reference);
1058
+ reference.link(envObject.reflist);
1059
+ return reference;
1060
+ };
1061
+ ReferenceWithData.prototype.data = function () {
1062
+ return this._data;
1063
+ };
1064
+ return ReferenceWithData;
1065
+ }(Reference));
1066
+ var ReferenceWithFinalizer = /*#__PURE__*/ (function (_super) {
1067
+ __extends(ReferenceWithFinalizer, _super);
1068
+ function ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1069
+ var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
1070
+ _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
1071
+ return _this;
1072
+ }
1073
+ ReferenceWithFinalizer.create = function (envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1074
+ var reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1075
+ envObject.ctx.refStore.add(reference);
1076
+ reference.link(envObject.finalizing_reflist);
1077
+ return reference;
1078
+ };
1079
+ ReferenceWithFinalizer.prototype.resetFinalizer = function () {
1080
+ this._finalizer.resetFinalizer();
1081
+ };
1082
+ ReferenceWithFinalizer.prototype.data = function () {
1083
+ return this._finalizer.data();
1084
+ };
1085
+ ReferenceWithFinalizer.prototype.callUserFinalizer = function () {
1086
+ this._finalizer.callFinalizer();
1087
+ };
1088
+ ReferenceWithFinalizer.prototype.invokeFinalizerFromGC = function () {
1089
+ this._finalizer.envObject.invokeFinalizerFromGC(this);
1090
+ };
1091
+ ReferenceWithFinalizer.prototype.dispose = function () {
1092
+ if (!this._finalizer)
1093
+ return;
1094
+ this._finalizer.envObject.dequeueFinalizer(this);
1095
+ this._finalizer.dispose();
1096
+ _super.prototype.dispose.call(this);
1097
+ this._finalizer = undefined;
1098
+ };
1099
+ return ReferenceWithFinalizer;
1100
+ }(Reference));
1101
+
1102
+ var Deferred = /*#__PURE__*/ (function () {
1103
+ function Deferred(ctx, value) {
1104
+ this.id = 0;
1105
+ this.ctx = ctx;
1106
+ this.value = value;
1107
+ }
1108
+ Deferred.create = function (ctx, value) {
1109
+ var deferred = new Deferred(ctx, value);
1110
+ ctx.deferredStore.add(deferred);
1111
+ return deferred;
1112
+ };
1113
+ Deferred.prototype.resolve = function (value) {
1114
+ this.value.resolve(value);
1115
+ this.dispose();
1116
+ };
1117
+ Deferred.prototype.reject = function (reason) {
1118
+ this.value.reject(reason);
1119
+ this.dispose();
1120
+ };
1121
+ Deferred.prototype.dispose = function () {
1122
+ this.ctx.deferredStore.remove(this.id);
1123
+ this.id = 0;
1124
+ this.value = null;
1125
+ this.ctx = null;
1126
+ };
1127
+ return Deferred;
1128
+ }());
1129
+
1130
+ var Store = /*#__PURE__*/ (function () {
1131
+ function Store() {
1132
+ this._values = [undefined];
1133
+ this._values.length = 4;
1134
+ this._size = 1;
1135
+ this._freeList = [];
1136
+ }
1137
+ Store.prototype.add = function (value) {
1138
+ var id;
1139
+ if (this._freeList.length) {
1140
+ id = this._freeList.shift();
1141
+ }
1142
+ else {
1143
+ id = this._size;
1144
+ this._size++;
1145
+ var capacity = this._values.length;
1146
+ if (id >= capacity) {
1147
+ this._values.length = capacity + (capacity >> 1) + 16;
1148
+ }
1149
+ }
1150
+ value.id = id;
1151
+ this._values[id] = value;
1152
+ };
1153
+ Store.prototype.get = function (id) {
1154
+ return this._values[id];
1155
+ };
1156
+ Store.prototype.has = function (id) {
1157
+ return this._values[id] !== undefined;
1158
+ };
1159
+ Store.prototype.remove = function (id) {
1160
+ var value = this._values[id];
1161
+ if (value) {
1162
+ value.id = 0;
1163
+ this._values[id] = undefined;
1164
+ this._freeList.push(Number(id));
1165
+ }
1166
+ };
1167
+ Store.prototype.dispose = function () {
1168
+ for (var i = 1; i < this._size; ++i) {
1169
+ var value = this._values[i];
1170
+ value === null || value === void 0 ? void 0 : value.dispose();
1171
+ }
1172
+ this._values = [undefined];
1173
+ this._size = 1;
1174
+ this._freeList = [];
1175
+ };
1176
+ return Store;
1177
+ }());
1178
+
1179
+ var CleanupHookCallback = /*#__PURE__*/ (function () {
1180
+ function CleanupHookCallback(envObject, fn, arg, order) {
1181
+ this.envObject = envObject;
1182
+ this.fn = fn;
1183
+ this.arg = arg;
1184
+ this.order = order;
1185
+ }
1186
+ return CleanupHookCallback;
1187
+ }());
1188
+ var CleanupQueue = /*#__PURE__*/ (function () {
1189
+ function CleanupQueue() {
1190
+ this._cleanupHooks = [];
1191
+ this._cleanupHookCounter = 0;
1192
+ }
1193
+ CleanupQueue.prototype.empty = function () {
1194
+ return this._cleanupHooks.length === 0;
1195
+ };
1196
+ CleanupQueue.prototype.add = function (envObject, fn, arg) {
1197
+ if (this._cleanupHooks.filter(function (hook) { return (hook.envObject === envObject && hook.fn === fn && hook.arg === arg); }).length > 0) {
1198
+ throw new Error('Can not add same fn and arg twice');
1199
+ }
1200
+ this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++));
1201
+ };
1202
+ CleanupQueue.prototype.remove = function (envObject, fn, arg) {
1203
+ for (var i = 0; i < this._cleanupHooks.length; ++i) {
1204
+ var hook = this._cleanupHooks[i];
1205
+ if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) {
1206
+ this._cleanupHooks.splice(i, 1);
1207
+ return;
1208
+ }
1209
+ }
1210
+ };
1211
+ CleanupQueue.prototype.drain = function () {
1212
+ var hooks = this._cleanupHooks.slice();
1213
+ hooks.sort(function (a, b) { return (b.order - a.order); });
1214
+ for (var i = 0; i < hooks.length; ++i) {
1215
+ var cb = hooks[i];
1216
+ if (typeof cb.fn === 'number') {
1217
+ cb.envObject.makeDynCall_vp(cb.fn)(cb.arg);
1218
+ }
1219
+ else {
1220
+ cb.fn(cb.arg);
1221
+ }
1222
+ this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1);
1223
+ }
1224
+ };
1225
+ CleanupQueue.prototype.dispose = function () {
1226
+ this._cleanupHooks.length = 0;
1227
+ this._cleanupHookCounter = 0;
1228
+ };
1229
+ return CleanupQueue;
1230
+ }());
1231
+ var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () {
1232
+ function NodejsWaitingRequestCounter() {
1233
+ this.refHandle = new _MessageChannel().port1;
1234
+ this.count = 0;
1235
+ }
1236
+ NodejsWaitingRequestCounter.prototype.increase = function () {
1237
+ if (this.count === 0) {
1238
+ this.refHandle.ref();
1239
+ }
1240
+ this.count++;
1241
+ };
1242
+ NodejsWaitingRequestCounter.prototype.decrease = function () {
1243
+ if (this.count === 0)
1244
+ return;
1245
+ if (this.count === 1) {
1246
+ this.refHandle.unref();
1247
+ }
1248
+ this.count--;
1249
+ };
1250
+ return NodejsWaitingRequestCounter;
1251
+ }());
1252
+ var Context = /*#__PURE__*/ (function () {
1253
+ function Context() {
1254
+ var _this = this;
1255
+ this._isStopping = false;
1256
+ this._canCallIntoJs = true;
1257
+ this._suppressDestroy = false;
1258
+ this.envStore = new Store();
1259
+ this.scopeStore = new ScopeStore();
1260
+ this.refStore = new Store();
1261
+ this.deferredStore = new Store();
1262
+ this.handleStore = new HandleStore();
1263
+ this.feature = {
1264
+ supportReflect: supportReflect,
1265
+ supportFinalizer: supportFinalizer,
1266
+ supportWeakSymbol: supportWeakSymbol,
1267
+ supportBigInt: supportBigInt,
1268
+ supportNewFunction: supportNewFunction,
1269
+ canSetFunctionName: canSetFunctionName,
1270
+ setImmediate: _setImmediate,
1271
+ Buffer: _Buffer,
1272
+ MessageChannel: _MessageChannel
1273
+ };
1274
+ this.cleanupQueue = new CleanupQueue();
1275
+ if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1276
+ this.refCounter = new NodejsWaitingRequestCounter();
1277
+ process.once('beforeExit', function () {
1278
+ if (!_this._suppressDestroy) {
1279
+ _this.destroy();
1280
+ }
1281
+ });
1282
+ }
1283
+ }
1284
+ /**
1285
+ * Suppress the destroy on `beforeExit` event in Node.js.
1286
+ * Call this method if you want to keep the context and
1287
+ * all associated {@link Env | Env} alive,
1288
+ * this also means that cleanup hooks will not be called.
1289
+ * After call this method, you should call
1290
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
1291
+ */
1292
+ Context.prototype.suppressDestroy = function () {
1293
+ this._suppressDestroy = true;
1294
+ };
1295
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
1296
+ Context.prototype.getRuntimeVersions = function () {
1297
+ return {
1298
+ version: version,
1299
+ NODE_API_SUPPORTED_VERSION_MAX: NODE_API_SUPPORTED_VERSION_MAX,
1300
+ NAPI_VERSION_EXPERIMENTAL: NAPI_VERSION_EXPERIMENTAL,
1301
+ NODE_API_DEFAULT_MODULE_API_VERSION: NODE_API_DEFAULT_MODULE_API_VERSION
1302
+ };
1303
+ };
1304
+ Context.prototype.createNotSupportWeakRefError = function (api, message) {
1305
+ return new NotSupportWeakRefError(api, message);
1306
+ };
1307
+ Context.prototype.createNotSupportBufferError = function (api, message) {
1308
+ return new NotSupportBufferError(api, message);
1309
+ };
1310
+ Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership) {
1311
+ return Reference.create(envObject, handle_id, initialRefcount, ownership);
1312
+ };
1313
+ Context.prototype.createReferenceWithData = function (envObject, handle_id, initialRefcount, ownership, data) {
1314
+ return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
1315
+ };
1316
+ Context.prototype.createReferenceWithFinalizer = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1317
+ if (finalize_callback === void 0) { finalize_callback = 0; }
1318
+ if (finalize_data === void 0) { finalize_data = 0; }
1319
+ if (finalize_hint === void 0) { finalize_hint = 0; }
1320
+ return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1321
+ };
1322
+ Context.prototype.createDeferred = function (value) {
1323
+ return Deferred.create(this, value);
1324
+ };
1325
+ Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1326
+ return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1327
+ };
1328
+ Context.prototype.createTrackedFinalizer = function (envObject, finalize_callback, finalize_data, finalize_hint) {
1329
+ return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint);
1330
+ };
1331
+ Context.prototype.getCurrentScope = function () {
1332
+ return this.scopeStore.currentScope;
1333
+ };
1334
+ Context.prototype.addToCurrentScope = function (value) {
1335
+ return this.scopeStore.currentScope.add(value);
1336
+ };
1337
+ Context.prototype.openScope = function (envObject) {
1338
+ return this.scopeStore.openScope(envObject);
1339
+ };
1340
+ Context.prototype.closeScope = function (envObject, _scope) {
1341
+ this.scopeStore.closeScope(envObject);
1342
+ };
1343
+ Context.prototype.ensureHandle = function (value) {
1344
+ switch (value) {
1345
+ case undefined: return HandleStore.UNDEFINED;
1346
+ case null: return HandleStore.NULL;
1347
+ case true: return HandleStore.TRUE;
1348
+ case false: return HandleStore.FALSE;
1349
+ case _global: return HandleStore.GLOBAL;
1350
+ }
1351
+ return this.addToCurrentScope(value);
1352
+ };
1353
+ Context.prototype.addCleanupHook = function (envObject, fn, arg) {
1354
+ this.cleanupQueue.add(envObject, fn, arg);
1355
+ };
1356
+ Context.prototype.removeCleanupHook = function (envObject, fn, arg) {
1357
+ this.cleanupQueue.remove(envObject, fn, arg);
1358
+ };
1359
+ Context.prototype.runCleanup = function () {
1360
+ while (!this.cleanupQueue.empty()) {
1361
+ this.cleanupQueue.drain();
1362
+ }
1363
+ };
1364
+ Context.prototype.increaseWaitingRequestCounter = function () {
1365
+ var _a;
1366
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase();
1367
+ };
1368
+ Context.prototype.decreaseWaitingRequestCounter = function () {
1369
+ var _a;
1370
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease();
1371
+ };
1372
+ Context.prototype.setCanCallIntoJs = function (value) {
1373
+ this._canCallIntoJs = value;
1374
+ };
1375
+ Context.prototype.setStopping = function (value) {
1376
+ this._isStopping = value;
1377
+ };
1378
+ Context.prototype.canCallIntoJs = function () {
1379
+ return this._canCallIntoJs && !this._isStopping;
1380
+ };
1381
+ /**
1382
+ * Destroy the context and call cleanup hooks.
1383
+ * Associated {@link Env | Env} will be destroyed.
1384
+ */
1385
+ Context.prototype.destroy = function () {
1386
+ this.setStopping(true);
1387
+ this.setCanCallIntoJs(false);
1388
+ this.runCleanup();
1389
+ };
1390
+ return Context;
1391
+ }());
1392
+ var defaultContext;
1393
+ function createContext() {
1394
+ return new Context();
1395
+ }
1396
+ function getDefaultContext() {
1397
+ if (!defaultContext) {
1398
+ defaultContext = createContext();
1399
+ }
1400
+ return defaultContext;
1401
+ }
1402
+
1403
+ export { ConstHandle, Context, Deferred, EmnapiError, Env, External, 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, RefTracker, Reference, ReferenceOwnership, ReferenceWithData, ReferenceWithFinalizer, ScopeStore, Store, TrackedFinalizer, TryCatch, createContext, getDefaultContext, getExternalValue, isExternal, isReferenceType, version };