Puyiiii commited on
Commit
bc8130e
·
verified ·
1 Parent(s): b8ee04d

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. astra_scene_test/X_03/node_modules/@emnapi/core/LICENSE +21 -0
  2. astra_scene_test/X_03/node_modules/@emnapi/core/README.md +1 -0
  3. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.cjs.js +0 -0
  4. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts +420 -0
  5. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.js +0 -0
  6. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.d.mts +420 -0
  7. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.d.ts +422 -0
  8. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js +0 -0
  9. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.js +0 -0
  10. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts +420 -0
  11. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.min.js +0 -0
  12. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.min.mjs +0 -0
  13. astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.mjs +0 -0
  14. astra_scene_test/X_03/node_modules/@emnapi/core/index.js +5 -0
  15. astra_scene_test/X_03/node_modules/@emnapi/core/package.json +49 -0
  16. astra_scene_test/X_03/node_modules/@emnapi/runtime/LICENSE +21 -0
  17. astra_scene_test/X_03/node_modules/@emnapi/runtime/README.md +1 -0
  18. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.cjs.js +1398 -0
  19. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts +671 -0
  20. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js +1 -0
  21. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.d.mts +671 -0
  22. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.d.ts +673 -0
  23. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js +1457 -0
  24. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts +426 -0
  25. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.iife.js +1528 -0
  26. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.js +1529 -0
  27. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts +671 -0
  28. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.min.js +1 -0
  29. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.min.mjs +1 -0
  30. astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.mjs +1367 -0
  31. astra_scene_test/X_03/node_modules/@emnapi/runtime/index.js +5 -0
  32. astra_scene_test/X_03/node_modules/@emnapi/runtime/package.json +48 -0
  33. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
  34. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/README.md +203 -0
  35. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js +894 -0
  36. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts +272 -0
  37. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.js +1 -0
  38. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.mts +272 -0
  39. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +274 -0
  40. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js +942 -0
  41. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +954 -0
  42. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts +272 -0
  43. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.js +1 -0
  44. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.mjs +1 -0
  45. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.mjs +889 -0
  46. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/index.js +5 -0
  47. astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/package.json +50 -0
  48. astra_scene_test/X_03/node_modules/@rolldown/binding-darwin-arm64/README.md +3 -0
  49. astra_scene_test/X_03/node_modules/@rolldown/binding-darwin-arm64/package.json +37 -0
  50. astra_scene_test/X_03/node_modules/@rolldown/pluginutils/LICENSE +21 -0
astra_scene_test/X_03/node_modules/@emnapi/core/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Toyobayashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
astra_scene_test/X_03/node_modules/@emnapi/core/README.md ADDED
@@ -0,0 +1 @@
 
 
1
+ See [https://github.com/toyobayashi/emnapi](https://github.com/toyobayashi/emnapi)
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.cjs.js ADDED
The diff for this file is too large to render. See raw diff
 
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+
3
+ import type { Context } from '@emnapi/runtime';
4
+ import type { ReferenceOwnership } from '@emnapi/runtime';
5
+ import type { Worker as Worker_2 } from 'worker_threads';
6
+
7
+ /** @public */
8
+ export declare type BaseCreateOptions = {
9
+ filename?: string
10
+ nodeBinding?: NodeBinding
11
+ reuseWorker?: ThreadManagerOptionsMain['reuseWorker']
12
+ asyncWorkPoolSize?: number
13
+ waitThreadStart?: MainThreadBaseOptions['waitThreadStart']
14
+ onCreateWorker?: (info: CreateWorkerInfo) => any
15
+ print?: (str: string) => void
16
+ printErr?: (str: string) => void
17
+ postMessage?: (msg: any) => any
18
+ }
19
+
20
+ /** @public */
21
+ export declare interface BaseOptions {
22
+ wasi: WASIInstance;
23
+ version?: 'preview1';
24
+ wasm64?: boolean;
25
+ }
26
+
27
+ /** @public */
28
+ export declare interface ChildThreadOptions extends BaseOptions {
29
+ childThread: true;
30
+ postMessage?: (data: any) => void;
31
+ }
32
+
33
+ /** @public */
34
+ export declare interface CleanupThreadPayload {
35
+ tid: number;
36
+ }
37
+
38
+ /** @public */
39
+ export declare interface CommandInfo<T extends CommandType> {
40
+ type: T;
41
+ payload: CommandPayloadMap[T];
42
+ }
43
+
44
+ /** @public */
45
+ export declare interface CommandPayloadMap {
46
+ load: LoadPayload;
47
+ loaded: LoadedPayload;
48
+ start: StartPayload;
49
+ 'cleanup-thread': CleanupThreadPayload;
50
+ 'terminate-all-threads': TerminateAllThreadsPayload;
51
+ 'spawn-thread': SpawnThreadPayload;
52
+ }
53
+
54
+ /** @public */
55
+ export declare type CommandType = keyof CommandPayloadMap;
56
+
57
+ /** @public */
58
+ export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
59
+
60
+ /** @public */
61
+ export declare function createNapiModule (
62
+ options: CreateOptions
63
+ ): NapiModule
64
+
65
+ /** @public */
66
+ export declare type CreateOptions = BaseCreateOptions & ({
67
+ context: Context
68
+ childThread?: boolean
69
+ } | {
70
+ context?: Context
71
+ childThread: true
72
+ })
73
+
74
+ /** @public */
75
+ export declare interface CreateWorkerInfo {
76
+ type: 'thread' | 'async-work'
77
+ name: string
78
+ }
79
+
80
+ /** @public */
81
+ export declare interface InitOptions {
82
+ instance: WebAssembly.Instance
83
+ module: WebAssembly.Module
84
+ memory?: WebAssembly.Memory
85
+ table?: WebAssembly.Table
86
+ }
87
+
88
+ export declare type InputType = string | URL | Response | BufferSource | WebAssembly.Module;
89
+
90
+ /** @public */
91
+ export declare interface InstantiatedSource extends LoadedSource {
92
+ napiModule: NapiModule;
93
+ }
94
+
95
+ /** @public */
96
+ export declare function instantiateNapiModule(
97
+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
98
+ wasmInput: InputType | Promise<InputType>, options: InstantiateOptions): Promise<InstantiatedSource>;
99
+
100
+ /** @public */
101
+ export declare function instantiateNapiModuleSync(wasmInput: BufferSource | WebAssembly.Module, options: InstantiateOptions): InstantiatedSource;
102
+
103
+ /** @public */
104
+ export declare type InstantiateOptions = CreateOptions & LoadOptions;
105
+
106
+ /** @public */
107
+ export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
108
+
109
+ /** @public */
110
+ export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
111
+
112
+ /** @public */
113
+ export declare interface LoadedPayload {
114
+ }
115
+
116
+ /** @public */
117
+ export declare interface LoadedSource extends WebAssembly.WebAssemblyInstantiatedSource {
118
+ usedInstance: WebAssembly.Instance;
119
+ }
120
+
121
+ /** @public */
122
+ export declare function loadNapiModule(napiModule: NapiModule,
123
+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
124
+ wasmInput: InputType | Promise<InputType>, options?: LoadOptions): Promise<LoadedSource>;
125
+
126
+ /** @public */
127
+ export declare function loadNapiModuleSync(napiModule: NapiModule, wasmInput: BufferSource | WebAssembly.Module, options?: LoadOptions): LoadedSource;
128
+
129
+ /** @public */
130
+ export declare interface LoadOptions {
131
+ wasi?: WASIInstance;
132
+ overwriteImports?: (importObject: WebAssembly.Imports) => WebAssembly.Imports;
133
+ beforeInit?: (source: WebAssembly.WebAssemblyInstantiatedSource) => void;
134
+ getMemory?: (exports: WebAssembly.Exports) => WebAssembly.Memory;
135
+ getTable?: (exports: WebAssembly.Exports) => WebAssembly.Table;
136
+ }
137
+
138
+ /** @public */
139
+ export declare interface LoadPayload {
140
+ wasmModule: WebAssembly.Module;
141
+ wasmMemory: WebAssembly.Memory;
142
+ sab?: Int32Array;
143
+ }
144
+
145
+ /** @public */
146
+ export declare interface MainThreadBaseOptions extends BaseOptions {
147
+ waitThreadStart?: boolean | number;
148
+ }
149
+
150
+ /** @public */
151
+ export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
152
+
153
+ /** @public */
154
+ export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
155
+ }
156
+
157
+ /** @public */
158
+ export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
159
+ threadManager?: ThreadManager | (() => ThreadManager);
160
+ }
161
+
162
+ /** @public */
163
+ export declare interface MessageEventData<T extends CommandType> {
164
+ __emnapi__: CommandInfo<T>;
165
+ }
166
+
167
+ /** @public */
168
+ export declare class MessageHandler extends ThreadMessageHandler {
169
+ napiModule: NapiModule | undefined;
170
+ constructor(options: MessageHandlerOptions);
171
+ instantiate(data: LoadPayload): InstantiatedSource | PromiseLike<InstantiatedSource>;
172
+ handle(e: WorkerMessageEvent): void;
173
+ }
174
+
175
+ /** @public */
176
+ export declare interface MessageHandlerOptions extends ThreadMessageHandlerOptions {
177
+ onLoad: (data: LoadPayload) => InstantiatedSource | PromiseLike<InstantiatedSource>;
178
+ }
179
+
180
+ /** @public */
181
+ export declare interface NapiModule {
182
+ imports: {
183
+ env: any
184
+ napi: any
185
+ emnapi: any
186
+ }
187
+ exports: any
188
+ loaded: boolean
189
+ filename: string
190
+ childThread: boolean
191
+ emnapi: {
192
+ syncMemory<T extends ArrayBuffer | ArrayBufferView> (
193
+ js_to_wasm: boolean,
194
+ arrayBufferOrView: T,
195
+ offset?: number,
196
+ len?: number
197
+ ): T
198
+ getMemoryAddress (arrayBufferOrView: ArrayBuffer | ArrayBufferView): PointerInfo
199
+ addSendListener (worker: any): boolean
200
+ }
201
+
202
+ init (options: InitOptions): any
203
+ initWorker (arg: number, func: [number, number]): void
204
+ postMessage?: (msg: any) => any
205
+
206
+ waitThreadStart: boolean | number
207
+ /* Excluded from this release type: PThread */}
208
+
209
+ /** @public */
210
+ export declare interface NodeBinding {
211
+ node: {
212
+ emitAsyncInit: Function
213
+ emitAsyncDestroy: Function
214
+ makeCallback: Function
215
+ }
216
+ napi: {
217
+ asyncInit: Function
218
+ asyncDestroy: Function
219
+ makeCallback: Function
220
+ }
221
+ }
222
+
223
+ /** @public */
224
+ export declare interface PointerInfo {
225
+ address: number
226
+ ownership: ReferenceOwnership
227
+ runtimeAllocated: 0 | 1
228
+ }
229
+
230
+ /** @public */
231
+ export declare interface ReuseWorkerOptions {
232
+ /**
233
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
234
+ */
235
+ size: number;
236
+ /**
237
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
238
+ */
239
+ strict?: boolean;
240
+ }
241
+
242
+ /** @public */
243
+ export declare interface SpawnThreadPayload {
244
+ startArg: number;
245
+ errorOrTid: number;
246
+ }
247
+
248
+ /** @public */
249
+ export declare interface StartPayload {
250
+ tid: number;
251
+ arg: number;
252
+ sab?: Int32Array;
253
+ }
254
+
255
+ /** @public */
256
+ export declare interface StartResult {
257
+ exitCode: number;
258
+ instance: WebAssembly.Instance;
259
+ }
260
+
261
+ /** @public */
262
+ export declare interface TerminateAllThreadsPayload {
263
+ }
264
+
265
+ /** @public */
266
+ export declare class ThreadManager {
267
+ unusedWorkers: WorkerLike[];
268
+ runningWorkers: WorkerLike[];
269
+ pthreads: Record<number, WorkerLike>;
270
+ get nextWorkerID(): number;
271
+ wasmModule: WebAssembly.Module | null;
272
+ wasmMemory: WebAssembly.Memory | null;
273
+ private readonly messageEvents;
274
+ private readonly _childThread;
275
+ private readonly _onCreateWorker;
276
+ private readonly _reuseWorker;
277
+ private readonly _beforeLoad?;
278
+ /* Excluded from this release type: printErr */
279
+ threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
280
+ constructor(options: ThreadManagerOptions);
281
+ init(): void;
282
+ initMainThread(): void;
283
+ private preparePool;
284
+ shouldPreloadWorkers(): boolean;
285
+ loadWasmModuleToAllWorkers(): Promise<WorkerLike[]>;
286
+ preloadWorkers(): Promise<WorkerLike[]>;
287
+ setup(wasmModule: WebAssembly.Module, wasmMemory: WebAssembly.Memory): void;
288
+ markId(worker: WorkerLike): number;
289
+ returnWorkerToPool(worker: WorkerLike): void;
290
+ loadWasmModuleToWorker(worker: WorkerLike, sab?: Int32Array): Promise<WorkerLike>;
291
+ allocateUnusedWorker(): WorkerLike;
292
+ getNewWorker(sab?: Int32Array): WorkerLike | undefined;
293
+ cleanThread(worker: WorkerLike, tid: number, force?: boolean): void;
294
+ terminateWorker(worker: WorkerLike): void;
295
+ terminateAllThreads(): void;
296
+ addMessageEventListener(worker: WorkerLike, onMessage: (e: WorkerMessageEvent) => void): () => void;
297
+ fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
298
+ }
299
+
300
+ /** @public */
301
+ export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
302
+
303
+ /** @public */
304
+ export declare interface ThreadManagerOptionsBase {
305
+ printErr?: (message: string) => void;
306
+ threadSpawn?: (startArg: number, errorOrTid?: number) => number;
307
+ }
308
+
309
+ /** @public */
310
+ export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
311
+ childThread: true;
312
+ }
313
+
314
+ /** @public */
315
+ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
316
+ beforeLoad?: (worker: WorkerLike) => any;
317
+ reuseWorker?: boolean | number | ReuseWorkerOptions;
318
+ onCreateWorker: WorkerFactory;
319
+ childThread?: false;
320
+ }
321
+
322
+ /** @public */
323
+ export declare class ThreadMessageHandler {
324
+ protected instance: WebAssembly.Instance | undefined;
325
+ private messagesBeforeLoad;
326
+ protected postMessage: (message: any) => void;
327
+ protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
328
+ protected onError: (error: Error, type: WorkerMessageType) => void;
329
+ constructor(options?: ThreadMessageHandlerOptions);
330
+ /** @virtual */
331
+ instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
332
+ /** @virtual */
333
+ handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
334
+ private _load;
335
+ private _start;
336
+ protected _loaded(err: Error | null, source: WebAssembly.WebAssemblyInstantiatedSource | null, payload: LoadPayload): void;
337
+ protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
338
+ }
339
+
340
+ /** @public */
341
+ export declare interface ThreadMessageHandlerOptions {
342
+ onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
343
+ onError?: (error: Error, type: WorkerMessageType) => void;
344
+ postMessage?: (message: any) => void;
345
+ }
346
+
347
+ export declare const version: string;
348
+
349
+ /** @public */
350
+ export declare interface WASIInstance {
351
+ readonly wasiImport?: Record<string, any>;
352
+ initialize(instance: object): void;
353
+ start(instance: object): number;
354
+ getImportObject?(): any;
355
+ }
356
+
357
+ /** @public */
358
+ export declare class WASIThreads {
359
+ PThread: ThreadManager | undefined;
360
+ private wasmMemory;
361
+ private wasmInstance;
362
+ private readonly threadSpawn;
363
+ readonly childThread: boolean;
364
+ private readonly postMessage;
365
+ readonly wasi: WASIInstance;
366
+ constructor(options: WASIThreadsOptions);
367
+ getImportObject(): {
368
+ wasi: WASIThreadsImports;
369
+ };
370
+ setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
371
+ preloadWorkers(): Promise<WorkerLike[]>;
372
+ /**
373
+ * It's ok to call this method to a WASI command module.
374
+ *
375
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
376
+ *
377
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
378
+ */
379
+ initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
380
+ /**
381
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
382
+ * ```js
383
+ * this.initialize(instance, module, memory)
384
+ * this.wasi.start(instance)
385
+ * ```
386
+ */
387
+ start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
388
+ terminateAllThreads(): void;
389
+ }
390
+
391
+ /** @public */
392
+ export declare interface WASIThreadsImports {
393
+ 'thread-spawn': (startArg: number, errorOrTid?: number) => number;
394
+ }
395
+
396
+ /** @public */
397
+ export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
398
+
399
+ /** @public */
400
+ export declare type WorkerFactory = (ctx: {
401
+ type: string;
402
+ name: string;
403
+ }) => WorkerLike;
404
+
405
+ /** @public */
406
+ export declare type WorkerLike = (Worker | Worker_2) & {
407
+ whenLoaded?: Promise<WorkerLike>;
408
+ loaded?: boolean;
409
+ __emnapi_tid?: number;
410
+ };
411
+
412
+ /** @public */
413
+ export declare interface WorkerMessageEvent<T = any> {
414
+ data: T;
415
+ }
416
+
417
+ /** @public */
418
+ export declare type WorkerMessageType = 'load' | 'start';
419
+
420
+ export { }
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.js ADDED
The diff for this file is too large to render. See raw diff
 
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.d.mts ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+
3
+ import type { Context } from '@emnapi/runtime';
4
+ import type { ReferenceOwnership } from '@emnapi/runtime';
5
+ import type { Worker as Worker_2 } from 'worker_threads';
6
+
7
+ /** @public */
8
+ export declare type BaseCreateOptions = {
9
+ filename?: string
10
+ nodeBinding?: NodeBinding
11
+ reuseWorker?: ThreadManagerOptionsMain['reuseWorker']
12
+ asyncWorkPoolSize?: number
13
+ waitThreadStart?: MainThreadBaseOptions['waitThreadStart']
14
+ onCreateWorker?: (info: CreateWorkerInfo) => any
15
+ print?: (str: string) => void
16
+ printErr?: (str: string) => void
17
+ postMessage?: (msg: any) => any
18
+ }
19
+
20
+ /** @public */
21
+ export declare interface BaseOptions {
22
+ wasi: WASIInstance;
23
+ version?: 'preview1';
24
+ wasm64?: boolean;
25
+ }
26
+
27
+ /** @public */
28
+ export declare interface ChildThreadOptions extends BaseOptions {
29
+ childThread: true;
30
+ postMessage?: (data: any) => void;
31
+ }
32
+
33
+ /** @public */
34
+ export declare interface CleanupThreadPayload {
35
+ tid: number;
36
+ }
37
+
38
+ /** @public */
39
+ export declare interface CommandInfo<T extends CommandType> {
40
+ type: T;
41
+ payload: CommandPayloadMap[T];
42
+ }
43
+
44
+ /** @public */
45
+ export declare interface CommandPayloadMap {
46
+ load: LoadPayload;
47
+ loaded: LoadedPayload;
48
+ start: StartPayload;
49
+ 'cleanup-thread': CleanupThreadPayload;
50
+ 'terminate-all-threads': TerminateAllThreadsPayload;
51
+ 'spawn-thread': SpawnThreadPayload;
52
+ }
53
+
54
+ /** @public */
55
+ export declare type CommandType = keyof CommandPayloadMap;
56
+
57
+ /** @public */
58
+ export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
59
+
60
+ /** @public */
61
+ export declare function createNapiModule (
62
+ options: CreateOptions
63
+ ): NapiModule
64
+
65
+ /** @public */
66
+ export declare type CreateOptions = BaseCreateOptions & ({
67
+ context: Context
68
+ childThread?: boolean
69
+ } | {
70
+ context?: Context
71
+ childThread: true
72
+ })
73
+
74
+ /** @public */
75
+ export declare interface CreateWorkerInfo {
76
+ type: 'thread' | 'async-work'
77
+ name: string
78
+ }
79
+
80
+ /** @public */
81
+ export declare interface InitOptions {
82
+ instance: WebAssembly.Instance
83
+ module: WebAssembly.Module
84
+ memory?: WebAssembly.Memory
85
+ table?: WebAssembly.Table
86
+ }
87
+
88
+ export declare type InputType = string | URL | Response | BufferSource | WebAssembly.Module;
89
+
90
+ /** @public */
91
+ export declare interface InstantiatedSource extends LoadedSource {
92
+ napiModule: NapiModule;
93
+ }
94
+
95
+ /** @public */
96
+ export declare function instantiateNapiModule(
97
+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
98
+ wasmInput: InputType | Promise<InputType>, options: InstantiateOptions): Promise<InstantiatedSource>;
99
+
100
+ /** @public */
101
+ export declare function instantiateNapiModuleSync(wasmInput: BufferSource | WebAssembly.Module, options: InstantiateOptions): InstantiatedSource;
102
+
103
+ /** @public */
104
+ export declare type InstantiateOptions = CreateOptions & LoadOptions;
105
+
106
+ /** @public */
107
+ export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
108
+
109
+ /** @public */
110
+ export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
111
+
112
+ /** @public */
113
+ export declare interface LoadedPayload {
114
+ }
115
+
116
+ /** @public */
117
+ export declare interface LoadedSource extends WebAssembly.WebAssemblyInstantiatedSource {
118
+ usedInstance: WebAssembly.Instance;
119
+ }
120
+
121
+ /** @public */
122
+ export declare function loadNapiModule(napiModule: NapiModule,
123
+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
124
+ wasmInput: InputType | Promise<InputType>, options?: LoadOptions): Promise<LoadedSource>;
125
+
126
+ /** @public */
127
+ export declare function loadNapiModuleSync(napiModule: NapiModule, wasmInput: BufferSource | WebAssembly.Module, options?: LoadOptions): LoadedSource;
128
+
129
+ /** @public */
130
+ export declare interface LoadOptions {
131
+ wasi?: WASIInstance;
132
+ overwriteImports?: (importObject: WebAssembly.Imports) => WebAssembly.Imports;
133
+ beforeInit?: (source: WebAssembly.WebAssemblyInstantiatedSource) => void;
134
+ getMemory?: (exports: WebAssembly.Exports) => WebAssembly.Memory;
135
+ getTable?: (exports: WebAssembly.Exports) => WebAssembly.Table;
136
+ }
137
+
138
+ /** @public */
139
+ export declare interface LoadPayload {
140
+ wasmModule: WebAssembly.Module;
141
+ wasmMemory: WebAssembly.Memory;
142
+ sab?: Int32Array;
143
+ }
144
+
145
+ /** @public */
146
+ export declare interface MainThreadBaseOptions extends BaseOptions {
147
+ waitThreadStart?: boolean | number;
148
+ }
149
+
150
+ /** @public */
151
+ export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
152
+
153
+ /** @public */
154
+ export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
155
+ }
156
+
157
+ /** @public */
158
+ export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
159
+ threadManager?: ThreadManager | (() => ThreadManager);
160
+ }
161
+
162
+ /** @public */
163
+ export declare interface MessageEventData<T extends CommandType> {
164
+ __emnapi__: CommandInfo<T>;
165
+ }
166
+
167
+ /** @public */
168
+ export declare class MessageHandler extends ThreadMessageHandler {
169
+ napiModule: NapiModule | undefined;
170
+ constructor(options: MessageHandlerOptions);
171
+ instantiate(data: LoadPayload): InstantiatedSource | PromiseLike<InstantiatedSource>;
172
+ handle(e: WorkerMessageEvent): void;
173
+ }
174
+
175
+ /** @public */
176
+ export declare interface MessageHandlerOptions extends ThreadMessageHandlerOptions {
177
+ onLoad: (data: LoadPayload) => InstantiatedSource | PromiseLike<InstantiatedSource>;
178
+ }
179
+
180
+ /** @public */
181
+ export declare interface NapiModule {
182
+ imports: {
183
+ env: any
184
+ napi: any
185
+ emnapi: any
186
+ }
187
+ exports: any
188
+ loaded: boolean
189
+ filename: string
190
+ childThread: boolean
191
+ emnapi: {
192
+ syncMemory<T extends ArrayBuffer | ArrayBufferView> (
193
+ js_to_wasm: boolean,
194
+ arrayBufferOrView: T,
195
+ offset?: number,
196
+ len?: number
197
+ ): T
198
+ getMemoryAddress (arrayBufferOrView: ArrayBuffer | ArrayBufferView): PointerInfo
199
+ addSendListener (worker: any): boolean
200
+ }
201
+
202
+ init (options: InitOptions): any
203
+ initWorker (arg: number, func: [number, number]): void
204
+ postMessage?: (msg: any) => any
205
+
206
+ waitThreadStart: boolean | number
207
+ /* Excluded from this release type: PThread */}
208
+
209
+ /** @public */
210
+ export declare interface NodeBinding {
211
+ node: {
212
+ emitAsyncInit: Function
213
+ emitAsyncDestroy: Function
214
+ makeCallback: Function
215
+ }
216
+ napi: {
217
+ asyncInit: Function
218
+ asyncDestroy: Function
219
+ makeCallback: Function
220
+ }
221
+ }
222
+
223
+ /** @public */
224
+ export declare interface PointerInfo {
225
+ address: number
226
+ ownership: ReferenceOwnership
227
+ runtimeAllocated: 0 | 1
228
+ }
229
+
230
+ /** @public */
231
+ export declare interface ReuseWorkerOptions {
232
+ /**
233
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
234
+ */
235
+ size: number;
236
+ /**
237
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
238
+ */
239
+ strict?: boolean;
240
+ }
241
+
242
+ /** @public */
243
+ export declare interface SpawnThreadPayload {
244
+ startArg: number;
245
+ errorOrTid: number;
246
+ }
247
+
248
+ /** @public */
249
+ export declare interface StartPayload {
250
+ tid: number;
251
+ arg: number;
252
+ sab?: Int32Array;
253
+ }
254
+
255
+ /** @public */
256
+ export declare interface StartResult {
257
+ exitCode: number;
258
+ instance: WebAssembly.Instance;
259
+ }
260
+
261
+ /** @public */
262
+ export declare interface TerminateAllThreadsPayload {
263
+ }
264
+
265
+ /** @public */
266
+ export declare class ThreadManager {
267
+ unusedWorkers: WorkerLike[];
268
+ runningWorkers: WorkerLike[];
269
+ pthreads: Record<number, WorkerLike>;
270
+ get nextWorkerID(): number;
271
+ wasmModule: WebAssembly.Module | null;
272
+ wasmMemory: WebAssembly.Memory | null;
273
+ private readonly messageEvents;
274
+ private readonly _childThread;
275
+ private readonly _onCreateWorker;
276
+ private readonly _reuseWorker;
277
+ private readonly _beforeLoad?;
278
+ /* Excluded from this release type: printErr */
279
+ threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
280
+ constructor(options: ThreadManagerOptions);
281
+ init(): void;
282
+ initMainThread(): void;
283
+ private preparePool;
284
+ shouldPreloadWorkers(): boolean;
285
+ loadWasmModuleToAllWorkers(): Promise<WorkerLike[]>;
286
+ preloadWorkers(): Promise<WorkerLike[]>;
287
+ setup(wasmModule: WebAssembly.Module, wasmMemory: WebAssembly.Memory): void;
288
+ markId(worker: WorkerLike): number;
289
+ returnWorkerToPool(worker: WorkerLike): void;
290
+ loadWasmModuleToWorker(worker: WorkerLike, sab?: Int32Array): Promise<WorkerLike>;
291
+ allocateUnusedWorker(): WorkerLike;
292
+ getNewWorker(sab?: Int32Array): WorkerLike | undefined;
293
+ cleanThread(worker: WorkerLike, tid: number, force?: boolean): void;
294
+ terminateWorker(worker: WorkerLike): void;
295
+ terminateAllThreads(): void;
296
+ addMessageEventListener(worker: WorkerLike, onMessage: (e: WorkerMessageEvent) => void): () => void;
297
+ fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
298
+ }
299
+
300
+ /** @public */
301
+ export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
302
+
303
+ /** @public */
304
+ export declare interface ThreadManagerOptionsBase {
305
+ printErr?: (message: string) => void;
306
+ threadSpawn?: (startArg: number, errorOrTid?: number) => number;
307
+ }
308
+
309
+ /** @public */
310
+ export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
311
+ childThread: true;
312
+ }
313
+
314
+ /** @public */
315
+ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
316
+ beforeLoad?: (worker: WorkerLike) => any;
317
+ reuseWorker?: boolean | number | ReuseWorkerOptions;
318
+ onCreateWorker: WorkerFactory;
319
+ childThread?: false;
320
+ }
321
+
322
+ /** @public */
323
+ export declare class ThreadMessageHandler {
324
+ protected instance: WebAssembly.Instance | undefined;
325
+ private messagesBeforeLoad;
326
+ protected postMessage: (message: any) => void;
327
+ protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
328
+ protected onError: (error: Error, type: WorkerMessageType) => void;
329
+ constructor(options?: ThreadMessageHandlerOptions);
330
+ /** @virtual */
331
+ instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
332
+ /** @virtual */
333
+ handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
334
+ private _load;
335
+ private _start;
336
+ protected _loaded(err: Error | null, source: WebAssembly.WebAssemblyInstantiatedSource | null, payload: LoadPayload): void;
337
+ protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
338
+ }
339
+
340
+ /** @public */
341
+ export declare interface ThreadMessageHandlerOptions {
342
+ onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
343
+ onError?: (error: Error, type: WorkerMessageType) => void;
344
+ postMessage?: (message: any) => void;
345
+ }
346
+
347
+ export declare const version: string;
348
+
349
+ /** @public */
350
+ export declare interface WASIInstance {
351
+ readonly wasiImport?: Record<string, any>;
352
+ initialize(instance: object): void;
353
+ start(instance: object): number;
354
+ getImportObject?(): any;
355
+ }
356
+
357
+ /** @public */
358
+ export declare class WASIThreads {
359
+ PThread: ThreadManager | undefined;
360
+ private wasmMemory;
361
+ private wasmInstance;
362
+ private readonly threadSpawn;
363
+ readonly childThread: boolean;
364
+ private readonly postMessage;
365
+ readonly wasi: WASIInstance;
366
+ constructor(options: WASIThreadsOptions);
367
+ getImportObject(): {
368
+ wasi: WASIThreadsImports;
369
+ };
370
+ setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
371
+ preloadWorkers(): Promise<WorkerLike[]>;
372
+ /**
373
+ * It's ok to call this method to a WASI command module.
374
+ *
375
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
376
+ *
377
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
378
+ */
379
+ initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
380
+ /**
381
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
382
+ * ```js
383
+ * this.initialize(instance, module, memory)
384
+ * this.wasi.start(instance)
385
+ * ```
386
+ */
387
+ start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
388
+ terminateAllThreads(): void;
389
+ }
390
+
391
+ /** @public */
392
+ export declare interface WASIThreadsImports {
393
+ 'thread-spawn': (startArg: number, errorOrTid?: number) => number;
394
+ }
395
+
396
+ /** @public */
397
+ export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
398
+
399
+ /** @public */
400
+ export declare type WorkerFactory = (ctx: {
401
+ type: string;
402
+ name: string;
403
+ }) => WorkerLike;
404
+
405
+ /** @public */
406
+ export declare type WorkerLike = (Worker | Worker_2) & {
407
+ whenLoaded?: Promise<WorkerLike>;
408
+ loaded?: boolean;
409
+ __emnapi_tid?: number;
410
+ };
411
+
412
+ /** @public */
413
+ export declare interface WorkerMessageEvent<T = any> {
414
+ data: T;
415
+ }
416
+
417
+ /** @public */
418
+ export declare type WorkerMessageType = 'load' | 'start';
419
+
420
+ export { }
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.d.ts ADDED
@@ -0,0 +1,422 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+
3
+ import type { Context } from '@emnapi/runtime';
4
+ import type { ReferenceOwnership } from '@emnapi/runtime';
5
+ import type { Worker as Worker_2 } from 'worker_threads';
6
+
7
+ /** @public */
8
+ export declare type BaseCreateOptions = {
9
+ filename?: string
10
+ nodeBinding?: NodeBinding
11
+ reuseWorker?: ThreadManagerOptionsMain['reuseWorker']
12
+ asyncWorkPoolSize?: number
13
+ waitThreadStart?: MainThreadBaseOptions['waitThreadStart']
14
+ onCreateWorker?: (info: CreateWorkerInfo) => any
15
+ print?: (str: string) => void
16
+ printErr?: (str: string) => void
17
+ postMessage?: (msg: any) => any
18
+ }
19
+
20
+ /** @public */
21
+ export declare interface BaseOptions {
22
+ wasi: WASIInstance;
23
+ version?: 'preview1';
24
+ wasm64?: boolean;
25
+ }
26
+
27
+ /** @public */
28
+ export declare interface ChildThreadOptions extends BaseOptions {
29
+ childThread: true;
30
+ postMessage?: (data: any) => void;
31
+ }
32
+
33
+ /** @public */
34
+ export declare interface CleanupThreadPayload {
35
+ tid: number;
36
+ }
37
+
38
+ /** @public */
39
+ export declare interface CommandInfo<T extends CommandType> {
40
+ type: T;
41
+ payload: CommandPayloadMap[T];
42
+ }
43
+
44
+ /** @public */
45
+ export declare interface CommandPayloadMap {
46
+ load: LoadPayload;
47
+ loaded: LoadedPayload;
48
+ start: StartPayload;
49
+ 'cleanup-thread': CleanupThreadPayload;
50
+ 'terminate-all-threads': TerminateAllThreadsPayload;
51
+ 'spawn-thread': SpawnThreadPayload;
52
+ }
53
+
54
+ /** @public */
55
+ export declare type CommandType = keyof CommandPayloadMap;
56
+
57
+ /** @public */
58
+ export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
59
+
60
+ /** @public */
61
+ export declare function createNapiModule (
62
+ options: CreateOptions
63
+ ): NapiModule
64
+
65
+ /** @public */
66
+ export declare type CreateOptions = BaseCreateOptions & ({
67
+ context: Context
68
+ childThread?: boolean
69
+ } | {
70
+ context?: Context
71
+ childThread: true
72
+ })
73
+
74
+ /** @public */
75
+ export declare interface CreateWorkerInfo {
76
+ type: 'thread' | 'async-work'
77
+ name: string
78
+ }
79
+
80
+ /** @public */
81
+ export declare interface InitOptions {
82
+ instance: WebAssembly.Instance
83
+ module: WebAssembly.Module
84
+ memory?: WebAssembly.Memory
85
+ table?: WebAssembly.Table
86
+ }
87
+
88
+ export declare type InputType = string | URL | Response | BufferSource | WebAssembly.Module;
89
+
90
+ /** @public */
91
+ export declare interface InstantiatedSource extends LoadedSource {
92
+ napiModule: NapiModule;
93
+ }
94
+
95
+ /** @public */
96
+ export declare function instantiateNapiModule(
97
+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
98
+ wasmInput: InputType | Promise<InputType>, options: InstantiateOptions): Promise<InstantiatedSource>;
99
+
100
+ /** @public */
101
+ export declare function instantiateNapiModuleSync(wasmInput: BufferSource | WebAssembly.Module, options: InstantiateOptions): InstantiatedSource;
102
+
103
+ /** @public */
104
+ export declare type InstantiateOptions = CreateOptions & LoadOptions;
105
+
106
+ /** @public */
107
+ export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
108
+
109
+ /** @public */
110
+ export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
111
+
112
+ /** @public */
113
+ export declare interface LoadedPayload {
114
+ }
115
+
116
+ /** @public */
117
+ export declare interface LoadedSource extends WebAssembly.WebAssemblyInstantiatedSource {
118
+ usedInstance: WebAssembly.Instance;
119
+ }
120
+
121
+ /** @public */
122
+ export declare function loadNapiModule(napiModule: NapiModule,
123
+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
124
+ wasmInput: InputType | Promise<InputType>, options?: LoadOptions): Promise<LoadedSource>;
125
+
126
+ /** @public */
127
+ export declare function loadNapiModuleSync(napiModule: NapiModule, wasmInput: BufferSource | WebAssembly.Module, options?: LoadOptions): LoadedSource;
128
+
129
+ /** @public */
130
+ export declare interface LoadOptions {
131
+ wasi?: WASIInstance;
132
+ overwriteImports?: (importObject: WebAssembly.Imports) => WebAssembly.Imports;
133
+ beforeInit?: (source: WebAssembly.WebAssemblyInstantiatedSource) => void;
134
+ getMemory?: (exports: WebAssembly.Exports) => WebAssembly.Memory;
135
+ getTable?: (exports: WebAssembly.Exports) => WebAssembly.Table;
136
+ }
137
+
138
+ /** @public */
139
+ export declare interface LoadPayload {
140
+ wasmModule: WebAssembly.Module;
141
+ wasmMemory: WebAssembly.Memory;
142
+ sab?: Int32Array;
143
+ }
144
+
145
+ /** @public */
146
+ export declare interface MainThreadBaseOptions extends BaseOptions {
147
+ waitThreadStart?: boolean | number;
148
+ }
149
+
150
+ /** @public */
151
+ export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
152
+
153
+ /** @public */
154
+ export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
155
+ }
156
+
157
+ /** @public */
158
+ export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
159
+ threadManager?: ThreadManager | (() => ThreadManager);
160
+ }
161
+
162
+ /** @public */
163
+ export declare interface MessageEventData<T extends CommandType> {
164
+ __emnapi__: CommandInfo<T>;
165
+ }
166
+
167
+ /** @public */
168
+ export declare class MessageHandler extends ThreadMessageHandler {
169
+ napiModule: NapiModule | undefined;
170
+ constructor(options: MessageHandlerOptions);
171
+ instantiate(data: LoadPayload): InstantiatedSource | PromiseLike<InstantiatedSource>;
172
+ handle(e: WorkerMessageEvent): void;
173
+ }
174
+
175
+ /** @public */
176
+ export declare interface MessageHandlerOptions extends ThreadMessageHandlerOptions {
177
+ onLoad: (data: LoadPayload) => InstantiatedSource | PromiseLike<InstantiatedSource>;
178
+ }
179
+
180
+ /** @public */
181
+ export declare interface NapiModule {
182
+ imports: {
183
+ env: any
184
+ napi: any
185
+ emnapi: any
186
+ }
187
+ exports: any
188
+ loaded: boolean
189
+ filename: string
190
+ childThread: boolean
191
+ emnapi: {
192
+ syncMemory<T extends ArrayBuffer | ArrayBufferView> (
193
+ js_to_wasm: boolean,
194
+ arrayBufferOrView: T,
195
+ offset?: number,
196
+ len?: number
197
+ ): T
198
+ getMemoryAddress (arrayBufferOrView: ArrayBuffer | ArrayBufferView): PointerInfo
199
+ addSendListener (worker: any): boolean
200
+ }
201
+
202
+ init (options: InitOptions): any
203
+ initWorker (arg: number, func: [number, number]): void
204
+ postMessage?: (msg: any) => any
205
+
206
+ waitThreadStart: boolean | number
207
+ /* Excluded from this release type: PThread */}
208
+
209
+ /** @public */
210
+ export declare interface NodeBinding {
211
+ node: {
212
+ emitAsyncInit: Function
213
+ emitAsyncDestroy: Function
214
+ makeCallback: Function
215
+ }
216
+ napi: {
217
+ asyncInit: Function
218
+ asyncDestroy: Function
219
+ makeCallback: Function
220
+ }
221
+ }
222
+
223
+ /** @public */
224
+ export declare interface PointerInfo {
225
+ address: number
226
+ ownership: ReferenceOwnership
227
+ runtimeAllocated: 0 | 1
228
+ }
229
+
230
+ /** @public */
231
+ export declare interface ReuseWorkerOptions {
232
+ /**
233
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
234
+ */
235
+ size: number;
236
+ /**
237
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
238
+ */
239
+ strict?: boolean;
240
+ }
241
+
242
+ /** @public */
243
+ export declare interface SpawnThreadPayload {
244
+ startArg: number;
245
+ errorOrTid: number;
246
+ }
247
+
248
+ /** @public */
249
+ export declare interface StartPayload {
250
+ tid: number;
251
+ arg: number;
252
+ sab?: Int32Array;
253
+ }
254
+
255
+ /** @public */
256
+ export declare interface StartResult {
257
+ exitCode: number;
258
+ instance: WebAssembly.Instance;
259
+ }
260
+
261
+ /** @public */
262
+ export declare interface TerminateAllThreadsPayload {
263
+ }
264
+
265
+ /** @public */
266
+ export declare class ThreadManager {
267
+ unusedWorkers: WorkerLike[];
268
+ runningWorkers: WorkerLike[];
269
+ pthreads: Record<number, WorkerLike>;
270
+ get nextWorkerID(): number;
271
+ wasmModule: WebAssembly.Module | null;
272
+ wasmMemory: WebAssembly.Memory | null;
273
+ private readonly messageEvents;
274
+ private readonly _childThread;
275
+ private readonly _onCreateWorker;
276
+ private readonly _reuseWorker;
277
+ private readonly _beforeLoad?;
278
+ /* Excluded from this release type: printErr */
279
+ threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
280
+ constructor(options: ThreadManagerOptions);
281
+ init(): void;
282
+ initMainThread(): void;
283
+ private preparePool;
284
+ shouldPreloadWorkers(): boolean;
285
+ loadWasmModuleToAllWorkers(): Promise<WorkerLike[]>;
286
+ preloadWorkers(): Promise<WorkerLike[]>;
287
+ setup(wasmModule: WebAssembly.Module, wasmMemory: WebAssembly.Memory): void;
288
+ markId(worker: WorkerLike): number;
289
+ returnWorkerToPool(worker: WorkerLike): void;
290
+ loadWasmModuleToWorker(worker: WorkerLike, sab?: Int32Array): Promise<WorkerLike>;
291
+ allocateUnusedWorker(): WorkerLike;
292
+ getNewWorker(sab?: Int32Array): WorkerLike | undefined;
293
+ cleanThread(worker: WorkerLike, tid: number, force?: boolean): void;
294
+ terminateWorker(worker: WorkerLike): void;
295
+ terminateAllThreads(): void;
296
+ addMessageEventListener(worker: WorkerLike, onMessage: (e: WorkerMessageEvent) => void): () => void;
297
+ fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
298
+ }
299
+
300
+ /** @public */
301
+ export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
302
+
303
+ /** @public */
304
+ export declare interface ThreadManagerOptionsBase {
305
+ printErr?: (message: string) => void;
306
+ threadSpawn?: (startArg: number, errorOrTid?: number) => number;
307
+ }
308
+
309
+ /** @public */
310
+ export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
311
+ childThread: true;
312
+ }
313
+
314
+ /** @public */
315
+ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
316
+ beforeLoad?: (worker: WorkerLike) => any;
317
+ reuseWorker?: boolean | number | ReuseWorkerOptions;
318
+ onCreateWorker: WorkerFactory;
319
+ childThread?: false;
320
+ }
321
+
322
+ /** @public */
323
+ export declare class ThreadMessageHandler {
324
+ protected instance: WebAssembly.Instance | undefined;
325
+ private messagesBeforeLoad;
326
+ protected postMessage: (message: any) => void;
327
+ protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
328
+ protected onError: (error: Error, type: WorkerMessageType) => void;
329
+ constructor(options?: ThreadMessageHandlerOptions);
330
+ /** @virtual */
331
+ instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
332
+ /** @virtual */
333
+ handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
334
+ private _load;
335
+ private _start;
336
+ protected _loaded(err: Error | null, source: WebAssembly.WebAssemblyInstantiatedSource | null, payload: LoadPayload): void;
337
+ protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
338
+ }
339
+
340
+ /** @public */
341
+ export declare interface ThreadMessageHandlerOptions {
342
+ onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
343
+ onError?: (error: Error, type: WorkerMessageType) => void;
344
+ postMessage?: (message: any) => void;
345
+ }
346
+
347
+ export declare const version: string;
348
+
349
+ /** @public */
350
+ export declare interface WASIInstance {
351
+ readonly wasiImport?: Record<string, any>;
352
+ initialize(instance: object): void;
353
+ start(instance: object): number;
354
+ getImportObject?(): any;
355
+ }
356
+
357
+ /** @public */
358
+ export declare class WASIThreads {
359
+ PThread: ThreadManager | undefined;
360
+ private wasmMemory;
361
+ private wasmInstance;
362
+ private readonly threadSpawn;
363
+ readonly childThread: boolean;
364
+ private readonly postMessage;
365
+ readonly wasi: WASIInstance;
366
+ constructor(options: WASIThreadsOptions);
367
+ getImportObject(): {
368
+ wasi: WASIThreadsImports;
369
+ };
370
+ setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
371
+ preloadWorkers(): Promise<WorkerLike[]>;
372
+ /**
373
+ * It's ok to call this method to a WASI command module.
374
+ *
375
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
376
+ *
377
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
378
+ */
379
+ initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
380
+ /**
381
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
382
+ * ```js
383
+ * this.initialize(instance, module, memory)
384
+ * this.wasi.start(instance)
385
+ * ```
386
+ */
387
+ start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
388
+ terminateAllThreads(): void;
389
+ }
390
+
391
+ /** @public */
392
+ export declare interface WASIThreadsImports {
393
+ 'thread-spawn': (startArg: number, errorOrTid?: number) => number;
394
+ }
395
+
396
+ /** @public */
397
+ export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
398
+
399
+ /** @public */
400
+ export declare type WorkerFactory = (ctx: {
401
+ type: string;
402
+ name: string;
403
+ }) => WorkerLike;
404
+
405
+ /** @public */
406
+ export declare type WorkerLike = (Worker | Worker_2) & {
407
+ whenLoaded?: Promise<WorkerLike>;
408
+ loaded?: boolean;
409
+ __emnapi_tid?: number;
410
+ };
411
+
412
+ /** @public */
413
+ export declare interface WorkerMessageEvent<T = any> {
414
+ data: T;
415
+ }
416
+
417
+ /** @public */
418
+ export declare type WorkerMessageType = 'load' | 'start';
419
+
420
+ export { }
421
+
422
+ export as namespace emnapiCore;
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js ADDED
The diff for this file is too large to render. See raw diff
 
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.js ADDED
The diff for this file is too large to render. See raw diff
 
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+
3
+ import type { Context } from '@emnapi/runtime';
4
+ import type { ReferenceOwnership } from '@emnapi/runtime';
5
+ import type { Worker as Worker_2 } from 'worker_threads';
6
+
7
+ /** @public */
8
+ export declare type BaseCreateOptions = {
9
+ filename?: string
10
+ nodeBinding?: NodeBinding
11
+ reuseWorker?: ThreadManagerOptionsMain['reuseWorker']
12
+ asyncWorkPoolSize?: number
13
+ waitThreadStart?: MainThreadBaseOptions['waitThreadStart']
14
+ onCreateWorker?: (info: CreateWorkerInfo) => any
15
+ print?: (str: string) => void
16
+ printErr?: (str: string) => void
17
+ postMessage?: (msg: any) => any
18
+ }
19
+
20
+ /** @public */
21
+ export declare interface BaseOptions {
22
+ wasi: WASIInstance;
23
+ version?: 'preview1';
24
+ wasm64?: boolean;
25
+ }
26
+
27
+ /** @public */
28
+ export declare interface ChildThreadOptions extends BaseOptions {
29
+ childThread: true;
30
+ postMessage?: (data: any) => void;
31
+ }
32
+
33
+ /** @public */
34
+ export declare interface CleanupThreadPayload {
35
+ tid: number;
36
+ }
37
+
38
+ /** @public */
39
+ export declare interface CommandInfo<T extends CommandType> {
40
+ type: T;
41
+ payload: CommandPayloadMap[T];
42
+ }
43
+
44
+ /** @public */
45
+ export declare interface CommandPayloadMap {
46
+ load: LoadPayload;
47
+ loaded: LoadedPayload;
48
+ start: StartPayload;
49
+ 'cleanup-thread': CleanupThreadPayload;
50
+ 'terminate-all-threads': TerminateAllThreadsPayload;
51
+ 'spawn-thread': SpawnThreadPayload;
52
+ }
53
+
54
+ /** @public */
55
+ export declare type CommandType = keyof CommandPayloadMap;
56
+
57
+ /** @public */
58
+ export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
59
+
60
+ /** @public */
61
+ export declare function createNapiModule (
62
+ options: CreateOptions
63
+ ): NapiModule
64
+
65
+ /** @public */
66
+ export declare type CreateOptions = BaseCreateOptions & ({
67
+ context: Context
68
+ childThread?: boolean
69
+ } | {
70
+ context?: Context
71
+ childThread: true
72
+ })
73
+
74
+ /** @public */
75
+ export declare interface CreateWorkerInfo {
76
+ type: 'thread' | 'async-work'
77
+ name: string
78
+ }
79
+
80
+ /** @public */
81
+ export declare interface InitOptions {
82
+ instance: WebAssembly.Instance
83
+ module: WebAssembly.Module
84
+ memory?: WebAssembly.Memory
85
+ table?: WebAssembly.Table
86
+ }
87
+
88
+ export declare type InputType = string | URL | Response | BufferSource | WebAssembly.Module;
89
+
90
+ /** @public */
91
+ export declare interface InstantiatedSource extends LoadedSource {
92
+ napiModule: NapiModule;
93
+ }
94
+
95
+ /** @public */
96
+ export declare function instantiateNapiModule(
97
+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
98
+ wasmInput: InputType | Promise<InputType>, options: InstantiateOptions): Promise<InstantiatedSource>;
99
+
100
+ /** @public */
101
+ export declare function instantiateNapiModuleSync(wasmInput: BufferSource | WebAssembly.Module, options: InstantiateOptions): InstantiatedSource;
102
+
103
+ /** @public */
104
+ export declare type InstantiateOptions = CreateOptions & LoadOptions;
105
+
106
+ /** @public */
107
+ export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
108
+
109
+ /** @public */
110
+ export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
111
+
112
+ /** @public */
113
+ export declare interface LoadedPayload {
114
+ }
115
+
116
+ /** @public */
117
+ export declare interface LoadedSource extends WebAssembly.WebAssemblyInstantiatedSource {
118
+ usedInstance: WebAssembly.Instance;
119
+ }
120
+
121
+ /** @public */
122
+ export declare function loadNapiModule(napiModule: NapiModule,
123
+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
124
+ wasmInput: InputType | Promise<InputType>, options?: LoadOptions): Promise<LoadedSource>;
125
+
126
+ /** @public */
127
+ export declare function loadNapiModuleSync(napiModule: NapiModule, wasmInput: BufferSource | WebAssembly.Module, options?: LoadOptions): LoadedSource;
128
+
129
+ /** @public */
130
+ export declare interface LoadOptions {
131
+ wasi?: WASIInstance;
132
+ overwriteImports?: (importObject: WebAssembly.Imports) => WebAssembly.Imports;
133
+ beforeInit?: (source: WebAssembly.WebAssemblyInstantiatedSource) => void;
134
+ getMemory?: (exports: WebAssembly.Exports) => WebAssembly.Memory;
135
+ getTable?: (exports: WebAssembly.Exports) => WebAssembly.Table;
136
+ }
137
+
138
+ /** @public */
139
+ export declare interface LoadPayload {
140
+ wasmModule: WebAssembly.Module;
141
+ wasmMemory: WebAssembly.Memory;
142
+ sab?: Int32Array;
143
+ }
144
+
145
+ /** @public */
146
+ export declare interface MainThreadBaseOptions extends BaseOptions {
147
+ waitThreadStart?: boolean | number;
148
+ }
149
+
150
+ /** @public */
151
+ export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
152
+
153
+ /** @public */
154
+ export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
155
+ }
156
+
157
+ /** @public */
158
+ export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
159
+ threadManager?: ThreadManager | (() => ThreadManager);
160
+ }
161
+
162
+ /** @public */
163
+ export declare interface MessageEventData<T extends CommandType> {
164
+ __emnapi__: CommandInfo<T>;
165
+ }
166
+
167
+ /** @public */
168
+ export declare class MessageHandler extends ThreadMessageHandler {
169
+ napiModule: NapiModule | undefined;
170
+ constructor(options: MessageHandlerOptions);
171
+ instantiate(data: LoadPayload): InstantiatedSource | PromiseLike<InstantiatedSource>;
172
+ handle(e: WorkerMessageEvent): void;
173
+ }
174
+
175
+ /** @public */
176
+ export declare interface MessageHandlerOptions extends ThreadMessageHandlerOptions {
177
+ onLoad: (data: LoadPayload) => InstantiatedSource | PromiseLike<InstantiatedSource>;
178
+ }
179
+
180
+ /** @public */
181
+ export declare interface NapiModule {
182
+ imports: {
183
+ env: any
184
+ napi: any
185
+ emnapi: any
186
+ }
187
+ exports: any
188
+ loaded: boolean
189
+ filename: string
190
+ childThread: boolean
191
+ emnapi: {
192
+ syncMemory<T extends ArrayBuffer | ArrayBufferView> (
193
+ js_to_wasm: boolean,
194
+ arrayBufferOrView: T,
195
+ offset?: number,
196
+ len?: number
197
+ ): T
198
+ getMemoryAddress (arrayBufferOrView: ArrayBuffer | ArrayBufferView): PointerInfo
199
+ addSendListener (worker: any): boolean
200
+ }
201
+
202
+ init (options: InitOptions): any
203
+ initWorker (arg: number, func: [number, number]): void
204
+ postMessage?: (msg: any) => any
205
+
206
+ waitThreadStart: boolean | number
207
+ /* Excluded from this release type: PThread */}
208
+
209
+ /** @public */
210
+ export declare interface NodeBinding {
211
+ node: {
212
+ emitAsyncInit: Function
213
+ emitAsyncDestroy: Function
214
+ makeCallback: Function
215
+ }
216
+ napi: {
217
+ asyncInit: Function
218
+ asyncDestroy: Function
219
+ makeCallback: Function
220
+ }
221
+ }
222
+
223
+ /** @public */
224
+ export declare interface PointerInfo {
225
+ address: number
226
+ ownership: ReferenceOwnership
227
+ runtimeAllocated: 0 | 1
228
+ }
229
+
230
+ /** @public */
231
+ export declare interface ReuseWorkerOptions {
232
+ /**
233
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
234
+ */
235
+ size: number;
236
+ /**
237
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
238
+ */
239
+ strict?: boolean;
240
+ }
241
+
242
+ /** @public */
243
+ export declare interface SpawnThreadPayload {
244
+ startArg: number;
245
+ errorOrTid: number;
246
+ }
247
+
248
+ /** @public */
249
+ export declare interface StartPayload {
250
+ tid: number;
251
+ arg: number;
252
+ sab?: Int32Array;
253
+ }
254
+
255
+ /** @public */
256
+ export declare interface StartResult {
257
+ exitCode: number;
258
+ instance: WebAssembly.Instance;
259
+ }
260
+
261
+ /** @public */
262
+ export declare interface TerminateAllThreadsPayload {
263
+ }
264
+
265
+ /** @public */
266
+ export declare class ThreadManager {
267
+ unusedWorkers: WorkerLike[];
268
+ runningWorkers: WorkerLike[];
269
+ pthreads: Record<number, WorkerLike>;
270
+ get nextWorkerID(): number;
271
+ wasmModule: WebAssembly.Module | null;
272
+ wasmMemory: WebAssembly.Memory | null;
273
+ private readonly messageEvents;
274
+ private readonly _childThread;
275
+ private readonly _onCreateWorker;
276
+ private readonly _reuseWorker;
277
+ private readonly _beforeLoad?;
278
+ /* Excluded from this release type: printErr */
279
+ threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
280
+ constructor(options: ThreadManagerOptions);
281
+ init(): void;
282
+ initMainThread(): void;
283
+ private preparePool;
284
+ shouldPreloadWorkers(): boolean;
285
+ loadWasmModuleToAllWorkers(): Promise<WorkerLike[]>;
286
+ preloadWorkers(): Promise<WorkerLike[]>;
287
+ setup(wasmModule: WebAssembly.Module, wasmMemory: WebAssembly.Memory): void;
288
+ markId(worker: WorkerLike): number;
289
+ returnWorkerToPool(worker: WorkerLike): void;
290
+ loadWasmModuleToWorker(worker: WorkerLike, sab?: Int32Array): Promise<WorkerLike>;
291
+ allocateUnusedWorker(): WorkerLike;
292
+ getNewWorker(sab?: Int32Array): WorkerLike | undefined;
293
+ cleanThread(worker: WorkerLike, tid: number, force?: boolean): void;
294
+ terminateWorker(worker: WorkerLike): void;
295
+ terminateAllThreads(): void;
296
+ addMessageEventListener(worker: WorkerLike, onMessage: (e: WorkerMessageEvent) => void): () => void;
297
+ fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
298
+ }
299
+
300
+ /** @public */
301
+ export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
302
+
303
+ /** @public */
304
+ export declare interface ThreadManagerOptionsBase {
305
+ printErr?: (message: string) => void;
306
+ threadSpawn?: (startArg: number, errorOrTid?: number) => number;
307
+ }
308
+
309
+ /** @public */
310
+ export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
311
+ childThread: true;
312
+ }
313
+
314
+ /** @public */
315
+ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
316
+ beforeLoad?: (worker: WorkerLike) => any;
317
+ reuseWorker?: boolean | number | ReuseWorkerOptions;
318
+ onCreateWorker: WorkerFactory;
319
+ childThread?: false;
320
+ }
321
+
322
+ /** @public */
323
+ export declare class ThreadMessageHandler {
324
+ protected instance: WebAssembly.Instance | undefined;
325
+ private messagesBeforeLoad;
326
+ protected postMessage: (message: any) => void;
327
+ protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
328
+ protected onError: (error: Error, type: WorkerMessageType) => void;
329
+ constructor(options?: ThreadMessageHandlerOptions);
330
+ /** @virtual */
331
+ instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
332
+ /** @virtual */
333
+ handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
334
+ private _load;
335
+ private _start;
336
+ protected _loaded(err: Error | null, source: WebAssembly.WebAssemblyInstantiatedSource | null, payload: LoadPayload): void;
337
+ protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
338
+ }
339
+
340
+ /** @public */
341
+ export declare interface ThreadMessageHandlerOptions {
342
+ onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
343
+ onError?: (error: Error, type: WorkerMessageType) => void;
344
+ postMessage?: (message: any) => void;
345
+ }
346
+
347
+ export declare const version: string;
348
+
349
+ /** @public */
350
+ export declare interface WASIInstance {
351
+ readonly wasiImport?: Record<string, any>;
352
+ initialize(instance: object): void;
353
+ start(instance: object): number;
354
+ getImportObject?(): any;
355
+ }
356
+
357
+ /** @public */
358
+ export declare class WASIThreads {
359
+ PThread: ThreadManager | undefined;
360
+ private wasmMemory;
361
+ private wasmInstance;
362
+ private readonly threadSpawn;
363
+ readonly childThread: boolean;
364
+ private readonly postMessage;
365
+ readonly wasi: WASIInstance;
366
+ constructor(options: WASIThreadsOptions);
367
+ getImportObject(): {
368
+ wasi: WASIThreadsImports;
369
+ };
370
+ setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
371
+ preloadWorkers(): Promise<WorkerLike[]>;
372
+ /**
373
+ * It's ok to call this method to a WASI command module.
374
+ *
375
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
376
+ *
377
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
378
+ */
379
+ initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
380
+ /**
381
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
382
+ * ```js
383
+ * this.initialize(instance, module, memory)
384
+ * this.wasi.start(instance)
385
+ * ```
386
+ */
387
+ start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
388
+ terminateAllThreads(): void;
389
+ }
390
+
391
+ /** @public */
392
+ export declare interface WASIThreadsImports {
393
+ 'thread-spawn': (startArg: number, errorOrTid?: number) => number;
394
+ }
395
+
396
+ /** @public */
397
+ export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
398
+
399
+ /** @public */
400
+ export declare type WorkerFactory = (ctx: {
401
+ type: string;
402
+ name: string;
403
+ }) => WorkerLike;
404
+
405
+ /** @public */
406
+ export declare type WorkerLike = (Worker | Worker_2) & {
407
+ whenLoaded?: Promise<WorkerLike>;
408
+ loaded?: boolean;
409
+ __emnapi_tid?: number;
410
+ };
411
+
412
+ /** @public */
413
+ export declare interface WorkerMessageEvent<T = any> {
414
+ data: T;
415
+ }
416
+
417
+ /** @public */
418
+ export declare type WorkerMessageType = 'load' | 'start';
419
+
420
+ export { }
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.min.js ADDED
The diff for this file is too large to render. See raw diff
 
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.min.mjs ADDED
The diff for this file is too large to render. See raw diff
 
astra_scene_test/X_03/node_modules/@emnapi/core/dist/emnapi-core.mjs ADDED
The diff for this file is too large to render. See raw diff
 
astra_scene_test/X_03/node_modules/@emnapi/core/index.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') {
2
+ module.exports = require('./dist/emnapi-core.cjs.min.js')
3
+ } else {
4
+ module.exports = require('./dist/emnapi-core.cjs.js')
5
+ }
astra_scene_test/X_03/node_modules/@emnapi/core/package.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@emnapi/core",
3
+ "version": "1.10.0",
4
+ "description": "emnapi core",
5
+ "main": "index.js",
6
+ "module": "./dist/emnapi-core.esm-bundler.js",
7
+ "types": "./dist/emnapi-core.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": {
12
+ "module": "./dist/emnapi-core.d.ts",
13
+ "import": "./dist/emnapi-core.d.mts",
14
+ "default": "./dist/emnapi-core.d.ts"
15
+ },
16
+ "module": "./dist/emnapi-core.esm-bundler.js",
17
+ "import": "./dist/emnapi-core.mjs",
18
+ "default": "./index.js"
19
+ },
20
+ "./dist/emnapi-core.cjs.min": {
21
+ "types": "./dist/emnapi-core.d.ts",
22
+ "default": "./dist/emnapi-core.cjs.min.js"
23
+ },
24
+ "./dist/emnapi-core.min.mjs": {
25
+ "types": "./dist/emnapi-core.d.mts",
26
+ "default": "./dist/emnapi-core.min.mjs"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "@emnapi/wasi-threads": "1.2.1",
31
+ "tslib": "^2.4.0"
32
+ },
33
+ "scripts": {
34
+ "build": "node ./script/build.js"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/toyobayashi/emnapi.git"
39
+ },
40
+ "author": "toyobayashi",
41
+ "license": "MIT",
42
+ "bugs": {
43
+ "url": "https://github.com/toyobayashi/emnapi/issues"
44
+ },
45
+ "homepage": "https://github.com/toyobayashi/emnapi#readme",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }
astra_scene_test/X_03/node_modules/@emnapi/runtime/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Toyobayashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
astra_scene_test/X_03/node_modules/@emnapi/runtime/README.md ADDED
@@ -0,0 +1 @@
 
 
1
+ See [https://github.com/toyobayashi/emnapi](https://github.com/toyobayashi/emnapi)
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.cjs.js ADDED
@@ -0,0 +1,1398 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.bind(_global)
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.11.3";
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(handleStore) {
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(handleStore, id, currentScope, currentScope.end);
361
+ this._values[id] = scope;
362
+ }
363
+ this.currentScope = scope;
364
+ return scope;
365
+ }
366
+ closeScope() {
367
+ const scope = this.currentScope;
368
+ this.currentScope = scope.parent;
369
+ scope.dispose();
370
+ }
371
+ dispose() {
372
+ this.currentScope = this._rootScope;
373
+ this._values.length = 1;
374
+ }
375
+ }
376
+
377
+ class RefTracker {
378
+ constructor() {
379
+ this._next = null;
380
+ this._prev = null;
381
+ }
382
+ dispose() { }
383
+ finalize() { }
384
+ link(list) {
385
+ this._prev = list;
386
+ this._next = list._next;
387
+ if (this._next !== null) {
388
+ this._next._prev = this;
389
+ }
390
+ list._next = this;
391
+ }
392
+ unlink() {
393
+ if (this._prev !== null) {
394
+ this._prev._next = this._next;
395
+ }
396
+ if (this._next !== null) {
397
+ this._next._prev = this._prev;
398
+ }
399
+ this._prev = null;
400
+ this._next = null;
401
+ }
402
+ static finalizeAll(list) {
403
+ while (list._next !== null) {
404
+ list._next.finalize();
405
+ }
406
+ }
407
+ }
408
+
409
+ class Finalizer {
410
+ constructor(envObject, _finalizeCallback = 0, _finalizeData = 0, _finalizeHint = 0) {
411
+ this.envObject = envObject;
412
+ this._finalizeCallback = _finalizeCallback;
413
+ this._finalizeData = _finalizeData;
414
+ this._finalizeHint = _finalizeHint;
415
+ this._makeDynCall_vppp = envObject.makeDynCall_vppp;
416
+ }
417
+ callback() { return this._finalizeCallback; }
418
+ data() { return this._finalizeData; }
419
+ hint() { return this._finalizeHint; }
420
+ resetEnv() {
421
+ this.envObject = undefined;
422
+ }
423
+ resetFinalizer() {
424
+ this._finalizeCallback = 0;
425
+ this._finalizeData = 0;
426
+ this._finalizeHint = 0;
427
+ }
428
+ callFinalizer() {
429
+ const finalize_callback = this._finalizeCallback;
430
+ const finalize_data = this._finalizeData;
431
+ const finalize_hint = this._finalizeHint;
432
+ this.resetFinalizer();
433
+ if (!finalize_callback)
434
+ return;
435
+ const fini = Number(finalize_callback);
436
+ if (!this.envObject) {
437
+ this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
438
+ }
439
+ else {
440
+ this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
441
+ }
442
+ }
443
+ dispose() {
444
+ this.envObject = undefined;
445
+ this._makeDynCall_vppp = undefined;
446
+ }
447
+ }
448
+
449
+ class TrackedFinalizer extends RefTracker {
450
+ static create(envObject, finalize_callback, finalize_data, finalize_hint) {
451
+ const finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
452
+ finalizer.link(envObject.finalizing_reflist);
453
+ return finalizer;
454
+ }
455
+ constructor(envObject, finalize_callback, finalize_data, finalize_hint) {
456
+ super();
457
+ this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
458
+ }
459
+ data() {
460
+ return this._finalizer.data();
461
+ }
462
+ dispose() {
463
+ if (!this._finalizer)
464
+ return;
465
+ this.unlink();
466
+ this._finalizer.envObject.dequeueFinalizer(this);
467
+ this._finalizer.dispose();
468
+ this._finalizer = undefined;
469
+ super.dispose();
470
+ }
471
+ finalize() {
472
+ this.unlink();
473
+ let error;
474
+ let caught = false;
475
+ try {
476
+ this._finalizer.callFinalizer();
477
+ }
478
+ catch (err) {
479
+ caught = true;
480
+ error = err;
481
+ }
482
+ this.dispose();
483
+ if (caught) {
484
+ throw error;
485
+ }
486
+ }
487
+ }
488
+
489
+ function throwNodeApiVersionError(moduleName, moduleApiVersion) {
490
+ const errorMessage = `${moduleName} requires Node-API version ${moduleApiVersion}, but this version of Node.js only supports version ${NODE_API_SUPPORTED_VERSION_MAX} add-ons.`;
491
+ throw new Error(errorMessage);
492
+ }
493
+ function handleThrow(envObject, value) {
494
+ if (envObject.terminatedOrTerminating()) {
495
+ return;
496
+ }
497
+ throw value;
498
+ }
499
+ class Env {
500
+ constructor(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) {
501
+ this.ctx = ctx;
502
+ this.moduleApiVersion = moduleApiVersion;
503
+ this.makeDynCall_vppp = makeDynCall_vppp;
504
+ this.makeDynCall_vp = makeDynCall_vp;
505
+ this.abort = abort;
506
+ this.openHandleScopes = 0;
507
+ this.instanceData = null;
508
+ this.tryCatch = new TryCatch();
509
+ this.refs = 1;
510
+ this.reflist = new RefTracker();
511
+ this.finalizing_reflist = new RefTracker();
512
+ this.pendingFinalizers = [];
513
+ this.lastError = {
514
+ errorCode: 0,
515
+ engineErrorCode: 0,
516
+ engineReserved: 0
517
+ };
518
+ this.inGcFinalizer = false;
519
+ this._bindingMap = new WeakMap();
520
+ this.id = 0;
521
+ }
522
+ canCallIntoJs() {
523
+ return true;
524
+ }
525
+ terminatedOrTerminating() {
526
+ return !this.canCallIntoJs();
527
+ }
528
+ ref() {
529
+ this.refs++;
530
+ }
531
+ unref() {
532
+ this.refs--;
533
+ if (this.refs === 0) {
534
+ this.dispose();
535
+ }
536
+ }
537
+ ensureHandle(value) {
538
+ return this.ctx.ensureHandle(value);
539
+ }
540
+ ensureHandleId(value) {
541
+ return this.ensureHandle(value).id;
542
+ }
543
+ clearLastError() {
544
+ const lastError = this.lastError;
545
+ if (lastError.errorCode !== 0)
546
+ lastError.errorCode = 0;
547
+ if (lastError.engineErrorCode !== 0)
548
+ lastError.engineErrorCode = 0;
549
+ if (lastError.engineReserved !== 0)
550
+ lastError.engineReserved = 0;
551
+ return 0;
552
+ }
553
+ setLastError(error_code, engine_error_code = 0, engine_reserved = 0) {
554
+ const lastError = this.lastError;
555
+ if (lastError.errorCode !== error_code)
556
+ lastError.errorCode = error_code;
557
+ if (lastError.engineErrorCode !== engine_error_code)
558
+ lastError.engineErrorCode = engine_error_code;
559
+ if (lastError.engineReserved !== engine_reserved)
560
+ lastError.engineReserved = engine_reserved;
561
+ return error_code;
562
+ }
563
+ getReturnStatus() {
564
+ return !this.tryCatch.hasCaught() ? 0 : this.setLastError(10);
565
+ }
566
+ callIntoModule(fn, handleException = handleThrow) {
567
+ const openHandleScopesBefore = this.openHandleScopes;
568
+ this.clearLastError();
569
+ const r = fn(this);
570
+ if (openHandleScopesBefore !== this.openHandleScopes) {
571
+ this.abort('open_handle_scopes != open_handle_scopes_before');
572
+ }
573
+ if (this.tryCatch.hasCaught()) {
574
+ const err = this.tryCatch.extractException();
575
+ handleException(this, err);
576
+ }
577
+ return r;
578
+ }
579
+ invokeFinalizerFromGC(finalizer) {
580
+ if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
581
+ this.enqueueFinalizer(finalizer);
582
+ }
583
+ else {
584
+ const saved = this.inGcFinalizer;
585
+ this.inGcFinalizer = true;
586
+ try {
587
+ finalizer.finalize();
588
+ }
589
+ finally {
590
+ this.inGcFinalizer = saved;
591
+ }
592
+ }
593
+ }
594
+ checkGCAccess() {
595
+ if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) {
596
+ this.abort('Finalizer is calling a function that may affect GC state.\n' +
597
+ 'The finalizers are run directly from GC and must not affect GC ' +
598
+ 'state.\n' +
599
+ 'Use `node_api_post_finalizer` from inside of the finalizer to work ' +
600
+ 'around this issue.\n' +
601
+ 'It schedules the call as a new task in the event loop.');
602
+ }
603
+ }
604
+ enqueueFinalizer(finalizer) {
605
+ if (this.pendingFinalizers.indexOf(finalizer) === -1) {
606
+ this.pendingFinalizers.push(finalizer);
607
+ }
608
+ }
609
+ dequeueFinalizer(finalizer) {
610
+ const index = this.pendingFinalizers.indexOf(finalizer);
611
+ if (index !== -1) {
612
+ this.pendingFinalizers.splice(index, 1);
613
+ }
614
+ }
615
+ deleteMe() {
616
+ RefTracker.finalizeAll(this.finalizing_reflist);
617
+ RefTracker.finalizeAll(this.reflist);
618
+ this.tryCatch.extractException();
619
+ this.ctx.envStore.remove(this.id);
620
+ }
621
+ dispose() {
622
+ if (this.id === 0)
623
+ return;
624
+ this.deleteMe();
625
+ this.finalizing_reflist.dispose();
626
+ this.reflist.dispose();
627
+ this.id = 0;
628
+ }
629
+ initObjectBinding(value) {
630
+ const binding = {
631
+ wrapped: 0,
632
+ tag: null
633
+ };
634
+ this._bindingMap.set(value, binding);
635
+ return binding;
636
+ }
637
+ getObjectBinding(value) {
638
+ if (this._bindingMap.has(value)) {
639
+ return this._bindingMap.get(value);
640
+ }
641
+ return this.initObjectBinding(value);
642
+ }
643
+ setInstanceData(data, finalize_cb, finalize_hint) {
644
+ if (this.instanceData) {
645
+ this.instanceData.dispose();
646
+ }
647
+ this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
648
+ }
649
+ getInstanceData() {
650
+ return this.instanceData ? this.instanceData.data() : 0;
651
+ }
652
+ }
653
+ class NodeEnv extends Env {
654
+ constructor(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
655
+ super(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort);
656
+ this.filename = filename;
657
+ this.nodeBinding = nodeBinding;
658
+ this.destructing = false;
659
+ this.finalizationScheduled = false;
660
+ }
661
+ deleteMe() {
662
+ this.destructing = true;
663
+ this.drainFinalizerQueue();
664
+ super.deleteMe();
665
+ }
666
+ canCallIntoJs() {
667
+ return super.canCallIntoJs() && this.ctx.canCallIntoJs();
668
+ }
669
+ triggerFatalException(err) {
670
+ if (this.nodeBinding) {
671
+ this.nodeBinding.napi.fatalException(err);
672
+ }
673
+ else {
674
+ if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') {
675
+ const handled = process._fatalException(err);
676
+ if (!handled) {
677
+ console.error(err);
678
+ process.exit(1);
679
+ }
680
+ }
681
+ else {
682
+ throw err;
683
+ }
684
+ }
685
+ }
686
+ callbackIntoModule(enforceUncaughtExceptionPolicy, fn) {
687
+ return this.callIntoModule(fn, (envObject, err) => {
688
+ if (envObject.terminatedOrTerminating()) {
689
+ return;
690
+ }
691
+ const hasProcess = typeof process === 'object' && process !== null;
692
+ const hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
693
+ if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
694
+ const warn = hasProcess && typeof process.emitWarning === 'function'
695
+ ? process.emitWarning
696
+ : function (warning, type, code) {
697
+ if (warning instanceof Error) {
698
+ console.warn(warning.toString());
699
+ }
700
+ else {
701
+ const prefix = code ? `[${code}] ` : '';
702
+ console.warn(`${prefix}${type || 'Warning'}: ${warning}`);
703
+ }
704
+ };
705
+ warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
706
+ return;
707
+ }
708
+ envObject.triggerFatalException(err);
709
+ });
710
+ }
711
+ callFinalizer(cb, data, hint) {
712
+ this.callFinalizerInternal(1, cb, data, hint);
713
+ }
714
+ callFinalizerInternal(forceUncaught, cb, data, hint) {
715
+ const f = this.makeDynCall_vppp(cb);
716
+ const env = this.id;
717
+ const scope = this.ctx.openScope(this);
718
+ try {
719
+ this.callbackIntoModule(Boolean(forceUncaught), () => { f(env, data, hint); });
720
+ }
721
+ finally {
722
+ this.ctx.closeScope(this, scope);
723
+ }
724
+ }
725
+ enqueueFinalizer(finalizer) {
726
+ super.enqueueFinalizer(finalizer);
727
+ if (!this.finalizationScheduled && !this.destructing) {
728
+ this.finalizationScheduled = true;
729
+ this.ref();
730
+ _setImmediate(() => {
731
+ this.finalizationScheduled = false;
732
+ this.unref();
733
+ this.drainFinalizerQueue();
734
+ });
735
+ }
736
+ }
737
+ drainFinalizerQueue() {
738
+ while (this.pendingFinalizers.length > 0) {
739
+ const refTracker = this.pendingFinalizers.shift();
740
+ refTracker.finalize();
741
+ }
742
+ }
743
+ }
744
+ function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
745
+ moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion;
746
+ if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
747
+ moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
748
+ }
749
+ else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
750
+ throwNodeApiVersionError(filename, moduleApiVersion);
751
+ }
752
+ const env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
753
+ ctx.envStore.add(env);
754
+ ctx.addCleanupHook(env, () => { env.unref(); }, 0);
755
+ return env;
756
+ }
757
+
758
+ class EmnapiError extends Error {
759
+ constructor(message) {
760
+ super(message);
761
+ const ErrorConstructor = new.target;
762
+ const proto = ErrorConstructor.prototype;
763
+ if (!(this instanceof EmnapiError)) {
764
+ const setPrototypeOf = Object.setPrototypeOf;
765
+ if (typeof setPrototypeOf === 'function') {
766
+ setPrototypeOf.call(Object, this, proto);
767
+ }
768
+ else {
769
+ this.__proto__ = proto;
770
+ }
771
+ if (typeof Error.captureStackTrace === 'function') {
772
+ Error.captureStackTrace(this, ErrorConstructor);
773
+ }
774
+ }
775
+ }
776
+ }
777
+ Object.defineProperty(EmnapiError.prototype, 'name', {
778
+ configurable: true,
779
+ writable: true,
780
+ value: 'EmnapiError'
781
+ });
782
+ class NotSupportWeakRefError extends EmnapiError {
783
+ constructor(api, message) {
784
+ super(`${api}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${message ? ` ${message}` : ''}`);
785
+ }
786
+ }
787
+ Object.defineProperty(NotSupportWeakRefError.prototype, 'name', {
788
+ configurable: true,
789
+ writable: true,
790
+ value: 'NotSupportWeakRefError'
791
+ });
792
+ class NotSupportBufferError extends EmnapiError {
793
+ constructor(api, message) {
794
+ super(`${api}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${message ? ` ${message}` : ''}`);
795
+ }
796
+ }
797
+ Object.defineProperty(NotSupportBufferError.prototype, 'name', {
798
+ configurable: true,
799
+ writable: true,
800
+ value: 'NotSupportBufferError'
801
+ });
802
+
803
+ class StrongRef {
804
+ constructor(value) {
805
+ this._value = value;
806
+ }
807
+ deref() {
808
+ return this._value;
809
+ }
810
+ dispose() {
811
+ this._value = undefined;
812
+ }
813
+ }
814
+ class Persistent {
815
+ constructor(value) {
816
+ this._ref = new StrongRef(value);
817
+ }
818
+ setWeak(param, callback) {
819
+ if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef)
820
+ return;
821
+ const value = this._ref.deref();
822
+ try {
823
+ Persistent._registry.register(value, this, this);
824
+ const weakRef = new WeakRef(value);
825
+ this._ref.dispose();
826
+ this._ref = weakRef;
827
+ this._param = param;
828
+ this._callback = callback;
829
+ }
830
+ catch (err) {
831
+ if (typeof value === 'symbol') ;
832
+ else {
833
+ throw err;
834
+ }
835
+ }
836
+ }
837
+ clearWeak() {
838
+ if (!supportFinalizer || this._ref === undefined)
839
+ return;
840
+ if (this._ref instanceof WeakRef) {
841
+ try {
842
+ Persistent._registry.unregister(this);
843
+ }
844
+ catch (_) { }
845
+ this._param = undefined;
846
+ this._callback = undefined;
847
+ const value = this._ref.deref();
848
+ if (value === undefined) {
849
+ this._ref = value;
850
+ }
851
+ else {
852
+ this._ref = new StrongRef(value);
853
+ }
854
+ }
855
+ }
856
+ reset() {
857
+ if (supportFinalizer) {
858
+ try {
859
+ Persistent._registry.unregister(this);
860
+ }
861
+ catch (_) { }
862
+ }
863
+ this._param = undefined;
864
+ this._callback = undefined;
865
+ if (this._ref instanceof StrongRef) {
866
+ this._ref.dispose();
867
+ }
868
+ this._ref = undefined;
869
+ }
870
+ isEmpty() {
871
+ return this._ref === undefined;
872
+ }
873
+ deref() {
874
+ if (this._ref === undefined)
875
+ return undefined;
876
+ return this._ref.deref();
877
+ }
878
+ }
879
+ Persistent._registry = supportFinalizer
880
+ ? new FinalizationRegistry((value) => {
881
+ value._ref = undefined;
882
+ const callback = value._callback;
883
+ const param = value._param;
884
+ value._callback = undefined;
885
+ value._param = undefined;
886
+ if (typeof callback === 'function') {
887
+ callback(param);
888
+ }
889
+ })
890
+ : undefined;
891
+
892
+ exports.ReferenceOwnership = void 0;
893
+ (function (ReferenceOwnership) {
894
+ ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
895
+ ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
896
+ })(exports.ReferenceOwnership || (exports.ReferenceOwnership = {}));
897
+ function canBeHeldWeakly(value) {
898
+ return value.isObject() || value.isFunction() || value.isSymbol();
899
+ }
900
+ class Reference extends RefTracker {
901
+ static weakCallback(ref) {
902
+ ref.persistent.reset();
903
+ ref.invokeFinalizerFromGC();
904
+ }
905
+ static create(envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
906
+ const ref = new Reference(envObject, handle_id, initialRefcount, ownership);
907
+ envObject.ctx.refStore.add(ref);
908
+ ref.link(envObject.reflist);
909
+ return ref;
910
+ }
911
+ constructor(envObject, handle_id, initialRefcount, ownership) {
912
+ super();
913
+ this.envObject = envObject;
914
+ this._refcount = initialRefcount;
915
+ this._ownership = ownership;
916
+ const handle = envObject.ctx.handleStore.get(handle_id);
917
+ this.canBeWeak = canBeHeldWeakly(handle);
918
+ this.persistent = new Persistent(handle.value);
919
+ this.id = 0;
920
+ if (initialRefcount === 0) {
921
+ this._setWeak();
922
+ }
923
+ }
924
+ ref() {
925
+ if (this.persistent.isEmpty()) {
926
+ return 0;
927
+ }
928
+ if (++this._refcount === 1 && this.canBeWeak) {
929
+ this.persistent.clearWeak();
930
+ }
931
+ return this._refcount;
932
+ }
933
+ unref() {
934
+ if (this.persistent.isEmpty() || this._refcount === 0) {
935
+ return 0;
936
+ }
937
+ if (--this._refcount === 0) {
938
+ this._setWeak();
939
+ }
940
+ return this._refcount;
941
+ }
942
+ get(envObject = this.envObject) {
943
+ if (this.persistent.isEmpty()) {
944
+ return 0;
945
+ }
946
+ const obj = this.persistent.deref();
947
+ const handle = envObject.ensureHandle(obj);
948
+ return handle.id;
949
+ }
950
+ resetFinalizer() { }
951
+ data() { return 0; }
952
+ refcount() { return this._refcount; }
953
+ ownership() { return this._ownership; }
954
+ callUserFinalizer() { }
955
+ invokeFinalizerFromGC() {
956
+ this.finalize();
957
+ }
958
+ _setWeak() {
959
+ if (this.canBeWeak) {
960
+ this.persistent.setWeak(this, Reference.weakCallback);
961
+ }
962
+ else {
963
+ this.persistent.reset();
964
+ }
965
+ }
966
+ finalize() {
967
+ this.persistent.reset();
968
+ const deleteMe = this._ownership === exports.ReferenceOwnership.kRuntime;
969
+ this.unlink();
970
+ this.callUserFinalizer();
971
+ if (deleteMe) {
972
+ this.dispose();
973
+ }
974
+ }
975
+ dispose() {
976
+ if (this.id === 0)
977
+ return;
978
+ this.unlink();
979
+ this.persistent.reset();
980
+ this.envObject.ctx.refStore.remove(this.id);
981
+ super.dispose();
982
+ this.envObject = undefined;
983
+ this.id = 0;
984
+ }
985
+ }
986
+ class ReferenceWithData extends Reference {
987
+ static create(envObject, value, initialRefcount, ownership, data) {
988
+ const reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
989
+ envObject.ctx.refStore.add(reference);
990
+ reference.link(envObject.reflist);
991
+ return reference;
992
+ }
993
+ constructor(envObject, value, initialRefcount, ownership, _data) {
994
+ super(envObject, value, initialRefcount, ownership);
995
+ this._data = _data;
996
+ }
997
+ data() {
998
+ return this._data;
999
+ }
1000
+ }
1001
+ class ReferenceWithFinalizer extends Reference {
1002
+ static create(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1003
+ const reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1004
+ envObject.ctx.refStore.add(reference);
1005
+ reference.link(envObject.finalizing_reflist);
1006
+ return reference;
1007
+ }
1008
+ constructor(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1009
+ super(envObject, value, initialRefcount, ownership);
1010
+ this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
1011
+ }
1012
+ resetFinalizer() {
1013
+ this._finalizer.resetFinalizer();
1014
+ }
1015
+ data() {
1016
+ return this._finalizer.data();
1017
+ }
1018
+ callUserFinalizer() {
1019
+ this._finalizer.callFinalizer();
1020
+ }
1021
+ invokeFinalizerFromGC() {
1022
+ this._finalizer.envObject.invokeFinalizerFromGC(this);
1023
+ }
1024
+ dispose() {
1025
+ if (!this._finalizer)
1026
+ return;
1027
+ this._finalizer.envObject.dequeueFinalizer(this);
1028
+ this._finalizer.dispose();
1029
+ super.dispose();
1030
+ this._finalizer = undefined;
1031
+ }
1032
+ }
1033
+
1034
+ class Deferred {
1035
+ static create(ctx, value) {
1036
+ const deferred = new Deferred(ctx, value);
1037
+ ctx.deferredStore.add(deferred);
1038
+ return deferred;
1039
+ }
1040
+ constructor(ctx, value) {
1041
+ Object.defineProperties(this, {
1042
+ id: {
1043
+ configurable: true,
1044
+ enumerable: true,
1045
+ value: 0,
1046
+ writable: true
1047
+ },
1048
+ ctx: {
1049
+ configurable: true,
1050
+ enumerable: true,
1051
+ value: ctx,
1052
+ writable: true
1053
+ },
1054
+ value: {
1055
+ configurable: true,
1056
+ enumerable: true,
1057
+ value,
1058
+ writable: true
1059
+ }
1060
+ });
1061
+ }
1062
+ resolve(value) {
1063
+ this.value.resolve(value);
1064
+ this.dispose();
1065
+ }
1066
+ reject(reason) {
1067
+ this.value.reject(reason);
1068
+ this.dispose();
1069
+ }
1070
+ dispose() {
1071
+ this.ctx.deferredStore.remove(this.id);
1072
+ this.id = 0;
1073
+ this.value = null;
1074
+ this.ctx = null;
1075
+ }
1076
+ }
1077
+
1078
+ class Store {
1079
+ constructor() {
1080
+ this._values = [undefined];
1081
+ this._values.length = 4;
1082
+ this._size = 1;
1083
+ this._freeList = [];
1084
+ }
1085
+ add(value) {
1086
+ let id;
1087
+ if (this._freeList.length) {
1088
+ id = this._freeList.shift();
1089
+ }
1090
+ else {
1091
+ id = this._size;
1092
+ this._size++;
1093
+ const capacity = this._values.length;
1094
+ if (id >= capacity) {
1095
+ this._values.length = capacity + (capacity >> 1) + 16;
1096
+ }
1097
+ }
1098
+ value.id = id;
1099
+ this._values[id] = value;
1100
+ }
1101
+ get(id) {
1102
+ return this._values[id];
1103
+ }
1104
+ has(id) {
1105
+ return this._values[id] !== undefined;
1106
+ }
1107
+ remove(id) {
1108
+ const value = this._values[id];
1109
+ if (value) {
1110
+ value.id = 0;
1111
+ this._values[id] = undefined;
1112
+ this._freeList.push(Number(id));
1113
+ }
1114
+ }
1115
+ dispose() {
1116
+ for (let i = 1; i < this._size; ++i) {
1117
+ const value = this._values[i];
1118
+ value === null || value === void 0 ? void 0 : value.dispose();
1119
+ }
1120
+ this._values = [undefined];
1121
+ this._size = 1;
1122
+ this._freeList = [];
1123
+ }
1124
+ }
1125
+
1126
+ const kMaxReasonableBytes = BigInt(1) << BigInt(60);
1127
+ const kMinReasonableBytes = -kMaxReasonableBytes;
1128
+ class ExternalMemory {
1129
+ constructor(onChange) {
1130
+ this.total = BigInt(0);
1131
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
1132
+ }
1133
+ adjust(changeInBytes) {
1134
+ changeInBytes = BigInt(changeInBytes);
1135
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
1136
+ throw new RangeError(`changeInBytes ${changeInBytes} is out of reasonable range`);
1137
+ }
1138
+ const old = this.total;
1139
+ this.total += changeInBytes;
1140
+ const amount = this.total;
1141
+ const onChange = this.onChange;
1142
+ if (changeInBytes) {
1143
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
1144
+ }
1145
+ return amount;
1146
+ }
1147
+ }
1148
+
1149
+ class CleanupHookCallback {
1150
+ constructor(envObject, fn, arg, order) {
1151
+ this.envObject = envObject;
1152
+ this.fn = fn;
1153
+ this.arg = arg;
1154
+ this.order = order;
1155
+ }
1156
+ }
1157
+ class CleanupQueue {
1158
+ constructor() {
1159
+ this._cleanupHooks = [];
1160
+ this._cleanupHookCounter = 0;
1161
+ }
1162
+ empty() {
1163
+ return this._cleanupHooks.length === 0;
1164
+ }
1165
+ add(envObject, fn, arg) {
1166
+ if (this._cleanupHooks.filter((hook) => (hook.envObject === envObject && hook.fn === fn && hook.arg === arg)).length > 0) {
1167
+ throw new Error('Can not add same fn and arg twice');
1168
+ }
1169
+ this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++));
1170
+ }
1171
+ remove(envObject, fn, arg) {
1172
+ for (let i = 0; i < this._cleanupHooks.length; ++i) {
1173
+ const hook = this._cleanupHooks[i];
1174
+ if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) {
1175
+ this._cleanupHooks.splice(i, 1);
1176
+ return;
1177
+ }
1178
+ }
1179
+ }
1180
+ drain() {
1181
+ const hooks = this._cleanupHooks.slice();
1182
+ hooks.sort((a, b) => (b.order - a.order));
1183
+ for (let i = 0; i < hooks.length; ++i) {
1184
+ const cb = hooks[i];
1185
+ if (typeof cb.fn === 'number') {
1186
+ cb.envObject.makeDynCall_vp(cb.fn)(cb.arg);
1187
+ }
1188
+ else {
1189
+ cb.fn(cb.arg);
1190
+ }
1191
+ this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1);
1192
+ }
1193
+ }
1194
+ dispose() {
1195
+ this._cleanupHooks.length = 0;
1196
+ this._cleanupHookCounter = 0;
1197
+ }
1198
+ }
1199
+ class NodejsWaitingRequestCounter {
1200
+ constructor() {
1201
+ this.refHandle = new _MessageChannel().port1;
1202
+ this.count = 0;
1203
+ }
1204
+ increase() {
1205
+ if (this.count === 0) {
1206
+ if (this.refHandle.ref) {
1207
+ this.refHandle.ref();
1208
+ }
1209
+ }
1210
+ this.count++;
1211
+ }
1212
+ decrease() {
1213
+ if (this.count === 0)
1214
+ return;
1215
+ if (this.count === 1) {
1216
+ if (this.refHandle.unref) {
1217
+ this.refHandle.unref();
1218
+ }
1219
+ }
1220
+ this.count--;
1221
+ }
1222
+ }
1223
+ class Context {
1224
+ constructor(options) {
1225
+ this._isStopping = false;
1226
+ this._canCallIntoJs = true;
1227
+ this._suppressDestroy = false;
1228
+ this.envStore = new Store();
1229
+ this.scopeStore = new ScopeStore();
1230
+ this.refStore = new Store();
1231
+ this.deferredStore = new Store();
1232
+ this.handleStore = new HandleStore();
1233
+ this.feature = {
1234
+ supportReflect,
1235
+ supportFinalizer,
1236
+ supportWeakSymbol,
1237
+ supportBigInt,
1238
+ supportNewFunction,
1239
+ canSetFunctionName,
1240
+ setImmediate: _setImmediate,
1241
+ Buffer: _Buffer,
1242
+ MessageChannel: _MessageChannel
1243
+ };
1244
+ this.cleanupQueue = new CleanupQueue();
1245
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
1246
+ if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1247
+ this.refCounter = new NodejsWaitingRequestCounter();
1248
+ process.once('beforeExit', () => {
1249
+ if (!this._suppressDestroy) {
1250
+ this.destroy();
1251
+ }
1252
+ });
1253
+ }
1254
+ }
1255
+ suppressDestroy() {
1256
+ this._suppressDestroy = true;
1257
+ }
1258
+ getRuntimeVersions() {
1259
+ return {
1260
+ version,
1261
+ NODE_API_SUPPORTED_VERSION_MAX,
1262
+ NAPI_VERSION_EXPERIMENTAL,
1263
+ NODE_API_DEFAULT_MODULE_API_VERSION
1264
+ };
1265
+ }
1266
+ createNotSupportWeakRefError(api, message) {
1267
+ return new NotSupportWeakRefError(api, message);
1268
+ }
1269
+ createNotSupportBufferError(api, message) {
1270
+ return new NotSupportBufferError(api, message);
1271
+ }
1272
+ createReference(envObject, handle_id, initialRefcount, ownership) {
1273
+ return Reference.create(envObject, handle_id, initialRefcount, ownership);
1274
+ }
1275
+ createReferenceWithData(envObject, handle_id, initialRefcount, ownership, data) {
1276
+ return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
1277
+ }
1278
+ createReferenceWithFinalizer(envObject, handle_id, initialRefcount, ownership, finalize_callback = 0, finalize_data = 0, finalize_hint = 0) {
1279
+ return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1280
+ }
1281
+ createDeferred(value) {
1282
+ return Deferred.create(this, value);
1283
+ }
1284
+ adjustAmountOfExternalAllocatedMemory(changeInBytes) {
1285
+ return this._externalMemory.adjust(changeInBytes);
1286
+ }
1287
+ createEnv(filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1288
+ return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1289
+ }
1290
+ createTrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
1291
+ return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint);
1292
+ }
1293
+ getCurrentScope() {
1294
+ return this.scopeStore.currentScope;
1295
+ }
1296
+ addToCurrentScope(value) {
1297
+ return this.scopeStore.currentScope.add(value);
1298
+ }
1299
+ openScope(envObject) {
1300
+ const scope = this.scopeStore.openScope(this.handleStore);
1301
+ if (envObject)
1302
+ envObject.openHandleScopes++;
1303
+ return scope;
1304
+ }
1305
+ closeScope(envObject, _scope) {
1306
+ if (envObject && envObject.openHandleScopes === 0)
1307
+ return;
1308
+ this.scopeStore.closeScope();
1309
+ if (envObject)
1310
+ envObject.openHandleScopes--;
1311
+ }
1312
+ ensureHandle(value) {
1313
+ switch (value) {
1314
+ case undefined: return HandleStore.UNDEFINED;
1315
+ case null: return HandleStore.NULL;
1316
+ case true: return HandleStore.TRUE;
1317
+ case false: return HandleStore.FALSE;
1318
+ case _global: return HandleStore.GLOBAL;
1319
+ }
1320
+ return this.addToCurrentScope(value);
1321
+ }
1322
+ addCleanupHook(envObject, fn, arg) {
1323
+ this.cleanupQueue.add(envObject, fn, arg);
1324
+ }
1325
+ removeCleanupHook(envObject, fn, arg) {
1326
+ this.cleanupQueue.remove(envObject, fn, arg);
1327
+ }
1328
+ runCleanup() {
1329
+ while (!this.cleanupQueue.empty()) {
1330
+ this.cleanupQueue.drain();
1331
+ }
1332
+ }
1333
+ increaseWaitingRequestCounter() {
1334
+ var _a;
1335
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase();
1336
+ }
1337
+ decreaseWaitingRequestCounter() {
1338
+ var _a;
1339
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease();
1340
+ }
1341
+ setCanCallIntoJs(value) {
1342
+ this._canCallIntoJs = value;
1343
+ }
1344
+ setStopping(value) {
1345
+ this._isStopping = value;
1346
+ }
1347
+ canCallIntoJs() {
1348
+ return this._canCallIntoJs && !this._isStopping;
1349
+ }
1350
+ destroy() {
1351
+ this.setStopping(true);
1352
+ this.setCanCallIntoJs(false);
1353
+ this.runCleanup();
1354
+ }
1355
+ }
1356
+ let defaultContext;
1357
+ function createContext(options) {
1358
+ return new Context(options);
1359
+ }
1360
+ function getDefaultContext() {
1361
+ if (!defaultContext) {
1362
+ defaultContext = createContext();
1363
+ }
1364
+ return defaultContext;
1365
+ }
1366
+
1367
+ exports.ConstHandle = ConstHandle;
1368
+ exports.Context = Context;
1369
+ exports.Deferred = Deferred;
1370
+ exports.EmnapiError = EmnapiError;
1371
+ exports.Env = Env;
1372
+ exports.External = External;
1373
+ exports.Finalizer = Finalizer;
1374
+ exports.Handle = Handle;
1375
+ exports.HandleScope = HandleScope;
1376
+ exports.HandleStore = HandleStore;
1377
+ exports.NAPI_VERSION_EXPERIMENTAL = NAPI_VERSION_EXPERIMENTAL;
1378
+ exports.NODE_API_DEFAULT_MODULE_API_VERSION = NODE_API_DEFAULT_MODULE_API_VERSION;
1379
+ exports.NODE_API_SUPPORTED_VERSION_MAX = NODE_API_SUPPORTED_VERSION_MAX;
1380
+ exports.NODE_API_SUPPORTED_VERSION_MIN = NODE_API_SUPPORTED_VERSION_MIN;
1381
+ exports.NodeEnv = NodeEnv;
1382
+ exports.NotSupportBufferError = NotSupportBufferError;
1383
+ exports.NotSupportWeakRefError = NotSupportWeakRefError;
1384
+ exports.Persistent = Persistent;
1385
+ exports.RefTracker = RefTracker;
1386
+ exports.Reference = Reference;
1387
+ exports.ReferenceWithData = ReferenceWithData;
1388
+ exports.ReferenceWithFinalizer = ReferenceWithFinalizer;
1389
+ exports.ScopeStore = ScopeStore;
1390
+ exports.Store = Store;
1391
+ exports.TrackedFinalizer = TrackedFinalizer;
1392
+ exports.TryCatch = TryCatch;
1393
+ exports.createContext = createContext;
1394
+ exports.getDefaultContext = getDefaultContext;
1395
+ exports.getExternalValue = getExternalValue;
1396
+ exports.isExternal = isExternal;
1397
+ exports.isReferenceType = isReferenceType;
1398
+ exports.version = version;
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts ADDED
@@ -0,0 +1,671 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export declare type Ptr = number | bigint
2
+
3
+ export declare interface IBuffer extends Uint8Array {}
4
+ export declare interface BufferCtor {
5
+ readonly prototype: IBuffer
6
+ /** @deprecated */
7
+ new (...args: any[]): IBuffer
8
+ from: {
9
+ (buffer: ArrayBufferLike): IBuffer
10
+ (buffer: ArrayBufferLike, byteOffset: number, length: number): IBuffer
11
+ }
12
+ alloc: (size: number) => IBuffer
13
+ isBuffer: (obj: unknown) => obj is IBuffer
14
+ }
15
+
16
+ export declare const enum GlobalHandle {
17
+ UNDEFINED = 1,
18
+ NULL,
19
+ FALSE,
20
+ TRUE,
21
+ GLOBAL
22
+ }
23
+
24
+ export declare const enum Version {
25
+ NODE_API_SUPPORTED_VERSION_MIN = 1,
26
+ NODE_API_DEFAULT_MODULE_API_VERSION = 8,
27
+ NODE_API_SUPPORTED_VERSION_MAX = 10,
28
+ NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ export declare type Pointer<T> = number
32
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
+ export declare type PointerPointer<T> = number
34
+ export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T>
35
+ export declare type Const<T> = T
36
+
37
+ export declare type void_p = Pointer<void>
38
+ export declare type void_pp = Pointer<void_p>
39
+ export declare type bool = number
40
+ export declare type char = number
41
+ export declare type char_p = Pointer<char>
42
+ export declare type unsigned_char = number
43
+ export declare type const_char = Const<char>
44
+ export declare type const_char_p = Pointer<const_char>
45
+ export declare type char16_t_p = number
46
+ export declare type const_char16_t_p = number
47
+
48
+ export declare type short = number
49
+ export declare type unsigned_short = number
50
+ export declare type int = number
51
+ export declare type unsigned_int = number
52
+ export declare type long = number
53
+ export declare type unsigned_long = number
54
+ export declare type long_long = bigint
55
+ export declare type unsigned_long_long = bigint
56
+ export declare type float = number
57
+ export declare type double = number
58
+ export declare type long_double = number
59
+ export declare type size_t = number
60
+
61
+ export declare type int8_t = number
62
+ export declare type uint8_t = number
63
+ export declare type int16_t = number
64
+ export declare type uint16_t = number
65
+ export declare type int32_t = number
66
+ export declare type uint32_t = number
67
+ export declare type int64_t = bigint
68
+ export declare type uint64_t = bigint
69
+ export declare type napi_env = Pointer<unknown>
70
+
71
+ export declare type napi_value = Pointer<unknown>
72
+ export declare type napi_ref = Pointer<unknown>
73
+ export declare type napi_deferred = Pointer<unknown>
74
+ export declare type napi_handle_scope = Pointer<unknown>
75
+ export declare type napi_escapable_handle_scope = Pointer<unknown>
76
+
77
+ export declare type napi_addon_register_func = FunctionPointer<(env: napi_env, exports: napi_value) => napi_value>
78
+
79
+ export declare type napi_callback_info = Pointer<unknown>
80
+ export declare type napi_callback = FunctionPointer<(env: napi_env, info: napi_callback_info) => napi_value>
81
+
82
+ export declare interface napi_extended_error_info {
83
+ error_message: const_char_p
84
+ engine_reserved: void_p
85
+ engine_error_code: uint32_t
86
+ error_code: napi_status
87
+ }
88
+
89
+ export declare interface napi_property_descriptor {
90
+ // One of utf8name or name should be NULL.
91
+ utf8name: const_char_p
92
+ name: napi_value
93
+
94
+ method: napi_callback
95
+ getter: napi_callback
96
+ setter: napi_callback
97
+ value: napi_value
98
+ /* napi_property_attributes */
99
+ attributes: number
100
+ data: void_p
101
+ }
102
+
103
+ export declare type napi_finalize = FunctionPointer<(
104
+ env: napi_env,
105
+ finalize_data: void_p,
106
+ finalize_hint: void_p
107
+ ) => void>
108
+
109
+ export declare interface node_module {
110
+ nm_version: int32_t
111
+ nm_flags: uint32_t
112
+ nm_filename: Pointer<const_char>
113
+ nm_register_func: napi_addon_register_func
114
+ nm_modname: Pointer<const_char>
115
+ nm_priv: Pointer<void>
116
+ reserved: PointerPointer<void>
117
+ }
118
+
119
+ export declare interface napi_node_version {
120
+ major: uint32_t
121
+ minor: uint32_t
122
+ patch: uint32_t
123
+ release: const_char_p
124
+ }
125
+
126
+ export declare interface emnapi_emscripten_version {
127
+ major: uint32_t
128
+ minor: uint32_t
129
+ patch: uint32_t
130
+ }
131
+
132
+ export declare const enum napi_status {
133
+ napi_ok,
134
+ napi_invalid_arg,
135
+ napi_object_expected,
136
+ napi_string_expected,
137
+ napi_name_expected,
138
+ napi_function_expected,
139
+ napi_number_expected,
140
+ napi_boolean_expected,
141
+ napi_array_expected,
142
+ napi_generic_failure,
143
+ napi_pending_exception,
144
+ napi_cancelled,
145
+ napi_escape_called_twice,
146
+ napi_handle_scope_mismatch,
147
+ napi_callback_scope_mismatch,
148
+ napi_queue_full,
149
+ napi_closing,
150
+ napi_bigint_expected,
151
+ napi_date_expected,
152
+ napi_arraybuffer_expected,
153
+ napi_detachable_arraybuffer_expected,
154
+ napi_would_deadlock, // unused
155
+ napi_no_external_buffers_allowed,
156
+ napi_cannot_run_js
157
+ }
158
+
159
+ export declare const enum napi_property_attributes {
160
+ napi_default = 0,
161
+ napi_writable = 1 << 0,
162
+ napi_enumerable = 1 << 1,
163
+ napi_configurable = 1 << 2,
164
+
165
+ // Used with napi_define_class to distinguish static properties
166
+ // from instance properties. Ignored by napi_define_properties.
167
+ napi_static = 1 << 10,
168
+
169
+ /// #ifdef NAPI_EXPERIMENTAL
170
+ // Default for class methods.
171
+ napi_default_method = napi_writable | napi_configurable,
172
+
173
+ // Default for object properties, like in JS obj[prop].
174
+ napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable
175
+ /// #endif // NAPI_EXPERIMENTAL
176
+ }
177
+
178
+ export declare const enum napi_valuetype {
179
+ napi_undefined,
180
+ napi_null,
181
+ napi_boolean,
182
+ napi_number,
183
+ napi_string,
184
+ napi_symbol,
185
+ napi_object,
186
+ napi_function,
187
+ napi_external,
188
+ napi_bigint
189
+ }
190
+
191
+ export declare const enum napi_typedarray_type {
192
+ napi_int8_array,
193
+ napi_uint8_array,
194
+ napi_uint8_clamped_array,
195
+ napi_int16_array,
196
+ napi_uint16_array,
197
+ napi_int32_array,
198
+ napi_uint32_array,
199
+ napi_float32_array,
200
+ napi_float64_array,
201
+ napi_bigint64_array,
202
+ napi_biguint64_array,
203
+ napi_float16_array,
204
+ }
205
+
206
+ export declare const enum napi_key_collection_mode {
207
+ napi_key_include_prototypes,
208
+ napi_key_own_only
209
+ }
210
+
211
+ export declare const enum napi_key_filter {
212
+ napi_key_all_properties = 0,
213
+ napi_key_writable = 1,
214
+ napi_key_enumerable = 1 << 1,
215
+ napi_key_configurable = 1 << 2,
216
+ napi_key_skip_strings = 1 << 3,
217
+ napi_key_skip_symbols = 1 << 4
218
+ }
219
+
220
+ export declare const enum napi_key_conversion {
221
+ napi_key_keep_numbers,
222
+ napi_key_numbers_to_strings
223
+ }
224
+
225
+ export declare const enum emnapi_memory_view_type {
226
+ emnapi_int8_array,
227
+ emnapi_uint8_array,
228
+ emnapi_uint8_clamped_array,
229
+ emnapi_int16_array,
230
+ emnapi_uint16_array,
231
+ emnapi_int32_array,
232
+ emnapi_uint32_array,
233
+ emnapi_float32_array,
234
+ emnapi_float64_array,
235
+ emnapi_bigint64_array,
236
+ emnapi_biguint64_array,
237
+ emnapi_float16_array,
238
+ emnapi_data_view = -1,
239
+ emnapi_buffer = -2
240
+ }
241
+
242
+ export declare const enum napi_threadsafe_function_call_mode {
243
+ napi_tsfn_nonblocking,
244
+ napi_tsfn_blocking
245
+ }
246
+
247
+ export declare const enum napi_threadsafe_function_release_mode {
248
+ napi_tsfn_release,
249
+ napi_tsfn_abort
250
+ }
251
+ export declare type CleanupHookCallbackFunction = number | ((arg: number) => void);
252
+
253
+ export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> {
254
+ constructor(id: number, value: S);
255
+ dispose(): void;
256
+ }
257
+
258
+ export declare class Context {
259
+ private _isStopping;
260
+ private _canCallIntoJs;
261
+ private _suppressDestroy;
262
+ envStore: Store<Env>;
263
+ scopeStore: ScopeStore;
264
+ refStore: Store<Reference>;
265
+ deferredStore: Store<Deferred<any>>;
266
+ handleStore: HandleStore;
267
+ private readonly refCounter?;
268
+ private readonly cleanupQueue;
269
+ private readonly _externalMemory;
270
+ feature: {
271
+ supportReflect: boolean;
272
+ supportFinalizer: boolean;
273
+ supportWeakSymbol: boolean;
274
+ supportBigInt: boolean;
275
+ supportNewFunction: boolean;
276
+ canSetFunctionName: boolean;
277
+ setImmediate: (callback: () => void) => void;
278
+ Buffer: BufferCtor | undefined;
279
+ MessageChannel: {
280
+ new (): MessageChannel;
281
+ prototype: MessageChannel;
282
+ } | undefined;
283
+ };
284
+ constructor(options?: ContextOptions);
285
+ /**
286
+ * Suppress the destroy on `beforeExit` event in Node.js.
287
+ * Call this method if you want to keep the context and
288
+ * all associated {@link Env | Env} alive,
289
+ * this also means that cleanup hooks will not be called.
290
+ * After call this method, you should call
291
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
292
+ */
293
+ suppressDestroy(): void;
294
+ getRuntimeVersions(): {
295
+ version: string;
296
+ NODE_API_SUPPORTED_VERSION_MAX: Version;
297
+ NAPI_VERSION_EXPERIMENTAL: Version;
298
+ NODE_API_DEFAULT_MODULE_API_VERSION: Version;
299
+ };
300
+ createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
301
+ createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
302
+ createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference;
303
+ createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
304
+ createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
305
+ createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
306
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
307
+ createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
308
+ createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
309
+ getCurrentScope(): HandleScope | null;
310
+ addToCurrentScope<V>(value: V): Handle<V>;
311
+ openScope(envObject?: Env): HandleScope;
312
+ closeScope(envObject?: Env, _scope?: HandleScope): void;
313
+ ensureHandle<S>(value: S): Handle<S>;
314
+ addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
315
+ removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
316
+ runCleanup(): void;
317
+ increaseWaitingRequestCounter(): void;
318
+ decreaseWaitingRequestCounter(): void;
319
+ setCanCallIntoJs(value: boolean): void;
320
+ setStopping(value: boolean): void;
321
+ canCallIntoJs(): boolean;
322
+ /**
323
+ * Destroy the context and call cleanup hooks.
324
+ * Associated {@link Env | Env} will be destroyed.
325
+ */
326
+ destroy(): void;
327
+ }
328
+
329
+ export declare interface ContextOptions {
330
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
331
+ }
332
+
333
+ export declare function createContext(options?: ContextOptions): Context;
334
+
335
+ export declare class Deferred<T = any> implements IStoreValue {
336
+ static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
337
+ id: number;
338
+ ctx: Context;
339
+ value: IDeferrdValue<T>;
340
+ constructor(ctx: Context, value: IDeferrdValue<T>);
341
+ resolve(value: T): void;
342
+ reject(reason?: any): void;
343
+ dispose(): void;
344
+ }
345
+
346
+ export declare class EmnapiError extends Error {
347
+ constructor(message?: string);
348
+ }
349
+
350
+ export declare abstract class Env implements IStoreValue {
351
+ readonly ctx: Context;
352
+ moduleApiVersion: number;
353
+ makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
354
+ makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
355
+ abort: (msg?: string) => never;
356
+ id: number;
357
+ openHandleScopes: number;
358
+ instanceData: TrackedFinalizer | null;
359
+ tryCatch: TryCatch;
360
+ refs: number;
361
+ reflist: RefTracker;
362
+ finalizing_reflist: RefTracker;
363
+ pendingFinalizers: RefTracker[];
364
+ lastError: {
365
+ errorCode: napi_status;
366
+ engineErrorCode: number;
367
+ engineReserved: Ptr;
368
+ };
369
+ inGcFinalizer: boolean;
370
+ constructor(ctx: Context, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never);
371
+ /** @virtual */
372
+ canCallIntoJs(): boolean;
373
+ terminatedOrTerminating(): boolean;
374
+ ref(): void;
375
+ unref(): void;
376
+ ensureHandle<S>(value: S): Handle<S>;
377
+ ensureHandleId(value: any): napi_value;
378
+ clearLastError(): napi_status;
379
+ setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
380
+ getReturnStatus(): napi_status;
381
+ callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
382
+ /** @virtual */
383
+ abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
384
+ invokeFinalizerFromGC(finalizer: RefTracker): void;
385
+ checkGCAccess(): void;
386
+ /** @virtual */
387
+ enqueueFinalizer(finalizer: RefTracker): void;
388
+ /** @virtual */
389
+ dequeueFinalizer(finalizer: RefTracker): void;
390
+ /** @virtual */
391
+ deleteMe(): void;
392
+ dispose(): void;
393
+ private readonly _bindingMap;
394
+ initObjectBinding<S extends object>(value: S): IReferenceBinding;
395
+ getObjectBinding<S extends object>(value: S): IReferenceBinding;
396
+ setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void;
397
+ getInstanceData(): number;
398
+ }
399
+
400
+ /** @public */
401
+ declare interface External_2 extends Record<any, any> {
402
+ }
403
+
404
+ /** @public */
405
+ declare const External_2: {
406
+ new (value: number | bigint): External_2;
407
+ prototype: null;
408
+ };
409
+ export { External_2 as External }
410
+
411
+ export declare class Finalizer {
412
+ envObject: Env;
413
+ private _finalizeCallback;
414
+ private _finalizeData;
415
+ private _finalizeHint;
416
+ private _makeDynCall_vppp;
417
+ constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
418
+ callback(): napi_finalize;
419
+ data(): void_p;
420
+ hint(): void_p;
421
+ resetEnv(): void;
422
+ resetFinalizer(): void;
423
+ callFinalizer(): void;
424
+ dispose(): void;
425
+ }
426
+
427
+ export declare function getDefaultContext(): Context;
428
+
429
+ /** @public */
430
+ export declare function getExternalValue(external: External_2): number | bigint;
431
+
432
+ export declare class Handle<S> {
433
+ id: number;
434
+ value: S;
435
+ constructor(id: number, value: S);
436
+ data(): void_p;
437
+ isNumber(): boolean;
438
+ isBigInt(): boolean;
439
+ isString(): boolean;
440
+ isFunction(): boolean;
441
+ isExternal(): boolean;
442
+ isObject(): boolean;
443
+ isArray(): boolean;
444
+ isArrayBuffer(): boolean;
445
+ isTypedArray(): boolean;
446
+ isBuffer(BufferConstructor?: BufferCtor): boolean;
447
+ isDataView(): boolean;
448
+ isDate(): boolean;
449
+ isPromise(): boolean;
450
+ isBoolean(): boolean;
451
+ isUndefined(): boolean;
452
+ isSymbol(): boolean;
453
+ isNull(): boolean;
454
+ dispose(): void;
455
+ }
456
+
457
+ export declare class HandleScope {
458
+ handleStore: HandleStore;
459
+ id: number;
460
+ parent: HandleScope | null;
461
+ child: HandleScope | null;
462
+ start: number;
463
+ end: number;
464
+ private _escapeCalled;
465
+ callbackInfo: ICallbackInfo;
466
+ constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number);
467
+ add<V>(value: V): Handle<V>;
468
+ addExternal(data: void_p): Handle<object>;
469
+ dispose(): void;
470
+ escape(handle: number): Handle<any> | null;
471
+ escapeCalled(): boolean;
472
+ }
473
+
474
+ export declare class HandleStore {
475
+ static UNDEFINED: ConstHandle<undefined>;
476
+ static NULL: ConstHandle<null>;
477
+ static FALSE: ConstHandle<false>;
478
+ static TRUE: ConstHandle<true>;
479
+ static GLOBAL: ConstHandle<typeof globalThis>;
480
+ static MIN_ID: 6;
481
+ private readonly _values;
482
+ private _next;
483
+ push<S>(value: S): Handle<S>;
484
+ erase(start: number, end: number): void;
485
+ get(id: Ptr): Handle<any> | undefined;
486
+ swap(a: number, b: number): void;
487
+ dispose(): void;
488
+ }
489
+
490
+ export declare interface ICallbackInfo {
491
+ thiz: any;
492
+ data: void_p;
493
+ args: ArrayLike<any>;
494
+ fn: Function;
495
+ }
496
+
497
+ export declare interface IDeferrdValue<T = any> {
498
+ resolve: (value: T) => void;
499
+ reject: (reason?: any) => void;
500
+ }
501
+
502
+ export declare interface IReferenceBinding {
503
+ wrapped: number;
504
+ tag: Uint32Array | null;
505
+ }
506
+
507
+ /** @public */
508
+ export declare function isExternal(object: unknown): object is External_2;
509
+
510
+ export declare function isReferenceType(v: any): v is object;
511
+
512
+ export declare interface IStoreValue {
513
+ id: number;
514
+ dispose(): void;
515
+ [x: string]: any;
516
+ }
517
+
518
+ export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL;
519
+
520
+ export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION;
521
+
522
+ export declare const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX;
523
+
524
+ export declare const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN;
525
+
526
+ export declare class NodeEnv extends Env {
527
+ filename: string;
528
+ private readonly nodeBinding?;
529
+ destructing: boolean;
530
+ finalizationScheduled: boolean;
531
+ constructor(ctx: Context, filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any);
532
+ deleteMe(): void;
533
+ canCallIntoJs(): boolean;
534
+ triggerFatalException(err: any): void;
535
+ callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T;
536
+ callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
537
+ callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void;
538
+ enqueueFinalizer(finalizer: RefTracker): void;
539
+ drainFinalizerQueue(): void;
540
+ }
541
+
542
+ export declare class NotSupportBufferError extends EmnapiError {
543
+ constructor(api: string, message: string);
544
+ }
545
+
546
+ export declare class NotSupportWeakRefError extends EmnapiError {
547
+ constructor(api: string, message: string);
548
+ }
549
+
550
+ export declare class Persistent<T> {
551
+ private _ref;
552
+ private _param;
553
+ private _callback;
554
+ private static readonly _registry;
555
+ constructor(value: T);
556
+ setWeak<P>(param: P, callback: (param: P) => void): void;
557
+ clearWeak(): void;
558
+ reset(): void;
559
+ isEmpty(): boolean;
560
+ deref(): T | undefined;
561
+ }
562
+
563
+ export declare class Reference extends RefTracker implements IStoreValue {
564
+ private static weakCallback;
565
+ id: number;
566
+ envObject: Env;
567
+ private readonly canBeWeak;
568
+ private _refcount;
569
+ private readonly _ownership;
570
+ persistent: Persistent<object>;
571
+ static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference;
572
+ protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
573
+ ref(): number;
574
+ unref(): number;
575
+ get(envObject?: Env): napi_value;
576
+ /** @virtual */
577
+ resetFinalizer(): void;
578
+ /** @virtual */
579
+ data(): void_p;
580
+ refcount(): number;
581
+ ownership(): ReferenceOwnership;
582
+ /** @virtual */
583
+ protected callUserFinalizer(): void;
584
+ /** @virtual */
585
+ protected invokeFinalizerFromGC(): void;
586
+ private _setWeak;
587
+ finalize(): void;
588
+ dispose(): void;
589
+ }
590
+
591
+ export declare enum ReferenceOwnership {
592
+ kRuntime = 0,
593
+ kUserland = 1
594
+ }
595
+
596
+ export declare class ReferenceWithData extends Reference {
597
+ private readonly _data;
598
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
599
+ private constructor();
600
+ data(): void_p;
601
+ }
602
+
603
+ export declare class ReferenceWithFinalizer extends Reference {
604
+ private _finalizer;
605
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer;
606
+ private constructor();
607
+ resetFinalizer(): void;
608
+ data(): void_p;
609
+ protected callUserFinalizer(): void;
610
+ protected invokeFinalizerFromGC(): void;
611
+ dispose(): void;
612
+ }
613
+
614
+ export declare class RefTracker {
615
+ /** @virtual */
616
+ dispose(): void;
617
+ /** @virtual */
618
+ finalize(): void;
619
+ private _next;
620
+ private _prev;
621
+ link(list: RefTracker): void;
622
+ unlink(): void;
623
+ static finalizeAll(list: RefTracker): void;
624
+ }
625
+
626
+ export declare class ScopeStore {
627
+ private readonly _rootScope;
628
+ currentScope: HandleScope;
629
+ private readonly _values;
630
+ constructor();
631
+ get(id: number): HandleScope | undefined;
632
+ openScope(handleStore: HandleStore): HandleScope;
633
+ closeScope(): void;
634
+ dispose(): void;
635
+ }
636
+
637
+ export declare class Store<V extends IStoreValue> {
638
+ protected _values: Array<V | undefined>;
639
+ private _freeList;
640
+ private _size;
641
+ constructor();
642
+ add(value: V): void;
643
+ get(id: Ptr): V | undefined;
644
+ has(id: Ptr): boolean;
645
+ remove(id: Ptr): void;
646
+ dispose(): void;
647
+ }
648
+
649
+ export declare class TrackedFinalizer extends RefTracker {
650
+ private _finalizer;
651
+ static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
652
+ private constructor();
653
+ data(): void_p;
654
+ dispose(): void;
655
+ finalize(): void;
656
+ }
657
+
658
+ export declare class TryCatch {
659
+ private _exception;
660
+ private _caught;
661
+ isEmpty(): boolean;
662
+ hasCaught(): boolean;
663
+ exception(): any;
664
+ setError(err: any): void;
665
+ reset(): void;
666
+ extractException(): any;
667
+ }
668
+
669
+ export declare const version: string;
670
+
671
+ export { }
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js ADDED
@@ -0,0 +1 @@
 
 
1
+ const e=new WeakMap;function t(t){return e.has(t)}const i=(()=>{function t(t){Object.setPrototypeOf(this,null),e.set(this,t)}return t.prototype=null,t})();function s(i){if(!t(i))throw new TypeError("not external");return e.get(i)}const n=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),r=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&n)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}();class o{constructor(){this._exception=void 0,this._caught=!1}isEmpty(){return!this._caught}hasCaught(){return this._caught}exception(){return this._exception}setError(e){this._caught=!0,this._exception=e}reset(){this._caught=!1,this._exception=void 0}extractException(){const e=this._exception;return this.reset(),e}}const a=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),l="object"==typeof Reflect,c="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,u=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),h="undefined"!=typeof BigInt;const p=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),f="function"==typeof MessageChannel?MessageChannel:function(){try{return p("worker_threads").MessageChannel}catch(e){}}(),d="function"==typeof setImmediate?setImmediate.bind(r):function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(f){let t=new f;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},_="function"==typeof Buffer?Buffer:function(){try{return p("buffer").Buffer}catch(e){}}(),v="1.11.3",g=2147483647;class y{constructor(e,t){this.id=e,this.value=t}data(){return s(this.value)}isNumber(){return"number"==typeof this.value}isBigInt(){return"bigint"==typeof this.value}isString(){return"string"==typeof this.value}isFunction(){return"function"==typeof this.value}isExternal(){return t(this.value)}isObject(){return"object"==typeof this.value&&null!==this.value}isArray(){return Array.isArray(this.value)}isArrayBuffer(){return this.value instanceof ArrayBuffer}isTypedArray(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(e){return!!ArrayBuffer.isView(this.value)||(null!=e||(e=_),"function"==typeof e&&e.isBuffer(this.value))}isDataView(){return this.value instanceof DataView}isDate(){return this.value instanceof Date}isPromise(){return this.value instanceof Promise}isBoolean(){return"boolean"==typeof this.value}isUndefined(){return void 0===this.value}isSymbol(){return"symbol"==typeof this.value}isNull(){return null===this.value}dispose(){this.value=void 0}}class x extends y{constructor(e,t){super(e,t)}dispose(){}}class b{constructor(){this._values=[void 0,b.UNDEFINED,b.NULL,b.FALSE,b.TRUE,b.GLOBAL],this._next=b.MIN_ID}push(e){let t;const i=this._next,s=this._values;return i<s.length?(t=s[i],t.value=e):(t=new y(i,e),s[i]=t),this._next++,t}erase(e,t){this._next=e;const i=this._values;for(let s=e;s<t;++s)i[s].dispose()}get(e){return this._values[e]}swap(e,t){const i=this._values,s=i[e];i[e]=i[t],i[e].id=Number(e),i[t]=s,s.id=Number(t)}dispose(){this._values.length=b.MIN_ID,this._next=b.MIN_ID}}b.UNDEFINED=new x(1,void 0),b.NULL=new x(2,null),b.FALSE=new x(3,!1),b.TRUE=new x(4,!0),b.GLOBAL=new x(5,r),b.MIN_ID=6;class z{constructor(e,t,i,s,n=s){this.handleStore=e,this.id=t,this.parent=i,this.child=null,null!==i&&(i.child=this),this.start=s,this.end=n,this._escapeCalled=!1,this.callbackInfo={thiz:void 0,data:0,args:void 0,fn:void 0}}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e){return this.add(new i(e))}dispose(){this._escapeCalled&&(this._escapeCalled=!1),this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class w{constructor(){this._rootScope=new z(null,0,null,1,b.MIN_ID),this.currentScope=this._rootScope,this._values=[void 0]}get(e){return this._values[e]}openScope(e){const t=this.currentScope;let i=t.child;if(null!==i)i.start=i.end=t.end;else{const s=t.id+1;i=new z(e,s,t,t.end),this._values[s]=i}return this.currentScope=i,i}closeScope(){const e=this.currentScope;this.currentScope=e.parent,e.dispose()}dispose(){this.currentScope=this._rootScope,this._values.length=1}}class k{constructor(){this._next=null,this._prev=null}dispose(){}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class m{constructor(e,t=0,i=0,s=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=i,this._finalizeHint=s,this._makeDynCall_vppp=e.makeDynCall_vppp}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetEnv(){this.envObject=void 0}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}callFinalizer(){const e=this._finalizeCallback,t=this._finalizeData,i=this._finalizeHint;if(this.resetFinalizer(),!e)return;const s=Number(e);this.envObject?this.envObject.callFinalizer(s,t,i):this._makeDynCall_vppp(s)(0,t,i)}dispose(){this.envObject=void 0,this._makeDynCall_vppp=void 0}}class E extends k{static create(e,t,i,s){const n=new E(e,t,i,s);return n.link(e.finalizing_reflist),n}constructor(e,t,i,s){super(),this._finalizer=new m(e,t,i,s)}data(){return this._finalizer.data()}dispose(){this._finalizer&&(this.unlink(),this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),this._finalizer=void 0,super.dispose())}finalize(){let e;this.unlink();let t=!1;try{this._finalizer.callFinalizer()}catch(i){t=!0,e=i}if(this.dispose(),t)throw e}}function S(e,t){if(!e.terminatedOrTerminating())throw t}class C{constructor(e,t,i,s,n){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=i,this.makeDynCall_vp=s,this.abort=n,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new o,this.refs=1,this.reflist=new k,this.finalizing_reflist=new k,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,this._bindingMap=new WeakMap,this.id=0}canCallIntoJs(){return!0}terminatedOrTerminating(){return!this.canCallIntoJs()}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return 0!==e.errorCode&&(e.errorCode=0),0!==e.engineErrorCode&&(e.engineErrorCode=0),0!==e.engineReserved&&(e.engineReserved=0),0}setLastError(e,t=0,i=0){const s=this.lastError;return s.errorCode!==e&&(s.errorCode=e),s.engineErrorCode!==t&&(s.engineErrorCode=t),s.engineReserved!==i&&(s.engineReserved=i),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=S){const i=this.openHandleScopes;this.clearLastError();const s=e(this);if(i!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return s}invokeFinalizerFromGC(e){if(this.moduleApiVersion!==g)this.enqueueFinalizer(e);else{const t=this.inGcFinalizer;this.inGcFinalizer=!0;try{e.finalize()}finally{this.inGcFinalizer=t}}}checkGCAccess(){this.moduleApiVersion===g&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e)}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}deleteMe(){k.finalizeAll(this.finalizing_reflist),k.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),this.finalizing_reflist.dispose(),this.reflist.dispose(),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,i){this.instanceData&&this.instanceData.dispose(),this.instanceData=E.create(this,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class F extends C{constructor(e,t,i,s,n,r,o){super(e,i,s,n,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return super.canCallIntoJs()&&this.ctx.canCallIntoJs()}triggerFatalException(e){if(this.nodeBinding)this.nodeBinding.napi.fatalException(e);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw e;process._fatalException(e)||(console.error(e),process.exit(1))}}callbackIntoModule(e,t){return this.callIntoModule(t,(t,i)=>{if(t.terminatedOrTerminating())return;const s="object"==typeof process&&null!==process,n=!!s&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(t.moduleApiVersion<10&&!n&&!e){return void(s&&"function"==typeof process.emitWarning?process.emitWarning:function(e,t,i){if(e instanceof Error)console.warn(e.toString());else{const s=i?`[${i}] `:"";console.warn(`${s}${t||"Warning"}: ${e}`)}})("Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168")}t.triggerFatalException(i)})}callFinalizer(e,t,i){this.callFinalizerInternal(1,e,t,i)}callFinalizerInternal(e,t,i,s){const n=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),()=>{n(r,i,s)})}finally{this.ctx.closeScope(this,o)}}enqueueFinalizer(e){super.enqueueFinalizer(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),d(()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()}))}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}}function I(e,t,i,s,n,r,o){(i="number"!=typeof i?8:i)<8?i=8:i>10&&i!==g&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version 10 add-ons.`)}(t,i);const a=new F(e,t,i,s,n,r,o);return e.envStore.add(a),e.addCleanupHook(a,()=>{a.unref()},0),a}class O extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof O)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,i):this.__proto__=i,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(O.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class D extends O{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(D.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class R extends O{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(R.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class N{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class A{constructor(e){this._ref=new N(e)}setWeak(e,t){if(!c||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{A._registry.register(i,this,this);const s=new WeakRef(i);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof i)throw e}}clearWeak(){if(c&&void 0!==this._ref&&this._ref instanceof WeakRef){try{A._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new N(e)}}reset(){if(c)try{A._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof N&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}var H;A._registry=c?new FinalizationRegistry(e=>{e._ref=void 0;const t=e._callback,i=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(i)}):void 0,exports.ReferenceOwnership=void 0,(H=exports.ReferenceOwnership||(exports.ReferenceOwnership={}))[H.kRuntime=0]="kRuntime",H[H.kUserland=1]="kUserland";class j extends k{static weakCallback(e){e.persistent.reset(),e.invokeFinalizerFromGC()}static create(e,t,i,s,n,r,o){const a=new j(e,t,i,s);return e.ctx.refStore.add(a),a.link(e.reflist),a}constructor(e,t,i,s){super(),this.envObject=e,this._refcount=i,this._ownership=s;const n=e.ctx.handleStore.get(t);var r;this.canBeWeak=(r=n).isObject()||r.isFunction()||r.isSymbol(),this.persistent=new A(n.value),this.id=0,0===i&&this._setWeak()}ref(){return this.persistent.isEmpty()?0:(1===++this._refcount&&this.canBeWeak&&this.persistent.clearWeak(),this._refcount)}unref(){return this.persistent.isEmpty()||0===this._refcount?0:(0===--this._refcount&&this._setWeak(),this._refcount)}get(e=this.envObject){if(this.persistent.isEmpty())return 0;const t=this.persistent.deref();return e.ensureHandle(t).id}resetFinalizer(){}data(){return 0}refcount(){return this._refcount}ownership(){return this._ownership}callUserFinalizer(){}invokeFinalizerFromGC(){this.finalize()}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,j.weakCallback):this.persistent.reset()}finalize(){this.persistent.reset();const e=this._ownership===exports.ReferenceOwnership.kRuntime;this.unlink(),this.callUserFinalizer(),e&&this.dispose()}dispose(){0!==this.id&&(this.unlink(),this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.envObject=void 0,this.id=0)}}class B extends j{static create(e,t,i,s,n){const r=new B(e,t,i,s,n);return e.ctx.refStore.add(r),r.link(e.reflist),r}constructor(e,t,i,s,n){super(e,t,i,s),this._data=n}data(){return this._data}}class M extends j{static create(e,t,i,s,n,r,o){const a=new M(e,t,i,s,n,r,o);return e.ctx.refStore.add(a),a.link(e.finalizing_reflist),a}constructor(e,t,i,s,n,r,o){super(e,t,i,s),this._finalizer=new m(e,n,r,o)}resetFinalizer(){this._finalizer.resetFinalizer()}data(){return this._finalizer.data()}callUserFinalizer(){this._finalizer.callFinalizer()}invokeFinalizerFromGC(){this._finalizer.envObject.invokeFinalizerFromGC(this)}dispose(){this._finalizer&&(this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),super.dispose(),this._finalizer=void 0)}}class T{static create(e,t){const i=new T(e,t);return e.deferredStore.add(i),i}constructor(e,t){Object.defineProperties(this,{id:{configurable:!0,enumerable:!0,value:0,writable:!0},ctx:{configurable:!0,enumerable:!0,value:e,writable:!0},value:{configurable:!0,enumerable:!0,value:t,writable:!0}})}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class W{constructor(){this._values=[void 0],this._values.length=4,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=e+(e>>1)+16)}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}const L=BigInt(1)<<BigInt(60),P=-L;class U{constructor(e){this.total=BigInt(0),this.onChange=null!=e?e:null}adjust(e){if(e=BigInt(e),!(P<=e&&e<L))throw new RangeError(`changeInBytes ${e} is out of reasonable range`);const t=this.total;this.total+=e;const i=this.total,s=this.onChange;return e&&(null==s||s(i,t,e)),i}}class V{constructor(e,t,i,s){this.envObject=e,this.fn=t,this.arg=i,this.order=s}}class G{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,i){if(this._cleanupHooks.filter(s=>s.envObject===e&&s.fn===t&&s.arg===i).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new V(e,t,i,this._cleanupHookCounter++))}remove(e,t,i){for(let s=0;s<this._cleanupHooks.length;++s){const n=this._cleanupHooks[s];if(n.envObject===e&&n.fn===t&&n.arg===i)return void this._cleanupHooks.splice(s,1)}}drain(){const e=this._cleanupHooks.slice();e.sort((e,t)=>t.order-e.order);for(let t=0;t<e.length;++t){const i=e[t];"number"==typeof i.fn?i.envObject.makeDynCall_vp(i.fn)(i.arg):i.fn(i.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(i),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class q{constructor(){this.refHandle=(new f).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref&&this.refHandle.unref(),this.count--)}}class ${constructor(e){this._isStopping=!1,this._canCallIntoJs=!0,this._suppressDestroy=!1,this.envStore=new W,this.scopeStore=new w,this.refStore=new W,this.deferredStore=new W,this.handleStore=new b,this.feature={supportReflect:l,supportFinalizer:c,supportWeakSymbol:u,supportBigInt:h,supportNewFunction:n,canSetFunctionName:a,setImmediate:d,Buffer:_,MessageChannel:f},this.cleanupQueue=new G,this._externalMemory=new U(null==e?void 0:e.onExternalMemoryChange),"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new q,process.once("beforeExit",()=>{this._suppressDestroy||this.destroy()}))}suppressDestroy(){this._suppressDestroy=!0}getRuntimeVersions(){return{version:v,NODE_API_SUPPORTED_VERSION_MAX:10,NAPI_VERSION_EXPERIMENTAL:g,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new D(e,t)}createNotSupportBufferError(e,t){return new R(e,t)}createReference(e,t,i,s){return j.create(e,t,i,s)}createReferenceWithData(e,t,i,s,n){return B.create(e,t,i,s,n)}createReferenceWithFinalizer(e,t,i,s,n=0,r=0,o=0){return M.create(e,t,i,s,n,r,o)}createDeferred(e){return T.create(this,e)}adjustAmountOfExternalAllocatedMemory(e){return this._externalMemory.adjust(e)}createEnv(e,t,i,s,n,r){return I(this,e,t,i,s,n,r)}createTrackedFinalizer(e,t,i,s){return E.create(e,t,i,s)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){const t=this.scopeStore.openScope(this.handleStore);return e&&e.openHandleScopes++,t}closeScope(e,t){e&&0===e.openHandleScopes||(this.scopeStore.closeScope(),e&&e.openHandleScopes--)}ensureHandle(e){switch(e){case void 0:return b.UNDEFINED;case null:return b.NULL;case!0:return b.TRUE;case!1:return b.FALSE;case r:return b.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,i){this.cleanupQueue.add(e,t,i)}removeCleanupHook(e,t,i){this.cleanupQueue.remove(e,t,i)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}setCanCallIntoJs(e){this._canCallIntoJs=e}setStopping(e){this._isStopping=e}canCallIntoJs(){return this._canCallIntoJs&&!this._isStopping}destroy(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()}}let J;function Q(e){return new $(e)}exports.ConstHandle=x,exports.Context=$,exports.Deferred=T,exports.EmnapiError=O,exports.Env=C,exports.External=i,exports.Finalizer=m,exports.Handle=y,exports.HandleScope=z,exports.HandleStore=b,exports.NAPI_VERSION_EXPERIMENTAL=g,exports.NODE_API_DEFAULT_MODULE_API_VERSION=8,exports.NODE_API_SUPPORTED_VERSION_MAX=10,exports.NODE_API_SUPPORTED_VERSION_MIN=1,exports.NodeEnv=F,exports.NotSupportBufferError=R,exports.NotSupportWeakRefError=D,exports.Persistent=A,exports.RefTracker=k,exports.Reference=j,exports.ReferenceWithData=B,exports.ReferenceWithFinalizer=M,exports.ScopeStore=w,exports.Store=W,exports.TrackedFinalizer=E,exports.TryCatch=o,exports.createContext=Q,exports.getDefaultContext=function(){return J||(J=Q()),J},exports.getExternalValue=s,exports.isExternal=t,exports.isReferenceType=function(e){return"object"==typeof e&&null!==e||"function"==typeof e},exports.version=v;
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.d.mts ADDED
@@ -0,0 +1,671 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export declare type Ptr = number | bigint
2
+
3
+ export declare interface IBuffer extends Uint8Array {}
4
+ export declare interface BufferCtor {
5
+ readonly prototype: IBuffer
6
+ /** @deprecated */
7
+ new (...args: any[]): IBuffer
8
+ from: {
9
+ (buffer: ArrayBufferLike): IBuffer
10
+ (buffer: ArrayBufferLike, byteOffset: number, length: number): IBuffer
11
+ }
12
+ alloc: (size: number) => IBuffer
13
+ isBuffer: (obj: unknown) => obj is IBuffer
14
+ }
15
+
16
+ export declare const enum GlobalHandle {
17
+ UNDEFINED = 1,
18
+ NULL,
19
+ FALSE,
20
+ TRUE,
21
+ GLOBAL
22
+ }
23
+
24
+ export declare const enum Version {
25
+ NODE_API_SUPPORTED_VERSION_MIN = 1,
26
+ NODE_API_DEFAULT_MODULE_API_VERSION = 8,
27
+ NODE_API_SUPPORTED_VERSION_MAX = 10,
28
+ NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ export declare type Pointer<T> = number
32
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
+ export declare type PointerPointer<T> = number
34
+ export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T>
35
+ export declare type Const<T> = T
36
+
37
+ export declare type void_p = Pointer<void>
38
+ export declare type void_pp = Pointer<void_p>
39
+ export declare type bool = number
40
+ export declare type char = number
41
+ export declare type char_p = Pointer<char>
42
+ export declare type unsigned_char = number
43
+ export declare type const_char = Const<char>
44
+ export declare type const_char_p = Pointer<const_char>
45
+ export declare type char16_t_p = number
46
+ export declare type const_char16_t_p = number
47
+
48
+ export declare type short = number
49
+ export declare type unsigned_short = number
50
+ export declare type int = number
51
+ export declare type unsigned_int = number
52
+ export declare type long = number
53
+ export declare type unsigned_long = number
54
+ export declare type long_long = bigint
55
+ export declare type unsigned_long_long = bigint
56
+ export declare type float = number
57
+ export declare type double = number
58
+ export declare type long_double = number
59
+ export declare type size_t = number
60
+
61
+ export declare type int8_t = number
62
+ export declare type uint8_t = number
63
+ export declare type int16_t = number
64
+ export declare type uint16_t = number
65
+ export declare type int32_t = number
66
+ export declare type uint32_t = number
67
+ export declare type int64_t = bigint
68
+ export declare type uint64_t = bigint
69
+ export declare type napi_env = Pointer<unknown>
70
+
71
+ export declare type napi_value = Pointer<unknown>
72
+ export declare type napi_ref = Pointer<unknown>
73
+ export declare type napi_deferred = Pointer<unknown>
74
+ export declare type napi_handle_scope = Pointer<unknown>
75
+ export declare type napi_escapable_handle_scope = Pointer<unknown>
76
+
77
+ export declare type napi_addon_register_func = FunctionPointer<(env: napi_env, exports: napi_value) => napi_value>
78
+
79
+ export declare type napi_callback_info = Pointer<unknown>
80
+ export declare type napi_callback = FunctionPointer<(env: napi_env, info: napi_callback_info) => napi_value>
81
+
82
+ export declare interface napi_extended_error_info {
83
+ error_message: const_char_p
84
+ engine_reserved: void_p
85
+ engine_error_code: uint32_t
86
+ error_code: napi_status
87
+ }
88
+
89
+ export declare interface napi_property_descriptor {
90
+ // One of utf8name or name should be NULL.
91
+ utf8name: const_char_p
92
+ name: napi_value
93
+
94
+ method: napi_callback
95
+ getter: napi_callback
96
+ setter: napi_callback
97
+ value: napi_value
98
+ /* napi_property_attributes */
99
+ attributes: number
100
+ data: void_p
101
+ }
102
+
103
+ export declare type napi_finalize = FunctionPointer<(
104
+ env: napi_env,
105
+ finalize_data: void_p,
106
+ finalize_hint: void_p
107
+ ) => void>
108
+
109
+ export declare interface node_module {
110
+ nm_version: int32_t
111
+ nm_flags: uint32_t
112
+ nm_filename: Pointer<const_char>
113
+ nm_register_func: napi_addon_register_func
114
+ nm_modname: Pointer<const_char>
115
+ nm_priv: Pointer<void>
116
+ reserved: PointerPointer<void>
117
+ }
118
+
119
+ export declare interface napi_node_version {
120
+ major: uint32_t
121
+ minor: uint32_t
122
+ patch: uint32_t
123
+ release: const_char_p
124
+ }
125
+
126
+ export declare interface emnapi_emscripten_version {
127
+ major: uint32_t
128
+ minor: uint32_t
129
+ patch: uint32_t
130
+ }
131
+
132
+ export declare const enum napi_status {
133
+ napi_ok,
134
+ napi_invalid_arg,
135
+ napi_object_expected,
136
+ napi_string_expected,
137
+ napi_name_expected,
138
+ napi_function_expected,
139
+ napi_number_expected,
140
+ napi_boolean_expected,
141
+ napi_array_expected,
142
+ napi_generic_failure,
143
+ napi_pending_exception,
144
+ napi_cancelled,
145
+ napi_escape_called_twice,
146
+ napi_handle_scope_mismatch,
147
+ napi_callback_scope_mismatch,
148
+ napi_queue_full,
149
+ napi_closing,
150
+ napi_bigint_expected,
151
+ napi_date_expected,
152
+ napi_arraybuffer_expected,
153
+ napi_detachable_arraybuffer_expected,
154
+ napi_would_deadlock, // unused
155
+ napi_no_external_buffers_allowed,
156
+ napi_cannot_run_js
157
+ }
158
+
159
+ export declare const enum napi_property_attributes {
160
+ napi_default = 0,
161
+ napi_writable = 1 << 0,
162
+ napi_enumerable = 1 << 1,
163
+ napi_configurable = 1 << 2,
164
+
165
+ // Used with napi_define_class to distinguish static properties
166
+ // from instance properties. Ignored by napi_define_properties.
167
+ napi_static = 1 << 10,
168
+
169
+ /// #ifdef NAPI_EXPERIMENTAL
170
+ // Default for class methods.
171
+ napi_default_method = napi_writable | napi_configurable,
172
+
173
+ // Default for object properties, like in JS obj[prop].
174
+ napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable
175
+ /// #endif // NAPI_EXPERIMENTAL
176
+ }
177
+
178
+ export declare const enum napi_valuetype {
179
+ napi_undefined,
180
+ napi_null,
181
+ napi_boolean,
182
+ napi_number,
183
+ napi_string,
184
+ napi_symbol,
185
+ napi_object,
186
+ napi_function,
187
+ napi_external,
188
+ napi_bigint
189
+ }
190
+
191
+ export declare const enum napi_typedarray_type {
192
+ napi_int8_array,
193
+ napi_uint8_array,
194
+ napi_uint8_clamped_array,
195
+ napi_int16_array,
196
+ napi_uint16_array,
197
+ napi_int32_array,
198
+ napi_uint32_array,
199
+ napi_float32_array,
200
+ napi_float64_array,
201
+ napi_bigint64_array,
202
+ napi_biguint64_array,
203
+ napi_float16_array,
204
+ }
205
+
206
+ export declare const enum napi_key_collection_mode {
207
+ napi_key_include_prototypes,
208
+ napi_key_own_only
209
+ }
210
+
211
+ export declare const enum napi_key_filter {
212
+ napi_key_all_properties = 0,
213
+ napi_key_writable = 1,
214
+ napi_key_enumerable = 1 << 1,
215
+ napi_key_configurable = 1 << 2,
216
+ napi_key_skip_strings = 1 << 3,
217
+ napi_key_skip_symbols = 1 << 4
218
+ }
219
+
220
+ export declare const enum napi_key_conversion {
221
+ napi_key_keep_numbers,
222
+ napi_key_numbers_to_strings
223
+ }
224
+
225
+ export declare const enum emnapi_memory_view_type {
226
+ emnapi_int8_array,
227
+ emnapi_uint8_array,
228
+ emnapi_uint8_clamped_array,
229
+ emnapi_int16_array,
230
+ emnapi_uint16_array,
231
+ emnapi_int32_array,
232
+ emnapi_uint32_array,
233
+ emnapi_float32_array,
234
+ emnapi_float64_array,
235
+ emnapi_bigint64_array,
236
+ emnapi_biguint64_array,
237
+ emnapi_float16_array,
238
+ emnapi_data_view = -1,
239
+ emnapi_buffer = -2
240
+ }
241
+
242
+ export declare const enum napi_threadsafe_function_call_mode {
243
+ napi_tsfn_nonblocking,
244
+ napi_tsfn_blocking
245
+ }
246
+
247
+ export declare const enum napi_threadsafe_function_release_mode {
248
+ napi_tsfn_release,
249
+ napi_tsfn_abort
250
+ }
251
+ export declare type CleanupHookCallbackFunction = number | ((arg: number) => void);
252
+
253
+ export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> {
254
+ constructor(id: number, value: S);
255
+ dispose(): void;
256
+ }
257
+
258
+ export declare class Context {
259
+ private _isStopping;
260
+ private _canCallIntoJs;
261
+ private _suppressDestroy;
262
+ envStore: Store<Env>;
263
+ scopeStore: ScopeStore;
264
+ refStore: Store<Reference>;
265
+ deferredStore: Store<Deferred<any>>;
266
+ handleStore: HandleStore;
267
+ private readonly refCounter?;
268
+ private readonly cleanupQueue;
269
+ private readonly _externalMemory;
270
+ feature: {
271
+ supportReflect: boolean;
272
+ supportFinalizer: boolean;
273
+ supportWeakSymbol: boolean;
274
+ supportBigInt: boolean;
275
+ supportNewFunction: boolean;
276
+ canSetFunctionName: boolean;
277
+ setImmediate: (callback: () => void) => void;
278
+ Buffer: BufferCtor | undefined;
279
+ MessageChannel: {
280
+ new (): MessageChannel;
281
+ prototype: MessageChannel;
282
+ } | undefined;
283
+ };
284
+ constructor(options?: ContextOptions);
285
+ /**
286
+ * Suppress the destroy on `beforeExit` event in Node.js.
287
+ * Call this method if you want to keep the context and
288
+ * all associated {@link Env | Env} alive,
289
+ * this also means that cleanup hooks will not be called.
290
+ * After call this method, you should call
291
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
292
+ */
293
+ suppressDestroy(): void;
294
+ getRuntimeVersions(): {
295
+ version: string;
296
+ NODE_API_SUPPORTED_VERSION_MAX: Version;
297
+ NAPI_VERSION_EXPERIMENTAL: Version;
298
+ NODE_API_DEFAULT_MODULE_API_VERSION: Version;
299
+ };
300
+ createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
301
+ createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
302
+ createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference;
303
+ createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
304
+ createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
305
+ createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
306
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
307
+ createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
308
+ createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
309
+ getCurrentScope(): HandleScope | null;
310
+ addToCurrentScope<V>(value: V): Handle<V>;
311
+ openScope(envObject?: Env): HandleScope;
312
+ closeScope(envObject?: Env, _scope?: HandleScope): void;
313
+ ensureHandle<S>(value: S): Handle<S>;
314
+ addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
315
+ removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
316
+ runCleanup(): void;
317
+ increaseWaitingRequestCounter(): void;
318
+ decreaseWaitingRequestCounter(): void;
319
+ setCanCallIntoJs(value: boolean): void;
320
+ setStopping(value: boolean): void;
321
+ canCallIntoJs(): boolean;
322
+ /**
323
+ * Destroy the context and call cleanup hooks.
324
+ * Associated {@link Env | Env} will be destroyed.
325
+ */
326
+ destroy(): void;
327
+ }
328
+
329
+ export declare interface ContextOptions {
330
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
331
+ }
332
+
333
+ export declare function createContext(options?: ContextOptions): Context;
334
+
335
+ export declare class Deferred<T = any> implements IStoreValue {
336
+ static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
337
+ id: number;
338
+ ctx: Context;
339
+ value: IDeferrdValue<T>;
340
+ constructor(ctx: Context, value: IDeferrdValue<T>);
341
+ resolve(value: T): void;
342
+ reject(reason?: any): void;
343
+ dispose(): void;
344
+ }
345
+
346
+ export declare class EmnapiError extends Error {
347
+ constructor(message?: string);
348
+ }
349
+
350
+ export declare abstract class Env implements IStoreValue {
351
+ readonly ctx: Context;
352
+ moduleApiVersion: number;
353
+ makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
354
+ makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
355
+ abort: (msg?: string) => never;
356
+ id: number;
357
+ openHandleScopes: number;
358
+ instanceData: TrackedFinalizer | null;
359
+ tryCatch: TryCatch;
360
+ refs: number;
361
+ reflist: RefTracker;
362
+ finalizing_reflist: RefTracker;
363
+ pendingFinalizers: RefTracker[];
364
+ lastError: {
365
+ errorCode: napi_status;
366
+ engineErrorCode: number;
367
+ engineReserved: Ptr;
368
+ };
369
+ inGcFinalizer: boolean;
370
+ constructor(ctx: Context, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never);
371
+ /** @virtual */
372
+ canCallIntoJs(): boolean;
373
+ terminatedOrTerminating(): boolean;
374
+ ref(): void;
375
+ unref(): void;
376
+ ensureHandle<S>(value: S): Handle<S>;
377
+ ensureHandleId(value: any): napi_value;
378
+ clearLastError(): napi_status;
379
+ setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
380
+ getReturnStatus(): napi_status;
381
+ callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
382
+ /** @virtual */
383
+ abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
384
+ invokeFinalizerFromGC(finalizer: RefTracker): void;
385
+ checkGCAccess(): void;
386
+ /** @virtual */
387
+ enqueueFinalizer(finalizer: RefTracker): void;
388
+ /** @virtual */
389
+ dequeueFinalizer(finalizer: RefTracker): void;
390
+ /** @virtual */
391
+ deleteMe(): void;
392
+ dispose(): void;
393
+ private readonly _bindingMap;
394
+ initObjectBinding<S extends object>(value: S): IReferenceBinding;
395
+ getObjectBinding<S extends object>(value: S): IReferenceBinding;
396
+ setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void;
397
+ getInstanceData(): number;
398
+ }
399
+
400
+ /** @public */
401
+ declare interface External_2 extends Record<any, any> {
402
+ }
403
+
404
+ /** @public */
405
+ declare const External_2: {
406
+ new (value: number | bigint): External_2;
407
+ prototype: null;
408
+ };
409
+ export { External_2 as External }
410
+
411
+ export declare class Finalizer {
412
+ envObject: Env;
413
+ private _finalizeCallback;
414
+ private _finalizeData;
415
+ private _finalizeHint;
416
+ private _makeDynCall_vppp;
417
+ constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
418
+ callback(): napi_finalize;
419
+ data(): void_p;
420
+ hint(): void_p;
421
+ resetEnv(): void;
422
+ resetFinalizer(): void;
423
+ callFinalizer(): void;
424
+ dispose(): void;
425
+ }
426
+
427
+ export declare function getDefaultContext(): Context;
428
+
429
+ /** @public */
430
+ export declare function getExternalValue(external: External_2): number | bigint;
431
+
432
+ export declare class Handle<S> {
433
+ id: number;
434
+ value: S;
435
+ constructor(id: number, value: S);
436
+ data(): void_p;
437
+ isNumber(): boolean;
438
+ isBigInt(): boolean;
439
+ isString(): boolean;
440
+ isFunction(): boolean;
441
+ isExternal(): boolean;
442
+ isObject(): boolean;
443
+ isArray(): boolean;
444
+ isArrayBuffer(): boolean;
445
+ isTypedArray(): boolean;
446
+ isBuffer(BufferConstructor?: BufferCtor): boolean;
447
+ isDataView(): boolean;
448
+ isDate(): boolean;
449
+ isPromise(): boolean;
450
+ isBoolean(): boolean;
451
+ isUndefined(): boolean;
452
+ isSymbol(): boolean;
453
+ isNull(): boolean;
454
+ dispose(): void;
455
+ }
456
+
457
+ export declare class HandleScope {
458
+ handleStore: HandleStore;
459
+ id: number;
460
+ parent: HandleScope | null;
461
+ child: HandleScope | null;
462
+ start: number;
463
+ end: number;
464
+ private _escapeCalled;
465
+ callbackInfo: ICallbackInfo;
466
+ constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number);
467
+ add<V>(value: V): Handle<V>;
468
+ addExternal(data: void_p): Handle<object>;
469
+ dispose(): void;
470
+ escape(handle: number): Handle<any> | null;
471
+ escapeCalled(): boolean;
472
+ }
473
+
474
+ export declare class HandleStore {
475
+ static UNDEFINED: ConstHandle<undefined>;
476
+ static NULL: ConstHandle<null>;
477
+ static FALSE: ConstHandle<false>;
478
+ static TRUE: ConstHandle<true>;
479
+ static GLOBAL: ConstHandle<typeof globalThis>;
480
+ static MIN_ID: 6;
481
+ private readonly _values;
482
+ private _next;
483
+ push<S>(value: S): Handle<S>;
484
+ erase(start: number, end: number): void;
485
+ get(id: Ptr): Handle<any> | undefined;
486
+ swap(a: number, b: number): void;
487
+ dispose(): void;
488
+ }
489
+
490
+ export declare interface ICallbackInfo {
491
+ thiz: any;
492
+ data: void_p;
493
+ args: ArrayLike<any>;
494
+ fn: Function;
495
+ }
496
+
497
+ export declare interface IDeferrdValue<T = any> {
498
+ resolve: (value: T) => void;
499
+ reject: (reason?: any) => void;
500
+ }
501
+
502
+ export declare interface IReferenceBinding {
503
+ wrapped: number;
504
+ tag: Uint32Array | null;
505
+ }
506
+
507
+ /** @public */
508
+ export declare function isExternal(object: unknown): object is External_2;
509
+
510
+ export declare function isReferenceType(v: any): v is object;
511
+
512
+ export declare interface IStoreValue {
513
+ id: number;
514
+ dispose(): void;
515
+ [x: string]: any;
516
+ }
517
+
518
+ export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL;
519
+
520
+ export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION;
521
+
522
+ export declare const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX;
523
+
524
+ export declare const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN;
525
+
526
+ export declare class NodeEnv extends Env {
527
+ filename: string;
528
+ private readonly nodeBinding?;
529
+ destructing: boolean;
530
+ finalizationScheduled: boolean;
531
+ constructor(ctx: Context, filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any);
532
+ deleteMe(): void;
533
+ canCallIntoJs(): boolean;
534
+ triggerFatalException(err: any): void;
535
+ callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T;
536
+ callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
537
+ callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void;
538
+ enqueueFinalizer(finalizer: RefTracker): void;
539
+ drainFinalizerQueue(): void;
540
+ }
541
+
542
+ export declare class NotSupportBufferError extends EmnapiError {
543
+ constructor(api: string, message: string);
544
+ }
545
+
546
+ export declare class NotSupportWeakRefError extends EmnapiError {
547
+ constructor(api: string, message: string);
548
+ }
549
+
550
+ export declare class Persistent<T> {
551
+ private _ref;
552
+ private _param;
553
+ private _callback;
554
+ private static readonly _registry;
555
+ constructor(value: T);
556
+ setWeak<P>(param: P, callback: (param: P) => void): void;
557
+ clearWeak(): void;
558
+ reset(): void;
559
+ isEmpty(): boolean;
560
+ deref(): T | undefined;
561
+ }
562
+
563
+ export declare class Reference extends RefTracker implements IStoreValue {
564
+ private static weakCallback;
565
+ id: number;
566
+ envObject: Env;
567
+ private readonly canBeWeak;
568
+ private _refcount;
569
+ private readonly _ownership;
570
+ persistent: Persistent<object>;
571
+ static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference;
572
+ protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
573
+ ref(): number;
574
+ unref(): number;
575
+ get(envObject?: Env): napi_value;
576
+ /** @virtual */
577
+ resetFinalizer(): void;
578
+ /** @virtual */
579
+ data(): void_p;
580
+ refcount(): number;
581
+ ownership(): ReferenceOwnership;
582
+ /** @virtual */
583
+ protected callUserFinalizer(): void;
584
+ /** @virtual */
585
+ protected invokeFinalizerFromGC(): void;
586
+ private _setWeak;
587
+ finalize(): void;
588
+ dispose(): void;
589
+ }
590
+
591
+ export declare enum ReferenceOwnership {
592
+ kRuntime = 0,
593
+ kUserland = 1
594
+ }
595
+
596
+ export declare class ReferenceWithData extends Reference {
597
+ private readonly _data;
598
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
599
+ private constructor();
600
+ data(): void_p;
601
+ }
602
+
603
+ export declare class ReferenceWithFinalizer extends Reference {
604
+ private _finalizer;
605
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer;
606
+ private constructor();
607
+ resetFinalizer(): void;
608
+ data(): void_p;
609
+ protected callUserFinalizer(): void;
610
+ protected invokeFinalizerFromGC(): void;
611
+ dispose(): void;
612
+ }
613
+
614
+ export declare class RefTracker {
615
+ /** @virtual */
616
+ dispose(): void;
617
+ /** @virtual */
618
+ finalize(): void;
619
+ private _next;
620
+ private _prev;
621
+ link(list: RefTracker): void;
622
+ unlink(): void;
623
+ static finalizeAll(list: RefTracker): void;
624
+ }
625
+
626
+ export declare class ScopeStore {
627
+ private readonly _rootScope;
628
+ currentScope: HandleScope;
629
+ private readonly _values;
630
+ constructor();
631
+ get(id: number): HandleScope | undefined;
632
+ openScope(handleStore: HandleStore): HandleScope;
633
+ closeScope(): void;
634
+ dispose(): void;
635
+ }
636
+
637
+ export declare class Store<V extends IStoreValue> {
638
+ protected _values: Array<V | undefined>;
639
+ private _freeList;
640
+ private _size;
641
+ constructor();
642
+ add(value: V): void;
643
+ get(id: Ptr): V | undefined;
644
+ has(id: Ptr): boolean;
645
+ remove(id: Ptr): void;
646
+ dispose(): void;
647
+ }
648
+
649
+ export declare class TrackedFinalizer extends RefTracker {
650
+ private _finalizer;
651
+ static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
652
+ private constructor();
653
+ data(): void_p;
654
+ dispose(): void;
655
+ finalize(): void;
656
+ }
657
+
658
+ export declare class TryCatch {
659
+ private _exception;
660
+ private _caught;
661
+ isEmpty(): boolean;
662
+ hasCaught(): boolean;
663
+ exception(): any;
664
+ setError(err: any): void;
665
+ reset(): void;
666
+ extractException(): any;
667
+ }
668
+
669
+ export declare const version: string;
670
+
671
+ export { }
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.d.ts ADDED
@@ -0,0 +1,673 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export declare type Ptr = number | bigint
2
+
3
+ export declare interface IBuffer extends Uint8Array {}
4
+ export declare interface BufferCtor {
5
+ readonly prototype: IBuffer
6
+ /** @deprecated */
7
+ new (...args: any[]): IBuffer
8
+ from: {
9
+ (buffer: ArrayBufferLike): IBuffer
10
+ (buffer: ArrayBufferLike, byteOffset: number, length: number): IBuffer
11
+ }
12
+ alloc: (size: number) => IBuffer
13
+ isBuffer: (obj: unknown) => obj is IBuffer
14
+ }
15
+
16
+ export declare const enum GlobalHandle {
17
+ UNDEFINED = 1,
18
+ NULL,
19
+ FALSE,
20
+ TRUE,
21
+ GLOBAL
22
+ }
23
+
24
+ export declare const enum Version {
25
+ NODE_API_SUPPORTED_VERSION_MIN = 1,
26
+ NODE_API_DEFAULT_MODULE_API_VERSION = 8,
27
+ NODE_API_SUPPORTED_VERSION_MAX = 10,
28
+ NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ export declare type Pointer<T> = number
32
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
+ export declare type PointerPointer<T> = number
34
+ export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T>
35
+ export declare type Const<T> = T
36
+
37
+ export declare type void_p = Pointer<void>
38
+ export declare type void_pp = Pointer<void_p>
39
+ export declare type bool = number
40
+ export declare type char = number
41
+ export declare type char_p = Pointer<char>
42
+ export declare type unsigned_char = number
43
+ export declare type const_char = Const<char>
44
+ export declare type const_char_p = Pointer<const_char>
45
+ export declare type char16_t_p = number
46
+ export declare type const_char16_t_p = number
47
+
48
+ export declare type short = number
49
+ export declare type unsigned_short = number
50
+ export declare type int = number
51
+ export declare type unsigned_int = number
52
+ export declare type long = number
53
+ export declare type unsigned_long = number
54
+ export declare type long_long = bigint
55
+ export declare type unsigned_long_long = bigint
56
+ export declare type float = number
57
+ export declare type double = number
58
+ export declare type long_double = number
59
+ export declare type size_t = number
60
+
61
+ export declare type int8_t = number
62
+ export declare type uint8_t = number
63
+ export declare type int16_t = number
64
+ export declare type uint16_t = number
65
+ export declare type int32_t = number
66
+ export declare type uint32_t = number
67
+ export declare type int64_t = bigint
68
+ export declare type uint64_t = bigint
69
+ export declare type napi_env = Pointer<unknown>
70
+
71
+ export declare type napi_value = Pointer<unknown>
72
+ export declare type napi_ref = Pointer<unknown>
73
+ export declare type napi_deferred = Pointer<unknown>
74
+ export declare type napi_handle_scope = Pointer<unknown>
75
+ export declare type napi_escapable_handle_scope = Pointer<unknown>
76
+
77
+ export declare type napi_addon_register_func = FunctionPointer<(env: napi_env, exports: napi_value) => napi_value>
78
+
79
+ export declare type napi_callback_info = Pointer<unknown>
80
+ export declare type napi_callback = FunctionPointer<(env: napi_env, info: napi_callback_info) => napi_value>
81
+
82
+ export declare interface napi_extended_error_info {
83
+ error_message: const_char_p
84
+ engine_reserved: void_p
85
+ engine_error_code: uint32_t
86
+ error_code: napi_status
87
+ }
88
+
89
+ export declare interface napi_property_descriptor {
90
+ // One of utf8name or name should be NULL.
91
+ utf8name: const_char_p
92
+ name: napi_value
93
+
94
+ method: napi_callback
95
+ getter: napi_callback
96
+ setter: napi_callback
97
+ value: napi_value
98
+ /* napi_property_attributes */
99
+ attributes: number
100
+ data: void_p
101
+ }
102
+
103
+ export declare type napi_finalize = FunctionPointer<(
104
+ env: napi_env,
105
+ finalize_data: void_p,
106
+ finalize_hint: void_p
107
+ ) => void>
108
+
109
+ export declare interface node_module {
110
+ nm_version: int32_t
111
+ nm_flags: uint32_t
112
+ nm_filename: Pointer<const_char>
113
+ nm_register_func: napi_addon_register_func
114
+ nm_modname: Pointer<const_char>
115
+ nm_priv: Pointer<void>
116
+ reserved: PointerPointer<void>
117
+ }
118
+
119
+ export declare interface napi_node_version {
120
+ major: uint32_t
121
+ minor: uint32_t
122
+ patch: uint32_t
123
+ release: const_char_p
124
+ }
125
+
126
+ export declare interface emnapi_emscripten_version {
127
+ major: uint32_t
128
+ minor: uint32_t
129
+ patch: uint32_t
130
+ }
131
+
132
+ export declare const enum napi_status {
133
+ napi_ok,
134
+ napi_invalid_arg,
135
+ napi_object_expected,
136
+ napi_string_expected,
137
+ napi_name_expected,
138
+ napi_function_expected,
139
+ napi_number_expected,
140
+ napi_boolean_expected,
141
+ napi_array_expected,
142
+ napi_generic_failure,
143
+ napi_pending_exception,
144
+ napi_cancelled,
145
+ napi_escape_called_twice,
146
+ napi_handle_scope_mismatch,
147
+ napi_callback_scope_mismatch,
148
+ napi_queue_full,
149
+ napi_closing,
150
+ napi_bigint_expected,
151
+ napi_date_expected,
152
+ napi_arraybuffer_expected,
153
+ napi_detachable_arraybuffer_expected,
154
+ napi_would_deadlock, // unused
155
+ napi_no_external_buffers_allowed,
156
+ napi_cannot_run_js
157
+ }
158
+
159
+ export declare const enum napi_property_attributes {
160
+ napi_default = 0,
161
+ napi_writable = 1 << 0,
162
+ napi_enumerable = 1 << 1,
163
+ napi_configurable = 1 << 2,
164
+
165
+ // Used with napi_define_class to distinguish static properties
166
+ // from instance properties. Ignored by napi_define_properties.
167
+ napi_static = 1 << 10,
168
+
169
+ /// #ifdef NAPI_EXPERIMENTAL
170
+ // Default for class methods.
171
+ napi_default_method = napi_writable | napi_configurable,
172
+
173
+ // Default for object properties, like in JS obj[prop].
174
+ napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable
175
+ /// #endif // NAPI_EXPERIMENTAL
176
+ }
177
+
178
+ export declare const enum napi_valuetype {
179
+ napi_undefined,
180
+ napi_null,
181
+ napi_boolean,
182
+ napi_number,
183
+ napi_string,
184
+ napi_symbol,
185
+ napi_object,
186
+ napi_function,
187
+ napi_external,
188
+ napi_bigint
189
+ }
190
+
191
+ export declare const enum napi_typedarray_type {
192
+ napi_int8_array,
193
+ napi_uint8_array,
194
+ napi_uint8_clamped_array,
195
+ napi_int16_array,
196
+ napi_uint16_array,
197
+ napi_int32_array,
198
+ napi_uint32_array,
199
+ napi_float32_array,
200
+ napi_float64_array,
201
+ napi_bigint64_array,
202
+ napi_biguint64_array,
203
+ napi_float16_array,
204
+ }
205
+
206
+ export declare const enum napi_key_collection_mode {
207
+ napi_key_include_prototypes,
208
+ napi_key_own_only
209
+ }
210
+
211
+ export declare const enum napi_key_filter {
212
+ napi_key_all_properties = 0,
213
+ napi_key_writable = 1,
214
+ napi_key_enumerable = 1 << 1,
215
+ napi_key_configurable = 1 << 2,
216
+ napi_key_skip_strings = 1 << 3,
217
+ napi_key_skip_symbols = 1 << 4
218
+ }
219
+
220
+ export declare const enum napi_key_conversion {
221
+ napi_key_keep_numbers,
222
+ napi_key_numbers_to_strings
223
+ }
224
+
225
+ export declare const enum emnapi_memory_view_type {
226
+ emnapi_int8_array,
227
+ emnapi_uint8_array,
228
+ emnapi_uint8_clamped_array,
229
+ emnapi_int16_array,
230
+ emnapi_uint16_array,
231
+ emnapi_int32_array,
232
+ emnapi_uint32_array,
233
+ emnapi_float32_array,
234
+ emnapi_float64_array,
235
+ emnapi_bigint64_array,
236
+ emnapi_biguint64_array,
237
+ emnapi_float16_array,
238
+ emnapi_data_view = -1,
239
+ emnapi_buffer = -2
240
+ }
241
+
242
+ export declare const enum napi_threadsafe_function_call_mode {
243
+ napi_tsfn_nonblocking,
244
+ napi_tsfn_blocking
245
+ }
246
+
247
+ export declare const enum napi_threadsafe_function_release_mode {
248
+ napi_tsfn_release,
249
+ napi_tsfn_abort
250
+ }
251
+ export declare type CleanupHookCallbackFunction = number | ((arg: number) => void);
252
+
253
+ export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> {
254
+ constructor(id: number, value: S);
255
+ dispose(): void;
256
+ }
257
+
258
+ export declare class Context {
259
+ private _isStopping;
260
+ private _canCallIntoJs;
261
+ private _suppressDestroy;
262
+ envStore: Store<Env>;
263
+ scopeStore: ScopeStore;
264
+ refStore: Store<Reference>;
265
+ deferredStore: Store<Deferred<any>>;
266
+ handleStore: HandleStore;
267
+ private readonly refCounter?;
268
+ private readonly cleanupQueue;
269
+ private readonly _externalMemory;
270
+ feature: {
271
+ supportReflect: boolean;
272
+ supportFinalizer: boolean;
273
+ supportWeakSymbol: boolean;
274
+ supportBigInt: boolean;
275
+ supportNewFunction: boolean;
276
+ canSetFunctionName: boolean;
277
+ setImmediate: (callback: () => void) => void;
278
+ Buffer: BufferCtor | undefined;
279
+ MessageChannel: {
280
+ new (): MessageChannel;
281
+ prototype: MessageChannel;
282
+ } | undefined;
283
+ };
284
+ constructor(options?: ContextOptions);
285
+ /**
286
+ * Suppress the destroy on `beforeExit` event in Node.js.
287
+ * Call this method if you want to keep the context and
288
+ * all associated {@link Env | Env} alive,
289
+ * this also means that cleanup hooks will not be called.
290
+ * After call this method, you should call
291
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
292
+ */
293
+ suppressDestroy(): void;
294
+ getRuntimeVersions(): {
295
+ version: string;
296
+ NODE_API_SUPPORTED_VERSION_MAX: Version;
297
+ NAPI_VERSION_EXPERIMENTAL: Version;
298
+ NODE_API_DEFAULT_MODULE_API_VERSION: Version;
299
+ };
300
+ createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
301
+ createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
302
+ createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference;
303
+ createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
304
+ createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
305
+ createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
306
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
307
+ createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
308
+ createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
309
+ getCurrentScope(): HandleScope | null;
310
+ addToCurrentScope<V>(value: V): Handle<V>;
311
+ openScope(envObject?: Env): HandleScope;
312
+ closeScope(envObject?: Env, _scope?: HandleScope): void;
313
+ ensureHandle<S>(value: S): Handle<S>;
314
+ addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
315
+ removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
316
+ runCleanup(): void;
317
+ increaseWaitingRequestCounter(): void;
318
+ decreaseWaitingRequestCounter(): void;
319
+ setCanCallIntoJs(value: boolean): void;
320
+ setStopping(value: boolean): void;
321
+ canCallIntoJs(): boolean;
322
+ /**
323
+ * Destroy the context and call cleanup hooks.
324
+ * Associated {@link Env | Env} will be destroyed.
325
+ */
326
+ destroy(): void;
327
+ }
328
+
329
+ export declare interface ContextOptions {
330
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
331
+ }
332
+
333
+ export declare function createContext(options?: ContextOptions): Context;
334
+
335
+ export declare class Deferred<T = any> implements IStoreValue {
336
+ static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
337
+ id: number;
338
+ ctx: Context;
339
+ value: IDeferrdValue<T>;
340
+ constructor(ctx: Context, value: IDeferrdValue<T>);
341
+ resolve(value: T): void;
342
+ reject(reason?: any): void;
343
+ dispose(): void;
344
+ }
345
+
346
+ export declare class EmnapiError extends Error {
347
+ constructor(message?: string);
348
+ }
349
+
350
+ export declare abstract class Env implements IStoreValue {
351
+ readonly ctx: Context;
352
+ moduleApiVersion: number;
353
+ makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
354
+ makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
355
+ abort: (msg?: string) => never;
356
+ id: number;
357
+ openHandleScopes: number;
358
+ instanceData: TrackedFinalizer | null;
359
+ tryCatch: TryCatch;
360
+ refs: number;
361
+ reflist: RefTracker;
362
+ finalizing_reflist: RefTracker;
363
+ pendingFinalizers: RefTracker[];
364
+ lastError: {
365
+ errorCode: napi_status;
366
+ engineErrorCode: number;
367
+ engineReserved: Ptr;
368
+ };
369
+ inGcFinalizer: boolean;
370
+ constructor(ctx: Context, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never);
371
+ /** @virtual */
372
+ canCallIntoJs(): boolean;
373
+ terminatedOrTerminating(): boolean;
374
+ ref(): void;
375
+ unref(): void;
376
+ ensureHandle<S>(value: S): Handle<S>;
377
+ ensureHandleId(value: any): napi_value;
378
+ clearLastError(): napi_status;
379
+ setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
380
+ getReturnStatus(): napi_status;
381
+ callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
382
+ /** @virtual */
383
+ abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
384
+ invokeFinalizerFromGC(finalizer: RefTracker): void;
385
+ checkGCAccess(): void;
386
+ /** @virtual */
387
+ enqueueFinalizer(finalizer: RefTracker): void;
388
+ /** @virtual */
389
+ dequeueFinalizer(finalizer: RefTracker): void;
390
+ /** @virtual */
391
+ deleteMe(): void;
392
+ dispose(): void;
393
+ private readonly _bindingMap;
394
+ initObjectBinding<S extends object>(value: S): IReferenceBinding;
395
+ getObjectBinding<S extends object>(value: S): IReferenceBinding;
396
+ setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void;
397
+ getInstanceData(): number;
398
+ }
399
+
400
+ /** @public */
401
+ declare interface External_2 extends Record<any, any> {
402
+ }
403
+
404
+ /** @public */
405
+ declare const External_2: {
406
+ new (value: number | bigint): External_2;
407
+ prototype: null;
408
+ };
409
+ export { External_2 as External }
410
+
411
+ export declare class Finalizer {
412
+ envObject: Env;
413
+ private _finalizeCallback;
414
+ private _finalizeData;
415
+ private _finalizeHint;
416
+ private _makeDynCall_vppp;
417
+ constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
418
+ callback(): napi_finalize;
419
+ data(): void_p;
420
+ hint(): void_p;
421
+ resetEnv(): void;
422
+ resetFinalizer(): void;
423
+ callFinalizer(): void;
424
+ dispose(): void;
425
+ }
426
+
427
+ export declare function getDefaultContext(): Context;
428
+
429
+ /** @public */
430
+ export declare function getExternalValue(external: External_2): number | bigint;
431
+
432
+ export declare class Handle<S> {
433
+ id: number;
434
+ value: S;
435
+ constructor(id: number, value: S);
436
+ data(): void_p;
437
+ isNumber(): boolean;
438
+ isBigInt(): boolean;
439
+ isString(): boolean;
440
+ isFunction(): boolean;
441
+ isExternal(): boolean;
442
+ isObject(): boolean;
443
+ isArray(): boolean;
444
+ isArrayBuffer(): boolean;
445
+ isTypedArray(): boolean;
446
+ isBuffer(BufferConstructor?: BufferCtor): boolean;
447
+ isDataView(): boolean;
448
+ isDate(): boolean;
449
+ isPromise(): boolean;
450
+ isBoolean(): boolean;
451
+ isUndefined(): boolean;
452
+ isSymbol(): boolean;
453
+ isNull(): boolean;
454
+ dispose(): void;
455
+ }
456
+
457
+ export declare class HandleScope {
458
+ handleStore: HandleStore;
459
+ id: number;
460
+ parent: HandleScope | null;
461
+ child: HandleScope | null;
462
+ start: number;
463
+ end: number;
464
+ private _escapeCalled;
465
+ callbackInfo: ICallbackInfo;
466
+ constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number);
467
+ add<V>(value: V): Handle<V>;
468
+ addExternal(data: void_p): Handle<object>;
469
+ dispose(): void;
470
+ escape(handle: number): Handle<any> | null;
471
+ escapeCalled(): boolean;
472
+ }
473
+
474
+ export declare class HandleStore {
475
+ static UNDEFINED: ConstHandle<undefined>;
476
+ static NULL: ConstHandle<null>;
477
+ static FALSE: ConstHandle<false>;
478
+ static TRUE: ConstHandle<true>;
479
+ static GLOBAL: ConstHandle<typeof globalThis>;
480
+ static MIN_ID: 6;
481
+ private readonly _values;
482
+ private _next;
483
+ push<S>(value: S): Handle<S>;
484
+ erase(start: number, end: number): void;
485
+ get(id: Ptr): Handle<any> | undefined;
486
+ swap(a: number, b: number): void;
487
+ dispose(): void;
488
+ }
489
+
490
+ export declare interface ICallbackInfo {
491
+ thiz: any;
492
+ data: void_p;
493
+ args: ArrayLike<any>;
494
+ fn: Function;
495
+ }
496
+
497
+ export declare interface IDeferrdValue<T = any> {
498
+ resolve: (value: T) => void;
499
+ reject: (reason?: any) => void;
500
+ }
501
+
502
+ export declare interface IReferenceBinding {
503
+ wrapped: number;
504
+ tag: Uint32Array | null;
505
+ }
506
+
507
+ /** @public */
508
+ export declare function isExternal(object: unknown): object is External_2;
509
+
510
+ export declare function isReferenceType(v: any): v is object;
511
+
512
+ export declare interface IStoreValue {
513
+ id: number;
514
+ dispose(): void;
515
+ [x: string]: any;
516
+ }
517
+
518
+ export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL;
519
+
520
+ export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION;
521
+
522
+ export declare const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX;
523
+
524
+ export declare const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN;
525
+
526
+ export declare class NodeEnv extends Env {
527
+ filename: string;
528
+ private readonly nodeBinding?;
529
+ destructing: boolean;
530
+ finalizationScheduled: boolean;
531
+ constructor(ctx: Context, filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any);
532
+ deleteMe(): void;
533
+ canCallIntoJs(): boolean;
534
+ triggerFatalException(err: any): void;
535
+ callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T;
536
+ callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
537
+ callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void;
538
+ enqueueFinalizer(finalizer: RefTracker): void;
539
+ drainFinalizerQueue(): void;
540
+ }
541
+
542
+ export declare class NotSupportBufferError extends EmnapiError {
543
+ constructor(api: string, message: string);
544
+ }
545
+
546
+ export declare class NotSupportWeakRefError extends EmnapiError {
547
+ constructor(api: string, message: string);
548
+ }
549
+
550
+ export declare class Persistent<T> {
551
+ private _ref;
552
+ private _param;
553
+ private _callback;
554
+ private static readonly _registry;
555
+ constructor(value: T);
556
+ setWeak<P>(param: P, callback: (param: P) => void): void;
557
+ clearWeak(): void;
558
+ reset(): void;
559
+ isEmpty(): boolean;
560
+ deref(): T | undefined;
561
+ }
562
+
563
+ export declare class Reference extends RefTracker implements IStoreValue {
564
+ private static weakCallback;
565
+ id: number;
566
+ envObject: Env;
567
+ private readonly canBeWeak;
568
+ private _refcount;
569
+ private readonly _ownership;
570
+ persistent: Persistent<object>;
571
+ static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference;
572
+ protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
573
+ ref(): number;
574
+ unref(): number;
575
+ get(envObject?: Env): napi_value;
576
+ /** @virtual */
577
+ resetFinalizer(): void;
578
+ /** @virtual */
579
+ data(): void_p;
580
+ refcount(): number;
581
+ ownership(): ReferenceOwnership;
582
+ /** @virtual */
583
+ protected callUserFinalizer(): void;
584
+ /** @virtual */
585
+ protected invokeFinalizerFromGC(): void;
586
+ private _setWeak;
587
+ finalize(): void;
588
+ dispose(): void;
589
+ }
590
+
591
+ export declare enum ReferenceOwnership {
592
+ kRuntime = 0,
593
+ kUserland = 1
594
+ }
595
+
596
+ export declare class ReferenceWithData extends Reference {
597
+ private readonly _data;
598
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
599
+ private constructor();
600
+ data(): void_p;
601
+ }
602
+
603
+ export declare class ReferenceWithFinalizer extends Reference {
604
+ private _finalizer;
605
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer;
606
+ private constructor();
607
+ resetFinalizer(): void;
608
+ data(): void_p;
609
+ protected callUserFinalizer(): void;
610
+ protected invokeFinalizerFromGC(): void;
611
+ dispose(): void;
612
+ }
613
+
614
+ export declare class RefTracker {
615
+ /** @virtual */
616
+ dispose(): void;
617
+ /** @virtual */
618
+ finalize(): void;
619
+ private _next;
620
+ private _prev;
621
+ link(list: RefTracker): void;
622
+ unlink(): void;
623
+ static finalizeAll(list: RefTracker): void;
624
+ }
625
+
626
+ export declare class ScopeStore {
627
+ private readonly _rootScope;
628
+ currentScope: HandleScope;
629
+ private readonly _values;
630
+ constructor();
631
+ get(id: number): HandleScope | undefined;
632
+ openScope(handleStore: HandleStore): HandleScope;
633
+ closeScope(): void;
634
+ dispose(): void;
635
+ }
636
+
637
+ export declare class Store<V extends IStoreValue> {
638
+ protected _values: Array<V | undefined>;
639
+ private _freeList;
640
+ private _size;
641
+ constructor();
642
+ add(value: V): void;
643
+ get(id: Ptr): V | undefined;
644
+ has(id: Ptr): boolean;
645
+ remove(id: Ptr): void;
646
+ dispose(): void;
647
+ }
648
+
649
+ export declare class TrackedFinalizer extends RefTracker {
650
+ private _finalizer;
651
+ static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
652
+ private constructor();
653
+ data(): void_p;
654
+ dispose(): void;
655
+ finalize(): void;
656
+ }
657
+
658
+ export declare class TryCatch {
659
+ private _exception;
660
+ private _caught;
661
+ isEmpty(): boolean;
662
+ hasCaught(): boolean;
663
+ exception(): any;
664
+ setError(err: any): void;
665
+ reset(): void;
666
+ extractException(): any;
667
+ }
668
+
669
+ export declare const version: string;
670
+
671
+ export { }
672
+
673
+ export as namespace emnapi;
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js ADDED
@@ -0,0 +1,1457 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.bind(_global)
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.11.3";
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 (handleStore) {
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(handleStore, id, currentScope, currentScope.end);
375
+ this._values[id] = scope;
376
+ }
377
+ this.currentScope = scope;
378
+ return scope;
379
+ };
380
+ ScopeStore.prototype.closeScope = function () {
381
+ var scope = this.currentScope;
382
+ this.currentScope = scope.parent;
383
+ scope.dispose();
384
+ };
385
+ ScopeStore.prototype.dispose = function () {
386
+ this.currentScope = this._rootScope;
387
+ this._values.length = 1;
388
+ };
389
+ return ScopeStore;
390
+ }());
391
+
392
+ var RefTracker = /*#__PURE__*/ (function () {
393
+ function RefTracker() {
394
+ this._next = null;
395
+ this._prev = null;
396
+ }
397
+ /** @virtual */
398
+ RefTracker.prototype.dispose = function () { };
399
+ /** @virtual */
400
+ RefTracker.prototype.finalize = function () { };
401
+ RefTracker.prototype.link = function (list) {
402
+ this._prev = list;
403
+ this._next = list._next;
404
+ if (this._next !== null) {
405
+ this._next._prev = this;
406
+ }
407
+ list._next = this;
408
+ };
409
+ RefTracker.prototype.unlink = function () {
410
+ if (this._prev !== null) {
411
+ this._prev._next = this._next;
412
+ }
413
+ if (this._next !== null) {
414
+ this._next._prev = this._prev;
415
+ }
416
+ this._prev = null;
417
+ this._next = null;
418
+ };
419
+ RefTracker.finalizeAll = function (list) {
420
+ while (list._next !== null) {
421
+ list._next.finalize();
422
+ }
423
+ };
424
+ return RefTracker;
425
+ }());
426
+
427
+ var Finalizer = /*#__PURE__*/ (function () {
428
+ function Finalizer(envObject, _finalizeCallback, _finalizeData, _finalizeHint) {
429
+ if (_finalizeCallback === void 0) { _finalizeCallback = 0; }
430
+ if (_finalizeData === void 0) { _finalizeData = 0; }
431
+ if (_finalizeHint === void 0) { _finalizeHint = 0; }
432
+ this.envObject = envObject;
433
+ this._finalizeCallback = _finalizeCallback;
434
+ this._finalizeData = _finalizeData;
435
+ this._finalizeHint = _finalizeHint;
436
+ this._makeDynCall_vppp = envObject.makeDynCall_vppp;
437
+ }
438
+ Finalizer.prototype.callback = function () { return this._finalizeCallback; };
439
+ Finalizer.prototype.data = function () { return this._finalizeData; };
440
+ Finalizer.prototype.hint = function () { return this._finalizeHint; };
441
+ Finalizer.prototype.resetEnv = function () {
442
+ this.envObject = undefined;
443
+ };
444
+ Finalizer.prototype.resetFinalizer = function () {
445
+ this._finalizeCallback = 0;
446
+ this._finalizeData = 0;
447
+ this._finalizeHint = 0;
448
+ };
449
+ Finalizer.prototype.callFinalizer = function () {
450
+ var finalize_callback = this._finalizeCallback;
451
+ var finalize_data = this._finalizeData;
452
+ var finalize_hint = this._finalizeHint;
453
+ this.resetFinalizer();
454
+ if (!finalize_callback)
455
+ return;
456
+ var fini = Number(finalize_callback);
457
+ if (!this.envObject) {
458
+ this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
459
+ }
460
+ else {
461
+ this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
462
+ }
463
+ };
464
+ Finalizer.prototype.dispose = function () {
465
+ this.envObject = undefined;
466
+ this._makeDynCall_vppp = undefined;
467
+ };
468
+ return Finalizer;
469
+ }());
470
+
471
+ var TrackedFinalizer = /*#__PURE__*/ (function (_super) {
472
+ __extends(TrackedFinalizer, _super);
473
+ function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
474
+ var _this = _super.call(this) || this;
475
+ _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
476
+ return _this;
477
+ }
478
+ TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) {
479
+ var finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
480
+ finalizer.link(envObject.finalizing_reflist);
481
+ return finalizer;
482
+ };
483
+ TrackedFinalizer.prototype.data = function () {
484
+ return this._finalizer.data();
485
+ };
486
+ TrackedFinalizer.prototype.dispose = function () {
487
+ if (!this._finalizer)
488
+ return;
489
+ this.unlink();
490
+ this._finalizer.envObject.dequeueFinalizer(this);
491
+ this._finalizer.dispose();
492
+ this._finalizer = undefined;
493
+ _super.prototype.dispose.call(this);
494
+ };
495
+ TrackedFinalizer.prototype.finalize = function () {
496
+ this.unlink();
497
+ var error;
498
+ var caught = false;
499
+ try {
500
+ this._finalizer.callFinalizer();
501
+ }
502
+ catch (err) {
503
+ caught = true;
504
+ error = err;
505
+ }
506
+ this.dispose();
507
+ if (caught) {
508
+ throw error;
509
+ }
510
+ };
511
+ return TrackedFinalizer;
512
+ }(RefTracker));
513
+
514
+ function throwNodeApiVersionError(moduleName, moduleApiVersion) {
515
+ 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.");
516
+ throw new Error(errorMessage);
517
+ }
518
+ function handleThrow(envObject, value) {
519
+ if (envObject.terminatedOrTerminating()) {
520
+ return;
521
+ }
522
+ throw value;
523
+ }
524
+ var Env = /*#__PURE__*/ (function () {
525
+ function Env(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) {
526
+ this.ctx = ctx;
527
+ this.moduleApiVersion = moduleApiVersion;
528
+ this.makeDynCall_vppp = makeDynCall_vppp;
529
+ this.makeDynCall_vp = makeDynCall_vp;
530
+ this.abort = abort;
531
+ this.openHandleScopes = 0;
532
+ this.instanceData = null;
533
+ this.tryCatch = new TryCatch();
534
+ this.refs = 1;
535
+ this.reflist = new RefTracker();
536
+ this.finalizing_reflist = new RefTracker();
537
+ this.pendingFinalizers = [];
538
+ this.lastError = {
539
+ errorCode: 0 /* napi_status.napi_ok */,
540
+ engineErrorCode: 0,
541
+ engineReserved: 0
542
+ };
543
+ this.inGcFinalizer = false;
544
+ this._bindingMap = new WeakMap();
545
+ this.id = 0;
546
+ }
547
+ /** @virtual */
548
+ Env.prototype.canCallIntoJs = function () {
549
+ return true;
550
+ };
551
+ Env.prototype.terminatedOrTerminating = function () {
552
+ return !this.canCallIntoJs();
553
+ };
554
+ Env.prototype.ref = function () {
555
+ this.refs++;
556
+ };
557
+ Env.prototype.unref = function () {
558
+ this.refs--;
559
+ if (this.refs === 0) {
560
+ this.dispose();
561
+ }
562
+ };
563
+ Env.prototype.ensureHandle = function (value) {
564
+ return this.ctx.ensureHandle(value);
565
+ };
566
+ Env.prototype.ensureHandleId = function (value) {
567
+ return this.ensureHandle(value).id;
568
+ };
569
+ Env.prototype.clearLastError = function () {
570
+ var lastError = this.lastError;
571
+ if (lastError.errorCode !== 0 /* napi_status.napi_ok */)
572
+ lastError.errorCode = 0 /* napi_status.napi_ok */;
573
+ if (lastError.engineErrorCode !== 0)
574
+ lastError.engineErrorCode = 0;
575
+ if (lastError.engineReserved !== 0)
576
+ lastError.engineReserved = 0;
577
+ return 0 /* napi_status.napi_ok */;
578
+ };
579
+ Env.prototype.setLastError = function (error_code, engine_error_code, engine_reserved) {
580
+ if (engine_error_code === void 0) { engine_error_code = 0; }
581
+ if (engine_reserved === void 0) { engine_reserved = 0; }
582
+ var lastError = this.lastError;
583
+ if (lastError.errorCode !== error_code)
584
+ lastError.errorCode = error_code;
585
+ if (lastError.engineErrorCode !== engine_error_code)
586
+ lastError.engineErrorCode = engine_error_code;
587
+ if (lastError.engineReserved !== engine_reserved)
588
+ lastError.engineReserved = engine_reserved;
589
+ return error_code;
590
+ };
591
+ Env.prototype.getReturnStatus = function () {
592
+ return !this.tryCatch.hasCaught() ? 0 /* napi_status.napi_ok */ : this.setLastError(10 /* napi_status.napi_pending_exception */);
593
+ };
594
+ Env.prototype.callIntoModule = function (fn, handleException) {
595
+ if (handleException === void 0) { handleException = handleThrow; }
596
+ var openHandleScopesBefore = this.openHandleScopes;
597
+ this.clearLastError();
598
+ var r = fn(this);
599
+ if (openHandleScopesBefore !== this.openHandleScopes) {
600
+ this.abort('open_handle_scopes != open_handle_scopes_before');
601
+ }
602
+ if (this.tryCatch.hasCaught()) {
603
+ var err = this.tryCatch.extractException();
604
+ handleException(this, err);
605
+ }
606
+ return r;
607
+ };
608
+ Env.prototype.invokeFinalizerFromGC = function (finalizer) {
609
+ if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
610
+ this.enqueueFinalizer(finalizer);
611
+ }
612
+ else {
613
+ var saved = this.inGcFinalizer;
614
+ this.inGcFinalizer = true;
615
+ try {
616
+ finalizer.finalize();
617
+ }
618
+ finally {
619
+ this.inGcFinalizer = saved;
620
+ }
621
+ }
622
+ };
623
+ Env.prototype.checkGCAccess = function () {
624
+ if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) {
625
+ this.abort('Finalizer is calling a function that may affect GC state.\n' +
626
+ 'The finalizers are run directly from GC and must not affect GC ' +
627
+ 'state.\n' +
628
+ 'Use `node_api_post_finalizer` from inside of the finalizer to work ' +
629
+ 'around this issue.\n' +
630
+ 'It schedules the call as a new task in the event loop.');
631
+ }
632
+ };
633
+ /** @virtual */
634
+ Env.prototype.enqueueFinalizer = function (finalizer) {
635
+ if (this.pendingFinalizers.indexOf(finalizer) === -1) {
636
+ this.pendingFinalizers.push(finalizer);
637
+ }
638
+ };
639
+ /** @virtual */
640
+ Env.prototype.dequeueFinalizer = function (finalizer) {
641
+ var index = this.pendingFinalizers.indexOf(finalizer);
642
+ if (index !== -1) {
643
+ this.pendingFinalizers.splice(index, 1);
644
+ }
645
+ };
646
+ /** @virtual */
647
+ Env.prototype.deleteMe = function () {
648
+ RefTracker.finalizeAll(this.finalizing_reflist);
649
+ RefTracker.finalizeAll(this.reflist);
650
+ this.tryCatch.extractException();
651
+ this.ctx.envStore.remove(this.id);
652
+ };
653
+ Env.prototype.dispose = function () {
654
+ if (this.id === 0)
655
+ return;
656
+ this.deleteMe();
657
+ this.finalizing_reflist.dispose();
658
+ this.reflist.dispose();
659
+ this.id = 0;
660
+ };
661
+ Env.prototype.initObjectBinding = function (value) {
662
+ var binding = {
663
+ wrapped: 0,
664
+ tag: null
665
+ };
666
+ this._bindingMap.set(value, binding);
667
+ return binding;
668
+ };
669
+ Env.prototype.getObjectBinding = function (value) {
670
+ if (this._bindingMap.has(value)) {
671
+ return this._bindingMap.get(value);
672
+ }
673
+ return this.initObjectBinding(value);
674
+ };
675
+ Env.prototype.setInstanceData = function (data, finalize_cb, finalize_hint) {
676
+ if (this.instanceData) {
677
+ this.instanceData.dispose();
678
+ }
679
+ this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
680
+ };
681
+ Env.prototype.getInstanceData = function () {
682
+ return this.instanceData ? this.instanceData.data() : 0;
683
+ };
684
+ return Env;
685
+ }());
686
+ var NodeEnv = /*#__PURE__*/ (function (_super) {
687
+ __extends(NodeEnv, _super);
688
+ function NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
689
+ var _this = _super.call(this, ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) || this;
690
+ _this.filename = filename;
691
+ _this.nodeBinding = nodeBinding;
692
+ _this.destructing = false;
693
+ _this.finalizationScheduled = false;
694
+ return _this;
695
+ }
696
+ NodeEnv.prototype.deleteMe = function () {
697
+ this.destructing = true;
698
+ this.drainFinalizerQueue();
699
+ _super.prototype.deleteMe.call(this);
700
+ };
701
+ NodeEnv.prototype.canCallIntoJs = function () {
702
+ return _super.prototype.canCallIntoJs.call(this) && this.ctx.canCallIntoJs();
703
+ };
704
+ NodeEnv.prototype.triggerFatalException = function (err) {
705
+ if (this.nodeBinding) {
706
+ this.nodeBinding.napi.fatalException(err);
707
+ }
708
+ else {
709
+ if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') {
710
+ var handled = process._fatalException(err);
711
+ if (!handled) {
712
+ console.error(err);
713
+ process.exit(1);
714
+ }
715
+ }
716
+ else {
717
+ throw err;
718
+ }
719
+ }
720
+ };
721
+ NodeEnv.prototype.callbackIntoModule = function (enforceUncaughtExceptionPolicy, fn) {
722
+ return this.callIntoModule(fn, function (envObject, err) {
723
+ if (envObject.terminatedOrTerminating()) {
724
+ return;
725
+ }
726
+ var hasProcess = typeof process === 'object' && process !== null;
727
+ var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
728
+ if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
729
+ var warn = hasProcess && typeof process.emitWarning === 'function'
730
+ ? process.emitWarning
731
+ : function (warning, type, code) {
732
+ if (warning instanceof Error) {
733
+ console.warn(warning.toString());
734
+ }
735
+ else {
736
+ var prefix = code ? "[".concat(code, "] ") : '';
737
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
738
+ console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
739
+ }
740
+ };
741
+ warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
742
+ return;
743
+ }
744
+ envObject.triggerFatalException(err);
745
+ });
746
+ };
747
+ NodeEnv.prototype.callFinalizer = function (cb, data, hint) {
748
+ this.callFinalizerInternal(1, cb, data, hint);
749
+ };
750
+ NodeEnv.prototype.callFinalizerInternal = function (forceUncaught, cb, data, hint) {
751
+ var f = this.makeDynCall_vppp(cb);
752
+ var env = this.id;
753
+ var scope = this.ctx.openScope(this);
754
+ try {
755
+ this.callbackIntoModule(Boolean(forceUncaught), function () { f(env, data, hint); });
756
+ }
757
+ finally {
758
+ this.ctx.closeScope(this, scope);
759
+ }
760
+ };
761
+ NodeEnv.prototype.enqueueFinalizer = function (finalizer) {
762
+ var _this = this;
763
+ _super.prototype.enqueueFinalizer.call(this, finalizer);
764
+ if (!this.finalizationScheduled && !this.destructing) {
765
+ this.finalizationScheduled = true;
766
+ this.ref();
767
+ _setImmediate(function () {
768
+ _this.finalizationScheduled = false;
769
+ _this.unref();
770
+ _this.drainFinalizerQueue();
771
+ });
772
+ }
773
+ };
774
+ NodeEnv.prototype.drainFinalizerQueue = function () {
775
+ while (this.pendingFinalizers.length > 0) {
776
+ var refTracker = this.pendingFinalizers.shift();
777
+ refTracker.finalize();
778
+ }
779
+ };
780
+ return NodeEnv;
781
+ }(Env));
782
+ function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
783
+ moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion;
784
+ // Validate module_api_version.
785
+ if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
786
+ moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
787
+ }
788
+ else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
789
+ throwNodeApiVersionError(filename, moduleApiVersion);
790
+ }
791
+ var env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
792
+ ctx.envStore.add(env);
793
+ ctx.addCleanupHook(env, function () { env.unref(); }, 0);
794
+ return env;
795
+ }
796
+
797
+ var EmnapiError = /*#__PURE__*/ (function (_super) {
798
+ __extends(EmnapiError, _super);
799
+ function EmnapiError(message) {
800
+ var _newTarget = this.constructor;
801
+ var _this = _super.call(this, message) || this;
802
+ var ErrorConstructor = _newTarget;
803
+ var proto = ErrorConstructor.prototype;
804
+ if (!(_this instanceof EmnapiError)) {
805
+ var setPrototypeOf = Object.setPrototypeOf;
806
+ if (typeof setPrototypeOf === 'function') {
807
+ setPrototypeOf.call(Object, _this, proto);
808
+ }
809
+ else {
810
+ // eslint-disable-next-line no-proto
811
+ _this.__proto__ = proto;
812
+ }
813
+ if (typeof Error.captureStackTrace === 'function') {
814
+ Error.captureStackTrace(_this, ErrorConstructor);
815
+ }
816
+ }
817
+ return _this;
818
+ }
819
+ return EmnapiError;
820
+ }(Error));
821
+ Object.defineProperty(EmnapiError.prototype, 'name', {
822
+ configurable: true,
823
+ writable: true,
824
+ value: 'EmnapiError'
825
+ });
826
+ var NotSupportWeakRefError = /*#__PURE__*/ (function (_super) {
827
+ __extends(NotSupportWeakRefError, _super);
828
+ function NotSupportWeakRefError(api, message) {
829
+ return _super.call(this, "".concat(api, ": The current runtime does not support \"FinalizationRegistry\" and \"WeakRef\".").concat(message ? " ".concat(message) : '')) || this;
830
+ }
831
+ return NotSupportWeakRefError;
832
+ }(EmnapiError));
833
+ Object.defineProperty(NotSupportWeakRefError.prototype, 'name', {
834
+ configurable: true,
835
+ writable: true,
836
+ value: 'NotSupportWeakRefError'
837
+ });
838
+ var NotSupportBufferError = /*#__PURE__*/ (function (_super) {
839
+ __extends(NotSupportBufferError, _super);
840
+ function NotSupportBufferError(api, message) {
841
+ 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;
842
+ }
843
+ return NotSupportBufferError;
844
+ }(EmnapiError));
845
+ Object.defineProperty(NotSupportBufferError.prototype, 'name', {
846
+ configurable: true,
847
+ writable: true,
848
+ value: 'NotSupportBufferError'
849
+ });
850
+
851
+ var StrongRef = /*#__PURE__*/ (function () {
852
+ function StrongRef(value) {
853
+ this._value = value;
854
+ }
855
+ StrongRef.prototype.deref = function () {
856
+ return this._value;
857
+ };
858
+ StrongRef.prototype.dispose = function () {
859
+ this._value = undefined;
860
+ };
861
+ return StrongRef;
862
+ }());
863
+ var Persistent = /*#__PURE__*/ (function () {
864
+ function Persistent(value) {
865
+ this._ref = new StrongRef(value);
866
+ }
867
+ Persistent.prototype.setWeak = function (param, callback) {
868
+ if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef)
869
+ return;
870
+ var value = this._ref.deref();
871
+ try {
872
+ Persistent._registry.register(value, this, this);
873
+ var weakRef = new WeakRef(value);
874
+ this._ref.dispose();
875
+ this._ref = weakRef;
876
+ this._param = param;
877
+ this._callback = callback;
878
+ }
879
+ catch (err) {
880
+ if (typeof value === 'symbol') ;
881
+ else {
882
+ throw err;
883
+ }
884
+ }
885
+ };
886
+ Persistent.prototype.clearWeak = function () {
887
+ if (!supportFinalizer || this._ref === undefined)
888
+ return;
889
+ if (this._ref instanceof WeakRef) {
890
+ try {
891
+ Persistent._registry.unregister(this);
892
+ }
893
+ catch (_) { }
894
+ this._param = undefined;
895
+ this._callback = undefined;
896
+ var value = this._ref.deref();
897
+ if (value === undefined) {
898
+ this._ref = value;
899
+ }
900
+ else {
901
+ this._ref = new StrongRef(value);
902
+ }
903
+ }
904
+ };
905
+ Persistent.prototype.reset = function () {
906
+ if (supportFinalizer) {
907
+ try {
908
+ Persistent._registry.unregister(this);
909
+ }
910
+ catch (_) { }
911
+ }
912
+ this._param = undefined;
913
+ this._callback = undefined;
914
+ if (this._ref instanceof StrongRef) {
915
+ this._ref.dispose();
916
+ }
917
+ this._ref = undefined;
918
+ };
919
+ Persistent.prototype.isEmpty = function () {
920
+ return this._ref === undefined;
921
+ };
922
+ Persistent.prototype.deref = function () {
923
+ if (this._ref === undefined)
924
+ return undefined;
925
+ return this._ref.deref();
926
+ };
927
+ Persistent._registry = supportFinalizer
928
+ ? new FinalizationRegistry(function (value) {
929
+ value._ref = undefined;
930
+ var callback = value._callback;
931
+ var param = value._param;
932
+ value._callback = undefined;
933
+ value._param = undefined;
934
+ if (typeof callback === 'function') {
935
+ callback(param);
936
+ }
937
+ })
938
+ : undefined;
939
+ return Persistent;
940
+ }());
941
+
942
+ var ReferenceOwnership;
943
+ (function (ReferenceOwnership) {
944
+ ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
945
+ ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
946
+ })(ReferenceOwnership || (ReferenceOwnership = {}));
947
+ function canBeHeldWeakly(value) {
948
+ return value.isObject() || value.isFunction() || value.isSymbol();
949
+ }
950
+ var Reference = /*#__PURE__*/ (function (_super) {
951
+ __extends(Reference, _super);
952
+ function Reference(envObject, handle_id, initialRefcount, ownership) {
953
+ var _this = _super.call(this) || this;
954
+ _this.envObject = envObject;
955
+ _this._refcount = initialRefcount;
956
+ _this._ownership = ownership;
957
+ var handle = envObject.ctx.handleStore.get(handle_id);
958
+ _this.canBeWeak = canBeHeldWeakly(handle);
959
+ _this.persistent = new Persistent(handle.value);
960
+ _this.id = 0;
961
+ if (initialRefcount === 0) {
962
+ _this._setWeak();
963
+ }
964
+ return _this;
965
+ }
966
+ Reference.weakCallback = function (ref) {
967
+ ref.persistent.reset();
968
+ ref.invokeFinalizerFromGC();
969
+ };
970
+ Reference.create = function (envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
971
+ var ref = new Reference(envObject, handle_id, initialRefcount, ownership);
972
+ envObject.ctx.refStore.add(ref);
973
+ ref.link(envObject.reflist);
974
+ return ref;
975
+ };
976
+ Reference.prototype.ref = function () {
977
+ if (this.persistent.isEmpty()) {
978
+ return 0;
979
+ }
980
+ if (++this._refcount === 1 && this.canBeWeak) {
981
+ this.persistent.clearWeak();
982
+ }
983
+ return this._refcount;
984
+ };
985
+ Reference.prototype.unref = function () {
986
+ if (this.persistent.isEmpty() || this._refcount === 0) {
987
+ return 0;
988
+ }
989
+ if (--this._refcount === 0) {
990
+ this._setWeak();
991
+ }
992
+ return this._refcount;
993
+ };
994
+ Reference.prototype.get = function (envObject) {
995
+ if (envObject === void 0) { envObject = this.envObject; }
996
+ if (this.persistent.isEmpty()) {
997
+ return 0;
998
+ }
999
+ var obj = this.persistent.deref();
1000
+ var handle = envObject.ensureHandle(obj);
1001
+ return handle.id;
1002
+ };
1003
+ /** @virtual */
1004
+ Reference.prototype.resetFinalizer = function () { };
1005
+ /** @virtual */
1006
+ Reference.prototype.data = function () { return 0; };
1007
+ Reference.prototype.refcount = function () { return this._refcount; };
1008
+ Reference.prototype.ownership = function () { return this._ownership; };
1009
+ /** @virtual */
1010
+ Reference.prototype.callUserFinalizer = function () { };
1011
+ /** @virtual */
1012
+ Reference.prototype.invokeFinalizerFromGC = function () {
1013
+ this.finalize();
1014
+ };
1015
+ Reference.prototype._setWeak = function () {
1016
+ if (this.canBeWeak) {
1017
+ this.persistent.setWeak(this, Reference.weakCallback);
1018
+ }
1019
+ else {
1020
+ this.persistent.reset();
1021
+ }
1022
+ };
1023
+ Reference.prototype.finalize = function () {
1024
+ this.persistent.reset();
1025
+ var deleteMe = this._ownership === ReferenceOwnership.kRuntime;
1026
+ this.unlink();
1027
+ this.callUserFinalizer();
1028
+ if (deleteMe) {
1029
+ this.dispose();
1030
+ }
1031
+ };
1032
+ Reference.prototype.dispose = function () {
1033
+ if (this.id === 0)
1034
+ return;
1035
+ this.unlink();
1036
+ this.persistent.reset();
1037
+ this.envObject.ctx.refStore.remove(this.id);
1038
+ _super.prototype.dispose.call(this);
1039
+ this.envObject = undefined;
1040
+ this.id = 0;
1041
+ };
1042
+ return Reference;
1043
+ }(RefTracker));
1044
+ var ReferenceWithData = /*#__PURE__*/ (function (_super) {
1045
+ __extends(ReferenceWithData, _super);
1046
+ function ReferenceWithData(envObject, value, initialRefcount, ownership, _data) {
1047
+ var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
1048
+ _this._data = _data;
1049
+ return _this;
1050
+ }
1051
+ ReferenceWithData.create = function (envObject, value, initialRefcount, ownership, data) {
1052
+ var reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
1053
+ envObject.ctx.refStore.add(reference);
1054
+ reference.link(envObject.reflist);
1055
+ return reference;
1056
+ };
1057
+ ReferenceWithData.prototype.data = function () {
1058
+ return this._data;
1059
+ };
1060
+ return ReferenceWithData;
1061
+ }(Reference));
1062
+ var ReferenceWithFinalizer = /*#__PURE__*/ (function (_super) {
1063
+ __extends(ReferenceWithFinalizer, _super);
1064
+ function ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1065
+ var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
1066
+ _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
1067
+ return _this;
1068
+ }
1069
+ ReferenceWithFinalizer.create = function (envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1070
+ var reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1071
+ envObject.ctx.refStore.add(reference);
1072
+ reference.link(envObject.finalizing_reflist);
1073
+ return reference;
1074
+ };
1075
+ ReferenceWithFinalizer.prototype.resetFinalizer = function () {
1076
+ this._finalizer.resetFinalizer();
1077
+ };
1078
+ ReferenceWithFinalizer.prototype.data = function () {
1079
+ return this._finalizer.data();
1080
+ };
1081
+ ReferenceWithFinalizer.prototype.callUserFinalizer = function () {
1082
+ this._finalizer.callFinalizer();
1083
+ };
1084
+ ReferenceWithFinalizer.prototype.invokeFinalizerFromGC = function () {
1085
+ this._finalizer.envObject.invokeFinalizerFromGC(this);
1086
+ };
1087
+ ReferenceWithFinalizer.prototype.dispose = function () {
1088
+ if (!this._finalizer)
1089
+ return;
1090
+ this._finalizer.envObject.dequeueFinalizer(this);
1091
+ this._finalizer.dispose();
1092
+ _super.prototype.dispose.call(this);
1093
+ this._finalizer = undefined;
1094
+ };
1095
+ return ReferenceWithFinalizer;
1096
+ }(Reference));
1097
+
1098
+ var Deferred = /*#__PURE__*/ (function () {
1099
+ function Deferred(ctx, value) {
1100
+ // Plain assignment would invoke inherited setters before these fields
1101
+ // become own properties.
1102
+ Object.defineProperties(this, {
1103
+ id: {
1104
+ configurable: true,
1105
+ enumerable: true,
1106
+ value: 0,
1107
+ writable: true
1108
+ },
1109
+ ctx: {
1110
+ configurable: true,
1111
+ enumerable: true,
1112
+ value: ctx,
1113
+ writable: true
1114
+ },
1115
+ value: {
1116
+ configurable: true,
1117
+ enumerable: true,
1118
+ value: value,
1119
+ writable: true
1120
+ }
1121
+ });
1122
+ }
1123
+ Deferred.create = function (ctx, value) {
1124
+ var deferred = new Deferred(ctx, value);
1125
+ ctx.deferredStore.add(deferred);
1126
+ return deferred;
1127
+ };
1128
+ Deferred.prototype.resolve = function (value) {
1129
+ this.value.resolve(value);
1130
+ this.dispose();
1131
+ };
1132
+ Deferred.prototype.reject = function (reason) {
1133
+ this.value.reject(reason);
1134
+ this.dispose();
1135
+ };
1136
+ Deferred.prototype.dispose = function () {
1137
+ this.ctx.deferredStore.remove(this.id);
1138
+ this.id = 0;
1139
+ this.value = null;
1140
+ this.ctx = null;
1141
+ };
1142
+ return Deferred;
1143
+ }());
1144
+
1145
+ var Store = /*#__PURE__*/ (function () {
1146
+ function Store() {
1147
+ this._values = [undefined];
1148
+ this._values.length = 4;
1149
+ this._size = 1;
1150
+ this._freeList = [];
1151
+ }
1152
+ Store.prototype.add = function (value) {
1153
+ var id;
1154
+ if (this._freeList.length) {
1155
+ id = this._freeList.shift();
1156
+ }
1157
+ else {
1158
+ id = this._size;
1159
+ this._size++;
1160
+ var capacity = this._values.length;
1161
+ if (id >= capacity) {
1162
+ this._values.length = capacity + (capacity >> 1) + 16;
1163
+ }
1164
+ }
1165
+ value.id = id;
1166
+ this._values[id] = value;
1167
+ };
1168
+ Store.prototype.get = function (id) {
1169
+ return this._values[id];
1170
+ };
1171
+ Store.prototype.has = function (id) {
1172
+ return this._values[id] !== undefined;
1173
+ };
1174
+ Store.prototype.remove = function (id) {
1175
+ var value = this._values[id];
1176
+ if (value) {
1177
+ value.id = 0;
1178
+ this._values[id] = undefined;
1179
+ this._freeList.push(Number(id));
1180
+ }
1181
+ };
1182
+ Store.prototype.dispose = function () {
1183
+ for (var i = 1; i < this._size; ++i) {
1184
+ var value = this._values[i];
1185
+ value === null || value === void 0 ? void 0 : value.dispose();
1186
+ }
1187
+ this._values = [undefined];
1188
+ this._size = 1;
1189
+ this._freeList = [];
1190
+ };
1191
+ return Store;
1192
+ }());
1193
+
1194
+ var kMaxReasonableBytes = BigInt(1) << BigInt(60);
1195
+ var kMinReasonableBytes = -kMaxReasonableBytes;
1196
+ var ExternalMemory = /*#__PURE__*/ (function () {
1197
+ function ExternalMemory(onChange) {
1198
+ this.total = BigInt(0);
1199
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
1200
+ }
1201
+ ExternalMemory.prototype.adjust = function (changeInBytes) {
1202
+ changeInBytes = BigInt(changeInBytes);
1203
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
1204
+ throw new RangeError("changeInBytes ".concat(changeInBytes, " is out of reasonable range"));
1205
+ }
1206
+ var old = this.total;
1207
+ this.total += changeInBytes;
1208
+ var amount = this.total;
1209
+ var onChange = this.onChange;
1210
+ if (changeInBytes) {
1211
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
1212
+ }
1213
+ return amount;
1214
+ };
1215
+ return ExternalMemory;
1216
+ }());
1217
+
1218
+ var CleanupHookCallback = /*#__PURE__*/ (function () {
1219
+ function CleanupHookCallback(envObject, fn, arg, order) {
1220
+ this.envObject = envObject;
1221
+ this.fn = fn;
1222
+ this.arg = arg;
1223
+ this.order = order;
1224
+ }
1225
+ return CleanupHookCallback;
1226
+ }());
1227
+ var CleanupQueue = /*#__PURE__*/ (function () {
1228
+ function CleanupQueue() {
1229
+ this._cleanupHooks = [];
1230
+ this._cleanupHookCounter = 0;
1231
+ }
1232
+ CleanupQueue.prototype.empty = function () {
1233
+ return this._cleanupHooks.length === 0;
1234
+ };
1235
+ CleanupQueue.prototype.add = function (envObject, fn, arg) {
1236
+ if (this._cleanupHooks.filter(function (hook) { return (hook.envObject === envObject && hook.fn === fn && hook.arg === arg); }).length > 0) {
1237
+ throw new Error('Can not add same fn and arg twice');
1238
+ }
1239
+ this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++));
1240
+ };
1241
+ CleanupQueue.prototype.remove = function (envObject, fn, arg) {
1242
+ for (var i = 0; i < this._cleanupHooks.length; ++i) {
1243
+ var hook = this._cleanupHooks[i];
1244
+ if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) {
1245
+ this._cleanupHooks.splice(i, 1);
1246
+ return;
1247
+ }
1248
+ }
1249
+ };
1250
+ CleanupQueue.prototype.drain = function () {
1251
+ var hooks = this._cleanupHooks.slice();
1252
+ hooks.sort(function (a, b) { return (b.order - a.order); });
1253
+ for (var i = 0; i < hooks.length; ++i) {
1254
+ var cb = hooks[i];
1255
+ if (typeof cb.fn === 'number') {
1256
+ cb.envObject.makeDynCall_vp(cb.fn)(cb.arg);
1257
+ }
1258
+ else {
1259
+ cb.fn(cb.arg);
1260
+ }
1261
+ this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1);
1262
+ }
1263
+ };
1264
+ CleanupQueue.prototype.dispose = function () {
1265
+ this._cleanupHooks.length = 0;
1266
+ this._cleanupHookCounter = 0;
1267
+ };
1268
+ return CleanupQueue;
1269
+ }());
1270
+ var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () {
1271
+ function NodejsWaitingRequestCounter() {
1272
+ this.refHandle = new _MessageChannel().port1;
1273
+ this.count = 0;
1274
+ }
1275
+ NodejsWaitingRequestCounter.prototype.increase = function () {
1276
+ if (this.count === 0) {
1277
+ if (this.refHandle.ref) {
1278
+ this.refHandle.ref();
1279
+ }
1280
+ }
1281
+ this.count++;
1282
+ };
1283
+ NodejsWaitingRequestCounter.prototype.decrease = function () {
1284
+ if (this.count === 0)
1285
+ return;
1286
+ if (this.count === 1) {
1287
+ if (this.refHandle.unref) {
1288
+ this.refHandle.unref();
1289
+ }
1290
+ }
1291
+ this.count--;
1292
+ };
1293
+ return NodejsWaitingRequestCounter;
1294
+ }());
1295
+ var Context = /*#__PURE__*/ (function () {
1296
+ function Context(options) {
1297
+ var _this = this;
1298
+ this._isStopping = false;
1299
+ this._canCallIntoJs = true;
1300
+ this._suppressDestroy = false;
1301
+ this.envStore = new Store();
1302
+ this.scopeStore = new ScopeStore();
1303
+ this.refStore = new Store();
1304
+ this.deferredStore = new Store();
1305
+ this.handleStore = new HandleStore();
1306
+ this.feature = {
1307
+ supportReflect: supportReflect,
1308
+ supportFinalizer: supportFinalizer,
1309
+ supportWeakSymbol: supportWeakSymbol,
1310
+ supportBigInt: supportBigInt,
1311
+ supportNewFunction: supportNewFunction,
1312
+ canSetFunctionName: canSetFunctionName,
1313
+ setImmediate: _setImmediate,
1314
+ Buffer: _Buffer,
1315
+ MessageChannel: _MessageChannel
1316
+ };
1317
+ this.cleanupQueue = new CleanupQueue();
1318
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
1319
+ if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1320
+ this.refCounter = new NodejsWaitingRequestCounter();
1321
+ process.once('beforeExit', function () {
1322
+ if (!_this._suppressDestroy) {
1323
+ _this.destroy();
1324
+ }
1325
+ });
1326
+ }
1327
+ }
1328
+ /**
1329
+ * Suppress the destroy on `beforeExit` event in Node.js.
1330
+ * Call this method if you want to keep the context and
1331
+ * all associated {@link Env | Env} alive,
1332
+ * this also means that cleanup hooks will not be called.
1333
+ * After call this method, you should call
1334
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
1335
+ */
1336
+ Context.prototype.suppressDestroy = function () {
1337
+ this._suppressDestroy = true;
1338
+ };
1339
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
1340
+ Context.prototype.getRuntimeVersions = function () {
1341
+ return {
1342
+ version: version,
1343
+ NODE_API_SUPPORTED_VERSION_MAX: NODE_API_SUPPORTED_VERSION_MAX,
1344
+ NAPI_VERSION_EXPERIMENTAL: NAPI_VERSION_EXPERIMENTAL,
1345
+ NODE_API_DEFAULT_MODULE_API_VERSION: NODE_API_DEFAULT_MODULE_API_VERSION
1346
+ };
1347
+ };
1348
+ Context.prototype.createNotSupportWeakRefError = function (api, message) {
1349
+ return new NotSupportWeakRefError(api, message);
1350
+ };
1351
+ Context.prototype.createNotSupportBufferError = function (api, message) {
1352
+ return new NotSupportBufferError(api, message);
1353
+ };
1354
+ Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership) {
1355
+ return Reference.create(envObject, handle_id, initialRefcount, ownership);
1356
+ };
1357
+ Context.prototype.createReferenceWithData = function (envObject, handle_id, initialRefcount, ownership, data) {
1358
+ return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
1359
+ };
1360
+ Context.prototype.createReferenceWithFinalizer = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1361
+ if (finalize_callback === void 0) { finalize_callback = 0; }
1362
+ if (finalize_data === void 0) { finalize_data = 0; }
1363
+ if (finalize_hint === void 0) { finalize_hint = 0; }
1364
+ return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1365
+ };
1366
+ Context.prototype.createDeferred = function (value) {
1367
+ return Deferred.create(this, value);
1368
+ };
1369
+ Context.prototype.adjustAmountOfExternalAllocatedMemory = function (changeInBytes) {
1370
+ return this._externalMemory.adjust(changeInBytes);
1371
+ };
1372
+ Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1373
+ return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1374
+ };
1375
+ Context.prototype.createTrackedFinalizer = function (envObject, finalize_callback, finalize_data, finalize_hint) {
1376
+ return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint);
1377
+ };
1378
+ Context.prototype.getCurrentScope = function () {
1379
+ return this.scopeStore.currentScope;
1380
+ };
1381
+ Context.prototype.addToCurrentScope = function (value) {
1382
+ return this.scopeStore.currentScope.add(value);
1383
+ };
1384
+ Context.prototype.openScope = function (envObject) {
1385
+ var scope = this.scopeStore.openScope(this.handleStore);
1386
+ if (envObject)
1387
+ envObject.openHandleScopes++;
1388
+ return scope;
1389
+ };
1390
+ Context.prototype.closeScope = function (envObject, _scope) {
1391
+ if (envObject && envObject.openHandleScopes === 0)
1392
+ return;
1393
+ this.scopeStore.closeScope();
1394
+ if (envObject)
1395
+ envObject.openHandleScopes--;
1396
+ };
1397
+ Context.prototype.ensureHandle = function (value) {
1398
+ switch (value) {
1399
+ case undefined: return HandleStore.UNDEFINED;
1400
+ case null: return HandleStore.NULL;
1401
+ case true: return HandleStore.TRUE;
1402
+ case false: return HandleStore.FALSE;
1403
+ case _global: return HandleStore.GLOBAL;
1404
+ }
1405
+ return this.addToCurrentScope(value);
1406
+ };
1407
+ Context.prototype.addCleanupHook = function (envObject, fn, arg) {
1408
+ this.cleanupQueue.add(envObject, fn, arg);
1409
+ };
1410
+ Context.prototype.removeCleanupHook = function (envObject, fn, arg) {
1411
+ this.cleanupQueue.remove(envObject, fn, arg);
1412
+ };
1413
+ Context.prototype.runCleanup = function () {
1414
+ while (!this.cleanupQueue.empty()) {
1415
+ this.cleanupQueue.drain();
1416
+ }
1417
+ };
1418
+ Context.prototype.increaseWaitingRequestCounter = function () {
1419
+ var _a;
1420
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase();
1421
+ };
1422
+ Context.prototype.decreaseWaitingRequestCounter = function () {
1423
+ var _a;
1424
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease();
1425
+ };
1426
+ Context.prototype.setCanCallIntoJs = function (value) {
1427
+ this._canCallIntoJs = value;
1428
+ };
1429
+ Context.prototype.setStopping = function (value) {
1430
+ this._isStopping = value;
1431
+ };
1432
+ Context.prototype.canCallIntoJs = function () {
1433
+ return this._canCallIntoJs && !this._isStopping;
1434
+ };
1435
+ /**
1436
+ * Destroy the context and call cleanup hooks.
1437
+ * Associated {@link Env | Env} will be destroyed.
1438
+ */
1439
+ Context.prototype.destroy = function () {
1440
+ this.setStopping(true);
1441
+ this.setCanCallIntoJs(false);
1442
+ this.runCleanup();
1443
+ };
1444
+ return Context;
1445
+ }());
1446
+ var defaultContext;
1447
+ function createContext(options) {
1448
+ return new Context(options);
1449
+ }
1450
+ function getDefaultContext() {
1451
+ if (!defaultContext) {
1452
+ defaultContext = createContext();
1453
+ }
1454
+ return defaultContext;
1455
+ }
1456
+
1457
+ 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 };
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts ADDED
@@ -0,0 +1,426 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ declare namespace emnapi {
2
+
3
+ export type CleanupHookCallbackFunction = number | ((arg: number) => void);
4
+
5
+ export class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> {
6
+ constructor(id: number, value: S);
7
+ dispose(): void;
8
+ }
9
+
10
+ export class Context {
11
+ private _isStopping;
12
+ private _canCallIntoJs;
13
+ private _suppressDestroy;
14
+ envStore: Store<Env>;
15
+ scopeStore: ScopeStore;
16
+ refStore: Store<Reference>;
17
+ deferredStore: Store<Deferred<any>>;
18
+ handleStore: HandleStore;
19
+ private readonly refCounter?;
20
+ private readonly cleanupQueue;
21
+ private readonly _externalMemory;
22
+ feature: {
23
+ supportReflect: boolean;
24
+ supportFinalizer: boolean;
25
+ supportWeakSymbol: boolean;
26
+ supportBigInt: boolean;
27
+ supportNewFunction: boolean;
28
+ canSetFunctionName: boolean;
29
+ setImmediate: (callback: () => void) => void;
30
+ Buffer: BufferCtor | undefined;
31
+ MessageChannel: {
32
+ new (): MessageChannel;
33
+ prototype: MessageChannel;
34
+ } | undefined;
35
+ };
36
+ constructor(options?: ContextOptions);
37
+ /**
38
+ * Suppress the destroy on `beforeExit` event in Node.js.
39
+ * Call this method if you want to keep the context and
40
+ * all associated {@link Env | Env} alive,
41
+ * this also means that cleanup hooks will not be called.
42
+ * After call this method, you should call
43
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
44
+ */
45
+ suppressDestroy(): void;
46
+ getRuntimeVersions(): {
47
+ version: string;
48
+ NODE_API_SUPPORTED_VERSION_MAX: Version;
49
+ NAPI_VERSION_EXPERIMENTAL: Version;
50
+ NODE_API_DEFAULT_MODULE_API_VERSION: Version;
51
+ };
52
+ createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
53
+ createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
54
+ createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference;
55
+ createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
56
+ createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
57
+ createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
58
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
59
+ createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
60
+ createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
61
+ getCurrentScope(): HandleScope | null;
62
+ addToCurrentScope<V>(value: V): Handle<V>;
63
+ openScope(envObject?: Env): HandleScope;
64
+ closeScope(envObject?: Env, _scope?: HandleScope): void;
65
+ ensureHandle<S>(value: S): Handle<S>;
66
+ addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
67
+ removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
68
+ runCleanup(): void;
69
+ increaseWaitingRequestCounter(): void;
70
+ decreaseWaitingRequestCounter(): void;
71
+ setCanCallIntoJs(value: boolean): void;
72
+ setStopping(value: boolean): void;
73
+ canCallIntoJs(): boolean;
74
+ /**
75
+ * Destroy the context and call cleanup hooks.
76
+ * Associated {@link Env | Env} will be destroyed.
77
+ */
78
+ destroy(): void;
79
+ }
80
+
81
+ export interface ContextOptions {
82
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
83
+ }
84
+
85
+ export function createContext(options?: ContextOptions): Context;
86
+
87
+ export class Deferred<T = any> implements IStoreValue {
88
+ static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
89
+ id: number;
90
+ ctx: Context;
91
+ value: IDeferrdValue<T>;
92
+ constructor(ctx: Context, value: IDeferrdValue<T>);
93
+ resolve(value: T): void;
94
+ reject(reason?: any): void;
95
+ dispose(): void;
96
+ }
97
+
98
+ export class EmnapiError extends Error {
99
+ constructor(message?: string);
100
+ }
101
+
102
+ export abstract class Env implements IStoreValue {
103
+ readonly ctx: Context;
104
+ moduleApiVersion: number;
105
+ makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
106
+ makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
107
+ abort: (msg?: string) => never;
108
+ id: number;
109
+ openHandleScopes: number;
110
+ instanceData: TrackedFinalizer | null;
111
+ tryCatch: TryCatch;
112
+ refs: number;
113
+ reflist: RefTracker;
114
+ finalizing_reflist: RefTracker;
115
+ pendingFinalizers: RefTracker[];
116
+ lastError: {
117
+ errorCode: napi_status;
118
+ engineErrorCode: number;
119
+ engineReserved: Ptr;
120
+ };
121
+ inGcFinalizer: boolean;
122
+ constructor(ctx: Context, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never);
123
+ /** @virtual */
124
+ canCallIntoJs(): boolean;
125
+ terminatedOrTerminating(): boolean;
126
+ ref(): void;
127
+ unref(): void;
128
+ ensureHandle<S>(value: S): Handle<S>;
129
+ ensureHandleId(value: any): napi_value;
130
+ clearLastError(): napi_status;
131
+ setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
132
+ getReturnStatus(): napi_status;
133
+ callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
134
+ /** @virtual */
135
+ abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
136
+ invokeFinalizerFromGC(finalizer: RefTracker): void;
137
+ checkGCAccess(): void;
138
+ /** @virtual */
139
+ enqueueFinalizer(finalizer: RefTracker): void;
140
+ /** @virtual */
141
+ dequeueFinalizer(finalizer: RefTracker): void;
142
+ /** @virtual */
143
+ deleteMe(): void;
144
+ dispose(): void;
145
+ private readonly _bindingMap;
146
+ initObjectBinding<S extends object>(value: S): IReferenceBinding;
147
+ getObjectBinding<S extends object>(value: S): IReferenceBinding;
148
+ setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void;
149
+ getInstanceData(): number;
150
+ }
151
+
152
+ /** @public */
153
+ interface External_2 extends Record<any, any> {
154
+ }
155
+
156
+ /** @public */
157
+ const External_2: {
158
+ new (value: number | bigint): External_2;
159
+ prototype: null;
160
+ };
161
+ export { External_2 as External }
162
+
163
+ export class Finalizer {
164
+ envObject: Env;
165
+ private _finalizeCallback;
166
+ private _finalizeData;
167
+ private _finalizeHint;
168
+ private _makeDynCall_vppp;
169
+ constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
170
+ callback(): napi_finalize;
171
+ data(): void_p;
172
+ hint(): void_p;
173
+ resetEnv(): void;
174
+ resetFinalizer(): void;
175
+ callFinalizer(): void;
176
+ dispose(): void;
177
+ }
178
+
179
+ export function getDefaultContext(): Context;
180
+
181
+ /** @public */
182
+ export function getExternalValue(external: External_2): number | bigint;
183
+
184
+ export class Handle<S> {
185
+ id: number;
186
+ value: S;
187
+ constructor(id: number, value: S);
188
+ data(): void_p;
189
+ isNumber(): boolean;
190
+ isBigInt(): boolean;
191
+ isString(): boolean;
192
+ isFunction(): boolean;
193
+ isExternal(): boolean;
194
+ isObject(): boolean;
195
+ isArray(): boolean;
196
+ isArrayBuffer(): boolean;
197
+ isTypedArray(): boolean;
198
+ isBuffer(BufferConstructor?: BufferCtor): boolean;
199
+ isDataView(): boolean;
200
+ isDate(): boolean;
201
+ isPromise(): boolean;
202
+ isBoolean(): boolean;
203
+ isUndefined(): boolean;
204
+ isSymbol(): boolean;
205
+ isNull(): boolean;
206
+ dispose(): void;
207
+ }
208
+
209
+ export class HandleScope {
210
+ handleStore: HandleStore;
211
+ id: number;
212
+ parent: HandleScope | null;
213
+ child: HandleScope | null;
214
+ start: number;
215
+ end: number;
216
+ private _escapeCalled;
217
+ callbackInfo: ICallbackInfo;
218
+ constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number);
219
+ add<V>(value: V): Handle<V>;
220
+ addExternal(data: void_p): Handle<object>;
221
+ dispose(): void;
222
+ escape(handle: number): Handle<any> | null;
223
+ escapeCalled(): boolean;
224
+ }
225
+
226
+ export class HandleStore {
227
+ static UNDEFINED: ConstHandle<undefined>;
228
+ static NULL: ConstHandle<null>;
229
+ static FALSE: ConstHandle<false>;
230
+ static TRUE: ConstHandle<true>;
231
+ static GLOBAL: ConstHandle<typeof globalThis>;
232
+ static MIN_ID: 6;
233
+ private readonly _values;
234
+ private _next;
235
+ push<S>(value: S): Handle<S>;
236
+ erase(start: number, end: number): void;
237
+ get(id: Ptr): Handle<any> | undefined;
238
+ swap(a: number, b: number): void;
239
+ dispose(): void;
240
+ }
241
+
242
+ export interface ICallbackInfo {
243
+ thiz: any;
244
+ data: void_p;
245
+ args: ArrayLike<any>;
246
+ fn: Function;
247
+ }
248
+
249
+ export interface IDeferrdValue<T = any> {
250
+ resolve: (value: T) => void;
251
+ reject: (reason?: any) => void;
252
+ }
253
+
254
+ export interface IReferenceBinding {
255
+ wrapped: number;
256
+ tag: Uint32Array | null;
257
+ }
258
+
259
+ /** @public */
260
+ export function isExternal(object: unknown): object is External_2;
261
+
262
+ export function isReferenceType(v: any): v is object;
263
+
264
+ export interface IStoreValue {
265
+ id: number;
266
+ dispose(): void;
267
+ [x: string]: any;
268
+ }
269
+
270
+ export const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL;
271
+
272
+ export const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION;
273
+
274
+ export const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX;
275
+
276
+ export const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN;
277
+
278
+ export class NodeEnv extends Env {
279
+ filename: string;
280
+ private readonly nodeBinding?;
281
+ destructing: boolean;
282
+ finalizationScheduled: boolean;
283
+ constructor(ctx: Context, filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any);
284
+ deleteMe(): void;
285
+ canCallIntoJs(): boolean;
286
+ triggerFatalException(err: any): void;
287
+ callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T;
288
+ callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
289
+ callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void;
290
+ enqueueFinalizer(finalizer: RefTracker): void;
291
+ drainFinalizerQueue(): void;
292
+ }
293
+
294
+ export class NotSupportBufferError extends EmnapiError {
295
+ constructor(api: string, message: string);
296
+ }
297
+
298
+ export class NotSupportWeakRefError extends EmnapiError {
299
+ constructor(api: string, message: string);
300
+ }
301
+
302
+ export class Persistent<T> {
303
+ private _ref;
304
+ private _param;
305
+ private _callback;
306
+ private static readonly _registry;
307
+ constructor(value: T);
308
+ setWeak<P>(param: P, callback: (param: P) => void): void;
309
+ clearWeak(): void;
310
+ reset(): void;
311
+ isEmpty(): boolean;
312
+ deref(): T | undefined;
313
+ }
314
+
315
+ export class Reference extends RefTracker implements IStoreValue {
316
+ private static weakCallback;
317
+ id: number;
318
+ envObject: Env;
319
+ private readonly canBeWeak;
320
+ private _refcount;
321
+ private readonly _ownership;
322
+ persistent: Persistent<object>;
323
+ static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference;
324
+ protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
325
+ ref(): number;
326
+ unref(): number;
327
+ get(envObject?: Env): napi_value;
328
+ /** @virtual */
329
+ resetFinalizer(): void;
330
+ /** @virtual */
331
+ data(): void_p;
332
+ refcount(): number;
333
+ ownership(): ReferenceOwnership;
334
+ /** @virtual */
335
+ protected callUserFinalizer(): void;
336
+ /** @virtual */
337
+ protected invokeFinalizerFromGC(): void;
338
+ private _setWeak;
339
+ finalize(): void;
340
+ dispose(): void;
341
+ }
342
+
343
+ export enum ReferenceOwnership {
344
+ kRuntime = 0,
345
+ kUserland = 1
346
+ }
347
+
348
+ export class ReferenceWithData extends Reference {
349
+ private readonly _data;
350
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
351
+ private constructor();
352
+ data(): void_p;
353
+ }
354
+
355
+ export class ReferenceWithFinalizer extends Reference {
356
+ private _finalizer;
357
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer;
358
+ private constructor();
359
+ resetFinalizer(): void;
360
+ data(): void_p;
361
+ protected callUserFinalizer(): void;
362
+ protected invokeFinalizerFromGC(): void;
363
+ dispose(): void;
364
+ }
365
+
366
+ export class RefTracker {
367
+ /** @virtual */
368
+ dispose(): void;
369
+ /** @virtual */
370
+ finalize(): void;
371
+ private _next;
372
+ private _prev;
373
+ link(list: RefTracker): void;
374
+ unlink(): void;
375
+ static finalizeAll(list: RefTracker): void;
376
+ }
377
+
378
+ export class ScopeStore {
379
+ private readonly _rootScope;
380
+ currentScope: HandleScope;
381
+ private readonly _values;
382
+ constructor();
383
+ get(id: number): HandleScope | undefined;
384
+ openScope(handleStore: HandleStore): HandleScope;
385
+ closeScope(): void;
386
+ dispose(): void;
387
+ }
388
+
389
+ export class Store<V extends IStoreValue> {
390
+ protected _values: Array<V | undefined>;
391
+ private _freeList;
392
+ private _size;
393
+ constructor();
394
+ add(value: V): void;
395
+ get(id: Ptr): V | undefined;
396
+ has(id: Ptr): boolean;
397
+ remove(id: Ptr): void;
398
+ dispose(): void;
399
+ }
400
+
401
+ export class TrackedFinalizer extends RefTracker {
402
+ private _finalizer;
403
+ static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
404
+ private constructor();
405
+ data(): void_p;
406
+ dispose(): void;
407
+ finalize(): void;
408
+ }
409
+
410
+ export class TryCatch {
411
+ private _exception;
412
+ private _caught;
413
+ isEmpty(): boolean;
414
+ hasCaught(): boolean;
415
+ exception(): any;
416
+ setError(err: any): void;
417
+ reset(): void;
418
+ extractException(): any;
419
+ }
420
+
421
+ export const version: string;
422
+
423
+
424
+
425
+
426
+ }
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.iife.js ADDED
@@ -0,0 +1,1528 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var emnapi = (function (exports) {
2
+
3
+ /******************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
18
+
19
+ var extendStatics = function(d, b) {
20
+ extendStatics = Object.setPrototypeOf ||
21
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
23
+ return extendStatics(d, b);
24
+ };
25
+
26
+ function __extends(d, b) {
27
+ if (typeof b !== "function" && b !== null)
28
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29
+ extendStatics(d, b);
30
+ function __() { this.constructor = d; }
31
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
+ }
33
+
34
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
+ var e = new Error(message);
36
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
+ };
38
+
39
+ var externalValue = new WeakMap();
40
+ /** @public */
41
+ function isExternal(object) {
42
+ return externalValue.has(object);
43
+ }
44
+ /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare
45
+ var External = (function () {
46
+ function External(value) {
47
+ Object.setPrototypeOf(this, null);
48
+ externalValue.set(this, value);
49
+ }
50
+ External.prototype = null;
51
+ return External;
52
+ })();
53
+ /** @public */
54
+ function getExternalValue(external) {
55
+ if (!isExternal(external)) {
56
+ throw new TypeError('not external');
57
+ }
58
+ return externalValue.get(external);
59
+ }
60
+
61
+ var supportNewFunction = /*#__PURE__*/ (function () {
62
+ var f;
63
+ try {
64
+ f = new Function();
65
+ }
66
+ catch (_) {
67
+ return false;
68
+ }
69
+ return typeof f === 'function';
70
+ })();
71
+ var _global = /*#__PURE__*/ (function () {
72
+ if (typeof globalThis !== 'undefined')
73
+ return globalThis;
74
+ var g = (function () { return this; })();
75
+ if (!g && supportNewFunction) {
76
+ try {
77
+ g = new Function('return this')();
78
+ }
79
+ catch (_) { }
80
+ }
81
+ if (!g) {
82
+ if (typeof __webpack_public_path__ === 'undefined') {
83
+ if (typeof global !== 'undefined')
84
+ return global;
85
+ }
86
+ if (typeof window !== 'undefined')
87
+ return window;
88
+ if (typeof self !== 'undefined')
89
+ return self;
90
+ }
91
+ return g;
92
+ })();
93
+ var TryCatch = /*#__PURE__*/ (function () {
94
+ function TryCatch() {
95
+ this._exception = undefined;
96
+ this._caught = false;
97
+ }
98
+ TryCatch.prototype.isEmpty = function () {
99
+ return !this._caught;
100
+ };
101
+ TryCatch.prototype.hasCaught = function () {
102
+ return this._caught;
103
+ };
104
+ TryCatch.prototype.exception = function () {
105
+ return this._exception;
106
+ };
107
+ TryCatch.prototype.setError = function (err) {
108
+ this._caught = true;
109
+ this._exception = err;
110
+ };
111
+ TryCatch.prototype.reset = function () {
112
+ this._caught = false;
113
+ this._exception = undefined;
114
+ };
115
+ TryCatch.prototype.extractException = function () {
116
+ var e = this._exception;
117
+ this.reset();
118
+ return e;
119
+ };
120
+ return TryCatch;
121
+ }());
122
+ var canSetFunctionName = /*#__PURE__*/ (function () {
123
+ var _a;
124
+ try {
125
+ return Boolean((_a = Object.getOwnPropertyDescriptor(Function.prototype, 'name')) === null || _a === void 0 ? void 0 : _a.configurable);
126
+ }
127
+ catch (_) {
128
+ return false;
129
+ }
130
+ })();
131
+ var supportReflect = typeof Reflect === 'object';
132
+ var supportFinalizer = (typeof FinalizationRegistry !== 'undefined') && (typeof WeakRef !== 'undefined');
133
+ var supportWeakSymbol = /*#__PURE__*/ (function () {
134
+ try {
135
+ // eslint-disable-next-line symbol-description
136
+ var sym = Symbol();
137
+ // eslint-disable-next-line no-new
138
+ new WeakRef(sym);
139
+ new WeakMap().set(sym, undefined);
140
+ }
141
+ catch (_) {
142
+ return false;
143
+ }
144
+ return true;
145
+ })();
146
+ var supportBigInt = typeof BigInt !== 'undefined';
147
+ function isReferenceType(v) {
148
+ return (typeof v === 'object' && v !== null) || typeof v === 'function';
149
+ }
150
+ var _require = /*#__PURE__*/ (function () {
151
+ var nativeRequire;
152
+ if (typeof __webpack_public_path__ !== 'undefined') {
153
+ nativeRequire = (function () {
154
+ return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined;
155
+ })();
156
+ }
157
+ else {
158
+ nativeRequire = (function () {
159
+ return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined);
160
+ })();
161
+ }
162
+ return nativeRequire;
163
+ })();
164
+ var _MessageChannel = typeof MessageChannel === 'function'
165
+ ? MessageChannel
166
+ : /*#__PURE__*/ (function () {
167
+ try {
168
+ return _require('worker_threads').MessageChannel;
169
+ }
170
+ catch (_) { }
171
+ return undefined;
172
+ })();
173
+ var _setImmediate = typeof setImmediate === 'function'
174
+ ? setImmediate.bind(_global)
175
+ : function (callback) {
176
+ if (typeof callback !== 'function') {
177
+ throw new TypeError('The "callback" argument must be of type function');
178
+ }
179
+ if (_MessageChannel) {
180
+ var channel_1 = new _MessageChannel();
181
+ channel_1.port1.onmessage = function () {
182
+ channel_1.port1.onmessage = null;
183
+ channel_1 = undefined;
184
+ callback();
185
+ };
186
+ channel_1.port2.postMessage(null);
187
+ }
188
+ else {
189
+ setTimeout(callback, 0);
190
+ }
191
+ };
192
+ var _Buffer = typeof Buffer === 'function'
193
+ ? Buffer
194
+ : /*#__PURE__*/ (function () {
195
+ try {
196
+ return _require('buffer').Buffer;
197
+ }
198
+ catch (_) { }
199
+ return undefined;
200
+ })();
201
+ var version = "1.11.3";
202
+ var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
203
+ var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
204
+ var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
205
+ var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */;
206
+
207
+ var Handle = /*#__PURE__*/ (function () {
208
+ function Handle(id, value) {
209
+ this.id = id;
210
+ this.value = value;
211
+ }
212
+ Handle.prototype.data = function () {
213
+ return getExternalValue(this.value);
214
+ };
215
+ Handle.prototype.isNumber = function () {
216
+ return typeof this.value === 'number';
217
+ };
218
+ Handle.prototype.isBigInt = function () {
219
+ return typeof this.value === 'bigint';
220
+ };
221
+ Handle.prototype.isString = function () {
222
+ return typeof this.value === 'string';
223
+ };
224
+ Handle.prototype.isFunction = function () {
225
+ return typeof this.value === 'function';
226
+ };
227
+ Handle.prototype.isExternal = function () {
228
+ return isExternal(this.value);
229
+ };
230
+ Handle.prototype.isObject = function () {
231
+ return typeof this.value === 'object' && this.value !== null;
232
+ };
233
+ Handle.prototype.isArray = function () {
234
+ return Array.isArray(this.value);
235
+ };
236
+ Handle.prototype.isArrayBuffer = function () {
237
+ return (this.value instanceof ArrayBuffer);
238
+ };
239
+ Handle.prototype.isTypedArray = function () {
240
+ return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
241
+ };
242
+ Handle.prototype.isBuffer = function (BufferConstructor) {
243
+ if (ArrayBuffer.isView(this.value))
244
+ return true;
245
+ BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer);
246
+ return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value);
247
+ };
248
+ Handle.prototype.isDataView = function () {
249
+ return (this.value instanceof DataView);
250
+ };
251
+ Handle.prototype.isDate = function () {
252
+ return (this.value instanceof Date);
253
+ };
254
+ Handle.prototype.isPromise = function () {
255
+ return (this.value instanceof Promise);
256
+ };
257
+ Handle.prototype.isBoolean = function () {
258
+ return typeof this.value === 'boolean';
259
+ };
260
+ Handle.prototype.isUndefined = function () {
261
+ return this.value === undefined;
262
+ };
263
+ Handle.prototype.isSymbol = function () {
264
+ return typeof this.value === 'symbol';
265
+ };
266
+ Handle.prototype.isNull = function () {
267
+ return this.value === null;
268
+ };
269
+ Handle.prototype.dispose = function () {
270
+ this.value = undefined;
271
+ };
272
+ return Handle;
273
+ }());
274
+ var ConstHandle = /*#__PURE__*/ (function (_super) {
275
+ __extends(ConstHandle, _super);
276
+ function ConstHandle(id, value) {
277
+ return _super.call(this, id, value) || this;
278
+ }
279
+ ConstHandle.prototype.dispose = function () { };
280
+ return ConstHandle;
281
+ }(Handle));
282
+ var HandleStore = /*#__PURE__*/ (function () {
283
+ function HandleStore() {
284
+ this._values = [
285
+ undefined,
286
+ HandleStore.UNDEFINED,
287
+ HandleStore.NULL,
288
+ HandleStore.FALSE,
289
+ HandleStore.TRUE,
290
+ HandleStore.GLOBAL
291
+ ];
292
+ this._next = HandleStore.MIN_ID;
293
+ }
294
+ HandleStore.prototype.push = function (value) {
295
+ var h;
296
+ var next = this._next;
297
+ var values = this._values;
298
+ if (next < values.length) {
299
+ h = values[next];
300
+ h.value = value;
301
+ }
302
+ else {
303
+ h = new Handle(next, value);
304
+ values[next] = h;
305
+ }
306
+ this._next++;
307
+ return h;
308
+ };
309
+ HandleStore.prototype.erase = function (start, end) {
310
+ this._next = start;
311
+ var values = this._values;
312
+ for (var i = start; i < end; ++i) {
313
+ values[i].dispose();
314
+ }
315
+ };
316
+ HandleStore.prototype.get = function (id) {
317
+ return this._values[id];
318
+ };
319
+ HandleStore.prototype.swap = function (a, b) {
320
+ var values = this._values;
321
+ var h = values[a];
322
+ values[a] = values[b];
323
+ values[a].id = Number(a);
324
+ values[b] = h;
325
+ h.id = Number(b);
326
+ };
327
+ HandleStore.prototype.dispose = function () {
328
+ this._values.length = HandleStore.MIN_ID;
329
+ this._next = HandleStore.MIN_ID;
330
+ };
331
+ HandleStore.UNDEFINED = new ConstHandle(1 /* GlobalHandle.UNDEFINED */, undefined);
332
+ HandleStore.NULL = new ConstHandle(2 /* GlobalHandle.NULL */, null);
333
+ HandleStore.FALSE = new ConstHandle(3 /* GlobalHandle.FALSE */, false);
334
+ HandleStore.TRUE = new ConstHandle(4 /* GlobalHandle.TRUE */, true);
335
+ HandleStore.GLOBAL = new ConstHandle(5 /* GlobalHandle.GLOBAL */, _global);
336
+ HandleStore.MIN_ID = 6;
337
+ return HandleStore;
338
+ }());
339
+
340
+ var HandleScope = /*#__PURE__*/ (function () {
341
+ function HandleScope(handleStore, id, parentScope, start, end) {
342
+ if (end === void 0) { end = start; }
343
+ this.handleStore = handleStore;
344
+ this.id = id;
345
+ this.parent = parentScope;
346
+ this.child = null;
347
+ if (parentScope !== null)
348
+ parentScope.child = this;
349
+ this.start = start;
350
+ this.end = end;
351
+ this._escapeCalled = false;
352
+ this.callbackInfo = {
353
+ thiz: undefined,
354
+ data: 0,
355
+ args: undefined,
356
+ fn: undefined
357
+ };
358
+ }
359
+ HandleScope.prototype.add = function (value) {
360
+ var h = this.handleStore.push(value);
361
+ this.end++;
362
+ return h;
363
+ };
364
+ HandleScope.prototype.addExternal = function (data) {
365
+ return this.add(new External(data));
366
+ };
367
+ HandleScope.prototype.dispose = function () {
368
+ if (this._escapeCalled)
369
+ this._escapeCalled = false;
370
+ if (this.start === this.end)
371
+ return;
372
+ this.handleStore.erase(this.start, this.end);
373
+ };
374
+ HandleScope.prototype.escape = function (handle) {
375
+ if (this._escapeCalled)
376
+ return null;
377
+ this._escapeCalled = true;
378
+ if (handle < this.start || handle >= this.end) {
379
+ return null;
380
+ }
381
+ this.handleStore.swap(handle, this.start);
382
+ var h = this.handleStore.get(this.start);
383
+ this.start++;
384
+ this.parent.end++;
385
+ return h;
386
+ };
387
+ HandleScope.prototype.escapeCalled = function () {
388
+ return this._escapeCalled;
389
+ };
390
+ return HandleScope;
391
+ }());
392
+
393
+ var ScopeStore = /*#__PURE__*/ (function () {
394
+ function ScopeStore() {
395
+ this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID);
396
+ this.currentScope = this._rootScope;
397
+ this._values = [undefined];
398
+ }
399
+ ScopeStore.prototype.get = function (id) {
400
+ return this._values[id];
401
+ };
402
+ ScopeStore.prototype.openScope = function (handleStore) {
403
+ var currentScope = this.currentScope;
404
+ var scope = currentScope.child;
405
+ if (scope !== null) {
406
+ scope.start = scope.end = currentScope.end;
407
+ }
408
+ else {
409
+ var id = currentScope.id + 1;
410
+ scope = new HandleScope(handleStore, id, currentScope, currentScope.end);
411
+ this._values[id] = scope;
412
+ }
413
+ this.currentScope = scope;
414
+ return scope;
415
+ };
416
+ ScopeStore.prototype.closeScope = function () {
417
+ var scope = this.currentScope;
418
+ this.currentScope = scope.parent;
419
+ scope.dispose();
420
+ };
421
+ ScopeStore.prototype.dispose = function () {
422
+ this.currentScope = this._rootScope;
423
+ this._values.length = 1;
424
+ };
425
+ return ScopeStore;
426
+ }());
427
+
428
+ var RefTracker = /*#__PURE__*/ (function () {
429
+ function RefTracker() {
430
+ this._next = null;
431
+ this._prev = null;
432
+ }
433
+ /** @virtual */
434
+ RefTracker.prototype.dispose = function () { };
435
+ /** @virtual */
436
+ RefTracker.prototype.finalize = function () { };
437
+ RefTracker.prototype.link = function (list) {
438
+ this._prev = list;
439
+ this._next = list._next;
440
+ if (this._next !== null) {
441
+ this._next._prev = this;
442
+ }
443
+ list._next = this;
444
+ };
445
+ RefTracker.prototype.unlink = function () {
446
+ if (this._prev !== null) {
447
+ this._prev._next = this._next;
448
+ }
449
+ if (this._next !== null) {
450
+ this._next._prev = this._prev;
451
+ }
452
+ this._prev = null;
453
+ this._next = null;
454
+ };
455
+ RefTracker.finalizeAll = function (list) {
456
+ while (list._next !== null) {
457
+ list._next.finalize();
458
+ }
459
+ };
460
+ return RefTracker;
461
+ }());
462
+
463
+ var Finalizer = /*#__PURE__*/ (function () {
464
+ function Finalizer(envObject, _finalizeCallback, _finalizeData, _finalizeHint) {
465
+ if (_finalizeCallback === void 0) { _finalizeCallback = 0; }
466
+ if (_finalizeData === void 0) { _finalizeData = 0; }
467
+ if (_finalizeHint === void 0) { _finalizeHint = 0; }
468
+ this.envObject = envObject;
469
+ this._finalizeCallback = _finalizeCallback;
470
+ this._finalizeData = _finalizeData;
471
+ this._finalizeHint = _finalizeHint;
472
+ this._makeDynCall_vppp = envObject.makeDynCall_vppp;
473
+ }
474
+ Finalizer.prototype.callback = function () { return this._finalizeCallback; };
475
+ Finalizer.prototype.data = function () { return this._finalizeData; };
476
+ Finalizer.prototype.hint = function () { return this._finalizeHint; };
477
+ Finalizer.prototype.resetEnv = function () {
478
+ this.envObject = undefined;
479
+ };
480
+ Finalizer.prototype.resetFinalizer = function () {
481
+ this._finalizeCallback = 0;
482
+ this._finalizeData = 0;
483
+ this._finalizeHint = 0;
484
+ };
485
+ Finalizer.prototype.callFinalizer = function () {
486
+ var finalize_callback = this._finalizeCallback;
487
+ var finalize_data = this._finalizeData;
488
+ var finalize_hint = this._finalizeHint;
489
+ this.resetFinalizer();
490
+ if (!finalize_callback)
491
+ return;
492
+ var fini = Number(finalize_callback);
493
+ if (!this.envObject) {
494
+ this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
495
+ }
496
+ else {
497
+ this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
498
+ }
499
+ };
500
+ Finalizer.prototype.dispose = function () {
501
+ this.envObject = undefined;
502
+ this._makeDynCall_vppp = undefined;
503
+ };
504
+ return Finalizer;
505
+ }());
506
+
507
+ var TrackedFinalizer = /*#__PURE__*/ (function (_super) {
508
+ __extends(TrackedFinalizer, _super);
509
+ function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
510
+ var _this = _super.call(this) || this;
511
+ _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
512
+ return _this;
513
+ }
514
+ TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) {
515
+ var finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
516
+ finalizer.link(envObject.finalizing_reflist);
517
+ return finalizer;
518
+ };
519
+ TrackedFinalizer.prototype.data = function () {
520
+ return this._finalizer.data();
521
+ };
522
+ TrackedFinalizer.prototype.dispose = function () {
523
+ if (!this._finalizer)
524
+ return;
525
+ this.unlink();
526
+ this._finalizer.envObject.dequeueFinalizer(this);
527
+ this._finalizer.dispose();
528
+ this._finalizer = undefined;
529
+ _super.prototype.dispose.call(this);
530
+ };
531
+ TrackedFinalizer.prototype.finalize = function () {
532
+ this.unlink();
533
+ var error;
534
+ var caught = false;
535
+ try {
536
+ this._finalizer.callFinalizer();
537
+ }
538
+ catch (err) {
539
+ caught = true;
540
+ error = err;
541
+ }
542
+ this.dispose();
543
+ if (caught) {
544
+ throw error;
545
+ }
546
+ };
547
+ return TrackedFinalizer;
548
+ }(RefTracker));
549
+
550
+ function throwNodeApiVersionError(moduleName, moduleApiVersion) {
551
+ 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.");
552
+ throw new Error(errorMessage);
553
+ }
554
+ function handleThrow(envObject, value) {
555
+ if (envObject.terminatedOrTerminating()) {
556
+ return;
557
+ }
558
+ throw value;
559
+ }
560
+ var Env = /*#__PURE__*/ (function () {
561
+ function Env(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) {
562
+ this.ctx = ctx;
563
+ this.moduleApiVersion = moduleApiVersion;
564
+ this.makeDynCall_vppp = makeDynCall_vppp;
565
+ this.makeDynCall_vp = makeDynCall_vp;
566
+ this.abort = abort;
567
+ this.openHandleScopes = 0;
568
+ this.instanceData = null;
569
+ this.tryCatch = new TryCatch();
570
+ this.refs = 1;
571
+ this.reflist = new RefTracker();
572
+ this.finalizing_reflist = new RefTracker();
573
+ this.pendingFinalizers = [];
574
+ this.lastError = {
575
+ errorCode: 0 /* napi_status.napi_ok */,
576
+ engineErrorCode: 0,
577
+ engineReserved: 0
578
+ };
579
+ this.inGcFinalizer = false;
580
+ this._bindingMap = new WeakMap();
581
+ this.id = 0;
582
+ }
583
+ /** @virtual */
584
+ Env.prototype.canCallIntoJs = function () {
585
+ return true;
586
+ };
587
+ Env.prototype.terminatedOrTerminating = function () {
588
+ return !this.canCallIntoJs();
589
+ };
590
+ Env.prototype.ref = function () {
591
+ this.refs++;
592
+ };
593
+ Env.prototype.unref = function () {
594
+ this.refs--;
595
+ if (this.refs === 0) {
596
+ this.dispose();
597
+ }
598
+ };
599
+ Env.prototype.ensureHandle = function (value) {
600
+ return this.ctx.ensureHandle(value);
601
+ };
602
+ Env.prototype.ensureHandleId = function (value) {
603
+ return this.ensureHandle(value).id;
604
+ };
605
+ Env.prototype.clearLastError = function () {
606
+ var lastError = this.lastError;
607
+ if (lastError.errorCode !== 0 /* napi_status.napi_ok */)
608
+ lastError.errorCode = 0 /* napi_status.napi_ok */;
609
+ if (lastError.engineErrorCode !== 0)
610
+ lastError.engineErrorCode = 0;
611
+ if (lastError.engineReserved !== 0)
612
+ lastError.engineReserved = 0;
613
+ return 0 /* napi_status.napi_ok */;
614
+ };
615
+ Env.prototype.setLastError = function (error_code, engine_error_code, engine_reserved) {
616
+ if (engine_error_code === void 0) { engine_error_code = 0; }
617
+ if (engine_reserved === void 0) { engine_reserved = 0; }
618
+ var lastError = this.lastError;
619
+ if (lastError.errorCode !== error_code)
620
+ lastError.errorCode = error_code;
621
+ if (lastError.engineErrorCode !== engine_error_code)
622
+ lastError.engineErrorCode = engine_error_code;
623
+ if (lastError.engineReserved !== engine_reserved)
624
+ lastError.engineReserved = engine_reserved;
625
+ return error_code;
626
+ };
627
+ Env.prototype.getReturnStatus = function () {
628
+ return !this.tryCatch.hasCaught() ? 0 /* napi_status.napi_ok */ : this.setLastError(10 /* napi_status.napi_pending_exception */);
629
+ };
630
+ Env.prototype.callIntoModule = function (fn, handleException) {
631
+ if (handleException === void 0) { handleException = handleThrow; }
632
+ var openHandleScopesBefore = this.openHandleScopes;
633
+ this.clearLastError();
634
+ var r = fn(this);
635
+ if (openHandleScopesBefore !== this.openHandleScopes) {
636
+ this.abort('open_handle_scopes != open_handle_scopes_before');
637
+ }
638
+ if (this.tryCatch.hasCaught()) {
639
+ var err = this.tryCatch.extractException();
640
+ handleException(this, err);
641
+ }
642
+ return r;
643
+ };
644
+ Env.prototype.invokeFinalizerFromGC = function (finalizer) {
645
+ if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
646
+ this.enqueueFinalizer(finalizer);
647
+ }
648
+ else {
649
+ var saved = this.inGcFinalizer;
650
+ this.inGcFinalizer = true;
651
+ try {
652
+ finalizer.finalize();
653
+ }
654
+ finally {
655
+ this.inGcFinalizer = saved;
656
+ }
657
+ }
658
+ };
659
+ Env.prototype.checkGCAccess = function () {
660
+ if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) {
661
+ this.abort('Finalizer is calling a function that may affect GC state.\n' +
662
+ 'The finalizers are run directly from GC and must not affect GC ' +
663
+ 'state.\n' +
664
+ 'Use `node_api_post_finalizer` from inside of the finalizer to work ' +
665
+ 'around this issue.\n' +
666
+ 'It schedules the call as a new task in the event loop.');
667
+ }
668
+ };
669
+ /** @virtual */
670
+ Env.prototype.enqueueFinalizer = function (finalizer) {
671
+ if (this.pendingFinalizers.indexOf(finalizer) === -1) {
672
+ this.pendingFinalizers.push(finalizer);
673
+ }
674
+ };
675
+ /** @virtual */
676
+ Env.prototype.dequeueFinalizer = function (finalizer) {
677
+ var index = this.pendingFinalizers.indexOf(finalizer);
678
+ if (index !== -1) {
679
+ this.pendingFinalizers.splice(index, 1);
680
+ }
681
+ };
682
+ /** @virtual */
683
+ Env.prototype.deleteMe = function () {
684
+ RefTracker.finalizeAll(this.finalizing_reflist);
685
+ RefTracker.finalizeAll(this.reflist);
686
+ this.tryCatch.extractException();
687
+ this.ctx.envStore.remove(this.id);
688
+ };
689
+ Env.prototype.dispose = function () {
690
+ if (this.id === 0)
691
+ return;
692
+ this.deleteMe();
693
+ this.finalizing_reflist.dispose();
694
+ this.reflist.dispose();
695
+ this.id = 0;
696
+ };
697
+ Env.prototype.initObjectBinding = function (value) {
698
+ var binding = {
699
+ wrapped: 0,
700
+ tag: null
701
+ };
702
+ this._bindingMap.set(value, binding);
703
+ return binding;
704
+ };
705
+ Env.prototype.getObjectBinding = function (value) {
706
+ if (this._bindingMap.has(value)) {
707
+ return this._bindingMap.get(value);
708
+ }
709
+ return this.initObjectBinding(value);
710
+ };
711
+ Env.prototype.setInstanceData = function (data, finalize_cb, finalize_hint) {
712
+ if (this.instanceData) {
713
+ this.instanceData.dispose();
714
+ }
715
+ this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
716
+ };
717
+ Env.prototype.getInstanceData = function () {
718
+ return this.instanceData ? this.instanceData.data() : 0;
719
+ };
720
+ return Env;
721
+ }());
722
+ var NodeEnv = /*#__PURE__*/ (function (_super) {
723
+ __extends(NodeEnv, _super);
724
+ function NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
725
+ var _this = _super.call(this, ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) || this;
726
+ _this.filename = filename;
727
+ _this.nodeBinding = nodeBinding;
728
+ _this.destructing = false;
729
+ _this.finalizationScheduled = false;
730
+ return _this;
731
+ }
732
+ NodeEnv.prototype.deleteMe = function () {
733
+ this.destructing = true;
734
+ this.drainFinalizerQueue();
735
+ _super.prototype.deleteMe.call(this);
736
+ };
737
+ NodeEnv.prototype.canCallIntoJs = function () {
738
+ return _super.prototype.canCallIntoJs.call(this) && this.ctx.canCallIntoJs();
739
+ };
740
+ NodeEnv.prototype.triggerFatalException = function (err) {
741
+ if (this.nodeBinding) {
742
+ this.nodeBinding.napi.fatalException(err);
743
+ }
744
+ else {
745
+ if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') {
746
+ var handled = process._fatalException(err);
747
+ if (!handled) {
748
+ console.error(err);
749
+ process.exit(1);
750
+ }
751
+ }
752
+ else {
753
+ throw err;
754
+ }
755
+ }
756
+ };
757
+ NodeEnv.prototype.callbackIntoModule = function (enforceUncaughtExceptionPolicy, fn) {
758
+ return this.callIntoModule(fn, function (envObject, err) {
759
+ if (envObject.terminatedOrTerminating()) {
760
+ return;
761
+ }
762
+ var hasProcess = typeof process === 'object' && process !== null;
763
+ var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
764
+ if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
765
+ var warn = hasProcess && typeof process.emitWarning === 'function'
766
+ ? process.emitWarning
767
+ : function (warning, type, code) {
768
+ if (warning instanceof Error) {
769
+ console.warn(warning.toString());
770
+ }
771
+ else {
772
+ var prefix = code ? "[".concat(code, "] ") : '';
773
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
774
+ console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
775
+ }
776
+ };
777
+ warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
778
+ return;
779
+ }
780
+ envObject.triggerFatalException(err);
781
+ });
782
+ };
783
+ NodeEnv.prototype.callFinalizer = function (cb, data, hint) {
784
+ this.callFinalizerInternal(1, cb, data, hint);
785
+ };
786
+ NodeEnv.prototype.callFinalizerInternal = function (forceUncaught, cb, data, hint) {
787
+ var f = this.makeDynCall_vppp(cb);
788
+ var env = this.id;
789
+ var scope = this.ctx.openScope(this);
790
+ try {
791
+ this.callbackIntoModule(Boolean(forceUncaught), function () { f(env, data, hint); });
792
+ }
793
+ finally {
794
+ this.ctx.closeScope(this, scope);
795
+ }
796
+ };
797
+ NodeEnv.prototype.enqueueFinalizer = function (finalizer) {
798
+ var _this = this;
799
+ _super.prototype.enqueueFinalizer.call(this, finalizer);
800
+ if (!this.finalizationScheduled && !this.destructing) {
801
+ this.finalizationScheduled = true;
802
+ this.ref();
803
+ _setImmediate(function () {
804
+ _this.finalizationScheduled = false;
805
+ _this.unref();
806
+ _this.drainFinalizerQueue();
807
+ });
808
+ }
809
+ };
810
+ NodeEnv.prototype.drainFinalizerQueue = function () {
811
+ while (this.pendingFinalizers.length > 0) {
812
+ var refTracker = this.pendingFinalizers.shift();
813
+ refTracker.finalize();
814
+ }
815
+ };
816
+ return NodeEnv;
817
+ }(Env));
818
+ function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
819
+ moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion;
820
+ // Validate module_api_version.
821
+ if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
822
+ moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
823
+ }
824
+ else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
825
+ throwNodeApiVersionError(filename, moduleApiVersion);
826
+ }
827
+ var env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
828
+ ctx.envStore.add(env);
829
+ ctx.addCleanupHook(env, function () { env.unref(); }, 0);
830
+ return env;
831
+ }
832
+
833
+ var EmnapiError = /*#__PURE__*/ (function (_super) {
834
+ __extends(EmnapiError, _super);
835
+ function EmnapiError(message) {
836
+ var _newTarget = this.constructor;
837
+ var _this = _super.call(this, message) || this;
838
+ var ErrorConstructor = _newTarget;
839
+ var proto = ErrorConstructor.prototype;
840
+ if (!(_this instanceof EmnapiError)) {
841
+ var setPrototypeOf = Object.setPrototypeOf;
842
+ if (typeof setPrototypeOf === 'function') {
843
+ setPrototypeOf.call(Object, _this, proto);
844
+ }
845
+ else {
846
+ // eslint-disable-next-line no-proto
847
+ _this.__proto__ = proto;
848
+ }
849
+ if (typeof Error.captureStackTrace === 'function') {
850
+ Error.captureStackTrace(_this, ErrorConstructor);
851
+ }
852
+ }
853
+ return _this;
854
+ }
855
+ return EmnapiError;
856
+ }(Error));
857
+ Object.defineProperty(EmnapiError.prototype, 'name', {
858
+ configurable: true,
859
+ writable: true,
860
+ value: 'EmnapiError'
861
+ });
862
+ var NotSupportWeakRefError = /*#__PURE__*/ (function (_super) {
863
+ __extends(NotSupportWeakRefError, _super);
864
+ function NotSupportWeakRefError(api, message) {
865
+ return _super.call(this, "".concat(api, ": The current runtime does not support \"FinalizationRegistry\" and \"WeakRef\".").concat(message ? " ".concat(message) : '')) || this;
866
+ }
867
+ return NotSupportWeakRefError;
868
+ }(EmnapiError));
869
+ Object.defineProperty(NotSupportWeakRefError.prototype, 'name', {
870
+ configurable: true,
871
+ writable: true,
872
+ value: 'NotSupportWeakRefError'
873
+ });
874
+ var NotSupportBufferError = /*#__PURE__*/ (function (_super) {
875
+ __extends(NotSupportBufferError, _super);
876
+ function NotSupportBufferError(api, message) {
877
+ 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;
878
+ }
879
+ return NotSupportBufferError;
880
+ }(EmnapiError));
881
+ Object.defineProperty(NotSupportBufferError.prototype, 'name', {
882
+ configurable: true,
883
+ writable: true,
884
+ value: 'NotSupportBufferError'
885
+ });
886
+
887
+ var StrongRef = /*#__PURE__*/ (function () {
888
+ function StrongRef(value) {
889
+ this._value = value;
890
+ }
891
+ StrongRef.prototype.deref = function () {
892
+ return this._value;
893
+ };
894
+ StrongRef.prototype.dispose = function () {
895
+ this._value = undefined;
896
+ };
897
+ return StrongRef;
898
+ }());
899
+ var Persistent = /*#__PURE__*/ (function () {
900
+ function Persistent(value) {
901
+ this._ref = new StrongRef(value);
902
+ }
903
+ Persistent.prototype.setWeak = function (param, callback) {
904
+ if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef)
905
+ return;
906
+ var value = this._ref.deref();
907
+ try {
908
+ Persistent._registry.register(value, this, this);
909
+ var weakRef = new WeakRef(value);
910
+ this._ref.dispose();
911
+ this._ref = weakRef;
912
+ this._param = param;
913
+ this._callback = callback;
914
+ }
915
+ catch (err) {
916
+ if (typeof value === 'symbol') ;
917
+ else {
918
+ throw err;
919
+ }
920
+ }
921
+ };
922
+ Persistent.prototype.clearWeak = function () {
923
+ if (!supportFinalizer || this._ref === undefined)
924
+ return;
925
+ if (this._ref instanceof WeakRef) {
926
+ try {
927
+ Persistent._registry.unregister(this);
928
+ }
929
+ catch (_) { }
930
+ this._param = undefined;
931
+ this._callback = undefined;
932
+ var value = this._ref.deref();
933
+ if (value === undefined) {
934
+ this._ref = value;
935
+ }
936
+ else {
937
+ this._ref = new StrongRef(value);
938
+ }
939
+ }
940
+ };
941
+ Persistent.prototype.reset = function () {
942
+ if (supportFinalizer) {
943
+ try {
944
+ Persistent._registry.unregister(this);
945
+ }
946
+ catch (_) { }
947
+ }
948
+ this._param = undefined;
949
+ this._callback = undefined;
950
+ if (this._ref instanceof StrongRef) {
951
+ this._ref.dispose();
952
+ }
953
+ this._ref = undefined;
954
+ };
955
+ Persistent.prototype.isEmpty = function () {
956
+ return this._ref === undefined;
957
+ };
958
+ Persistent.prototype.deref = function () {
959
+ if (this._ref === undefined)
960
+ return undefined;
961
+ return this._ref.deref();
962
+ };
963
+ Persistent._registry = supportFinalizer
964
+ ? new FinalizationRegistry(function (value) {
965
+ value._ref = undefined;
966
+ var callback = value._callback;
967
+ var param = value._param;
968
+ value._callback = undefined;
969
+ value._param = undefined;
970
+ if (typeof callback === 'function') {
971
+ callback(param);
972
+ }
973
+ })
974
+ : undefined;
975
+ return Persistent;
976
+ }());
977
+
978
+ exports.ReferenceOwnership = void 0;
979
+ (function (ReferenceOwnership) {
980
+ ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
981
+ ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
982
+ })(exports.ReferenceOwnership || (exports.ReferenceOwnership = {}));
983
+ function canBeHeldWeakly(value) {
984
+ return value.isObject() || value.isFunction() || value.isSymbol();
985
+ }
986
+ var Reference = /*#__PURE__*/ (function (_super) {
987
+ __extends(Reference, _super);
988
+ function Reference(envObject, handle_id, initialRefcount, ownership) {
989
+ var _this = _super.call(this) || this;
990
+ _this.envObject = envObject;
991
+ _this._refcount = initialRefcount;
992
+ _this._ownership = ownership;
993
+ var handle = envObject.ctx.handleStore.get(handle_id);
994
+ _this.canBeWeak = canBeHeldWeakly(handle);
995
+ _this.persistent = new Persistent(handle.value);
996
+ _this.id = 0;
997
+ if (initialRefcount === 0) {
998
+ _this._setWeak();
999
+ }
1000
+ return _this;
1001
+ }
1002
+ Reference.weakCallback = function (ref) {
1003
+ ref.persistent.reset();
1004
+ ref.invokeFinalizerFromGC();
1005
+ };
1006
+ Reference.create = function (envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
1007
+ var ref = new Reference(envObject, handle_id, initialRefcount, ownership);
1008
+ envObject.ctx.refStore.add(ref);
1009
+ ref.link(envObject.reflist);
1010
+ return ref;
1011
+ };
1012
+ Reference.prototype.ref = function () {
1013
+ if (this.persistent.isEmpty()) {
1014
+ return 0;
1015
+ }
1016
+ if (++this._refcount === 1 && this.canBeWeak) {
1017
+ this.persistent.clearWeak();
1018
+ }
1019
+ return this._refcount;
1020
+ };
1021
+ Reference.prototype.unref = function () {
1022
+ if (this.persistent.isEmpty() || this._refcount === 0) {
1023
+ return 0;
1024
+ }
1025
+ if (--this._refcount === 0) {
1026
+ this._setWeak();
1027
+ }
1028
+ return this._refcount;
1029
+ };
1030
+ Reference.prototype.get = function (envObject) {
1031
+ if (envObject === void 0) { envObject = this.envObject; }
1032
+ if (this.persistent.isEmpty()) {
1033
+ return 0;
1034
+ }
1035
+ var obj = this.persistent.deref();
1036
+ var handle = envObject.ensureHandle(obj);
1037
+ return handle.id;
1038
+ };
1039
+ /** @virtual */
1040
+ Reference.prototype.resetFinalizer = function () { };
1041
+ /** @virtual */
1042
+ Reference.prototype.data = function () { return 0; };
1043
+ Reference.prototype.refcount = function () { return this._refcount; };
1044
+ Reference.prototype.ownership = function () { return this._ownership; };
1045
+ /** @virtual */
1046
+ Reference.prototype.callUserFinalizer = function () { };
1047
+ /** @virtual */
1048
+ Reference.prototype.invokeFinalizerFromGC = function () {
1049
+ this.finalize();
1050
+ };
1051
+ Reference.prototype._setWeak = function () {
1052
+ if (this.canBeWeak) {
1053
+ this.persistent.setWeak(this, Reference.weakCallback);
1054
+ }
1055
+ else {
1056
+ this.persistent.reset();
1057
+ }
1058
+ };
1059
+ Reference.prototype.finalize = function () {
1060
+ this.persistent.reset();
1061
+ var deleteMe = this._ownership === exports.ReferenceOwnership.kRuntime;
1062
+ this.unlink();
1063
+ this.callUserFinalizer();
1064
+ if (deleteMe) {
1065
+ this.dispose();
1066
+ }
1067
+ };
1068
+ Reference.prototype.dispose = function () {
1069
+ if (this.id === 0)
1070
+ return;
1071
+ this.unlink();
1072
+ this.persistent.reset();
1073
+ this.envObject.ctx.refStore.remove(this.id);
1074
+ _super.prototype.dispose.call(this);
1075
+ this.envObject = undefined;
1076
+ this.id = 0;
1077
+ };
1078
+ return Reference;
1079
+ }(RefTracker));
1080
+ var ReferenceWithData = /*#__PURE__*/ (function (_super) {
1081
+ __extends(ReferenceWithData, _super);
1082
+ function ReferenceWithData(envObject, value, initialRefcount, ownership, _data) {
1083
+ var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
1084
+ _this._data = _data;
1085
+ return _this;
1086
+ }
1087
+ ReferenceWithData.create = function (envObject, value, initialRefcount, ownership, data) {
1088
+ var reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
1089
+ envObject.ctx.refStore.add(reference);
1090
+ reference.link(envObject.reflist);
1091
+ return reference;
1092
+ };
1093
+ ReferenceWithData.prototype.data = function () {
1094
+ return this._data;
1095
+ };
1096
+ return ReferenceWithData;
1097
+ }(Reference));
1098
+ var ReferenceWithFinalizer = /*#__PURE__*/ (function (_super) {
1099
+ __extends(ReferenceWithFinalizer, _super);
1100
+ function ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1101
+ var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
1102
+ _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
1103
+ return _this;
1104
+ }
1105
+ ReferenceWithFinalizer.create = function (envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1106
+ var reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1107
+ envObject.ctx.refStore.add(reference);
1108
+ reference.link(envObject.finalizing_reflist);
1109
+ return reference;
1110
+ };
1111
+ ReferenceWithFinalizer.prototype.resetFinalizer = function () {
1112
+ this._finalizer.resetFinalizer();
1113
+ };
1114
+ ReferenceWithFinalizer.prototype.data = function () {
1115
+ return this._finalizer.data();
1116
+ };
1117
+ ReferenceWithFinalizer.prototype.callUserFinalizer = function () {
1118
+ this._finalizer.callFinalizer();
1119
+ };
1120
+ ReferenceWithFinalizer.prototype.invokeFinalizerFromGC = function () {
1121
+ this._finalizer.envObject.invokeFinalizerFromGC(this);
1122
+ };
1123
+ ReferenceWithFinalizer.prototype.dispose = function () {
1124
+ if (!this._finalizer)
1125
+ return;
1126
+ this._finalizer.envObject.dequeueFinalizer(this);
1127
+ this._finalizer.dispose();
1128
+ _super.prototype.dispose.call(this);
1129
+ this._finalizer = undefined;
1130
+ };
1131
+ return ReferenceWithFinalizer;
1132
+ }(Reference));
1133
+
1134
+ var Deferred = /*#__PURE__*/ (function () {
1135
+ function Deferred(ctx, value) {
1136
+ // Plain assignment would invoke inherited setters before these fields
1137
+ // become own properties.
1138
+ Object.defineProperties(this, {
1139
+ id: {
1140
+ configurable: true,
1141
+ enumerable: true,
1142
+ value: 0,
1143
+ writable: true
1144
+ },
1145
+ ctx: {
1146
+ configurable: true,
1147
+ enumerable: true,
1148
+ value: ctx,
1149
+ writable: true
1150
+ },
1151
+ value: {
1152
+ configurable: true,
1153
+ enumerable: true,
1154
+ value: value,
1155
+ writable: true
1156
+ }
1157
+ });
1158
+ }
1159
+ Deferred.create = function (ctx, value) {
1160
+ var deferred = new Deferred(ctx, value);
1161
+ ctx.deferredStore.add(deferred);
1162
+ return deferred;
1163
+ };
1164
+ Deferred.prototype.resolve = function (value) {
1165
+ this.value.resolve(value);
1166
+ this.dispose();
1167
+ };
1168
+ Deferred.prototype.reject = function (reason) {
1169
+ this.value.reject(reason);
1170
+ this.dispose();
1171
+ };
1172
+ Deferred.prototype.dispose = function () {
1173
+ this.ctx.deferredStore.remove(this.id);
1174
+ this.id = 0;
1175
+ this.value = null;
1176
+ this.ctx = null;
1177
+ };
1178
+ return Deferred;
1179
+ }());
1180
+
1181
+ var Store = /*#__PURE__*/ (function () {
1182
+ function Store() {
1183
+ this._values = [undefined];
1184
+ this._values.length = 4;
1185
+ this._size = 1;
1186
+ this._freeList = [];
1187
+ }
1188
+ Store.prototype.add = function (value) {
1189
+ var id;
1190
+ if (this._freeList.length) {
1191
+ id = this._freeList.shift();
1192
+ }
1193
+ else {
1194
+ id = this._size;
1195
+ this._size++;
1196
+ var capacity = this._values.length;
1197
+ if (id >= capacity) {
1198
+ this._values.length = capacity + (capacity >> 1) + 16;
1199
+ }
1200
+ }
1201
+ value.id = id;
1202
+ this._values[id] = value;
1203
+ };
1204
+ Store.prototype.get = function (id) {
1205
+ return this._values[id];
1206
+ };
1207
+ Store.prototype.has = function (id) {
1208
+ return this._values[id] !== undefined;
1209
+ };
1210
+ Store.prototype.remove = function (id) {
1211
+ var value = this._values[id];
1212
+ if (value) {
1213
+ value.id = 0;
1214
+ this._values[id] = undefined;
1215
+ this._freeList.push(Number(id));
1216
+ }
1217
+ };
1218
+ Store.prototype.dispose = function () {
1219
+ for (var i = 1; i < this._size; ++i) {
1220
+ var value = this._values[i];
1221
+ value === null || value === void 0 ? void 0 : value.dispose();
1222
+ }
1223
+ this._values = [undefined];
1224
+ this._size = 1;
1225
+ this._freeList = [];
1226
+ };
1227
+ return Store;
1228
+ }());
1229
+
1230
+ var kMaxReasonableBytes = BigInt(1) << BigInt(60);
1231
+ var kMinReasonableBytes = -kMaxReasonableBytes;
1232
+ var ExternalMemory = /*#__PURE__*/ (function () {
1233
+ function ExternalMemory(onChange) {
1234
+ this.total = BigInt(0);
1235
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
1236
+ }
1237
+ ExternalMemory.prototype.adjust = function (changeInBytes) {
1238
+ changeInBytes = BigInt(changeInBytes);
1239
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
1240
+ throw new RangeError("changeInBytes ".concat(changeInBytes, " is out of reasonable range"));
1241
+ }
1242
+ var old = this.total;
1243
+ this.total += changeInBytes;
1244
+ var amount = this.total;
1245
+ var onChange = this.onChange;
1246
+ if (changeInBytes) {
1247
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
1248
+ }
1249
+ return amount;
1250
+ };
1251
+ return ExternalMemory;
1252
+ }());
1253
+
1254
+ var CleanupHookCallback = /*#__PURE__*/ (function () {
1255
+ function CleanupHookCallback(envObject, fn, arg, order) {
1256
+ this.envObject = envObject;
1257
+ this.fn = fn;
1258
+ this.arg = arg;
1259
+ this.order = order;
1260
+ }
1261
+ return CleanupHookCallback;
1262
+ }());
1263
+ var CleanupQueue = /*#__PURE__*/ (function () {
1264
+ function CleanupQueue() {
1265
+ this._cleanupHooks = [];
1266
+ this._cleanupHookCounter = 0;
1267
+ }
1268
+ CleanupQueue.prototype.empty = function () {
1269
+ return this._cleanupHooks.length === 0;
1270
+ };
1271
+ CleanupQueue.prototype.add = function (envObject, fn, arg) {
1272
+ if (this._cleanupHooks.filter(function (hook) { return (hook.envObject === envObject && hook.fn === fn && hook.arg === arg); }).length > 0) {
1273
+ throw new Error('Can not add same fn and arg twice');
1274
+ }
1275
+ this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++));
1276
+ };
1277
+ CleanupQueue.prototype.remove = function (envObject, fn, arg) {
1278
+ for (var i = 0; i < this._cleanupHooks.length; ++i) {
1279
+ var hook = this._cleanupHooks[i];
1280
+ if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) {
1281
+ this._cleanupHooks.splice(i, 1);
1282
+ return;
1283
+ }
1284
+ }
1285
+ };
1286
+ CleanupQueue.prototype.drain = function () {
1287
+ var hooks = this._cleanupHooks.slice();
1288
+ hooks.sort(function (a, b) { return (b.order - a.order); });
1289
+ for (var i = 0; i < hooks.length; ++i) {
1290
+ var cb = hooks[i];
1291
+ if (typeof cb.fn === 'number') {
1292
+ cb.envObject.makeDynCall_vp(cb.fn)(cb.arg);
1293
+ }
1294
+ else {
1295
+ cb.fn(cb.arg);
1296
+ }
1297
+ this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1);
1298
+ }
1299
+ };
1300
+ CleanupQueue.prototype.dispose = function () {
1301
+ this._cleanupHooks.length = 0;
1302
+ this._cleanupHookCounter = 0;
1303
+ };
1304
+ return CleanupQueue;
1305
+ }());
1306
+ var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () {
1307
+ function NodejsWaitingRequestCounter() {
1308
+ this.refHandle = new _MessageChannel().port1;
1309
+ this.count = 0;
1310
+ }
1311
+ NodejsWaitingRequestCounter.prototype.increase = function () {
1312
+ if (this.count === 0) {
1313
+ if (this.refHandle.ref) {
1314
+ this.refHandle.ref();
1315
+ }
1316
+ }
1317
+ this.count++;
1318
+ };
1319
+ NodejsWaitingRequestCounter.prototype.decrease = function () {
1320
+ if (this.count === 0)
1321
+ return;
1322
+ if (this.count === 1) {
1323
+ if (this.refHandle.unref) {
1324
+ this.refHandle.unref();
1325
+ }
1326
+ }
1327
+ this.count--;
1328
+ };
1329
+ return NodejsWaitingRequestCounter;
1330
+ }());
1331
+ var Context = /*#__PURE__*/ (function () {
1332
+ function Context(options) {
1333
+ var _this = this;
1334
+ this._isStopping = false;
1335
+ this._canCallIntoJs = true;
1336
+ this._suppressDestroy = false;
1337
+ this.envStore = new Store();
1338
+ this.scopeStore = new ScopeStore();
1339
+ this.refStore = new Store();
1340
+ this.deferredStore = new Store();
1341
+ this.handleStore = new HandleStore();
1342
+ this.feature = {
1343
+ supportReflect: supportReflect,
1344
+ supportFinalizer: supportFinalizer,
1345
+ supportWeakSymbol: supportWeakSymbol,
1346
+ supportBigInt: supportBigInt,
1347
+ supportNewFunction: supportNewFunction,
1348
+ canSetFunctionName: canSetFunctionName,
1349
+ setImmediate: _setImmediate,
1350
+ Buffer: _Buffer,
1351
+ MessageChannel: _MessageChannel
1352
+ };
1353
+ this.cleanupQueue = new CleanupQueue();
1354
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
1355
+ if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1356
+ this.refCounter = new NodejsWaitingRequestCounter();
1357
+ process.once('beforeExit', function () {
1358
+ if (!_this._suppressDestroy) {
1359
+ _this.destroy();
1360
+ }
1361
+ });
1362
+ }
1363
+ }
1364
+ /**
1365
+ * Suppress the destroy on `beforeExit` event in Node.js.
1366
+ * Call this method if you want to keep the context and
1367
+ * all associated {@link Env | Env} alive,
1368
+ * this also means that cleanup hooks will not be called.
1369
+ * After call this method, you should call
1370
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
1371
+ */
1372
+ Context.prototype.suppressDestroy = function () {
1373
+ this._suppressDestroy = true;
1374
+ };
1375
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
1376
+ Context.prototype.getRuntimeVersions = function () {
1377
+ return {
1378
+ version: version,
1379
+ NODE_API_SUPPORTED_VERSION_MAX: NODE_API_SUPPORTED_VERSION_MAX,
1380
+ NAPI_VERSION_EXPERIMENTAL: NAPI_VERSION_EXPERIMENTAL,
1381
+ NODE_API_DEFAULT_MODULE_API_VERSION: NODE_API_DEFAULT_MODULE_API_VERSION
1382
+ };
1383
+ };
1384
+ Context.prototype.createNotSupportWeakRefError = function (api, message) {
1385
+ return new NotSupportWeakRefError(api, message);
1386
+ };
1387
+ Context.prototype.createNotSupportBufferError = function (api, message) {
1388
+ return new NotSupportBufferError(api, message);
1389
+ };
1390
+ Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership) {
1391
+ return Reference.create(envObject, handle_id, initialRefcount, ownership);
1392
+ };
1393
+ Context.prototype.createReferenceWithData = function (envObject, handle_id, initialRefcount, ownership, data) {
1394
+ return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
1395
+ };
1396
+ Context.prototype.createReferenceWithFinalizer = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1397
+ if (finalize_callback === void 0) { finalize_callback = 0; }
1398
+ if (finalize_data === void 0) { finalize_data = 0; }
1399
+ if (finalize_hint === void 0) { finalize_hint = 0; }
1400
+ return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1401
+ };
1402
+ Context.prototype.createDeferred = function (value) {
1403
+ return Deferred.create(this, value);
1404
+ };
1405
+ Context.prototype.adjustAmountOfExternalAllocatedMemory = function (changeInBytes) {
1406
+ return this._externalMemory.adjust(changeInBytes);
1407
+ };
1408
+ Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1409
+ return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1410
+ };
1411
+ Context.prototype.createTrackedFinalizer = function (envObject, finalize_callback, finalize_data, finalize_hint) {
1412
+ return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint);
1413
+ };
1414
+ Context.prototype.getCurrentScope = function () {
1415
+ return this.scopeStore.currentScope;
1416
+ };
1417
+ Context.prototype.addToCurrentScope = function (value) {
1418
+ return this.scopeStore.currentScope.add(value);
1419
+ };
1420
+ Context.prototype.openScope = function (envObject) {
1421
+ var scope = this.scopeStore.openScope(this.handleStore);
1422
+ if (envObject)
1423
+ envObject.openHandleScopes++;
1424
+ return scope;
1425
+ };
1426
+ Context.prototype.closeScope = function (envObject, _scope) {
1427
+ if (envObject && envObject.openHandleScopes === 0)
1428
+ return;
1429
+ this.scopeStore.closeScope();
1430
+ if (envObject)
1431
+ envObject.openHandleScopes--;
1432
+ };
1433
+ Context.prototype.ensureHandle = function (value) {
1434
+ switch (value) {
1435
+ case undefined: return HandleStore.UNDEFINED;
1436
+ case null: return HandleStore.NULL;
1437
+ case true: return HandleStore.TRUE;
1438
+ case false: return HandleStore.FALSE;
1439
+ case _global: return HandleStore.GLOBAL;
1440
+ }
1441
+ return this.addToCurrentScope(value);
1442
+ };
1443
+ Context.prototype.addCleanupHook = function (envObject, fn, arg) {
1444
+ this.cleanupQueue.add(envObject, fn, arg);
1445
+ };
1446
+ Context.prototype.removeCleanupHook = function (envObject, fn, arg) {
1447
+ this.cleanupQueue.remove(envObject, fn, arg);
1448
+ };
1449
+ Context.prototype.runCleanup = function () {
1450
+ while (!this.cleanupQueue.empty()) {
1451
+ this.cleanupQueue.drain();
1452
+ }
1453
+ };
1454
+ Context.prototype.increaseWaitingRequestCounter = function () {
1455
+ var _a;
1456
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase();
1457
+ };
1458
+ Context.prototype.decreaseWaitingRequestCounter = function () {
1459
+ var _a;
1460
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease();
1461
+ };
1462
+ Context.prototype.setCanCallIntoJs = function (value) {
1463
+ this._canCallIntoJs = value;
1464
+ };
1465
+ Context.prototype.setStopping = function (value) {
1466
+ this._isStopping = value;
1467
+ };
1468
+ Context.prototype.canCallIntoJs = function () {
1469
+ return this._canCallIntoJs && !this._isStopping;
1470
+ };
1471
+ /**
1472
+ * Destroy the context and call cleanup hooks.
1473
+ * Associated {@link Env | Env} will be destroyed.
1474
+ */
1475
+ Context.prototype.destroy = function () {
1476
+ this.setStopping(true);
1477
+ this.setCanCallIntoJs(false);
1478
+ this.runCleanup();
1479
+ };
1480
+ return Context;
1481
+ }());
1482
+ var defaultContext;
1483
+ function createContext(options) {
1484
+ return new Context(options);
1485
+ }
1486
+ function getDefaultContext() {
1487
+ if (!defaultContext) {
1488
+ defaultContext = createContext();
1489
+ }
1490
+ return defaultContext;
1491
+ }
1492
+
1493
+ exports.ConstHandle = ConstHandle;
1494
+ exports.Context = Context;
1495
+ exports.Deferred = Deferred;
1496
+ exports.EmnapiError = EmnapiError;
1497
+ exports.Env = Env;
1498
+ exports.External = External;
1499
+ exports.Finalizer = Finalizer;
1500
+ exports.Handle = Handle;
1501
+ exports.HandleScope = HandleScope;
1502
+ exports.HandleStore = HandleStore;
1503
+ exports.NAPI_VERSION_EXPERIMENTAL = NAPI_VERSION_EXPERIMENTAL;
1504
+ exports.NODE_API_DEFAULT_MODULE_API_VERSION = NODE_API_DEFAULT_MODULE_API_VERSION;
1505
+ exports.NODE_API_SUPPORTED_VERSION_MAX = NODE_API_SUPPORTED_VERSION_MAX;
1506
+ exports.NODE_API_SUPPORTED_VERSION_MIN = NODE_API_SUPPORTED_VERSION_MIN;
1507
+ exports.NodeEnv = NodeEnv;
1508
+ exports.NotSupportBufferError = NotSupportBufferError;
1509
+ exports.NotSupportWeakRefError = NotSupportWeakRefError;
1510
+ exports.Persistent = Persistent;
1511
+ exports.RefTracker = RefTracker;
1512
+ exports.Reference = Reference;
1513
+ exports.ReferenceWithData = ReferenceWithData;
1514
+ exports.ReferenceWithFinalizer = ReferenceWithFinalizer;
1515
+ exports.ScopeStore = ScopeStore;
1516
+ exports.Store = Store;
1517
+ exports.TrackedFinalizer = TrackedFinalizer;
1518
+ exports.TryCatch = TryCatch;
1519
+ exports.createContext = createContext;
1520
+ exports.getDefaultContext = getDefaultContext;
1521
+ exports.getExternalValue = getExternalValue;
1522
+ exports.isExternal = isExternal;
1523
+ exports.isReferenceType = isReferenceType;
1524
+ exports.version = version;
1525
+
1526
+ return exports;
1527
+
1528
+ })({});
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.js ADDED
@@ -0,0 +1,1529 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.emnapi = {}));
5
+ })(this, (function (exports) {
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
21
+
22
+ var extendStatics = function(d, b) {
23
+ extendStatics = Object.setPrototypeOf ||
24
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
26
+ return extendStatics(d, b);
27
+ };
28
+
29
+ function __extends(d, b) {
30
+ if (typeof b !== "function" && b !== null)
31
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
32
+ extendStatics(d, b);
33
+ function __() { this.constructor = d; }
34
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
35
+ }
36
+
37
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
38
+ var e = new Error(message);
39
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
40
+ };
41
+
42
+ var externalValue = new WeakMap();
43
+ /** @public */
44
+ function isExternal(object) {
45
+ return externalValue.has(object);
46
+ }
47
+ /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare
48
+ var External = (function () {
49
+ function External(value) {
50
+ Object.setPrototypeOf(this, null);
51
+ externalValue.set(this, value);
52
+ }
53
+ External.prototype = null;
54
+ return External;
55
+ })();
56
+ /** @public */
57
+ function getExternalValue(external) {
58
+ if (!isExternal(external)) {
59
+ throw new TypeError('not external');
60
+ }
61
+ return externalValue.get(external);
62
+ }
63
+
64
+ var supportNewFunction = /*#__PURE__*/ (function () {
65
+ var f;
66
+ try {
67
+ f = new Function();
68
+ }
69
+ catch (_) {
70
+ return false;
71
+ }
72
+ return typeof f === 'function';
73
+ })();
74
+ var _global = /*#__PURE__*/ (function () {
75
+ if (typeof globalThis !== 'undefined')
76
+ return globalThis;
77
+ var g = (function () { return this; })();
78
+ if (!g && supportNewFunction) {
79
+ try {
80
+ g = new Function('return this')();
81
+ }
82
+ catch (_) { }
83
+ }
84
+ if (!g) {
85
+ if (typeof __webpack_public_path__ === 'undefined') {
86
+ if (typeof global !== 'undefined')
87
+ return global;
88
+ }
89
+ if (typeof window !== 'undefined')
90
+ return window;
91
+ if (typeof self !== 'undefined')
92
+ return self;
93
+ }
94
+ return g;
95
+ })();
96
+ var TryCatch = /*#__PURE__*/ (function () {
97
+ function TryCatch() {
98
+ this._exception = undefined;
99
+ this._caught = false;
100
+ }
101
+ TryCatch.prototype.isEmpty = function () {
102
+ return !this._caught;
103
+ };
104
+ TryCatch.prototype.hasCaught = function () {
105
+ return this._caught;
106
+ };
107
+ TryCatch.prototype.exception = function () {
108
+ return this._exception;
109
+ };
110
+ TryCatch.prototype.setError = function (err) {
111
+ this._caught = true;
112
+ this._exception = err;
113
+ };
114
+ TryCatch.prototype.reset = function () {
115
+ this._caught = false;
116
+ this._exception = undefined;
117
+ };
118
+ TryCatch.prototype.extractException = function () {
119
+ var e = this._exception;
120
+ this.reset();
121
+ return e;
122
+ };
123
+ return TryCatch;
124
+ }());
125
+ var canSetFunctionName = /*#__PURE__*/ (function () {
126
+ var _a;
127
+ try {
128
+ return Boolean((_a = Object.getOwnPropertyDescriptor(Function.prototype, 'name')) === null || _a === void 0 ? void 0 : _a.configurable);
129
+ }
130
+ catch (_) {
131
+ return false;
132
+ }
133
+ })();
134
+ var supportReflect = typeof Reflect === 'object';
135
+ var supportFinalizer = (typeof FinalizationRegistry !== 'undefined') && (typeof WeakRef !== 'undefined');
136
+ var supportWeakSymbol = /*#__PURE__*/ (function () {
137
+ try {
138
+ // eslint-disable-next-line symbol-description
139
+ var sym = Symbol();
140
+ // eslint-disable-next-line no-new
141
+ new WeakRef(sym);
142
+ new WeakMap().set(sym, undefined);
143
+ }
144
+ catch (_) {
145
+ return false;
146
+ }
147
+ return true;
148
+ })();
149
+ var supportBigInt = typeof BigInt !== 'undefined';
150
+ function isReferenceType(v) {
151
+ return (typeof v === 'object' && v !== null) || typeof v === 'function';
152
+ }
153
+ var _require = /*#__PURE__*/ (function () {
154
+ var nativeRequire;
155
+ if (typeof __webpack_public_path__ !== 'undefined') {
156
+ nativeRequire = (function () {
157
+ return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined;
158
+ })();
159
+ }
160
+ else {
161
+ nativeRequire = (function () {
162
+ return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined);
163
+ })();
164
+ }
165
+ return nativeRequire;
166
+ })();
167
+ var _MessageChannel = typeof MessageChannel === 'function'
168
+ ? MessageChannel
169
+ : /*#__PURE__*/ (function () {
170
+ try {
171
+ return _require('worker_threads').MessageChannel;
172
+ }
173
+ catch (_) { }
174
+ return undefined;
175
+ })();
176
+ var _setImmediate = typeof setImmediate === 'function'
177
+ ? setImmediate.bind(_global)
178
+ : function (callback) {
179
+ if (typeof callback !== 'function') {
180
+ throw new TypeError('The "callback" argument must be of type function');
181
+ }
182
+ if (_MessageChannel) {
183
+ var channel_1 = new _MessageChannel();
184
+ channel_1.port1.onmessage = function () {
185
+ channel_1.port1.onmessage = null;
186
+ channel_1 = undefined;
187
+ callback();
188
+ };
189
+ channel_1.port2.postMessage(null);
190
+ }
191
+ else {
192
+ setTimeout(callback, 0);
193
+ }
194
+ };
195
+ var _Buffer = typeof Buffer === 'function'
196
+ ? Buffer
197
+ : /*#__PURE__*/ (function () {
198
+ try {
199
+ return _require('buffer').Buffer;
200
+ }
201
+ catch (_) { }
202
+ return undefined;
203
+ })();
204
+ var version = "1.11.3";
205
+ var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
206
+ var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
207
+ var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
208
+ var NODE_API_DEFAULT_MODULE_API_VERSION = 8 /* Version.NODE_API_DEFAULT_MODULE_API_VERSION */;
209
+
210
+ var Handle = /*#__PURE__*/ (function () {
211
+ function Handle(id, value) {
212
+ this.id = id;
213
+ this.value = value;
214
+ }
215
+ Handle.prototype.data = function () {
216
+ return getExternalValue(this.value);
217
+ };
218
+ Handle.prototype.isNumber = function () {
219
+ return typeof this.value === 'number';
220
+ };
221
+ Handle.prototype.isBigInt = function () {
222
+ return typeof this.value === 'bigint';
223
+ };
224
+ Handle.prototype.isString = function () {
225
+ return typeof this.value === 'string';
226
+ };
227
+ Handle.prototype.isFunction = function () {
228
+ return typeof this.value === 'function';
229
+ };
230
+ Handle.prototype.isExternal = function () {
231
+ return isExternal(this.value);
232
+ };
233
+ Handle.prototype.isObject = function () {
234
+ return typeof this.value === 'object' && this.value !== null;
235
+ };
236
+ Handle.prototype.isArray = function () {
237
+ return Array.isArray(this.value);
238
+ };
239
+ Handle.prototype.isArrayBuffer = function () {
240
+ return (this.value instanceof ArrayBuffer);
241
+ };
242
+ Handle.prototype.isTypedArray = function () {
243
+ return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
244
+ };
245
+ Handle.prototype.isBuffer = function (BufferConstructor) {
246
+ if (ArrayBuffer.isView(this.value))
247
+ return true;
248
+ BufferConstructor !== null && BufferConstructor !== void 0 ? BufferConstructor : (BufferConstructor = _Buffer);
249
+ return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value);
250
+ };
251
+ Handle.prototype.isDataView = function () {
252
+ return (this.value instanceof DataView);
253
+ };
254
+ Handle.prototype.isDate = function () {
255
+ return (this.value instanceof Date);
256
+ };
257
+ Handle.prototype.isPromise = function () {
258
+ return (this.value instanceof Promise);
259
+ };
260
+ Handle.prototype.isBoolean = function () {
261
+ return typeof this.value === 'boolean';
262
+ };
263
+ Handle.prototype.isUndefined = function () {
264
+ return this.value === undefined;
265
+ };
266
+ Handle.prototype.isSymbol = function () {
267
+ return typeof this.value === 'symbol';
268
+ };
269
+ Handle.prototype.isNull = function () {
270
+ return this.value === null;
271
+ };
272
+ Handle.prototype.dispose = function () {
273
+ this.value = undefined;
274
+ };
275
+ return Handle;
276
+ }());
277
+ var ConstHandle = /*#__PURE__*/ (function (_super) {
278
+ __extends(ConstHandle, _super);
279
+ function ConstHandle(id, value) {
280
+ return _super.call(this, id, value) || this;
281
+ }
282
+ ConstHandle.prototype.dispose = function () { };
283
+ return ConstHandle;
284
+ }(Handle));
285
+ var HandleStore = /*#__PURE__*/ (function () {
286
+ function HandleStore() {
287
+ this._values = [
288
+ undefined,
289
+ HandleStore.UNDEFINED,
290
+ HandleStore.NULL,
291
+ HandleStore.FALSE,
292
+ HandleStore.TRUE,
293
+ HandleStore.GLOBAL
294
+ ];
295
+ this._next = HandleStore.MIN_ID;
296
+ }
297
+ HandleStore.prototype.push = function (value) {
298
+ var h;
299
+ var next = this._next;
300
+ var values = this._values;
301
+ if (next < values.length) {
302
+ h = values[next];
303
+ h.value = value;
304
+ }
305
+ else {
306
+ h = new Handle(next, value);
307
+ values[next] = h;
308
+ }
309
+ this._next++;
310
+ return h;
311
+ };
312
+ HandleStore.prototype.erase = function (start, end) {
313
+ this._next = start;
314
+ var values = this._values;
315
+ for (var i = start; i < end; ++i) {
316
+ values[i].dispose();
317
+ }
318
+ };
319
+ HandleStore.prototype.get = function (id) {
320
+ return this._values[id];
321
+ };
322
+ HandleStore.prototype.swap = function (a, b) {
323
+ var values = this._values;
324
+ var h = values[a];
325
+ values[a] = values[b];
326
+ values[a].id = Number(a);
327
+ values[b] = h;
328
+ h.id = Number(b);
329
+ };
330
+ HandleStore.prototype.dispose = function () {
331
+ this._values.length = HandleStore.MIN_ID;
332
+ this._next = HandleStore.MIN_ID;
333
+ };
334
+ HandleStore.UNDEFINED = new ConstHandle(1 /* GlobalHandle.UNDEFINED */, undefined);
335
+ HandleStore.NULL = new ConstHandle(2 /* GlobalHandle.NULL */, null);
336
+ HandleStore.FALSE = new ConstHandle(3 /* GlobalHandle.FALSE */, false);
337
+ HandleStore.TRUE = new ConstHandle(4 /* GlobalHandle.TRUE */, true);
338
+ HandleStore.GLOBAL = new ConstHandle(5 /* GlobalHandle.GLOBAL */, _global);
339
+ HandleStore.MIN_ID = 6;
340
+ return HandleStore;
341
+ }());
342
+
343
+ var HandleScope = /*#__PURE__*/ (function () {
344
+ function HandleScope(handleStore, id, parentScope, start, end) {
345
+ if (end === void 0) { end = start; }
346
+ this.handleStore = handleStore;
347
+ this.id = id;
348
+ this.parent = parentScope;
349
+ this.child = null;
350
+ if (parentScope !== null)
351
+ parentScope.child = this;
352
+ this.start = start;
353
+ this.end = end;
354
+ this._escapeCalled = false;
355
+ this.callbackInfo = {
356
+ thiz: undefined,
357
+ data: 0,
358
+ args: undefined,
359
+ fn: undefined
360
+ };
361
+ }
362
+ HandleScope.prototype.add = function (value) {
363
+ var h = this.handleStore.push(value);
364
+ this.end++;
365
+ return h;
366
+ };
367
+ HandleScope.prototype.addExternal = function (data) {
368
+ return this.add(new External(data));
369
+ };
370
+ HandleScope.prototype.dispose = function () {
371
+ if (this._escapeCalled)
372
+ this._escapeCalled = false;
373
+ if (this.start === this.end)
374
+ return;
375
+ this.handleStore.erase(this.start, this.end);
376
+ };
377
+ HandleScope.prototype.escape = function (handle) {
378
+ if (this._escapeCalled)
379
+ return null;
380
+ this._escapeCalled = true;
381
+ if (handle < this.start || handle >= this.end) {
382
+ return null;
383
+ }
384
+ this.handleStore.swap(handle, this.start);
385
+ var h = this.handleStore.get(this.start);
386
+ this.start++;
387
+ this.parent.end++;
388
+ return h;
389
+ };
390
+ HandleScope.prototype.escapeCalled = function () {
391
+ return this._escapeCalled;
392
+ };
393
+ return HandleScope;
394
+ }());
395
+
396
+ var ScopeStore = /*#__PURE__*/ (function () {
397
+ function ScopeStore() {
398
+ this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID);
399
+ this.currentScope = this._rootScope;
400
+ this._values = [undefined];
401
+ }
402
+ ScopeStore.prototype.get = function (id) {
403
+ return this._values[id];
404
+ };
405
+ ScopeStore.prototype.openScope = function (handleStore) {
406
+ var currentScope = this.currentScope;
407
+ var scope = currentScope.child;
408
+ if (scope !== null) {
409
+ scope.start = scope.end = currentScope.end;
410
+ }
411
+ else {
412
+ var id = currentScope.id + 1;
413
+ scope = new HandleScope(handleStore, id, currentScope, currentScope.end);
414
+ this._values[id] = scope;
415
+ }
416
+ this.currentScope = scope;
417
+ return scope;
418
+ };
419
+ ScopeStore.prototype.closeScope = function () {
420
+ var scope = this.currentScope;
421
+ this.currentScope = scope.parent;
422
+ scope.dispose();
423
+ };
424
+ ScopeStore.prototype.dispose = function () {
425
+ this.currentScope = this._rootScope;
426
+ this._values.length = 1;
427
+ };
428
+ return ScopeStore;
429
+ }());
430
+
431
+ var RefTracker = /*#__PURE__*/ (function () {
432
+ function RefTracker() {
433
+ this._next = null;
434
+ this._prev = null;
435
+ }
436
+ /** @virtual */
437
+ RefTracker.prototype.dispose = function () { };
438
+ /** @virtual */
439
+ RefTracker.prototype.finalize = function () { };
440
+ RefTracker.prototype.link = function (list) {
441
+ this._prev = list;
442
+ this._next = list._next;
443
+ if (this._next !== null) {
444
+ this._next._prev = this;
445
+ }
446
+ list._next = this;
447
+ };
448
+ RefTracker.prototype.unlink = function () {
449
+ if (this._prev !== null) {
450
+ this._prev._next = this._next;
451
+ }
452
+ if (this._next !== null) {
453
+ this._next._prev = this._prev;
454
+ }
455
+ this._prev = null;
456
+ this._next = null;
457
+ };
458
+ RefTracker.finalizeAll = function (list) {
459
+ while (list._next !== null) {
460
+ list._next.finalize();
461
+ }
462
+ };
463
+ return RefTracker;
464
+ }());
465
+
466
+ var Finalizer = /*#__PURE__*/ (function () {
467
+ function Finalizer(envObject, _finalizeCallback, _finalizeData, _finalizeHint) {
468
+ if (_finalizeCallback === void 0) { _finalizeCallback = 0; }
469
+ if (_finalizeData === void 0) { _finalizeData = 0; }
470
+ if (_finalizeHint === void 0) { _finalizeHint = 0; }
471
+ this.envObject = envObject;
472
+ this._finalizeCallback = _finalizeCallback;
473
+ this._finalizeData = _finalizeData;
474
+ this._finalizeHint = _finalizeHint;
475
+ this._makeDynCall_vppp = envObject.makeDynCall_vppp;
476
+ }
477
+ Finalizer.prototype.callback = function () { return this._finalizeCallback; };
478
+ Finalizer.prototype.data = function () { return this._finalizeData; };
479
+ Finalizer.prototype.hint = function () { return this._finalizeHint; };
480
+ Finalizer.prototype.resetEnv = function () {
481
+ this.envObject = undefined;
482
+ };
483
+ Finalizer.prototype.resetFinalizer = function () {
484
+ this._finalizeCallback = 0;
485
+ this._finalizeData = 0;
486
+ this._finalizeHint = 0;
487
+ };
488
+ Finalizer.prototype.callFinalizer = function () {
489
+ var finalize_callback = this._finalizeCallback;
490
+ var finalize_data = this._finalizeData;
491
+ var finalize_hint = this._finalizeHint;
492
+ this.resetFinalizer();
493
+ if (!finalize_callback)
494
+ return;
495
+ var fini = Number(finalize_callback);
496
+ if (!this.envObject) {
497
+ this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
498
+ }
499
+ else {
500
+ this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
501
+ }
502
+ };
503
+ Finalizer.prototype.dispose = function () {
504
+ this.envObject = undefined;
505
+ this._makeDynCall_vppp = undefined;
506
+ };
507
+ return Finalizer;
508
+ }());
509
+
510
+ var TrackedFinalizer = /*#__PURE__*/ (function (_super) {
511
+ __extends(TrackedFinalizer, _super);
512
+ function TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
513
+ var _this = _super.call(this) || this;
514
+ _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
515
+ return _this;
516
+ }
517
+ TrackedFinalizer.create = function (envObject, finalize_callback, finalize_data, finalize_hint) {
518
+ var finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
519
+ finalizer.link(envObject.finalizing_reflist);
520
+ return finalizer;
521
+ };
522
+ TrackedFinalizer.prototype.data = function () {
523
+ return this._finalizer.data();
524
+ };
525
+ TrackedFinalizer.prototype.dispose = function () {
526
+ if (!this._finalizer)
527
+ return;
528
+ this.unlink();
529
+ this._finalizer.envObject.dequeueFinalizer(this);
530
+ this._finalizer.dispose();
531
+ this._finalizer = undefined;
532
+ _super.prototype.dispose.call(this);
533
+ };
534
+ TrackedFinalizer.prototype.finalize = function () {
535
+ this.unlink();
536
+ var error;
537
+ var caught = false;
538
+ try {
539
+ this._finalizer.callFinalizer();
540
+ }
541
+ catch (err) {
542
+ caught = true;
543
+ error = err;
544
+ }
545
+ this.dispose();
546
+ if (caught) {
547
+ throw error;
548
+ }
549
+ };
550
+ return TrackedFinalizer;
551
+ }(RefTracker));
552
+
553
+ function throwNodeApiVersionError(moduleName, moduleApiVersion) {
554
+ var errorMessage = "".concat(moduleName, " requires Node-API version ").concat(moduleApiVersion, ", but this version of Node.js only supports version ").concat(NODE_API_SUPPORTED_VERSION_MAX, " add-ons.");
555
+ throw new Error(errorMessage);
556
+ }
557
+ function handleThrow(envObject, value) {
558
+ if (envObject.terminatedOrTerminating()) {
559
+ return;
560
+ }
561
+ throw value;
562
+ }
563
+ var Env = /*#__PURE__*/ (function () {
564
+ function Env(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) {
565
+ this.ctx = ctx;
566
+ this.moduleApiVersion = moduleApiVersion;
567
+ this.makeDynCall_vppp = makeDynCall_vppp;
568
+ this.makeDynCall_vp = makeDynCall_vp;
569
+ this.abort = abort;
570
+ this.openHandleScopes = 0;
571
+ this.instanceData = null;
572
+ this.tryCatch = new TryCatch();
573
+ this.refs = 1;
574
+ this.reflist = new RefTracker();
575
+ this.finalizing_reflist = new RefTracker();
576
+ this.pendingFinalizers = [];
577
+ this.lastError = {
578
+ errorCode: 0 /* napi_status.napi_ok */,
579
+ engineErrorCode: 0,
580
+ engineReserved: 0
581
+ };
582
+ this.inGcFinalizer = false;
583
+ this._bindingMap = new WeakMap();
584
+ this.id = 0;
585
+ }
586
+ /** @virtual */
587
+ Env.prototype.canCallIntoJs = function () {
588
+ return true;
589
+ };
590
+ Env.prototype.terminatedOrTerminating = function () {
591
+ return !this.canCallIntoJs();
592
+ };
593
+ Env.prototype.ref = function () {
594
+ this.refs++;
595
+ };
596
+ Env.prototype.unref = function () {
597
+ this.refs--;
598
+ if (this.refs === 0) {
599
+ this.dispose();
600
+ }
601
+ };
602
+ Env.prototype.ensureHandle = function (value) {
603
+ return this.ctx.ensureHandle(value);
604
+ };
605
+ Env.prototype.ensureHandleId = function (value) {
606
+ return this.ensureHandle(value).id;
607
+ };
608
+ Env.prototype.clearLastError = function () {
609
+ var lastError = this.lastError;
610
+ if (lastError.errorCode !== 0 /* napi_status.napi_ok */)
611
+ lastError.errorCode = 0 /* napi_status.napi_ok */;
612
+ if (lastError.engineErrorCode !== 0)
613
+ lastError.engineErrorCode = 0;
614
+ if (lastError.engineReserved !== 0)
615
+ lastError.engineReserved = 0;
616
+ return 0 /* napi_status.napi_ok */;
617
+ };
618
+ Env.prototype.setLastError = function (error_code, engine_error_code, engine_reserved) {
619
+ if (engine_error_code === void 0) { engine_error_code = 0; }
620
+ if (engine_reserved === void 0) { engine_reserved = 0; }
621
+ var lastError = this.lastError;
622
+ if (lastError.errorCode !== error_code)
623
+ lastError.errorCode = error_code;
624
+ if (lastError.engineErrorCode !== engine_error_code)
625
+ lastError.engineErrorCode = engine_error_code;
626
+ if (lastError.engineReserved !== engine_reserved)
627
+ lastError.engineReserved = engine_reserved;
628
+ return error_code;
629
+ };
630
+ Env.prototype.getReturnStatus = function () {
631
+ return !this.tryCatch.hasCaught() ? 0 /* napi_status.napi_ok */ : this.setLastError(10 /* napi_status.napi_pending_exception */);
632
+ };
633
+ Env.prototype.callIntoModule = function (fn, handleException) {
634
+ if (handleException === void 0) { handleException = handleThrow; }
635
+ var openHandleScopesBefore = this.openHandleScopes;
636
+ this.clearLastError();
637
+ var r = fn(this);
638
+ if (openHandleScopesBefore !== this.openHandleScopes) {
639
+ this.abort('open_handle_scopes != open_handle_scopes_before');
640
+ }
641
+ if (this.tryCatch.hasCaught()) {
642
+ var err = this.tryCatch.extractException();
643
+ handleException(this, err);
644
+ }
645
+ return r;
646
+ };
647
+ Env.prototype.invokeFinalizerFromGC = function (finalizer) {
648
+ if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
649
+ this.enqueueFinalizer(finalizer);
650
+ }
651
+ else {
652
+ var saved = this.inGcFinalizer;
653
+ this.inGcFinalizer = true;
654
+ try {
655
+ finalizer.finalize();
656
+ }
657
+ finally {
658
+ this.inGcFinalizer = saved;
659
+ }
660
+ }
661
+ };
662
+ Env.prototype.checkGCAccess = function () {
663
+ if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) {
664
+ this.abort('Finalizer is calling a function that may affect GC state.\n' +
665
+ 'The finalizers are run directly from GC and must not affect GC ' +
666
+ 'state.\n' +
667
+ 'Use `node_api_post_finalizer` from inside of the finalizer to work ' +
668
+ 'around this issue.\n' +
669
+ 'It schedules the call as a new task in the event loop.');
670
+ }
671
+ };
672
+ /** @virtual */
673
+ Env.prototype.enqueueFinalizer = function (finalizer) {
674
+ if (this.pendingFinalizers.indexOf(finalizer) === -1) {
675
+ this.pendingFinalizers.push(finalizer);
676
+ }
677
+ };
678
+ /** @virtual */
679
+ Env.prototype.dequeueFinalizer = function (finalizer) {
680
+ var index = this.pendingFinalizers.indexOf(finalizer);
681
+ if (index !== -1) {
682
+ this.pendingFinalizers.splice(index, 1);
683
+ }
684
+ };
685
+ /** @virtual */
686
+ Env.prototype.deleteMe = function () {
687
+ RefTracker.finalizeAll(this.finalizing_reflist);
688
+ RefTracker.finalizeAll(this.reflist);
689
+ this.tryCatch.extractException();
690
+ this.ctx.envStore.remove(this.id);
691
+ };
692
+ Env.prototype.dispose = function () {
693
+ if (this.id === 0)
694
+ return;
695
+ this.deleteMe();
696
+ this.finalizing_reflist.dispose();
697
+ this.reflist.dispose();
698
+ this.id = 0;
699
+ };
700
+ Env.prototype.initObjectBinding = function (value) {
701
+ var binding = {
702
+ wrapped: 0,
703
+ tag: null
704
+ };
705
+ this._bindingMap.set(value, binding);
706
+ return binding;
707
+ };
708
+ Env.prototype.getObjectBinding = function (value) {
709
+ if (this._bindingMap.has(value)) {
710
+ return this._bindingMap.get(value);
711
+ }
712
+ return this.initObjectBinding(value);
713
+ };
714
+ Env.prototype.setInstanceData = function (data, finalize_cb, finalize_hint) {
715
+ if (this.instanceData) {
716
+ this.instanceData.dispose();
717
+ }
718
+ this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
719
+ };
720
+ Env.prototype.getInstanceData = function () {
721
+ return this.instanceData ? this.instanceData.data() : 0;
722
+ };
723
+ return Env;
724
+ }());
725
+ var NodeEnv = /*#__PURE__*/ (function (_super) {
726
+ __extends(NodeEnv, _super);
727
+ function NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
728
+ var _this = _super.call(this, ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) || this;
729
+ _this.filename = filename;
730
+ _this.nodeBinding = nodeBinding;
731
+ _this.destructing = false;
732
+ _this.finalizationScheduled = false;
733
+ return _this;
734
+ }
735
+ NodeEnv.prototype.deleteMe = function () {
736
+ this.destructing = true;
737
+ this.drainFinalizerQueue();
738
+ _super.prototype.deleteMe.call(this);
739
+ };
740
+ NodeEnv.prototype.canCallIntoJs = function () {
741
+ return _super.prototype.canCallIntoJs.call(this) && this.ctx.canCallIntoJs();
742
+ };
743
+ NodeEnv.prototype.triggerFatalException = function (err) {
744
+ if (this.nodeBinding) {
745
+ this.nodeBinding.napi.fatalException(err);
746
+ }
747
+ else {
748
+ if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') {
749
+ var handled = process._fatalException(err);
750
+ if (!handled) {
751
+ console.error(err);
752
+ process.exit(1);
753
+ }
754
+ }
755
+ else {
756
+ throw err;
757
+ }
758
+ }
759
+ };
760
+ NodeEnv.prototype.callbackIntoModule = function (enforceUncaughtExceptionPolicy, fn) {
761
+ return this.callIntoModule(fn, function (envObject, err) {
762
+ if (envObject.terminatedOrTerminating()) {
763
+ return;
764
+ }
765
+ var hasProcess = typeof process === 'object' && process !== null;
766
+ var hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
767
+ if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
768
+ var warn = hasProcess && typeof process.emitWarning === 'function'
769
+ ? process.emitWarning
770
+ : function (warning, type, code) {
771
+ if (warning instanceof Error) {
772
+ console.warn(warning.toString());
773
+ }
774
+ else {
775
+ var prefix = code ? "[".concat(code, "] ") : '';
776
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
777
+ console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
778
+ }
779
+ };
780
+ warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
781
+ return;
782
+ }
783
+ envObject.triggerFatalException(err);
784
+ });
785
+ };
786
+ NodeEnv.prototype.callFinalizer = function (cb, data, hint) {
787
+ this.callFinalizerInternal(1, cb, data, hint);
788
+ };
789
+ NodeEnv.prototype.callFinalizerInternal = function (forceUncaught, cb, data, hint) {
790
+ var f = this.makeDynCall_vppp(cb);
791
+ var env = this.id;
792
+ var scope = this.ctx.openScope(this);
793
+ try {
794
+ this.callbackIntoModule(Boolean(forceUncaught), function () { f(env, data, hint); });
795
+ }
796
+ finally {
797
+ this.ctx.closeScope(this, scope);
798
+ }
799
+ };
800
+ NodeEnv.prototype.enqueueFinalizer = function (finalizer) {
801
+ var _this = this;
802
+ _super.prototype.enqueueFinalizer.call(this, finalizer);
803
+ if (!this.finalizationScheduled && !this.destructing) {
804
+ this.finalizationScheduled = true;
805
+ this.ref();
806
+ _setImmediate(function () {
807
+ _this.finalizationScheduled = false;
808
+ _this.unref();
809
+ _this.drainFinalizerQueue();
810
+ });
811
+ }
812
+ };
813
+ NodeEnv.prototype.drainFinalizerQueue = function () {
814
+ while (this.pendingFinalizers.length > 0) {
815
+ var refTracker = this.pendingFinalizers.shift();
816
+ refTracker.finalize();
817
+ }
818
+ };
819
+ return NodeEnv;
820
+ }(Env));
821
+ function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
822
+ moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion;
823
+ // Validate module_api_version.
824
+ if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
825
+ moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
826
+ }
827
+ else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
828
+ throwNodeApiVersionError(filename, moduleApiVersion);
829
+ }
830
+ var env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
831
+ ctx.envStore.add(env);
832
+ ctx.addCleanupHook(env, function () { env.unref(); }, 0);
833
+ return env;
834
+ }
835
+
836
+ var EmnapiError = /*#__PURE__*/ (function (_super) {
837
+ __extends(EmnapiError, _super);
838
+ function EmnapiError(message) {
839
+ var _newTarget = this.constructor;
840
+ var _this = _super.call(this, message) || this;
841
+ var ErrorConstructor = _newTarget;
842
+ var proto = ErrorConstructor.prototype;
843
+ if (!(_this instanceof EmnapiError)) {
844
+ var setPrototypeOf = Object.setPrototypeOf;
845
+ if (typeof setPrototypeOf === 'function') {
846
+ setPrototypeOf.call(Object, _this, proto);
847
+ }
848
+ else {
849
+ // eslint-disable-next-line no-proto
850
+ _this.__proto__ = proto;
851
+ }
852
+ if (typeof Error.captureStackTrace === 'function') {
853
+ Error.captureStackTrace(_this, ErrorConstructor);
854
+ }
855
+ }
856
+ return _this;
857
+ }
858
+ return EmnapiError;
859
+ }(Error));
860
+ Object.defineProperty(EmnapiError.prototype, 'name', {
861
+ configurable: true,
862
+ writable: true,
863
+ value: 'EmnapiError'
864
+ });
865
+ var NotSupportWeakRefError = /*#__PURE__*/ (function (_super) {
866
+ __extends(NotSupportWeakRefError, _super);
867
+ function NotSupportWeakRefError(api, message) {
868
+ return _super.call(this, "".concat(api, ": The current runtime does not support \"FinalizationRegistry\" and \"WeakRef\".").concat(message ? " ".concat(message) : '')) || this;
869
+ }
870
+ return NotSupportWeakRefError;
871
+ }(EmnapiError));
872
+ Object.defineProperty(NotSupportWeakRefError.prototype, 'name', {
873
+ configurable: true,
874
+ writable: true,
875
+ value: 'NotSupportWeakRefError'
876
+ });
877
+ var NotSupportBufferError = /*#__PURE__*/ (function (_super) {
878
+ __extends(NotSupportBufferError, _super);
879
+ function NotSupportBufferError(api, message) {
880
+ 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;
881
+ }
882
+ return NotSupportBufferError;
883
+ }(EmnapiError));
884
+ Object.defineProperty(NotSupportBufferError.prototype, 'name', {
885
+ configurable: true,
886
+ writable: true,
887
+ value: 'NotSupportBufferError'
888
+ });
889
+
890
+ var StrongRef = /*#__PURE__*/ (function () {
891
+ function StrongRef(value) {
892
+ this._value = value;
893
+ }
894
+ StrongRef.prototype.deref = function () {
895
+ return this._value;
896
+ };
897
+ StrongRef.prototype.dispose = function () {
898
+ this._value = undefined;
899
+ };
900
+ return StrongRef;
901
+ }());
902
+ var Persistent = /*#__PURE__*/ (function () {
903
+ function Persistent(value) {
904
+ this._ref = new StrongRef(value);
905
+ }
906
+ Persistent.prototype.setWeak = function (param, callback) {
907
+ if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef)
908
+ return;
909
+ var value = this._ref.deref();
910
+ try {
911
+ Persistent._registry.register(value, this, this);
912
+ var weakRef = new WeakRef(value);
913
+ this._ref.dispose();
914
+ this._ref = weakRef;
915
+ this._param = param;
916
+ this._callback = callback;
917
+ }
918
+ catch (err) {
919
+ if (typeof value === 'symbol') ;
920
+ else {
921
+ throw err;
922
+ }
923
+ }
924
+ };
925
+ Persistent.prototype.clearWeak = function () {
926
+ if (!supportFinalizer || this._ref === undefined)
927
+ return;
928
+ if (this._ref instanceof WeakRef) {
929
+ try {
930
+ Persistent._registry.unregister(this);
931
+ }
932
+ catch (_) { }
933
+ this._param = undefined;
934
+ this._callback = undefined;
935
+ var value = this._ref.deref();
936
+ if (value === undefined) {
937
+ this._ref = value;
938
+ }
939
+ else {
940
+ this._ref = new StrongRef(value);
941
+ }
942
+ }
943
+ };
944
+ Persistent.prototype.reset = function () {
945
+ if (supportFinalizer) {
946
+ try {
947
+ Persistent._registry.unregister(this);
948
+ }
949
+ catch (_) { }
950
+ }
951
+ this._param = undefined;
952
+ this._callback = undefined;
953
+ if (this._ref instanceof StrongRef) {
954
+ this._ref.dispose();
955
+ }
956
+ this._ref = undefined;
957
+ };
958
+ Persistent.prototype.isEmpty = function () {
959
+ return this._ref === undefined;
960
+ };
961
+ Persistent.prototype.deref = function () {
962
+ if (this._ref === undefined)
963
+ return undefined;
964
+ return this._ref.deref();
965
+ };
966
+ Persistent._registry = supportFinalizer
967
+ ? new FinalizationRegistry(function (value) {
968
+ value._ref = undefined;
969
+ var callback = value._callback;
970
+ var param = value._param;
971
+ value._callback = undefined;
972
+ value._param = undefined;
973
+ if (typeof callback === 'function') {
974
+ callback(param);
975
+ }
976
+ })
977
+ : undefined;
978
+ return Persistent;
979
+ }());
980
+
981
+ exports.ReferenceOwnership = void 0;
982
+ (function (ReferenceOwnership) {
983
+ ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
984
+ ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
985
+ })(exports.ReferenceOwnership || (exports.ReferenceOwnership = {}));
986
+ function canBeHeldWeakly(value) {
987
+ return value.isObject() || value.isFunction() || value.isSymbol();
988
+ }
989
+ var Reference = /*#__PURE__*/ (function (_super) {
990
+ __extends(Reference, _super);
991
+ function Reference(envObject, handle_id, initialRefcount, ownership) {
992
+ var _this = _super.call(this) || this;
993
+ _this.envObject = envObject;
994
+ _this._refcount = initialRefcount;
995
+ _this._ownership = ownership;
996
+ var handle = envObject.ctx.handleStore.get(handle_id);
997
+ _this.canBeWeak = canBeHeldWeakly(handle);
998
+ _this.persistent = new Persistent(handle.value);
999
+ _this.id = 0;
1000
+ if (initialRefcount === 0) {
1001
+ _this._setWeak();
1002
+ }
1003
+ return _this;
1004
+ }
1005
+ Reference.weakCallback = function (ref) {
1006
+ ref.persistent.reset();
1007
+ ref.invokeFinalizerFromGC();
1008
+ };
1009
+ Reference.create = function (envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
1010
+ var ref = new Reference(envObject, handle_id, initialRefcount, ownership);
1011
+ envObject.ctx.refStore.add(ref);
1012
+ ref.link(envObject.reflist);
1013
+ return ref;
1014
+ };
1015
+ Reference.prototype.ref = function () {
1016
+ if (this.persistent.isEmpty()) {
1017
+ return 0;
1018
+ }
1019
+ if (++this._refcount === 1 && this.canBeWeak) {
1020
+ this.persistent.clearWeak();
1021
+ }
1022
+ return this._refcount;
1023
+ };
1024
+ Reference.prototype.unref = function () {
1025
+ if (this.persistent.isEmpty() || this._refcount === 0) {
1026
+ return 0;
1027
+ }
1028
+ if (--this._refcount === 0) {
1029
+ this._setWeak();
1030
+ }
1031
+ return this._refcount;
1032
+ };
1033
+ Reference.prototype.get = function (envObject) {
1034
+ if (envObject === void 0) { envObject = this.envObject; }
1035
+ if (this.persistent.isEmpty()) {
1036
+ return 0;
1037
+ }
1038
+ var obj = this.persistent.deref();
1039
+ var handle = envObject.ensureHandle(obj);
1040
+ return handle.id;
1041
+ };
1042
+ /** @virtual */
1043
+ Reference.prototype.resetFinalizer = function () { };
1044
+ /** @virtual */
1045
+ Reference.prototype.data = function () { return 0; };
1046
+ Reference.prototype.refcount = function () { return this._refcount; };
1047
+ Reference.prototype.ownership = function () { return this._ownership; };
1048
+ /** @virtual */
1049
+ Reference.prototype.callUserFinalizer = function () { };
1050
+ /** @virtual */
1051
+ Reference.prototype.invokeFinalizerFromGC = function () {
1052
+ this.finalize();
1053
+ };
1054
+ Reference.prototype._setWeak = function () {
1055
+ if (this.canBeWeak) {
1056
+ this.persistent.setWeak(this, Reference.weakCallback);
1057
+ }
1058
+ else {
1059
+ this.persistent.reset();
1060
+ }
1061
+ };
1062
+ Reference.prototype.finalize = function () {
1063
+ this.persistent.reset();
1064
+ var deleteMe = this._ownership === exports.ReferenceOwnership.kRuntime;
1065
+ this.unlink();
1066
+ this.callUserFinalizer();
1067
+ if (deleteMe) {
1068
+ this.dispose();
1069
+ }
1070
+ };
1071
+ Reference.prototype.dispose = function () {
1072
+ if (this.id === 0)
1073
+ return;
1074
+ this.unlink();
1075
+ this.persistent.reset();
1076
+ this.envObject.ctx.refStore.remove(this.id);
1077
+ _super.prototype.dispose.call(this);
1078
+ this.envObject = undefined;
1079
+ this.id = 0;
1080
+ };
1081
+ return Reference;
1082
+ }(RefTracker));
1083
+ var ReferenceWithData = /*#__PURE__*/ (function (_super) {
1084
+ __extends(ReferenceWithData, _super);
1085
+ function ReferenceWithData(envObject, value, initialRefcount, ownership, _data) {
1086
+ var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
1087
+ _this._data = _data;
1088
+ return _this;
1089
+ }
1090
+ ReferenceWithData.create = function (envObject, value, initialRefcount, ownership, data) {
1091
+ var reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
1092
+ envObject.ctx.refStore.add(reference);
1093
+ reference.link(envObject.reflist);
1094
+ return reference;
1095
+ };
1096
+ ReferenceWithData.prototype.data = function () {
1097
+ return this._data;
1098
+ };
1099
+ return ReferenceWithData;
1100
+ }(Reference));
1101
+ var ReferenceWithFinalizer = /*#__PURE__*/ (function (_super) {
1102
+ __extends(ReferenceWithFinalizer, _super);
1103
+ function ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1104
+ var _this = _super.call(this, envObject, value, initialRefcount, ownership) || this;
1105
+ _this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
1106
+ return _this;
1107
+ }
1108
+ ReferenceWithFinalizer.create = function (envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1109
+ var reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1110
+ envObject.ctx.refStore.add(reference);
1111
+ reference.link(envObject.finalizing_reflist);
1112
+ return reference;
1113
+ };
1114
+ ReferenceWithFinalizer.prototype.resetFinalizer = function () {
1115
+ this._finalizer.resetFinalizer();
1116
+ };
1117
+ ReferenceWithFinalizer.prototype.data = function () {
1118
+ return this._finalizer.data();
1119
+ };
1120
+ ReferenceWithFinalizer.prototype.callUserFinalizer = function () {
1121
+ this._finalizer.callFinalizer();
1122
+ };
1123
+ ReferenceWithFinalizer.prototype.invokeFinalizerFromGC = function () {
1124
+ this._finalizer.envObject.invokeFinalizerFromGC(this);
1125
+ };
1126
+ ReferenceWithFinalizer.prototype.dispose = function () {
1127
+ if (!this._finalizer)
1128
+ return;
1129
+ this._finalizer.envObject.dequeueFinalizer(this);
1130
+ this._finalizer.dispose();
1131
+ _super.prototype.dispose.call(this);
1132
+ this._finalizer = undefined;
1133
+ };
1134
+ return ReferenceWithFinalizer;
1135
+ }(Reference));
1136
+
1137
+ var Deferred = /*#__PURE__*/ (function () {
1138
+ function Deferred(ctx, value) {
1139
+ // Plain assignment would invoke inherited setters before these fields
1140
+ // become own properties.
1141
+ Object.defineProperties(this, {
1142
+ id: {
1143
+ configurable: true,
1144
+ enumerable: true,
1145
+ value: 0,
1146
+ writable: true
1147
+ },
1148
+ ctx: {
1149
+ configurable: true,
1150
+ enumerable: true,
1151
+ value: ctx,
1152
+ writable: true
1153
+ },
1154
+ value: {
1155
+ configurable: true,
1156
+ enumerable: true,
1157
+ value: value,
1158
+ writable: true
1159
+ }
1160
+ });
1161
+ }
1162
+ Deferred.create = function (ctx, value) {
1163
+ var deferred = new Deferred(ctx, value);
1164
+ ctx.deferredStore.add(deferred);
1165
+ return deferred;
1166
+ };
1167
+ Deferred.prototype.resolve = function (value) {
1168
+ this.value.resolve(value);
1169
+ this.dispose();
1170
+ };
1171
+ Deferred.prototype.reject = function (reason) {
1172
+ this.value.reject(reason);
1173
+ this.dispose();
1174
+ };
1175
+ Deferred.prototype.dispose = function () {
1176
+ this.ctx.deferredStore.remove(this.id);
1177
+ this.id = 0;
1178
+ this.value = null;
1179
+ this.ctx = null;
1180
+ };
1181
+ return Deferred;
1182
+ }());
1183
+
1184
+ var Store = /*#__PURE__*/ (function () {
1185
+ function Store() {
1186
+ this._values = [undefined];
1187
+ this._values.length = 4;
1188
+ this._size = 1;
1189
+ this._freeList = [];
1190
+ }
1191
+ Store.prototype.add = function (value) {
1192
+ var id;
1193
+ if (this._freeList.length) {
1194
+ id = this._freeList.shift();
1195
+ }
1196
+ else {
1197
+ id = this._size;
1198
+ this._size++;
1199
+ var capacity = this._values.length;
1200
+ if (id >= capacity) {
1201
+ this._values.length = capacity + (capacity >> 1) + 16;
1202
+ }
1203
+ }
1204
+ value.id = id;
1205
+ this._values[id] = value;
1206
+ };
1207
+ Store.prototype.get = function (id) {
1208
+ return this._values[id];
1209
+ };
1210
+ Store.prototype.has = function (id) {
1211
+ return this._values[id] !== undefined;
1212
+ };
1213
+ Store.prototype.remove = function (id) {
1214
+ var value = this._values[id];
1215
+ if (value) {
1216
+ value.id = 0;
1217
+ this._values[id] = undefined;
1218
+ this._freeList.push(Number(id));
1219
+ }
1220
+ };
1221
+ Store.prototype.dispose = function () {
1222
+ for (var i = 1; i < this._size; ++i) {
1223
+ var value = this._values[i];
1224
+ value === null || value === void 0 ? void 0 : value.dispose();
1225
+ }
1226
+ this._values = [undefined];
1227
+ this._size = 1;
1228
+ this._freeList = [];
1229
+ };
1230
+ return Store;
1231
+ }());
1232
+
1233
+ var kMaxReasonableBytes = BigInt(1) << BigInt(60);
1234
+ var kMinReasonableBytes = -kMaxReasonableBytes;
1235
+ var ExternalMemory = /*#__PURE__*/ (function () {
1236
+ function ExternalMemory(onChange) {
1237
+ this.total = BigInt(0);
1238
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
1239
+ }
1240
+ ExternalMemory.prototype.adjust = function (changeInBytes) {
1241
+ changeInBytes = BigInt(changeInBytes);
1242
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
1243
+ throw new RangeError("changeInBytes ".concat(changeInBytes, " is out of reasonable range"));
1244
+ }
1245
+ var old = this.total;
1246
+ this.total += changeInBytes;
1247
+ var amount = this.total;
1248
+ var onChange = this.onChange;
1249
+ if (changeInBytes) {
1250
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
1251
+ }
1252
+ return amount;
1253
+ };
1254
+ return ExternalMemory;
1255
+ }());
1256
+
1257
+ var CleanupHookCallback = /*#__PURE__*/ (function () {
1258
+ function CleanupHookCallback(envObject, fn, arg, order) {
1259
+ this.envObject = envObject;
1260
+ this.fn = fn;
1261
+ this.arg = arg;
1262
+ this.order = order;
1263
+ }
1264
+ return CleanupHookCallback;
1265
+ }());
1266
+ var CleanupQueue = /*#__PURE__*/ (function () {
1267
+ function CleanupQueue() {
1268
+ this._cleanupHooks = [];
1269
+ this._cleanupHookCounter = 0;
1270
+ }
1271
+ CleanupQueue.prototype.empty = function () {
1272
+ return this._cleanupHooks.length === 0;
1273
+ };
1274
+ CleanupQueue.prototype.add = function (envObject, fn, arg) {
1275
+ if (this._cleanupHooks.filter(function (hook) { return (hook.envObject === envObject && hook.fn === fn && hook.arg === arg); }).length > 0) {
1276
+ throw new Error('Can not add same fn and arg twice');
1277
+ }
1278
+ this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++));
1279
+ };
1280
+ CleanupQueue.prototype.remove = function (envObject, fn, arg) {
1281
+ for (var i = 0; i < this._cleanupHooks.length; ++i) {
1282
+ var hook = this._cleanupHooks[i];
1283
+ if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) {
1284
+ this._cleanupHooks.splice(i, 1);
1285
+ return;
1286
+ }
1287
+ }
1288
+ };
1289
+ CleanupQueue.prototype.drain = function () {
1290
+ var hooks = this._cleanupHooks.slice();
1291
+ hooks.sort(function (a, b) { return (b.order - a.order); });
1292
+ for (var i = 0; i < hooks.length; ++i) {
1293
+ var cb = hooks[i];
1294
+ if (typeof cb.fn === 'number') {
1295
+ cb.envObject.makeDynCall_vp(cb.fn)(cb.arg);
1296
+ }
1297
+ else {
1298
+ cb.fn(cb.arg);
1299
+ }
1300
+ this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1);
1301
+ }
1302
+ };
1303
+ CleanupQueue.prototype.dispose = function () {
1304
+ this._cleanupHooks.length = 0;
1305
+ this._cleanupHookCounter = 0;
1306
+ };
1307
+ return CleanupQueue;
1308
+ }());
1309
+ var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () {
1310
+ function NodejsWaitingRequestCounter() {
1311
+ this.refHandle = new _MessageChannel().port1;
1312
+ this.count = 0;
1313
+ }
1314
+ NodejsWaitingRequestCounter.prototype.increase = function () {
1315
+ if (this.count === 0) {
1316
+ if (this.refHandle.ref) {
1317
+ this.refHandle.ref();
1318
+ }
1319
+ }
1320
+ this.count++;
1321
+ };
1322
+ NodejsWaitingRequestCounter.prototype.decrease = function () {
1323
+ if (this.count === 0)
1324
+ return;
1325
+ if (this.count === 1) {
1326
+ if (this.refHandle.unref) {
1327
+ this.refHandle.unref();
1328
+ }
1329
+ }
1330
+ this.count--;
1331
+ };
1332
+ return NodejsWaitingRequestCounter;
1333
+ }());
1334
+ var Context = /*#__PURE__*/ (function () {
1335
+ function Context(options) {
1336
+ var _this = this;
1337
+ this._isStopping = false;
1338
+ this._canCallIntoJs = true;
1339
+ this._suppressDestroy = false;
1340
+ this.envStore = new Store();
1341
+ this.scopeStore = new ScopeStore();
1342
+ this.refStore = new Store();
1343
+ this.deferredStore = new Store();
1344
+ this.handleStore = new HandleStore();
1345
+ this.feature = {
1346
+ supportReflect: supportReflect,
1347
+ supportFinalizer: supportFinalizer,
1348
+ supportWeakSymbol: supportWeakSymbol,
1349
+ supportBigInt: supportBigInt,
1350
+ supportNewFunction: supportNewFunction,
1351
+ canSetFunctionName: canSetFunctionName,
1352
+ setImmediate: _setImmediate,
1353
+ Buffer: _Buffer,
1354
+ MessageChannel: _MessageChannel
1355
+ };
1356
+ this.cleanupQueue = new CleanupQueue();
1357
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
1358
+ if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1359
+ this.refCounter = new NodejsWaitingRequestCounter();
1360
+ process.once('beforeExit', function () {
1361
+ if (!_this._suppressDestroy) {
1362
+ _this.destroy();
1363
+ }
1364
+ });
1365
+ }
1366
+ }
1367
+ /**
1368
+ * Suppress the destroy on `beforeExit` event in Node.js.
1369
+ * Call this method if you want to keep the context and
1370
+ * all associated {@link Env | Env} alive,
1371
+ * this also means that cleanup hooks will not be called.
1372
+ * After call this method, you should call
1373
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
1374
+ */
1375
+ Context.prototype.suppressDestroy = function () {
1376
+ this._suppressDestroy = true;
1377
+ };
1378
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
1379
+ Context.prototype.getRuntimeVersions = function () {
1380
+ return {
1381
+ version: version,
1382
+ NODE_API_SUPPORTED_VERSION_MAX: NODE_API_SUPPORTED_VERSION_MAX,
1383
+ NAPI_VERSION_EXPERIMENTAL: NAPI_VERSION_EXPERIMENTAL,
1384
+ NODE_API_DEFAULT_MODULE_API_VERSION: NODE_API_DEFAULT_MODULE_API_VERSION
1385
+ };
1386
+ };
1387
+ Context.prototype.createNotSupportWeakRefError = function (api, message) {
1388
+ return new NotSupportWeakRefError(api, message);
1389
+ };
1390
+ Context.prototype.createNotSupportBufferError = function (api, message) {
1391
+ return new NotSupportBufferError(api, message);
1392
+ };
1393
+ Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership) {
1394
+ return Reference.create(envObject, handle_id, initialRefcount, ownership);
1395
+ };
1396
+ Context.prototype.createReferenceWithData = function (envObject, handle_id, initialRefcount, ownership, data) {
1397
+ return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
1398
+ };
1399
+ Context.prototype.createReferenceWithFinalizer = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1400
+ if (finalize_callback === void 0) { finalize_callback = 0; }
1401
+ if (finalize_data === void 0) { finalize_data = 0; }
1402
+ if (finalize_hint === void 0) { finalize_hint = 0; }
1403
+ return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1404
+ };
1405
+ Context.prototype.createDeferred = function (value) {
1406
+ return Deferred.create(this, value);
1407
+ };
1408
+ Context.prototype.adjustAmountOfExternalAllocatedMemory = function (changeInBytes) {
1409
+ return this._externalMemory.adjust(changeInBytes);
1410
+ };
1411
+ Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1412
+ return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1413
+ };
1414
+ Context.prototype.createTrackedFinalizer = function (envObject, finalize_callback, finalize_data, finalize_hint) {
1415
+ return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint);
1416
+ };
1417
+ Context.prototype.getCurrentScope = function () {
1418
+ return this.scopeStore.currentScope;
1419
+ };
1420
+ Context.prototype.addToCurrentScope = function (value) {
1421
+ return this.scopeStore.currentScope.add(value);
1422
+ };
1423
+ Context.prototype.openScope = function (envObject) {
1424
+ var scope = this.scopeStore.openScope(this.handleStore);
1425
+ if (envObject)
1426
+ envObject.openHandleScopes++;
1427
+ return scope;
1428
+ };
1429
+ Context.prototype.closeScope = function (envObject, _scope) {
1430
+ if (envObject && envObject.openHandleScopes === 0)
1431
+ return;
1432
+ this.scopeStore.closeScope();
1433
+ if (envObject)
1434
+ envObject.openHandleScopes--;
1435
+ };
1436
+ Context.prototype.ensureHandle = function (value) {
1437
+ switch (value) {
1438
+ case undefined: return HandleStore.UNDEFINED;
1439
+ case null: return HandleStore.NULL;
1440
+ case true: return HandleStore.TRUE;
1441
+ case false: return HandleStore.FALSE;
1442
+ case _global: return HandleStore.GLOBAL;
1443
+ }
1444
+ return this.addToCurrentScope(value);
1445
+ };
1446
+ Context.prototype.addCleanupHook = function (envObject, fn, arg) {
1447
+ this.cleanupQueue.add(envObject, fn, arg);
1448
+ };
1449
+ Context.prototype.removeCleanupHook = function (envObject, fn, arg) {
1450
+ this.cleanupQueue.remove(envObject, fn, arg);
1451
+ };
1452
+ Context.prototype.runCleanup = function () {
1453
+ while (!this.cleanupQueue.empty()) {
1454
+ this.cleanupQueue.drain();
1455
+ }
1456
+ };
1457
+ Context.prototype.increaseWaitingRequestCounter = function () {
1458
+ var _a;
1459
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase();
1460
+ };
1461
+ Context.prototype.decreaseWaitingRequestCounter = function () {
1462
+ var _a;
1463
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease();
1464
+ };
1465
+ Context.prototype.setCanCallIntoJs = function (value) {
1466
+ this._canCallIntoJs = value;
1467
+ };
1468
+ Context.prototype.setStopping = function (value) {
1469
+ this._isStopping = value;
1470
+ };
1471
+ Context.prototype.canCallIntoJs = function () {
1472
+ return this._canCallIntoJs && !this._isStopping;
1473
+ };
1474
+ /**
1475
+ * Destroy the context and call cleanup hooks.
1476
+ * Associated {@link Env | Env} will be destroyed.
1477
+ */
1478
+ Context.prototype.destroy = function () {
1479
+ this.setStopping(true);
1480
+ this.setCanCallIntoJs(false);
1481
+ this.runCleanup();
1482
+ };
1483
+ return Context;
1484
+ }());
1485
+ var defaultContext;
1486
+ function createContext(options) {
1487
+ return new Context(options);
1488
+ }
1489
+ function getDefaultContext() {
1490
+ if (!defaultContext) {
1491
+ defaultContext = createContext();
1492
+ }
1493
+ return defaultContext;
1494
+ }
1495
+
1496
+ exports.ConstHandle = ConstHandle;
1497
+ exports.Context = Context;
1498
+ exports.Deferred = Deferred;
1499
+ exports.EmnapiError = EmnapiError;
1500
+ exports.Env = Env;
1501
+ exports.External = External;
1502
+ exports.Finalizer = Finalizer;
1503
+ exports.Handle = Handle;
1504
+ exports.HandleScope = HandleScope;
1505
+ exports.HandleStore = HandleStore;
1506
+ exports.NAPI_VERSION_EXPERIMENTAL = NAPI_VERSION_EXPERIMENTAL;
1507
+ exports.NODE_API_DEFAULT_MODULE_API_VERSION = NODE_API_DEFAULT_MODULE_API_VERSION;
1508
+ exports.NODE_API_SUPPORTED_VERSION_MAX = NODE_API_SUPPORTED_VERSION_MAX;
1509
+ exports.NODE_API_SUPPORTED_VERSION_MIN = NODE_API_SUPPORTED_VERSION_MIN;
1510
+ exports.NodeEnv = NodeEnv;
1511
+ exports.NotSupportBufferError = NotSupportBufferError;
1512
+ exports.NotSupportWeakRefError = NotSupportWeakRefError;
1513
+ exports.Persistent = Persistent;
1514
+ exports.RefTracker = RefTracker;
1515
+ exports.Reference = Reference;
1516
+ exports.ReferenceWithData = ReferenceWithData;
1517
+ exports.ReferenceWithFinalizer = ReferenceWithFinalizer;
1518
+ exports.ScopeStore = ScopeStore;
1519
+ exports.Store = Store;
1520
+ exports.TrackedFinalizer = TrackedFinalizer;
1521
+ exports.TryCatch = TryCatch;
1522
+ exports.createContext = createContext;
1523
+ exports.getDefaultContext = getDefaultContext;
1524
+ exports.getExternalValue = getExternalValue;
1525
+ exports.isExternal = isExternal;
1526
+ exports.isReferenceType = isReferenceType;
1527
+ exports.version = version;
1528
+
1529
+ }));
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts ADDED
@@ -0,0 +1,671 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export declare type Ptr = number | bigint
2
+
3
+ export declare interface IBuffer extends Uint8Array {}
4
+ export declare interface BufferCtor {
5
+ readonly prototype: IBuffer
6
+ /** @deprecated */
7
+ new (...args: any[]): IBuffer
8
+ from: {
9
+ (buffer: ArrayBufferLike): IBuffer
10
+ (buffer: ArrayBufferLike, byteOffset: number, length: number): IBuffer
11
+ }
12
+ alloc: (size: number) => IBuffer
13
+ isBuffer: (obj: unknown) => obj is IBuffer
14
+ }
15
+
16
+ export declare const enum GlobalHandle {
17
+ UNDEFINED = 1,
18
+ NULL,
19
+ FALSE,
20
+ TRUE,
21
+ GLOBAL
22
+ }
23
+
24
+ export declare const enum Version {
25
+ NODE_API_SUPPORTED_VERSION_MIN = 1,
26
+ NODE_API_DEFAULT_MODULE_API_VERSION = 8,
27
+ NODE_API_SUPPORTED_VERSION_MAX = 10,
28
+ NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ export declare type Pointer<T> = number
32
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
+ export declare type PointerPointer<T> = number
34
+ export declare type FunctionPointer<T extends (...args: any[]) => any> = Pointer<T>
35
+ export declare type Const<T> = T
36
+
37
+ export declare type void_p = Pointer<void>
38
+ export declare type void_pp = Pointer<void_p>
39
+ export declare type bool = number
40
+ export declare type char = number
41
+ export declare type char_p = Pointer<char>
42
+ export declare type unsigned_char = number
43
+ export declare type const_char = Const<char>
44
+ export declare type const_char_p = Pointer<const_char>
45
+ export declare type char16_t_p = number
46
+ export declare type const_char16_t_p = number
47
+
48
+ export declare type short = number
49
+ export declare type unsigned_short = number
50
+ export declare type int = number
51
+ export declare type unsigned_int = number
52
+ export declare type long = number
53
+ export declare type unsigned_long = number
54
+ export declare type long_long = bigint
55
+ export declare type unsigned_long_long = bigint
56
+ export declare type float = number
57
+ export declare type double = number
58
+ export declare type long_double = number
59
+ export declare type size_t = number
60
+
61
+ export declare type int8_t = number
62
+ export declare type uint8_t = number
63
+ export declare type int16_t = number
64
+ export declare type uint16_t = number
65
+ export declare type int32_t = number
66
+ export declare type uint32_t = number
67
+ export declare type int64_t = bigint
68
+ export declare type uint64_t = bigint
69
+ export declare type napi_env = Pointer<unknown>
70
+
71
+ export declare type napi_value = Pointer<unknown>
72
+ export declare type napi_ref = Pointer<unknown>
73
+ export declare type napi_deferred = Pointer<unknown>
74
+ export declare type napi_handle_scope = Pointer<unknown>
75
+ export declare type napi_escapable_handle_scope = Pointer<unknown>
76
+
77
+ export declare type napi_addon_register_func = FunctionPointer<(env: napi_env, exports: napi_value) => napi_value>
78
+
79
+ export declare type napi_callback_info = Pointer<unknown>
80
+ export declare type napi_callback = FunctionPointer<(env: napi_env, info: napi_callback_info) => napi_value>
81
+
82
+ export declare interface napi_extended_error_info {
83
+ error_message: const_char_p
84
+ engine_reserved: void_p
85
+ engine_error_code: uint32_t
86
+ error_code: napi_status
87
+ }
88
+
89
+ export declare interface napi_property_descriptor {
90
+ // One of utf8name or name should be NULL.
91
+ utf8name: const_char_p
92
+ name: napi_value
93
+
94
+ method: napi_callback
95
+ getter: napi_callback
96
+ setter: napi_callback
97
+ value: napi_value
98
+ /* napi_property_attributes */
99
+ attributes: number
100
+ data: void_p
101
+ }
102
+
103
+ export declare type napi_finalize = FunctionPointer<(
104
+ env: napi_env,
105
+ finalize_data: void_p,
106
+ finalize_hint: void_p
107
+ ) => void>
108
+
109
+ export declare interface node_module {
110
+ nm_version: int32_t
111
+ nm_flags: uint32_t
112
+ nm_filename: Pointer<const_char>
113
+ nm_register_func: napi_addon_register_func
114
+ nm_modname: Pointer<const_char>
115
+ nm_priv: Pointer<void>
116
+ reserved: PointerPointer<void>
117
+ }
118
+
119
+ export declare interface napi_node_version {
120
+ major: uint32_t
121
+ minor: uint32_t
122
+ patch: uint32_t
123
+ release: const_char_p
124
+ }
125
+
126
+ export declare interface emnapi_emscripten_version {
127
+ major: uint32_t
128
+ minor: uint32_t
129
+ patch: uint32_t
130
+ }
131
+
132
+ export declare const enum napi_status {
133
+ napi_ok,
134
+ napi_invalid_arg,
135
+ napi_object_expected,
136
+ napi_string_expected,
137
+ napi_name_expected,
138
+ napi_function_expected,
139
+ napi_number_expected,
140
+ napi_boolean_expected,
141
+ napi_array_expected,
142
+ napi_generic_failure,
143
+ napi_pending_exception,
144
+ napi_cancelled,
145
+ napi_escape_called_twice,
146
+ napi_handle_scope_mismatch,
147
+ napi_callback_scope_mismatch,
148
+ napi_queue_full,
149
+ napi_closing,
150
+ napi_bigint_expected,
151
+ napi_date_expected,
152
+ napi_arraybuffer_expected,
153
+ napi_detachable_arraybuffer_expected,
154
+ napi_would_deadlock, // unused
155
+ napi_no_external_buffers_allowed,
156
+ napi_cannot_run_js
157
+ }
158
+
159
+ export declare const enum napi_property_attributes {
160
+ napi_default = 0,
161
+ napi_writable = 1 << 0,
162
+ napi_enumerable = 1 << 1,
163
+ napi_configurable = 1 << 2,
164
+
165
+ // Used with napi_define_class to distinguish static properties
166
+ // from instance properties. Ignored by napi_define_properties.
167
+ napi_static = 1 << 10,
168
+
169
+ /// #ifdef NAPI_EXPERIMENTAL
170
+ // Default for class methods.
171
+ napi_default_method = napi_writable | napi_configurable,
172
+
173
+ // Default for object properties, like in JS obj[prop].
174
+ napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable
175
+ /// #endif // NAPI_EXPERIMENTAL
176
+ }
177
+
178
+ export declare const enum napi_valuetype {
179
+ napi_undefined,
180
+ napi_null,
181
+ napi_boolean,
182
+ napi_number,
183
+ napi_string,
184
+ napi_symbol,
185
+ napi_object,
186
+ napi_function,
187
+ napi_external,
188
+ napi_bigint
189
+ }
190
+
191
+ export declare const enum napi_typedarray_type {
192
+ napi_int8_array,
193
+ napi_uint8_array,
194
+ napi_uint8_clamped_array,
195
+ napi_int16_array,
196
+ napi_uint16_array,
197
+ napi_int32_array,
198
+ napi_uint32_array,
199
+ napi_float32_array,
200
+ napi_float64_array,
201
+ napi_bigint64_array,
202
+ napi_biguint64_array,
203
+ napi_float16_array,
204
+ }
205
+
206
+ export declare const enum napi_key_collection_mode {
207
+ napi_key_include_prototypes,
208
+ napi_key_own_only
209
+ }
210
+
211
+ export declare const enum napi_key_filter {
212
+ napi_key_all_properties = 0,
213
+ napi_key_writable = 1,
214
+ napi_key_enumerable = 1 << 1,
215
+ napi_key_configurable = 1 << 2,
216
+ napi_key_skip_strings = 1 << 3,
217
+ napi_key_skip_symbols = 1 << 4
218
+ }
219
+
220
+ export declare const enum napi_key_conversion {
221
+ napi_key_keep_numbers,
222
+ napi_key_numbers_to_strings
223
+ }
224
+
225
+ export declare const enum emnapi_memory_view_type {
226
+ emnapi_int8_array,
227
+ emnapi_uint8_array,
228
+ emnapi_uint8_clamped_array,
229
+ emnapi_int16_array,
230
+ emnapi_uint16_array,
231
+ emnapi_int32_array,
232
+ emnapi_uint32_array,
233
+ emnapi_float32_array,
234
+ emnapi_float64_array,
235
+ emnapi_bigint64_array,
236
+ emnapi_biguint64_array,
237
+ emnapi_float16_array,
238
+ emnapi_data_view = -1,
239
+ emnapi_buffer = -2
240
+ }
241
+
242
+ export declare const enum napi_threadsafe_function_call_mode {
243
+ napi_tsfn_nonblocking,
244
+ napi_tsfn_blocking
245
+ }
246
+
247
+ export declare const enum napi_threadsafe_function_release_mode {
248
+ napi_tsfn_release,
249
+ napi_tsfn_abort
250
+ }
251
+ export declare type CleanupHookCallbackFunction = number | ((arg: number) => void);
252
+
253
+ export declare class ConstHandle<S extends undefined | null | boolean | typeof globalThis> extends Handle<S> {
254
+ constructor(id: number, value: S);
255
+ dispose(): void;
256
+ }
257
+
258
+ export declare class Context {
259
+ private _isStopping;
260
+ private _canCallIntoJs;
261
+ private _suppressDestroy;
262
+ envStore: Store<Env>;
263
+ scopeStore: ScopeStore;
264
+ refStore: Store<Reference>;
265
+ deferredStore: Store<Deferred<any>>;
266
+ handleStore: HandleStore;
267
+ private readonly refCounter?;
268
+ private readonly cleanupQueue;
269
+ private readonly _externalMemory;
270
+ feature: {
271
+ supportReflect: boolean;
272
+ supportFinalizer: boolean;
273
+ supportWeakSymbol: boolean;
274
+ supportBigInt: boolean;
275
+ supportNewFunction: boolean;
276
+ canSetFunctionName: boolean;
277
+ setImmediate: (callback: () => void) => void;
278
+ Buffer: BufferCtor | undefined;
279
+ MessageChannel: {
280
+ new (): MessageChannel;
281
+ prototype: MessageChannel;
282
+ } | undefined;
283
+ };
284
+ constructor(options?: ContextOptions);
285
+ /**
286
+ * Suppress the destroy on `beforeExit` event in Node.js.
287
+ * Call this method if you want to keep the context and
288
+ * all associated {@link Env | Env} alive,
289
+ * this also means that cleanup hooks will not be called.
290
+ * After call this method, you should call
291
+ * {@link Context.destroy | `Context.prototype.destroy`} method manually.
292
+ */
293
+ suppressDestroy(): void;
294
+ getRuntimeVersions(): {
295
+ version: string;
296
+ NODE_API_SUPPORTED_VERSION_MAX: Version;
297
+ NAPI_VERSION_EXPERIMENTAL: Version;
298
+ NODE_API_DEFAULT_MODULE_API_VERSION: Version;
299
+ };
300
+ createNotSupportWeakRefError(api: string, message: string): NotSupportWeakRefError;
301
+ createNotSupportBufferError(api: string, message: string): NotSupportBufferError;
302
+ createReference(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership): Reference;
303
+ createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
304
+ createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
305
+ createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
306
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
307
+ createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
308
+ createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
309
+ getCurrentScope(): HandleScope | null;
310
+ addToCurrentScope<V>(value: V): Handle<V>;
311
+ openScope(envObject?: Env): HandleScope;
312
+ closeScope(envObject?: Env, _scope?: HandleScope): void;
313
+ ensureHandle<S>(value: S): Handle<S>;
314
+ addCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
315
+ removeCleanupHook(envObject: Env, fn: CleanupHookCallbackFunction, arg: number): void;
316
+ runCleanup(): void;
317
+ increaseWaitingRequestCounter(): void;
318
+ decreaseWaitingRequestCounter(): void;
319
+ setCanCallIntoJs(value: boolean): void;
320
+ setStopping(value: boolean): void;
321
+ canCallIntoJs(): boolean;
322
+ /**
323
+ * Destroy the context and call cleanup hooks.
324
+ * Associated {@link Env | Env} will be destroyed.
325
+ */
326
+ destroy(): void;
327
+ }
328
+
329
+ export declare interface ContextOptions {
330
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
331
+ }
332
+
333
+ export declare function createContext(options?: ContextOptions): Context;
334
+
335
+ export declare class Deferred<T = any> implements IStoreValue {
336
+ static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
337
+ id: number;
338
+ ctx: Context;
339
+ value: IDeferrdValue<T>;
340
+ constructor(ctx: Context, value: IDeferrdValue<T>);
341
+ resolve(value: T): void;
342
+ reject(reason?: any): void;
343
+ dispose(): void;
344
+ }
345
+
346
+ export declare class EmnapiError extends Error {
347
+ constructor(message?: string);
348
+ }
349
+
350
+ export declare abstract class Env implements IStoreValue {
351
+ readonly ctx: Context;
352
+ moduleApiVersion: number;
353
+ makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void;
354
+ makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void;
355
+ abort: (msg?: string) => never;
356
+ id: number;
357
+ openHandleScopes: number;
358
+ instanceData: TrackedFinalizer | null;
359
+ tryCatch: TryCatch;
360
+ refs: number;
361
+ reflist: RefTracker;
362
+ finalizing_reflist: RefTracker;
363
+ pendingFinalizers: RefTracker[];
364
+ lastError: {
365
+ errorCode: napi_status;
366
+ engineErrorCode: number;
367
+ engineReserved: Ptr;
368
+ };
369
+ inGcFinalizer: boolean;
370
+ constructor(ctx: Context, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never);
371
+ /** @virtual */
372
+ canCallIntoJs(): boolean;
373
+ terminatedOrTerminating(): boolean;
374
+ ref(): void;
375
+ unref(): void;
376
+ ensureHandle<S>(value: S): Handle<S>;
377
+ ensureHandleId(value: any): napi_value;
378
+ clearLastError(): napi_status;
379
+ setLastError(error_code: napi_status, engine_error_code?: uint32_t, engine_reserved?: void_p): napi_status;
380
+ getReturnStatus(): napi_status;
381
+ callIntoModule<T>(fn: (env: Env) => T, handleException?: (envObject: Env, value: any) => void): T;
382
+ /** @virtual */
383
+ abstract callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
384
+ invokeFinalizerFromGC(finalizer: RefTracker): void;
385
+ checkGCAccess(): void;
386
+ /** @virtual */
387
+ enqueueFinalizer(finalizer: RefTracker): void;
388
+ /** @virtual */
389
+ dequeueFinalizer(finalizer: RefTracker): void;
390
+ /** @virtual */
391
+ deleteMe(): void;
392
+ dispose(): void;
393
+ private readonly _bindingMap;
394
+ initObjectBinding<S extends object>(value: S): IReferenceBinding;
395
+ getObjectBinding<S extends object>(value: S): IReferenceBinding;
396
+ setInstanceData(data: number, finalize_cb: number, finalize_hint: number): void;
397
+ getInstanceData(): number;
398
+ }
399
+
400
+ /** @public */
401
+ declare interface External_2 extends Record<any, any> {
402
+ }
403
+
404
+ /** @public */
405
+ declare const External_2: {
406
+ new (value: number | bigint): External_2;
407
+ prototype: null;
408
+ };
409
+ export { External_2 as External }
410
+
411
+ export declare class Finalizer {
412
+ envObject: Env;
413
+ private _finalizeCallback;
414
+ private _finalizeData;
415
+ private _finalizeHint;
416
+ private _makeDynCall_vppp;
417
+ constructor(envObject: Env, _finalizeCallback?: napi_finalize, _finalizeData?: void_p, _finalizeHint?: void_p);
418
+ callback(): napi_finalize;
419
+ data(): void_p;
420
+ hint(): void_p;
421
+ resetEnv(): void;
422
+ resetFinalizer(): void;
423
+ callFinalizer(): void;
424
+ dispose(): void;
425
+ }
426
+
427
+ export declare function getDefaultContext(): Context;
428
+
429
+ /** @public */
430
+ export declare function getExternalValue(external: External_2): number | bigint;
431
+
432
+ export declare class Handle<S> {
433
+ id: number;
434
+ value: S;
435
+ constructor(id: number, value: S);
436
+ data(): void_p;
437
+ isNumber(): boolean;
438
+ isBigInt(): boolean;
439
+ isString(): boolean;
440
+ isFunction(): boolean;
441
+ isExternal(): boolean;
442
+ isObject(): boolean;
443
+ isArray(): boolean;
444
+ isArrayBuffer(): boolean;
445
+ isTypedArray(): boolean;
446
+ isBuffer(BufferConstructor?: BufferCtor): boolean;
447
+ isDataView(): boolean;
448
+ isDate(): boolean;
449
+ isPromise(): boolean;
450
+ isBoolean(): boolean;
451
+ isUndefined(): boolean;
452
+ isSymbol(): boolean;
453
+ isNull(): boolean;
454
+ dispose(): void;
455
+ }
456
+
457
+ export declare class HandleScope {
458
+ handleStore: HandleStore;
459
+ id: number;
460
+ parent: HandleScope | null;
461
+ child: HandleScope | null;
462
+ start: number;
463
+ end: number;
464
+ private _escapeCalled;
465
+ callbackInfo: ICallbackInfo;
466
+ constructor(handleStore: HandleStore, id: number, parentScope: HandleScope | null, start: number, end?: number);
467
+ add<V>(value: V): Handle<V>;
468
+ addExternal(data: void_p): Handle<object>;
469
+ dispose(): void;
470
+ escape(handle: number): Handle<any> | null;
471
+ escapeCalled(): boolean;
472
+ }
473
+
474
+ export declare class HandleStore {
475
+ static UNDEFINED: ConstHandle<undefined>;
476
+ static NULL: ConstHandle<null>;
477
+ static FALSE: ConstHandle<false>;
478
+ static TRUE: ConstHandle<true>;
479
+ static GLOBAL: ConstHandle<typeof globalThis>;
480
+ static MIN_ID: 6;
481
+ private readonly _values;
482
+ private _next;
483
+ push<S>(value: S): Handle<S>;
484
+ erase(start: number, end: number): void;
485
+ get(id: Ptr): Handle<any> | undefined;
486
+ swap(a: number, b: number): void;
487
+ dispose(): void;
488
+ }
489
+
490
+ export declare interface ICallbackInfo {
491
+ thiz: any;
492
+ data: void_p;
493
+ args: ArrayLike<any>;
494
+ fn: Function;
495
+ }
496
+
497
+ export declare interface IDeferrdValue<T = any> {
498
+ resolve: (value: T) => void;
499
+ reject: (reason?: any) => void;
500
+ }
501
+
502
+ export declare interface IReferenceBinding {
503
+ wrapped: number;
504
+ tag: Uint32Array | null;
505
+ }
506
+
507
+ /** @public */
508
+ export declare function isExternal(object: unknown): object is External_2;
509
+
510
+ export declare function isReferenceType(v: any): v is object;
511
+
512
+ export declare interface IStoreValue {
513
+ id: number;
514
+ dispose(): void;
515
+ [x: string]: any;
516
+ }
517
+
518
+ export declare const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL;
519
+
520
+ export declare const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION;
521
+
522
+ export declare const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX;
523
+
524
+ export declare const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN;
525
+
526
+ export declare class NodeEnv extends Env {
527
+ filename: string;
528
+ private readonly nodeBinding?;
529
+ destructing: boolean;
530
+ finalizationScheduled: boolean;
531
+ constructor(ctx: Context, filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any);
532
+ deleteMe(): void;
533
+ canCallIntoJs(): boolean;
534
+ triggerFatalException(err: any): void;
535
+ callbackIntoModule<T>(enforceUncaughtExceptionPolicy: boolean, fn: (env: Env) => T): T;
536
+ callFinalizer(cb: napi_finalize, data: void_p, hint: void_p): void;
537
+ callFinalizerInternal(forceUncaught: int, cb: napi_finalize, data: void_p, hint: void_p): void;
538
+ enqueueFinalizer(finalizer: RefTracker): void;
539
+ drainFinalizerQueue(): void;
540
+ }
541
+
542
+ export declare class NotSupportBufferError extends EmnapiError {
543
+ constructor(api: string, message: string);
544
+ }
545
+
546
+ export declare class NotSupportWeakRefError extends EmnapiError {
547
+ constructor(api: string, message: string);
548
+ }
549
+
550
+ export declare class Persistent<T> {
551
+ private _ref;
552
+ private _param;
553
+ private _callback;
554
+ private static readonly _registry;
555
+ constructor(value: T);
556
+ setWeak<P>(param: P, callback: (param: P) => void): void;
557
+ clearWeak(): void;
558
+ reset(): void;
559
+ isEmpty(): boolean;
560
+ deref(): T | undefined;
561
+ }
562
+
563
+ export declare class Reference extends RefTracker implements IStoreValue {
564
+ private static weakCallback;
565
+ id: number;
566
+ envObject: Env;
567
+ private readonly canBeWeak;
568
+ private _refcount;
569
+ private readonly _ownership;
570
+ persistent: Persistent<object>;
571
+ static create(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, _unused1?: void_p, _unused2?: void_p, _unused3?: void_p): Reference;
572
+ protected constructor(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership);
573
+ ref(): number;
574
+ unref(): number;
575
+ get(envObject?: Env): napi_value;
576
+ /** @virtual */
577
+ resetFinalizer(): void;
578
+ /** @virtual */
579
+ data(): void_p;
580
+ refcount(): number;
581
+ ownership(): ReferenceOwnership;
582
+ /** @virtual */
583
+ protected callUserFinalizer(): void;
584
+ /** @virtual */
585
+ protected invokeFinalizerFromGC(): void;
586
+ private _setWeak;
587
+ finalize(): void;
588
+ dispose(): void;
589
+ }
590
+
591
+ export declare enum ReferenceOwnership {
592
+ kRuntime = 0,
593
+ kUserland = 1
594
+ }
595
+
596
+ export declare class ReferenceWithData extends Reference {
597
+ private readonly _data;
598
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): ReferenceWithData;
599
+ private constructor();
600
+ data(): void_p;
601
+ }
602
+
603
+ export declare class ReferenceWithFinalizer extends Reference {
604
+ private _finalizer;
605
+ static create(envObject: Env, value: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): ReferenceWithFinalizer;
606
+ private constructor();
607
+ resetFinalizer(): void;
608
+ data(): void_p;
609
+ protected callUserFinalizer(): void;
610
+ protected invokeFinalizerFromGC(): void;
611
+ dispose(): void;
612
+ }
613
+
614
+ export declare class RefTracker {
615
+ /** @virtual */
616
+ dispose(): void;
617
+ /** @virtual */
618
+ finalize(): void;
619
+ private _next;
620
+ private _prev;
621
+ link(list: RefTracker): void;
622
+ unlink(): void;
623
+ static finalizeAll(list: RefTracker): void;
624
+ }
625
+
626
+ export declare class ScopeStore {
627
+ private readonly _rootScope;
628
+ currentScope: HandleScope;
629
+ private readonly _values;
630
+ constructor();
631
+ get(id: number): HandleScope | undefined;
632
+ openScope(handleStore: HandleStore): HandleScope;
633
+ closeScope(): void;
634
+ dispose(): void;
635
+ }
636
+
637
+ export declare class Store<V extends IStoreValue> {
638
+ protected _values: Array<V | undefined>;
639
+ private _freeList;
640
+ private _size;
641
+ constructor();
642
+ add(value: V): void;
643
+ get(id: Ptr): V | undefined;
644
+ has(id: Ptr): boolean;
645
+ remove(id: Ptr): void;
646
+ dispose(): void;
647
+ }
648
+
649
+ export declare class TrackedFinalizer extends RefTracker {
650
+ private _finalizer;
651
+ static create(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
652
+ private constructor();
653
+ data(): void_p;
654
+ dispose(): void;
655
+ finalize(): void;
656
+ }
657
+
658
+ export declare class TryCatch {
659
+ private _exception;
660
+ private _caught;
661
+ isEmpty(): boolean;
662
+ hasCaught(): boolean;
663
+ exception(): any;
664
+ setError(err: any): void;
665
+ reset(): void;
666
+ extractException(): any;
667
+ }
668
+
669
+ export declare const version: string;
670
+
671
+ export { }
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.min.js ADDED
@@ -0,0 +1 @@
 
 
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).emnapi={})}(this,function(t){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}"function"==typeof SuppressedError&&SuppressedError;var i=new WeakMap;function r(t){return i.has(t)}var o=function(){function t(t){Object.setPrototypeOf(this,null),i.set(this,t)}return t.prototype=null,t}();function s(t){if(!r(t))throw new TypeError("not external");return i.get(t)}var a=function(){var t;try{t=new Function}catch(t){return!1}return"function"==typeof t}(),u=function(){if("undefined"!=typeof globalThis)return globalThis;var t=function(){return this}();if(!t&&a)try{t=new Function("return this")()}catch(t){}if(!t){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return t}(),c=function(){function t(){this._exception=void 0,this._caught=!1}return t.prototype.isEmpty=function(){return!this._caught},t.prototype.hasCaught=function(){return this._caught},t.prototype.exception=function(){return this._exception},t.prototype.setError=function(t){this._caught=!0,this._exception=t},t.prototype.reset=function(){this._caught=!1,this._exception=void 0},t.prototype.extractException=function(){var t=this._exception;return this.reset(),t},t}(),p=function(){var t;try{return Boolean(null===(t=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===t?void 0:t.configurable)}catch(t){return!1}}(),l="object"==typeof Reflect,f="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,h=function(){try{var t=Symbol();new WeakRef(t),(new WeakMap).set(t,void 0)}catch(t){return!1}return!0}(),d="undefined"!=typeof BigInt;var y=function(){return"undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0}(),_="function"==typeof MessageChannel?MessageChannel:function(){try{return y("worker_threads").MessageChannel}catch(t){}}(),v="function"==typeof setImmediate?setImmediate.bind(u):function(t){if("function"!=typeof t)throw new TypeError('The "callback" argument must be of type function');if(_){var e=new _;e.port1.onmessage=function(){e.port1.onmessage=null,e=void 0,t()},e.port2.postMessage(null)}else setTimeout(t,0)},g="function"==typeof Buffer?Buffer:function(){try{return y("buffer").Buffer}catch(t){}}(),b="1.11.3",z=2147483647,w=function(){function t(t,e){this.id=t,this.value=e}return t.prototype.data=function(){return s(this.value)},t.prototype.isNumber=function(){return"number"==typeof this.value},t.prototype.isBigInt=function(){return"bigint"==typeof this.value},t.prototype.isString=function(){return"string"==typeof this.value},t.prototype.isFunction=function(){return"function"==typeof this.value},t.prototype.isExternal=function(){return r(this.value)},t.prototype.isObject=function(){return"object"==typeof this.value&&null!==this.value},t.prototype.isArray=function(){return Array.isArray(this.value)},t.prototype.isArrayBuffer=function(){return this.value instanceof ArrayBuffer},t.prototype.isTypedArray=function(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)},t.prototype.isBuffer=function(t){return!!ArrayBuffer.isView(this.value)||(null!=t||(t=g),"function"==typeof t&&t.isBuffer(this.value))},t.prototype.isDataView=function(){return this.value instanceof DataView},t.prototype.isDate=function(){return this.value instanceof Date},t.prototype.isPromise=function(){return this.value instanceof Promise},t.prototype.isBoolean=function(){return"boolean"==typeof this.value},t.prototype.isUndefined=function(){return void 0===this.value},t.prototype.isSymbol=function(){return"symbol"==typeof this.value},t.prototype.isNull=function(){return null===this.value},t.prototype.dispose=function(){this.value=void 0},t}(),k=function(t){function e(e,n){return t.call(this,e,n)||this}return n(e,t),e.prototype.dispose=function(){},e}(w),m=function(){function t(){this._values=[void 0,t.UNDEFINED,t.NULL,t.FALSE,t.TRUE,t.GLOBAL],this._next=t.MIN_ID}return t.prototype.push=function(t){var e,n=this._next,i=this._values;return n<i.length?(e=i[n]).value=t:(e=new w(n,t),i[n]=e),this._next++,e},t.prototype.erase=function(t,e){this._next=t;for(var n=this._values,i=t;i<e;++i)n[i].dispose()},t.prototype.get=function(t){return this._values[t]},t.prototype.swap=function(t,e){var n=this._values,i=n[t];n[t]=n[e],n[t].id=Number(t),n[e]=i,i.id=Number(e)},t.prototype.dispose=function(){this._values.length=t.MIN_ID,this._next=t.MIN_ID},t.UNDEFINED=new k(1,void 0),t.NULL=new k(2,null),t.FALSE=new k(3,!1),t.TRUE=new k(4,!0),t.GLOBAL=new k(5,u),t.MIN_ID=6,t}(),E=function(){function t(t,e,n,i,r){void 0===r&&(r=i),this.handleStore=t,this.id=e,this.parent=n,this.child=null,null!==n&&(n.child=this),this.start=i,this.end=r,this._escapeCalled=!1,this.callbackInfo={thiz:void 0,data:0,args:void 0,fn:void 0}}return t.prototype.add=function(t){var e=this.handleStore.push(t);return this.end++,e},t.prototype.addExternal=function(t){return this.add(new o(t))},t.prototype.dispose=function(){this._escapeCalled&&(this._escapeCalled=!1),this.start!==this.end&&this.handleStore.erase(this.start,this.end)},t.prototype.escape=function(t){if(this._escapeCalled)return null;if(this._escapeCalled=!0,t<this.start||t>=this.end)return null;this.handleStore.swap(t,this.start);var e=this.handleStore.get(this.start);return this.start++,this.parent.end++,e},t.prototype.escapeCalled=function(){return this._escapeCalled},t}(),S=function(){function t(){this._rootScope=new E(null,0,null,1,m.MIN_ID),this.currentScope=this._rootScope,this._values=[void 0]}return t.prototype.get=function(t){return this._values[t]},t.prototype.openScope=function(t){var e=this.currentScope,n=e.child;if(null!==n)n.start=n.end=e.end;else{var i=e.id+1;n=new E(t,i,e,e.end),this._values[i]=n}return this.currentScope=n,n},t.prototype.closeScope=function(){var t=this.currentScope;this.currentScope=t.parent,t.dispose()},t.prototype.dispose=function(){this.currentScope=this._rootScope,this._values.length=1},t}(),C=function(){function t(){this._next=null,this._prev=null}return t.prototype.dispose=function(){},t.prototype.finalize=function(){},t.prototype.link=function(t){this._prev=t,this._next=t._next,null!==this._next&&(this._next._prev=this),t._next=this},t.prototype.unlink=function(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null},t.finalizeAll=function(t){for(;null!==t._next;)t._next.finalize()},t}(),x=function(){function t(t,e,n,i){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.envObject=t,this._finalizeCallback=e,this._finalizeData=n,this._finalizeHint=i,this._makeDynCall_vppp=t.makeDynCall_vppp}return t.prototype.callback=function(){return this._finalizeCallback},t.prototype.data=function(){return this._finalizeData},t.prototype.hint=function(){return this._finalizeHint},t.prototype.resetEnv=function(){this.envObject=void 0},t.prototype.resetFinalizer=function(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0},t.prototype.callFinalizer=function(){var t=this._finalizeCallback,e=this._finalizeData,n=this._finalizeHint;if(this.resetFinalizer(),t){var i=Number(t);this.envObject?this.envObject.callFinalizer(i,e,n):this._makeDynCall_vppp(i)(0,e,n)}},t.prototype.dispose=function(){this.envObject=void 0,this._makeDynCall_vppp=void 0},t}(),F=function(t){function e(e,n,i,r){var o=t.call(this)||this;return o._finalizer=new x(e,n,i,r),o}return n(e,t),e.create=function(t,n,i,r){var o=new e(t,n,i,r);return o.link(t.finalizing_reflist),o},e.prototype.data=function(){return this._finalizer.data()},e.prototype.dispose=function(){this._finalizer&&(this.unlink(),this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),this._finalizer=void 0,t.prototype.dispose.call(this))},e.prototype.finalize=function(){var t;this.unlink();var e=!1;try{this._finalizer.callFinalizer()}catch(n){e=!0,t=n}if(this.dispose(),e)throw t},e}(C);function O(t,e){if(!t.terminatedOrTerminating())throw e}var I=function(){function t(t,e,n,i,r){this.ctx=t,this.moduleApiVersion=e,this.makeDynCall_vppp=n,this.makeDynCall_vp=i,this.abort=r,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new c,this.refs=1,this.reflist=new C,this.finalizing_reflist=new C,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,this._bindingMap=new WeakMap,this.id=0}return t.prototype.canCallIntoJs=function(){return!0},t.prototype.terminatedOrTerminating=function(){return!this.canCallIntoJs()},t.prototype.ref=function(){this.refs++},t.prototype.unref=function(){this.refs--,0===this.refs&&this.dispose()},t.prototype.ensureHandle=function(t){return this.ctx.ensureHandle(t)},t.prototype.ensureHandleId=function(t){return this.ensureHandle(t).id},t.prototype.clearLastError=function(){var t=this.lastError;return 0!==t.errorCode&&(t.errorCode=0),0!==t.engineErrorCode&&(t.engineErrorCode=0),0!==t.engineReserved&&(t.engineReserved=0),0},t.prototype.setLastError=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n=0);var i=this.lastError;return i.errorCode!==t&&(i.errorCode=t),i.engineErrorCode!==e&&(i.engineErrorCode=e),i.engineReserved!==n&&(i.engineReserved=n),t},t.prototype.getReturnStatus=function(){return this.tryCatch.hasCaught()?this.setLastError(10):0},t.prototype.callIntoModule=function(t,e){void 0===e&&(e=O);var n=this.openHandleScopes;this.clearLastError();var i=t(this);(n!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught())&&e(this,this.tryCatch.extractException());return i},t.prototype.invokeFinalizerFromGC=function(t){if(this.moduleApiVersion!==z)this.enqueueFinalizer(t);else{var e=this.inGcFinalizer;this.inGcFinalizer=!0;try{t.finalize()}finally{this.inGcFinalizer=e}}},t.prototype.checkGCAccess=function(){this.moduleApiVersion===z&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")},t.prototype.enqueueFinalizer=function(t){-1===this.pendingFinalizers.indexOf(t)&&this.pendingFinalizers.push(t)},t.prototype.dequeueFinalizer=function(t){var e=this.pendingFinalizers.indexOf(t);-1!==e&&this.pendingFinalizers.splice(e,1)},t.prototype.deleteMe=function(){C.finalizeAll(this.finalizing_reflist),C.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)},t.prototype.dispose=function(){0!==this.id&&(this.deleteMe(),this.finalizing_reflist.dispose(),this.reflist.dispose(),this.id=0)},t.prototype.initObjectBinding=function(t){var e={wrapped:0,tag:null};return this._bindingMap.set(t,e),e},t.prototype.getObjectBinding=function(t){return this._bindingMap.has(t)?this._bindingMap.get(t):this.initObjectBinding(t)},t.prototype.setInstanceData=function(t,e,n){this.instanceData&&this.instanceData.dispose(),this.instanceData=F.create(this,e,t,n)},t.prototype.getInstanceData=function(){return this.instanceData?this.instanceData.data():0},t}(),D=function(t){function e(e,n,i,r,o,s,a){var u=t.call(this,e,i,r,o,s)||this;return u.filename=n,u.nodeBinding=a,u.destructing=!1,u.finalizationScheduled=!1,u}return n(e,t),e.prototype.deleteMe=function(){this.destructing=!0,this.drainFinalizerQueue(),t.prototype.deleteMe.call(this)},e.prototype.canCallIntoJs=function(){return t.prototype.canCallIntoJs.call(this)&&this.ctx.canCallIntoJs()},e.prototype.triggerFatalException=function(t){if(this.nodeBinding)this.nodeBinding.napi.fatalException(t);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw t;process._fatalException(t)||(console.error(t),process.exit(1))}},e.prototype.callbackIntoModule=function(t,e){return this.callIntoModule(e,function(e,n){if(!e.terminatedOrTerminating()){var i="object"==typeof process&&null!==process,r=!!i&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(e.moduleApiVersion<10&&!r&&!t)(i&&"function"==typeof process.emitWarning?process.emitWarning:function(t,e,n){if(t instanceof Error)console.warn(t.toString());else{var i=n?"[".concat(n,"] "):"";console.warn("".concat(i).concat(e||"Warning",": ").concat(t))}})("Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168");else e.triggerFatalException(n)}})},e.prototype.callFinalizer=function(t,e,n){this.callFinalizerInternal(1,t,e,n)},e.prototype.callFinalizerInternal=function(t,e,n,i){var r=this.makeDynCall_vppp(e),o=this.id,s=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(t),function(){r(o,n,i)})}finally{this.ctx.closeScope(this,s)}},e.prototype.enqueueFinalizer=function(e){var n=this;t.prototype.enqueueFinalizer.call(this,e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),v(function(){n.finalizationScheduled=!1,n.unref(),n.drainFinalizerQueue()}))},e.prototype.drainFinalizerQueue=function(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}},e}(I);function R(t,e,n,i,r,o,s){(n="number"!=typeof n?8:n)<8?n=8:n>10&&n!==z&&function(t,e){var n="".concat(t," requires Node-API version ").concat(e,", but this version of Node.js only supports version ").concat(10," add-ons.");throw new Error(n)}(e,n);var a=new D(t,e,n,i,r,o,s);return t.envStore.add(a),t.addCleanupHook(a,function(){a.unref()},0),a}var N=function(t){function e(n){var i=this.constructor,r=t.call(this,n)||this,o=i,s=o.prototype;if(!(r instanceof e)){var a=Object.setPrototypeOf;"function"==typeof a?a.call(Object,r,s):r.__proto__=s,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(r,o)}return r}return n(e,t),e}(Error);Object.defineProperty(N.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});var j=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "FinalizationRegistry" and "WeakRef".').concat(n?" ".concat(n):""))||this}return n(e,t),e}(N);Object.defineProperty(j.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});var A=function(t){function e(e,n){return t.call(this,"".concat(e,': The current runtime does not support "Buffer". Consider using buffer polyfill to make sure `globalThis.Buffer` is defined.').concat(n?" ".concat(n):""))||this}return n(e,t),e}(N);Object.defineProperty(A.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});var H,B=function(){function t(t){this._value=t}return t.prototype.deref=function(){return this._value},t.prototype.dispose=function(){this._value=void 0},t}(),M=function(){function t(t){this._ref=new B(t)}return t.prototype.setWeak=function(e,n){if(f&&void 0!==this._ref&&!(this._ref instanceof WeakRef)){var i=this._ref.deref();try{t._registry.register(i,this,this);var r=new WeakRef(i);this._ref.dispose(),this._ref=r,this._param=e,this._callback=n}catch(t){if("symbol"!=typeof i)throw t}}},t.prototype.clearWeak=function(){if(f&&void 0!==this._ref&&this._ref instanceof WeakRef){try{t._registry.unregister(this)}catch(t){}this._param=void 0,this._callback=void 0;var e=this._ref.deref();this._ref=void 0===e?e:new B(e)}},t.prototype.reset=function(){if(f)try{t._registry.unregister(this)}catch(t){}this._param=void 0,this._callback=void 0,this._ref instanceof B&&this._ref.dispose(),this._ref=void 0},t.prototype.isEmpty=function(){return void 0===this._ref},t.prototype.deref=function(){if(void 0!==this._ref)return this._ref.deref()},t._registry=f?new FinalizationRegistry(function(t){t._ref=void 0;var e=t._callback,n=t._param;t._callback=void 0,t._param=void 0,"function"==typeof e&&e(n)}):void 0,t}();t.ReferenceOwnership=void 0,(H=t.ReferenceOwnership||(t.ReferenceOwnership={}))[H.kRuntime=0]="kRuntime",H[H.kUserland=1]="kUserland";var T,W=function(e){function i(t,n,i,r){var o=e.call(this)||this;o.envObject=t,o._refcount=i,o._ownership=r;var s,a=t.ctx.handleStore.get(n);return o.canBeWeak=(s=a).isObject()||s.isFunction()||s.isSymbol(),o.persistent=new M(a.value),o.id=0,0===i&&o._setWeak(),o}return n(i,e),i.weakCallback=function(t){t.persistent.reset(),t.invokeFinalizerFromGC()},i.create=function(t,e,n,r,o,s,a){var u=new i(t,e,n,r);return t.ctx.refStore.add(u),u.link(t.reflist),u},i.prototype.ref=function(){return this.persistent.isEmpty()?0:(1===++this._refcount&&this.canBeWeak&&this.persistent.clearWeak(),this._refcount)},i.prototype.unref=function(){return this.persistent.isEmpty()||0===this._refcount?0:(0===--this._refcount&&this._setWeak(),this._refcount)},i.prototype.get=function(t){if(void 0===t&&(t=this.envObject),this.persistent.isEmpty())return 0;var e=this.persistent.deref();return t.ensureHandle(e).id},i.prototype.resetFinalizer=function(){},i.prototype.data=function(){return 0},i.prototype.refcount=function(){return this._refcount},i.prototype.ownership=function(){return this._ownership},i.prototype.callUserFinalizer=function(){},i.prototype.invokeFinalizerFromGC=function(){this.finalize()},i.prototype._setWeak=function(){this.canBeWeak?this.persistent.setWeak(this,i.weakCallback):this.persistent.reset()},i.prototype.finalize=function(){this.persistent.reset();var e=this._ownership===t.ReferenceOwnership.kRuntime;this.unlink(),this.callUserFinalizer(),e&&this.dispose()},i.prototype.dispose=function(){0!==this.id&&(this.unlink(),this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),e.prototype.dispose.call(this),this.envObject=void 0,this.id=0)},i}(C),P=function(t){function e(e,n,i,r,o){var s=t.call(this,e,n,i,r)||this;return s._data=o,s}return n(e,t),e.create=function(t,n,i,r,o){var s=new e(t,n,i,r,o);return t.ctx.refStore.add(s),s.link(t.reflist),s},e.prototype.data=function(){return this._data},e}(W),L=function(t){function e(e,n,i,r,o,s,a){var u=t.call(this,e,n,i,r)||this;return u._finalizer=new x(e,o,s,a),u}return n(e,t),e.create=function(t,n,i,r,o,s,a){var u=new e(t,n,i,r,o,s,a);return t.ctx.refStore.add(u),u.link(t.finalizing_reflist),u},e.prototype.resetFinalizer=function(){this._finalizer.resetFinalizer()},e.prototype.data=function(){return this._finalizer.data()},e.prototype.callUserFinalizer=function(){this._finalizer.callFinalizer()},e.prototype.invokeFinalizerFromGC=function(){this._finalizer.envObject.invokeFinalizerFromGC(this)},e.prototype.dispose=function(){this._finalizer&&(this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),t.prototype.dispose.call(this),this._finalizer=void 0)},e}(W),U=function(){function t(t,e){Object.defineProperties(this,{id:{configurable:!0,enumerable:!0,value:0,writable:!0},ctx:{configurable:!0,enumerable:!0,value:t,writable:!0},value:{configurable:!0,enumerable:!0,value:e,writable:!0}})}return t.create=function(e,n){var i=new t(e,n);return e.deferredStore.add(i),i},t.prototype.resolve=function(t){this.value.resolve(t),this.dispose()},t.prototype.reject=function(t){this.value.reject(t),this.dispose()},t.prototype.dispose=function(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null},t}(),V=function(){function t(){this._values=[void 0],this._values.length=4,this._size=1,this._freeList=[]}return t.prototype.add=function(t){var e;if(this._freeList.length)e=this._freeList.shift();else{e=this._size,this._size++;var n=this._values.length;e>=n&&(this._values.length=n+(n>>1)+16)}t.id=e,this._values[e]=t},t.prototype.get=function(t){return this._values[t]},t.prototype.has=function(t){return void 0!==this._values[t]},t.prototype.remove=function(t){var e=this._values[t];e&&(e.id=0,this._values[t]=void 0,this._freeList.push(Number(t)))},t.prototype.dispose=function(){for(var t=1;t<this._size;++t){var e=this._values[t];null==e||e.dispose()}this._values=[void 0],this._size=1,this._freeList=[]},t}(),G=BigInt(1)<<BigInt(60),q=-G,J=function(){function t(t){this.total=BigInt(0),this.onChange=null!=t?t:null}return t.prototype.adjust=function(t){if(t=BigInt(t),!(q<=t&&t<G))throw new RangeError("changeInBytes ".concat(t," is out of reasonable range"));var e=this.total;this.total+=t;var n=this.total,i=this.onChange;return t&&(null==i||i(n,e,t)),n},t}(),Q=function(){return function(t,e,n,i){this.envObject=t,this.fn=e,this.arg=n,this.order=i}}(),X=function(){function t(){this._cleanupHooks=[],this._cleanupHookCounter=0}return t.prototype.empty=function(){return 0===this._cleanupHooks.length},t.prototype.add=function(t,e,n){if(this._cleanupHooks.filter(function(i){return i.envObject===t&&i.fn===e&&i.arg===n}).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new Q(t,e,n,this._cleanupHookCounter++))},t.prototype.remove=function(t,e,n){for(var i=0;i<this._cleanupHooks.length;++i){var r=this._cleanupHooks[i];if(r.envObject===t&&r.fn===e&&r.arg===n)return void this._cleanupHooks.splice(i,1)}},t.prototype.drain=function(){var t=this._cleanupHooks.slice();t.sort(function(t,e){return e.order-t.order});for(var e=0;e<t.length;++e){var n=t[e];"number"==typeof n.fn?n.envObject.makeDynCall_vp(n.fn)(n.arg):n.fn(n.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(n),1)}},t.prototype.dispose=function(){this._cleanupHooks.length=0,this._cleanupHookCounter=0},t}(),K=function(){function t(){this.refHandle=(new _).port1,this.count=0}return t.prototype.increase=function(){0===this.count&&this.refHandle.ref&&this.refHandle.ref(),this.count++},t.prototype.decrease=function(){0!==this.count&&(1===this.count&&this.refHandle.unref&&this.refHandle.unref(),this.count--)},t}(),Y=function(){function t(t){var e=this;this._isStopping=!1,this._canCallIntoJs=!0,this._suppressDestroy=!1,this.envStore=new V,this.scopeStore=new S,this.refStore=new V,this.deferredStore=new V,this.handleStore=new m,this.feature={supportReflect:l,supportFinalizer:f,supportWeakSymbol:h,supportBigInt:d,supportNewFunction:a,canSetFunctionName:p,setImmediate:v,Buffer:g,MessageChannel:_},this.cleanupQueue=new X,this._externalMemory=new J(null==t?void 0:t.onExternalMemoryChange),"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new K,process.once("beforeExit",function(){e._suppressDestroy||e.destroy()}))}return t.prototype.suppressDestroy=function(){this._suppressDestroy=!0},t.prototype.getRuntimeVersions=function(){return{version:b,NODE_API_SUPPORTED_VERSION_MAX:10,NAPI_VERSION_EXPERIMENTAL:z,NODE_API_DEFAULT_MODULE_API_VERSION:8}},t.prototype.createNotSupportWeakRefError=function(t,e){return new j(t,e)},t.prototype.createNotSupportBufferError=function(t,e){return new A(t,e)},t.prototype.createReference=function(t,e,n,i){return W.create(t,e,n,i)},t.prototype.createReferenceWithData=function(t,e,n,i,r){return P.create(t,e,n,i,r)},t.prototype.createReferenceWithFinalizer=function(t,e,n,i,r,o,s){return void 0===r&&(r=0),void 0===o&&(o=0),void 0===s&&(s=0),L.create(t,e,n,i,r,o,s)},t.prototype.createDeferred=function(t){return U.create(this,t)},t.prototype.adjustAmountOfExternalAllocatedMemory=function(t){return this._externalMemory.adjust(t)},t.prototype.createEnv=function(t,e,n,i,r,o){return R(this,t,e,n,i,r,o)},t.prototype.createTrackedFinalizer=function(t,e,n,i){return F.create(t,e,n,i)},t.prototype.getCurrentScope=function(){return this.scopeStore.currentScope},t.prototype.addToCurrentScope=function(t){return this.scopeStore.currentScope.add(t)},t.prototype.openScope=function(t){var e=this.scopeStore.openScope(this.handleStore);return t&&t.openHandleScopes++,e},t.prototype.closeScope=function(t,e){t&&0===t.openHandleScopes||(this.scopeStore.closeScope(),t&&t.openHandleScopes--)},t.prototype.ensureHandle=function(t){switch(t){case void 0:return m.UNDEFINED;case null:return m.NULL;case!0:return m.TRUE;case!1:return m.FALSE;case u:return m.GLOBAL}return this.addToCurrentScope(t)},t.prototype.addCleanupHook=function(t,e,n){this.cleanupQueue.add(t,e,n)},t.prototype.removeCleanupHook=function(t,e,n){this.cleanupQueue.remove(t,e,n)},t.prototype.runCleanup=function(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()},t.prototype.increaseWaitingRequestCounter=function(){var t;null===(t=this.refCounter)||void 0===t||t.increase()},t.prototype.decreaseWaitingRequestCounter=function(){var t;null===(t=this.refCounter)||void 0===t||t.decrease()},t.prototype.setCanCallIntoJs=function(t){this._canCallIntoJs=t},t.prototype.setStopping=function(t){this._isStopping=t},t.prototype.canCallIntoJs=function(){return this._canCallIntoJs&&!this._isStopping},t.prototype.destroy=function(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()},t}();function Z(t){return new Y(t)}t.ConstHandle=k,t.Context=Y,t.Deferred=U,t.EmnapiError=N,t.Env=I,t.External=o,t.Finalizer=x,t.Handle=w,t.HandleScope=E,t.HandleStore=m,t.NAPI_VERSION_EXPERIMENTAL=z,t.NODE_API_DEFAULT_MODULE_API_VERSION=8,t.NODE_API_SUPPORTED_VERSION_MAX=10,t.NODE_API_SUPPORTED_VERSION_MIN=1,t.NodeEnv=D,t.NotSupportBufferError=A,t.NotSupportWeakRefError=j,t.Persistent=M,t.RefTracker=C,t.Reference=W,t.ReferenceWithData=P,t.ReferenceWithFinalizer=L,t.ScopeStore=S,t.Store=V,t.TrackedFinalizer=F,t.TryCatch=c,t.createContext=Z,t.getDefaultContext=function(){return T||(T=Z()),T},t.getExternalValue=s,t.isExternal=r,t.isReferenceType=function(t){return"object"==typeof t&&null!==t||"function"==typeof t},t.version=b});
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.min.mjs ADDED
@@ -0,0 +1 @@
 
 
1
+ const e=new WeakMap;function t(t){return e.has(t)}const i=(()=>{function t(t){Object.setPrototypeOf(this,null),e.set(this,t)}return t.prototype=null,t})();function n(i){if(!t(i))throw new TypeError("not external");return e.get(i)}const s=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),r=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&s)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}();class a{constructor(){this._exception=void 0,this._caught=!1}isEmpty(){return!this._caught}hasCaught(){return this._caught}exception(){return this._exception}setError(e){this._caught=!0,this._exception=e}reset(){this._caught=!1,this._exception=void 0}extractException(){const e=this._exception;return this.reset(),e}}const o=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),l="object"==typeof Reflect,c="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,u=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),h="undefined"!=typeof BigInt;function p(e){return"object"==typeof e&&null!==e||"function"==typeof e}const f=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),d="function"==typeof MessageChannel?MessageChannel:function(){try{return f("worker_threads").MessageChannel}catch(e){}}(),_="function"==typeof setImmediate?setImmediate.bind(r):function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(d){let t=new d;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},v="function"==typeof Buffer?Buffer:function(){try{return f("buffer").Buffer}catch(e){}}(),g="1.11.3",y=1,b=10,z=2147483647,k=8;class w{constructor(e,t){this.id=e,this.value=t}data(){return n(this.value)}isNumber(){return"number"==typeof this.value}isBigInt(){return"bigint"==typeof this.value}isString(){return"string"==typeof this.value}isFunction(){return"function"==typeof this.value}isExternal(){return t(this.value)}isObject(){return"object"==typeof this.value&&null!==this.value}isArray(){return Array.isArray(this.value)}isArrayBuffer(){return this.value instanceof ArrayBuffer}isTypedArray(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(e){return!!ArrayBuffer.isView(this.value)||(null!=e||(e=v),"function"==typeof e&&e.isBuffer(this.value))}isDataView(){return this.value instanceof DataView}isDate(){return this.value instanceof Date}isPromise(){return this.value instanceof Promise}isBoolean(){return"boolean"==typeof this.value}isUndefined(){return void 0===this.value}isSymbol(){return"symbol"==typeof this.value}isNull(){return null===this.value}dispose(){this.value=void 0}}class m extends w{constructor(e,t){super(e,t)}dispose(){}}class C{constructor(){this._values=[void 0,C.UNDEFINED,C.NULL,C.FALSE,C.TRUE,C.GLOBAL],this._next=C.MIN_ID}push(e){let t;const i=this._next,n=this._values;return i<n.length?(t=n[i],t.value=e):(t=new w(i,e),n[i]=t),this._next++,t}erase(e,t){this._next=e;const i=this._values;for(let n=e;n<t;++n)i[n].dispose()}get(e){return this._values[e]}swap(e,t){const i=this._values,n=i[e];i[e]=i[t],i[e].id=Number(e),i[t]=n,n.id=Number(t)}dispose(){this._values.length=C.MIN_ID,this._next=C.MIN_ID}}C.UNDEFINED=new m(1,void 0),C.NULL=new m(2,null),C.FALSE=new m(3,!1),C.TRUE=new m(4,!0),C.GLOBAL=new m(5,r),C.MIN_ID=6;class S{constructor(e,t,i,n,s=n){this.handleStore=e,this.id=t,this.parent=i,this.child=null,null!==i&&(i.child=this),this.start=n,this.end=s,this._escapeCalled=!1,this.callbackInfo={thiz:void 0,data:0,args:void 0,fn:void 0}}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e){return this.add(new i(e))}dispose(){this._escapeCalled&&(this._escapeCalled=!1),this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class x{constructor(){this._rootScope=new S(null,0,null,1,C.MIN_ID),this.currentScope=this._rootScope,this._values=[void 0]}get(e){return this._values[e]}openScope(e){const t=this.currentScope;let i=t.child;if(null!==i)i.start=i.end=t.end;else{const n=t.id+1;i=new S(e,n,t,t.end),this._values[n]=i}return this.currentScope=i,i}closeScope(){const e=this.currentScope;this.currentScope=e.parent,e.dispose()}dispose(){this.currentScope=this._rootScope,this._values.length=1}}class E{constructor(){this._next=null,this._prev=null}dispose(){}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class F{constructor(e,t=0,i=0,n=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=i,this._finalizeHint=n,this._makeDynCall_vppp=e.makeDynCall_vppp}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetEnv(){this.envObject=void 0}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}callFinalizer(){const e=this._finalizeCallback,t=this._finalizeData,i=this._finalizeHint;if(this.resetFinalizer(),!e)return;const n=Number(e);this.envObject?this.envObject.callFinalizer(n,t,i):this._makeDynCall_vppp(n)(0,t,i)}dispose(){this.envObject=void 0,this._makeDynCall_vppp=void 0}}class I extends E{static create(e,t,i,n){const s=new I(e,t,i,n);return s.link(e.finalizing_reflist),s}constructor(e,t,i,n){super(),this._finalizer=new F(e,t,i,n)}data(){return this._finalizer.data()}dispose(){this._finalizer&&(this.unlink(),this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),this._finalizer=void 0,super.dispose())}finalize(){let e;this.unlink();let t=!1;try{this._finalizer.callFinalizer()}catch(i){t=!0,e=i}if(this.dispose(),t)throw e}}function D(e,t){if(!e.terminatedOrTerminating())throw t}class O{constructor(e,t,i,n,s){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=i,this.makeDynCall_vp=n,this.abort=s,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new a,this.refs=1,this.reflist=new E,this.finalizing_reflist=new E,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,this._bindingMap=new WeakMap,this.id=0}canCallIntoJs(){return!0}terminatedOrTerminating(){return!this.canCallIntoJs()}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return 0!==e.errorCode&&(e.errorCode=0),0!==e.engineErrorCode&&(e.engineErrorCode=0),0!==e.engineReserved&&(e.engineReserved=0),0}setLastError(e,t=0,i=0){const n=this.lastError;return n.errorCode!==e&&(n.errorCode=e),n.engineErrorCode!==t&&(n.engineErrorCode=t),n.engineReserved!==i&&(n.engineReserved=i),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=D){const i=this.openHandleScopes;this.clearLastError();const n=e(this);if(i!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return n}invokeFinalizerFromGC(e){if(this.moduleApiVersion!==z)this.enqueueFinalizer(e);else{const t=this.inGcFinalizer;this.inGcFinalizer=!0;try{e.finalize()}finally{this.inGcFinalizer=t}}}checkGCAccess(){this.moduleApiVersion===z&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e)}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}deleteMe(){E.finalizeAll(this.finalizing_reflist),E.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),this.finalizing_reflist.dispose(),this.reflist.dispose(),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,i){this.instanceData&&this.instanceData.dispose(),this.instanceData=I.create(this,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class j extends O{constructor(e,t,i,n,s,r,a){super(e,i,n,s,r),this.filename=t,this.nodeBinding=a,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return super.canCallIntoJs()&&this.ctx.canCallIntoJs()}triggerFatalException(e){if(this.nodeBinding)this.nodeBinding.napi.fatalException(e);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw e;process._fatalException(e)||(console.error(e),process.exit(1))}}callbackIntoModule(e,t){return this.callIntoModule(t,(t,i)=>{if(t.terminatedOrTerminating())return;const n="object"==typeof process&&null!==process,s=!!n&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(t.moduleApiVersion<10&&!s&&!e){return void(n&&"function"==typeof process.emitWarning?process.emitWarning:function(e,t,i){if(e instanceof Error)console.warn(e.toString());else{const n=i?`[${i}] `:"";console.warn(`${n}${t||"Warning"}: ${e}`)}})("Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168")}t.triggerFatalException(i)})}callFinalizer(e,t,i){this.callFinalizerInternal(1,e,t,i)}callFinalizerInternal(e,t,i,n){const s=this.makeDynCall_vppp(t),r=this.id,a=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),()=>{s(r,i,n)})}finally{this.ctx.closeScope(this,a)}}enqueueFinalizer(e){super.enqueueFinalizer(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),_(()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()}))}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}}function B(e,t,i,n,s,r,a){(i="number"!=typeof i?8:i)<8?i=8:i>10&&i!==z&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version 10 add-ons.`)}(t,i);const o=new j(e,t,i,n,s,r,a);return e.envStore.add(o),e.addCleanupHook(o,()=>{o.unref()},0),o}class H extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof H)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,i):this.__proto__=i,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(H.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class R extends H{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(R.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class N extends H{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(N.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class A{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class M{constructor(e){this._ref=new A(e)}setWeak(e,t){if(!c||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{M._registry.register(i,this,this);const n=new WeakRef(i);this._ref.dispose(),this._ref=n,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof i)throw e}}clearWeak(){if(c&&void 0!==this._ref&&this._ref instanceof WeakRef){try{M._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new A(e)}}reset(){if(c)try{M._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof A&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}var W;M._registry=c?new FinalizationRegistry(e=>{e._ref=void 0;const t=e._callback,i=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(i)}):void 0,function(e){e[e.kRuntime=0]="kRuntime",e[e.kUserland=1]="kUserland"}(W||(W={}));class L extends E{static weakCallback(e){e.persistent.reset(),e.invokeFinalizerFromGC()}static create(e,t,i,n,s,r,a){const o=new L(e,t,i,n);return e.ctx.refStore.add(o),o.link(e.reflist),o}constructor(e,t,i,n){super(),this.envObject=e,this._refcount=i,this._ownership=n;const s=e.ctx.handleStore.get(t);var r;this.canBeWeak=(r=s).isObject()||r.isFunction()||r.isSymbol(),this.persistent=new M(s.value),this.id=0,0===i&&this._setWeak()}ref(){return this.persistent.isEmpty()?0:(1===++this._refcount&&this.canBeWeak&&this.persistent.clearWeak(),this._refcount)}unref(){return this.persistent.isEmpty()||0===this._refcount?0:(0===--this._refcount&&this._setWeak(),this._refcount)}get(e=this.envObject){if(this.persistent.isEmpty())return 0;const t=this.persistent.deref();return e.ensureHandle(t).id}resetFinalizer(){}data(){return 0}refcount(){return this._refcount}ownership(){return this._ownership}callUserFinalizer(){}invokeFinalizerFromGC(){this.finalize()}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,L.weakCallback):this.persistent.reset()}finalize(){this.persistent.reset();const e=this._ownership===W.kRuntime;this.unlink(),this.callUserFinalizer(),e&&this.dispose()}dispose(){0!==this.id&&(this.unlink(),this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.envObject=void 0,this.id=0)}}class T extends L{static create(e,t,i,n,s){const r=new T(e,t,i,n,s);return e.ctx.refStore.add(r),r.link(e.reflist),r}constructor(e,t,i,n,s){super(e,t,i,n),this._data=s}data(){return this._data}}class U extends L{static create(e,t,i,n,s,r,a){const o=new U(e,t,i,n,s,r,a);return e.ctx.refStore.add(o),o.link(e.finalizing_reflist),o}constructor(e,t,i,n,s,r,a){super(e,t,i,n),this._finalizer=new F(e,s,r,a)}resetFinalizer(){this._finalizer.resetFinalizer()}data(){return this._finalizer.data()}callUserFinalizer(){this._finalizer.callFinalizer()}invokeFinalizerFromGC(){this._finalizer.envObject.invokeFinalizerFromGC(this)}dispose(){this._finalizer&&(this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),super.dispose(),this._finalizer=void 0)}}class P{static create(e,t){const i=new P(e,t);return e.deferredStore.add(i),i}constructor(e,t){Object.defineProperties(this,{id:{configurable:!0,enumerable:!0,value:0,writable:!0},ctx:{configurable:!0,enumerable:!0,value:e,writable:!0},value:{configurable:!0,enumerable:!0,value:t,writable:!0}})}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class G{constructor(){this._values=[void 0],this._values.length=4,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=e+(e>>1)+16)}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}const q=BigInt(1)<<BigInt(60),V=-q;class ${constructor(e){this.total=BigInt(0),this.onChange=null!=e?e:null}adjust(e){if(e=BigInt(e),!(V<=e&&e<q))throw new RangeError(`changeInBytes ${e} is out of reasonable range`);const t=this.total;this.total+=e;const i=this.total,n=this.onChange;return e&&(null==n||n(i,t,e)),i}}class J{constructor(e,t,i,n){this.envObject=e,this.fn=t,this.arg=i,this.order=n}}class Q{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,i){if(this._cleanupHooks.filter(n=>n.envObject===e&&n.fn===t&&n.arg===i).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new J(e,t,i,this._cleanupHookCounter++))}remove(e,t,i){for(let n=0;n<this._cleanupHooks.length;++n){const s=this._cleanupHooks[n];if(s.envObject===e&&s.fn===t&&s.arg===i)return void this._cleanupHooks.splice(n,1)}}drain(){const e=this._cleanupHooks.slice();e.sort((e,t)=>t.order-e.order);for(let t=0;t<e.length;++t){const i=e[t];"number"==typeof i.fn?i.envObject.makeDynCall_vp(i.fn)(i.arg):i.fn(i.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(i),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class X{constructor(){this.refHandle=(new d).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref&&this.refHandle.unref(),this.count--)}}class K{constructor(e){this._isStopping=!1,this._canCallIntoJs=!0,this._suppressDestroy=!1,this.envStore=new G,this.scopeStore=new x,this.refStore=new G,this.deferredStore=new G,this.handleStore=new C,this.feature={supportReflect:l,supportFinalizer:c,supportWeakSymbol:u,supportBigInt:h,supportNewFunction:s,canSetFunctionName:o,setImmediate:_,Buffer:v,MessageChannel:d},this.cleanupQueue=new Q,this._externalMemory=new $(null==e?void 0:e.onExternalMemoryChange),"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new X,process.once("beforeExit",()=>{this._suppressDestroy||this.destroy()}))}suppressDestroy(){this._suppressDestroy=!0}getRuntimeVersions(){return{version:g,NODE_API_SUPPORTED_VERSION_MAX:10,NAPI_VERSION_EXPERIMENTAL:z,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new R(e,t)}createNotSupportBufferError(e,t){return new N(e,t)}createReference(e,t,i,n){return L.create(e,t,i,n)}createReferenceWithData(e,t,i,n,s){return T.create(e,t,i,n,s)}createReferenceWithFinalizer(e,t,i,n,s=0,r=0,a=0){return U.create(e,t,i,n,s,r,a)}createDeferred(e){return P.create(this,e)}adjustAmountOfExternalAllocatedMemory(e){return this._externalMemory.adjust(e)}createEnv(e,t,i,n,s,r){return B(this,e,t,i,n,s,r)}createTrackedFinalizer(e,t,i,n){return I.create(e,t,i,n)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){const t=this.scopeStore.openScope(this.handleStore);return e&&e.openHandleScopes++,t}closeScope(e,t){e&&0===e.openHandleScopes||(this.scopeStore.closeScope(),e&&e.openHandleScopes--)}ensureHandle(e){switch(e){case void 0:return C.UNDEFINED;case null:return C.NULL;case!0:return C.TRUE;case!1:return C.FALSE;case r:return C.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,i){this.cleanupQueue.add(e,t,i)}removeCleanupHook(e,t,i){this.cleanupQueue.remove(e,t,i)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}setCanCallIntoJs(e){this._canCallIntoJs=e}setStopping(e){this._isStopping=e}canCallIntoJs(){return this._canCallIntoJs&&!this._isStopping}destroy(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()}}let Y;function Z(e){return new K(e)}function ee(){return Y||(Y=Z()),Y}export{m as ConstHandle,K as Context,P as Deferred,H as EmnapiError,O as Env,i as External,F as Finalizer,w as Handle,S as HandleScope,C as HandleStore,z as NAPI_VERSION_EXPERIMENTAL,k as NODE_API_DEFAULT_MODULE_API_VERSION,b as NODE_API_SUPPORTED_VERSION_MAX,y as NODE_API_SUPPORTED_VERSION_MIN,j as NodeEnv,N as NotSupportBufferError,R as NotSupportWeakRefError,M as Persistent,E as RefTracker,L as Reference,W as ReferenceOwnership,T as ReferenceWithData,U as ReferenceWithFinalizer,x as ScopeStore,G as Store,I as TrackedFinalizer,a as TryCatch,Z as createContext,ee as getDefaultContext,n as getExternalValue,t as isExternal,p as isReferenceType,g as version};
astra_scene_test/X_03/node_modules/@emnapi/runtime/dist/emnapi.mjs ADDED
@@ -0,0 +1,1367 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.bind(_global)
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.11.3";
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(handleStore) {
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(handleStore, id, currentScope, currentScope.end);
361
+ this._values[id] = scope;
362
+ }
363
+ this.currentScope = scope;
364
+ return scope;
365
+ }
366
+ closeScope() {
367
+ const scope = this.currentScope;
368
+ this.currentScope = scope.parent;
369
+ scope.dispose();
370
+ }
371
+ dispose() {
372
+ this.currentScope = this._rootScope;
373
+ this._values.length = 1;
374
+ }
375
+ }
376
+
377
+ class RefTracker {
378
+ constructor() {
379
+ this._next = null;
380
+ this._prev = null;
381
+ }
382
+ dispose() { }
383
+ finalize() { }
384
+ link(list) {
385
+ this._prev = list;
386
+ this._next = list._next;
387
+ if (this._next !== null) {
388
+ this._next._prev = this;
389
+ }
390
+ list._next = this;
391
+ }
392
+ unlink() {
393
+ if (this._prev !== null) {
394
+ this._prev._next = this._next;
395
+ }
396
+ if (this._next !== null) {
397
+ this._next._prev = this._prev;
398
+ }
399
+ this._prev = null;
400
+ this._next = null;
401
+ }
402
+ static finalizeAll(list) {
403
+ while (list._next !== null) {
404
+ list._next.finalize();
405
+ }
406
+ }
407
+ }
408
+
409
+ class Finalizer {
410
+ constructor(envObject, _finalizeCallback = 0, _finalizeData = 0, _finalizeHint = 0) {
411
+ this.envObject = envObject;
412
+ this._finalizeCallback = _finalizeCallback;
413
+ this._finalizeData = _finalizeData;
414
+ this._finalizeHint = _finalizeHint;
415
+ this._makeDynCall_vppp = envObject.makeDynCall_vppp;
416
+ }
417
+ callback() { return this._finalizeCallback; }
418
+ data() { return this._finalizeData; }
419
+ hint() { return this._finalizeHint; }
420
+ resetEnv() {
421
+ this.envObject = undefined;
422
+ }
423
+ resetFinalizer() {
424
+ this._finalizeCallback = 0;
425
+ this._finalizeData = 0;
426
+ this._finalizeHint = 0;
427
+ }
428
+ callFinalizer() {
429
+ const finalize_callback = this._finalizeCallback;
430
+ const finalize_data = this._finalizeData;
431
+ const finalize_hint = this._finalizeHint;
432
+ this.resetFinalizer();
433
+ if (!finalize_callback)
434
+ return;
435
+ const fini = Number(finalize_callback);
436
+ if (!this.envObject) {
437
+ this._makeDynCall_vppp(fini)(0, finalize_data, finalize_hint);
438
+ }
439
+ else {
440
+ this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
441
+ }
442
+ }
443
+ dispose() {
444
+ this.envObject = undefined;
445
+ this._makeDynCall_vppp = undefined;
446
+ }
447
+ }
448
+
449
+ class TrackedFinalizer extends RefTracker {
450
+ static create(envObject, finalize_callback, finalize_data, finalize_hint) {
451
+ const finalizer = new TrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint);
452
+ finalizer.link(envObject.finalizing_reflist);
453
+ return finalizer;
454
+ }
455
+ constructor(envObject, finalize_callback, finalize_data, finalize_hint) {
456
+ super();
457
+ this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
458
+ }
459
+ data() {
460
+ return this._finalizer.data();
461
+ }
462
+ dispose() {
463
+ if (!this._finalizer)
464
+ return;
465
+ this.unlink();
466
+ this._finalizer.envObject.dequeueFinalizer(this);
467
+ this._finalizer.dispose();
468
+ this._finalizer = undefined;
469
+ super.dispose();
470
+ }
471
+ finalize() {
472
+ this.unlink();
473
+ let error;
474
+ let caught = false;
475
+ try {
476
+ this._finalizer.callFinalizer();
477
+ }
478
+ catch (err) {
479
+ caught = true;
480
+ error = err;
481
+ }
482
+ this.dispose();
483
+ if (caught) {
484
+ throw error;
485
+ }
486
+ }
487
+ }
488
+
489
+ function throwNodeApiVersionError(moduleName, moduleApiVersion) {
490
+ const errorMessage = `${moduleName} requires Node-API version ${moduleApiVersion}, but this version of Node.js only supports version ${NODE_API_SUPPORTED_VERSION_MAX} add-ons.`;
491
+ throw new Error(errorMessage);
492
+ }
493
+ function handleThrow(envObject, value) {
494
+ if (envObject.terminatedOrTerminating()) {
495
+ return;
496
+ }
497
+ throw value;
498
+ }
499
+ class Env {
500
+ constructor(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort) {
501
+ this.ctx = ctx;
502
+ this.moduleApiVersion = moduleApiVersion;
503
+ this.makeDynCall_vppp = makeDynCall_vppp;
504
+ this.makeDynCall_vp = makeDynCall_vp;
505
+ this.abort = abort;
506
+ this.openHandleScopes = 0;
507
+ this.instanceData = null;
508
+ this.tryCatch = new TryCatch();
509
+ this.refs = 1;
510
+ this.reflist = new RefTracker();
511
+ this.finalizing_reflist = new RefTracker();
512
+ this.pendingFinalizers = [];
513
+ this.lastError = {
514
+ errorCode: 0,
515
+ engineErrorCode: 0,
516
+ engineReserved: 0
517
+ };
518
+ this.inGcFinalizer = false;
519
+ this._bindingMap = new WeakMap();
520
+ this.id = 0;
521
+ }
522
+ canCallIntoJs() {
523
+ return true;
524
+ }
525
+ terminatedOrTerminating() {
526
+ return !this.canCallIntoJs();
527
+ }
528
+ ref() {
529
+ this.refs++;
530
+ }
531
+ unref() {
532
+ this.refs--;
533
+ if (this.refs === 0) {
534
+ this.dispose();
535
+ }
536
+ }
537
+ ensureHandle(value) {
538
+ return this.ctx.ensureHandle(value);
539
+ }
540
+ ensureHandleId(value) {
541
+ return this.ensureHandle(value).id;
542
+ }
543
+ clearLastError() {
544
+ const lastError = this.lastError;
545
+ if (lastError.errorCode !== 0)
546
+ lastError.errorCode = 0;
547
+ if (lastError.engineErrorCode !== 0)
548
+ lastError.engineErrorCode = 0;
549
+ if (lastError.engineReserved !== 0)
550
+ lastError.engineReserved = 0;
551
+ return 0;
552
+ }
553
+ setLastError(error_code, engine_error_code = 0, engine_reserved = 0) {
554
+ const lastError = this.lastError;
555
+ if (lastError.errorCode !== error_code)
556
+ lastError.errorCode = error_code;
557
+ if (lastError.engineErrorCode !== engine_error_code)
558
+ lastError.engineErrorCode = engine_error_code;
559
+ if (lastError.engineReserved !== engine_reserved)
560
+ lastError.engineReserved = engine_reserved;
561
+ return error_code;
562
+ }
563
+ getReturnStatus() {
564
+ return !this.tryCatch.hasCaught() ? 0 : this.setLastError(10);
565
+ }
566
+ callIntoModule(fn, handleException = handleThrow) {
567
+ const openHandleScopesBefore = this.openHandleScopes;
568
+ this.clearLastError();
569
+ const r = fn(this);
570
+ if (openHandleScopesBefore !== this.openHandleScopes) {
571
+ this.abort('open_handle_scopes != open_handle_scopes_before');
572
+ }
573
+ if (this.tryCatch.hasCaught()) {
574
+ const err = this.tryCatch.extractException();
575
+ handleException(this, err);
576
+ }
577
+ return r;
578
+ }
579
+ invokeFinalizerFromGC(finalizer) {
580
+ if (this.moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
581
+ this.enqueueFinalizer(finalizer);
582
+ }
583
+ else {
584
+ const saved = this.inGcFinalizer;
585
+ this.inGcFinalizer = true;
586
+ try {
587
+ finalizer.finalize();
588
+ }
589
+ finally {
590
+ this.inGcFinalizer = saved;
591
+ }
592
+ }
593
+ }
594
+ checkGCAccess() {
595
+ if (this.moduleApiVersion === NAPI_VERSION_EXPERIMENTAL && this.inGcFinalizer) {
596
+ this.abort('Finalizer is calling a function that may affect GC state.\n' +
597
+ 'The finalizers are run directly from GC and must not affect GC ' +
598
+ 'state.\n' +
599
+ 'Use `node_api_post_finalizer` from inside of the finalizer to work ' +
600
+ 'around this issue.\n' +
601
+ 'It schedules the call as a new task in the event loop.');
602
+ }
603
+ }
604
+ enqueueFinalizer(finalizer) {
605
+ if (this.pendingFinalizers.indexOf(finalizer) === -1) {
606
+ this.pendingFinalizers.push(finalizer);
607
+ }
608
+ }
609
+ dequeueFinalizer(finalizer) {
610
+ const index = this.pendingFinalizers.indexOf(finalizer);
611
+ if (index !== -1) {
612
+ this.pendingFinalizers.splice(index, 1);
613
+ }
614
+ }
615
+ deleteMe() {
616
+ RefTracker.finalizeAll(this.finalizing_reflist);
617
+ RefTracker.finalizeAll(this.reflist);
618
+ this.tryCatch.extractException();
619
+ this.ctx.envStore.remove(this.id);
620
+ }
621
+ dispose() {
622
+ if (this.id === 0)
623
+ return;
624
+ this.deleteMe();
625
+ this.finalizing_reflist.dispose();
626
+ this.reflist.dispose();
627
+ this.id = 0;
628
+ }
629
+ initObjectBinding(value) {
630
+ const binding = {
631
+ wrapped: 0,
632
+ tag: null
633
+ };
634
+ this._bindingMap.set(value, binding);
635
+ return binding;
636
+ }
637
+ getObjectBinding(value) {
638
+ if (this._bindingMap.has(value)) {
639
+ return this._bindingMap.get(value);
640
+ }
641
+ return this.initObjectBinding(value);
642
+ }
643
+ setInstanceData(data, finalize_cb, finalize_hint) {
644
+ if (this.instanceData) {
645
+ this.instanceData.dispose();
646
+ }
647
+ this.instanceData = TrackedFinalizer.create(this, finalize_cb, data, finalize_hint);
648
+ }
649
+ getInstanceData() {
650
+ return this.instanceData ? this.instanceData.data() : 0;
651
+ }
652
+ }
653
+ class NodeEnv extends Env {
654
+ constructor(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
655
+ super(ctx, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort);
656
+ this.filename = filename;
657
+ this.nodeBinding = nodeBinding;
658
+ this.destructing = false;
659
+ this.finalizationScheduled = false;
660
+ }
661
+ deleteMe() {
662
+ this.destructing = true;
663
+ this.drainFinalizerQueue();
664
+ super.deleteMe();
665
+ }
666
+ canCallIntoJs() {
667
+ return super.canCallIntoJs() && this.ctx.canCallIntoJs();
668
+ }
669
+ triggerFatalException(err) {
670
+ if (this.nodeBinding) {
671
+ this.nodeBinding.napi.fatalException(err);
672
+ }
673
+ else {
674
+ if (typeof process === 'object' && process !== null && typeof process._fatalException === 'function') {
675
+ const handled = process._fatalException(err);
676
+ if (!handled) {
677
+ console.error(err);
678
+ process.exit(1);
679
+ }
680
+ }
681
+ else {
682
+ throw err;
683
+ }
684
+ }
685
+ }
686
+ callbackIntoModule(enforceUncaughtExceptionPolicy, fn) {
687
+ return this.callIntoModule(fn, (envObject, err) => {
688
+ if (envObject.terminatedOrTerminating()) {
689
+ return;
690
+ }
691
+ const hasProcess = typeof process === 'object' && process !== null;
692
+ const hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false;
693
+ if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
694
+ const warn = hasProcess && typeof process.emitWarning === 'function'
695
+ ? process.emitWarning
696
+ : function (warning, type, code) {
697
+ if (warning instanceof Error) {
698
+ console.warn(warning.toString());
699
+ }
700
+ else {
701
+ const prefix = code ? `[${code}] ` : '';
702
+ console.warn(`${prefix}${type || 'Warning'}: ${warning}`);
703
+ }
704
+ };
705
+ warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
706
+ return;
707
+ }
708
+ envObject.triggerFatalException(err);
709
+ });
710
+ }
711
+ callFinalizer(cb, data, hint) {
712
+ this.callFinalizerInternal(1, cb, data, hint);
713
+ }
714
+ callFinalizerInternal(forceUncaught, cb, data, hint) {
715
+ const f = this.makeDynCall_vppp(cb);
716
+ const env = this.id;
717
+ const scope = this.ctx.openScope(this);
718
+ try {
719
+ this.callbackIntoModule(Boolean(forceUncaught), () => { f(env, data, hint); });
720
+ }
721
+ finally {
722
+ this.ctx.closeScope(this, scope);
723
+ }
724
+ }
725
+ enqueueFinalizer(finalizer) {
726
+ super.enqueueFinalizer(finalizer);
727
+ if (!this.finalizationScheduled && !this.destructing) {
728
+ this.finalizationScheduled = true;
729
+ this.ref();
730
+ _setImmediate(() => {
731
+ this.finalizationScheduled = false;
732
+ this.unref();
733
+ this.drainFinalizerQueue();
734
+ });
735
+ }
736
+ }
737
+ drainFinalizerQueue() {
738
+ while (this.pendingFinalizers.length > 0) {
739
+ const refTracker = this.pendingFinalizers.shift();
740
+ refTracker.finalize();
741
+ }
742
+ }
743
+ }
744
+ function newEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
745
+ moduleApiVersion = typeof moduleApiVersion !== 'number' ? NODE_API_DEFAULT_MODULE_API_VERSION : moduleApiVersion;
746
+ if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
747
+ moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION;
748
+ }
749
+ else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
750
+ throwNodeApiVersionError(filename, moduleApiVersion);
751
+ }
752
+ const env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
753
+ ctx.envStore.add(env);
754
+ ctx.addCleanupHook(env, () => { env.unref(); }, 0);
755
+ return env;
756
+ }
757
+
758
+ class EmnapiError extends Error {
759
+ constructor(message) {
760
+ super(message);
761
+ const ErrorConstructor = new.target;
762
+ const proto = ErrorConstructor.prototype;
763
+ if (!(this instanceof EmnapiError)) {
764
+ const setPrototypeOf = Object.setPrototypeOf;
765
+ if (typeof setPrototypeOf === 'function') {
766
+ setPrototypeOf.call(Object, this, proto);
767
+ }
768
+ else {
769
+ this.__proto__ = proto;
770
+ }
771
+ if (typeof Error.captureStackTrace === 'function') {
772
+ Error.captureStackTrace(this, ErrorConstructor);
773
+ }
774
+ }
775
+ }
776
+ }
777
+ Object.defineProperty(EmnapiError.prototype, 'name', {
778
+ configurable: true,
779
+ writable: true,
780
+ value: 'EmnapiError'
781
+ });
782
+ class NotSupportWeakRefError extends EmnapiError {
783
+ constructor(api, message) {
784
+ super(`${api}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${message ? ` ${message}` : ''}`);
785
+ }
786
+ }
787
+ Object.defineProperty(NotSupportWeakRefError.prototype, 'name', {
788
+ configurable: true,
789
+ writable: true,
790
+ value: 'NotSupportWeakRefError'
791
+ });
792
+ class NotSupportBufferError extends EmnapiError {
793
+ constructor(api, message) {
794
+ super(`${api}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${message ? ` ${message}` : ''}`);
795
+ }
796
+ }
797
+ Object.defineProperty(NotSupportBufferError.prototype, 'name', {
798
+ configurable: true,
799
+ writable: true,
800
+ value: 'NotSupportBufferError'
801
+ });
802
+
803
+ class StrongRef {
804
+ constructor(value) {
805
+ this._value = value;
806
+ }
807
+ deref() {
808
+ return this._value;
809
+ }
810
+ dispose() {
811
+ this._value = undefined;
812
+ }
813
+ }
814
+ class Persistent {
815
+ constructor(value) {
816
+ this._ref = new StrongRef(value);
817
+ }
818
+ setWeak(param, callback) {
819
+ if (!supportFinalizer || this._ref === undefined || this._ref instanceof WeakRef)
820
+ return;
821
+ const value = this._ref.deref();
822
+ try {
823
+ Persistent._registry.register(value, this, this);
824
+ const weakRef = new WeakRef(value);
825
+ this._ref.dispose();
826
+ this._ref = weakRef;
827
+ this._param = param;
828
+ this._callback = callback;
829
+ }
830
+ catch (err) {
831
+ if (typeof value === 'symbol') ;
832
+ else {
833
+ throw err;
834
+ }
835
+ }
836
+ }
837
+ clearWeak() {
838
+ if (!supportFinalizer || this._ref === undefined)
839
+ return;
840
+ if (this._ref instanceof WeakRef) {
841
+ try {
842
+ Persistent._registry.unregister(this);
843
+ }
844
+ catch (_) { }
845
+ this._param = undefined;
846
+ this._callback = undefined;
847
+ const value = this._ref.deref();
848
+ if (value === undefined) {
849
+ this._ref = value;
850
+ }
851
+ else {
852
+ this._ref = new StrongRef(value);
853
+ }
854
+ }
855
+ }
856
+ reset() {
857
+ if (supportFinalizer) {
858
+ try {
859
+ Persistent._registry.unregister(this);
860
+ }
861
+ catch (_) { }
862
+ }
863
+ this._param = undefined;
864
+ this._callback = undefined;
865
+ if (this._ref instanceof StrongRef) {
866
+ this._ref.dispose();
867
+ }
868
+ this._ref = undefined;
869
+ }
870
+ isEmpty() {
871
+ return this._ref === undefined;
872
+ }
873
+ deref() {
874
+ if (this._ref === undefined)
875
+ return undefined;
876
+ return this._ref.deref();
877
+ }
878
+ }
879
+ Persistent._registry = supportFinalizer
880
+ ? new FinalizationRegistry((value) => {
881
+ value._ref = undefined;
882
+ const callback = value._callback;
883
+ const param = value._param;
884
+ value._callback = undefined;
885
+ value._param = undefined;
886
+ if (typeof callback === 'function') {
887
+ callback(param);
888
+ }
889
+ })
890
+ : undefined;
891
+
892
+ var ReferenceOwnership;
893
+ (function (ReferenceOwnership) {
894
+ ReferenceOwnership[ReferenceOwnership["kRuntime"] = 0] = "kRuntime";
895
+ ReferenceOwnership[ReferenceOwnership["kUserland"] = 1] = "kUserland";
896
+ })(ReferenceOwnership || (ReferenceOwnership = {}));
897
+ function canBeHeldWeakly(value) {
898
+ return value.isObject() || value.isFunction() || value.isSymbol();
899
+ }
900
+ class Reference extends RefTracker {
901
+ static weakCallback(ref) {
902
+ ref.persistent.reset();
903
+ ref.invokeFinalizerFromGC();
904
+ }
905
+ static create(envObject, handle_id, initialRefcount, ownership, _unused1, _unused2, _unused3) {
906
+ const ref = new Reference(envObject, handle_id, initialRefcount, ownership);
907
+ envObject.ctx.refStore.add(ref);
908
+ ref.link(envObject.reflist);
909
+ return ref;
910
+ }
911
+ constructor(envObject, handle_id, initialRefcount, ownership) {
912
+ super();
913
+ this.envObject = envObject;
914
+ this._refcount = initialRefcount;
915
+ this._ownership = ownership;
916
+ const handle = envObject.ctx.handleStore.get(handle_id);
917
+ this.canBeWeak = canBeHeldWeakly(handle);
918
+ this.persistent = new Persistent(handle.value);
919
+ this.id = 0;
920
+ if (initialRefcount === 0) {
921
+ this._setWeak();
922
+ }
923
+ }
924
+ ref() {
925
+ if (this.persistent.isEmpty()) {
926
+ return 0;
927
+ }
928
+ if (++this._refcount === 1 && this.canBeWeak) {
929
+ this.persistent.clearWeak();
930
+ }
931
+ return this._refcount;
932
+ }
933
+ unref() {
934
+ if (this.persistent.isEmpty() || this._refcount === 0) {
935
+ return 0;
936
+ }
937
+ if (--this._refcount === 0) {
938
+ this._setWeak();
939
+ }
940
+ return this._refcount;
941
+ }
942
+ get(envObject = this.envObject) {
943
+ if (this.persistent.isEmpty()) {
944
+ return 0;
945
+ }
946
+ const obj = this.persistent.deref();
947
+ const handle = envObject.ensureHandle(obj);
948
+ return handle.id;
949
+ }
950
+ resetFinalizer() { }
951
+ data() { return 0; }
952
+ refcount() { return this._refcount; }
953
+ ownership() { return this._ownership; }
954
+ callUserFinalizer() { }
955
+ invokeFinalizerFromGC() {
956
+ this.finalize();
957
+ }
958
+ _setWeak() {
959
+ if (this.canBeWeak) {
960
+ this.persistent.setWeak(this, Reference.weakCallback);
961
+ }
962
+ else {
963
+ this.persistent.reset();
964
+ }
965
+ }
966
+ finalize() {
967
+ this.persistent.reset();
968
+ const deleteMe = this._ownership === ReferenceOwnership.kRuntime;
969
+ this.unlink();
970
+ this.callUserFinalizer();
971
+ if (deleteMe) {
972
+ this.dispose();
973
+ }
974
+ }
975
+ dispose() {
976
+ if (this.id === 0)
977
+ return;
978
+ this.unlink();
979
+ this.persistent.reset();
980
+ this.envObject.ctx.refStore.remove(this.id);
981
+ super.dispose();
982
+ this.envObject = undefined;
983
+ this.id = 0;
984
+ }
985
+ }
986
+ class ReferenceWithData extends Reference {
987
+ static create(envObject, value, initialRefcount, ownership, data) {
988
+ const reference = new ReferenceWithData(envObject, value, initialRefcount, ownership, data);
989
+ envObject.ctx.refStore.add(reference);
990
+ reference.link(envObject.reflist);
991
+ return reference;
992
+ }
993
+ constructor(envObject, value, initialRefcount, ownership, _data) {
994
+ super(envObject, value, initialRefcount, ownership);
995
+ this._data = _data;
996
+ }
997
+ data() {
998
+ return this._data;
999
+ }
1000
+ }
1001
+ class ReferenceWithFinalizer extends Reference {
1002
+ static create(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1003
+ const reference = new ReferenceWithFinalizer(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1004
+ envObject.ctx.refStore.add(reference);
1005
+ reference.link(envObject.finalizing_reflist);
1006
+ return reference;
1007
+ }
1008
+ constructor(envObject, value, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
1009
+ super(envObject, value, initialRefcount, ownership);
1010
+ this._finalizer = new Finalizer(envObject, finalize_callback, finalize_data, finalize_hint);
1011
+ }
1012
+ resetFinalizer() {
1013
+ this._finalizer.resetFinalizer();
1014
+ }
1015
+ data() {
1016
+ return this._finalizer.data();
1017
+ }
1018
+ callUserFinalizer() {
1019
+ this._finalizer.callFinalizer();
1020
+ }
1021
+ invokeFinalizerFromGC() {
1022
+ this._finalizer.envObject.invokeFinalizerFromGC(this);
1023
+ }
1024
+ dispose() {
1025
+ if (!this._finalizer)
1026
+ return;
1027
+ this._finalizer.envObject.dequeueFinalizer(this);
1028
+ this._finalizer.dispose();
1029
+ super.dispose();
1030
+ this._finalizer = undefined;
1031
+ }
1032
+ }
1033
+
1034
+ class Deferred {
1035
+ static create(ctx, value) {
1036
+ const deferred = new Deferred(ctx, value);
1037
+ ctx.deferredStore.add(deferred);
1038
+ return deferred;
1039
+ }
1040
+ constructor(ctx, value) {
1041
+ Object.defineProperties(this, {
1042
+ id: {
1043
+ configurable: true,
1044
+ enumerable: true,
1045
+ value: 0,
1046
+ writable: true
1047
+ },
1048
+ ctx: {
1049
+ configurable: true,
1050
+ enumerable: true,
1051
+ value: ctx,
1052
+ writable: true
1053
+ },
1054
+ value: {
1055
+ configurable: true,
1056
+ enumerable: true,
1057
+ value,
1058
+ writable: true
1059
+ }
1060
+ });
1061
+ }
1062
+ resolve(value) {
1063
+ this.value.resolve(value);
1064
+ this.dispose();
1065
+ }
1066
+ reject(reason) {
1067
+ this.value.reject(reason);
1068
+ this.dispose();
1069
+ }
1070
+ dispose() {
1071
+ this.ctx.deferredStore.remove(this.id);
1072
+ this.id = 0;
1073
+ this.value = null;
1074
+ this.ctx = null;
1075
+ }
1076
+ }
1077
+
1078
+ class Store {
1079
+ constructor() {
1080
+ this._values = [undefined];
1081
+ this._values.length = 4;
1082
+ this._size = 1;
1083
+ this._freeList = [];
1084
+ }
1085
+ add(value) {
1086
+ let id;
1087
+ if (this._freeList.length) {
1088
+ id = this._freeList.shift();
1089
+ }
1090
+ else {
1091
+ id = this._size;
1092
+ this._size++;
1093
+ const capacity = this._values.length;
1094
+ if (id >= capacity) {
1095
+ this._values.length = capacity + (capacity >> 1) + 16;
1096
+ }
1097
+ }
1098
+ value.id = id;
1099
+ this._values[id] = value;
1100
+ }
1101
+ get(id) {
1102
+ return this._values[id];
1103
+ }
1104
+ has(id) {
1105
+ return this._values[id] !== undefined;
1106
+ }
1107
+ remove(id) {
1108
+ const value = this._values[id];
1109
+ if (value) {
1110
+ value.id = 0;
1111
+ this._values[id] = undefined;
1112
+ this._freeList.push(Number(id));
1113
+ }
1114
+ }
1115
+ dispose() {
1116
+ for (let i = 1; i < this._size; ++i) {
1117
+ const value = this._values[i];
1118
+ value === null || value === void 0 ? void 0 : value.dispose();
1119
+ }
1120
+ this._values = [undefined];
1121
+ this._size = 1;
1122
+ this._freeList = [];
1123
+ }
1124
+ }
1125
+
1126
+ const kMaxReasonableBytes = BigInt(1) << BigInt(60);
1127
+ const kMinReasonableBytes = -kMaxReasonableBytes;
1128
+ class ExternalMemory {
1129
+ constructor(onChange) {
1130
+ this.total = BigInt(0);
1131
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
1132
+ }
1133
+ adjust(changeInBytes) {
1134
+ changeInBytes = BigInt(changeInBytes);
1135
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
1136
+ throw new RangeError(`changeInBytes ${changeInBytes} is out of reasonable range`);
1137
+ }
1138
+ const old = this.total;
1139
+ this.total += changeInBytes;
1140
+ const amount = this.total;
1141
+ const onChange = this.onChange;
1142
+ if (changeInBytes) {
1143
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
1144
+ }
1145
+ return amount;
1146
+ }
1147
+ }
1148
+
1149
+ class CleanupHookCallback {
1150
+ constructor(envObject, fn, arg, order) {
1151
+ this.envObject = envObject;
1152
+ this.fn = fn;
1153
+ this.arg = arg;
1154
+ this.order = order;
1155
+ }
1156
+ }
1157
+ class CleanupQueue {
1158
+ constructor() {
1159
+ this._cleanupHooks = [];
1160
+ this._cleanupHookCounter = 0;
1161
+ }
1162
+ empty() {
1163
+ return this._cleanupHooks.length === 0;
1164
+ }
1165
+ add(envObject, fn, arg) {
1166
+ if (this._cleanupHooks.filter((hook) => (hook.envObject === envObject && hook.fn === fn && hook.arg === arg)).length > 0) {
1167
+ throw new Error('Can not add same fn and arg twice');
1168
+ }
1169
+ this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++));
1170
+ }
1171
+ remove(envObject, fn, arg) {
1172
+ for (let i = 0; i < this._cleanupHooks.length; ++i) {
1173
+ const hook = this._cleanupHooks[i];
1174
+ if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) {
1175
+ this._cleanupHooks.splice(i, 1);
1176
+ return;
1177
+ }
1178
+ }
1179
+ }
1180
+ drain() {
1181
+ const hooks = this._cleanupHooks.slice();
1182
+ hooks.sort((a, b) => (b.order - a.order));
1183
+ for (let i = 0; i < hooks.length; ++i) {
1184
+ const cb = hooks[i];
1185
+ if (typeof cb.fn === 'number') {
1186
+ cb.envObject.makeDynCall_vp(cb.fn)(cb.arg);
1187
+ }
1188
+ else {
1189
+ cb.fn(cb.arg);
1190
+ }
1191
+ this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1);
1192
+ }
1193
+ }
1194
+ dispose() {
1195
+ this._cleanupHooks.length = 0;
1196
+ this._cleanupHookCounter = 0;
1197
+ }
1198
+ }
1199
+ class NodejsWaitingRequestCounter {
1200
+ constructor() {
1201
+ this.refHandle = new _MessageChannel().port1;
1202
+ this.count = 0;
1203
+ }
1204
+ increase() {
1205
+ if (this.count === 0) {
1206
+ if (this.refHandle.ref) {
1207
+ this.refHandle.ref();
1208
+ }
1209
+ }
1210
+ this.count++;
1211
+ }
1212
+ decrease() {
1213
+ if (this.count === 0)
1214
+ return;
1215
+ if (this.count === 1) {
1216
+ if (this.refHandle.unref) {
1217
+ this.refHandle.unref();
1218
+ }
1219
+ }
1220
+ this.count--;
1221
+ }
1222
+ }
1223
+ class Context {
1224
+ constructor(options) {
1225
+ this._isStopping = false;
1226
+ this._canCallIntoJs = true;
1227
+ this._suppressDestroy = false;
1228
+ this.envStore = new Store();
1229
+ this.scopeStore = new ScopeStore();
1230
+ this.refStore = new Store();
1231
+ this.deferredStore = new Store();
1232
+ this.handleStore = new HandleStore();
1233
+ this.feature = {
1234
+ supportReflect,
1235
+ supportFinalizer,
1236
+ supportWeakSymbol,
1237
+ supportBigInt,
1238
+ supportNewFunction,
1239
+ canSetFunctionName,
1240
+ setImmediate: _setImmediate,
1241
+ Buffer: _Buffer,
1242
+ MessageChannel: _MessageChannel
1243
+ };
1244
+ this.cleanupQueue = new CleanupQueue();
1245
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
1246
+ if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1247
+ this.refCounter = new NodejsWaitingRequestCounter();
1248
+ process.once('beforeExit', () => {
1249
+ if (!this._suppressDestroy) {
1250
+ this.destroy();
1251
+ }
1252
+ });
1253
+ }
1254
+ }
1255
+ suppressDestroy() {
1256
+ this._suppressDestroy = true;
1257
+ }
1258
+ getRuntimeVersions() {
1259
+ return {
1260
+ version,
1261
+ NODE_API_SUPPORTED_VERSION_MAX,
1262
+ NAPI_VERSION_EXPERIMENTAL,
1263
+ NODE_API_DEFAULT_MODULE_API_VERSION
1264
+ };
1265
+ }
1266
+ createNotSupportWeakRefError(api, message) {
1267
+ return new NotSupportWeakRefError(api, message);
1268
+ }
1269
+ createNotSupportBufferError(api, message) {
1270
+ return new NotSupportBufferError(api, message);
1271
+ }
1272
+ createReference(envObject, handle_id, initialRefcount, ownership) {
1273
+ return Reference.create(envObject, handle_id, initialRefcount, ownership);
1274
+ }
1275
+ createReferenceWithData(envObject, handle_id, initialRefcount, ownership, data) {
1276
+ return ReferenceWithData.create(envObject, handle_id, initialRefcount, ownership, data);
1277
+ }
1278
+ createReferenceWithFinalizer(envObject, handle_id, initialRefcount, ownership, finalize_callback = 0, finalize_data = 0, finalize_hint = 0) {
1279
+ return ReferenceWithFinalizer.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
1280
+ }
1281
+ createDeferred(value) {
1282
+ return Deferred.create(this, value);
1283
+ }
1284
+ adjustAmountOfExternalAllocatedMemory(changeInBytes) {
1285
+ return this._externalMemory.adjust(changeInBytes);
1286
+ }
1287
+ createEnv(filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1288
+ return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1289
+ }
1290
+ createTrackedFinalizer(envObject, finalize_callback, finalize_data, finalize_hint) {
1291
+ return TrackedFinalizer.create(envObject, finalize_callback, finalize_data, finalize_hint);
1292
+ }
1293
+ getCurrentScope() {
1294
+ return this.scopeStore.currentScope;
1295
+ }
1296
+ addToCurrentScope(value) {
1297
+ return this.scopeStore.currentScope.add(value);
1298
+ }
1299
+ openScope(envObject) {
1300
+ const scope = this.scopeStore.openScope(this.handleStore);
1301
+ if (envObject)
1302
+ envObject.openHandleScopes++;
1303
+ return scope;
1304
+ }
1305
+ closeScope(envObject, _scope) {
1306
+ if (envObject && envObject.openHandleScopes === 0)
1307
+ return;
1308
+ this.scopeStore.closeScope();
1309
+ if (envObject)
1310
+ envObject.openHandleScopes--;
1311
+ }
1312
+ ensureHandle(value) {
1313
+ switch (value) {
1314
+ case undefined: return HandleStore.UNDEFINED;
1315
+ case null: return HandleStore.NULL;
1316
+ case true: return HandleStore.TRUE;
1317
+ case false: return HandleStore.FALSE;
1318
+ case _global: return HandleStore.GLOBAL;
1319
+ }
1320
+ return this.addToCurrentScope(value);
1321
+ }
1322
+ addCleanupHook(envObject, fn, arg) {
1323
+ this.cleanupQueue.add(envObject, fn, arg);
1324
+ }
1325
+ removeCleanupHook(envObject, fn, arg) {
1326
+ this.cleanupQueue.remove(envObject, fn, arg);
1327
+ }
1328
+ runCleanup() {
1329
+ while (!this.cleanupQueue.empty()) {
1330
+ this.cleanupQueue.drain();
1331
+ }
1332
+ }
1333
+ increaseWaitingRequestCounter() {
1334
+ var _a;
1335
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase();
1336
+ }
1337
+ decreaseWaitingRequestCounter() {
1338
+ var _a;
1339
+ (_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease();
1340
+ }
1341
+ setCanCallIntoJs(value) {
1342
+ this._canCallIntoJs = value;
1343
+ }
1344
+ setStopping(value) {
1345
+ this._isStopping = value;
1346
+ }
1347
+ canCallIntoJs() {
1348
+ return this._canCallIntoJs && !this._isStopping;
1349
+ }
1350
+ destroy() {
1351
+ this.setStopping(true);
1352
+ this.setCanCallIntoJs(false);
1353
+ this.runCleanup();
1354
+ }
1355
+ }
1356
+ let defaultContext;
1357
+ function createContext(options) {
1358
+ return new Context(options);
1359
+ }
1360
+ function getDefaultContext() {
1361
+ if (!defaultContext) {
1362
+ defaultContext = createContext();
1363
+ }
1364
+ return defaultContext;
1365
+ }
1366
+
1367
+ 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 };
astra_scene_test/X_03/node_modules/@emnapi/runtime/index.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') {
2
+ module.exports = require('./dist/emnapi.cjs.min.js')
3
+ } else {
4
+ module.exports = require('./dist/emnapi.cjs.js')
5
+ }
astra_scene_test/X_03/node_modules/@emnapi/runtime/package.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@emnapi/runtime",
3
+ "version": "1.11.3",
4
+ "description": "emnapi runtime",
5
+ "main": "index.js",
6
+ "module": "./dist/emnapi.esm-bundler.js",
7
+ "types": "./dist/emnapi.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": {
12
+ "module": "./dist/emnapi.d.ts",
13
+ "import": "./dist/emnapi.d.mts",
14
+ "default": "./dist/emnapi.d.ts"
15
+ },
16
+ "module": "./dist/emnapi.esm-bundler.js",
17
+ "import": "./dist/emnapi.mjs",
18
+ "default": "./index.js"
19
+ },
20
+ "./dist/emnapi.cjs.min": {
21
+ "types": "./dist/emnapi.d.ts",
22
+ "default": "./dist/emnapi.cjs.min.js"
23
+ },
24
+ "./dist/emnapi.min.mjs": {
25
+ "types": "./dist/emnapi.d.mts",
26
+ "default": "./dist/emnapi.min.mjs"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "tslib": "^2.4.0"
31
+ },
32
+ "scripts": {
33
+ "build": "node ./script/build.js"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/toyobayashi/emnapi.git"
38
+ },
39
+ "author": "toyobayashi",
40
+ "license": "MIT",
41
+ "bugs": {
42
+ "url": "https://github.com/toyobayashi/emnapi/issues"
43
+ },
44
+ "homepage": "https://github.com/toyobayashi/emnapi#readme",
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Toyobayashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/README.md ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # @emnapi/wasi-threads
2
+
3
+ This package makes [wasi-threads proposal](https://github.com/WebAssembly/wasi-threads) based WASI modules work in Node.js and browser.
4
+
5
+ ## Quick Start
6
+
7
+ `index.html`
8
+
9
+ ```html
10
+ <script src="./node_modules/@tybys/wasm-util/dist/wasm-util.js"></script>
11
+ <script src="./node_modules/@emnapi/wasi-threads/dist/wasi-threads.js"></script>
12
+ <script src="./index.js"></script>
13
+ ```
14
+
15
+ If your application will block browser main thread (for example `pthread_join`), please run it in worker instead.
16
+
17
+ ```html
18
+ <script>
19
+ // pthread_join (Atomics.wait) cannot be called in browser main thread
20
+ new Worker('./index.js')
21
+ </script>
22
+ ```
23
+
24
+ `index.js`
25
+
26
+ ```js
27
+ const ENVIRONMENT_IS_NODE =
28
+ typeof process === 'object' && process !== null &&
29
+ typeof process.versions === 'object' && process.versions !== null &&
30
+ typeof process.versions.node === 'string';
31
+
32
+ (function (main) {
33
+ if (ENVIRONMENT_IS_NODE) {
34
+ main(require)
35
+ } else {
36
+ if (typeof importScripts === 'function') {
37
+ importScripts('./node_modules/@tybys/wasm-util/dist/wasm-util.js')
38
+ importScripts('./node_modules/@emnapi/wasi-threads/dist/wasi-threads.js')
39
+ }
40
+ const nodeWasi = { WASI: globalThis.wasmUtil.WASI }
41
+ const nodeWorkerThreads = {
42
+ Worker: globalThis.Worker
43
+ }
44
+ const _require = function (request) {
45
+ if (request === 'node:wasi' || request === 'wasi') return nodeWasi
46
+ if (request === 'node:worker_threads' || request === 'worker_threads') return nodeWorkerThreads
47
+ if (request === '@emnapi/wasi-threads') return globalThis.wasiThreads
48
+ throw new Error('Can not find module: ' + request)
49
+ }
50
+ main(_require)
51
+ }
52
+ })(async function (require) {
53
+ const { WASI } = require('wasi')
54
+ const { Worker } = require('worker_threads')
55
+ const { WASIThreads } = require('@emnapi/wasi-threads')
56
+
57
+ const wasi = new WASI({
58
+ version: 'preview1'
59
+ })
60
+ const wasiThreads = new WASIThreads({
61
+ wasi,
62
+
63
+ /**
64
+ * avoid Atomics.wait() deadlock during thread creation in browser
65
+ * see https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size
66
+ */
67
+ reuseWorker: ENVIRONMENT_IS_NODE
68
+ ? false
69
+ : {
70
+ size: 4 /** greater than actual needs (2) */,
71
+ strict: true
72
+ },
73
+
74
+ /**
75
+ * Synchronous thread creation
76
+ * pthread_create will not return until thread worker actually starts
77
+ */
78
+ waitThreadStart: typeof window === 'undefined' ? 1000 : false,
79
+
80
+ onCreateWorker: () => {
81
+ return new Worker('./worker.js', {
82
+ execArgv: ['--experimental-wasi-unstable-preview1']
83
+ })
84
+ }
85
+ })
86
+ const memory = new WebAssembly.Memory({
87
+ initial: 16777216 / 65536,
88
+ maximum: 2147483648 / 65536,
89
+ shared: true
90
+ })
91
+ let input
92
+ const file = 'path/to/your/wasi-module.wasm'
93
+ try {
94
+ input = require('fs').readFileSync(require('path').join(__dirname, file))
95
+ } catch (err) {
96
+ const response = await fetch(file)
97
+ input = await response.arrayBuffer()
98
+ }
99
+ let { module, instance } = await WebAssembly.instantiate(input, {
100
+ env: { memory },
101
+ wasi_snapshot_preview1: wasi.wasiImport,
102
+ ...wasiThreads.getImportObject()
103
+ })
104
+
105
+ wasiThreads.setup(instance, module, memory)
106
+ await wasiThreads.preloadWorkers()
107
+
108
+ if (typeof instance.exports._start === 'function') {
109
+ return wasi.start(instance)
110
+ } else {
111
+ wasi.initialize(instance)
112
+ // instance.exports.exported_wasm_function()
113
+ }
114
+ })
115
+ ```
116
+
117
+ `worker.js`
118
+
119
+ ```js
120
+ (function (main) {
121
+ const ENVIRONMENT_IS_NODE =
122
+ typeof process === 'object' && process !== null &&
123
+ typeof process.versions === 'object' && process.versions !== null &&
124
+ typeof process.versions.node === 'string'
125
+
126
+ if (ENVIRONMENT_IS_NODE) {
127
+ const _require = function (request) {
128
+ return require(request)
129
+ }
130
+
131
+ const _init = function () {
132
+ const nodeWorkerThreads = require('worker_threads')
133
+ const parentPort = nodeWorkerThreads.parentPort
134
+
135
+ parentPort.on('message', (data) => {
136
+ globalThis.onmessage({ data })
137
+ })
138
+
139
+ Object.assign(globalThis, {
140
+ self: globalThis,
141
+ require,
142
+ Worker: nodeWorkerThreads.Worker,
143
+ importScripts: function (f) {
144
+ (0, eval)(require('fs').readFileSync(f, 'utf8') + '//# sourceURL=' + f)
145
+ },
146
+ postMessage: function (msg) {
147
+ parentPort.postMessage(msg)
148
+ }
149
+ })
150
+ }
151
+
152
+ main(_require, _init)
153
+ } else {
154
+ importScripts('./node_modules/@tybys/wasm-util/dist/wasm-util.js')
155
+ importScripts('./node_modules/@emnapi/wasi-threads/dist/wasi-threads.js')
156
+
157
+ const nodeWasi = { WASI: globalThis.wasmUtil.WASI }
158
+ const _require = function (request) {
159
+ if (request === '@emnapi/wasi-threads') return globalThis.wasiThreads
160
+ if (request === 'node:wasi' || request === 'wasi') return nodeWasi
161
+ throw new Error('Can not find module: ' + request)
162
+ }
163
+ const _init = function () {}
164
+ main(_require, _init)
165
+ }
166
+ })(function main (require, init) {
167
+ init()
168
+
169
+ const { WASI } = require('wasi')
170
+ const { ThreadMessageHandler, WASIThreads } = require('@emnapi/wasi-threads')
171
+
172
+ const handler = new ThreadMessageHandler({
173
+ async onLoad ({ wasmModule, wasmMemory }) {
174
+ const wasi = new WASI({
175
+ version: 'preview1'
176
+ })
177
+
178
+ const wasiThreads = new WASIThreads({
179
+ wasi,
180
+ childThread: true
181
+ })
182
+
183
+ const originalInstance = await WebAssembly.instantiate(wasmModule, {
184
+ env: {
185
+ memory: wasmMemory,
186
+ },
187
+ wasi_snapshot_preview1: wasi.wasiImport,
188
+ ...wasiThreads.getImportObject()
189
+ })
190
+
191
+ // must call `initialize` instead of `start` in child thread
192
+ const instance = wasiThreads.initialize(originalInstance, wasmModule, wasmMemory)
193
+
194
+ return { module: wasmModule, instance }
195
+ }
196
+ })
197
+
198
+ globalThis.onmessage = function (e) {
199
+ handler.handle(e)
200
+ // handle other messages
201
+ }
202
+ })
203
+ ```
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js ADDED
@@ -0,0 +1,894 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const _WebAssembly = typeof WebAssembly !== 'undefined'
2
+ ? WebAssembly
3
+ : typeof WXWebAssembly !== 'undefined'
4
+ ? WXWebAssembly
5
+ : undefined;
6
+ const ENVIRONMENT_IS_NODE = typeof process === 'object' && process !== null &&
7
+ typeof process.versions === 'object' && process.versions !== null &&
8
+ typeof process.versions.node === 'string';
9
+ function getPostMessage(options) {
10
+ return typeof (options === null || options === void 0 ? void 0 : options.postMessage) === 'function'
11
+ ? options.postMessage
12
+ : typeof postMessage === 'function'
13
+ ? postMessage
14
+ : undefined;
15
+ }
16
+ function serizeErrorToBuffer(sab, code, error) {
17
+ const i32array = new Int32Array(sab);
18
+ Atomics.store(i32array, 0, code);
19
+ if (code > 1 && error) {
20
+ const name = error.name;
21
+ const message = error.message;
22
+ const stack = error.stack;
23
+ const nameBuffer = new TextEncoder().encode(name);
24
+ const messageBuffer = new TextEncoder().encode(message);
25
+ const stackBuffer = new TextEncoder().encode(stack);
26
+ Atomics.store(i32array, 1, nameBuffer.length);
27
+ Atomics.store(i32array, 2, messageBuffer.length);
28
+ Atomics.store(i32array, 3, stackBuffer.length);
29
+ const buffer = new Uint8Array(sab);
30
+ buffer.set(nameBuffer, 16);
31
+ buffer.set(messageBuffer, 16 + nameBuffer.length);
32
+ buffer.set(stackBuffer, 16 + nameBuffer.length + messageBuffer.length);
33
+ }
34
+ }
35
+ function deserizeErrorFromBuffer(sab) {
36
+ var _a, _b;
37
+ const i32array = new Int32Array(sab);
38
+ const status = Atomics.load(i32array, 0);
39
+ if (status <= 1) {
40
+ return null;
41
+ }
42
+ const nameLength = Atomics.load(i32array, 1);
43
+ const messageLength = Atomics.load(i32array, 2);
44
+ const stackLength = Atomics.load(i32array, 3);
45
+ const buffer = new Uint8Array(sab);
46
+ const nameBuffer = buffer.slice(16, 16 + nameLength);
47
+ const messageBuffer = buffer.slice(16 + nameLength, 16 + nameLength + messageLength);
48
+ const stackBuffer = buffer.slice(16 + nameLength + messageLength, 16 + nameLength + messageLength + stackLength);
49
+ const name = new TextDecoder().decode(nameBuffer);
50
+ const message = new TextDecoder().decode(messageBuffer);
51
+ const stack = new TextDecoder().decode(stackBuffer);
52
+ const ErrorConstructor = (_a = globalThis[name]) !== null && _a !== void 0 ? _a : (name === 'RuntimeError' ? ((_b = _WebAssembly.RuntimeError) !== null && _b !== void 0 ? _b : Error) : Error);
53
+ const error = new ErrorConstructor(message);
54
+ Object.defineProperty(error, 'stack', {
55
+ value: stack,
56
+ writable: true,
57
+ enumerable: false,
58
+ configurable: true
59
+ });
60
+ return error;
61
+ }
62
+ function isSharedArrayBuffer(value) {
63
+ return ((typeof SharedArrayBuffer === 'function' && value instanceof SharedArrayBuffer) ||
64
+ (Object.prototype.toString.call(value) === '[object SharedArrayBuffer]'));
65
+ }
66
+ function isTrapError(e) {
67
+ try {
68
+ return e instanceof _WebAssembly.RuntimeError;
69
+ }
70
+ catch (_) {
71
+ return false;
72
+ }
73
+ }
74
+
75
+ function createMessage(type, payload) {
76
+ return {
77
+ __emnapi__: {
78
+ type,
79
+ payload
80
+ }
81
+ };
82
+ }
83
+
84
+ const WASI_THREADS_MAX_TID = 0x1FFFFFFF;
85
+ function checkSharedWasmMemory(wasmMemory) {
86
+ if (wasmMemory) {
87
+ if (!isSharedArrayBuffer(wasmMemory.buffer)) {
88
+ throw new Error('Multithread features require shared wasm memory. ' +
89
+ 'Try to compile with `-matomics -mbulk-memory` and use `--import-memory --shared-memory` during linking, ' +
90
+ 'then create WebAssembly.Memory with `shared: true` option');
91
+ }
92
+ }
93
+ else {
94
+ if (typeof SharedArrayBuffer === 'undefined') {
95
+ throw new Error('Current environment does not support SharedArrayBuffer, threads are not available!');
96
+ }
97
+ }
98
+ }
99
+ function getReuseWorker(value) {
100
+ var _a;
101
+ if (typeof value === 'boolean') {
102
+ return value ? { size: 0, strict: false } : false;
103
+ }
104
+ if (typeof value === 'number') {
105
+ if (!(value >= 0)) {
106
+ throw new RangeError('reuseWorker: size must be a non-negative integer');
107
+ }
108
+ return { size: value, strict: false };
109
+ }
110
+ if (!value) {
111
+ return false;
112
+ }
113
+ const size = (_a = Number(value.size)) !== null && _a !== void 0 ? _a : 0;
114
+ const strict = Boolean(value.strict);
115
+ if (!(size > 0) && strict) {
116
+ throw new RangeError('reuseWorker: size must be set to positive integer if strict is set to true');
117
+ }
118
+ return { size, strict };
119
+ }
120
+ let nextWorkerID = 0;
121
+ class ThreadManager {
122
+ get nextWorkerID() { return nextWorkerID; }
123
+ constructor(options) {
124
+ var _a;
125
+ this.unusedWorkers = [];
126
+ this.runningWorkers = [];
127
+ this.pthreads = Object.create(null);
128
+ this.wasmModule = null;
129
+ this.wasmMemory = null;
130
+ this.messageEvents = new WeakMap();
131
+ if (!options) {
132
+ throw new TypeError('ThreadManager(): options is not provided');
133
+ }
134
+ if ('childThread' in options) {
135
+ this._childThread = Boolean(options.childThread);
136
+ }
137
+ else {
138
+ this._childThread = false;
139
+ }
140
+ if (this._childThread) {
141
+ this._onCreateWorker = undefined;
142
+ this._reuseWorker = false;
143
+ this._beforeLoad = undefined;
144
+ }
145
+ else {
146
+ this._onCreateWorker = options.onCreateWorker;
147
+ this._reuseWorker = getReuseWorker(options.reuseWorker);
148
+ this._beforeLoad = options.beforeLoad;
149
+ }
150
+ this.printErr = (_a = options.printErr) !== null && _a !== void 0 ? _a : console.error.bind(console);
151
+ this.threadSpawn = options.threadSpawn;
152
+ }
153
+ init() {
154
+ if (!this._childThread) {
155
+ this.initMainThread();
156
+ }
157
+ }
158
+ initMainThread() {
159
+ this.preparePool();
160
+ }
161
+ preparePool() {
162
+ if (this._reuseWorker) {
163
+ if (this._reuseWorker.size) {
164
+ let pthreadPoolSize = this._reuseWorker.size;
165
+ while (pthreadPoolSize--) {
166
+ const worker = this.allocateUnusedWorker();
167
+ if (ENVIRONMENT_IS_NODE) {
168
+ worker.once('message', () => { });
169
+ worker.unref();
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ shouldPreloadWorkers() {
176
+ return !this._childThread && this._reuseWorker && this._reuseWorker.size > 0;
177
+ }
178
+ loadWasmModuleToAllWorkers() {
179
+ const promises = Array(this.unusedWorkers.length);
180
+ for (let i = 0; i < this.unusedWorkers.length; ++i) {
181
+ const worker = this.unusedWorkers[i];
182
+ if (ENVIRONMENT_IS_NODE)
183
+ worker.ref();
184
+ promises[i] = this.loadWasmModuleToWorker(worker).then((w) => {
185
+ if (ENVIRONMENT_IS_NODE)
186
+ worker.unref();
187
+ return w;
188
+ }, (e) => {
189
+ if (ENVIRONMENT_IS_NODE)
190
+ worker.unref();
191
+ throw e;
192
+ });
193
+ }
194
+ return Promise.all(promises).catch((err) => {
195
+ this.terminateAllThreads();
196
+ throw err;
197
+ });
198
+ }
199
+ preloadWorkers() {
200
+ if (this.shouldPreloadWorkers()) {
201
+ return this.loadWasmModuleToAllWorkers();
202
+ }
203
+ return Promise.resolve([]);
204
+ }
205
+ setup(wasmModule, wasmMemory) {
206
+ this.wasmModule = wasmModule;
207
+ this.wasmMemory = wasmMemory;
208
+ }
209
+ markId(worker) {
210
+ if (worker.__emnapi_tid)
211
+ return worker.__emnapi_tid;
212
+ const tid = nextWorkerID + 43;
213
+ nextWorkerID = (nextWorkerID + 1) % (WASI_THREADS_MAX_TID - 42);
214
+ this.pthreads[tid] = worker;
215
+ worker.__emnapi_tid = tid;
216
+ return tid;
217
+ }
218
+ returnWorkerToPool(worker) {
219
+ var tid = worker.__emnapi_tid;
220
+ if (tid !== undefined) {
221
+ delete this.pthreads[tid];
222
+ }
223
+ this.unusedWorkers.push(worker);
224
+ this.runningWorkers.splice(this.runningWorkers.indexOf(worker), 1);
225
+ delete worker.__emnapi_tid;
226
+ if (ENVIRONMENT_IS_NODE) {
227
+ worker.unref();
228
+ }
229
+ }
230
+ loadWasmModuleToWorker(worker, sab) {
231
+ if (worker.whenLoaded)
232
+ return worker.whenLoaded;
233
+ const err = this.printErr;
234
+ const beforeLoad = this._beforeLoad;
235
+ const _this = this;
236
+ worker.whenLoaded = new Promise((resolve, reject) => {
237
+ const handleError = function (e) {
238
+ let message = 'worker sent an error!';
239
+ if (worker.__emnapi_tid !== undefined) {
240
+ message = 'worker (tid = ' + worker.__emnapi_tid + ') sent an error!';
241
+ }
242
+ if ('message' in e) {
243
+ err(message + ' ' + e.message);
244
+ if (e.message.indexOf('RuntimeError') !== -1 || e.message.indexOf('unreachable') !== -1) {
245
+ try {
246
+ _this.terminateAllThreads();
247
+ }
248
+ catch (_) { }
249
+ }
250
+ }
251
+ else {
252
+ err(message);
253
+ }
254
+ reject(e);
255
+ throw e;
256
+ };
257
+ const handleMessage = (data) => {
258
+ if (data.__emnapi__) {
259
+ const type = data.__emnapi__.type;
260
+ const payload = data.__emnapi__.payload;
261
+ if (type === 'loaded') {
262
+ worker.loaded = true;
263
+ if (ENVIRONMENT_IS_NODE && !worker.__emnapi_tid) {
264
+ worker.unref();
265
+ }
266
+ resolve(worker);
267
+ }
268
+ else if (type === 'cleanup-thread') {
269
+ if (payload.tid in this.pthreads) {
270
+ this.cleanThread(worker, payload.tid);
271
+ }
272
+ }
273
+ else if (type === 'spawn-thread') {
274
+ this.threadSpawn(payload.startArg, payload.errorOrTid);
275
+ }
276
+ else if (type === 'terminate-all-threads') {
277
+ this.terminateAllThreads();
278
+ }
279
+ }
280
+ };
281
+ worker.onmessage = (e) => {
282
+ handleMessage(e.data);
283
+ this.fireMessageEvent(worker, e);
284
+ };
285
+ worker.onerror = handleError;
286
+ if (ENVIRONMENT_IS_NODE) {
287
+ worker.on('message', function (data) {
288
+ var _a, _b;
289
+ (_b = (_a = worker).onmessage) === null || _b === void 0 ? void 0 : _b.call(_a, {
290
+ data
291
+ });
292
+ });
293
+ worker.on('error', function (e) {
294
+ var _a, _b;
295
+ (_b = (_a = worker).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, e);
296
+ });
297
+ worker.on('detachedExit', function () { });
298
+ }
299
+ if (typeof beforeLoad === 'function') {
300
+ beforeLoad(worker);
301
+ }
302
+ try {
303
+ worker.postMessage(createMessage('load', {
304
+ wasmModule: this.wasmModule,
305
+ wasmMemory: this.wasmMemory,
306
+ sab
307
+ }));
308
+ }
309
+ catch (err) {
310
+ checkSharedWasmMemory(this.wasmMemory);
311
+ throw err;
312
+ }
313
+ });
314
+ return worker.whenLoaded;
315
+ }
316
+ allocateUnusedWorker() {
317
+ const _onCreateWorker = this._onCreateWorker;
318
+ if (typeof _onCreateWorker !== 'function') {
319
+ throw new TypeError('`options.onCreateWorker` is not provided');
320
+ }
321
+ const worker = _onCreateWorker({ type: 'thread', name: 'emnapi-pthread' });
322
+ this.unusedWorkers.push(worker);
323
+ return worker;
324
+ }
325
+ getNewWorker(sab) {
326
+ if (this._reuseWorker) {
327
+ if (this.unusedWorkers.length === 0) {
328
+ if (this._reuseWorker.strict) {
329
+ if (!ENVIRONMENT_IS_NODE) {
330
+ const err = this.printErr;
331
+ err('Tried to spawn a new thread, but the thread pool is exhausted.\n' +
332
+ 'This might result in a deadlock unless some threads eventually exit or the code explicitly breaks out to the event loop.');
333
+ return;
334
+ }
335
+ }
336
+ const worker = this.allocateUnusedWorker();
337
+ this.loadWasmModuleToWorker(worker, sab);
338
+ }
339
+ return this.unusedWorkers.pop();
340
+ }
341
+ const worker = this.allocateUnusedWorker();
342
+ this.loadWasmModuleToWorker(worker, sab);
343
+ return this.unusedWorkers.pop();
344
+ }
345
+ cleanThread(worker, tid, force) {
346
+ if (!force && this._reuseWorker) {
347
+ this.returnWorkerToPool(worker);
348
+ }
349
+ else {
350
+ delete this.pthreads[tid];
351
+ const index = this.runningWorkers.indexOf(worker);
352
+ if (index !== -1) {
353
+ this.runningWorkers.splice(index, 1);
354
+ }
355
+ this.terminateWorker(worker);
356
+ delete worker.__emnapi_tid;
357
+ }
358
+ }
359
+ terminateWorker(worker) {
360
+ var _a;
361
+ const tid = worker.__emnapi_tid;
362
+ worker.terminate();
363
+ (_a = this.messageEvents.get(worker)) === null || _a === void 0 ? void 0 : _a.clear();
364
+ this.messageEvents.delete(worker);
365
+ worker.onmessage = (e) => {
366
+ if (e.data.__emnapi__) {
367
+ const err = this.printErr;
368
+ err('received "' + e.data.__emnapi__.type + '" command from terminated worker: ' + tid);
369
+ }
370
+ };
371
+ }
372
+ terminateAllThreads() {
373
+ for (let i = 0; i < this.runningWorkers.length; ++i) {
374
+ this.terminateWorker(this.runningWorkers[i]);
375
+ }
376
+ for (let i = 0; i < this.unusedWorkers.length; ++i) {
377
+ this.terminateWorker(this.unusedWorkers[i]);
378
+ }
379
+ this.unusedWorkers = [];
380
+ this.runningWorkers = [];
381
+ this.pthreads = Object.create(null);
382
+ this.preparePool();
383
+ }
384
+ addMessageEventListener(worker, onMessage) {
385
+ let listeners = this.messageEvents.get(worker);
386
+ if (!listeners) {
387
+ listeners = new Set();
388
+ this.messageEvents.set(worker, listeners);
389
+ }
390
+ listeners.add(onMessage);
391
+ return () => {
392
+ listeners === null || listeners === void 0 ? void 0 : listeners.delete(onMessage);
393
+ };
394
+ }
395
+ fireMessageEvent(worker, e) {
396
+ const listeners = this.messageEvents.get(worker);
397
+ if (!listeners)
398
+ return;
399
+ const err = this.printErr;
400
+ listeners.forEach((listener) => {
401
+ try {
402
+ listener(e);
403
+ }
404
+ catch (e) {
405
+ err(e.stack);
406
+ }
407
+ });
408
+ }
409
+ }
410
+
411
+ const kIsProxy = Symbol('kIsProxy');
412
+ function createInstanceProxy(instance, memory) {
413
+ if (instance[kIsProxy])
414
+ return instance;
415
+ const originalExports = instance.exports;
416
+ const createHandler = function (target) {
417
+ const handlers = [
418
+ 'apply',
419
+ 'construct',
420
+ 'defineProperty',
421
+ 'deleteProperty',
422
+ 'get',
423
+ 'getOwnPropertyDescriptor',
424
+ 'getPrototypeOf',
425
+ 'has',
426
+ 'isExtensible',
427
+ 'ownKeys',
428
+ 'preventExtensions',
429
+ 'set',
430
+ 'setPrototypeOf'
431
+ ];
432
+ const handler = {};
433
+ for (let i = 0; i < handlers.length; i++) {
434
+ const name = handlers[i];
435
+ handler[name] = function () {
436
+ const args = Array.prototype.slice.call(arguments, 1);
437
+ args.unshift(target);
438
+ return Reflect[name].apply(Reflect, args);
439
+ };
440
+ }
441
+ return handler;
442
+ };
443
+ const handler = createHandler(originalExports);
444
+ const _initialize = () => { };
445
+ const _start = () => 0;
446
+ handler.get = function (_target, p, receiver) {
447
+ var _a;
448
+ if (p === 'memory') {
449
+ return (_a = (typeof memory === 'function' ? memory() : memory)) !== null && _a !== void 0 ? _a : Reflect.get(originalExports, p, receiver);
450
+ }
451
+ if (p === '_initialize') {
452
+ return p in originalExports ? _initialize : undefined;
453
+ }
454
+ if (p === '_start') {
455
+ return p in originalExports ? _start : undefined;
456
+ }
457
+ return Reflect.get(originalExports, p, receiver);
458
+ };
459
+ handler.has = function (_target, p) {
460
+ if (p === 'memory')
461
+ return true;
462
+ return Reflect.has(originalExports, p);
463
+ };
464
+ const exportsProxy = new Proxy(Object.create(null), handler);
465
+ return new Proxy(instance, {
466
+ get(target, p, receiver) {
467
+ if (p === 'exports') {
468
+ return exportsProxy;
469
+ }
470
+ if (p === kIsProxy) {
471
+ return true;
472
+ }
473
+ return Reflect.get(target, p, receiver);
474
+ }
475
+ });
476
+ }
477
+
478
+ const patchedWasiInstances = new WeakMap();
479
+ class WASIThreads {
480
+ constructor(options) {
481
+ if (!options) {
482
+ throw new TypeError('WASIThreads(): options is not provided');
483
+ }
484
+ if (!options.wasi) {
485
+ throw new TypeError('WASIThreads(): options.wasi is not provided');
486
+ }
487
+ patchedWasiInstances.set(this, new WeakSet());
488
+ const wasi = options.wasi;
489
+ patchWasiInstance(this, wasi);
490
+ this.wasi = wasi;
491
+ if ('childThread' in options) {
492
+ this.childThread = Boolean(options.childThread);
493
+ }
494
+ else {
495
+ this.childThread = false;
496
+ }
497
+ this.PThread = undefined;
498
+ if ('threadManager' in options) {
499
+ if (typeof options.threadManager === 'function') {
500
+ this.PThread = options.threadManager();
501
+ }
502
+ else {
503
+ this.PThread = options.threadManager;
504
+ }
505
+ }
506
+ else {
507
+ if (!this.childThread) {
508
+ this.PThread = new ThreadManager(options);
509
+ this.PThread.init();
510
+ }
511
+ }
512
+ let waitThreadStart = false;
513
+ if ('waitThreadStart' in options) {
514
+ waitThreadStart = typeof options.waitThreadStart === 'number' ? options.waitThreadStart : Boolean(options.waitThreadStart);
515
+ }
516
+ const postMessage = getPostMessage(options);
517
+ if (this.childThread && typeof postMessage !== 'function') {
518
+ throw new TypeError('options.postMessage is not a function');
519
+ }
520
+ this.postMessage = postMessage;
521
+ const wasm64 = Boolean(options.wasm64);
522
+ const threadSpawn = (startArg, errorOrTid) => {
523
+ var _a;
524
+ const EAGAIN = 6;
525
+ const isNewABI = errorOrTid !== undefined;
526
+ try {
527
+ checkSharedWasmMemory(this.wasmMemory);
528
+ }
529
+ catch (err) {
530
+ (_a = this.PThread) === null || _a === void 0 ? void 0 : _a.printErr(err.stack);
531
+ if (isNewABI) {
532
+ const struct = new Int32Array(this.wasmMemory.buffer, errorOrTid, 2);
533
+ Atomics.store(struct, 0, 1);
534
+ Atomics.store(struct, 1, EAGAIN);
535
+ Atomics.notify(struct, 1);
536
+ return 1;
537
+ }
538
+ else {
539
+ return -EAGAIN;
540
+ }
541
+ }
542
+ if (!isNewABI) {
543
+ const malloc = this.wasmInstance.exports.malloc;
544
+ errorOrTid = wasm64 ? Number(malloc(BigInt(8))) : (malloc(8) >>> 0);
545
+ if (!errorOrTid) {
546
+ return -48;
547
+ }
548
+ }
549
+ const _free = this.wasmInstance.exports.free;
550
+ const free = wasm64 ? (ptr) => { _free(BigInt(ptr)); } : _free;
551
+ const struct = new Int32Array(this.wasmMemory.buffer, errorOrTid, 2);
552
+ Atomics.store(struct, 0, 0);
553
+ Atomics.store(struct, 1, 0);
554
+ if (this.childThread) {
555
+ postMessage(createMessage('spawn-thread', {
556
+ startArg,
557
+ errorOrTid: errorOrTid
558
+ }));
559
+ Atomics.wait(struct, 1, 0);
560
+ const isError = Atomics.load(struct, 0);
561
+ const result = Atomics.load(struct, 1);
562
+ if (isNewABI) {
563
+ return isError;
564
+ }
565
+ free(errorOrTid);
566
+ return isError ? -result : result;
567
+ }
568
+ const shouldWait = waitThreadStart || (waitThreadStart === 0);
569
+ let sab;
570
+ if (shouldWait) {
571
+ sab = new Int32Array(new SharedArrayBuffer(16 + 8192));
572
+ Atomics.store(sab, 0, 0);
573
+ }
574
+ let worker;
575
+ let tid;
576
+ const PThread = this.PThread;
577
+ try {
578
+ worker = PThread.getNewWorker(sab);
579
+ if (!worker) {
580
+ throw new Error('failed to get new worker');
581
+ }
582
+ tid = PThread.markId(worker);
583
+ if (ENVIRONMENT_IS_NODE) {
584
+ worker.unref();
585
+ }
586
+ worker.postMessage(createMessage('start', {
587
+ tid,
588
+ arg: startArg,
589
+ sab
590
+ }));
591
+ if (shouldWait) {
592
+ if (typeof waitThreadStart === 'number') {
593
+ const waitResult = Atomics.wait(sab, 0, 0, waitThreadStart);
594
+ if (waitResult === 'timed-out') {
595
+ try {
596
+ PThread.cleanThread(worker, tid, true);
597
+ }
598
+ catch (_) { }
599
+ throw new Error('Spawning thread timed out. Please check if the worker is created successfully and if message is handled properly in the worker.');
600
+ }
601
+ }
602
+ else {
603
+ Atomics.wait(sab, 0, 0);
604
+ }
605
+ const r = Atomics.load(sab, 0);
606
+ if (r > 1) {
607
+ try {
608
+ PThread.cleanThread(worker, tid, true);
609
+ }
610
+ catch (_) { }
611
+ throw deserizeErrorFromBuffer(sab.buffer);
612
+ }
613
+ }
614
+ }
615
+ catch (e) {
616
+ Atomics.store(struct, 0, 1);
617
+ Atomics.store(struct, 1, EAGAIN);
618
+ Atomics.notify(struct, 1);
619
+ PThread === null || PThread === void 0 ? void 0 : PThread.printErr(e.stack);
620
+ if (isNewABI) {
621
+ return 1;
622
+ }
623
+ free(errorOrTid);
624
+ return -EAGAIN;
625
+ }
626
+ Atomics.store(struct, 0, 0);
627
+ Atomics.store(struct, 1, tid);
628
+ Atomics.notify(struct, 1);
629
+ PThread.runningWorkers.push(worker);
630
+ if (!shouldWait) {
631
+ worker.whenLoaded.catch((err) => {
632
+ delete worker.whenLoaded;
633
+ PThread.cleanThread(worker, tid, true);
634
+ throw err;
635
+ });
636
+ }
637
+ if (isNewABI) {
638
+ return 0;
639
+ }
640
+ free(errorOrTid);
641
+ return tid;
642
+ };
643
+ this.threadSpawn = threadSpawn;
644
+ if (this.PThread) {
645
+ this.PThread.threadSpawn = threadSpawn;
646
+ }
647
+ }
648
+ getImportObject() {
649
+ return {
650
+ wasi: {
651
+ 'thread-spawn': this.threadSpawn
652
+ }
653
+ };
654
+ }
655
+ setup(wasmInstance, wasmModule, wasmMemory) {
656
+ wasmMemory !== null && wasmMemory !== void 0 ? wasmMemory : (wasmMemory = wasmInstance.exports.memory);
657
+ this.wasmInstance = wasmInstance;
658
+ this.wasmMemory = wasmMemory;
659
+ if (this.PThread) {
660
+ this.PThread.setup(wasmModule, wasmMemory);
661
+ }
662
+ }
663
+ preloadWorkers() {
664
+ if (this.PThread) {
665
+ return this.PThread.preloadWorkers();
666
+ }
667
+ return Promise.resolve([]);
668
+ }
669
+ initialize(instance, module, memory) {
670
+ const exports$1 = instance.exports;
671
+ memory !== null && memory !== void 0 ? memory : (memory = exports$1.memory);
672
+ if (this.childThread) {
673
+ instance = createInstanceProxy(instance, memory);
674
+ }
675
+ this.setup(instance, module, memory);
676
+ const wasi = this.wasi;
677
+ if (('_start' in exports$1) && (typeof exports$1._start === 'function')) {
678
+ if (this.childThread) {
679
+ wasi.start(instance);
680
+ try {
681
+ const kStarted = getWasiSymbol(wasi, 'kStarted');
682
+ wasi[kStarted] = false;
683
+ }
684
+ catch (_) { }
685
+ }
686
+ else {
687
+ setupInstance(wasi, instance);
688
+ }
689
+ }
690
+ else {
691
+ wasi.initialize(instance);
692
+ }
693
+ return instance;
694
+ }
695
+ start(instance, module, memory) {
696
+ const exports$1 = instance.exports;
697
+ memory !== null && memory !== void 0 ? memory : (memory = exports$1.memory);
698
+ if (this.childThread) {
699
+ instance = createInstanceProxy(instance, memory);
700
+ }
701
+ this.setup(instance, module, memory);
702
+ const exitCode = this.wasi.start(instance);
703
+ return { exitCode, instance };
704
+ }
705
+ terminateAllThreads() {
706
+ var _a;
707
+ if (!this.childThread) {
708
+ (_a = this.PThread) === null || _a === void 0 ? void 0 : _a.terminateAllThreads();
709
+ }
710
+ else {
711
+ this.postMessage(createMessage('terminate-all-threads', {}));
712
+ }
713
+ }
714
+ }
715
+ function patchWasiInstance(wasiThreads, wasi) {
716
+ const patched = patchedWasiInstances.get(wasiThreads);
717
+ if (patched.has(wasi)) {
718
+ return;
719
+ }
720
+ const _this = wasiThreads;
721
+ const wasiImport = wasi.wasiImport;
722
+ if (wasiImport) {
723
+ const proc_exit = wasiImport.proc_exit;
724
+ wasiImport.proc_exit = function (code) {
725
+ _this.terminateAllThreads();
726
+ return proc_exit.call(this, code);
727
+ };
728
+ }
729
+ if (!_this.childThread) {
730
+ const start = wasi.start;
731
+ if (typeof start === 'function') {
732
+ wasi.start = function (instance) {
733
+ try {
734
+ return start.call(this, instance);
735
+ }
736
+ catch (err) {
737
+ if (isTrapError(err)) {
738
+ _this.terminateAllThreads();
739
+ }
740
+ throw err;
741
+ }
742
+ };
743
+ }
744
+ }
745
+ patched.add(wasi);
746
+ }
747
+ function getWasiSymbol(wasi, description) {
748
+ const symbols = Object.getOwnPropertySymbols(wasi);
749
+ const selectDescription = (description) => (s) => {
750
+ if (s.description) {
751
+ return s.description === description;
752
+ }
753
+ return s.toString() === `Symbol(${description})`;
754
+ };
755
+ if (Array.isArray(description)) {
756
+ return description.map(d => symbols.filter(selectDescription(d))[0]);
757
+ }
758
+ return symbols.filter(selectDescription(description))[0];
759
+ }
760
+ function setupInstance(wasi, instance) {
761
+ const [kInstance, kSetMemory] = getWasiSymbol(wasi, ['kInstance', 'kSetMemory']);
762
+ wasi[kInstance] = instance;
763
+ wasi[kSetMemory](instance.exports.memory);
764
+ }
765
+
766
+ class ThreadMessageHandler {
767
+ constructor(options) {
768
+ const postMsg = getPostMessage(options);
769
+ if (typeof postMsg !== 'function') {
770
+ throw new TypeError('options.postMessage is not a function');
771
+ }
772
+ this.postMessage = postMsg;
773
+ this.onLoad = options === null || options === void 0 ? void 0 : options.onLoad;
774
+ this.onError = typeof (options === null || options === void 0 ? void 0 : options.onError) === 'function' ? options.onError : (_type, err) => { throw err; };
775
+ this.instance = undefined;
776
+ this.messagesBeforeLoad = [];
777
+ }
778
+ instantiate(data) {
779
+ if (typeof this.onLoad === 'function') {
780
+ return this.onLoad(data);
781
+ }
782
+ throw new Error('ThreadMessageHandler.prototype.instantiate is not implemented');
783
+ }
784
+ handle(e) {
785
+ var _a;
786
+ if ((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.__emnapi__) {
787
+ const type = e.data.__emnapi__.type;
788
+ const payload = e.data.__emnapi__.payload;
789
+ try {
790
+ if (type === 'load') {
791
+ this._load(payload);
792
+ }
793
+ else if (type === 'start') {
794
+ this.handleAfterLoad(e, () => {
795
+ this._start(payload);
796
+ });
797
+ }
798
+ }
799
+ catch (err) {
800
+ this.onError(err, type);
801
+ }
802
+ }
803
+ }
804
+ _load(payload) {
805
+ if (this.instance !== undefined)
806
+ return;
807
+ let source;
808
+ try {
809
+ source = this.instantiate(payload);
810
+ }
811
+ catch (err) {
812
+ this._loaded(err, null, payload);
813
+ return;
814
+ }
815
+ const then = source && 'then' in source ? source.then : undefined;
816
+ if (typeof then === 'function') {
817
+ then.call(source, (source) => { this._loaded(null, source, payload); }, (err) => { this._loaded(err, null, payload); });
818
+ }
819
+ else {
820
+ this._loaded(null, source, payload);
821
+ }
822
+ }
823
+ _start(payload) {
824
+ const wasi_thread_start = this.instance.exports.wasi_thread_start;
825
+ if (typeof wasi_thread_start !== 'function') {
826
+ const err = new TypeError('wasi_thread_start is not exported');
827
+ notifyPthreadCreateResult(payload.sab, 2, err);
828
+ throw err;
829
+ }
830
+ const postMessage = this.postMessage;
831
+ const tid = payload.tid;
832
+ const startArg = payload.arg;
833
+ notifyPthreadCreateResult(payload.sab, 1);
834
+ try {
835
+ wasi_thread_start(tid, startArg);
836
+ }
837
+ catch (err) {
838
+ if (err !== 'unwind') {
839
+ throw err;
840
+ }
841
+ else {
842
+ return;
843
+ }
844
+ }
845
+ postMessage(createMessage('cleanup-thread', { tid }));
846
+ }
847
+ _loaded(err, source, payload) {
848
+ if (err) {
849
+ notifyPthreadCreateResult(payload.sab, 2, err);
850
+ throw err;
851
+ }
852
+ if (source == null) {
853
+ const err = new TypeError('onLoad should return an object');
854
+ notifyPthreadCreateResult(payload.sab, 2, err);
855
+ throw err;
856
+ }
857
+ const instance = source.instance;
858
+ if (!instance) {
859
+ const err = new TypeError('onLoad should return an object which includes "instance"');
860
+ notifyPthreadCreateResult(payload.sab, 2, err);
861
+ throw err;
862
+ }
863
+ this.instance = instance;
864
+ const postMessage = this.postMessage;
865
+ postMessage(createMessage('loaded', {}));
866
+ const messages = this.messagesBeforeLoad;
867
+ this.messagesBeforeLoad = [];
868
+ for (let i = 0; i < messages.length; i++) {
869
+ const data = messages[i];
870
+ this.handle({ data });
871
+ }
872
+ }
873
+ handleAfterLoad(e, f) {
874
+ if (this.instance !== undefined) {
875
+ f.call(this, e);
876
+ }
877
+ else {
878
+ this.messagesBeforeLoad.push(e.data);
879
+ }
880
+ }
881
+ }
882
+ function notifyPthreadCreateResult(sab, result, error) {
883
+ if (sab) {
884
+ serizeErrorToBuffer(sab.buffer, result, error);
885
+ Atomics.notify(sab, 0);
886
+ }
887
+ }
888
+
889
+ exports.ThreadManager = ThreadManager;
890
+ exports.ThreadMessageHandler = ThreadMessageHandler;
891
+ exports.WASIThreads = WASIThreads;
892
+ exports.createInstanceProxy = createInstanceProxy;
893
+ exports.isSharedArrayBuffer = isSharedArrayBuffer;
894
+ exports.isTrapError = isTrapError;
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+
3
+ import type { Worker as Worker_2 } from 'worker_threads';
4
+
5
+ /** @public */
6
+ export declare interface BaseOptions {
7
+ wasi: WASIInstance;
8
+ version?: 'preview1';
9
+ wasm64?: boolean;
10
+ }
11
+
12
+ /** @public */
13
+ export declare interface ChildThreadOptions extends BaseOptions {
14
+ childThread: true;
15
+ postMessage?: (data: any) => void;
16
+ }
17
+
18
+ /** @public */
19
+ export declare interface CleanupThreadPayload {
20
+ tid: number;
21
+ }
22
+
23
+ /** @public */
24
+ export declare interface CommandInfo<T extends CommandType> {
25
+ type: T;
26
+ payload: CommandPayloadMap[T];
27
+ }
28
+
29
+ /** @public */
30
+ export declare interface CommandPayloadMap {
31
+ load: LoadPayload;
32
+ loaded: LoadedPayload;
33
+ start: StartPayload;
34
+ 'cleanup-thread': CleanupThreadPayload;
35
+ 'terminate-all-threads': TerminateAllThreadsPayload;
36
+ 'spawn-thread': SpawnThreadPayload;
37
+ }
38
+
39
+ /** @public */
40
+ export declare type CommandType = keyof CommandPayloadMap;
41
+
42
+ /** @public */
43
+ export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
44
+
45
+ /** @public */
46
+ export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
47
+
48
+ /** @public */
49
+ export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
50
+
51
+ /** @public */
52
+ export declare interface LoadedPayload {
53
+ }
54
+
55
+ /** @public */
56
+ export declare interface LoadPayload {
57
+ wasmModule: WebAssembly.Module;
58
+ wasmMemory: WebAssembly.Memory;
59
+ sab?: Int32Array;
60
+ }
61
+
62
+ /** @public */
63
+ export declare interface MainThreadBaseOptions extends BaseOptions {
64
+ waitThreadStart?: boolean | number;
65
+ }
66
+
67
+ /** @public */
68
+ export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
69
+
70
+ /** @public */
71
+ export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
72
+ }
73
+
74
+ /** @public */
75
+ export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
76
+ threadManager?: ThreadManager | (() => ThreadManager);
77
+ }
78
+
79
+ /** @public */
80
+ export declare interface MessageEventData<T extends CommandType> {
81
+ __emnapi__: CommandInfo<T>;
82
+ }
83
+
84
+ /** @public */
85
+ export declare interface ReuseWorkerOptions {
86
+ /**
87
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
88
+ */
89
+ size: number;
90
+ /**
91
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
92
+ */
93
+ strict?: boolean;
94
+ }
95
+
96
+ /** @public */
97
+ export declare interface SpawnThreadPayload {
98
+ startArg: number;
99
+ errorOrTid: number;
100
+ }
101
+
102
+ /** @public */
103
+ export declare interface StartPayload {
104
+ tid: number;
105
+ arg: number;
106
+ sab?: Int32Array;
107
+ }
108
+
109
+ /** @public */
110
+ export declare interface StartResult {
111
+ exitCode: number;
112
+ instance: WebAssembly.Instance;
113
+ }
114
+
115
+ /** @public */
116
+ export declare interface TerminateAllThreadsPayload {
117
+ }
118
+
119
+ /** @public */
120
+ export declare class ThreadManager {
121
+ unusedWorkers: WorkerLike[];
122
+ runningWorkers: WorkerLike[];
123
+ pthreads: Record<number, WorkerLike>;
124
+ get nextWorkerID(): number;
125
+ wasmModule: WebAssembly.Module | null;
126
+ wasmMemory: WebAssembly.Memory | null;
127
+ private readonly messageEvents;
128
+ private readonly _childThread;
129
+ private readonly _onCreateWorker;
130
+ private readonly _reuseWorker;
131
+ private readonly _beforeLoad?;
132
+ /* Excluded from this release type: printErr */
133
+ threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
134
+ constructor(options: ThreadManagerOptions);
135
+ init(): void;
136
+ initMainThread(): void;
137
+ private preparePool;
138
+ shouldPreloadWorkers(): boolean;
139
+ loadWasmModuleToAllWorkers(): Promise<WorkerLike[]>;
140
+ preloadWorkers(): Promise<WorkerLike[]>;
141
+ setup(wasmModule: WebAssembly.Module, wasmMemory: WebAssembly.Memory): void;
142
+ markId(worker: WorkerLike): number;
143
+ returnWorkerToPool(worker: WorkerLike): void;
144
+ loadWasmModuleToWorker(worker: WorkerLike, sab?: Int32Array): Promise<WorkerLike>;
145
+ allocateUnusedWorker(): WorkerLike;
146
+ getNewWorker(sab?: Int32Array): WorkerLike | undefined;
147
+ cleanThread(worker: WorkerLike, tid: number, force?: boolean): void;
148
+ terminateWorker(worker: WorkerLike): void;
149
+ terminateAllThreads(): void;
150
+ addMessageEventListener(worker: WorkerLike, onMessage: (e: WorkerMessageEvent) => void): () => void;
151
+ fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
152
+ }
153
+
154
+ /** @public */
155
+ export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
156
+
157
+ /** @public */
158
+ export declare interface ThreadManagerOptionsBase {
159
+ printErr?: (message: string) => void;
160
+ threadSpawn?: (startArg: number, errorOrTid?: number) => number;
161
+ }
162
+
163
+ /** @public */
164
+ export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
165
+ childThread: true;
166
+ }
167
+
168
+ /** @public */
169
+ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
170
+ beforeLoad?: (worker: WorkerLike) => any;
171
+ reuseWorker?: boolean | number | ReuseWorkerOptions;
172
+ onCreateWorker: WorkerFactory;
173
+ childThread?: false;
174
+ }
175
+
176
+ /** @public */
177
+ export declare class ThreadMessageHandler {
178
+ protected instance: WebAssembly.Instance | undefined;
179
+ private messagesBeforeLoad;
180
+ protected postMessage: (message: any) => void;
181
+ protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
182
+ protected onError: (error: Error, type: WorkerMessageType) => void;
183
+ constructor(options?: ThreadMessageHandlerOptions);
184
+ /** @virtual */
185
+ instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
186
+ /** @virtual */
187
+ handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
188
+ private _load;
189
+ private _start;
190
+ protected _loaded(err: Error | null, source: WebAssembly.WebAssemblyInstantiatedSource | null, payload: LoadPayload): void;
191
+ protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
192
+ }
193
+
194
+ /** @public */
195
+ export declare interface ThreadMessageHandlerOptions {
196
+ onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
197
+ onError?: (error: Error, type: WorkerMessageType) => void;
198
+ postMessage?: (message: any) => void;
199
+ }
200
+
201
+ /** @public */
202
+ export declare interface WASIInstance {
203
+ readonly wasiImport?: Record<string, any>;
204
+ initialize(instance: object): void;
205
+ start(instance: object): number;
206
+ getImportObject?(): any;
207
+ }
208
+
209
+ /** @public */
210
+ export declare class WASIThreads {
211
+ PThread: ThreadManager | undefined;
212
+ private wasmMemory;
213
+ private wasmInstance;
214
+ private readonly threadSpawn;
215
+ readonly childThread: boolean;
216
+ private readonly postMessage;
217
+ readonly wasi: WASIInstance;
218
+ constructor(options: WASIThreadsOptions);
219
+ getImportObject(): {
220
+ wasi: WASIThreadsImports;
221
+ };
222
+ setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
223
+ preloadWorkers(): Promise<WorkerLike[]>;
224
+ /**
225
+ * It's ok to call this method to a WASI command module.
226
+ *
227
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
228
+ *
229
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
230
+ */
231
+ initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
232
+ /**
233
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
234
+ * ```js
235
+ * this.initialize(instance, module, memory)
236
+ * this.wasi.start(instance)
237
+ * ```
238
+ */
239
+ start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
240
+ terminateAllThreads(): void;
241
+ }
242
+
243
+ /** @public */
244
+ export declare interface WASIThreadsImports {
245
+ 'thread-spawn': (startArg: number, errorOrTid?: number) => number;
246
+ }
247
+
248
+ /** @public */
249
+ export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
250
+
251
+ /** @public */
252
+ export declare type WorkerFactory = (ctx: {
253
+ type: string;
254
+ name: string;
255
+ }) => WorkerLike;
256
+
257
+ /** @public */
258
+ export declare type WorkerLike = (Worker | Worker_2) & {
259
+ whenLoaded?: Promise<WorkerLike>;
260
+ loaded?: boolean;
261
+ __emnapi_tid?: number;
262
+ };
263
+
264
+ /** @public */
265
+ export declare interface WorkerMessageEvent<T = any> {
266
+ data: T;
267
+ }
268
+
269
+ /** @public */
270
+ export declare type WorkerMessageType = 'load' | 'start';
271
+
272
+ export { }
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.js ADDED
@@ -0,0 +1 @@
 
 
1
+ const e="undefined"!=typeof WebAssembly?WebAssembly:"undefined"!=typeof WXWebAssembly?WXWebAssembly:void 0,t="object"==typeof process&&null!==process&&"object"==typeof process.versions&&null!==process.versions&&"string"==typeof process.versions.node;function r(e){return"function"==typeof(null==e?void 0:e.postMessage)?e.postMessage:"function"==typeof postMessage?postMessage:void 0}function s(e){return"function"==typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(e)}function o(t){try{return t instanceof e.RuntimeError}catch(e){return!1}}function n(e,t){return{__emnapi__:{type:e,payload:t}}}function i(e){if(e){if(!s(e.buffer))throw new Error("Multithread features require shared wasm memory. Try to compile with `-matomics -mbulk-memory` and use `--import-memory --shared-memory` during linking, then create WebAssembly.Memory with `shared: true` option")}else if("undefined"==typeof SharedArrayBuffer)throw new Error("Current environment does not support SharedArrayBuffer, threads are not available!")}let a=0;class h{get nextWorkerID(){return a}constructor(e){var t;if(this.unusedWorkers=[],this.runningWorkers=[],this.pthreads=Object.create(null),this.wasmModule=null,this.wasmMemory=null,this.messageEvents=new WeakMap,!e)throw new TypeError("ThreadManager(): options is not provided");this._childThread="childThread"in e&&Boolean(e.childThread),this._childThread?(this._onCreateWorker=void 0,this._reuseWorker=!1,this._beforeLoad=void 0):(this._onCreateWorker=e.onCreateWorker,this._reuseWorker=function(e){var t;if("boolean"==typeof e)return!!e&&{size:0,strict:!1};if("number"==typeof e){if(!(e>=0))throw new RangeError("reuseWorker: size must be a non-negative integer");return{size:e,strict:!1}}if(!e)return!1;const r=null!==(t=Number(e.size))&&void 0!==t?t:0,s=Boolean(e.strict);if(!(r>0)&&s)throw new RangeError("reuseWorker: size must be set to positive integer if strict is set to true");return{size:r,strict:s}}(e.reuseWorker),this._beforeLoad=e.beforeLoad),this.printErr=null!==(t=e.printErr)&&void 0!==t?t:console.error.bind(console),this.threadSpawn=e.threadSpawn}init(){this._childThread||this.initMainThread()}initMainThread(){this.preparePool()}preparePool(){if(this._reuseWorker&&this._reuseWorker.size){let e=this._reuseWorker.size;for(;e--;){const e=this.allocateUnusedWorker();t&&(e.once("message",()=>{}),e.unref())}}}shouldPreloadWorkers(){return!this._childThread&&this._reuseWorker&&this._reuseWorker.size>0}loadWasmModuleToAllWorkers(){const e=Array(this.unusedWorkers.length);for(let r=0;r<this.unusedWorkers.length;++r){const s=this.unusedWorkers[r];t&&s.ref(),e[r]=this.loadWasmModuleToWorker(s).then(e=>(t&&s.unref(),e),e=>{throw t&&s.unref(),e})}return Promise.all(e).catch(e=>{throw this.terminateAllThreads(),e})}preloadWorkers(){return this.shouldPreloadWorkers()?this.loadWasmModuleToAllWorkers():Promise.resolve([])}setup(e,t){this.wasmModule=e,this.wasmMemory=t}markId(e){if(e.__emnapi_tid)return e.__emnapi_tid;const t=a+43;return a=(a+1)%536870869,this.pthreads[t]=e,e.__emnapi_tid=t,t}returnWorkerToPool(e){var r=e.__emnapi_tid;void 0!==r&&delete this.pthreads[r],this.unusedWorkers.push(e),this.runningWorkers.splice(this.runningWorkers.indexOf(e),1),delete e.__emnapi_tid,t&&e.unref()}loadWasmModuleToWorker(e,r){if(e.whenLoaded)return e.whenLoaded;const s=this.printErr,o=this._beforeLoad,a=this;return e.whenLoaded=new Promise((h,d)=>{const l=r=>{if(r.__emnapi__){const s=r.__emnapi__.type,o=r.__emnapi__.payload;"loaded"===s?(e.loaded=!0,t&&!e.__emnapi_tid&&e.unref(),h(e)):"cleanup-thread"===s?o.tid in this.pthreads&&this.cleanThread(e,o.tid):"spawn-thread"===s?this.threadSpawn(o.startArg,o.errorOrTid):"terminate-all-threads"===s&&this.terminateAllThreads()}};e.onmessage=t=>{l(t.data),this.fireMessageEvent(e,t)},e.onerror=function(t){let r="worker sent an error!";if(void 0!==e.__emnapi_tid&&(r="worker (tid = "+e.__emnapi_tid+") sent an error!"),"message"in t){if(s(r+" "+t.message),-1!==t.message.indexOf("RuntimeError")||-1!==t.message.indexOf("unreachable"))try{a.terminateAllThreads()}catch(e){}}else s(r);throw d(t),t},t&&(e.on("message",function(t){var r,s;null===(s=(r=e).onmessage)||void 0===s||s.call(r,{data:t})}),e.on("error",function(t){var r,s;null===(s=(r=e).onerror)||void 0===s||s.call(r,t)}),e.on("detachedExit",function(){})),"function"==typeof o&&o(e);try{e.postMessage(n("load",{wasmModule:this.wasmModule,wasmMemory:this.wasmMemory,sab:r}))}catch(e){throw i(this.wasmMemory),e}}),e.whenLoaded}allocateUnusedWorker(){const e=this._onCreateWorker;if("function"!=typeof e)throw new TypeError("`options.onCreateWorker` is not provided");const t=e({type:"thread",name:"emnapi-pthread"});return this.unusedWorkers.push(t),t}getNewWorker(e){if(this._reuseWorker){if(0===this.unusedWorkers.length){if(this._reuseWorker.strict&&!t){return void(0,this.printErr)("Tried to spawn a new thread, but the thread pool is exhausted.\nThis might result in a deadlock unless some threads eventually exit or the code explicitly breaks out to the event loop.")}const r=this.allocateUnusedWorker();this.loadWasmModuleToWorker(r,e)}return this.unusedWorkers.pop()}const r=this.allocateUnusedWorker();return this.loadWasmModuleToWorker(r,e),this.unusedWorkers.pop()}cleanThread(e,t,r){if(!r&&this._reuseWorker)this.returnWorkerToPool(e);else{delete this.pthreads[t];const r=this.runningWorkers.indexOf(e);-1!==r&&this.runningWorkers.splice(r,1),this.terminateWorker(e),delete e.__emnapi_tid}}terminateWorker(e){var t;const r=e.__emnapi_tid;e.terminate(),null===(t=this.messageEvents.get(e))||void 0===t||t.clear(),this.messageEvents.delete(e),e.onmessage=e=>{if(e.data.__emnapi__){(0,this.printErr)('received "'+e.data.__emnapi__.type+'" command from terminated worker: '+r)}}}terminateAllThreads(){for(let e=0;e<this.runningWorkers.length;++e)this.terminateWorker(this.runningWorkers[e]);for(let e=0;e<this.unusedWorkers.length;++e)this.terminateWorker(this.unusedWorkers[e]);this.unusedWorkers=[],this.runningWorkers=[],this.pthreads=Object.create(null),this.preparePool()}addMessageEventListener(e,t){let r=this.messageEvents.get(e);return r||(r=new Set,this.messageEvents.set(e,r)),r.add(t),()=>{null==r||r.delete(t)}}fireMessageEvent(e,t){const r=this.messageEvents.get(e);if(!r)return;const s=this.printErr;r.forEach(e=>{try{e(t)}catch(e){s(e.stack)}})}}const d=Symbol("kIsProxy");function l(e,t){if(e[d])return e;const r=e.exports,s=function(e){const t=["apply","construct","defineProperty","deleteProperty","get","getOwnPropertyDescriptor","getPrototypeOf","has","isExtensible","ownKeys","preventExtensions","set","setPrototypeOf"],r={};for(let s=0;s<t.length;s++){const o=t[s];r[o]=function(){const t=Array.prototype.slice.call(arguments,1);return t.unshift(e),Reflect[o].apply(Reflect,t)}}return r}(r),o=()=>{},n=()=>0;s.get=function(e,s,i){var a;return"memory"===s?null!==(a="function"==typeof t?t():t)&&void 0!==a?a:Reflect.get(r,s,i):"_initialize"===s?s in r?o:void 0:"_start"===s?s in r?n:void 0:Reflect.get(r,s,i)},s.has=function(e,t){return"memory"===t||Reflect.has(r,t)};const i=new Proxy(Object.create(null),s);return new Proxy(e,{get:(e,t,r)=>"exports"===t?i:t===d||Reflect.get(e,t,r)})}const c=new WeakMap;function u(e,t){const r=Object.getOwnPropertySymbols(e),s=e=>t=>t.description?t.description===e:t.toString()===`Symbol(${e})`;return Array.isArray(t)?t.map(e=>r.filter(s(e))[0]):r.filter(s(t))[0]}function f(e,t,r){e&&(!function(e,t,r){const s=new Int32Array(e);if(Atomics.store(s,0,t),t>1&&r){const t=r.name,o=r.message,n=r.stack,i=(new TextEncoder).encode(t),a=(new TextEncoder).encode(o),h=(new TextEncoder).encode(n);Atomics.store(s,1,i.length),Atomics.store(s,2,a.length),Atomics.store(s,3,h.length);const d=new Uint8Array(e);d.set(i,16),d.set(a,16+i.length),d.set(h,16+i.length+a.length)}}(e.buffer,t,r),Atomics.notify(e,0))}exports.ThreadManager=h,exports.ThreadMessageHandler=class{constructor(e){const t=r(e);if("function"!=typeof t)throw new TypeError("options.postMessage is not a function");this.postMessage=t,this.onLoad=null==e?void 0:e.onLoad,this.onError="function"==typeof(null==e?void 0:e.onError)?e.onError:(e,t)=>{throw t},this.instance=void 0,this.messagesBeforeLoad=[]}instantiate(e){if("function"==typeof this.onLoad)return this.onLoad(e);throw new Error("ThreadMessageHandler.prototype.instantiate is not implemented")}handle(e){var t;if(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.__emnapi__){const t=e.data.__emnapi__.type,r=e.data.__emnapi__.payload;try{"load"===t?this._load(r):"start"===t&&this.handleAfterLoad(e,()=>{this._start(r)})}catch(e){this.onError(e,t)}}}_load(e){if(void 0!==this.instance)return;let t;try{t=this.instantiate(e)}catch(t){return void this._loaded(t,null,e)}const r=t&&"then"in t?t.then:void 0;"function"==typeof r?r.call(t,t=>{this._loaded(null,t,e)},t=>{this._loaded(t,null,e)}):this._loaded(null,t,e)}_start(e){const t=this.instance.exports.wasi_thread_start;if("function"!=typeof t){const t=new TypeError("wasi_thread_start is not exported");throw f(e.sab,2,t),t}const r=this.postMessage,s=e.tid,o=e.arg;f(e.sab,1);try{t(s,o)}catch(e){if("unwind"!==e)throw e;return}r(n("cleanup-thread",{tid:s}))}_loaded(e,t,r){if(e)throw f(r.sab,2,e),e;if(null==t){const e=new TypeError("onLoad should return an object");throw f(r.sab,2,e),e}const s=t.instance;if(!s){const e=new TypeError('onLoad should return an object which includes "instance"');throw f(r.sab,2,e),e}this.instance=s;(0,this.postMessage)(n("loaded",{}));const o=this.messagesBeforeLoad;this.messagesBeforeLoad=[];for(let e=0;e<o.length;e++){const t=o[e];this.handle({data:t})}}handleAfterLoad(e,t){void 0!==this.instance?t.call(this,e):this.messagesBeforeLoad.push(e.data)}},exports.WASIThreads=class{constructor(s){if(!s)throw new TypeError("WASIThreads(): options is not provided");if(!s.wasi)throw new TypeError("WASIThreads(): options.wasi is not provided");c.set(this,new WeakSet);const a=s.wasi;!function(e,t){const r=c.get(e);if(r.has(t))return;const s=e,n=t.wasiImport;if(n){const e=n.proc_exit;n.proc_exit=function(t){return s.terminateAllThreads(),e.call(this,t)}}if(!s.childThread){const e=t.start;"function"==typeof e&&(t.start=function(t){try{return e.call(this,t)}catch(e){throw o(e)&&s.terminateAllThreads(),e}})}r.add(t)}(this,a),this.wasi=a,this.childThread="childThread"in s&&Boolean(s.childThread),this.PThread=void 0,"threadManager"in s?"function"==typeof s.threadManager?this.PThread=s.threadManager():this.PThread=s.threadManager:this.childThread||(this.PThread=new h(s),this.PThread.init());let d=!1;"waitThreadStart"in s&&(d="number"==typeof s.waitThreadStart?s.waitThreadStart:Boolean(s.waitThreadStart));const l=r(s);if(this.childThread&&"function"!=typeof l)throw new TypeError("options.postMessage is not a function");this.postMessage=l;const u=Boolean(s.wasm64),f=(r,s)=>{var o;const a=void 0!==s;try{i(this.wasmMemory)}catch(e){if(null===(o=this.PThread)||void 0===o||o.printErr(e.stack),a){const e=new Int32Array(this.wasmMemory.buffer,s,2);return Atomics.store(e,0,1),Atomics.store(e,1,6),Atomics.notify(e,1),1}return-6}if(!a){const e=this.wasmInstance.exports.malloc;if(!(s=u?Number(e(BigInt(8))):e(8)>>>0))return-48}const h=this.wasmInstance.exports.free,c=u?e=>{h(BigInt(e))}:h,f=new Int32Array(this.wasmMemory.buffer,s,2);if(Atomics.store(f,0,0),Atomics.store(f,1,0),this.childThread){l(n("spawn-thread",{startArg:r,errorOrTid:s})),Atomics.wait(f,1,0);const e=Atomics.load(f,0),t=Atomics.load(f,1);return a?e:(c(s),e?-t:t)}const p=d||0===d;let m,w,y;p&&(m=new Int32Array(new SharedArrayBuffer(8208)),Atomics.store(m,0,0));const g=this.PThread;try{if(w=g.getNewWorker(m),!w)throw new Error("failed to get new worker");if(y=g.markId(w),t&&w.unref(),w.postMessage(n("start",{tid:y,arg:r,sab:m})),p){if("number"==typeof d){if("timed-out"===Atomics.wait(m,0,0,d)){try{g.cleanThread(w,y,!0)}catch(e){}throw new Error("Spawning thread timed out. Please check if the worker is created successfully and if message is handled properly in the worker.")}}else Atomics.wait(m,0,0);if(Atomics.load(m,0)>1){try{g.cleanThread(w,y,!0)}catch(e){}throw function(t){var r,s;const o=new Int32Array(t);if(Atomics.load(o,0)<=1)return null;const n=Atomics.load(o,1),i=Atomics.load(o,2),a=Atomics.load(o,3),h=new Uint8Array(t),d=h.slice(16,16+n),l=h.slice(16+n,16+n+i),c=h.slice(16+n+i,16+n+i+a),u=(new TextDecoder).decode(d),f=(new TextDecoder).decode(l),p=(new TextDecoder).decode(c),m=new(null!==(r=globalThis[u])&&void 0!==r?r:"RuntimeError"===u&&null!==(s=e.RuntimeError)&&void 0!==s?s:Error)(f);return Object.defineProperty(m,"stack",{value:p,writable:!0,enumerable:!1,configurable:!0}),m}(m.buffer)}}}catch(e){return Atomics.store(f,0,1),Atomics.store(f,1,6),Atomics.notify(f,1),null==g||g.printErr(e.stack),a?1:(c(s),-6)}return Atomics.store(f,0,0),Atomics.store(f,1,y),Atomics.notify(f,1),g.runningWorkers.push(w),p||w.whenLoaded.catch(e=>{throw delete w.whenLoaded,g.cleanThread(w,y,!0),e}),a?0:(c(s),y)};this.threadSpawn=f,this.PThread&&(this.PThread.threadSpawn=f)}getImportObject(){return{wasi:{"thread-spawn":this.threadSpawn}}}setup(e,t,r){null!=r||(r=e.exports.memory),this.wasmInstance=e,this.wasmMemory=r,this.PThread&&this.PThread.setup(t,r)}preloadWorkers(){return this.PThread?this.PThread.preloadWorkers():Promise.resolve([])}initialize(e,t,r){const s=e.exports;null!=r||(r=s.memory),this.childThread&&(e=l(e,r)),this.setup(e,t,r);const o=this.wasi;if("_start"in s&&"function"==typeof s._start)if(this.childThread){o.start(e);try{o[u(o,"kStarted")]=!1}catch(e){}}else!function(e,t){const[r,s]=u(e,["kInstance","kSetMemory"]);e[r]=t,e[s](t.exports.memory)}(o,e);else o.initialize(e);return e}start(e,t,r){const s=e.exports;null!=r||(r=s.memory),this.childThread&&(e=l(e,r)),this.setup(e,t,r);return{exitCode:this.wasi.start(e),instance:e}}terminateAllThreads(){var e;this.childThread?this.postMessage(n("terminate-all-threads",{})):null===(e=this.PThread)||void 0===e||e.terminateAllThreads()}},exports.createInstanceProxy=l,exports.isSharedArrayBuffer=s,exports.isTrapError=o;
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.mts ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+
3
+ import type { Worker as Worker_2 } from 'worker_threads';
4
+
5
+ /** @public */
6
+ export declare interface BaseOptions {
7
+ wasi: WASIInstance;
8
+ version?: 'preview1';
9
+ wasm64?: boolean;
10
+ }
11
+
12
+ /** @public */
13
+ export declare interface ChildThreadOptions extends BaseOptions {
14
+ childThread: true;
15
+ postMessage?: (data: any) => void;
16
+ }
17
+
18
+ /** @public */
19
+ export declare interface CleanupThreadPayload {
20
+ tid: number;
21
+ }
22
+
23
+ /** @public */
24
+ export declare interface CommandInfo<T extends CommandType> {
25
+ type: T;
26
+ payload: CommandPayloadMap[T];
27
+ }
28
+
29
+ /** @public */
30
+ export declare interface CommandPayloadMap {
31
+ load: LoadPayload;
32
+ loaded: LoadedPayload;
33
+ start: StartPayload;
34
+ 'cleanup-thread': CleanupThreadPayload;
35
+ 'terminate-all-threads': TerminateAllThreadsPayload;
36
+ 'spawn-thread': SpawnThreadPayload;
37
+ }
38
+
39
+ /** @public */
40
+ export declare type CommandType = keyof CommandPayloadMap;
41
+
42
+ /** @public */
43
+ export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
44
+
45
+ /** @public */
46
+ export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
47
+
48
+ /** @public */
49
+ export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
50
+
51
+ /** @public */
52
+ export declare interface LoadedPayload {
53
+ }
54
+
55
+ /** @public */
56
+ export declare interface LoadPayload {
57
+ wasmModule: WebAssembly.Module;
58
+ wasmMemory: WebAssembly.Memory;
59
+ sab?: Int32Array;
60
+ }
61
+
62
+ /** @public */
63
+ export declare interface MainThreadBaseOptions extends BaseOptions {
64
+ waitThreadStart?: boolean | number;
65
+ }
66
+
67
+ /** @public */
68
+ export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
69
+
70
+ /** @public */
71
+ export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
72
+ }
73
+
74
+ /** @public */
75
+ export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
76
+ threadManager?: ThreadManager | (() => ThreadManager);
77
+ }
78
+
79
+ /** @public */
80
+ export declare interface MessageEventData<T extends CommandType> {
81
+ __emnapi__: CommandInfo<T>;
82
+ }
83
+
84
+ /** @public */
85
+ export declare interface ReuseWorkerOptions {
86
+ /**
87
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
88
+ */
89
+ size: number;
90
+ /**
91
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
92
+ */
93
+ strict?: boolean;
94
+ }
95
+
96
+ /** @public */
97
+ export declare interface SpawnThreadPayload {
98
+ startArg: number;
99
+ errorOrTid: number;
100
+ }
101
+
102
+ /** @public */
103
+ export declare interface StartPayload {
104
+ tid: number;
105
+ arg: number;
106
+ sab?: Int32Array;
107
+ }
108
+
109
+ /** @public */
110
+ export declare interface StartResult {
111
+ exitCode: number;
112
+ instance: WebAssembly.Instance;
113
+ }
114
+
115
+ /** @public */
116
+ export declare interface TerminateAllThreadsPayload {
117
+ }
118
+
119
+ /** @public */
120
+ export declare class ThreadManager {
121
+ unusedWorkers: WorkerLike[];
122
+ runningWorkers: WorkerLike[];
123
+ pthreads: Record<number, WorkerLike>;
124
+ get nextWorkerID(): number;
125
+ wasmModule: WebAssembly.Module | null;
126
+ wasmMemory: WebAssembly.Memory | null;
127
+ private readonly messageEvents;
128
+ private readonly _childThread;
129
+ private readonly _onCreateWorker;
130
+ private readonly _reuseWorker;
131
+ private readonly _beforeLoad?;
132
+ /* Excluded from this release type: printErr */
133
+ threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
134
+ constructor(options: ThreadManagerOptions);
135
+ init(): void;
136
+ initMainThread(): void;
137
+ private preparePool;
138
+ shouldPreloadWorkers(): boolean;
139
+ loadWasmModuleToAllWorkers(): Promise<WorkerLike[]>;
140
+ preloadWorkers(): Promise<WorkerLike[]>;
141
+ setup(wasmModule: WebAssembly.Module, wasmMemory: WebAssembly.Memory): void;
142
+ markId(worker: WorkerLike): number;
143
+ returnWorkerToPool(worker: WorkerLike): void;
144
+ loadWasmModuleToWorker(worker: WorkerLike, sab?: Int32Array): Promise<WorkerLike>;
145
+ allocateUnusedWorker(): WorkerLike;
146
+ getNewWorker(sab?: Int32Array): WorkerLike | undefined;
147
+ cleanThread(worker: WorkerLike, tid: number, force?: boolean): void;
148
+ terminateWorker(worker: WorkerLike): void;
149
+ terminateAllThreads(): void;
150
+ addMessageEventListener(worker: WorkerLike, onMessage: (e: WorkerMessageEvent) => void): () => void;
151
+ fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
152
+ }
153
+
154
+ /** @public */
155
+ export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
156
+
157
+ /** @public */
158
+ export declare interface ThreadManagerOptionsBase {
159
+ printErr?: (message: string) => void;
160
+ threadSpawn?: (startArg: number, errorOrTid?: number) => number;
161
+ }
162
+
163
+ /** @public */
164
+ export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
165
+ childThread: true;
166
+ }
167
+
168
+ /** @public */
169
+ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
170
+ beforeLoad?: (worker: WorkerLike) => any;
171
+ reuseWorker?: boolean | number | ReuseWorkerOptions;
172
+ onCreateWorker: WorkerFactory;
173
+ childThread?: false;
174
+ }
175
+
176
+ /** @public */
177
+ export declare class ThreadMessageHandler {
178
+ protected instance: WebAssembly.Instance | undefined;
179
+ private messagesBeforeLoad;
180
+ protected postMessage: (message: any) => void;
181
+ protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
182
+ protected onError: (error: Error, type: WorkerMessageType) => void;
183
+ constructor(options?: ThreadMessageHandlerOptions);
184
+ /** @virtual */
185
+ instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
186
+ /** @virtual */
187
+ handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
188
+ private _load;
189
+ private _start;
190
+ protected _loaded(err: Error | null, source: WebAssembly.WebAssemblyInstantiatedSource | null, payload: LoadPayload): void;
191
+ protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
192
+ }
193
+
194
+ /** @public */
195
+ export declare interface ThreadMessageHandlerOptions {
196
+ onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
197
+ onError?: (error: Error, type: WorkerMessageType) => void;
198
+ postMessage?: (message: any) => void;
199
+ }
200
+
201
+ /** @public */
202
+ export declare interface WASIInstance {
203
+ readonly wasiImport?: Record<string, any>;
204
+ initialize(instance: object): void;
205
+ start(instance: object): number;
206
+ getImportObject?(): any;
207
+ }
208
+
209
+ /** @public */
210
+ export declare class WASIThreads {
211
+ PThread: ThreadManager | undefined;
212
+ private wasmMemory;
213
+ private wasmInstance;
214
+ private readonly threadSpawn;
215
+ readonly childThread: boolean;
216
+ private readonly postMessage;
217
+ readonly wasi: WASIInstance;
218
+ constructor(options: WASIThreadsOptions);
219
+ getImportObject(): {
220
+ wasi: WASIThreadsImports;
221
+ };
222
+ setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
223
+ preloadWorkers(): Promise<WorkerLike[]>;
224
+ /**
225
+ * It's ok to call this method to a WASI command module.
226
+ *
227
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
228
+ *
229
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
230
+ */
231
+ initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
232
+ /**
233
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
234
+ * ```js
235
+ * this.initialize(instance, module, memory)
236
+ * this.wasi.start(instance)
237
+ * ```
238
+ */
239
+ start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
240
+ terminateAllThreads(): void;
241
+ }
242
+
243
+ /** @public */
244
+ export declare interface WASIThreadsImports {
245
+ 'thread-spawn': (startArg: number, errorOrTid?: number) => number;
246
+ }
247
+
248
+ /** @public */
249
+ export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
250
+
251
+ /** @public */
252
+ export declare type WorkerFactory = (ctx: {
253
+ type: string;
254
+ name: string;
255
+ }) => WorkerLike;
256
+
257
+ /** @public */
258
+ export declare type WorkerLike = (Worker | Worker_2) & {
259
+ whenLoaded?: Promise<WorkerLike>;
260
+ loaded?: boolean;
261
+ __emnapi_tid?: number;
262
+ };
263
+
264
+ /** @public */
265
+ export declare interface WorkerMessageEvent<T = any> {
266
+ data: T;
267
+ }
268
+
269
+ /** @public */
270
+ export declare type WorkerMessageType = 'load' | 'start';
271
+
272
+ export { }
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+
3
+ import type { Worker as Worker_2 } from 'worker_threads';
4
+
5
+ /** @public */
6
+ export declare interface BaseOptions {
7
+ wasi: WASIInstance;
8
+ version?: 'preview1';
9
+ wasm64?: boolean;
10
+ }
11
+
12
+ /** @public */
13
+ export declare interface ChildThreadOptions extends BaseOptions {
14
+ childThread: true;
15
+ postMessage?: (data: any) => void;
16
+ }
17
+
18
+ /** @public */
19
+ export declare interface CleanupThreadPayload {
20
+ tid: number;
21
+ }
22
+
23
+ /** @public */
24
+ export declare interface CommandInfo<T extends CommandType> {
25
+ type: T;
26
+ payload: CommandPayloadMap[T];
27
+ }
28
+
29
+ /** @public */
30
+ export declare interface CommandPayloadMap {
31
+ load: LoadPayload;
32
+ loaded: LoadedPayload;
33
+ start: StartPayload;
34
+ 'cleanup-thread': CleanupThreadPayload;
35
+ 'terminate-all-threads': TerminateAllThreadsPayload;
36
+ 'spawn-thread': SpawnThreadPayload;
37
+ }
38
+
39
+ /** @public */
40
+ export declare type CommandType = keyof CommandPayloadMap;
41
+
42
+ /** @public */
43
+ export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
44
+
45
+ /** @public */
46
+ export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
47
+
48
+ /** @public */
49
+ export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
50
+
51
+ /** @public */
52
+ export declare interface LoadedPayload {
53
+ }
54
+
55
+ /** @public */
56
+ export declare interface LoadPayload {
57
+ wasmModule: WebAssembly.Module;
58
+ wasmMemory: WebAssembly.Memory;
59
+ sab?: Int32Array;
60
+ }
61
+
62
+ /** @public */
63
+ export declare interface MainThreadBaseOptions extends BaseOptions {
64
+ waitThreadStart?: boolean | number;
65
+ }
66
+
67
+ /** @public */
68
+ export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
69
+
70
+ /** @public */
71
+ export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
72
+ }
73
+
74
+ /** @public */
75
+ export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
76
+ threadManager?: ThreadManager | (() => ThreadManager);
77
+ }
78
+
79
+ /** @public */
80
+ export declare interface MessageEventData<T extends CommandType> {
81
+ __emnapi__: CommandInfo<T>;
82
+ }
83
+
84
+ /** @public */
85
+ export declare interface ReuseWorkerOptions {
86
+ /**
87
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
88
+ */
89
+ size: number;
90
+ /**
91
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
92
+ */
93
+ strict?: boolean;
94
+ }
95
+
96
+ /** @public */
97
+ export declare interface SpawnThreadPayload {
98
+ startArg: number;
99
+ errorOrTid: number;
100
+ }
101
+
102
+ /** @public */
103
+ export declare interface StartPayload {
104
+ tid: number;
105
+ arg: number;
106
+ sab?: Int32Array;
107
+ }
108
+
109
+ /** @public */
110
+ export declare interface StartResult {
111
+ exitCode: number;
112
+ instance: WebAssembly.Instance;
113
+ }
114
+
115
+ /** @public */
116
+ export declare interface TerminateAllThreadsPayload {
117
+ }
118
+
119
+ /** @public */
120
+ export declare class ThreadManager {
121
+ unusedWorkers: WorkerLike[];
122
+ runningWorkers: WorkerLike[];
123
+ pthreads: Record<number, WorkerLike>;
124
+ get nextWorkerID(): number;
125
+ wasmModule: WebAssembly.Module | null;
126
+ wasmMemory: WebAssembly.Memory | null;
127
+ private readonly messageEvents;
128
+ private readonly _childThread;
129
+ private readonly _onCreateWorker;
130
+ private readonly _reuseWorker;
131
+ private readonly _beforeLoad?;
132
+ /* Excluded from this release type: printErr */
133
+ threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
134
+ constructor(options: ThreadManagerOptions);
135
+ init(): void;
136
+ initMainThread(): void;
137
+ private preparePool;
138
+ shouldPreloadWorkers(): boolean;
139
+ loadWasmModuleToAllWorkers(): Promise<WorkerLike[]>;
140
+ preloadWorkers(): Promise<WorkerLike[]>;
141
+ setup(wasmModule: WebAssembly.Module, wasmMemory: WebAssembly.Memory): void;
142
+ markId(worker: WorkerLike): number;
143
+ returnWorkerToPool(worker: WorkerLike): void;
144
+ loadWasmModuleToWorker(worker: WorkerLike, sab?: Int32Array): Promise<WorkerLike>;
145
+ allocateUnusedWorker(): WorkerLike;
146
+ getNewWorker(sab?: Int32Array): WorkerLike | undefined;
147
+ cleanThread(worker: WorkerLike, tid: number, force?: boolean): void;
148
+ terminateWorker(worker: WorkerLike): void;
149
+ terminateAllThreads(): void;
150
+ addMessageEventListener(worker: WorkerLike, onMessage: (e: WorkerMessageEvent) => void): () => void;
151
+ fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
152
+ }
153
+
154
+ /** @public */
155
+ export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
156
+
157
+ /** @public */
158
+ export declare interface ThreadManagerOptionsBase {
159
+ printErr?: (message: string) => void;
160
+ threadSpawn?: (startArg: number, errorOrTid?: number) => number;
161
+ }
162
+
163
+ /** @public */
164
+ export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
165
+ childThread: true;
166
+ }
167
+
168
+ /** @public */
169
+ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
170
+ beforeLoad?: (worker: WorkerLike) => any;
171
+ reuseWorker?: boolean | number | ReuseWorkerOptions;
172
+ onCreateWorker: WorkerFactory;
173
+ childThread?: false;
174
+ }
175
+
176
+ /** @public */
177
+ export declare class ThreadMessageHandler {
178
+ protected instance: WebAssembly.Instance | undefined;
179
+ private messagesBeforeLoad;
180
+ protected postMessage: (message: any) => void;
181
+ protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
182
+ protected onError: (error: Error, type: WorkerMessageType) => void;
183
+ constructor(options?: ThreadMessageHandlerOptions);
184
+ /** @virtual */
185
+ instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
186
+ /** @virtual */
187
+ handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
188
+ private _load;
189
+ private _start;
190
+ protected _loaded(err: Error | null, source: WebAssembly.WebAssemblyInstantiatedSource | null, payload: LoadPayload): void;
191
+ protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
192
+ }
193
+
194
+ /** @public */
195
+ export declare interface ThreadMessageHandlerOptions {
196
+ onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
197
+ onError?: (error: Error, type: WorkerMessageType) => void;
198
+ postMessage?: (message: any) => void;
199
+ }
200
+
201
+ /** @public */
202
+ export declare interface WASIInstance {
203
+ readonly wasiImport?: Record<string, any>;
204
+ initialize(instance: object): void;
205
+ start(instance: object): number;
206
+ getImportObject?(): any;
207
+ }
208
+
209
+ /** @public */
210
+ export declare class WASIThreads {
211
+ PThread: ThreadManager | undefined;
212
+ private wasmMemory;
213
+ private wasmInstance;
214
+ private readonly threadSpawn;
215
+ readonly childThread: boolean;
216
+ private readonly postMessage;
217
+ readonly wasi: WASIInstance;
218
+ constructor(options: WASIThreadsOptions);
219
+ getImportObject(): {
220
+ wasi: WASIThreadsImports;
221
+ };
222
+ setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
223
+ preloadWorkers(): Promise<WorkerLike[]>;
224
+ /**
225
+ * It's ok to call this method to a WASI command module.
226
+ *
227
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
228
+ *
229
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
230
+ */
231
+ initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
232
+ /**
233
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
234
+ * ```js
235
+ * this.initialize(instance, module, memory)
236
+ * this.wasi.start(instance)
237
+ * ```
238
+ */
239
+ start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
240
+ terminateAllThreads(): void;
241
+ }
242
+
243
+ /** @public */
244
+ export declare interface WASIThreadsImports {
245
+ 'thread-spawn': (startArg: number, errorOrTid?: number) => number;
246
+ }
247
+
248
+ /** @public */
249
+ export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
250
+
251
+ /** @public */
252
+ export declare type WorkerFactory = (ctx: {
253
+ type: string;
254
+ name: string;
255
+ }) => WorkerLike;
256
+
257
+ /** @public */
258
+ export declare type WorkerLike = (Worker | Worker_2) & {
259
+ whenLoaded?: Promise<WorkerLike>;
260
+ loaded?: boolean;
261
+ __emnapi_tid?: number;
262
+ };
263
+
264
+ /** @public */
265
+ export declare interface WorkerMessageEvent<T = any> {
266
+ data: T;
267
+ }
268
+
269
+ /** @public */
270
+ export declare type WorkerMessageType = 'load' | 'start';
271
+
272
+ export { }
273
+
274
+ export as namespace wasiThreads;
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js ADDED
@@ -0,0 +1,942 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var _WebAssembly = typeof WebAssembly !== 'undefined'
2
+ ? WebAssembly
3
+ : typeof WXWebAssembly !== 'undefined'
4
+ ? WXWebAssembly
5
+ : undefined;
6
+ var ENVIRONMENT_IS_NODE = typeof process === 'object' && process !== null &&
7
+ typeof process.versions === 'object' && process.versions !== null &&
8
+ typeof process.versions.node === 'string';
9
+ function getPostMessage(options) {
10
+ return typeof (options === null || options === void 0 ? void 0 : options.postMessage) === 'function'
11
+ ? options.postMessage
12
+ : typeof postMessage === 'function'
13
+ ? postMessage
14
+ : undefined;
15
+ }
16
+ function serizeErrorToBuffer(sab, code, error) {
17
+ var i32array = new Int32Array(sab);
18
+ Atomics.store(i32array, 0, code);
19
+ if (code > 1 && error) {
20
+ var name_1 = error.name;
21
+ var message = error.message;
22
+ var stack = error.stack;
23
+ var nameBuffer = new TextEncoder().encode(name_1);
24
+ var messageBuffer = new TextEncoder().encode(message);
25
+ var stackBuffer = new TextEncoder().encode(stack);
26
+ Atomics.store(i32array, 1, nameBuffer.length);
27
+ Atomics.store(i32array, 2, messageBuffer.length);
28
+ Atomics.store(i32array, 3, stackBuffer.length);
29
+ var buffer = new Uint8Array(sab);
30
+ buffer.set(nameBuffer, 16);
31
+ buffer.set(messageBuffer, 16 + nameBuffer.length);
32
+ buffer.set(stackBuffer, 16 + nameBuffer.length + messageBuffer.length);
33
+ }
34
+ }
35
+ function deserizeErrorFromBuffer(sab) {
36
+ var _a, _b;
37
+ var i32array = new Int32Array(sab);
38
+ var status = Atomics.load(i32array, 0);
39
+ if (status <= 1) {
40
+ return null;
41
+ }
42
+ var nameLength = Atomics.load(i32array, 1);
43
+ var messageLength = Atomics.load(i32array, 2);
44
+ var stackLength = Atomics.load(i32array, 3);
45
+ var buffer = new Uint8Array(sab);
46
+ var nameBuffer = buffer.slice(16, 16 + nameLength);
47
+ var messageBuffer = buffer.slice(16 + nameLength, 16 + nameLength + messageLength);
48
+ var stackBuffer = buffer.slice(16 + nameLength + messageLength, 16 + nameLength + messageLength + stackLength);
49
+ var name = new TextDecoder().decode(nameBuffer);
50
+ var message = new TextDecoder().decode(messageBuffer);
51
+ var stack = new TextDecoder().decode(stackBuffer);
52
+ var ErrorConstructor = (_a = globalThis[name]) !== null && _a !== void 0 ? _a : (name === 'RuntimeError' ? ((_b = _WebAssembly.RuntimeError) !== null && _b !== void 0 ? _b : Error) : Error);
53
+ var error = new ErrorConstructor(message);
54
+ Object.defineProperty(error, 'stack', {
55
+ value: stack,
56
+ writable: true,
57
+ enumerable: false,
58
+ configurable: true
59
+ });
60
+ return error;
61
+ }
62
+ /** @public */
63
+ function isSharedArrayBuffer(value) {
64
+ return ((typeof SharedArrayBuffer === 'function' && value instanceof SharedArrayBuffer) ||
65
+ (Object.prototype.toString.call(value) === '[object SharedArrayBuffer]'));
66
+ }
67
+ /** @public */
68
+ function isTrapError(e) {
69
+ try {
70
+ return e instanceof _WebAssembly.RuntimeError;
71
+ }
72
+ catch (_) {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ function createMessage(type, payload) {
78
+ return {
79
+ __emnapi__: {
80
+ type: type,
81
+ payload: payload
82
+ }
83
+ };
84
+ }
85
+
86
+ var WASI_THREADS_MAX_TID = 0x1FFFFFFF;
87
+ function checkSharedWasmMemory(wasmMemory) {
88
+ if (wasmMemory) {
89
+ if (!isSharedArrayBuffer(wasmMemory.buffer)) {
90
+ throw new Error('Multithread features require shared wasm memory. ' +
91
+ 'Try to compile with `-matomics -mbulk-memory` and use `--import-memory --shared-memory` during linking, ' +
92
+ 'then create WebAssembly.Memory with `shared: true` option');
93
+ }
94
+ }
95
+ else {
96
+ if (typeof SharedArrayBuffer === 'undefined') {
97
+ throw new Error('Current environment does not support SharedArrayBuffer, threads are not available!');
98
+ }
99
+ }
100
+ }
101
+ function getReuseWorker(value) {
102
+ var _a;
103
+ if (typeof value === 'boolean') {
104
+ return value ? { size: 0, strict: false } : false;
105
+ }
106
+ if (typeof value === 'number') {
107
+ if (!(value >= 0)) {
108
+ throw new RangeError('reuseWorker: size must be a non-negative integer');
109
+ }
110
+ return { size: value, strict: false };
111
+ }
112
+ if (!value) {
113
+ return false;
114
+ }
115
+ var size = (_a = Number(value.size)) !== null && _a !== void 0 ? _a : 0;
116
+ var strict = Boolean(value.strict);
117
+ if (!(size > 0) && strict) {
118
+ throw new RangeError('reuseWorker: size must be set to positive integer if strict is set to true');
119
+ }
120
+ return { size: size, strict: strict };
121
+ }
122
+ var nextWorkerID = 0;
123
+ /** @public */
124
+ var ThreadManager = /*#__PURE__*/ (function () {
125
+ function ThreadManager(options) {
126
+ var _a;
127
+ this.unusedWorkers = [];
128
+ this.runningWorkers = [];
129
+ this.pthreads = Object.create(null);
130
+ this.wasmModule = null;
131
+ this.wasmMemory = null;
132
+ this.messageEvents = new WeakMap();
133
+ if (!options) {
134
+ throw new TypeError('ThreadManager(): options is not provided');
135
+ }
136
+ if ('childThread' in options) {
137
+ this._childThread = Boolean(options.childThread);
138
+ }
139
+ else {
140
+ this._childThread = false;
141
+ }
142
+ if (this._childThread) {
143
+ this._onCreateWorker = undefined;
144
+ this._reuseWorker = false;
145
+ this._beforeLoad = undefined;
146
+ }
147
+ else {
148
+ this._onCreateWorker = options.onCreateWorker;
149
+ this._reuseWorker = getReuseWorker(options.reuseWorker);
150
+ this._beforeLoad = options.beforeLoad;
151
+ }
152
+ this.printErr = (_a = options.printErr) !== null && _a !== void 0 ? _a : console.error.bind(console);
153
+ this.threadSpawn = options.threadSpawn;
154
+ }
155
+ Object.defineProperty(ThreadManager.prototype, "nextWorkerID", {
156
+ get: function () { return nextWorkerID; },
157
+ enumerable: false,
158
+ configurable: true
159
+ });
160
+ ThreadManager.prototype.init = function () {
161
+ if (!this._childThread) {
162
+ this.initMainThread();
163
+ }
164
+ };
165
+ ThreadManager.prototype.initMainThread = function () {
166
+ this.preparePool();
167
+ };
168
+ ThreadManager.prototype.preparePool = function () {
169
+ if (this._reuseWorker) {
170
+ if (this._reuseWorker.size) {
171
+ var pthreadPoolSize = this._reuseWorker.size;
172
+ while (pthreadPoolSize--) {
173
+ var worker = this.allocateUnusedWorker();
174
+ if (ENVIRONMENT_IS_NODE) {
175
+ // https://github.com/nodejs/node/issues/53036
176
+ worker.once('message', function () { });
177
+ worker.unref();
178
+ }
179
+ }
180
+ }
181
+ }
182
+ };
183
+ ThreadManager.prototype.shouldPreloadWorkers = function () {
184
+ return !this._childThread && this._reuseWorker && this._reuseWorker.size > 0;
185
+ };
186
+ ThreadManager.prototype.loadWasmModuleToAllWorkers = function () {
187
+ var _this_1 = this;
188
+ var promises = Array(this.unusedWorkers.length);
189
+ var _loop_1 = function (i) {
190
+ var worker = this_1.unusedWorkers[i];
191
+ if (ENVIRONMENT_IS_NODE)
192
+ worker.ref();
193
+ promises[i] = this_1.loadWasmModuleToWorker(worker).then(function (w) {
194
+ if (ENVIRONMENT_IS_NODE)
195
+ worker.unref();
196
+ return w;
197
+ }, function (e) {
198
+ if (ENVIRONMENT_IS_NODE)
199
+ worker.unref();
200
+ throw e;
201
+ });
202
+ };
203
+ var this_1 = this;
204
+ for (var i = 0; i < this.unusedWorkers.length; ++i) {
205
+ _loop_1(i);
206
+ }
207
+ return Promise.all(promises).catch(function (err) {
208
+ _this_1.terminateAllThreads();
209
+ throw err;
210
+ });
211
+ };
212
+ ThreadManager.prototype.preloadWorkers = function () {
213
+ if (this.shouldPreloadWorkers()) {
214
+ return this.loadWasmModuleToAllWorkers();
215
+ }
216
+ return Promise.resolve([]);
217
+ };
218
+ ThreadManager.prototype.setup = function (wasmModule, wasmMemory) {
219
+ this.wasmModule = wasmModule;
220
+ this.wasmMemory = wasmMemory;
221
+ };
222
+ ThreadManager.prototype.markId = function (worker) {
223
+ if (worker.__emnapi_tid)
224
+ return worker.__emnapi_tid;
225
+ var tid = nextWorkerID + 43;
226
+ nextWorkerID = (nextWorkerID + 1) % (WASI_THREADS_MAX_TID - 42);
227
+ this.pthreads[tid] = worker;
228
+ worker.__emnapi_tid = tid;
229
+ return tid;
230
+ };
231
+ ThreadManager.prototype.returnWorkerToPool = function (worker) {
232
+ var tid = worker.__emnapi_tid;
233
+ if (tid !== undefined) {
234
+ delete this.pthreads[tid];
235
+ }
236
+ this.unusedWorkers.push(worker);
237
+ this.runningWorkers.splice(this.runningWorkers.indexOf(worker), 1);
238
+ delete worker.__emnapi_tid;
239
+ if (ENVIRONMENT_IS_NODE) {
240
+ worker.unref();
241
+ }
242
+ };
243
+ ThreadManager.prototype.loadWasmModuleToWorker = function (worker, sab) {
244
+ var _this_1 = this;
245
+ if (worker.whenLoaded)
246
+ return worker.whenLoaded;
247
+ var err = this.printErr;
248
+ var beforeLoad = this._beforeLoad;
249
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
250
+ var _this = this;
251
+ worker.whenLoaded = new Promise(function (resolve, reject) {
252
+ var handleError = function (e) {
253
+ var message = 'worker sent an error!';
254
+ if (worker.__emnapi_tid !== undefined) {
255
+ message = 'worker (tid = ' + worker.__emnapi_tid + ') sent an error!';
256
+ }
257
+ if ('message' in e) {
258
+ err(message + ' ' + e.message);
259
+ if (e.message.indexOf('RuntimeError') !== -1 || e.message.indexOf('unreachable') !== -1) {
260
+ try {
261
+ _this.terminateAllThreads();
262
+ }
263
+ catch (_) { }
264
+ }
265
+ }
266
+ else {
267
+ err(message);
268
+ }
269
+ reject(e);
270
+ throw e;
271
+ };
272
+ var handleMessage = function (data) {
273
+ if (data.__emnapi__) {
274
+ var type = data.__emnapi__.type;
275
+ var payload = data.__emnapi__.payload;
276
+ if (type === 'loaded') {
277
+ worker.loaded = true;
278
+ if (ENVIRONMENT_IS_NODE && !worker.__emnapi_tid) {
279
+ worker.unref();
280
+ }
281
+ resolve(worker);
282
+ // if (payload.err) {
283
+ // err('failed to load in child thread: ' + (payload.err.message || payload.err))
284
+ // }
285
+ }
286
+ else if (type === 'cleanup-thread') {
287
+ if (payload.tid in _this_1.pthreads) {
288
+ _this_1.cleanThread(worker, payload.tid);
289
+ }
290
+ }
291
+ else if (type === 'spawn-thread') {
292
+ _this_1.threadSpawn(payload.startArg, payload.errorOrTid);
293
+ }
294
+ else if (type === 'terminate-all-threads') {
295
+ _this_1.terminateAllThreads();
296
+ }
297
+ }
298
+ };
299
+ worker.onmessage = function (e) {
300
+ handleMessage(e.data);
301
+ _this_1.fireMessageEvent(worker, e);
302
+ };
303
+ worker.onerror = handleError;
304
+ if (ENVIRONMENT_IS_NODE) {
305
+ worker.on('message', function (data) {
306
+ var _a, _b;
307
+ (_b = (_a = worker).onmessage) === null || _b === void 0 ? void 0 : _b.call(_a, {
308
+ data: data
309
+ });
310
+ });
311
+ worker.on('error', function (e) {
312
+ var _a, _b;
313
+ (_b = (_a = worker).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, e);
314
+ });
315
+ worker.on('detachedExit', function () { });
316
+ }
317
+ if (typeof beforeLoad === 'function') {
318
+ beforeLoad(worker);
319
+ }
320
+ try {
321
+ worker.postMessage(createMessage('load', {
322
+ wasmModule: _this_1.wasmModule,
323
+ wasmMemory: _this_1.wasmMemory,
324
+ sab: sab
325
+ }));
326
+ }
327
+ catch (err) {
328
+ checkSharedWasmMemory(_this_1.wasmMemory);
329
+ throw err;
330
+ }
331
+ });
332
+ return worker.whenLoaded;
333
+ };
334
+ ThreadManager.prototype.allocateUnusedWorker = function () {
335
+ var _onCreateWorker = this._onCreateWorker;
336
+ if (typeof _onCreateWorker !== 'function') {
337
+ throw new TypeError('`options.onCreateWorker` is not provided');
338
+ }
339
+ var worker = _onCreateWorker({ type: 'thread', name: 'emnapi-pthread' });
340
+ this.unusedWorkers.push(worker);
341
+ return worker;
342
+ };
343
+ ThreadManager.prototype.getNewWorker = function (sab) {
344
+ if (this._reuseWorker) {
345
+ if (this.unusedWorkers.length === 0) {
346
+ if (this._reuseWorker.strict) {
347
+ if (!ENVIRONMENT_IS_NODE) {
348
+ var err = this.printErr;
349
+ err('Tried to spawn a new thread, but the thread pool is exhausted.\n' +
350
+ 'This might result in a deadlock unless some threads eventually exit or the code explicitly breaks out to the event loop.');
351
+ return;
352
+ }
353
+ }
354
+ var worker_1 = this.allocateUnusedWorker();
355
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
356
+ this.loadWasmModuleToWorker(worker_1, sab);
357
+ }
358
+ return this.unusedWorkers.pop();
359
+ }
360
+ var worker = this.allocateUnusedWorker();
361
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
362
+ this.loadWasmModuleToWorker(worker, sab);
363
+ return this.unusedWorkers.pop();
364
+ };
365
+ ThreadManager.prototype.cleanThread = function (worker, tid, force) {
366
+ if (!force && this._reuseWorker) {
367
+ this.returnWorkerToPool(worker);
368
+ }
369
+ else {
370
+ delete this.pthreads[tid];
371
+ var index = this.runningWorkers.indexOf(worker);
372
+ if (index !== -1) {
373
+ this.runningWorkers.splice(index, 1);
374
+ }
375
+ this.terminateWorker(worker);
376
+ delete worker.__emnapi_tid;
377
+ }
378
+ };
379
+ ThreadManager.prototype.terminateWorker = function (worker) {
380
+ var _this_1 = this;
381
+ var _a;
382
+ var tid = worker.__emnapi_tid;
383
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
384
+ worker.terminate();
385
+ (_a = this.messageEvents.get(worker)) === null || _a === void 0 ? void 0 : _a.clear();
386
+ this.messageEvents.delete(worker);
387
+ worker.onmessage = function (e) {
388
+ if (e.data.__emnapi__) {
389
+ var err = _this_1.printErr;
390
+ err('received "' + e.data.__emnapi__.type + '" command from terminated worker: ' + tid);
391
+ }
392
+ };
393
+ };
394
+ ThreadManager.prototype.terminateAllThreads = function () {
395
+ for (var i = 0; i < this.runningWorkers.length; ++i) {
396
+ this.terminateWorker(this.runningWorkers[i]);
397
+ }
398
+ for (var i = 0; i < this.unusedWorkers.length; ++i) {
399
+ this.terminateWorker(this.unusedWorkers[i]);
400
+ }
401
+ this.unusedWorkers = [];
402
+ this.runningWorkers = [];
403
+ this.pthreads = Object.create(null);
404
+ this.preparePool();
405
+ };
406
+ ThreadManager.prototype.addMessageEventListener = function (worker, onMessage) {
407
+ var listeners = this.messageEvents.get(worker);
408
+ if (!listeners) {
409
+ listeners = new Set();
410
+ this.messageEvents.set(worker, listeners);
411
+ }
412
+ listeners.add(onMessage);
413
+ return function () {
414
+ listeners === null || listeners === void 0 ? void 0 : listeners.delete(onMessage);
415
+ };
416
+ };
417
+ ThreadManager.prototype.fireMessageEvent = function (worker, e) {
418
+ var listeners = this.messageEvents.get(worker);
419
+ if (!listeners)
420
+ return;
421
+ var err = this.printErr;
422
+ listeners.forEach(function (listener) {
423
+ try {
424
+ listener(e);
425
+ }
426
+ catch (e) {
427
+ err(e.stack);
428
+ }
429
+ });
430
+ };
431
+ return ThreadManager;
432
+ }());
433
+
434
+ var kIsProxy = Symbol('kIsProxy');
435
+ /** @public */
436
+ function createInstanceProxy(instance, memory) {
437
+ if (instance[kIsProxy])
438
+ return instance;
439
+ // https://github.com/nodejs/help/issues/4102
440
+ var originalExports = instance.exports;
441
+ var createHandler = function (target) {
442
+ var handlers = [
443
+ 'apply',
444
+ 'construct',
445
+ 'defineProperty',
446
+ 'deleteProperty',
447
+ 'get',
448
+ 'getOwnPropertyDescriptor',
449
+ 'getPrototypeOf',
450
+ 'has',
451
+ 'isExtensible',
452
+ 'ownKeys',
453
+ 'preventExtensions',
454
+ 'set',
455
+ 'setPrototypeOf'
456
+ ];
457
+ var handler = {};
458
+ var _loop_1 = function (i) {
459
+ var name_1 = handlers[i];
460
+ handler[name_1] = function () {
461
+ var args = Array.prototype.slice.call(arguments, 1);
462
+ args.unshift(target);
463
+ return Reflect[name_1].apply(Reflect, args);
464
+ };
465
+ };
466
+ for (var i = 0; i < handlers.length; i++) {
467
+ _loop_1(i);
468
+ }
469
+ return handler;
470
+ };
471
+ var handler = createHandler(originalExports);
472
+ var _initialize = function () { };
473
+ var _start = function () { return 0; };
474
+ handler.get = function (_target, p, receiver) {
475
+ var _a;
476
+ if (p === 'memory') {
477
+ return (_a = (typeof memory === 'function' ? memory() : memory)) !== null && _a !== void 0 ? _a : Reflect.get(originalExports, p, receiver);
478
+ }
479
+ if (p === '_initialize') {
480
+ return p in originalExports ? _initialize : undefined;
481
+ }
482
+ if (p === '_start') {
483
+ return p in originalExports ? _start : undefined;
484
+ }
485
+ return Reflect.get(originalExports, p, receiver);
486
+ };
487
+ handler.has = function (_target, p) {
488
+ if (p === 'memory')
489
+ return true;
490
+ return Reflect.has(originalExports, p);
491
+ };
492
+ var exportsProxy = new Proxy(Object.create(null), handler);
493
+ return new Proxy(instance, {
494
+ get: function (target, p, receiver) {
495
+ if (p === 'exports') {
496
+ return exportsProxy;
497
+ }
498
+ if (p === kIsProxy) {
499
+ return true;
500
+ }
501
+ return Reflect.get(target, p, receiver);
502
+ }
503
+ });
504
+ }
505
+
506
+ var patchedWasiInstances = new WeakMap();
507
+ /** @public */
508
+ var WASIThreads = /*#__PURE__*/ (function () {
509
+ function WASIThreads(options) {
510
+ var _this_1 = this;
511
+ if (!options) {
512
+ throw new TypeError('WASIThreads(): options is not provided');
513
+ }
514
+ if (!options.wasi) {
515
+ throw new TypeError('WASIThreads(): options.wasi is not provided');
516
+ }
517
+ patchedWasiInstances.set(this, new WeakSet());
518
+ var wasi = options.wasi;
519
+ patchWasiInstance(this, wasi);
520
+ this.wasi = wasi;
521
+ if ('childThread' in options) {
522
+ this.childThread = Boolean(options.childThread);
523
+ }
524
+ else {
525
+ this.childThread = false;
526
+ }
527
+ this.PThread = undefined;
528
+ if ('threadManager' in options) {
529
+ if (typeof options.threadManager === 'function') {
530
+ this.PThread = options.threadManager();
531
+ }
532
+ else {
533
+ this.PThread = options.threadManager;
534
+ }
535
+ }
536
+ else {
537
+ if (!this.childThread) {
538
+ this.PThread = new ThreadManager(options);
539
+ this.PThread.init();
540
+ }
541
+ }
542
+ var waitThreadStart = false;
543
+ if ('waitThreadStart' in options) {
544
+ waitThreadStart = typeof options.waitThreadStart === 'number' ? options.waitThreadStart : Boolean(options.waitThreadStart);
545
+ }
546
+ var postMessage = getPostMessage(options);
547
+ if (this.childThread && typeof postMessage !== 'function') {
548
+ throw new TypeError('options.postMessage is not a function');
549
+ }
550
+ this.postMessage = postMessage;
551
+ var wasm64 = Boolean(options.wasm64);
552
+ var threadSpawn = function (startArg, errorOrTid) {
553
+ var _a;
554
+ var EAGAIN = 6;
555
+ var isNewABI = errorOrTid !== undefined;
556
+ try {
557
+ checkSharedWasmMemory(_this_1.wasmMemory);
558
+ }
559
+ catch (err) {
560
+ (_a = _this_1.PThread) === null || _a === void 0 ? void 0 : _a.printErr(err.stack);
561
+ if (isNewABI) {
562
+ var struct_1 = new Int32Array(_this_1.wasmMemory.buffer, errorOrTid, 2);
563
+ Atomics.store(struct_1, 0, 1);
564
+ Atomics.store(struct_1, 1, EAGAIN);
565
+ Atomics.notify(struct_1, 1);
566
+ return 1;
567
+ }
568
+ else {
569
+ return -EAGAIN;
570
+ }
571
+ }
572
+ if (!isNewABI) {
573
+ var malloc = _this_1.wasmInstance.exports.malloc;
574
+ errorOrTid = wasm64 ? Number(malloc(BigInt(8))) : (malloc(8) >>> 0);
575
+ if (!errorOrTid) {
576
+ return -48; /* ENOMEM */
577
+ }
578
+ }
579
+ var _free = _this_1.wasmInstance.exports.free;
580
+ var free = wasm64 ? function (ptr) { _free(BigInt(ptr)); } : _free;
581
+ var struct = new Int32Array(_this_1.wasmMemory.buffer, errorOrTid, 2);
582
+ Atomics.store(struct, 0, 0);
583
+ Atomics.store(struct, 1, 0);
584
+ if (_this_1.childThread) {
585
+ postMessage(createMessage('spawn-thread', {
586
+ startArg: startArg,
587
+ errorOrTid: errorOrTid
588
+ }));
589
+ Atomics.wait(struct, 1, 0);
590
+ var isError = Atomics.load(struct, 0);
591
+ var result = Atomics.load(struct, 1);
592
+ if (isNewABI) {
593
+ return isError;
594
+ }
595
+ free(errorOrTid);
596
+ return isError ? -result : result;
597
+ }
598
+ var shouldWait = waitThreadStart || (waitThreadStart === 0);
599
+ var sab;
600
+ if (shouldWait) {
601
+ sab = new Int32Array(new SharedArrayBuffer(16 + 8192));
602
+ Atomics.store(sab, 0, 0);
603
+ }
604
+ var worker;
605
+ var tid;
606
+ var PThread = _this_1.PThread;
607
+ try {
608
+ worker = PThread.getNewWorker(sab);
609
+ if (!worker) {
610
+ throw new Error('failed to get new worker');
611
+ }
612
+ tid = PThread.markId(worker);
613
+ if (ENVIRONMENT_IS_NODE) {
614
+ worker.unref();
615
+ }
616
+ worker.postMessage(createMessage('start', {
617
+ tid: tid,
618
+ arg: startArg,
619
+ sab: sab
620
+ }));
621
+ if (shouldWait) {
622
+ if (typeof waitThreadStart === 'number') {
623
+ var waitResult = Atomics.wait(sab, 0, 0, waitThreadStart);
624
+ if (waitResult === 'timed-out') {
625
+ try {
626
+ PThread.cleanThread(worker, tid, true);
627
+ }
628
+ catch (_) { }
629
+ throw new Error('Spawning thread timed out. Please check if the worker is created successfully and if message is handled properly in the worker.');
630
+ }
631
+ }
632
+ else {
633
+ Atomics.wait(sab, 0, 0);
634
+ }
635
+ var r = Atomics.load(sab, 0);
636
+ if (r > 1) {
637
+ try {
638
+ PThread.cleanThread(worker, tid, true);
639
+ }
640
+ catch (_) { }
641
+ throw deserizeErrorFromBuffer(sab.buffer);
642
+ }
643
+ }
644
+ }
645
+ catch (e) {
646
+ Atomics.store(struct, 0, 1);
647
+ Atomics.store(struct, 1, EAGAIN);
648
+ Atomics.notify(struct, 1);
649
+ PThread === null || PThread === void 0 ? void 0 : PThread.printErr(e.stack);
650
+ if (isNewABI) {
651
+ return 1;
652
+ }
653
+ free(errorOrTid);
654
+ return -EAGAIN;
655
+ }
656
+ Atomics.store(struct, 0, 0);
657
+ Atomics.store(struct, 1, tid);
658
+ Atomics.notify(struct, 1);
659
+ PThread.runningWorkers.push(worker);
660
+ if (!shouldWait) {
661
+ worker.whenLoaded.catch(function (err) {
662
+ delete worker.whenLoaded;
663
+ PThread.cleanThread(worker, tid, true);
664
+ throw err;
665
+ });
666
+ }
667
+ if (isNewABI) {
668
+ return 0;
669
+ }
670
+ free(errorOrTid);
671
+ return tid;
672
+ };
673
+ this.threadSpawn = threadSpawn;
674
+ if (this.PThread) {
675
+ this.PThread.threadSpawn = threadSpawn;
676
+ }
677
+ }
678
+ WASIThreads.prototype.getImportObject = function () {
679
+ return {
680
+ wasi: {
681
+ 'thread-spawn': this.threadSpawn
682
+ }
683
+ };
684
+ };
685
+ WASIThreads.prototype.setup = function (wasmInstance, wasmModule, wasmMemory) {
686
+ wasmMemory !== null && wasmMemory !== void 0 ? wasmMemory : (wasmMemory = wasmInstance.exports.memory);
687
+ this.wasmInstance = wasmInstance;
688
+ this.wasmMemory = wasmMemory;
689
+ if (this.PThread) {
690
+ this.PThread.setup(wasmModule, wasmMemory);
691
+ }
692
+ };
693
+ WASIThreads.prototype.preloadWorkers = function () {
694
+ if (this.PThread) {
695
+ return this.PThread.preloadWorkers();
696
+ }
697
+ return Promise.resolve([]);
698
+ };
699
+ /**
700
+ * It's ok to call this method to a WASI command module.
701
+ *
702
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
703
+ *
704
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
705
+ */
706
+ WASIThreads.prototype.initialize = function (instance, module, memory) {
707
+ var exports$1 = instance.exports;
708
+ memory !== null && memory !== void 0 ? memory : (memory = exports$1.memory);
709
+ if (this.childThread) {
710
+ instance = createInstanceProxy(instance, memory);
711
+ }
712
+ this.setup(instance, module, memory);
713
+ var wasi = this.wasi;
714
+ if (('_start' in exports$1) && (typeof exports$1._start === 'function')) {
715
+ if (this.childThread) {
716
+ wasi.start(instance);
717
+ try {
718
+ var kStarted = getWasiSymbol(wasi, 'kStarted');
719
+ wasi[kStarted] = false;
720
+ }
721
+ catch (_) { }
722
+ }
723
+ else {
724
+ setupInstance(wasi, instance);
725
+ }
726
+ }
727
+ else {
728
+ wasi.initialize(instance);
729
+ }
730
+ return instance;
731
+ };
732
+ /**
733
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
734
+ * ```js
735
+ * this.initialize(instance, module, memory)
736
+ * this.wasi.start(instance)
737
+ * ```
738
+ */
739
+ WASIThreads.prototype.start = function (instance, module, memory) {
740
+ var exports$1 = instance.exports;
741
+ memory !== null && memory !== void 0 ? memory : (memory = exports$1.memory);
742
+ if (this.childThread) {
743
+ instance = createInstanceProxy(instance, memory);
744
+ }
745
+ this.setup(instance, module, memory);
746
+ var exitCode = this.wasi.start(instance);
747
+ return { exitCode: exitCode, instance: instance };
748
+ };
749
+ WASIThreads.prototype.terminateAllThreads = function () {
750
+ var _a;
751
+ if (!this.childThread) {
752
+ (_a = this.PThread) === null || _a === void 0 ? void 0 : _a.terminateAllThreads();
753
+ }
754
+ else {
755
+ this.postMessage(createMessage('terminate-all-threads', {}));
756
+ }
757
+ };
758
+ return WASIThreads;
759
+ }());
760
+ function patchWasiInstance(wasiThreads, wasi) {
761
+ var patched = patchedWasiInstances.get(wasiThreads);
762
+ if (patched.has(wasi)) {
763
+ return;
764
+ }
765
+ var _this = wasiThreads;
766
+ var wasiImport = wasi.wasiImport;
767
+ if (wasiImport) {
768
+ var proc_exit_1 = wasiImport.proc_exit;
769
+ wasiImport.proc_exit = function (code) {
770
+ _this.terminateAllThreads();
771
+ return proc_exit_1.call(this, code);
772
+ };
773
+ }
774
+ if (!_this.childThread) {
775
+ var start_1 = wasi.start;
776
+ if (typeof start_1 === 'function') {
777
+ wasi.start = function (instance) {
778
+ try {
779
+ return start_1.call(this, instance);
780
+ }
781
+ catch (err) {
782
+ if (isTrapError(err)) {
783
+ _this.terminateAllThreads();
784
+ }
785
+ throw err;
786
+ }
787
+ };
788
+ }
789
+ }
790
+ patched.add(wasi);
791
+ }
792
+ function getWasiSymbol(wasi, description) {
793
+ var symbols = Object.getOwnPropertySymbols(wasi);
794
+ var selectDescription = function (description) { return function (s) {
795
+ if (s.description) {
796
+ return s.description === description;
797
+ }
798
+ return s.toString() === "Symbol(".concat(description, ")");
799
+ }; };
800
+ if (Array.isArray(description)) {
801
+ return description.map(function (d) { return symbols.filter(selectDescription(d))[0]; });
802
+ }
803
+ return symbols.filter(selectDescription(description))[0];
804
+ }
805
+ function setupInstance(wasi, instance) {
806
+ var _a = getWasiSymbol(wasi, ['kInstance', 'kSetMemory']), kInstance = _a[0], kSetMemory = _a[1];
807
+ wasi[kInstance] = instance;
808
+ wasi[kSetMemory](instance.exports.memory);
809
+ }
810
+
811
+ /** @public */
812
+ var ThreadMessageHandler = /*#__PURE__*/ (function () {
813
+ function ThreadMessageHandler(options) {
814
+ var postMsg = getPostMessage(options);
815
+ if (typeof postMsg !== 'function') {
816
+ throw new TypeError('options.postMessage is not a function');
817
+ }
818
+ this.postMessage = postMsg;
819
+ this.onLoad = options === null || options === void 0 ? void 0 : options.onLoad;
820
+ this.onError = typeof (options === null || options === void 0 ? void 0 : options.onError) === 'function' ? options.onError : function (_type, err) { throw err; };
821
+ this.instance = undefined;
822
+ // this.module = undefined
823
+ this.messagesBeforeLoad = [];
824
+ }
825
+ /** @virtual */
826
+ ThreadMessageHandler.prototype.instantiate = function (data) {
827
+ if (typeof this.onLoad === 'function') {
828
+ return this.onLoad(data);
829
+ }
830
+ throw new Error('ThreadMessageHandler.prototype.instantiate is not implemented');
831
+ };
832
+ /** @virtual */
833
+ ThreadMessageHandler.prototype.handle = function (e) {
834
+ var _this = this;
835
+ var _a;
836
+ if ((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.__emnapi__) {
837
+ var type = e.data.__emnapi__.type;
838
+ var payload_1 = e.data.__emnapi__.payload;
839
+ try {
840
+ if (type === 'load') {
841
+ this._load(payload_1);
842
+ }
843
+ else if (type === 'start') {
844
+ this.handleAfterLoad(e, function () {
845
+ _this._start(payload_1);
846
+ });
847
+ }
848
+ }
849
+ catch (err) {
850
+ this.onError(err, type);
851
+ }
852
+ }
853
+ };
854
+ ThreadMessageHandler.prototype._load = function (payload) {
855
+ var _this = this;
856
+ if (this.instance !== undefined)
857
+ return;
858
+ var source;
859
+ try {
860
+ source = this.instantiate(payload);
861
+ }
862
+ catch (err) {
863
+ this._loaded(err, null, payload);
864
+ return;
865
+ }
866
+ var then = source && 'then' in source ? source.then : undefined;
867
+ if (typeof then === 'function') {
868
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
869
+ then.call(source, function (source) { _this._loaded(null, source, payload); }, function (err) { _this._loaded(err, null, payload); });
870
+ }
871
+ else {
872
+ this._loaded(null, source, payload);
873
+ }
874
+ };
875
+ ThreadMessageHandler.prototype._start = function (payload) {
876
+ var wasi_thread_start = this.instance.exports.wasi_thread_start;
877
+ if (typeof wasi_thread_start !== 'function') {
878
+ var err = new TypeError('wasi_thread_start is not exported');
879
+ notifyPthreadCreateResult(payload.sab, 2, err);
880
+ throw err;
881
+ }
882
+ var postMessage = this.postMessage;
883
+ var tid = payload.tid;
884
+ var startArg = payload.arg;
885
+ notifyPthreadCreateResult(payload.sab, 1);
886
+ try {
887
+ wasi_thread_start(tid, startArg);
888
+ }
889
+ catch (err) {
890
+ if (err !== 'unwind') {
891
+ throw err;
892
+ }
893
+ else {
894
+ return;
895
+ }
896
+ }
897
+ postMessage(createMessage('cleanup-thread', { tid: tid }));
898
+ };
899
+ ThreadMessageHandler.prototype._loaded = function (err, source, payload) {
900
+ if (err) {
901
+ notifyPthreadCreateResult(payload.sab, 2, err);
902
+ throw err;
903
+ }
904
+ if (source == null) {
905
+ var err_1 = new TypeError('onLoad should return an object');
906
+ notifyPthreadCreateResult(payload.sab, 2, err_1);
907
+ throw err_1;
908
+ }
909
+ var instance = source.instance;
910
+ if (!instance) {
911
+ var err_2 = new TypeError('onLoad should return an object which includes "instance"');
912
+ notifyPthreadCreateResult(payload.sab, 2, err_2);
913
+ throw err_2;
914
+ }
915
+ this.instance = instance;
916
+ var postMessage = this.postMessage;
917
+ postMessage(createMessage('loaded', {}));
918
+ var messages = this.messagesBeforeLoad;
919
+ this.messagesBeforeLoad = [];
920
+ for (var i = 0; i < messages.length; i++) {
921
+ var data = messages[i];
922
+ this.handle({ data: data });
923
+ }
924
+ };
925
+ ThreadMessageHandler.prototype.handleAfterLoad = function (e, f) {
926
+ if (this.instance !== undefined) {
927
+ f.call(this, e);
928
+ }
929
+ else {
930
+ this.messagesBeforeLoad.push(e.data);
931
+ }
932
+ };
933
+ return ThreadMessageHandler;
934
+ }());
935
+ function notifyPthreadCreateResult(sab, result, error) {
936
+ if (sab) {
937
+ serizeErrorToBuffer(sab.buffer, result, error);
938
+ Atomics.notify(sab, 0);
939
+ }
940
+ }
941
+
942
+ export { ThreadManager, ThreadMessageHandler, WASIThreads, createInstanceProxy, isSharedArrayBuffer, isTrapError };
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js ADDED
@@ -0,0 +1,954 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.wasiThreads = {}));
5
+ })(this, (function (exports) {
6
+ var _WebAssembly = typeof WebAssembly !== 'undefined'
7
+ ? WebAssembly
8
+ : typeof WXWebAssembly !== 'undefined'
9
+ ? WXWebAssembly
10
+ : undefined;
11
+ var ENVIRONMENT_IS_NODE = typeof process === 'object' && process !== null &&
12
+ typeof process.versions === 'object' && process.versions !== null &&
13
+ typeof process.versions.node === 'string';
14
+ function getPostMessage(options) {
15
+ return typeof (options === null || options === void 0 ? void 0 : options.postMessage) === 'function'
16
+ ? options.postMessage
17
+ : typeof postMessage === 'function'
18
+ ? postMessage
19
+ : undefined;
20
+ }
21
+ function serizeErrorToBuffer(sab, code, error) {
22
+ var i32array = new Int32Array(sab);
23
+ Atomics.store(i32array, 0, code);
24
+ if (code > 1 && error) {
25
+ var name_1 = error.name;
26
+ var message = error.message;
27
+ var stack = error.stack;
28
+ var nameBuffer = new TextEncoder().encode(name_1);
29
+ var messageBuffer = new TextEncoder().encode(message);
30
+ var stackBuffer = new TextEncoder().encode(stack);
31
+ Atomics.store(i32array, 1, nameBuffer.length);
32
+ Atomics.store(i32array, 2, messageBuffer.length);
33
+ Atomics.store(i32array, 3, stackBuffer.length);
34
+ var buffer = new Uint8Array(sab);
35
+ buffer.set(nameBuffer, 16);
36
+ buffer.set(messageBuffer, 16 + nameBuffer.length);
37
+ buffer.set(stackBuffer, 16 + nameBuffer.length + messageBuffer.length);
38
+ }
39
+ }
40
+ function deserizeErrorFromBuffer(sab) {
41
+ var _a, _b;
42
+ var i32array = new Int32Array(sab);
43
+ var status = Atomics.load(i32array, 0);
44
+ if (status <= 1) {
45
+ return null;
46
+ }
47
+ var nameLength = Atomics.load(i32array, 1);
48
+ var messageLength = Atomics.load(i32array, 2);
49
+ var stackLength = Atomics.load(i32array, 3);
50
+ var buffer = new Uint8Array(sab);
51
+ var nameBuffer = buffer.slice(16, 16 + nameLength);
52
+ var messageBuffer = buffer.slice(16 + nameLength, 16 + nameLength + messageLength);
53
+ var stackBuffer = buffer.slice(16 + nameLength + messageLength, 16 + nameLength + messageLength + stackLength);
54
+ var name = new TextDecoder().decode(nameBuffer);
55
+ var message = new TextDecoder().decode(messageBuffer);
56
+ var stack = new TextDecoder().decode(stackBuffer);
57
+ var ErrorConstructor = (_a = globalThis[name]) !== null && _a !== void 0 ? _a : (name === 'RuntimeError' ? ((_b = _WebAssembly.RuntimeError) !== null && _b !== void 0 ? _b : Error) : Error);
58
+ var error = new ErrorConstructor(message);
59
+ Object.defineProperty(error, 'stack', {
60
+ value: stack,
61
+ writable: true,
62
+ enumerable: false,
63
+ configurable: true
64
+ });
65
+ return error;
66
+ }
67
+ /** @public */
68
+ function isSharedArrayBuffer(value) {
69
+ return ((typeof SharedArrayBuffer === 'function' && value instanceof SharedArrayBuffer) ||
70
+ (Object.prototype.toString.call(value) === '[object SharedArrayBuffer]'));
71
+ }
72
+ /** @public */
73
+ function isTrapError(e) {
74
+ try {
75
+ return e instanceof _WebAssembly.RuntimeError;
76
+ }
77
+ catch (_) {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ function createMessage(type, payload) {
83
+ return {
84
+ __emnapi__: {
85
+ type: type,
86
+ payload: payload
87
+ }
88
+ };
89
+ }
90
+
91
+ var WASI_THREADS_MAX_TID = 0x1FFFFFFF;
92
+ function checkSharedWasmMemory(wasmMemory) {
93
+ if (wasmMemory) {
94
+ if (!isSharedArrayBuffer(wasmMemory.buffer)) {
95
+ throw new Error('Multithread features require shared wasm memory. ' +
96
+ 'Try to compile with `-matomics -mbulk-memory` and use `--import-memory --shared-memory` during linking, ' +
97
+ 'then create WebAssembly.Memory with `shared: true` option');
98
+ }
99
+ }
100
+ else {
101
+ if (typeof SharedArrayBuffer === 'undefined') {
102
+ throw new Error('Current environment does not support SharedArrayBuffer, threads are not available!');
103
+ }
104
+ }
105
+ }
106
+ function getReuseWorker(value) {
107
+ var _a;
108
+ if (typeof value === 'boolean') {
109
+ return value ? { size: 0, strict: false } : false;
110
+ }
111
+ if (typeof value === 'number') {
112
+ if (!(value >= 0)) {
113
+ throw new RangeError('reuseWorker: size must be a non-negative integer');
114
+ }
115
+ return { size: value, strict: false };
116
+ }
117
+ if (!value) {
118
+ return false;
119
+ }
120
+ var size = (_a = Number(value.size)) !== null && _a !== void 0 ? _a : 0;
121
+ var strict = Boolean(value.strict);
122
+ if (!(size > 0) && strict) {
123
+ throw new RangeError('reuseWorker: size must be set to positive integer if strict is set to true');
124
+ }
125
+ return { size: size, strict: strict };
126
+ }
127
+ var nextWorkerID = 0;
128
+ /** @public */
129
+ var ThreadManager = /*#__PURE__*/ (function () {
130
+ function ThreadManager(options) {
131
+ var _a;
132
+ this.unusedWorkers = [];
133
+ this.runningWorkers = [];
134
+ this.pthreads = Object.create(null);
135
+ this.wasmModule = null;
136
+ this.wasmMemory = null;
137
+ this.messageEvents = new WeakMap();
138
+ if (!options) {
139
+ throw new TypeError('ThreadManager(): options is not provided');
140
+ }
141
+ if ('childThread' in options) {
142
+ this._childThread = Boolean(options.childThread);
143
+ }
144
+ else {
145
+ this._childThread = false;
146
+ }
147
+ if (this._childThread) {
148
+ this._onCreateWorker = undefined;
149
+ this._reuseWorker = false;
150
+ this._beforeLoad = undefined;
151
+ }
152
+ else {
153
+ this._onCreateWorker = options.onCreateWorker;
154
+ this._reuseWorker = getReuseWorker(options.reuseWorker);
155
+ this._beforeLoad = options.beforeLoad;
156
+ }
157
+ this.printErr = (_a = options.printErr) !== null && _a !== void 0 ? _a : console.error.bind(console);
158
+ this.threadSpawn = options.threadSpawn;
159
+ }
160
+ Object.defineProperty(ThreadManager.prototype, "nextWorkerID", {
161
+ get: function () { return nextWorkerID; },
162
+ enumerable: false,
163
+ configurable: true
164
+ });
165
+ ThreadManager.prototype.init = function () {
166
+ if (!this._childThread) {
167
+ this.initMainThread();
168
+ }
169
+ };
170
+ ThreadManager.prototype.initMainThread = function () {
171
+ this.preparePool();
172
+ };
173
+ ThreadManager.prototype.preparePool = function () {
174
+ if (this._reuseWorker) {
175
+ if (this._reuseWorker.size) {
176
+ var pthreadPoolSize = this._reuseWorker.size;
177
+ while (pthreadPoolSize--) {
178
+ var worker = this.allocateUnusedWorker();
179
+ if (ENVIRONMENT_IS_NODE) {
180
+ // https://github.com/nodejs/node/issues/53036
181
+ worker.once('message', function () { });
182
+ worker.unref();
183
+ }
184
+ }
185
+ }
186
+ }
187
+ };
188
+ ThreadManager.prototype.shouldPreloadWorkers = function () {
189
+ return !this._childThread && this._reuseWorker && this._reuseWorker.size > 0;
190
+ };
191
+ ThreadManager.prototype.loadWasmModuleToAllWorkers = function () {
192
+ var _this_1 = this;
193
+ var promises = Array(this.unusedWorkers.length);
194
+ var _loop_1 = function (i) {
195
+ var worker = this_1.unusedWorkers[i];
196
+ if (ENVIRONMENT_IS_NODE)
197
+ worker.ref();
198
+ promises[i] = this_1.loadWasmModuleToWorker(worker).then(function (w) {
199
+ if (ENVIRONMENT_IS_NODE)
200
+ worker.unref();
201
+ return w;
202
+ }, function (e) {
203
+ if (ENVIRONMENT_IS_NODE)
204
+ worker.unref();
205
+ throw e;
206
+ });
207
+ };
208
+ var this_1 = this;
209
+ for (var i = 0; i < this.unusedWorkers.length; ++i) {
210
+ _loop_1(i);
211
+ }
212
+ return Promise.all(promises).catch(function (err) {
213
+ _this_1.terminateAllThreads();
214
+ throw err;
215
+ });
216
+ };
217
+ ThreadManager.prototype.preloadWorkers = function () {
218
+ if (this.shouldPreloadWorkers()) {
219
+ return this.loadWasmModuleToAllWorkers();
220
+ }
221
+ return Promise.resolve([]);
222
+ };
223
+ ThreadManager.prototype.setup = function (wasmModule, wasmMemory) {
224
+ this.wasmModule = wasmModule;
225
+ this.wasmMemory = wasmMemory;
226
+ };
227
+ ThreadManager.prototype.markId = function (worker) {
228
+ if (worker.__emnapi_tid)
229
+ return worker.__emnapi_tid;
230
+ var tid = nextWorkerID + 43;
231
+ nextWorkerID = (nextWorkerID + 1) % (WASI_THREADS_MAX_TID - 42);
232
+ this.pthreads[tid] = worker;
233
+ worker.__emnapi_tid = tid;
234
+ return tid;
235
+ };
236
+ ThreadManager.prototype.returnWorkerToPool = function (worker) {
237
+ var tid = worker.__emnapi_tid;
238
+ if (tid !== undefined) {
239
+ delete this.pthreads[tid];
240
+ }
241
+ this.unusedWorkers.push(worker);
242
+ this.runningWorkers.splice(this.runningWorkers.indexOf(worker), 1);
243
+ delete worker.__emnapi_tid;
244
+ if (ENVIRONMENT_IS_NODE) {
245
+ worker.unref();
246
+ }
247
+ };
248
+ ThreadManager.prototype.loadWasmModuleToWorker = function (worker, sab) {
249
+ var _this_1 = this;
250
+ if (worker.whenLoaded)
251
+ return worker.whenLoaded;
252
+ var err = this.printErr;
253
+ var beforeLoad = this._beforeLoad;
254
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
255
+ var _this = this;
256
+ worker.whenLoaded = new Promise(function (resolve, reject) {
257
+ var handleError = function (e) {
258
+ var message = 'worker sent an error!';
259
+ if (worker.__emnapi_tid !== undefined) {
260
+ message = 'worker (tid = ' + worker.__emnapi_tid + ') sent an error!';
261
+ }
262
+ if ('message' in e) {
263
+ err(message + ' ' + e.message);
264
+ if (e.message.indexOf('RuntimeError') !== -1 || e.message.indexOf('unreachable') !== -1) {
265
+ try {
266
+ _this.terminateAllThreads();
267
+ }
268
+ catch (_) { }
269
+ }
270
+ }
271
+ else {
272
+ err(message);
273
+ }
274
+ reject(e);
275
+ throw e;
276
+ };
277
+ var handleMessage = function (data) {
278
+ if (data.__emnapi__) {
279
+ var type = data.__emnapi__.type;
280
+ var payload = data.__emnapi__.payload;
281
+ if (type === 'loaded') {
282
+ worker.loaded = true;
283
+ if (ENVIRONMENT_IS_NODE && !worker.__emnapi_tid) {
284
+ worker.unref();
285
+ }
286
+ resolve(worker);
287
+ // if (payload.err) {
288
+ // err('failed to load in child thread: ' + (payload.err.message || payload.err))
289
+ // }
290
+ }
291
+ else if (type === 'cleanup-thread') {
292
+ if (payload.tid in _this_1.pthreads) {
293
+ _this_1.cleanThread(worker, payload.tid);
294
+ }
295
+ }
296
+ else if (type === 'spawn-thread') {
297
+ _this_1.threadSpawn(payload.startArg, payload.errorOrTid);
298
+ }
299
+ else if (type === 'terminate-all-threads') {
300
+ _this_1.terminateAllThreads();
301
+ }
302
+ }
303
+ };
304
+ worker.onmessage = function (e) {
305
+ handleMessage(e.data);
306
+ _this_1.fireMessageEvent(worker, e);
307
+ };
308
+ worker.onerror = handleError;
309
+ if (ENVIRONMENT_IS_NODE) {
310
+ worker.on('message', function (data) {
311
+ var _a, _b;
312
+ (_b = (_a = worker).onmessage) === null || _b === void 0 ? void 0 : _b.call(_a, {
313
+ data: data
314
+ });
315
+ });
316
+ worker.on('error', function (e) {
317
+ var _a, _b;
318
+ (_b = (_a = worker).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, e);
319
+ });
320
+ worker.on('detachedExit', function () { });
321
+ }
322
+ if (typeof beforeLoad === 'function') {
323
+ beforeLoad(worker);
324
+ }
325
+ try {
326
+ worker.postMessage(createMessage('load', {
327
+ wasmModule: _this_1.wasmModule,
328
+ wasmMemory: _this_1.wasmMemory,
329
+ sab: sab
330
+ }));
331
+ }
332
+ catch (err) {
333
+ checkSharedWasmMemory(_this_1.wasmMemory);
334
+ throw err;
335
+ }
336
+ });
337
+ return worker.whenLoaded;
338
+ };
339
+ ThreadManager.prototype.allocateUnusedWorker = function () {
340
+ var _onCreateWorker = this._onCreateWorker;
341
+ if (typeof _onCreateWorker !== 'function') {
342
+ throw new TypeError('`options.onCreateWorker` is not provided');
343
+ }
344
+ var worker = _onCreateWorker({ type: 'thread', name: 'emnapi-pthread' });
345
+ this.unusedWorkers.push(worker);
346
+ return worker;
347
+ };
348
+ ThreadManager.prototype.getNewWorker = function (sab) {
349
+ if (this._reuseWorker) {
350
+ if (this.unusedWorkers.length === 0) {
351
+ if (this._reuseWorker.strict) {
352
+ if (!ENVIRONMENT_IS_NODE) {
353
+ var err = this.printErr;
354
+ err('Tried to spawn a new thread, but the thread pool is exhausted.\n' +
355
+ 'This might result in a deadlock unless some threads eventually exit or the code explicitly breaks out to the event loop.');
356
+ return;
357
+ }
358
+ }
359
+ var worker_1 = this.allocateUnusedWorker();
360
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
361
+ this.loadWasmModuleToWorker(worker_1, sab);
362
+ }
363
+ return this.unusedWorkers.pop();
364
+ }
365
+ var worker = this.allocateUnusedWorker();
366
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
367
+ this.loadWasmModuleToWorker(worker, sab);
368
+ return this.unusedWorkers.pop();
369
+ };
370
+ ThreadManager.prototype.cleanThread = function (worker, tid, force) {
371
+ if (!force && this._reuseWorker) {
372
+ this.returnWorkerToPool(worker);
373
+ }
374
+ else {
375
+ delete this.pthreads[tid];
376
+ var index = this.runningWorkers.indexOf(worker);
377
+ if (index !== -1) {
378
+ this.runningWorkers.splice(index, 1);
379
+ }
380
+ this.terminateWorker(worker);
381
+ delete worker.__emnapi_tid;
382
+ }
383
+ };
384
+ ThreadManager.prototype.terminateWorker = function (worker) {
385
+ var _this_1 = this;
386
+ var _a;
387
+ var tid = worker.__emnapi_tid;
388
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
389
+ worker.terminate();
390
+ (_a = this.messageEvents.get(worker)) === null || _a === void 0 ? void 0 : _a.clear();
391
+ this.messageEvents.delete(worker);
392
+ worker.onmessage = function (e) {
393
+ if (e.data.__emnapi__) {
394
+ var err = _this_1.printErr;
395
+ err('received "' + e.data.__emnapi__.type + '" command from terminated worker: ' + tid);
396
+ }
397
+ };
398
+ };
399
+ ThreadManager.prototype.terminateAllThreads = function () {
400
+ for (var i = 0; i < this.runningWorkers.length; ++i) {
401
+ this.terminateWorker(this.runningWorkers[i]);
402
+ }
403
+ for (var i = 0; i < this.unusedWorkers.length; ++i) {
404
+ this.terminateWorker(this.unusedWorkers[i]);
405
+ }
406
+ this.unusedWorkers = [];
407
+ this.runningWorkers = [];
408
+ this.pthreads = Object.create(null);
409
+ this.preparePool();
410
+ };
411
+ ThreadManager.prototype.addMessageEventListener = function (worker, onMessage) {
412
+ var listeners = this.messageEvents.get(worker);
413
+ if (!listeners) {
414
+ listeners = new Set();
415
+ this.messageEvents.set(worker, listeners);
416
+ }
417
+ listeners.add(onMessage);
418
+ return function () {
419
+ listeners === null || listeners === void 0 ? void 0 : listeners.delete(onMessage);
420
+ };
421
+ };
422
+ ThreadManager.prototype.fireMessageEvent = function (worker, e) {
423
+ var listeners = this.messageEvents.get(worker);
424
+ if (!listeners)
425
+ return;
426
+ var err = this.printErr;
427
+ listeners.forEach(function (listener) {
428
+ try {
429
+ listener(e);
430
+ }
431
+ catch (e) {
432
+ err(e.stack);
433
+ }
434
+ });
435
+ };
436
+ return ThreadManager;
437
+ }());
438
+
439
+ var kIsProxy = Symbol('kIsProxy');
440
+ /** @public */
441
+ function createInstanceProxy(instance, memory) {
442
+ if (instance[kIsProxy])
443
+ return instance;
444
+ // https://github.com/nodejs/help/issues/4102
445
+ var originalExports = instance.exports;
446
+ var createHandler = function (target) {
447
+ var handlers = [
448
+ 'apply',
449
+ 'construct',
450
+ 'defineProperty',
451
+ 'deleteProperty',
452
+ 'get',
453
+ 'getOwnPropertyDescriptor',
454
+ 'getPrototypeOf',
455
+ 'has',
456
+ 'isExtensible',
457
+ 'ownKeys',
458
+ 'preventExtensions',
459
+ 'set',
460
+ 'setPrototypeOf'
461
+ ];
462
+ var handler = {};
463
+ var _loop_1 = function (i) {
464
+ var name_1 = handlers[i];
465
+ handler[name_1] = function () {
466
+ var args = Array.prototype.slice.call(arguments, 1);
467
+ args.unshift(target);
468
+ return Reflect[name_1].apply(Reflect, args);
469
+ };
470
+ };
471
+ for (var i = 0; i < handlers.length; i++) {
472
+ _loop_1(i);
473
+ }
474
+ return handler;
475
+ };
476
+ var handler = createHandler(originalExports);
477
+ var _initialize = function () { };
478
+ var _start = function () { return 0; };
479
+ handler.get = function (_target, p, receiver) {
480
+ var _a;
481
+ if (p === 'memory') {
482
+ return (_a = (typeof memory === 'function' ? memory() : memory)) !== null && _a !== void 0 ? _a : Reflect.get(originalExports, p, receiver);
483
+ }
484
+ if (p === '_initialize') {
485
+ return p in originalExports ? _initialize : undefined;
486
+ }
487
+ if (p === '_start') {
488
+ return p in originalExports ? _start : undefined;
489
+ }
490
+ return Reflect.get(originalExports, p, receiver);
491
+ };
492
+ handler.has = function (_target, p) {
493
+ if (p === 'memory')
494
+ return true;
495
+ return Reflect.has(originalExports, p);
496
+ };
497
+ var exportsProxy = new Proxy(Object.create(null), handler);
498
+ return new Proxy(instance, {
499
+ get: function (target, p, receiver) {
500
+ if (p === 'exports') {
501
+ return exportsProxy;
502
+ }
503
+ if (p === kIsProxy) {
504
+ return true;
505
+ }
506
+ return Reflect.get(target, p, receiver);
507
+ }
508
+ });
509
+ }
510
+
511
+ var patchedWasiInstances = new WeakMap();
512
+ /** @public */
513
+ var WASIThreads = /*#__PURE__*/ (function () {
514
+ function WASIThreads(options) {
515
+ var _this_1 = this;
516
+ if (!options) {
517
+ throw new TypeError('WASIThreads(): options is not provided');
518
+ }
519
+ if (!options.wasi) {
520
+ throw new TypeError('WASIThreads(): options.wasi is not provided');
521
+ }
522
+ patchedWasiInstances.set(this, new WeakSet());
523
+ var wasi = options.wasi;
524
+ patchWasiInstance(this, wasi);
525
+ this.wasi = wasi;
526
+ if ('childThread' in options) {
527
+ this.childThread = Boolean(options.childThread);
528
+ }
529
+ else {
530
+ this.childThread = false;
531
+ }
532
+ this.PThread = undefined;
533
+ if ('threadManager' in options) {
534
+ if (typeof options.threadManager === 'function') {
535
+ this.PThread = options.threadManager();
536
+ }
537
+ else {
538
+ this.PThread = options.threadManager;
539
+ }
540
+ }
541
+ else {
542
+ if (!this.childThread) {
543
+ this.PThread = new ThreadManager(options);
544
+ this.PThread.init();
545
+ }
546
+ }
547
+ var waitThreadStart = false;
548
+ if ('waitThreadStart' in options) {
549
+ waitThreadStart = typeof options.waitThreadStart === 'number' ? options.waitThreadStart : Boolean(options.waitThreadStart);
550
+ }
551
+ var postMessage = getPostMessage(options);
552
+ if (this.childThread && typeof postMessage !== 'function') {
553
+ throw new TypeError('options.postMessage is not a function');
554
+ }
555
+ this.postMessage = postMessage;
556
+ var wasm64 = Boolean(options.wasm64);
557
+ var threadSpawn = function (startArg, errorOrTid) {
558
+ var _a;
559
+ var EAGAIN = 6;
560
+ var isNewABI = errorOrTid !== undefined;
561
+ try {
562
+ checkSharedWasmMemory(_this_1.wasmMemory);
563
+ }
564
+ catch (err) {
565
+ (_a = _this_1.PThread) === null || _a === void 0 ? void 0 : _a.printErr(err.stack);
566
+ if (isNewABI) {
567
+ var struct_1 = new Int32Array(_this_1.wasmMemory.buffer, errorOrTid, 2);
568
+ Atomics.store(struct_1, 0, 1);
569
+ Atomics.store(struct_1, 1, EAGAIN);
570
+ Atomics.notify(struct_1, 1);
571
+ return 1;
572
+ }
573
+ else {
574
+ return -EAGAIN;
575
+ }
576
+ }
577
+ if (!isNewABI) {
578
+ var malloc = _this_1.wasmInstance.exports.malloc;
579
+ errorOrTid = wasm64 ? Number(malloc(BigInt(8))) : (malloc(8) >>> 0);
580
+ if (!errorOrTid) {
581
+ return -48; /* ENOMEM */
582
+ }
583
+ }
584
+ var _free = _this_1.wasmInstance.exports.free;
585
+ var free = wasm64 ? function (ptr) { _free(BigInt(ptr)); } : _free;
586
+ var struct = new Int32Array(_this_1.wasmMemory.buffer, errorOrTid, 2);
587
+ Atomics.store(struct, 0, 0);
588
+ Atomics.store(struct, 1, 0);
589
+ if (_this_1.childThread) {
590
+ postMessage(createMessage('spawn-thread', {
591
+ startArg: startArg,
592
+ errorOrTid: errorOrTid
593
+ }));
594
+ Atomics.wait(struct, 1, 0);
595
+ var isError = Atomics.load(struct, 0);
596
+ var result = Atomics.load(struct, 1);
597
+ if (isNewABI) {
598
+ return isError;
599
+ }
600
+ free(errorOrTid);
601
+ return isError ? -result : result;
602
+ }
603
+ var shouldWait = waitThreadStart || (waitThreadStart === 0);
604
+ var sab;
605
+ if (shouldWait) {
606
+ sab = new Int32Array(new SharedArrayBuffer(16 + 8192));
607
+ Atomics.store(sab, 0, 0);
608
+ }
609
+ var worker;
610
+ var tid;
611
+ var PThread = _this_1.PThread;
612
+ try {
613
+ worker = PThread.getNewWorker(sab);
614
+ if (!worker) {
615
+ throw new Error('failed to get new worker');
616
+ }
617
+ tid = PThread.markId(worker);
618
+ if (ENVIRONMENT_IS_NODE) {
619
+ worker.unref();
620
+ }
621
+ worker.postMessage(createMessage('start', {
622
+ tid: tid,
623
+ arg: startArg,
624
+ sab: sab
625
+ }));
626
+ if (shouldWait) {
627
+ if (typeof waitThreadStart === 'number') {
628
+ var waitResult = Atomics.wait(sab, 0, 0, waitThreadStart);
629
+ if (waitResult === 'timed-out') {
630
+ try {
631
+ PThread.cleanThread(worker, tid, true);
632
+ }
633
+ catch (_) { }
634
+ throw new Error('Spawning thread timed out. Please check if the worker is created successfully and if message is handled properly in the worker.');
635
+ }
636
+ }
637
+ else {
638
+ Atomics.wait(sab, 0, 0);
639
+ }
640
+ var r = Atomics.load(sab, 0);
641
+ if (r > 1) {
642
+ try {
643
+ PThread.cleanThread(worker, tid, true);
644
+ }
645
+ catch (_) { }
646
+ throw deserizeErrorFromBuffer(sab.buffer);
647
+ }
648
+ }
649
+ }
650
+ catch (e) {
651
+ Atomics.store(struct, 0, 1);
652
+ Atomics.store(struct, 1, EAGAIN);
653
+ Atomics.notify(struct, 1);
654
+ PThread === null || PThread === void 0 ? void 0 : PThread.printErr(e.stack);
655
+ if (isNewABI) {
656
+ return 1;
657
+ }
658
+ free(errorOrTid);
659
+ return -EAGAIN;
660
+ }
661
+ Atomics.store(struct, 0, 0);
662
+ Atomics.store(struct, 1, tid);
663
+ Atomics.notify(struct, 1);
664
+ PThread.runningWorkers.push(worker);
665
+ if (!shouldWait) {
666
+ worker.whenLoaded.catch(function (err) {
667
+ delete worker.whenLoaded;
668
+ PThread.cleanThread(worker, tid, true);
669
+ throw err;
670
+ });
671
+ }
672
+ if (isNewABI) {
673
+ return 0;
674
+ }
675
+ free(errorOrTid);
676
+ return tid;
677
+ };
678
+ this.threadSpawn = threadSpawn;
679
+ if (this.PThread) {
680
+ this.PThread.threadSpawn = threadSpawn;
681
+ }
682
+ }
683
+ WASIThreads.prototype.getImportObject = function () {
684
+ return {
685
+ wasi: {
686
+ 'thread-spawn': this.threadSpawn
687
+ }
688
+ };
689
+ };
690
+ WASIThreads.prototype.setup = function (wasmInstance, wasmModule, wasmMemory) {
691
+ wasmMemory !== null && wasmMemory !== void 0 ? wasmMemory : (wasmMemory = wasmInstance.exports.memory);
692
+ this.wasmInstance = wasmInstance;
693
+ this.wasmMemory = wasmMemory;
694
+ if (this.PThread) {
695
+ this.PThread.setup(wasmModule, wasmMemory);
696
+ }
697
+ };
698
+ WASIThreads.prototype.preloadWorkers = function () {
699
+ if (this.PThread) {
700
+ return this.PThread.preloadWorkers();
701
+ }
702
+ return Promise.resolve([]);
703
+ };
704
+ /**
705
+ * It's ok to call this method to a WASI command module.
706
+ *
707
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
708
+ *
709
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
710
+ */
711
+ WASIThreads.prototype.initialize = function (instance, module, memory) {
712
+ var exports$1 = instance.exports;
713
+ memory !== null && memory !== void 0 ? memory : (memory = exports$1.memory);
714
+ if (this.childThread) {
715
+ instance = createInstanceProxy(instance, memory);
716
+ }
717
+ this.setup(instance, module, memory);
718
+ var wasi = this.wasi;
719
+ if (('_start' in exports$1) && (typeof exports$1._start === 'function')) {
720
+ if (this.childThread) {
721
+ wasi.start(instance);
722
+ try {
723
+ var kStarted = getWasiSymbol(wasi, 'kStarted');
724
+ wasi[kStarted] = false;
725
+ }
726
+ catch (_) { }
727
+ }
728
+ else {
729
+ setupInstance(wasi, instance);
730
+ }
731
+ }
732
+ else {
733
+ wasi.initialize(instance);
734
+ }
735
+ return instance;
736
+ };
737
+ /**
738
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
739
+ * ```js
740
+ * this.initialize(instance, module, memory)
741
+ * this.wasi.start(instance)
742
+ * ```
743
+ */
744
+ WASIThreads.prototype.start = function (instance, module, memory) {
745
+ var exports$1 = instance.exports;
746
+ memory !== null && memory !== void 0 ? memory : (memory = exports$1.memory);
747
+ if (this.childThread) {
748
+ instance = createInstanceProxy(instance, memory);
749
+ }
750
+ this.setup(instance, module, memory);
751
+ var exitCode = this.wasi.start(instance);
752
+ return { exitCode: exitCode, instance: instance };
753
+ };
754
+ WASIThreads.prototype.terminateAllThreads = function () {
755
+ var _a;
756
+ if (!this.childThread) {
757
+ (_a = this.PThread) === null || _a === void 0 ? void 0 : _a.terminateAllThreads();
758
+ }
759
+ else {
760
+ this.postMessage(createMessage('terminate-all-threads', {}));
761
+ }
762
+ };
763
+ return WASIThreads;
764
+ }());
765
+ function patchWasiInstance(wasiThreads, wasi) {
766
+ var patched = patchedWasiInstances.get(wasiThreads);
767
+ if (patched.has(wasi)) {
768
+ return;
769
+ }
770
+ var _this = wasiThreads;
771
+ var wasiImport = wasi.wasiImport;
772
+ if (wasiImport) {
773
+ var proc_exit_1 = wasiImport.proc_exit;
774
+ wasiImport.proc_exit = function (code) {
775
+ _this.terminateAllThreads();
776
+ return proc_exit_1.call(this, code);
777
+ };
778
+ }
779
+ if (!_this.childThread) {
780
+ var start_1 = wasi.start;
781
+ if (typeof start_1 === 'function') {
782
+ wasi.start = function (instance) {
783
+ try {
784
+ return start_1.call(this, instance);
785
+ }
786
+ catch (err) {
787
+ if (isTrapError(err)) {
788
+ _this.terminateAllThreads();
789
+ }
790
+ throw err;
791
+ }
792
+ };
793
+ }
794
+ }
795
+ patched.add(wasi);
796
+ }
797
+ function getWasiSymbol(wasi, description) {
798
+ var symbols = Object.getOwnPropertySymbols(wasi);
799
+ var selectDescription = function (description) { return function (s) {
800
+ if (s.description) {
801
+ return s.description === description;
802
+ }
803
+ return s.toString() === "Symbol(".concat(description, ")");
804
+ }; };
805
+ if (Array.isArray(description)) {
806
+ return description.map(function (d) { return symbols.filter(selectDescription(d))[0]; });
807
+ }
808
+ return symbols.filter(selectDescription(description))[0];
809
+ }
810
+ function setupInstance(wasi, instance) {
811
+ var _a = getWasiSymbol(wasi, ['kInstance', 'kSetMemory']), kInstance = _a[0], kSetMemory = _a[1];
812
+ wasi[kInstance] = instance;
813
+ wasi[kSetMemory](instance.exports.memory);
814
+ }
815
+
816
+ /** @public */
817
+ var ThreadMessageHandler = /*#__PURE__*/ (function () {
818
+ function ThreadMessageHandler(options) {
819
+ var postMsg = getPostMessage(options);
820
+ if (typeof postMsg !== 'function') {
821
+ throw new TypeError('options.postMessage is not a function');
822
+ }
823
+ this.postMessage = postMsg;
824
+ this.onLoad = options === null || options === void 0 ? void 0 : options.onLoad;
825
+ this.onError = typeof (options === null || options === void 0 ? void 0 : options.onError) === 'function' ? options.onError : function (_type, err) { throw err; };
826
+ this.instance = undefined;
827
+ // this.module = undefined
828
+ this.messagesBeforeLoad = [];
829
+ }
830
+ /** @virtual */
831
+ ThreadMessageHandler.prototype.instantiate = function (data) {
832
+ if (typeof this.onLoad === 'function') {
833
+ return this.onLoad(data);
834
+ }
835
+ throw new Error('ThreadMessageHandler.prototype.instantiate is not implemented');
836
+ };
837
+ /** @virtual */
838
+ ThreadMessageHandler.prototype.handle = function (e) {
839
+ var _this = this;
840
+ var _a;
841
+ if ((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.__emnapi__) {
842
+ var type = e.data.__emnapi__.type;
843
+ var payload_1 = e.data.__emnapi__.payload;
844
+ try {
845
+ if (type === 'load') {
846
+ this._load(payload_1);
847
+ }
848
+ else if (type === 'start') {
849
+ this.handleAfterLoad(e, function () {
850
+ _this._start(payload_1);
851
+ });
852
+ }
853
+ }
854
+ catch (err) {
855
+ this.onError(err, type);
856
+ }
857
+ }
858
+ };
859
+ ThreadMessageHandler.prototype._load = function (payload) {
860
+ var _this = this;
861
+ if (this.instance !== undefined)
862
+ return;
863
+ var source;
864
+ try {
865
+ source = this.instantiate(payload);
866
+ }
867
+ catch (err) {
868
+ this._loaded(err, null, payload);
869
+ return;
870
+ }
871
+ var then = source && 'then' in source ? source.then : undefined;
872
+ if (typeof then === 'function') {
873
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
874
+ then.call(source, function (source) { _this._loaded(null, source, payload); }, function (err) { _this._loaded(err, null, payload); });
875
+ }
876
+ else {
877
+ this._loaded(null, source, payload);
878
+ }
879
+ };
880
+ ThreadMessageHandler.prototype._start = function (payload) {
881
+ var wasi_thread_start = this.instance.exports.wasi_thread_start;
882
+ if (typeof wasi_thread_start !== 'function') {
883
+ var err = new TypeError('wasi_thread_start is not exported');
884
+ notifyPthreadCreateResult(payload.sab, 2, err);
885
+ throw err;
886
+ }
887
+ var postMessage = this.postMessage;
888
+ var tid = payload.tid;
889
+ var startArg = payload.arg;
890
+ notifyPthreadCreateResult(payload.sab, 1);
891
+ try {
892
+ wasi_thread_start(tid, startArg);
893
+ }
894
+ catch (err) {
895
+ if (err !== 'unwind') {
896
+ throw err;
897
+ }
898
+ else {
899
+ return;
900
+ }
901
+ }
902
+ postMessage(createMessage('cleanup-thread', { tid: tid }));
903
+ };
904
+ ThreadMessageHandler.prototype._loaded = function (err, source, payload) {
905
+ if (err) {
906
+ notifyPthreadCreateResult(payload.sab, 2, err);
907
+ throw err;
908
+ }
909
+ if (source == null) {
910
+ var err_1 = new TypeError('onLoad should return an object');
911
+ notifyPthreadCreateResult(payload.sab, 2, err_1);
912
+ throw err_1;
913
+ }
914
+ var instance = source.instance;
915
+ if (!instance) {
916
+ var err_2 = new TypeError('onLoad should return an object which includes "instance"');
917
+ notifyPthreadCreateResult(payload.sab, 2, err_2);
918
+ throw err_2;
919
+ }
920
+ this.instance = instance;
921
+ var postMessage = this.postMessage;
922
+ postMessage(createMessage('loaded', {}));
923
+ var messages = this.messagesBeforeLoad;
924
+ this.messagesBeforeLoad = [];
925
+ for (var i = 0; i < messages.length; i++) {
926
+ var data = messages[i];
927
+ this.handle({ data: data });
928
+ }
929
+ };
930
+ ThreadMessageHandler.prototype.handleAfterLoad = function (e, f) {
931
+ if (this.instance !== undefined) {
932
+ f.call(this, e);
933
+ }
934
+ else {
935
+ this.messagesBeforeLoad.push(e.data);
936
+ }
937
+ };
938
+ return ThreadMessageHandler;
939
+ }());
940
+ function notifyPthreadCreateResult(sab, result, error) {
941
+ if (sab) {
942
+ serizeErrorToBuffer(sab.buffer, result, error);
943
+ Atomics.notify(sab, 0);
944
+ }
945
+ }
946
+
947
+ exports.ThreadManager = ThreadManager;
948
+ exports.ThreadMessageHandler = ThreadMessageHandler;
949
+ exports.WASIThreads = WASIThreads;
950
+ exports.createInstanceProxy = createInstanceProxy;
951
+ exports.isSharedArrayBuffer = isSharedArrayBuffer;
952
+ exports.isTrapError = isTrapError;
953
+
954
+ }));
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+
3
+ import type { Worker as Worker_2 } from 'worker_threads';
4
+
5
+ /** @public */
6
+ export declare interface BaseOptions {
7
+ wasi: WASIInstance;
8
+ version?: 'preview1';
9
+ wasm64?: boolean;
10
+ }
11
+
12
+ /** @public */
13
+ export declare interface ChildThreadOptions extends BaseOptions {
14
+ childThread: true;
15
+ postMessage?: (data: any) => void;
16
+ }
17
+
18
+ /** @public */
19
+ export declare interface CleanupThreadPayload {
20
+ tid: number;
21
+ }
22
+
23
+ /** @public */
24
+ export declare interface CommandInfo<T extends CommandType> {
25
+ type: T;
26
+ payload: CommandPayloadMap[T];
27
+ }
28
+
29
+ /** @public */
30
+ export declare interface CommandPayloadMap {
31
+ load: LoadPayload;
32
+ loaded: LoadedPayload;
33
+ start: StartPayload;
34
+ 'cleanup-thread': CleanupThreadPayload;
35
+ 'terminate-all-threads': TerminateAllThreadsPayload;
36
+ 'spawn-thread': SpawnThreadPayload;
37
+ }
38
+
39
+ /** @public */
40
+ export declare type CommandType = keyof CommandPayloadMap;
41
+
42
+ /** @public */
43
+ export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
44
+
45
+ /** @public */
46
+ export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
47
+
48
+ /** @public */
49
+ export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
50
+
51
+ /** @public */
52
+ export declare interface LoadedPayload {
53
+ }
54
+
55
+ /** @public */
56
+ export declare interface LoadPayload {
57
+ wasmModule: WebAssembly.Module;
58
+ wasmMemory: WebAssembly.Memory;
59
+ sab?: Int32Array;
60
+ }
61
+
62
+ /** @public */
63
+ export declare interface MainThreadBaseOptions extends BaseOptions {
64
+ waitThreadStart?: boolean | number;
65
+ }
66
+
67
+ /** @public */
68
+ export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
69
+
70
+ /** @public */
71
+ export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
72
+ }
73
+
74
+ /** @public */
75
+ export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
76
+ threadManager?: ThreadManager | (() => ThreadManager);
77
+ }
78
+
79
+ /** @public */
80
+ export declare interface MessageEventData<T extends CommandType> {
81
+ __emnapi__: CommandInfo<T>;
82
+ }
83
+
84
+ /** @public */
85
+ export declare interface ReuseWorkerOptions {
86
+ /**
87
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
88
+ */
89
+ size: number;
90
+ /**
91
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
92
+ */
93
+ strict?: boolean;
94
+ }
95
+
96
+ /** @public */
97
+ export declare interface SpawnThreadPayload {
98
+ startArg: number;
99
+ errorOrTid: number;
100
+ }
101
+
102
+ /** @public */
103
+ export declare interface StartPayload {
104
+ tid: number;
105
+ arg: number;
106
+ sab?: Int32Array;
107
+ }
108
+
109
+ /** @public */
110
+ export declare interface StartResult {
111
+ exitCode: number;
112
+ instance: WebAssembly.Instance;
113
+ }
114
+
115
+ /** @public */
116
+ export declare interface TerminateAllThreadsPayload {
117
+ }
118
+
119
+ /** @public */
120
+ export declare class ThreadManager {
121
+ unusedWorkers: WorkerLike[];
122
+ runningWorkers: WorkerLike[];
123
+ pthreads: Record<number, WorkerLike>;
124
+ get nextWorkerID(): number;
125
+ wasmModule: WebAssembly.Module | null;
126
+ wasmMemory: WebAssembly.Memory | null;
127
+ private readonly messageEvents;
128
+ private readonly _childThread;
129
+ private readonly _onCreateWorker;
130
+ private readonly _reuseWorker;
131
+ private readonly _beforeLoad?;
132
+ /* Excluded from this release type: printErr */
133
+ threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
134
+ constructor(options: ThreadManagerOptions);
135
+ init(): void;
136
+ initMainThread(): void;
137
+ private preparePool;
138
+ shouldPreloadWorkers(): boolean;
139
+ loadWasmModuleToAllWorkers(): Promise<WorkerLike[]>;
140
+ preloadWorkers(): Promise<WorkerLike[]>;
141
+ setup(wasmModule: WebAssembly.Module, wasmMemory: WebAssembly.Memory): void;
142
+ markId(worker: WorkerLike): number;
143
+ returnWorkerToPool(worker: WorkerLike): void;
144
+ loadWasmModuleToWorker(worker: WorkerLike, sab?: Int32Array): Promise<WorkerLike>;
145
+ allocateUnusedWorker(): WorkerLike;
146
+ getNewWorker(sab?: Int32Array): WorkerLike | undefined;
147
+ cleanThread(worker: WorkerLike, tid: number, force?: boolean): void;
148
+ terminateWorker(worker: WorkerLike): void;
149
+ terminateAllThreads(): void;
150
+ addMessageEventListener(worker: WorkerLike, onMessage: (e: WorkerMessageEvent) => void): () => void;
151
+ fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
152
+ }
153
+
154
+ /** @public */
155
+ export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
156
+
157
+ /** @public */
158
+ export declare interface ThreadManagerOptionsBase {
159
+ printErr?: (message: string) => void;
160
+ threadSpawn?: (startArg: number, errorOrTid?: number) => number;
161
+ }
162
+
163
+ /** @public */
164
+ export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
165
+ childThread: true;
166
+ }
167
+
168
+ /** @public */
169
+ export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
170
+ beforeLoad?: (worker: WorkerLike) => any;
171
+ reuseWorker?: boolean | number | ReuseWorkerOptions;
172
+ onCreateWorker: WorkerFactory;
173
+ childThread?: false;
174
+ }
175
+
176
+ /** @public */
177
+ export declare class ThreadMessageHandler {
178
+ protected instance: WebAssembly.Instance | undefined;
179
+ private messagesBeforeLoad;
180
+ protected postMessage: (message: any) => void;
181
+ protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
182
+ protected onError: (error: Error, type: WorkerMessageType) => void;
183
+ constructor(options?: ThreadMessageHandlerOptions);
184
+ /** @virtual */
185
+ instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
186
+ /** @virtual */
187
+ handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
188
+ private _load;
189
+ private _start;
190
+ protected _loaded(err: Error | null, source: WebAssembly.WebAssemblyInstantiatedSource | null, payload: LoadPayload): void;
191
+ protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
192
+ }
193
+
194
+ /** @public */
195
+ export declare interface ThreadMessageHandlerOptions {
196
+ onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
197
+ onError?: (error: Error, type: WorkerMessageType) => void;
198
+ postMessage?: (message: any) => void;
199
+ }
200
+
201
+ /** @public */
202
+ export declare interface WASIInstance {
203
+ readonly wasiImport?: Record<string, any>;
204
+ initialize(instance: object): void;
205
+ start(instance: object): number;
206
+ getImportObject?(): any;
207
+ }
208
+
209
+ /** @public */
210
+ export declare class WASIThreads {
211
+ PThread: ThreadManager | undefined;
212
+ private wasmMemory;
213
+ private wasmInstance;
214
+ private readonly threadSpawn;
215
+ readonly childThread: boolean;
216
+ private readonly postMessage;
217
+ readonly wasi: WASIInstance;
218
+ constructor(options: WASIThreadsOptions);
219
+ getImportObject(): {
220
+ wasi: WASIThreadsImports;
221
+ };
222
+ setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
223
+ preloadWorkers(): Promise<WorkerLike[]>;
224
+ /**
225
+ * It's ok to call this method to a WASI command module.
226
+ *
227
+ * in child thread, must call this method instead of {@link WASIThreads.start} even if it's a WASI command module
228
+ *
229
+ * @returns A proxied WebAssembly instance if in child thread, other wise the original instance
230
+ */
231
+ initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
232
+ /**
233
+ * Equivalent to calling {@link WASIThreads.initialize} and then calling {@link WASIInstance.start}
234
+ * ```js
235
+ * this.initialize(instance, module, memory)
236
+ * this.wasi.start(instance)
237
+ * ```
238
+ */
239
+ start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
240
+ terminateAllThreads(): void;
241
+ }
242
+
243
+ /** @public */
244
+ export declare interface WASIThreadsImports {
245
+ 'thread-spawn': (startArg: number, errorOrTid?: number) => number;
246
+ }
247
+
248
+ /** @public */
249
+ export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
250
+
251
+ /** @public */
252
+ export declare type WorkerFactory = (ctx: {
253
+ type: string;
254
+ name: string;
255
+ }) => WorkerLike;
256
+
257
+ /** @public */
258
+ export declare type WorkerLike = (Worker | Worker_2) & {
259
+ whenLoaded?: Promise<WorkerLike>;
260
+ loaded?: boolean;
261
+ __emnapi_tid?: number;
262
+ };
263
+
264
+ /** @public */
265
+ export declare interface WorkerMessageEvent<T = any> {
266
+ data: T;
267
+ }
268
+
269
+ /** @public */
270
+ export declare type WorkerMessageType = 'load' | 'start';
271
+
272
+ export { }
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.js ADDED
@@ -0,0 +1 @@
 
 
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).wasiThreads={})}(this,function(e){var r="undefined"!=typeof WebAssembly?WebAssembly:"undefined"!=typeof WXWebAssembly?WXWebAssembly:void 0,t="object"==typeof process&&null!==process&&"object"==typeof process.versions&&null!==process.versions&&"string"==typeof process.versions.node;function o(e){return"function"==typeof(null==e?void 0:e.postMessage)?e.postMessage:"function"==typeof postMessage?postMessage:void 0}function n(e){return"function"==typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(e)}function i(e){try{return e instanceof r.RuntimeError}catch(e){return!1}}function s(e,r){return{__emnapi__:{type:e,payload:r}}}function a(e){if(e){if(!n(e.buffer))throw new Error("Multithread features require shared wasm memory. Try to compile with `-matomics -mbulk-memory` and use `--import-memory --shared-memory` during linking, then create WebAssembly.Memory with `shared: true` option")}else if("undefined"==typeof SharedArrayBuffer)throw new Error("Current environment does not support SharedArrayBuffer, threads are not available!")}var d=0,h=function(){function e(e){var r;if(this.unusedWorkers=[],this.runningWorkers=[],this.pthreads=Object.create(null),this.wasmModule=null,this.wasmMemory=null,this.messageEvents=new WeakMap,!e)throw new TypeError("ThreadManager(): options is not provided");this._childThread="childThread"in e&&Boolean(e.childThread),this._childThread?(this._onCreateWorker=void 0,this._reuseWorker=!1,this._beforeLoad=void 0):(this._onCreateWorker=e.onCreateWorker,this._reuseWorker=function(e){var r;if("boolean"==typeof e)return!!e&&{size:0,strict:!1};if("number"==typeof e){if(!(e>=0))throw new RangeError("reuseWorker: size must be a non-negative integer");return{size:e,strict:!1}}if(!e)return!1;var t=null!==(r=Number(e.size))&&void 0!==r?r:0,o=Boolean(e.strict);if(!(t>0)&&o)throw new RangeError("reuseWorker: size must be set to positive integer if strict is set to true");return{size:t,strict:o}}(e.reuseWorker),this._beforeLoad=e.beforeLoad),this.printErr=null!==(r=e.printErr)&&void 0!==r?r:console.error.bind(console),this.threadSpawn=e.threadSpawn}return Object.defineProperty(e.prototype,"nextWorkerID",{get:function(){return d},enumerable:!1,configurable:!0}),e.prototype.init=function(){this._childThread||this.initMainThread()},e.prototype.initMainThread=function(){this.preparePool()},e.prototype.preparePool=function(){if(this._reuseWorker&&this._reuseWorker.size)for(var e=this._reuseWorker.size;e--;){var r=this.allocateUnusedWorker();t&&(r.once("message",function(){}),r.unref())}},e.prototype.shouldPreloadWorkers=function(){return!this._childThread&&this._reuseWorker&&this._reuseWorker.size>0},e.prototype.loadWasmModuleToAllWorkers=function(){for(var e=this,r=Array(this.unusedWorkers.length),o=function(e){var o=n.unusedWorkers[e];t&&o.ref(),r[e]=n.loadWasmModuleToWorker(o).then(function(e){return t&&o.unref(),e},function(e){throw t&&o.unref(),e})},n=this,i=0;i<this.unusedWorkers.length;++i)o(i);return Promise.all(r).catch(function(r){throw e.terminateAllThreads(),r})},e.prototype.preloadWorkers=function(){return this.shouldPreloadWorkers()?this.loadWasmModuleToAllWorkers():Promise.resolve([])},e.prototype.setup=function(e,r){this.wasmModule=e,this.wasmMemory=r},e.prototype.markId=function(e){if(e.__emnapi_tid)return e.__emnapi_tid;var r=d+43;return d=(d+1)%536870869,this.pthreads[r]=e,e.__emnapi_tid=r,r},e.prototype.returnWorkerToPool=function(e){var r=e.__emnapi_tid;void 0!==r&&delete this.pthreads[r],this.unusedWorkers.push(e),this.runningWorkers.splice(this.runningWorkers.indexOf(e),1),delete e.__emnapi_tid,t&&e.unref()},e.prototype.loadWasmModuleToWorker=function(e,r){var o=this;if(e.whenLoaded)return e.whenLoaded;var n=this.printErr,i=this._beforeLoad,d=this;return e.whenLoaded=new Promise(function(h,u){e.onmessage=function(r){!function(r){if(r.__emnapi__){var n=r.__emnapi__.type,i=r.__emnapi__.payload;"loaded"===n?(e.loaded=!0,t&&!e.__emnapi_tid&&e.unref(),h(e)):"cleanup-thread"===n?i.tid in o.pthreads&&o.cleanThread(e,i.tid):"spawn-thread"===n?o.threadSpawn(i.startArg,i.errorOrTid):"terminate-all-threads"===n&&o.terminateAllThreads()}}(r.data),o.fireMessageEvent(e,r)},e.onerror=function(r){var t="worker sent an error!";if(void 0!==e.__emnapi_tid&&(t="worker (tid = "+e.__emnapi_tid+") sent an error!"),"message"in r){if(n(t+" "+r.message),-1!==r.message.indexOf("RuntimeError")||-1!==r.message.indexOf("unreachable"))try{d.terminateAllThreads()}catch(e){}}else n(t);throw u(r),r},t&&(e.on("message",function(r){var t,o;null===(o=(t=e).onmessage)||void 0===o||o.call(t,{data:r})}),e.on("error",function(r){var t,o;null===(o=(t=e).onerror)||void 0===o||o.call(t,r)}),e.on("detachedExit",function(){})),"function"==typeof i&&i(e);try{e.postMessage(s("load",{wasmModule:o.wasmModule,wasmMemory:o.wasmMemory,sab:r}))}catch(e){throw a(o.wasmMemory),e}}),e.whenLoaded},e.prototype.allocateUnusedWorker=function(){var e=this._onCreateWorker;if("function"!=typeof e)throw new TypeError("`options.onCreateWorker` is not provided");var r=e({type:"thread",name:"emnapi-pthread"});return this.unusedWorkers.push(r),r},e.prototype.getNewWorker=function(e){if(this._reuseWorker){if(0===this.unusedWorkers.length){if(this._reuseWorker.strict)if(!t)return void(0,this.printErr)("Tried to spawn a new thread, but the thread pool is exhausted.\nThis might result in a deadlock unless some threads eventually exit or the code explicitly breaks out to the event loop.");var r=this.allocateUnusedWorker();this.loadWasmModuleToWorker(r,e)}return this.unusedWorkers.pop()}var o=this.allocateUnusedWorker();return this.loadWasmModuleToWorker(o,e),this.unusedWorkers.pop()},e.prototype.cleanThread=function(e,r,t){if(!t&&this._reuseWorker)this.returnWorkerToPool(e);else{delete this.pthreads[r];var o=this.runningWorkers.indexOf(e);-1!==o&&this.runningWorkers.splice(o,1),this.terminateWorker(e),delete e.__emnapi_tid}},e.prototype.terminateWorker=function(e){var r,t=this,o=e.__emnapi_tid;e.terminate(),null===(r=this.messageEvents.get(e))||void 0===r||r.clear(),this.messageEvents.delete(e),e.onmessage=function(e){e.data.__emnapi__&&(0,t.printErr)('received "'+e.data.__emnapi__.type+'" command from terminated worker: '+o)}},e.prototype.terminateAllThreads=function(){for(var e=0;e<this.runningWorkers.length;++e)this.terminateWorker(this.runningWorkers[e]);for(e=0;e<this.unusedWorkers.length;++e)this.terminateWorker(this.unusedWorkers[e]);this.unusedWorkers=[],this.runningWorkers=[],this.pthreads=Object.create(null),this.preparePool()},e.prototype.addMessageEventListener=function(e,r){var t=this.messageEvents.get(e);return t||(t=new Set,this.messageEvents.set(e,t)),t.add(r),function(){null==t||t.delete(r)}},e.prototype.fireMessageEvent=function(e,r){var t=this.messageEvents.get(e);if(t){var o=this.printErr;t.forEach(function(e){try{e(r)}catch(e){o(e.stack)}})}},e}(),u=Symbol("kIsProxy");function c(e,r){if(e[u])return e;var t=e.exports,o=function(e){for(var r=["apply","construct","defineProperty","deleteProperty","get","getOwnPropertyDescriptor","getPrototypeOf","has","isExtensible","ownKeys","preventExtensions","set","setPrototypeOf"],t={},o=function(o){var n=r[o];t[n]=function(){var r=Array.prototype.slice.call(arguments,1);return r.unshift(e),Reflect[n].apply(Reflect,r)}},n=0;n<r.length;n++)o(n);return t}(t),n=function(){},i=function(){return 0};o.get=function(e,o,s){var a;return"memory"===o?null!==(a="function"==typeof r?r():r)&&void 0!==a?a:Reflect.get(t,o,s):"_initialize"===o?o in t?n:void 0:"_start"===o?o in t?i:void 0:Reflect.get(t,o,s)},o.has=function(e,r){return"memory"===r||Reflect.has(t,r)};var s=new Proxy(Object.create(null),o);return new Proxy(e,{get:function(e,r,t){return"exports"===r?s:r===u||Reflect.get(e,r,t)}})}var l=new WeakMap,f=function(){function e(e){var n=this;if(!e)throw new TypeError("WASIThreads(): options is not provided");if(!e.wasi)throw new TypeError("WASIThreads(): options.wasi is not provided");l.set(this,new WeakSet);var d=e.wasi;!function(e,r){var t=l.get(e);if(t.has(r))return;var o=e,n=r.wasiImport;if(n){var s=n.proc_exit;n.proc_exit=function(e){return o.terminateAllThreads(),s.call(this,e)}}if(!o.childThread){var a=r.start;"function"==typeof a&&(r.start=function(e){try{return a.call(this,e)}catch(e){throw i(e)&&o.terminateAllThreads(),e}})}t.add(r)}(this,d),this.wasi=d,this.childThread="childThread"in e&&Boolean(e.childThread),this.PThread=void 0,"threadManager"in e?"function"==typeof e.threadManager?this.PThread=e.threadManager():this.PThread=e.threadManager:this.childThread||(this.PThread=new h(e),this.PThread.init());var u=!1;"waitThreadStart"in e&&(u="number"==typeof e.waitThreadStart?e.waitThreadStart:Boolean(e.waitThreadStart));var c=o(e);if(this.childThread&&"function"!=typeof c)throw new TypeError("options.postMessage is not a function");this.postMessage=c;var f=Boolean(e.wasm64),p=function(e,o){var i,d=void 0!==o;try{a(n.wasmMemory)}catch(e){if(null===(i=n.PThread)||void 0===i||i.printErr(e.stack),d){var h=new Int32Array(n.wasmMemory.buffer,o,2);return Atomics.store(h,0,1),Atomics.store(h,1,6),Atomics.notify(h,1),1}return-6}if(!d){var l=n.wasmInstance.exports.malloc;if(!(o=f?Number(l(BigInt(8))):l(8)>>>0))return-48}var p=n.wasmInstance.exports.free,m=f?function(e){p(BigInt(e))}:p,y=new Int32Array(n.wasmMemory.buffer,o,2);if(Atomics.store(y,0,0),Atomics.store(y,1,0),n.childThread){c(s("spawn-thread",{startArg:e,errorOrTid:o})),Atomics.wait(y,1,0);var v=Atomics.load(y,0),w=Atomics.load(y,1);return d?v:(m(o),v?-w:w)}var g,_,T,k=u||0===u;k&&(g=new Int32Array(new SharedArrayBuffer(8208)),Atomics.store(g,0,0));var W=n.PThread;try{if(!(_=W.getNewWorker(g)))throw new Error("failed to get new worker");if(T=W.markId(_),t&&_.unref(),_.postMessage(s("start",{tid:T,arg:e,sab:g})),k){if("number"==typeof u){if("timed-out"===Atomics.wait(g,0,0,u)){try{W.cleanThread(_,T,!0)}catch(e){}throw new Error("Spawning thread timed out. Please check if the worker is created successfully and if message is handled properly in the worker.")}}else Atomics.wait(g,0,0);if(Atomics.load(g,0)>1){try{W.cleanThread(_,T,!0)}catch(e){}throw function(e){var t,o,n=new Int32Array(e);if(Atomics.load(n,0)<=1)return null;var i=Atomics.load(n,1),s=Atomics.load(n,2),a=Atomics.load(n,3),d=new Uint8Array(e),h=d.slice(16,16+i),u=d.slice(16+i,16+i+s),c=d.slice(16+i+s,16+i+s+a),l=(new TextDecoder).decode(h),f=(new TextDecoder).decode(u),p=(new TextDecoder).decode(c),m=new(null!==(t=globalThis[l])&&void 0!==t?t:"RuntimeError"===l&&null!==(o=r.RuntimeError)&&void 0!==o?o:Error)(f);return Object.defineProperty(m,"stack",{value:p,writable:!0,enumerable:!1,configurable:!0}),m}(g.buffer)}}}catch(e){return Atomics.store(y,0,1),Atomics.store(y,1,6),Atomics.notify(y,1),null==W||W.printErr(e.stack),d?1:(m(o),-6)}return Atomics.store(y,0,0),Atomics.store(y,1,T),Atomics.notify(y,1),W.runningWorkers.push(_),k||_.whenLoaded.catch(function(e){throw delete _.whenLoaded,W.cleanThread(_,T,!0),e}),d?0:(m(o),T)};this.threadSpawn=p,this.PThread&&(this.PThread.threadSpawn=p)}return e.prototype.getImportObject=function(){return{wasi:{"thread-spawn":this.threadSpawn}}},e.prototype.setup=function(e,r,t){null!=t||(t=e.exports.memory),this.wasmInstance=e,this.wasmMemory=t,this.PThread&&this.PThread.setup(r,t)},e.prototype.preloadWorkers=function(){return this.PThread?this.PThread.preloadWorkers():Promise.resolve([])},e.prototype.initialize=function(e,r,t){var o=e.exports;null!=t||(t=o.memory),this.childThread&&(e=c(e,t)),this.setup(e,r,t);var n=this.wasi;if("_start"in o&&"function"==typeof o._start)if(this.childThread){n.start(e);try{n[p(n,"kStarted")]=!1}catch(e){}}else!function(e,r){var t=p(e,["kInstance","kSetMemory"]),o=t[0],n=t[1];e[o]=r,e[n](r.exports.memory)}(n,e);else n.initialize(e);return e},e.prototype.start=function(e,r,t){var o=e.exports;return null!=t||(t=o.memory),this.childThread&&(e=c(e,t)),this.setup(e,r,t),{exitCode:this.wasi.start(e),instance:e}},e.prototype.terminateAllThreads=function(){var e;this.childThread?this.postMessage(s("terminate-all-threads",{})):null===(e=this.PThread)||void 0===e||e.terminateAllThreads()},e}();function p(e,r){var t=Object.getOwnPropertySymbols(e),o=function(e){return function(r){return r.description?r.description===e:r.toString()==="Symbol(".concat(e,")")}};return Array.isArray(r)?r.map(function(e){return t.filter(o(e))[0]}):t.filter(o(r))[0]}var m=function(){function e(e){var r=o(e);if("function"!=typeof r)throw new TypeError("options.postMessage is not a function");this.postMessage=r,this.onLoad=null==e?void 0:e.onLoad,this.onError="function"==typeof(null==e?void 0:e.onError)?e.onError:function(e,r){throw r},this.instance=void 0,this.messagesBeforeLoad=[]}return e.prototype.instantiate=function(e){if("function"==typeof this.onLoad)return this.onLoad(e);throw new Error("ThreadMessageHandler.prototype.instantiate is not implemented")},e.prototype.handle=function(e){var r,t=this;if(null===(r=null==e?void 0:e.data)||void 0===r?void 0:r.__emnapi__){var o=e.data.__emnapi__.type,n=e.data.__emnapi__.payload;try{"load"===o?this._load(n):"start"===o&&this.handleAfterLoad(e,function(){t._start(n)})}catch(e){this.onError(e,o)}}},e.prototype._load=function(e){var r=this;if(void 0===this.instance){var t;try{t=this.instantiate(e)}catch(r){return void this._loaded(r,null,e)}var o=t&&"then"in t?t.then:void 0;"function"==typeof o?o.call(t,function(t){r._loaded(null,t,e)},function(t){r._loaded(t,null,e)}):this._loaded(null,t,e)}},e.prototype._start=function(e){var r=this.instance.exports.wasi_thread_start;if("function"!=typeof r){var t=new TypeError("wasi_thread_start is not exported");throw y(e.sab,2,t),t}var o=this.postMessage,n=e.tid,i=e.arg;y(e.sab,1);try{r(n,i)}catch(t){if("unwind"!==t)throw t;return}o(s("cleanup-thread",{tid:n}))},e.prototype._loaded=function(e,r,t){if(e)throw y(t.sab,2,e),e;if(null==r){var o=new TypeError("onLoad should return an object");throw y(t.sab,2,o),o}var n=r.instance;if(!n){var i=new TypeError('onLoad should return an object which includes "instance"');throw y(t.sab,2,i),i}this.instance=n,(0,this.postMessage)(s("loaded",{}));var a=this.messagesBeforeLoad;this.messagesBeforeLoad=[];for(var d=0;d<a.length;d++){var h=a[d];this.handle({data:h})}},e.prototype.handleAfterLoad=function(e,r){void 0!==this.instance?r.call(this,e):this.messagesBeforeLoad.push(e.data)},e}();function y(e,r,t){e&&(!function(e,r,t){var o=new Int32Array(e);if(Atomics.store(o,0,r),r>1&&t){var n=t.name,i=t.message,s=t.stack,a=(new TextEncoder).encode(n),d=(new TextEncoder).encode(i),h=(new TextEncoder).encode(s);Atomics.store(o,1,a.length),Atomics.store(o,2,d.length),Atomics.store(o,3,h.length);var u=new Uint8Array(e);u.set(a,16),u.set(d,16+a.length),u.set(h,16+a.length+d.length)}}(e.buffer,r,t),Atomics.notify(e,0))}e.ThreadManager=h,e.ThreadMessageHandler=m,e.WASIThreads=f,e.createInstanceProxy=c,e.isSharedArrayBuffer=n,e.isTrapError=i});
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.mjs ADDED
@@ -0,0 +1 @@
 
 
1
+ const e="undefined"!=typeof WebAssembly?WebAssembly:"undefined"!=typeof WXWebAssembly?WXWebAssembly:void 0,t="object"==typeof process&&null!==process&&"object"==typeof process.versions&&null!==process.versions&&"string"==typeof process.versions.node;function r(e){return"function"==typeof(null==e?void 0:e.postMessage)?e.postMessage:"function"==typeof postMessage?postMessage:void 0}function s(e){return"function"==typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(e)}function o(t){try{return t instanceof e.RuntimeError}catch(e){return!1}}function n(e,t){return{__emnapi__:{type:e,payload:t}}}function i(e){if(e){if(!s(e.buffer))throw new Error("Multithread features require shared wasm memory. Try to compile with `-matomics -mbulk-memory` and use `--import-memory --shared-memory` during linking, then create WebAssembly.Memory with `shared: true` option")}else if("undefined"==typeof SharedArrayBuffer)throw new Error("Current environment does not support SharedArrayBuffer, threads are not available!")}let a=0;class h{get nextWorkerID(){return a}constructor(e){var t;if(this.unusedWorkers=[],this.runningWorkers=[],this.pthreads=Object.create(null),this.wasmModule=null,this.wasmMemory=null,this.messageEvents=new WeakMap,!e)throw new TypeError("ThreadManager(): options is not provided");this._childThread="childThread"in e&&Boolean(e.childThread),this._childThread?(this._onCreateWorker=void 0,this._reuseWorker=!1,this._beforeLoad=void 0):(this._onCreateWorker=e.onCreateWorker,this._reuseWorker=function(e){var t;if("boolean"==typeof e)return!!e&&{size:0,strict:!1};if("number"==typeof e){if(!(e>=0))throw new RangeError("reuseWorker: size must be a non-negative integer");return{size:e,strict:!1}}if(!e)return!1;const r=null!==(t=Number(e.size))&&void 0!==t?t:0,s=Boolean(e.strict);if(!(r>0)&&s)throw new RangeError("reuseWorker: size must be set to positive integer if strict is set to true");return{size:r,strict:s}}(e.reuseWorker),this._beforeLoad=e.beforeLoad),this.printErr=null!==(t=e.printErr)&&void 0!==t?t:console.error.bind(console),this.threadSpawn=e.threadSpawn}init(){this._childThread||this.initMainThread()}initMainThread(){this.preparePool()}preparePool(){if(this._reuseWorker&&this._reuseWorker.size){let e=this._reuseWorker.size;for(;e--;){const e=this.allocateUnusedWorker();t&&(e.once("message",()=>{}),e.unref())}}}shouldPreloadWorkers(){return!this._childThread&&this._reuseWorker&&this._reuseWorker.size>0}loadWasmModuleToAllWorkers(){const e=Array(this.unusedWorkers.length);for(let r=0;r<this.unusedWorkers.length;++r){const s=this.unusedWorkers[r];t&&s.ref(),e[r]=this.loadWasmModuleToWorker(s).then(e=>(t&&s.unref(),e),e=>{throw t&&s.unref(),e})}return Promise.all(e).catch(e=>{throw this.terminateAllThreads(),e})}preloadWorkers(){return this.shouldPreloadWorkers()?this.loadWasmModuleToAllWorkers():Promise.resolve([])}setup(e,t){this.wasmModule=e,this.wasmMemory=t}markId(e){if(e.__emnapi_tid)return e.__emnapi_tid;const t=a+43;return a=(a+1)%536870869,this.pthreads[t]=e,e.__emnapi_tid=t,t}returnWorkerToPool(e){var r=e.__emnapi_tid;void 0!==r&&delete this.pthreads[r],this.unusedWorkers.push(e),this.runningWorkers.splice(this.runningWorkers.indexOf(e),1),delete e.__emnapi_tid,t&&e.unref()}loadWasmModuleToWorker(e,r){if(e.whenLoaded)return e.whenLoaded;const s=this.printErr,o=this._beforeLoad,a=this;return e.whenLoaded=new Promise((h,d)=>{const l=r=>{if(r.__emnapi__){const s=r.__emnapi__.type,o=r.__emnapi__.payload;"loaded"===s?(e.loaded=!0,t&&!e.__emnapi_tid&&e.unref(),h(e)):"cleanup-thread"===s?o.tid in this.pthreads&&this.cleanThread(e,o.tid):"spawn-thread"===s?this.threadSpawn(o.startArg,o.errorOrTid):"terminate-all-threads"===s&&this.terminateAllThreads()}};e.onmessage=t=>{l(t.data),this.fireMessageEvent(e,t)},e.onerror=function(t){let r="worker sent an error!";if(void 0!==e.__emnapi_tid&&(r="worker (tid = "+e.__emnapi_tid+") sent an error!"),"message"in t){if(s(r+" "+t.message),-1!==t.message.indexOf("RuntimeError")||-1!==t.message.indexOf("unreachable"))try{a.terminateAllThreads()}catch(e){}}else s(r);throw d(t),t},t&&(e.on("message",function(t){var r,s;null===(s=(r=e).onmessage)||void 0===s||s.call(r,{data:t})}),e.on("error",function(t){var r,s;null===(s=(r=e).onerror)||void 0===s||s.call(r,t)}),e.on("detachedExit",function(){})),"function"==typeof o&&o(e);try{e.postMessage(n("load",{wasmModule:this.wasmModule,wasmMemory:this.wasmMemory,sab:r}))}catch(e){throw i(this.wasmMemory),e}}),e.whenLoaded}allocateUnusedWorker(){const e=this._onCreateWorker;if("function"!=typeof e)throw new TypeError("`options.onCreateWorker` is not provided");const t=e({type:"thread",name:"emnapi-pthread"});return this.unusedWorkers.push(t),t}getNewWorker(e){if(this._reuseWorker){if(0===this.unusedWorkers.length){if(this._reuseWorker.strict&&!t){return void(0,this.printErr)("Tried to spawn a new thread, but the thread pool is exhausted.\nThis might result in a deadlock unless some threads eventually exit or the code explicitly breaks out to the event loop.")}const r=this.allocateUnusedWorker();this.loadWasmModuleToWorker(r,e)}return this.unusedWorkers.pop()}const r=this.allocateUnusedWorker();return this.loadWasmModuleToWorker(r,e),this.unusedWorkers.pop()}cleanThread(e,t,r){if(!r&&this._reuseWorker)this.returnWorkerToPool(e);else{delete this.pthreads[t];const r=this.runningWorkers.indexOf(e);-1!==r&&this.runningWorkers.splice(r,1),this.terminateWorker(e),delete e.__emnapi_tid}}terminateWorker(e){var t;const r=e.__emnapi_tid;e.terminate(),null===(t=this.messageEvents.get(e))||void 0===t||t.clear(),this.messageEvents.delete(e),e.onmessage=e=>{if(e.data.__emnapi__){(0,this.printErr)('received "'+e.data.__emnapi__.type+'" command from terminated worker: '+r)}}}terminateAllThreads(){for(let e=0;e<this.runningWorkers.length;++e)this.terminateWorker(this.runningWorkers[e]);for(let e=0;e<this.unusedWorkers.length;++e)this.terminateWorker(this.unusedWorkers[e]);this.unusedWorkers=[],this.runningWorkers=[],this.pthreads=Object.create(null),this.preparePool()}addMessageEventListener(e,t){let r=this.messageEvents.get(e);return r||(r=new Set,this.messageEvents.set(e,r)),r.add(t),()=>{null==r||r.delete(t)}}fireMessageEvent(e,t){const r=this.messageEvents.get(e);if(!r)return;const s=this.printErr;r.forEach(e=>{try{e(t)}catch(e){s(e.stack)}})}}const d=Symbol("kIsProxy");function l(e,t){if(e[d])return e;const r=e.exports,s=function(e){const t=["apply","construct","defineProperty","deleteProperty","get","getOwnPropertyDescriptor","getPrototypeOf","has","isExtensible","ownKeys","preventExtensions","set","setPrototypeOf"],r={};for(let s=0;s<t.length;s++){const o=t[s];r[o]=function(){const t=Array.prototype.slice.call(arguments,1);return t.unshift(e),Reflect[o].apply(Reflect,t)}}return r}(r),o=()=>{},n=()=>0;s.get=function(e,s,i){var a;return"memory"===s?null!==(a="function"==typeof t?t():t)&&void 0!==a?a:Reflect.get(r,s,i):"_initialize"===s?s in r?o:void 0:"_start"===s?s in r?n:void 0:Reflect.get(r,s,i)},s.has=function(e,t){return"memory"===t||Reflect.has(r,t)};const i=new Proxy(Object.create(null),s);return new Proxy(e,{get:(e,t,r)=>"exports"===t?i:t===d||Reflect.get(e,t,r)})}const c=new WeakMap;class u{constructor(s){if(!s)throw new TypeError("WASIThreads(): options is not provided");if(!s.wasi)throw new TypeError("WASIThreads(): options.wasi is not provided");c.set(this,new WeakSet);const a=s.wasi;!function(e,t){const r=c.get(e);if(r.has(t))return;const s=e,n=t.wasiImport;if(n){const e=n.proc_exit;n.proc_exit=function(t){return s.terminateAllThreads(),e.call(this,t)}}if(!s.childThread){const e=t.start;"function"==typeof e&&(t.start=function(t){try{return e.call(this,t)}catch(e){throw o(e)&&s.terminateAllThreads(),e}})}r.add(t)}(this,a),this.wasi=a,this.childThread="childThread"in s&&Boolean(s.childThread),this.PThread=void 0,"threadManager"in s?"function"==typeof s.threadManager?this.PThread=s.threadManager():this.PThread=s.threadManager:this.childThread||(this.PThread=new h(s),this.PThread.init());let d=!1;"waitThreadStart"in s&&(d="number"==typeof s.waitThreadStart?s.waitThreadStart:Boolean(s.waitThreadStart));const l=r(s);if(this.childThread&&"function"!=typeof l)throw new TypeError("options.postMessage is not a function");this.postMessage=l;const u=Boolean(s.wasm64),f=(r,s)=>{var o;const a=void 0!==s;try{i(this.wasmMemory)}catch(e){if(null===(o=this.PThread)||void 0===o||o.printErr(e.stack),a){const e=new Int32Array(this.wasmMemory.buffer,s,2);return Atomics.store(e,0,1),Atomics.store(e,1,6),Atomics.notify(e,1),1}return-6}if(!a){const e=this.wasmInstance.exports.malloc;if(!(s=u?Number(e(BigInt(8))):e(8)>>>0))return-48}const h=this.wasmInstance.exports.free,c=u?e=>{h(BigInt(e))}:h,f=new Int32Array(this.wasmMemory.buffer,s,2);if(Atomics.store(f,0,0),Atomics.store(f,1,0),this.childThread){l(n("spawn-thread",{startArg:r,errorOrTid:s})),Atomics.wait(f,1,0);const e=Atomics.load(f,0),t=Atomics.load(f,1);return a?e:(c(s),e?-t:t)}const p=d||0===d;let m,w,y;p&&(m=new Int32Array(new SharedArrayBuffer(8208)),Atomics.store(m,0,0));const _=this.PThread;try{if(w=_.getNewWorker(m),!w)throw new Error("failed to get new worker");if(y=_.markId(w),t&&w.unref(),w.postMessage(n("start",{tid:y,arg:r,sab:m})),p){if("number"==typeof d){if("timed-out"===Atomics.wait(m,0,0,d)){try{_.cleanThread(w,y,!0)}catch(e){}throw new Error("Spawning thread timed out. Please check if the worker is created successfully and if message is handled properly in the worker.")}}else Atomics.wait(m,0,0);if(Atomics.load(m,0)>1){try{_.cleanThread(w,y,!0)}catch(e){}throw function(t){var r,s;const o=new Int32Array(t);if(Atomics.load(o,0)<=1)return null;const n=Atomics.load(o,1),i=Atomics.load(o,2),a=Atomics.load(o,3),h=new Uint8Array(t),d=h.slice(16,16+n),l=h.slice(16+n,16+n+i),c=h.slice(16+n+i,16+n+i+a),u=(new TextDecoder).decode(d),f=(new TextDecoder).decode(l),p=(new TextDecoder).decode(c),m=new(null!==(r=globalThis[u])&&void 0!==r?r:"RuntimeError"===u&&null!==(s=e.RuntimeError)&&void 0!==s?s:Error)(f);return Object.defineProperty(m,"stack",{value:p,writable:!0,enumerable:!1,configurable:!0}),m}(m.buffer)}}}catch(e){return Atomics.store(f,0,1),Atomics.store(f,1,6),Atomics.notify(f,1),null==_||_.printErr(e.stack),a?1:(c(s),-6)}return Atomics.store(f,0,0),Atomics.store(f,1,y),Atomics.notify(f,1),_.runningWorkers.push(w),p||w.whenLoaded.catch(e=>{throw delete w.whenLoaded,_.cleanThread(w,y,!0),e}),a?0:(c(s),y)};this.threadSpawn=f,this.PThread&&(this.PThread.threadSpawn=f)}getImportObject(){return{wasi:{"thread-spawn":this.threadSpawn}}}setup(e,t,r){null!=r||(r=e.exports.memory),this.wasmInstance=e,this.wasmMemory=r,this.PThread&&this.PThread.setup(t,r)}preloadWorkers(){return this.PThread?this.PThread.preloadWorkers():Promise.resolve([])}initialize(e,t,r){const s=e.exports;null!=r||(r=s.memory),this.childThread&&(e=l(e,r)),this.setup(e,t,r);const o=this.wasi;if("_start"in s&&"function"==typeof s._start)if(this.childThread){o.start(e);try{o[f(o,"kStarted")]=!1}catch(e){}}else!function(e,t){const[r,s]=f(e,["kInstance","kSetMemory"]);e[r]=t,e[s](t.exports.memory)}(o,e);else o.initialize(e);return e}start(e,t,r){const s=e.exports;null!=r||(r=s.memory),this.childThread&&(e=l(e,r)),this.setup(e,t,r);return{exitCode:this.wasi.start(e),instance:e}}terminateAllThreads(){var e;this.childThread?this.postMessage(n("terminate-all-threads",{})):null===(e=this.PThread)||void 0===e||e.terminateAllThreads()}}function f(e,t){const r=Object.getOwnPropertySymbols(e),s=e=>t=>t.description?t.description===e:t.toString()===`Symbol(${e})`;return Array.isArray(t)?t.map(e=>r.filter(s(e))[0]):r.filter(s(t))[0]}class p{constructor(e){const t=r(e);if("function"!=typeof t)throw new TypeError("options.postMessage is not a function");this.postMessage=t,this.onLoad=null==e?void 0:e.onLoad,this.onError="function"==typeof(null==e?void 0:e.onError)?e.onError:(e,t)=>{throw t},this.instance=void 0,this.messagesBeforeLoad=[]}instantiate(e){if("function"==typeof this.onLoad)return this.onLoad(e);throw new Error("ThreadMessageHandler.prototype.instantiate is not implemented")}handle(e){var t;if(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.__emnapi__){const t=e.data.__emnapi__.type,r=e.data.__emnapi__.payload;try{"load"===t?this._load(r):"start"===t&&this.handleAfterLoad(e,()=>{this._start(r)})}catch(e){this.onError(e,t)}}}_load(e){if(void 0!==this.instance)return;let t;try{t=this.instantiate(e)}catch(t){return void this._loaded(t,null,e)}const r=t&&"then"in t?t.then:void 0;"function"==typeof r?r.call(t,t=>{this._loaded(null,t,e)},t=>{this._loaded(t,null,e)}):this._loaded(null,t,e)}_start(e){const t=this.instance.exports.wasi_thread_start;if("function"!=typeof t){const t=new TypeError("wasi_thread_start is not exported");throw m(e.sab,2,t),t}const r=this.postMessage,s=e.tid,o=e.arg;m(e.sab,1);try{t(s,o)}catch(e){if("unwind"!==e)throw e;return}r(n("cleanup-thread",{tid:s}))}_loaded(e,t,r){if(e)throw m(r.sab,2,e),e;if(null==t){const e=new TypeError("onLoad should return an object");throw m(r.sab,2,e),e}const s=t.instance;if(!s){const e=new TypeError('onLoad should return an object which includes "instance"');throw m(r.sab,2,e),e}this.instance=s;(0,this.postMessage)(n("loaded",{}));const o=this.messagesBeforeLoad;this.messagesBeforeLoad=[];for(let e=0;e<o.length;e++){const t=o[e];this.handle({data:t})}}handleAfterLoad(e,t){void 0!==this.instance?t.call(this,e):this.messagesBeforeLoad.push(e.data)}}function m(e,t,r){e&&(!function(e,t,r){const s=new Int32Array(e);if(Atomics.store(s,0,t),t>1&&r){const t=r.name,o=r.message,n=r.stack,i=(new TextEncoder).encode(t),a=(new TextEncoder).encode(o),h=(new TextEncoder).encode(n);Atomics.store(s,1,i.length),Atomics.store(s,2,a.length),Atomics.store(s,3,h.length);const d=new Uint8Array(e);d.set(i,16),d.set(a,16+i.length),d.set(h,16+i.length+a.length)}}(e.buffer,t,r),Atomics.notify(e,0))}export{h as ThreadManager,p as ThreadMessageHandler,u as WASIThreads,l as createInstanceProxy,s as isSharedArrayBuffer,o as isTrapError};
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/dist/wasi-threads.mjs ADDED
@@ -0,0 +1,889 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const _WebAssembly = typeof WebAssembly !== 'undefined'
2
+ ? WebAssembly
3
+ : typeof WXWebAssembly !== 'undefined'
4
+ ? WXWebAssembly
5
+ : undefined;
6
+ const ENVIRONMENT_IS_NODE = typeof process === 'object' && process !== null &&
7
+ typeof process.versions === 'object' && process.versions !== null &&
8
+ typeof process.versions.node === 'string';
9
+ function getPostMessage(options) {
10
+ return typeof (options === null || options === void 0 ? void 0 : options.postMessage) === 'function'
11
+ ? options.postMessage
12
+ : typeof postMessage === 'function'
13
+ ? postMessage
14
+ : undefined;
15
+ }
16
+ function serizeErrorToBuffer(sab, code, error) {
17
+ const i32array = new Int32Array(sab);
18
+ Atomics.store(i32array, 0, code);
19
+ if (code > 1 && error) {
20
+ const name = error.name;
21
+ const message = error.message;
22
+ const stack = error.stack;
23
+ const nameBuffer = new TextEncoder().encode(name);
24
+ const messageBuffer = new TextEncoder().encode(message);
25
+ const stackBuffer = new TextEncoder().encode(stack);
26
+ Atomics.store(i32array, 1, nameBuffer.length);
27
+ Atomics.store(i32array, 2, messageBuffer.length);
28
+ Atomics.store(i32array, 3, stackBuffer.length);
29
+ const buffer = new Uint8Array(sab);
30
+ buffer.set(nameBuffer, 16);
31
+ buffer.set(messageBuffer, 16 + nameBuffer.length);
32
+ buffer.set(stackBuffer, 16 + nameBuffer.length + messageBuffer.length);
33
+ }
34
+ }
35
+ function deserizeErrorFromBuffer(sab) {
36
+ var _a, _b;
37
+ const i32array = new Int32Array(sab);
38
+ const status = Atomics.load(i32array, 0);
39
+ if (status <= 1) {
40
+ return null;
41
+ }
42
+ const nameLength = Atomics.load(i32array, 1);
43
+ const messageLength = Atomics.load(i32array, 2);
44
+ const stackLength = Atomics.load(i32array, 3);
45
+ const buffer = new Uint8Array(sab);
46
+ const nameBuffer = buffer.slice(16, 16 + nameLength);
47
+ const messageBuffer = buffer.slice(16 + nameLength, 16 + nameLength + messageLength);
48
+ const stackBuffer = buffer.slice(16 + nameLength + messageLength, 16 + nameLength + messageLength + stackLength);
49
+ const name = new TextDecoder().decode(nameBuffer);
50
+ const message = new TextDecoder().decode(messageBuffer);
51
+ const stack = new TextDecoder().decode(stackBuffer);
52
+ const ErrorConstructor = (_a = globalThis[name]) !== null && _a !== void 0 ? _a : (name === 'RuntimeError' ? ((_b = _WebAssembly.RuntimeError) !== null && _b !== void 0 ? _b : Error) : Error);
53
+ const error = new ErrorConstructor(message);
54
+ Object.defineProperty(error, 'stack', {
55
+ value: stack,
56
+ writable: true,
57
+ enumerable: false,
58
+ configurable: true
59
+ });
60
+ return error;
61
+ }
62
+ function isSharedArrayBuffer(value) {
63
+ return ((typeof SharedArrayBuffer === 'function' && value instanceof SharedArrayBuffer) ||
64
+ (Object.prototype.toString.call(value) === '[object SharedArrayBuffer]'));
65
+ }
66
+ function isTrapError(e) {
67
+ try {
68
+ return e instanceof _WebAssembly.RuntimeError;
69
+ }
70
+ catch (_) {
71
+ return false;
72
+ }
73
+ }
74
+
75
+ function createMessage(type, payload) {
76
+ return {
77
+ __emnapi__: {
78
+ type,
79
+ payload
80
+ }
81
+ };
82
+ }
83
+
84
+ const WASI_THREADS_MAX_TID = 0x1FFFFFFF;
85
+ function checkSharedWasmMemory(wasmMemory) {
86
+ if (wasmMemory) {
87
+ if (!isSharedArrayBuffer(wasmMemory.buffer)) {
88
+ throw new Error('Multithread features require shared wasm memory. ' +
89
+ 'Try to compile with `-matomics -mbulk-memory` and use `--import-memory --shared-memory` during linking, ' +
90
+ 'then create WebAssembly.Memory with `shared: true` option');
91
+ }
92
+ }
93
+ else {
94
+ if (typeof SharedArrayBuffer === 'undefined') {
95
+ throw new Error('Current environment does not support SharedArrayBuffer, threads are not available!');
96
+ }
97
+ }
98
+ }
99
+ function getReuseWorker(value) {
100
+ var _a;
101
+ if (typeof value === 'boolean') {
102
+ return value ? { size: 0, strict: false } : false;
103
+ }
104
+ if (typeof value === 'number') {
105
+ if (!(value >= 0)) {
106
+ throw new RangeError('reuseWorker: size must be a non-negative integer');
107
+ }
108
+ return { size: value, strict: false };
109
+ }
110
+ if (!value) {
111
+ return false;
112
+ }
113
+ const size = (_a = Number(value.size)) !== null && _a !== void 0 ? _a : 0;
114
+ const strict = Boolean(value.strict);
115
+ if (!(size > 0) && strict) {
116
+ throw new RangeError('reuseWorker: size must be set to positive integer if strict is set to true');
117
+ }
118
+ return { size, strict };
119
+ }
120
+ let nextWorkerID = 0;
121
+ class ThreadManager {
122
+ get nextWorkerID() { return nextWorkerID; }
123
+ constructor(options) {
124
+ var _a;
125
+ this.unusedWorkers = [];
126
+ this.runningWorkers = [];
127
+ this.pthreads = Object.create(null);
128
+ this.wasmModule = null;
129
+ this.wasmMemory = null;
130
+ this.messageEvents = new WeakMap();
131
+ if (!options) {
132
+ throw new TypeError('ThreadManager(): options is not provided');
133
+ }
134
+ if ('childThread' in options) {
135
+ this._childThread = Boolean(options.childThread);
136
+ }
137
+ else {
138
+ this._childThread = false;
139
+ }
140
+ if (this._childThread) {
141
+ this._onCreateWorker = undefined;
142
+ this._reuseWorker = false;
143
+ this._beforeLoad = undefined;
144
+ }
145
+ else {
146
+ this._onCreateWorker = options.onCreateWorker;
147
+ this._reuseWorker = getReuseWorker(options.reuseWorker);
148
+ this._beforeLoad = options.beforeLoad;
149
+ }
150
+ this.printErr = (_a = options.printErr) !== null && _a !== void 0 ? _a : console.error.bind(console);
151
+ this.threadSpawn = options.threadSpawn;
152
+ }
153
+ init() {
154
+ if (!this._childThread) {
155
+ this.initMainThread();
156
+ }
157
+ }
158
+ initMainThread() {
159
+ this.preparePool();
160
+ }
161
+ preparePool() {
162
+ if (this._reuseWorker) {
163
+ if (this._reuseWorker.size) {
164
+ let pthreadPoolSize = this._reuseWorker.size;
165
+ while (pthreadPoolSize--) {
166
+ const worker = this.allocateUnusedWorker();
167
+ if (ENVIRONMENT_IS_NODE) {
168
+ worker.once('message', () => { });
169
+ worker.unref();
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ shouldPreloadWorkers() {
176
+ return !this._childThread && this._reuseWorker && this._reuseWorker.size > 0;
177
+ }
178
+ loadWasmModuleToAllWorkers() {
179
+ const promises = Array(this.unusedWorkers.length);
180
+ for (let i = 0; i < this.unusedWorkers.length; ++i) {
181
+ const worker = this.unusedWorkers[i];
182
+ if (ENVIRONMENT_IS_NODE)
183
+ worker.ref();
184
+ promises[i] = this.loadWasmModuleToWorker(worker).then((w) => {
185
+ if (ENVIRONMENT_IS_NODE)
186
+ worker.unref();
187
+ return w;
188
+ }, (e) => {
189
+ if (ENVIRONMENT_IS_NODE)
190
+ worker.unref();
191
+ throw e;
192
+ });
193
+ }
194
+ return Promise.all(promises).catch((err) => {
195
+ this.terminateAllThreads();
196
+ throw err;
197
+ });
198
+ }
199
+ preloadWorkers() {
200
+ if (this.shouldPreloadWorkers()) {
201
+ return this.loadWasmModuleToAllWorkers();
202
+ }
203
+ return Promise.resolve([]);
204
+ }
205
+ setup(wasmModule, wasmMemory) {
206
+ this.wasmModule = wasmModule;
207
+ this.wasmMemory = wasmMemory;
208
+ }
209
+ markId(worker) {
210
+ if (worker.__emnapi_tid)
211
+ return worker.__emnapi_tid;
212
+ const tid = nextWorkerID + 43;
213
+ nextWorkerID = (nextWorkerID + 1) % (WASI_THREADS_MAX_TID - 42);
214
+ this.pthreads[tid] = worker;
215
+ worker.__emnapi_tid = tid;
216
+ return tid;
217
+ }
218
+ returnWorkerToPool(worker) {
219
+ var tid = worker.__emnapi_tid;
220
+ if (tid !== undefined) {
221
+ delete this.pthreads[tid];
222
+ }
223
+ this.unusedWorkers.push(worker);
224
+ this.runningWorkers.splice(this.runningWorkers.indexOf(worker), 1);
225
+ delete worker.__emnapi_tid;
226
+ if (ENVIRONMENT_IS_NODE) {
227
+ worker.unref();
228
+ }
229
+ }
230
+ loadWasmModuleToWorker(worker, sab) {
231
+ if (worker.whenLoaded)
232
+ return worker.whenLoaded;
233
+ const err = this.printErr;
234
+ const beforeLoad = this._beforeLoad;
235
+ const _this = this;
236
+ worker.whenLoaded = new Promise((resolve, reject) => {
237
+ const handleError = function (e) {
238
+ let message = 'worker sent an error!';
239
+ if (worker.__emnapi_tid !== undefined) {
240
+ message = 'worker (tid = ' + worker.__emnapi_tid + ') sent an error!';
241
+ }
242
+ if ('message' in e) {
243
+ err(message + ' ' + e.message);
244
+ if (e.message.indexOf('RuntimeError') !== -1 || e.message.indexOf('unreachable') !== -1) {
245
+ try {
246
+ _this.terminateAllThreads();
247
+ }
248
+ catch (_) { }
249
+ }
250
+ }
251
+ else {
252
+ err(message);
253
+ }
254
+ reject(e);
255
+ throw e;
256
+ };
257
+ const handleMessage = (data) => {
258
+ if (data.__emnapi__) {
259
+ const type = data.__emnapi__.type;
260
+ const payload = data.__emnapi__.payload;
261
+ if (type === 'loaded') {
262
+ worker.loaded = true;
263
+ if (ENVIRONMENT_IS_NODE && !worker.__emnapi_tid) {
264
+ worker.unref();
265
+ }
266
+ resolve(worker);
267
+ }
268
+ else if (type === 'cleanup-thread') {
269
+ if (payload.tid in this.pthreads) {
270
+ this.cleanThread(worker, payload.tid);
271
+ }
272
+ }
273
+ else if (type === 'spawn-thread') {
274
+ this.threadSpawn(payload.startArg, payload.errorOrTid);
275
+ }
276
+ else if (type === 'terminate-all-threads') {
277
+ this.terminateAllThreads();
278
+ }
279
+ }
280
+ };
281
+ worker.onmessage = (e) => {
282
+ handleMessage(e.data);
283
+ this.fireMessageEvent(worker, e);
284
+ };
285
+ worker.onerror = handleError;
286
+ if (ENVIRONMENT_IS_NODE) {
287
+ worker.on('message', function (data) {
288
+ var _a, _b;
289
+ (_b = (_a = worker).onmessage) === null || _b === void 0 ? void 0 : _b.call(_a, {
290
+ data
291
+ });
292
+ });
293
+ worker.on('error', function (e) {
294
+ var _a, _b;
295
+ (_b = (_a = worker).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, e);
296
+ });
297
+ worker.on('detachedExit', function () { });
298
+ }
299
+ if (typeof beforeLoad === 'function') {
300
+ beforeLoad(worker);
301
+ }
302
+ try {
303
+ worker.postMessage(createMessage('load', {
304
+ wasmModule: this.wasmModule,
305
+ wasmMemory: this.wasmMemory,
306
+ sab
307
+ }));
308
+ }
309
+ catch (err) {
310
+ checkSharedWasmMemory(this.wasmMemory);
311
+ throw err;
312
+ }
313
+ });
314
+ return worker.whenLoaded;
315
+ }
316
+ allocateUnusedWorker() {
317
+ const _onCreateWorker = this._onCreateWorker;
318
+ if (typeof _onCreateWorker !== 'function') {
319
+ throw new TypeError('`options.onCreateWorker` is not provided');
320
+ }
321
+ const worker = _onCreateWorker({ type: 'thread', name: 'emnapi-pthread' });
322
+ this.unusedWorkers.push(worker);
323
+ return worker;
324
+ }
325
+ getNewWorker(sab) {
326
+ if (this._reuseWorker) {
327
+ if (this.unusedWorkers.length === 0) {
328
+ if (this._reuseWorker.strict) {
329
+ if (!ENVIRONMENT_IS_NODE) {
330
+ const err = this.printErr;
331
+ err('Tried to spawn a new thread, but the thread pool is exhausted.\n' +
332
+ 'This might result in a deadlock unless some threads eventually exit or the code explicitly breaks out to the event loop.');
333
+ return;
334
+ }
335
+ }
336
+ const worker = this.allocateUnusedWorker();
337
+ this.loadWasmModuleToWorker(worker, sab);
338
+ }
339
+ return this.unusedWorkers.pop();
340
+ }
341
+ const worker = this.allocateUnusedWorker();
342
+ this.loadWasmModuleToWorker(worker, sab);
343
+ return this.unusedWorkers.pop();
344
+ }
345
+ cleanThread(worker, tid, force) {
346
+ if (!force && this._reuseWorker) {
347
+ this.returnWorkerToPool(worker);
348
+ }
349
+ else {
350
+ delete this.pthreads[tid];
351
+ const index = this.runningWorkers.indexOf(worker);
352
+ if (index !== -1) {
353
+ this.runningWorkers.splice(index, 1);
354
+ }
355
+ this.terminateWorker(worker);
356
+ delete worker.__emnapi_tid;
357
+ }
358
+ }
359
+ terminateWorker(worker) {
360
+ var _a;
361
+ const tid = worker.__emnapi_tid;
362
+ worker.terminate();
363
+ (_a = this.messageEvents.get(worker)) === null || _a === void 0 ? void 0 : _a.clear();
364
+ this.messageEvents.delete(worker);
365
+ worker.onmessage = (e) => {
366
+ if (e.data.__emnapi__) {
367
+ const err = this.printErr;
368
+ err('received "' + e.data.__emnapi__.type + '" command from terminated worker: ' + tid);
369
+ }
370
+ };
371
+ }
372
+ terminateAllThreads() {
373
+ for (let i = 0; i < this.runningWorkers.length; ++i) {
374
+ this.terminateWorker(this.runningWorkers[i]);
375
+ }
376
+ for (let i = 0; i < this.unusedWorkers.length; ++i) {
377
+ this.terminateWorker(this.unusedWorkers[i]);
378
+ }
379
+ this.unusedWorkers = [];
380
+ this.runningWorkers = [];
381
+ this.pthreads = Object.create(null);
382
+ this.preparePool();
383
+ }
384
+ addMessageEventListener(worker, onMessage) {
385
+ let listeners = this.messageEvents.get(worker);
386
+ if (!listeners) {
387
+ listeners = new Set();
388
+ this.messageEvents.set(worker, listeners);
389
+ }
390
+ listeners.add(onMessage);
391
+ return () => {
392
+ listeners === null || listeners === void 0 ? void 0 : listeners.delete(onMessage);
393
+ };
394
+ }
395
+ fireMessageEvent(worker, e) {
396
+ const listeners = this.messageEvents.get(worker);
397
+ if (!listeners)
398
+ return;
399
+ const err = this.printErr;
400
+ listeners.forEach((listener) => {
401
+ try {
402
+ listener(e);
403
+ }
404
+ catch (e) {
405
+ err(e.stack);
406
+ }
407
+ });
408
+ }
409
+ }
410
+
411
+ const kIsProxy = Symbol('kIsProxy');
412
+ function createInstanceProxy(instance, memory) {
413
+ if (instance[kIsProxy])
414
+ return instance;
415
+ const originalExports = instance.exports;
416
+ const createHandler = function (target) {
417
+ const handlers = [
418
+ 'apply',
419
+ 'construct',
420
+ 'defineProperty',
421
+ 'deleteProperty',
422
+ 'get',
423
+ 'getOwnPropertyDescriptor',
424
+ 'getPrototypeOf',
425
+ 'has',
426
+ 'isExtensible',
427
+ 'ownKeys',
428
+ 'preventExtensions',
429
+ 'set',
430
+ 'setPrototypeOf'
431
+ ];
432
+ const handler = {};
433
+ for (let i = 0; i < handlers.length; i++) {
434
+ const name = handlers[i];
435
+ handler[name] = function () {
436
+ const args = Array.prototype.slice.call(arguments, 1);
437
+ args.unshift(target);
438
+ return Reflect[name].apply(Reflect, args);
439
+ };
440
+ }
441
+ return handler;
442
+ };
443
+ const handler = createHandler(originalExports);
444
+ const _initialize = () => { };
445
+ const _start = () => 0;
446
+ handler.get = function (_target, p, receiver) {
447
+ var _a;
448
+ if (p === 'memory') {
449
+ return (_a = (typeof memory === 'function' ? memory() : memory)) !== null && _a !== void 0 ? _a : Reflect.get(originalExports, p, receiver);
450
+ }
451
+ if (p === '_initialize') {
452
+ return p in originalExports ? _initialize : undefined;
453
+ }
454
+ if (p === '_start') {
455
+ return p in originalExports ? _start : undefined;
456
+ }
457
+ return Reflect.get(originalExports, p, receiver);
458
+ };
459
+ handler.has = function (_target, p) {
460
+ if (p === 'memory')
461
+ return true;
462
+ return Reflect.has(originalExports, p);
463
+ };
464
+ const exportsProxy = new Proxy(Object.create(null), handler);
465
+ return new Proxy(instance, {
466
+ get(target, p, receiver) {
467
+ if (p === 'exports') {
468
+ return exportsProxy;
469
+ }
470
+ if (p === kIsProxy) {
471
+ return true;
472
+ }
473
+ return Reflect.get(target, p, receiver);
474
+ }
475
+ });
476
+ }
477
+
478
+ const patchedWasiInstances = new WeakMap();
479
+ class WASIThreads {
480
+ constructor(options) {
481
+ if (!options) {
482
+ throw new TypeError('WASIThreads(): options is not provided');
483
+ }
484
+ if (!options.wasi) {
485
+ throw new TypeError('WASIThreads(): options.wasi is not provided');
486
+ }
487
+ patchedWasiInstances.set(this, new WeakSet());
488
+ const wasi = options.wasi;
489
+ patchWasiInstance(this, wasi);
490
+ this.wasi = wasi;
491
+ if ('childThread' in options) {
492
+ this.childThread = Boolean(options.childThread);
493
+ }
494
+ else {
495
+ this.childThread = false;
496
+ }
497
+ this.PThread = undefined;
498
+ if ('threadManager' in options) {
499
+ if (typeof options.threadManager === 'function') {
500
+ this.PThread = options.threadManager();
501
+ }
502
+ else {
503
+ this.PThread = options.threadManager;
504
+ }
505
+ }
506
+ else {
507
+ if (!this.childThread) {
508
+ this.PThread = new ThreadManager(options);
509
+ this.PThread.init();
510
+ }
511
+ }
512
+ let waitThreadStart = false;
513
+ if ('waitThreadStart' in options) {
514
+ waitThreadStart = typeof options.waitThreadStart === 'number' ? options.waitThreadStart : Boolean(options.waitThreadStart);
515
+ }
516
+ const postMessage = getPostMessage(options);
517
+ if (this.childThread && typeof postMessage !== 'function') {
518
+ throw new TypeError('options.postMessage is not a function');
519
+ }
520
+ this.postMessage = postMessage;
521
+ const wasm64 = Boolean(options.wasm64);
522
+ const threadSpawn = (startArg, errorOrTid) => {
523
+ var _a;
524
+ const EAGAIN = 6;
525
+ const isNewABI = errorOrTid !== undefined;
526
+ try {
527
+ checkSharedWasmMemory(this.wasmMemory);
528
+ }
529
+ catch (err) {
530
+ (_a = this.PThread) === null || _a === void 0 ? void 0 : _a.printErr(err.stack);
531
+ if (isNewABI) {
532
+ const struct = new Int32Array(this.wasmMemory.buffer, errorOrTid, 2);
533
+ Atomics.store(struct, 0, 1);
534
+ Atomics.store(struct, 1, EAGAIN);
535
+ Atomics.notify(struct, 1);
536
+ return 1;
537
+ }
538
+ else {
539
+ return -EAGAIN;
540
+ }
541
+ }
542
+ if (!isNewABI) {
543
+ const malloc = this.wasmInstance.exports.malloc;
544
+ errorOrTid = wasm64 ? Number(malloc(BigInt(8))) : (malloc(8) >>> 0);
545
+ if (!errorOrTid) {
546
+ return -48;
547
+ }
548
+ }
549
+ const _free = this.wasmInstance.exports.free;
550
+ const free = wasm64 ? (ptr) => { _free(BigInt(ptr)); } : _free;
551
+ const struct = new Int32Array(this.wasmMemory.buffer, errorOrTid, 2);
552
+ Atomics.store(struct, 0, 0);
553
+ Atomics.store(struct, 1, 0);
554
+ if (this.childThread) {
555
+ postMessage(createMessage('spawn-thread', {
556
+ startArg,
557
+ errorOrTid: errorOrTid
558
+ }));
559
+ Atomics.wait(struct, 1, 0);
560
+ const isError = Atomics.load(struct, 0);
561
+ const result = Atomics.load(struct, 1);
562
+ if (isNewABI) {
563
+ return isError;
564
+ }
565
+ free(errorOrTid);
566
+ return isError ? -result : result;
567
+ }
568
+ const shouldWait = waitThreadStart || (waitThreadStart === 0);
569
+ let sab;
570
+ if (shouldWait) {
571
+ sab = new Int32Array(new SharedArrayBuffer(16 + 8192));
572
+ Atomics.store(sab, 0, 0);
573
+ }
574
+ let worker;
575
+ let tid;
576
+ const PThread = this.PThread;
577
+ try {
578
+ worker = PThread.getNewWorker(sab);
579
+ if (!worker) {
580
+ throw new Error('failed to get new worker');
581
+ }
582
+ tid = PThread.markId(worker);
583
+ if (ENVIRONMENT_IS_NODE) {
584
+ worker.unref();
585
+ }
586
+ worker.postMessage(createMessage('start', {
587
+ tid,
588
+ arg: startArg,
589
+ sab
590
+ }));
591
+ if (shouldWait) {
592
+ if (typeof waitThreadStart === 'number') {
593
+ const waitResult = Atomics.wait(sab, 0, 0, waitThreadStart);
594
+ if (waitResult === 'timed-out') {
595
+ try {
596
+ PThread.cleanThread(worker, tid, true);
597
+ }
598
+ catch (_) { }
599
+ throw new Error('Spawning thread timed out. Please check if the worker is created successfully and if message is handled properly in the worker.');
600
+ }
601
+ }
602
+ else {
603
+ Atomics.wait(sab, 0, 0);
604
+ }
605
+ const r = Atomics.load(sab, 0);
606
+ if (r > 1) {
607
+ try {
608
+ PThread.cleanThread(worker, tid, true);
609
+ }
610
+ catch (_) { }
611
+ throw deserizeErrorFromBuffer(sab.buffer);
612
+ }
613
+ }
614
+ }
615
+ catch (e) {
616
+ Atomics.store(struct, 0, 1);
617
+ Atomics.store(struct, 1, EAGAIN);
618
+ Atomics.notify(struct, 1);
619
+ PThread === null || PThread === void 0 ? void 0 : PThread.printErr(e.stack);
620
+ if (isNewABI) {
621
+ return 1;
622
+ }
623
+ free(errorOrTid);
624
+ return -EAGAIN;
625
+ }
626
+ Atomics.store(struct, 0, 0);
627
+ Atomics.store(struct, 1, tid);
628
+ Atomics.notify(struct, 1);
629
+ PThread.runningWorkers.push(worker);
630
+ if (!shouldWait) {
631
+ worker.whenLoaded.catch((err) => {
632
+ delete worker.whenLoaded;
633
+ PThread.cleanThread(worker, tid, true);
634
+ throw err;
635
+ });
636
+ }
637
+ if (isNewABI) {
638
+ return 0;
639
+ }
640
+ free(errorOrTid);
641
+ return tid;
642
+ };
643
+ this.threadSpawn = threadSpawn;
644
+ if (this.PThread) {
645
+ this.PThread.threadSpawn = threadSpawn;
646
+ }
647
+ }
648
+ getImportObject() {
649
+ return {
650
+ wasi: {
651
+ 'thread-spawn': this.threadSpawn
652
+ }
653
+ };
654
+ }
655
+ setup(wasmInstance, wasmModule, wasmMemory) {
656
+ wasmMemory !== null && wasmMemory !== void 0 ? wasmMemory : (wasmMemory = wasmInstance.exports.memory);
657
+ this.wasmInstance = wasmInstance;
658
+ this.wasmMemory = wasmMemory;
659
+ if (this.PThread) {
660
+ this.PThread.setup(wasmModule, wasmMemory);
661
+ }
662
+ }
663
+ preloadWorkers() {
664
+ if (this.PThread) {
665
+ return this.PThread.preloadWorkers();
666
+ }
667
+ return Promise.resolve([]);
668
+ }
669
+ initialize(instance, module, memory) {
670
+ const exports$1 = instance.exports;
671
+ memory !== null && memory !== void 0 ? memory : (memory = exports$1.memory);
672
+ if (this.childThread) {
673
+ instance = createInstanceProxy(instance, memory);
674
+ }
675
+ this.setup(instance, module, memory);
676
+ const wasi = this.wasi;
677
+ if (('_start' in exports$1) && (typeof exports$1._start === 'function')) {
678
+ if (this.childThread) {
679
+ wasi.start(instance);
680
+ try {
681
+ const kStarted = getWasiSymbol(wasi, 'kStarted');
682
+ wasi[kStarted] = false;
683
+ }
684
+ catch (_) { }
685
+ }
686
+ else {
687
+ setupInstance(wasi, instance);
688
+ }
689
+ }
690
+ else {
691
+ wasi.initialize(instance);
692
+ }
693
+ return instance;
694
+ }
695
+ start(instance, module, memory) {
696
+ const exports$1 = instance.exports;
697
+ memory !== null && memory !== void 0 ? memory : (memory = exports$1.memory);
698
+ if (this.childThread) {
699
+ instance = createInstanceProxy(instance, memory);
700
+ }
701
+ this.setup(instance, module, memory);
702
+ const exitCode = this.wasi.start(instance);
703
+ return { exitCode, instance };
704
+ }
705
+ terminateAllThreads() {
706
+ var _a;
707
+ if (!this.childThread) {
708
+ (_a = this.PThread) === null || _a === void 0 ? void 0 : _a.terminateAllThreads();
709
+ }
710
+ else {
711
+ this.postMessage(createMessage('terminate-all-threads', {}));
712
+ }
713
+ }
714
+ }
715
+ function patchWasiInstance(wasiThreads, wasi) {
716
+ const patched = patchedWasiInstances.get(wasiThreads);
717
+ if (patched.has(wasi)) {
718
+ return;
719
+ }
720
+ const _this = wasiThreads;
721
+ const wasiImport = wasi.wasiImport;
722
+ if (wasiImport) {
723
+ const proc_exit = wasiImport.proc_exit;
724
+ wasiImport.proc_exit = function (code) {
725
+ _this.terminateAllThreads();
726
+ return proc_exit.call(this, code);
727
+ };
728
+ }
729
+ if (!_this.childThread) {
730
+ const start = wasi.start;
731
+ if (typeof start === 'function') {
732
+ wasi.start = function (instance) {
733
+ try {
734
+ return start.call(this, instance);
735
+ }
736
+ catch (err) {
737
+ if (isTrapError(err)) {
738
+ _this.terminateAllThreads();
739
+ }
740
+ throw err;
741
+ }
742
+ };
743
+ }
744
+ }
745
+ patched.add(wasi);
746
+ }
747
+ function getWasiSymbol(wasi, description) {
748
+ const symbols = Object.getOwnPropertySymbols(wasi);
749
+ const selectDescription = (description) => (s) => {
750
+ if (s.description) {
751
+ return s.description === description;
752
+ }
753
+ return s.toString() === `Symbol(${description})`;
754
+ };
755
+ if (Array.isArray(description)) {
756
+ return description.map(d => symbols.filter(selectDescription(d))[0]);
757
+ }
758
+ return symbols.filter(selectDescription(description))[0];
759
+ }
760
+ function setupInstance(wasi, instance) {
761
+ const [kInstance, kSetMemory] = getWasiSymbol(wasi, ['kInstance', 'kSetMemory']);
762
+ wasi[kInstance] = instance;
763
+ wasi[kSetMemory](instance.exports.memory);
764
+ }
765
+
766
+ class ThreadMessageHandler {
767
+ constructor(options) {
768
+ const postMsg = getPostMessage(options);
769
+ if (typeof postMsg !== 'function') {
770
+ throw new TypeError('options.postMessage is not a function');
771
+ }
772
+ this.postMessage = postMsg;
773
+ this.onLoad = options === null || options === void 0 ? void 0 : options.onLoad;
774
+ this.onError = typeof (options === null || options === void 0 ? void 0 : options.onError) === 'function' ? options.onError : (_type, err) => { throw err; };
775
+ this.instance = undefined;
776
+ this.messagesBeforeLoad = [];
777
+ }
778
+ instantiate(data) {
779
+ if (typeof this.onLoad === 'function') {
780
+ return this.onLoad(data);
781
+ }
782
+ throw new Error('ThreadMessageHandler.prototype.instantiate is not implemented');
783
+ }
784
+ handle(e) {
785
+ var _a;
786
+ if ((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.__emnapi__) {
787
+ const type = e.data.__emnapi__.type;
788
+ const payload = e.data.__emnapi__.payload;
789
+ try {
790
+ if (type === 'load') {
791
+ this._load(payload);
792
+ }
793
+ else if (type === 'start') {
794
+ this.handleAfterLoad(e, () => {
795
+ this._start(payload);
796
+ });
797
+ }
798
+ }
799
+ catch (err) {
800
+ this.onError(err, type);
801
+ }
802
+ }
803
+ }
804
+ _load(payload) {
805
+ if (this.instance !== undefined)
806
+ return;
807
+ let source;
808
+ try {
809
+ source = this.instantiate(payload);
810
+ }
811
+ catch (err) {
812
+ this._loaded(err, null, payload);
813
+ return;
814
+ }
815
+ const then = source && 'then' in source ? source.then : undefined;
816
+ if (typeof then === 'function') {
817
+ then.call(source, (source) => { this._loaded(null, source, payload); }, (err) => { this._loaded(err, null, payload); });
818
+ }
819
+ else {
820
+ this._loaded(null, source, payload);
821
+ }
822
+ }
823
+ _start(payload) {
824
+ const wasi_thread_start = this.instance.exports.wasi_thread_start;
825
+ if (typeof wasi_thread_start !== 'function') {
826
+ const err = new TypeError('wasi_thread_start is not exported');
827
+ notifyPthreadCreateResult(payload.sab, 2, err);
828
+ throw err;
829
+ }
830
+ const postMessage = this.postMessage;
831
+ const tid = payload.tid;
832
+ const startArg = payload.arg;
833
+ notifyPthreadCreateResult(payload.sab, 1);
834
+ try {
835
+ wasi_thread_start(tid, startArg);
836
+ }
837
+ catch (err) {
838
+ if (err !== 'unwind') {
839
+ throw err;
840
+ }
841
+ else {
842
+ return;
843
+ }
844
+ }
845
+ postMessage(createMessage('cleanup-thread', { tid }));
846
+ }
847
+ _loaded(err, source, payload) {
848
+ if (err) {
849
+ notifyPthreadCreateResult(payload.sab, 2, err);
850
+ throw err;
851
+ }
852
+ if (source == null) {
853
+ const err = new TypeError('onLoad should return an object');
854
+ notifyPthreadCreateResult(payload.sab, 2, err);
855
+ throw err;
856
+ }
857
+ const instance = source.instance;
858
+ if (!instance) {
859
+ const err = new TypeError('onLoad should return an object which includes "instance"');
860
+ notifyPthreadCreateResult(payload.sab, 2, err);
861
+ throw err;
862
+ }
863
+ this.instance = instance;
864
+ const postMessage = this.postMessage;
865
+ postMessage(createMessage('loaded', {}));
866
+ const messages = this.messagesBeforeLoad;
867
+ this.messagesBeforeLoad = [];
868
+ for (let i = 0; i < messages.length; i++) {
869
+ const data = messages[i];
870
+ this.handle({ data });
871
+ }
872
+ }
873
+ handleAfterLoad(e, f) {
874
+ if (this.instance !== undefined) {
875
+ f.call(this, e);
876
+ }
877
+ else {
878
+ this.messagesBeforeLoad.push(e.data);
879
+ }
880
+ }
881
+ }
882
+ function notifyPthreadCreateResult(sab, result, error) {
883
+ if (sab) {
884
+ serizeErrorToBuffer(sab.buffer, result, error);
885
+ Atomics.notify(sab, 0);
886
+ }
887
+ }
888
+
889
+ export { ThreadManager, ThreadMessageHandler, WASIThreads, createInstanceProxy, isSharedArrayBuffer, isTrapError };
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/index.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') {
2
+ module.exports = require('./dist/wasi-threads.cjs.min.js')
3
+ } else {
4
+ module.exports = require('./dist/wasi-threads.cjs.js')
5
+ }
astra_scene_test/X_03/node_modules/@emnapi/wasi-threads/package.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@emnapi/wasi-threads",
3
+ "version": "1.2.1",
4
+ "description": "WASI threads proposal implementation in JavaScript",
5
+ "main": "index.js",
6
+ "module": "./dist/wasi-threads.esm-bundler.js",
7
+ "types": "./dist/wasi-threads.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": {
12
+ "module": "./dist/wasi-threads.d.ts",
13
+ "import": "./dist/wasi-threads.d.mts",
14
+ "default": "./dist/wasi-threads.d.ts"
15
+ },
16
+ "module": "./dist/wasi-threads.esm-bundler.js",
17
+ "import": "./dist/wasi-threads.mjs",
18
+ "default": "./index.js"
19
+ },
20
+ "./dist/wasi-threads.cjs.min": {
21
+ "types": "./dist/wasi-threads.d.ts",
22
+ "default": "./dist/wasi-threads.cjs.min.js"
23
+ },
24
+ "./dist/wasi-threads.min.mjs": {
25
+ "types": "./dist/wasi-threads.d.mts",
26
+ "default": "./dist/wasi-threads.min.mjs"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "tslib": "^2.4.0"
31
+ },
32
+ "scripts": {
33
+ "build": "node ./script/build.js",
34
+ "build:test": "node ./test/build.js",
35
+ "test": "node ./test/index.js"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/toyobayashi/emnapi.git"
40
+ },
41
+ "author": "toyobayashi",
42
+ "license": "MIT",
43
+ "bugs": {
44
+ "url": "https://github.com/toyobayashi/emnapi/issues"
45
+ },
46
+ "homepage": "https://github.com/toyobayashi/emnapi#readme",
47
+ "publishConfig": {
48
+ "access": "public"
49
+ }
50
+ }
astra_scene_test/X_03/node_modules/@rolldown/binding-darwin-arm64/README.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # `@rolldown/binding-darwin-arm64`
2
+
3
+ This is the **aarch64-apple-darwin** binary for `@rolldown/binding`
astra_scene_test/X_03/node_modules/@rolldown/binding-darwin-arm64/package.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@rolldown/binding-darwin-arm64",
3
+ "version": "1.0.1",
4
+ "cpu": [
5
+ "arm64"
6
+ ],
7
+ "main": "rolldown-binding.darwin-arm64.node",
8
+ "files": [
9
+ "rolldown-binding.darwin-arm64.node"
10
+ ],
11
+ "description": "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.",
12
+ "keywords": [
13
+ "bundler",
14
+ "esbuild",
15
+ "parcel",
16
+ "rolldown",
17
+ "rollup",
18
+ "webpack"
19
+ ],
20
+ "homepage": "https://rolldown.rs/",
21
+ "license": "MIT",
22
+ "engines": {
23
+ "node": "^20.19.0 || >=22.12.0"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/rolldown/rolldown.git",
28
+ "directory": "packages/rolldown"
29
+ },
30
+ "publishConfig": {
31
+ "registry": "https://registry.npmjs.org/",
32
+ "access": "public"
33
+ },
34
+ "os": [
35
+ "darwin"
36
+ ]
37
+ }
astra_scene_test/X_03/node_modules/@rolldown/pluginutils/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present, rolldown/plugins repository contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.