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