@componentor/quickjs-ffi-types 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ quickjs-emscripten copyright (c) 2019-2024 Jake Teton-Landis
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.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @componentor/quickjs-ffi-types
2
+
3
+ This is an internal package, part of [quickjs-emscripten](https://github.com/justjake/quickjs-emscripten).
4
+
5
+ See the main package for documentation.
@@ -0,0 +1,547 @@
1
+ /**
2
+ * C pointer to type `CType`. Pointer types are used internally for FFI, but
3
+ * are not intended for external use.
4
+ *
5
+ * @unstable This type is considered private and may change.
6
+ */
7
+ type Pointer<CType extends string> = number & {
8
+ ctype: CType;
9
+ };
10
+ type Brand<T, B> = T & {
11
+ brand: B;
12
+ };
13
+ /**
14
+ * `JSRuntime*`.
15
+ */
16
+ type JSRuntimePointer = Pointer<"JSRuntime">;
17
+ /**
18
+ * `JSContext*`.
19
+ */
20
+ type JSContextPointer = Pointer<"JSContext">;
21
+ /**
22
+ * `JSContext**`. Used internally for execute pending jobs.
23
+ */
24
+ type JSContextPointerPointer = Pointer<"JSContext">;
25
+ /**
26
+ * `JSModuleDef*`.
27
+ */
28
+ type JSModuleDefPointer = Pointer<"JSModuleDef">;
29
+ /**
30
+ * `JSValue*`.
31
+ * See {@link JSValue}.
32
+ */
33
+ type JSValuePointer = Pointer<"JSValue">;
34
+ /**
35
+ * `JSValueConst*
36
+ * See {@link JSValueConst} and {@link StaticJSValue}.
37
+ */
38
+ type JSValueConstPointer = Pointer<"JSValueConst">;
39
+ /**
40
+ * Used internally for Javascript-to-C function calls.
41
+ */
42
+ type JSValuePointerPointer = Pointer<"JSValue[]">;
43
+ /**
44
+ * Used internally for Javascript-to-C function calls.
45
+ */
46
+ type JSValuePointerPointerPointer = Pointer<"*JSValue[]">;
47
+ /**
48
+ * Used internally for Javascript-to-C function calls.
49
+ */
50
+ type JSValueConstPointerPointer = Pointer<"JSValueConst[]">;
51
+ /**
52
+ * Used internally for C-to-Javascript function calls.
53
+ */
54
+ /**
55
+ * Used internally for C-to-Javascript function calls.
56
+ */
57
+ type QTS_C_To_HostCallbackFuncPointer = Pointer<"C_To_HostCallbackFunc">;
58
+ /**
59
+ * Used internally for C-to-Javascript interrupt handlers.
60
+ */
61
+ type QTS_C_To_HostInterruptFuncPointer = Pointer<"C_To_HostInterruptFunc">;
62
+ /**
63
+ * Used internally for C-to-Javascript module loading.
64
+ */
65
+ type QTS_C_To_HostLoadModuleFuncPointer = Pointer<"C_To_HostLoadModuleFunc">;
66
+ /**
67
+ * Used internally for Javascript-to-C calls that may contain strings too large
68
+ * for the Emscripten stack.
69
+ */
70
+ type BorrowedHeapCharPointer = Pointer<"const char" | "char" | "js const char">;
71
+ /**
72
+ * Used internally for Javascript-to-C calls that may contain strings too large
73
+ * for the Emscripten stack.
74
+ */
75
+ type OwnedHeapCharPointer = Pointer<"char">;
76
+ /**
77
+ * Used internally for Javascript-to-C calls that may contain strings too large
78
+ * for the Emscripten stack.
79
+ */
80
+ type JSBorrowedCharPointer = Pointer<"js const char">;
81
+ /**
82
+ * Opaque pointer that was allocated by js_malloc.
83
+ */
84
+ type JSVoidPointer = Pointer<any>;
85
+ type UInt32Pointer = Pointer<"uint32_t">;
86
+ /**
87
+ * @private
88
+ */
89
+ type EvalDetectModule = Brand<number, "EvalDetectModule">;
90
+ declare function assertSync<Args extends any[], R>(fn: (...args: Args) => R): (...args: Args) => R;
91
+ /**
92
+ * @private
93
+ */
94
+ type EvalFlags = Brand<number, "EvalFlags">;
95
+ /** Bitfield options for JS_Eval() C function. */
96
+ declare const EvalFlags: {
97
+ /** global code (default) */
98
+ readonly JS_EVAL_TYPE_GLOBAL: number;
99
+ /** module code */
100
+ readonly JS_EVAL_TYPE_MODULE: number;
101
+ /** direct call (internal use) */
102
+ readonly JS_EVAL_TYPE_DIRECT: number;
103
+ /** indirect call (internal use) */
104
+ readonly JS_EVAL_TYPE_INDIRECT: number;
105
+ readonly JS_EVAL_TYPE_MASK: number;
106
+ /** force 'strict' mode */
107
+ readonly JS_EVAL_FLAG_STRICT: number;
108
+ /** force 'strip' mode */
109
+ readonly JS_EVAL_FLAG_STRIP: number;
110
+ /**
111
+ * compile but do not run. The result is an object with a
112
+ * JS_TAG_FUNCTION_BYTECODE or JS_TAG_MODULE tag. It can be executed
113
+ * with JS_EvalFunction().
114
+ */
115
+ readonly JS_EVAL_FLAG_COMPILE_ONLY: number;
116
+ /** don't include the stack frames before this eval in the Error() backtraces */
117
+ readonly JS_EVAL_FLAG_BACKTRACE_BARRIER: number;
118
+ };
119
+ /**
120
+ * @private
121
+ */
122
+ type IntrinsicsFlags = Brand<number, "IntrinsicsFlags">;
123
+ /** Bitfield options for QTS_NewContext intrinsics */
124
+ declare const IntrinsicsFlags: {
125
+ readonly BaseObjects: number;
126
+ readonly Date: number;
127
+ readonly Eval: number;
128
+ readonly StringNormalize: number;
129
+ readonly RegExp: number;
130
+ readonly RegExpCompiler: number;
131
+ readonly JSON: number;
132
+ readonly Proxy: number;
133
+ readonly MapSet: number;
134
+ readonly TypedArrays: number;
135
+ readonly Promise: number;
136
+ readonly BigInt: number;
137
+ readonly BigFloat: number;
138
+ readonly BigDecimal: number;
139
+ readonly OperatorOverloading: number;
140
+ readonly BignumExt: number;
141
+ };
142
+ /**
143
+ * State of a promise.
144
+ */
145
+ type JSPromiseStateEnum = Brand<(typeof JSPromiseStateEnum)[keyof typeof JSPromiseStateEnum], "JSPromiseStateEnum">;
146
+ declare const JSPromiseStateEnum: {
147
+ readonly Pending: 0;
148
+ readonly Fulfilled: 1;
149
+ readonly Rejected: 2;
150
+ };
151
+ /**
152
+ * @private
153
+ */
154
+ type GetOwnPropertyNamesFlags = Brand<number, "GetOwnPropertyNamesFlags">;
155
+ /** Bitfield options for QTS_GetOwnPropertyNames */
156
+ declare const GetOwnPropertyNamesFlags: {
157
+ JS_GPN_STRING_MASK: number;
158
+ JS_GPN_SYMBOL_MASK: number;
159
+ JS_GPN_PRIVATE_MASK: number;
160
+ JS_GPN_ENUM_ONLY: number;
161
+ JS_GPN_SET_ENUM: number;
162
+ QTS_GPN_NUMBER_MASK: number;
163
+ QTS_STANDARD_COMPLIANT_NUMBER: number;
164
+ };
165
+ /**
166
+ * @private
167
+ */
168
+ type IsEqualOp = Brand<number, "IsEqualOp">;
169
+ declare const IsEqualOp: {
170
+ IsStrictlyEqual: IsEqualOp;
171
+ IsSameValue: IsEqualOp;
172
+ IsSameValueZero: IsEqualOp;
173
+ };
174
+
175
+ declare namespace Emscripten {
176
+ interface FileSystemType {
177
+ }
178
+ type EnvironmentType = "WEB" | "NODE" | "SHELL" | "WORKER";
179
+ type ValueType = "number" | "string" | "array" | "boolean";
180
+ type TypeCompatibleWithC = number | string | any[] | boolean;
181
+ type WebAssemblyImports = Array<{
182
+ name: string;
183
+ kind: string;
184
+ }>;
185
+ type WebAssemblyExports = Array<{
186
+ module: string;
187
+ name: string;
188
+ kind: string;
189
+ }>;
190
+ interface CCallOpts {
191
+ async?: boolean;
192
+ }
193
+ class WasmOffsetConverter {
194
+ constructor(wasmBytes: ArrayBuffer, wasmModule: WebAssembly.Module);
195
+ convert(funcidx: number, offset: number): number;
196
+ getIndex(offset: number): number;
197
+ isSameFunc(offset1: number, offset2: number): boolean;
198
+ getName(offset: number): string;
199
+ }
200
+ }
201
+ interface SourceMapData {
202
+ version: number;
203
+ sources: string[];
204
+ names: string[];
205
+ mappings: string;
206
+ }
207
+ /** @private */
208
+ interface QuickJSEmscriptenExtensions {
209
+ mock?: boolean;
210
+ removeRunDependency?(name: string): void;
211
+ receiveSourceMapJSON?(data: SourceMapData): void;
212
+ WasmOffsetConverter?: typeof Emscripten.WasmOffsetConverter;
213
+ existingWasmOffsetConverter?: Emscripten.WasmOffsetConverter;
214
+ receiveWasmOffsetConverter?(bytes: ArrayBuffer, mod: WebAssembly.Module): void;
215
+ getWasmMemory?(): WebAssembly.Memory;
216
+ }
217
+ /**
218
+ * This structure is defined by Emscripten.
219
+ * It's possible to provide these parameters to an emscripten module loader.
220
+ * See [the Emscripten Module API reference](https://emscripten.org/docs/api_reference/module.html).
221
+ */
222
+ interface EmscriptenModuleLoaderOptions {
223
+ /**
224
+ * If set, this method will be called when the runtime needs to load a file,
225
+ * such as a .wasm WebAssembly file, .mem memory init file, or a file
226
+ * generated by the file packager.
227
+ *
228
+ * The function receives two parameters:
229
+ *
230
+ * - `fileName`, the relative path to the file as configured in build
231
+ * process, eg `"emscripten-module.wasm"`.
232
+ * - `prefix` (path to the main JavaScript file’s directory). This may be `''`
233
+ * (empty string) in some cases if the Emscripten Javascript code can't locate
234
+ * itself. Try logging it in your environment.
235
+ *
236
+ * It should return the actual URI or path to the requested file.
237
+ *
238
+ * This lets you host file packages on a different location than the directory
239
+ * of the JavaScript file (which is the default expectation), for example if
240
+ * you want to host them on a CDN.
241
+ */
242
+ locateFile?(fileName: "emscripten-module.wasm" | "emscripten-module.wasm.map" | string,
243
+ /** Often `''` (empty string) */
244
+ prefix: string): string;
245
+ /** Compile this to WebAssembly.Module */
246
+ wasmBinary?: ArrayBuffer;
247
+ /** If provided, use this WebAssembly.Memory instead of an automatically created one. */
248
+ wasmMemory?: WebAssembly.Memory;
249
+ /** Create an instance of the WASM module, call onSuccess(instance), then return instance.exports */
250
+ instantiateWasm?(imports: WebAssembly.Imports, onSuccess: (instance: WebAssembly.Instance) => void): WebAssembly.Exports | Promise<WebAssembly.Exports>;
251
+ /** Called by emscripten as dependencies blocking initialization are added or fulfilled. May only be called in debug builds. */
252
+ monitorRunDependencies?(left: number): void;
253
+ /**
254
+ * Emscripten may mutate the loader options object to contain this function.
255
+ * It's added in our --pre-js / pre.js file, and used by custom variant loaders.
256
+ * @private
257
+ */
258
+ quickjsEmscriptenInit?(log: typeof console.log): QuickJSEmscriptenExtensions;
259
+ }
260
+ /**
261
+ * Typings for the features we use to interface with our Emscripten build of
262
+ * QuickJS.
263
+ */
264
+ interface EmscriptenModule extends EmscriptenModuleLoaderOptions {
265
+ /**
266
+ * Write JS `str` to HeapChar pointer.
267
+ * https://emscripten.org/docs/api_reference/preamble.js.html#stringToUTF8
268
+ */
269
+ stringToUTF8(str: string, outPtr: OwnedHeapCharPointer, maxBytesToRead?: number): void;
270
+ /**
271
+ * HeapChar to JS string.
272
+ * https://emscripten.org/docs/api_reference/preamble.js.html#UTF8ToString
273
+ */
274
+ UTF8ToString(ptr: BorrowedHeapCharPointer, maxBytesToRead?: number): string;
275
+ lengthBytesUTF8(str: string): number;
276
+ _malloc(size: number): number;
277
+ _free(ptr: number): void;
278
+ cwrap(ident: string, returnType: Emscripten.ValueType | null, argTypes: Emscripten.ValueType[], opts?: Emscripten.CCallOpts): (...args: any[]) => any;
279
+ HEAP8: Int8Array;
280
+ HEAP16: Int16Array;
281
+ HEAP32: Int32Array;
282
+ HEAPU8: Uint8Array;
283
+ HEAPU16: Uint16Array;
284
+ HEAPU32: Uint32Array;
285
+ HEAPF32: Float32Array;
286
+ HEAPF64: Float64Array;
287
+ TOTAL_STACK: number;
288
+ TOTAL_MEMORY: number;
289
+ FAST_MEMORY: number;
290
+ }
291
+ declare const _AsyncifySleepReturnValue: unique symbol;
292
+ /** @private */
293
+ type AsyncifySleepResult<T> = T & typeof _AsyncifySleepReturnValue;
294
+ /**
295
+ * Allows us to optionally suspend the Emscripten runtime to wait for a promise.
296
+ * https://emscripten.org/docs/porting/asyncify.html#ways-to-use-async-apis-in-older-engines
297
+ * ```
298
+ * EM_JS(int, do_fetch, (), {
299
+ * return Asyncify.handleSleep(function (wakeUp) {
300
+ * out("waiting for a fetch");
301
+ * fetch("a.html").then(function (response) {
302
+ * out("got the fetch response");
303
+ * // (normally you would do something with the fetch here)
304
+ * wakeUp(42);
305
+ * });
306
+ * });
307
+ * });
308
+ * ```
309
+ * @private
310
+ */
311
+ interface Asyncify {
312
+ handleSleep<T>(maybeAsyncFn: (wakeUp: (result: T) => void) => void): AsyncifySleepResult<T>;
313
+ }
314
+ /**
315
+ * @private
316
+ */
317
+ interface EmscriptenModuleCallbacks {
318
+ callFunction: (asyncify: Asyncify | undefined, ctx: JSContextPointer, this_ptr: JSValueConstPointer, argc: number, argv: JSValueConstPointer, fn_id: number) => JSValuePointer | AsyncifySleepResult<JSValuePointer>;
319
+ loadModuleSource: (asyncify: Asyncify | undefined, rt: JSRuntimePointer, ctx: JSContextPointer, module_name: string) => BorrowedHeapCharPointer | AsyncifySleepResult<BorrowedHeapCharPointer>;
320
+ normalizeModule: (asyncify: Asyncify | undefined, rt: JSRuntimePointer, ctx: JSContextPointer, module_base_name: string, module_name: string) => BorrowedHeapCharPointer | AsyncifySleepResult<BorrowedHeapCharPointer>;
321
+ shouldInterrupt: (asyncify: Asyncify | undefined, rt: JSRuntimePointer) => 0 | 1 | AsyncifySleepResult<0 | 1>;
322
+ }
323
+ interface QuickJSEmscriptenModule extends EmscriptenModule {
324
+ type: "sync";
325
+ callbacks: EmscriptenModuleCallbacks;
326
+ }
327
+ interface QuickJSAsyncEmscriptenModule extends EmscriptenModule {
328
+ /** @todo Implement this field */
329
+ type: "async";
330
+ callbacks: EmscriptenModuleCallbacks;
331
+ }
332
+ type EitherModule = QuickJSEmscriptenModule | QuickJSAsyncEmscriptenModule;
333
+ interface EmscriptenModuleLoader<T extends EmscriptenModule> {
334
+ (options?: EmscriptenModuleLoaderOptions): Promise<T>;
335
+ }
336
+
337
+ /**
338
+ * Low-level FFI bindings to QuickJS's Emscripten module.
339
+ * See instead {@link QuickJSContext}, the public Javascript interface exposed by this
340
+ * library.
341
+ *
342
+ * @unstable The FFI interface is considered private and may change.
343
+ */
344
+ interface QuickJSFFI {
345
+ /** Set at compile time. */
346
+ readonly DEBUG: boolean;
347
+ QTS_Throw: (ctx: JSContextPointer, error: JSValuePointer | JSValueConstPointer) => JSValuePointer;
348
+ QTS_NewError: (ctx: JSContextPointer) => JSValuePointer;
349
+ QTS_RuntimeSetMemoryLimit: (rt: JSRuntimePointer, limit: number) => void;
350
+ QTS_RuntimeComputeMemoryUsage: (rt: JSRuntimePointer, ctx: JSContextPointer) => JSValuePointer;
351
+ QTS_RuntimeDumpMemoryUsage: (rt: JSRuntimePointer) => OwnedHeapCharPointer;
352
+ QTS_RecoverableLeakCheck: () => number;
353
+ QTS_BuildIsSanitizeLeak: () => number;
354
+ QTS_RuntimeSetMaxStackSize: (rt: JSRuntimePointer, stack_size: number) => void;
355
+ QTS_GetUndefined: () => JSValueConstPointer;
356
+ QTS_GetNull: () => JSValueConstPointer;
357
+ QTS_GetFalse: () => JSValueConstPointer;
358
+ QTS_GetTrue: () => JSValueConstPointer;
359
+ QTS_NewRuntime: () => JSRuntimePointer;
360
+ QTS_FreeRuntime: (rt: JSRuntimePointer) => void;
361
+ QTS_NewContext: (rt: JSRuntimePointer, intrinsics: IntrinsicsFlags) => JSContextPointer;
362
+ QTS_FreeContext: (ctx: JSContextPointer) => void;
363
+ QTS_FreeValuePointer: (ctx: JSContextPointer, value: JSValuePointer) => void;
364
+ QTS_FreeValuePointerRuntime: (rt: JSRuntimePointer, value: JSValuePointer) => void;
365
+ QTS_FreeVoidPointer: (ctx: JSContextPointer, ptr: JSVoidPointer) => void;
366
+ QTS_FreeCString: (ctx: JSContextPointer, str: JSBorrowedCharPointer) => void;
367
+ QTS_DupValuePointer: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
368
+ QTS_NewObject: (ctx: JSContextPointer) => JSValuePointer;
369
+ QTS_NewObjectProto: (ctx: JSContextPointer, proto: JSValuePointer | JSValueConstPointer) => JSValuePointer;
370
+ QTS_NewArray: (ctx: JSContextPointer) => JSValuePointer;
371
+ QTS_NewArrayBuffer: (ctx: JSContextPointer, buffer: JSVoidPointer, length: number) => JSValuePointer;
372
+ QTS_NewFloat64: (ctx: JSContextPointer, num: number) => JSValuePointer;
373
+ QTS_GetFloat64: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
374
+ QTS_NewString: (ctx: JSContextPointer, string: BorrowedHeapCharPointer) => JSValuePointer;
375
+ QTS_GetString: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
376
+ QTS_GetArrayBuffer: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSVoidPointer;
377
+ QTS_GetArrayBufferLength: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => number;
378
+ QTS_NewSymbol: (ctx: JSContextPointer, description: BorrowedHeapCharPointer, isGlobal: number) => JSValuePointer;
379
+ QTS_GetSymbolDescriptionOrKey: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
380
+ QTS_IsGlobalSymbol: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
381
+ QTS_IsJobPending: (rt: JSRuntimePointer) => number;
382
+ QTS_ExecutePendingJob: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer;
383
+ QTS_GetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer) => JSValuePointer;
384
+ QTS_GetPropNumber: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: number) => JSValuePointer;
385
+ QTS_SetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer) => void;
386
+ QTS_DefineProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer, get: JSValuePointer | JSValueConstPointer, set: JSValuePointer | JSValueConstPointer, configurable: boolean, enumerable: boolean, has_value: boolean) => void;
387
+ QTS_GetOwnPropertyNames: (ctx: JSContextPointer, out_ptrs: JSValuePointerPointerPointer, out_len: UInt32Pointer, obj: JSValuePointer | JSValueConstPointer, flags: number) => JSValuePointer;
388
+ QTS_Call: (ctx: JSContextPointer, func_obj: JSValuePointer | JSValueConstPointer, this_obj: JSValuePointer | JSValueConstPointer, argc: number, argv_ptrs: JSValueConstPointerPointer) => JSValuePointer;
389
+ QTS_ResolveException: (ctx: JSContextPointer, maybe_exception: JSValuePointer) => JSValuePointer;
390
+ QTS_Dump: (ctx: JSContextPointer, obj: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
391
+ QTS_Eval: (ctx: JSContextPointer, js_code: BorrowedHeapCharPointer, js_code_length: number, filename: string, detectModule: EvalDetectModule, evalFlags: EvalFlags) => JSValuePointer;
392
+ QTS_GetModuleNamespace: (ctx: JSContextPointer, module_func_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer;
393
+ QTS_Typeof: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => OwnedHeapCharPointer;
394
+ QTS_GetLength: (ctx: JSContextPointer, out_len: UInt32Pointer, value: JSValuePointer | JSValueConstPointer) => number;
395
+ QTS_IsEqual: (ctx: JSContextPointer, a: JSValuePointer | JSValueConstPointer, b: JSValuePointer | JSValueConstPointer, op: IsEqualOp) => number;
396
+ QTS_GetGlobalObject: (ctx: JSContextPointer) => JSValuePointer;
397
+ QTS_NewPromiseCapability: (ctx: JSContextPointer, resolve_funcs_out: JSValuePointerPointer) => JSValuePointer;
398
+ QTS_PromiseState: (ctx: JSContextPointer, promise: JSValuePointer | JSValueConstPointer) => JSPromiseStateEnum;
399
+ QTS_PromiseResult: (ctx: JSContextPointer, promise: JSValuePointer | JSValueConstPointer) => JSValuePointer;
400
+ QTS_TestStringArg: (string: string) => void;
401
+ QTS_GetDebugLogEnabled: (rt: JSRuntimePointer) => number;
402
+ QTS_SetDebugLogEnabled: (rt: JSRuntimePointer, is_enabled: number) => void;
403
+ QTS_BuildIsDebug: () => number;
404
+ QTS_BuildIsAsyncify: () => number;
405
+ QTS_NewFunction: (ctx: JSContextPointer, func_id: number, name: string) => JSValuePointer;
406
+ QTS_ArgvGetJSValueConstPointer: (argv: JSValuePointer | JSValueConstPointer, index: number) => JSValueConstPointer;
407
+ QTS_RuntimeEnableInterruptHandler: (rt: JSRuntimePointer) => void;
408
+ QTS_RuntimeDisableInterruptHandler: (rt: JSRuntimePointer) => void;
409
+ QTS_RuntimeEnableModuleLoader: (rt: JSRuntimePointer, use_custom_normalize: number) => void;
410
+ QTS_RuntimeDisableModuleLoader: (rt: JSRuntimePointer) => void;
411
+ QTS_bjson_encode: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
412
+ QTS_bjson_decode: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSValuePointer;
413
+ QTS_EvalFunction: (ctx: JSContextPointer, fun_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer;
414
+ QTS_EncodeBytecode: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
415
+ QTS_DecodeBytecode: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSValuePointer;
416
+ }
417
+
418
+ /**
419
+ * Low-level FFI bindings to QuickJS's Emscripten module.
420
+ * See instead {@link QuickJSContext}, the public Javascript interface exposed by this
421
+ * library.
422
+ *
423
+ * @unstable The FFI interface is considered private and may change.
424
+ */
425
+ interface QuickJSAsyncFFI {
426
+ /** Set at compile time. */
427
+ readonly DEBUG: boolean;
428
+ QTS_Throw: (ctx: JSContextPointer, error: JSValuePointer | JSValueConstPointer) => JSValuePointer;
429
+ QTS_NewError: (ctx: JSContextPointer) => JSValuePointer;
430
+ QTS_RuntimeSetMemoryLimit: (rt: JSRuntimePointer, limit: number) => void;
431
+ QTS_RuntimeComputeMemoryUsage: (rt: JSRuntimePointer, ctx: JSContextPointer) => JSValuePointer;
432
+ QTS_RuntimeDumpMemoryUsage: (rt: JSRuntimePointer) => OwnedHeapCharPointer;
433
+ QTS_RecoverableLeakCheck: () => number;
434
+ QTS_BuildIsSanitizeLeak: () => number;
435
+ QTS_RuntimeSetMaxStackSize: (rt: JSRuntimePointer, stack_size: number) => void;
436
+ QTS_GetUndefined: () => JSValueConstPointer;
437
+ QTS_GetNull: () => JSValueConstPointer;
438
+ QTS_GetFalse: () => JSValueConstPointer;
439
+ QTS_GetTrue: () => JSValueConstPointer;
440
+ QTS_NewRuntime: () => JSRuntimePointer;
441
+ QTS_FreeRuntime: (rt: JSRuntimePointer) => void;
442
+ QTS_NewContext: (rt: JSRuntimePointer, intrinsics: IntrinsicsFlags) => JSContextPointer;
443
+ QTS_FreeContext: (ctx: JSContextPointer) => void;
444
+ QTS_FreeValuePointer: (ctx: JSContextPointer, value: JSValuePointer) => void;
445
+ QTS_FreeValuePointerRuntime: (rt: JSRuntimePointer, value: JSValuePointer) => void;
446
+ QTS_FreeVoidPointer: (ctx: JSContextPointer, ptr: JSVoidPointer) => void;
447
+ QTS_FreeCString: (ctx: JSContextPointer, str: JSBorrowedCharPointer) => void;
448
+ QTS_DupValuePointer: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
449
+ QTS_NewObject: (ctx: JSContextPointer) => JSValuePointer;
450
+ QTS_NewObjectProto: (ctx: JSContextPointer, proto: JSValuePointer | JSValueConstPointer) => JSValuePointer;
451
+ QTS_NewArray: (ctx: JSContextPointer) => JSValuePointer;
452
+ QTS_NewArrayBuffer: (ctx: JSContextPointer, buffer: JSVoidPointer, length: number) => JSValuePointer;
453
+ QTS_NewFloat64: (ctx: JSContextPointer, num: number) => JSValuePointer;
454
+ QTS_GetFloat64: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
455
+ QTS_NewString: (ctx: JSContextPointer, string: BorrowedHeapCharPointer) => JSValuePointer;
456
+ QTS_GetString: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
457
+ QTS_GetArrayBuffer: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSVoidPointer;
458
+ QTS_GetArrayBufferLength: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => number;
459
+ QTS_NewSymbol: (ctx: JSContextPointer, description: BorrowedHeapCharPointer, isGlobal: number) => JSValuePointer;
460
+ QTS_GetSymbolDescriptionOrKey: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
461
+ QTS_GetSymbolDescriptionOrKey_MaybeAsync: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer | Promise<JSBorrowedCharPointer>;
462
+ QTS_IsGlobalSymbol: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
463
+ QTS_IsJobPending: (rt: JSRuntimePointer) => number;
464
+ QTS_ExecutePendingJob: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer;
465
+ QTS_ExecutePendingJob_MaybeAsync: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer | Promise<JSValuePointer>;
466
+ QTS_GetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer) => JSValuePointer;
467
+ QTS_GetProp_MaybeAsync: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer) => JSValuePointer | Promise<JSValuePointer>;
468
+ QTS_GetPropNumber: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: number) => JSValuePointer;
469
+ QTS_GetPropNumber_MaybeAsync: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: number) => JSValuePointer | Promise<JSValuePointer>;
470
+ QTS_SetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer) => void;
471
+ QTS_SetProp_MaybeAsync: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer) => void | Promise<void>;
472
+ QTS_DefineProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer, get: JSValuePointer | JSValueConstPointer, set: JSValuePointer | JSValueConstPointer, configurable: boolean, enumerable: boolean, has_value: boolean) => void;
473
+ QTS_GetOwnPropertyNames: (ctx: JSContextPointer, out_ptrs: JSValuePointerPointerPointer, out_len: UInt32Pointer, obj: JSValuePointer | JSValueConstPointer, flags: number) => JSValuePointer;
474
+ QTS_GetOwnPropertyNames_MaybeAsync: (ctx: JSContextPointer, out_ptrs: JSValuePointerPointerPointer, out_len: UInt32Pointer, obj: JSValuePointer | JSValueConstPointer, flags: number) => JSValuePointer | Promise<JSValuePointer>;
475
+ QTS_Call: (ctx: JSContextPointer, func_obj: JSValuePointer | JSValueConstPointer, this_obj: JSValuePointer | JSValueConstPointer, argc: number, argv_ptrs: JSValueConstPointerPointer) => JSValuePointer;
476
+ QTS_Call_MaybeAsync: (ctx: JSContextPointer, func_obj: JSValuePointer | JSValueConstPointer, this_obj: JSValuePointer | JSValueConstPointer, argc: number, argv_ptrs: JSValueConstPointerPointer) => JSValuePointer | Promise<JSValuePointer>;
477
+ QTS_ResolveException: (ctx: JSContextPointer, maybe_exception: JSValuePointer) => JSValuePointer;
478
+ QTS_Dump: (ctx: JSContextPointer, obj: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
479
+ QTS_Dump_MaybeAsync: (ctx: JSContextPointer, obj: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer | Promise<JSBorrowedCharPointer>;
480
+ QTS_Eval: (ctx: JSContextPointer, js_code: BorrowedHeapCharPointer, js_code_length: number, filename: string, detectModule: EvalDetectModule, evalFlags: EvalFlags) => JSValuePointer;
481
+ QTS_Eval_MaybeAsync: (ctx: JSContextPointer, js_code: BorrowedHeapCharPointer, js_code_length: number, filename: string, detectModule: EvalDetectModule, evalFlags: EvalFlags) => JSValuePointer | Promise<JSValuePointer>;
482
+ QTS_GetModuleNamespace: (ctx: JSContextPointer, module_func_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer;
483
+ QTS_Typeof: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => OwnedHeapCharPointer;
484
+ QTS_GetLength: (ctx: JSContextPointer, out_len: UInt32Pointer, value: JSValuePointer | JSValueConstPointer) => number;
485
+ QTS_IsEqual: (ctx: JSContextPointer, a: JSValuePointer | JSValueConstPointer, b: JSValuePointer | JSValueConstPointer, op: IsEqualOp) => number;
486
+ QTS_GetGlobalObject: (ctx: JSContextPointer) => JSValuePointer;
487
+ QTS_NewPromiseCapability: (ctx: JSContextPointer, resolve_funcs_out: JSValuePointerPointer) => JSValuePointer;
488
+ QTS_PromiseState: (ctx: JSContextPointer, promise: JSValuePointer | JSValueConstPointer) => JSPromiseStateEnum;
489
+ QTS_PromiseResult: (ctx: JSContextPointer, promise: JSValuePointer | JSValueConstPointer) => JSValuePointer;
490
+ QTS_TestStringArg: (string: string) => void;
491
+ QTS_GetDebugLogEnabled: (rt: JSRuntimePointer) => number;
492
+ QTS_SetDebugLogEnabled: (rt: JSRuntimePointer, is_enabled: number) => void;
493
+ QTS_BuildIsDebug: () => number;
494
+ QTS_BuildIsAsyncify: () => number;
495
+ QTS_NewFunction: (ctx: JSContextPointer, func_id: number, name: string) => JSValuePointer;
496
+ QTS_ArgvGetJSValueConstPointer: (argv: JSValuePointer | JSValueConstPointer, index: number) => JSValueConstPointer;
497
+ QTS_RuntimeEnableInterruptHandler: (rt: JSRuntimePointer) => void;
498
+ QTS_RuntimeDisableInterruptHandler: (rt: JSRuntimePointer) => void;
499
+ QTS_RuntimeEnableModuleLoader: (rt: JSRuntimePointer, use_custom_normalize: number) => void;
500
+ QTS_RuntimeDisableModuleLoader: (rt: JSRuntimePointer) => void;
501
+ QTS_bjson_encode: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
502
+ QTS_bjson_decode: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSValuePointer;
503
+ QTS_EvalFunction: (ctx: JSContextPointer, fun_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer;
504
+ QTS_EvalFunction_MaybeAsync: (ctx: JSContextPointer, fun_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer | Promise<JSValuePointer>;
505
+ QTS_EncodeBytecode: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
506
+ QTS_DecodeBytecode: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSValuePointer;
507
+ }
508
+
509
+ type EmscriptenImport<T extends EmscriptenModule> = EmscriptenModuleLoader<T> | {
510
+ default: EmscriptenModuleLoader<T>;
511
+ } | {
512
+ default: {
513
+ default: EmscriptenModuleLoader<T>;
514
+ };
515
+ };
516
+ /**
517
+ * A standard (sync) build variant.
518
+ *
519
+ * quickjs-emscripten provides multiple build variants of the core WebAssembly
520
+ * module. These variants are each intended for a different use case.
521
+ *
522
+ * To create an instance of the library using a specific build variant, pass the
523
+ * build variant to {@link newQuickJSWASMModule} or {@link newQuickJSAsyncWASMModule}.
524
+ */
525
+ interface QuickJSSyncVariant {
526
+ readonly type: "sync";
527
+ readonly importFFI: () => Promise<new (module: QuickJSEmscriptenModule) => QuickJSFFI>;
528
+ readonly importModuleLoader: () => Promise<EmscriptenImport<QuickJSEmscriptenModule>>;
529
+ }
530
+ /**
531
+ * An ASYNCIFY build variant.
532
+ *
533
+ * quickjs-emscripten provides multiple build variants of the core WebAssembly
534
+ * module. These variants are each intended for a different use case.
535
+ *
536
+ * To create an instance of the library using a specific build variant, pass the
537
+ * build variant to {@link newQuickJSWASMModule} or {@link newQuickJSAsyncWASMModule}.
538
+ */
539
+ interface QuickJSAsyncVariant {
540
+ readonly type: "async";
541
+ readonly importFFI: () => Promise<new (module: QuickJSAsyncEmscriptenModule) => QuickJSAsyncFFI>;
542
+ readonly importModuleLoader: () => Promise<EmscriptenImport<QuickJSAsyncEmscriptenModule>>;
543
+ }
544
+ type QuickJSVariant = QuickJSSyncVariant | QuickJSAsyncVariant;
545
+ type EitherFFI = QuickJSFFI | QuickJSAsyncFFI;
546
+
547
+ export { type Asyncify, type AsyncifySleepResult, type BorrowedHeapCharPointer, type EitherFFI, type EitherModule, type EmscriptenModule, type EmscriptenModuleCallbacks, type EmscriptenModuleLoader, type EmscriptenModuleLoaderOptions, type EvalDetectModule, EvalFlags, GetOwnPropertyNamesFlags, IntrinsicsFlags, IsEqualOp, type JSBorrowedCharPointer, type JSContextPointer, type JSContextPointerPointer, type JSModuleDefPointer, JSPromiseStateEnum, type JSRuntimePointer, type JSValueConstPointer, type JSValueConstPointerPointer, type JSValuePointer, type JSValuePointerPointer, type JSValuePointerPointerPointer, type JSVoidPointer, type OwnedHeapCharPointer, type QTS_C_To_HostCallbackFuncPointer, type QTS_C_To_HostInterruptFuncPointer, type QTS_C_To_HostLoadModuleFuncPointer, type QuickJSAsyncEmscriptenModule, type QuickJSAsyncFFI, type QuickJSAsyncVariant, type QuickJSEmscriptenExtensions, type QuickJSEmscriptenModule, type QuickJSFFI, type QuickJSSyncVariant, type QuickJSVariant, type SourceMapData, type UInt32Pointer, assertSync };
@@ -0,0 +1,547 @@
1
+ /**
2
+ * C pointer to type `CType`. Pointer types are used internally for FFI, but
3
+ * are not intended for external use.
4
+ *
5
+ * @unstable This type is considered private and may change.
6
+ */
7
+ type Pointer<CType extends string> = number & {
8
+ ctype: CType;
9
+ };
10
+ type Brand<T, B> = T & {
11
+ brand: B;
12
+ };
13
+ /**
14
+ * `JSRuntime*`.
15
+ */
16
+ type JSRuntimePointer = Pointer<"JSRuntime">;
17
+ /**
18
+ * `JSContext*`.
19
+ */
20
+ type JSContextPointer = Pointer<"JSContext">;
21
+ /**
22
+ * `JSContext**`. Used internally for execute pending jobs.
23
+ */
24
+ type JSContextPointerPointer = Pointer<"JSContext">;
25
+ /**
26
+ * `JSModuleDef*`.
27
+ */
28
+ type JSModuleDefPointer = Pointer<"JSModuleDef">;
29
+ /**
30
+ * `JSValue*`.
31
+ * See {@link JSValue}.
32
+ */
33
+ type JSValuePointer = Pointer<"JSValue">;
34
+ /**
35
+ * `JSValueConst*
36
+ * See {@link JSValueConst} and {@link StaticJSValue}.
37
+ */
38
+ type JSValueConstPointer = Pointer<"JSValueConst">;
39
+ /**
40
+ * Used internally for Javascript-to-C function calls.
41
+ */
42
+ type JSValuePointerPointer = Pointer<"JSValue[]">;
43
+ /**
44
+ * Used internally for Javascript-to-C function calls.
45
+ */
46
+ type JSValuePointerPointerPointer = Pointer<"*JSValue[]">;
47
+ /**
48
+ * Used internally for Javascript-to-C function calls.
49
+ */
50
+ type JSValueConstPointerPointer = Pointer<"JSValueConst[]">;
51
+ /**
52
+ * Used internally for C-to-Javascript function calls.
53
+ */
54
+ /**
55
+ * Used internally for C-to-Javascript function calls.
56
+ */
57
+ type QTS_C_To_HostCallbackFuncPointer = Pointer<"C_To_HostCallbackFunc">;
58
+ /**
59
+ * Used internally for C-to-Javascript interrupt handlers.
60
+ */
61
+ type QTS_C_To_HostInterruptFuncPointer = Pointer<"C_To_HostInterruptFunc">;
62
+ /**
63
+ * Used internally for C-to-Javascript module loading.
64
+ */
65
+ type QTS_C_To_HostLoadModuleFuncPointer = Pointer<"C_To_HostLoadModuleFunc">;
66
+ /**
67
+ * Used internally for Javascript-to-C calls that may contain strings too large
68
+ * for the Emscripten stack.
69
+ */
70
+ type BorrowedHeapCharPointer = Pointer<"const char" | "char" | "js const char">;
71
+ /**
72
+ * Used internally for Javascript-to-C calls that may contain strings too large
73
+ * for the Emscripten stack.
74
+ */
75
+ type OwnedHeapCharPointer = Pointer<"char">;
76
+ /**
77
+ * Used internally for Javascript-to-C calls that may contain strings too large
78
+ * for the Emscripten stack.
79
+ */
80
+ type JSBorrowedCharPointer = Pointer<"js const char">;
81
+ /**
82
+ * Opaque pointer that was allocated by js_malloc.
83
+ */
84
+ type JSVoidPointer = Pointer<any>;
85
+ type UInt32Pointer = Pointer<"uint32_t">;
86
+ /**
87
+ * @private
88
+ */
89
+ type EvalDetectModule = Brand<number, "EvalDetectModule">;
90
+ declare function assertSync<Args extends any[], R>(fn: (...args: Args) => R): (...args: Args) => R;
91
+ /**
92
+ * @private
93
+ */
94
+ type EvalFlags = Brand<number, "EvalFlags">;
95
+ /** Bitfield options for JS_Eval() C function. */
96
+ declare const EvalFlags: {
97
+ /** global code (default) */
98
+ readonly JS_EVAL_TYPE_GLOBAL: number;
99
+ /** module code */
100
+ readonly JS_EVAL_TYPE_MODULE: number;
101
+ /** direct call (internal use) */
102
+ readonly JS_EVAL_TYPE_DIRECT: number;
103
+ /** indirect call (internal use) */
104
+ readonly JS_EVAL_TYPE_INDIRECT: number;
105
+ readonly JS_EVAL_TYPE_MASK: number;
106
+ /** force 'strict' mode */
107
+ readonly JS_EVAL_FLAG_STRICT: number;
108
+ /** force 'strip' mode */
109
+ readonly JS_EVAL_FLAG_STRIP: number;
110
+ /**
111
+ * compile but do not run. The result is an object with a
112
+ * JS_TAG_FUNCTION_BYTECODE or JS_TAG_MODULE tag. It can be executed
113
+ * with JS_EvalFunction().
114
+ */
115
+ readonly JS_EVAL_FLAG_COMPILE_ONLY: number;
116
+ /** don't include the stack frames before this eval in the Error() backtraces */
117
+ readonly JS_EVAL_FLAG_BACKTRACE_BARRIER: number;
118
+ };
119
+ /**
120
+ * @private
121
+ */
122
+ type IntrinsicsFlags = Brand<number, "IntrinsicsFlags">;
123
+ /** Bitfield options for QTS_NewContext intrinsics */
124
+ declare const IntrinsicsFlags: {
125
+ readonly BaseObjects: number;
126
+ readonly Date: number;
127
+ readonly Eval: number;
128
+ readonly StringNormalize: number;
129
+ readonly RegExp: number;
130
+ readonly RegExpCompiler: number;
131
+ readonly JSON: number;
132
+ readonly Proxy: number;
133
+ readonly MapSet: number;
134
+ readonly TypedArrays: number;
135
+ readonly Promise: number;
136
+ readonly BigInt: number;
137
+ readonly BigFloat: number;
138
+ readonly BigDecimal: number;
139
+ readonly OperatorOverloading: number;
140
+ readonly BignumExt: number;
141
+ };
142
+ /**
143
+ * State of a promise.
144
+ */
145
+ type JSPromiseStateEnum = Brand<(typeof JSPromiseStateEnum)[keyof typeof JSPromiseStateEnum], "JSPromiseStateEnum">;
146
+ declare const JSPromiseStateEnum: {
147
+ readonly Pending: 0;
148
+ readonly Fulfilled: 1;
149
+ readonly Rejected: 2;
150
+ };
151
+ /**
152
+ * @private
153
+ */
154
+ type GetOwnPropertyNamesFlags = Brand<number, "GetOwnPropertyNamesFlags">;
155
+ /** Bitfield options for QTS_GetOwnPropertyNames */
156
+ declare const GetOwnPropertyNamesFlags: {
157
+ JS_GPN_STRING_MASK: number;
158
+ JS_GPN_SYMBOL_MASK: number;
159
+ JS_GPN_PRIVATE_MASK: number;
160
+ JS_GPN_ENUM_ONLY: number;
161
+ JS_GPN_SET_ENUM: number;
162
+ QTS_GPN_NUMBER_MASK: number;
163
+ QTS_STANDARD_COMPLIANT_NUMBER: number;
164
+ };
165
+ /**
166
+ * @private
167
+ */
168
+ type IsEqualOp = Brand<number, "IsEqualOp">;
169
+ declare const IsEqualOp: {
170
+ IsStrictlyEqual: IsEqualOp;
171
+ IsSameValue: IsEqualOp;
172
+ IsSameValueZero: IsEqualOp;
173
+ };
174
+
175
+ declare namespace Emscripten {
176
+ interface FileSystemType {
177
+ }
178
+ type EnvironmentType = "WEB" | "NODE" | "SHELL" | "WORKER";
179
+ type ValueType = "number" | "string" | "array" | "boolean";
180
+ type TypeCompatibleWithC = number | string | any[] | boolean;
181
+ type WebAssemblyImports = Array<{
182
+ name: string;
183
+ kind: string;
184
+ }>;
185
+ type WebAssemblyExports = Array<{
186
+ module: string;
187
+ name: string;
188
+ kind: string;
189
+ }>;
190
+ interface CCallOpts {
191
+ async?: boolean;
192
+ }
193
+ class WasmOffsetConverter {
194
+ constructor(wasmBytes: ArrayBuffer, wasmModule: WebAssembly.Module);
195
+ convert(funcidx: number, offset: number): number;
196
+ getIndex(offset: number): number;
197
+ isSameFunc(offset1: number, offset2: number): boolean;
198
+ getName(offset: number): string;
199
+ }
200
+ }
201
+ interface SourceMapData {
202
+ version: number;
203
+ sources: string[];
204
+ names: string[];
205
+ mappings: string;
206
+ }
207
+ /** @private */
208
+ interface QuickJSEmscriptenExtensions {
209
+ mock?: boolean;
210
+ removeRunDependency?(name: string): void;
211
+ receiveSourceMapJSON?(data: SourceMapData): void;
212
+ WasmOffsetConverter?: typeof Emscripten.WasmOffsetConverter;
213
+ existingWasmOffsetConverter?: Emscripten.WasmOffsetConverter;
214
+ receiveWasmOffsetConverter?(bytes: ArrayBuffer, mod: WebAssembly.Module): void;
215
+ getWasmMemory?(): WebAssembly.Memory;
216
+ }
217
+ /**
218
+ * This structure is defined by Emscripten.
219
+ * It's possible to provide these parameters to an emscripten module loader.
220
+ * See [the Emscripten Module API reference](https://emscripten.org/docs/api_reference/module.html).
221
+ */
222
+ interface EmscriptenModuleLoaderOptions {
223
+ /**
224
+ * If set, this method will be called when the runtime needs to load a file,
225
+ * such as a .wasm WebAssembly file, .mem memory init file, or a file
226
+ * generated by the file packager.
227
+ *
228
+ * The function receives two parameters:
229
+ *
230
+ * - `fileName`, the relative path to the file as configured in build
231
+ * process, eg `"emscripten-module.wasm"`.
232
+ * - `prefix` (path to the main JavaScript file’s directory). This may be `''`
233
+ * (empty string) in some cases if the Emscripten Javascript code can't locate
234
+ * itself. Try logging it in your environment.
235
+ *
236
+ * It should return the actual URI or path to the requested file.
237
+ *
238
+ * This lets you host file packages on a different location than the directory
239
+ * of the JavaScript file (which is the default expectation), for example if
240
+ * you want to host them on a CDN.
241
+ */
242
+ locateFile?(fileName: "emscripten-module.wasm" | "emscripten-module.wasm.map" | string,
243
+ /** Often `''` (empty string) */
244
+ prefix: string): string;
245
+ /** Compile this to WebAssembly.Module */
246
+ wasmBinary?: ArrayBuffer;
247
+ /** If provided, use this WebAssembly.Memory instead of an automatically created one. */
248
+ wasmMemory?: WebAssembly.Memory;
249
+ /** Create an instance of the WASM module, call onSuccess(instance), then return instance.exports */
250
+ instantiateWasm?(imports: WebAssembly.Imports, onSuccess: (instance: WebAssembly.Instance) => void): WebAssembly.Exports | Promise<WebAssembly.Exports>;
251
+ /** Called by emscripten as dependencies blocking initialization are added or fulfilled. May only be called in debug builds. */
252
+ monitorRunDependencies?(left: number): void;
253
+ /**
254
+ * Emscripten may mutate the loader options object to contain this function.
255
+ * It's added in our --pre-js / pre.js file, and used by custom variant loaders.
256
+ * @private
257
+ */
258
+ quickjsEmscriptenInit?(log: typeof console.log): QuickJSEmscriptenExtensions;
259
+ }
260
+ /**
261
+ * Typings for the features we use to interface with our Emscripten build of
262
+ * QuickJS.
263
+ */
264
+ interface EmscriptenModule extends EmscriptenModuleLoaderOptions {
265
+ /**
266
+ * Write JS `str` to HeapChar pointer.
267
+ * https://emscripten.org/docs/api_reference/preamble.js.html#stringToUTF8
268
+ */
269
+ stringToUTF8(str: string, outPtr: OwnedHeapCharPointer, maxBytesToRead?: number): void;
270
+ /**
271
+ * HeapChar to JS string.
272
+ * https://emscripten.org/docs/api_reference/preamble.js.html#UTF8ToString
273
+ */
274
+ UTF8ToString(ptr: BorrowedHeapCharPointer, maxBytesToRead?: number): string;
275
+ lengthBytesUTF8(str: string): number;
276
+ _malloc(size: number): number;
277
+ _free(ptr: number): void;
278
+ cwrap(ident: string, returnType: Emscripten.ValueType | null, argTypes: Emscripten.ValueType[], opts?: Emscripten.CCallOpts): (...args: any[]) => any;
279
+ HEAP8: Int8Array;
280
+ HEAP16: Int16Array;
281
+ HEAP32: Int32Array;
282
+ HEAPU8: Uint8Array;
283
+ HEAPU16: Uint16Array;
284
+ HEAPU32: Uint32Array;
285
+ HEAPF32: Float32Array;
286
+ HEAPF64: Float64Array;
287
+ TOTAL_STACK: number;
288
+ TOTAL_MEMORY: number;
289
+ FAST_MEMORY: number;
290
+ }
291
+ declare const _AsyncifySleepReturnValue: unique symbol;
292
+ /** @private */
293
+ type AsyncifySleepResult<T> = T & typeof _AsyncifySleepReturnValue;
294
+ /**
295
+ * Allows us to optionally suspend the Emscripten runtime to wait for a promise.
296
+ * https://emscripten.org/docs/porting/asyncify.html#ways-to-use-async-apis-in-older-engines
297
+ * ```
298
+ * EM_JS(int, do_fetch, (), {
299
+ * return Asyncify.handleSleep(function (wakeUp) {
300
+ * out("waiting for a fetch");
301
+ * fetch("a.html").then(function (response) {
302
+ * out("got the fetch response");
303
+ * // (normally you would do something with the fetch here)
304
+ * wakeUp(42);
305
+ * });
306
+ * });
307
+ * });
308
+ * ```
309
+ * @private
310
+ */
311
+ interface Asyncify {
312
+ handleSleep<T>(maybeAsyncFn: (wakeUp: (result: T) => void) => void): AsyncifySleepResult<T>;
313
+ }
314
+ /**
315
+ * @private
316
+ */
317
+ interface EmscriptenModuleCallbacks {
318
+ callFunction: (asyncify: Asyncify | undefined, ctx: JSContextPointer, this_ptr: JSValueConstPointer, argc: number, argv: JSValueConstPointer, fn_id: number) => JSValuePointer | AsyncifySleepResult<JSValuePointer>;
319
+ loadModuleSource: (asyncify: Asyncify | undefined, rt: JSRuntimePointer, ctx: JSContextPointer, module_name: string) => BorrowedHeapCharPointer | AsyncifySleepResult<BorrowedHeapCharPointer>;
320
+ normalizeModule: (asyncify: Asyncify | undefined, rt: JSRuntimePointer, ctx: JSContextPointer, module_base_name: string, module_name: string) => BorrowedHeapCharPointer | AsyncifySleepResult<BorrowedHeapCharPointer>;
321
+ shouldInterrupt: (asyncify: Asyncify | undefined, rt: JSRuntimePointer) => 0 | 1 | AsyncifySleepResult<0 | 1>;
322
+ }
323
+ interface QuickJSEmscriptenModule extends EmscriptenModule {
324
+ type: "sync";
325
+ callbacks: EmscriptenModuleCallbacks;
326
+ }
327
+ interface QuickJSAsyncEmscriptenModule extends EmscriptenModule {
328
+ /** @todo Implement this field */
329
+ type: "async";
330
+ callbacks: EmscriptenModuleCallbacks;
331
+ }
332
+ type EitherModule = QuickJSEmscriptenModule | QuickJSAsyncEmscriptenModule;
333
+ interface EmscriptenModuleLoader<T extends EmscriptenModule> {
334
+ (options?: EmscriptenModuleLoaderOptions): Promise<T>;
335
+ }
336
+
337
+ /**
338
+ * Low-level FFI bindings to QuickJS's Emscripten module.
339
+ * See instead {@link QuickJSContext}, the public Javascript interface exposed by this
340
+ * library.
341
+ *
342
+ * @unstable The FFI interface is considered private and may change.
343
+ */
344
+ interface QuickJSFFI {
345
+ /** Set at compile time. */
346
+ readonly DEBUG: boolean;
347
+ QTS_Throw: (ctx: JSContextPointer, error: JSValuePointer | JSValueConstPointer) => JSValuePointer;
348
+ QTS_NewError: (ctx: JSContextPointer) => JSValuePointer;
349
+ QTS_RuntimeSetMemoryLimit: (rt: JSRuntimePointer, limit: number) => void;
350
+ QTS_RuntimeComputeMemoryUsage: (rt: JSRuntimePointer, ctx: JSContextPointer) => JSValuePointer;
351
+ QTS_RuntimeDumpMemoryUsage: (rt: JSRuntimePointer) => OwnedHeapCharPointer;
352
+ QTS_RecoverableLeakCheck: () => number;
353
+ QTS_BuildIsSanitizeLeak: () => number;
354
+ QTS_RuntimeSetMaxStackSize: (rt: JSRuntimePointer, stack_size: number) => void;
355
+ QTS_GetUndefined: () => JSValueConstPointer;
356
+ QTS_GetNull: () => JSValueConstPointer;
357
+ QTS_GetFalse: () => JSValueConstPointer;
358
+ QTS_GetTrue: () => JSValueConstPointer;
359
+ QTS_NewRuntime: () => JSRuntimePointer;
360
+ QTS_FreeRuntime: (rt: JSRuntimePointer) => void;
361
+ QTS_NewContext: (rt: JSRuntimePointer, intrinsics: IntrinsicsFlags) => JSContextPointer;
362
+ QTS_FreeContext: (ctx: JSContextPointer) => void;
363
+ QTS_FreeValuePointer: (ctx: JSContextPointer, value: JSValuePointer) => void;
364
+ QTS_FreeValuePointerRuntime: (rt: JSRuntimePointer, value: JSValuePointer) => void;
365
+ QTS_FreeVoidPointer: (ctx: JSContextPointer, ptr: JSVoidPointer) => void;
366
+ QTS_FreeCString: (ctx: JSContextPointer, str: JSBorrowedCharPointer) => void;
367
+ QTS_DupValuePointer: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
368
+ QTS_NewObject: (ctx: JSContextPointer) => JSValuePointer;
369
+ QTS_NewObjectProto: (ctx: JSContextPointer, proto: JSValuePointer | JSValueConstPointer) => JSValuePointer;
370
+ QTS_NewArray: (ctx: JSContextPointer) => JSValuePointer;
371
+ QTS_NewArrayBuffer: (ctx: JSContextPointer, buffer: JSVoidPointer, length: number) => JSValuePointer;
372
+ QTS_NewFloat64: (ctx: JSContextPointer, num: number) => JSValuePointer;
373
+ QTS_GetFloat64: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
374
+ QTS_NewString: (ctx: JSContextPointer, string: BorrowedHeapCharPointer) => JSValuePointer;
375
+ QTS_GetString: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
376
+ QTS_GetArrayBuffer: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSVoidPointer;
377
+ QTS_GetArrayBufferLength: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => number;
378
+ QTS_NewSymbol: (ctx: JSContextPointer, description: BorrowedHeapCharPointer, isGlobal: number) => JSValuePointer;
379
+ QTS_GetSymbolDescriptionOrKey: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
380
+ QTS_IsGlobalSymbol: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
381
+ QTS_IsJobPending: (rt: JSRuntimePointer) => number;
382
+ QTS_ExecutePendingJob: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer;
383
+ QTS_GetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer) => JSValuePointer;
384
+ QTS_GetPropNumber: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: number) => JSValuePointer;
385
+ QTS_SetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer) => void;
386
+ QTS_DefineProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer, get: JSValuePointer | JSValueConstPointer, set: JSValuePointer | JSValueConstPointer, configurable: boolean, enumerable: boolean, has_value: boolean) => void;
387
+ QTS_GetOwnPropertyNames: (ctx: JSContextPointer, out_ptrs: JSValuePointerPointerPointer, out_len: UInt32Pointer, obj: JSValuePointer | JSValueConstPointer, flags: number) => JSValuePointer;
388
+ QTS_Call: (ctx: JSContextPointer, func_obj: JSValuePointer | JSValueConstPointer, this_obj: JSValuePointer | JSValueConstPointer, argc: number, argv_ptrs: JSValueConstPointerPointer) => JSValuePointer;
389
+ QTS_ResolveException: (ctx: JSContextPointer, maybe_exception: JSValuePointer) => JSValuePointer;
390
+ QTS_Dump: (ctx: JSContextPointer, obj: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
391
+ QTS_Eval: (ctx: JSContextPointer, js_code: BorrowedHeapCharPointer, js_code_length: number, filename: string, detectModule: EvalDetectModule, evalFlags: EvalFlags) => JSValuePointer;
392
+ QTS_GetModuleNamespace: (ctx: JSContextPointer, module_func_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer;
393
+ QTS_Typeof: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => OwnedHeapCharPointer;
394
+ QTS_GetLength: (ctx: JSContextPointer, out_len: UInt32Pointer, value: JSValuePointer | JSValueConstPointer) => number;
395
+ QTS_IsEqual: (ctx: JSContextPointer, a: JSValuePointer | JSValueConstPointer, b: JSValuePointer | JSValueConstPointer, op: IsEqualOp) => number;
396
+ QTS_GetGlobalObject: (ctx: JSContextPointer) => JSValuePointer;
397
+ QTS_NewPromiseCapability: (ctx: JSContextPointer, resolve_funcs_out: JSValuePointerPointer) => JSValuePointer;
398
+ QTS_PromiseState: (ctx: JSContextPointer, promise: JSValuePointer | JSValueConstPointer) => JSPromiseStateEnum;
399
+ QTS_PromiseResult: (ctx: JSContextPointer, promise: JSValuePointer | JSValueConstPointer) => JSValuePointer;
400
+ QTS_TestStringArg: (string: string) => void;
401
+ QTS_GetDebugLogEnabled: (rt: JSRuntimePointer) => number;
402
+ QTS_SetDebugLogEnabled: (rt: JSRuntimePointer, is_enabled: number) => void;
403
+ QTS_BuildIsDebug: () => number;
404
+ QTS_BuildIsAsyncify: () => number;
405
+ QTS_NewFunction: (ctx: JSContextPointer, func_id: number, name: string) => JSValuePointer;
406
+ QTS_ArgvGetJSValueConstPointer: (argv: JSValuePointer | JSValueConstPointer, index: number) => JSValueConstPointer;
407
+ QTS_RuntimeEnableInterruptHandler: (rt: JSRuntimePointer) => void;
408
+ QTS_RuntimeDisableInterruptHandler: (rt: JSRuntimePointer) => void;
409
+ QTS_RuntimeEnableModuleLoader: (rt: JSRuntimePointer, use_custom_normalize: number) => void;
410
+ QTS_RuntimeDisableModuleLoader: (rt: JSRuntimePointer) => void;
411
+ QTS_bjson_encode: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
412
+ QTS_bjson_decode: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSValuePointer;
413
+ QTS_EvalFunction: (ctx: JSContextPointer, fun_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer;
414
+ QTS_EncodeBytecode: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
415
+ QTS_DecodeBytecode: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSValuePointer;
416
+ }
417
+
418
+ /**
419
+ * Low-level FFI bindings to QuickJS's Emscripten module.
420
+ * See instead {@link QuickJSContext}, the public Javascript interface exposed by this
421
+ * library.
422
+ *
423
+ * @unstable The FFI interface is considered private and may change.
424
+ */
425
+ interface QuickJSAsyncFFI {
426
+ /** Set at compile time. */
427
+ readonly DEBUG: boolean;
428
+ QTS_Throw: (ctx: JSContextPointer, error: JSValuePointer | JSValueConstPointer) => JSValuePointer;
429
+ QTS_NewError: (ctx: JSContextPointer) => JSValuePointer;
430
+ QTS_RuntimeSetMemoryLimit: (rt: JSRuntimePointer, limit: number) => void;
431
+ QTS_RuntimeComputeMemoryUsage: (rt: JSRuntimePointer, ctx: JSContextPointer) => JSValuePointer;
432
+ QTS_RuntimeDumpMemoryUsage: (rt: JSRuntimePointer) => OwnedHeapCharPointer;
433
+ QTS_RecoverableLeakCheck: () => number;
434
+ QTS_BuildIsSanitizeLeak: () => number;
435
+ QTS_RuntimeSetMaxStackSize: (rt: JSRuntimePointer, stack_size: number) => void;
436
+ QTS_GetUndefined: () => JSValueConstPointer;
437
+ QTS_GetNull: () => JSValueConstPointer;
438
+ QTS_GetFalse: () => JSValueConstPointer;
439
+ QTS_GetTrue: () => JSValueConstPointer;
440
+ QTS_NewRuntime: () => JSRuntimePointer;
441
+ QTS_FreeRuntime: (rt: JSRuntimePointer) => void;
442
+ QTS_NewContext: (rt: JSRuntimePointer, intrinsics: IntrinsicsFlags) => JSContextPointer;
443
+ QTS_FreeContext: (ctx: JSContextPointer) => void;
444
+ QTS_FreeValuePointer: (ctx: JSContextPointer, value: JSValuePointer) => void;
445
+ QTS_FreeValuePointerRuntime: (rt: JSRuntimePointer, value: JSValuePointer) => void;
446
+ QTS_FreeVoidPointer: (ctx: JSContextPointer, ptr: JSVoidPointer) => void;
447
+ QTS_FreeCString: (ctx: JSContextPointer, str: JSBorrowedCharPointer) => void;
448
+ QTS_DupValuePointer: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
449
+ QTS_NewObject: (ctx: JSContextPointer) => JSValuePointer;
450
+ QTS_NewObjectProto: (ctx: JSContextPointer, proto: JSValuePointer | JSValueConstPointer) => JSValuePointer;
451
+ QTS_NewArray: (ctx: JSContextPointer) => JSValuePointer;
452
+ QTS_NewArrayBuffer: (ctx: JSContextPointer, buffer: JSVoidPointer, length: number) => JSValuePointer;
453
+ QTS_NewFloat64: (ctx: JSContextPointer, num: number) => JSValuePointer;
454
+ QTS_GetFloat64: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
455
+ QTS_NewString: (ctx: JSContextPointer, string: BorrowedHeapCharPointer) => JSValuePointer;
456
+ QTS_GetString: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
457
+ QTS_GetArrayBuffer: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSVoidPointer;
458
+ QTS_GetArrayBufferLength: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => number;
459
+ QTS_NewSymbol: (ctx: JSContextPointer, description: BorrowedHeapCharPointer, isGlobal: number) => JSValuePointer;
460
+ QTS_GetSymbolDescriptionOrKey: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
461
+ QTS_GetSymbolDescriptionOrKey_MaybeAsync: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer | Promise<JSBorrowedCharPointer>;
462
+ QTS_IsGlobalSymbol: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
463
+ QTS_IsJobPending: (rt: JSRuntimePointer) => number;
464
+ QTS_ExecutePendingJob: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer;
465
+ QTS_ExecutePendingJob_MaybeAsync: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer | Promise<JSValuePointer>;
466
+ QTS_GetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer) => JSValuePointer;
467
+ QTS_GetProp_MaybeAsync: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer) => JSValuePointer | Promise<JSValuePointer>;
468
+ QTS_GetPropNumber: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: number) => JSValuePointer;
469
+ QTS_GetPropNumber_MaybeAsync: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: number) => JSValuePointer | Promise<JSValuePointer>;
470
+ QTS_SetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer) => void;
471
+ QTS_SetProp_MaybeAsync: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer) => void | Promise<void>;
472
+ QTS_DefineProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer, get: JSValuePointer | JSValueConstPointer, set: JSValuePointer | JSValueConstPointer, configurable: boolean, enumerable: boolean, has_value: boolean) => void;
473
+ QTS_GetOwnPropertyNames: (ctx: JSContextPointer, out_ptrs: JSValuePointerPointerPointer, out_len: UInt32Pointer, obj: JSValuePointer | JSValueConstPointer, flags: number) => JSValuePointer;
474
+ QTS_GetOwnPropertyNames_MaybeAsync: (ctx: JSContextPointer, out_ptrs: JSValuePointerPointerPointer, out_len: UInt32Pointer, obj: JSValuePointer | JSValueConstPointer, flags: number) => JSValuePointer | Promise<JSValuePointer>;
475
+ QTS_Call: (ctx: JSContextPointer, func_obj: JSValuePointer | JSValueConstPointer, this_obj: JSValuePointer | JSValueConstPointer, argc: number, argv_ptrs: JSValueConstPointerPointer) => JSValuePointer;
476
+ QTS_Call_MaybeAsync: (ctx: JSContextPointer, func_obj: JSValuePointer | JSValueConstPointer, this_obj: JSValuePointer | JSValueConstPointer, argc: number, argv_ptrs: JSValueConstPointerPointer) => JSValuePointer | Promise<JSValuePointer>;
477
+ QTS_ResolveException: (ctx: JSContextPointer, maybe_exception: JSValuePointer) => JSValuePointer;
478
+ QTS_Dump: (ctx: JSContextPointer, obj: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
479
+ QTS_Dump_MaybeAsync: (ctx: JSContextPointer, obj: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer | Promise<JSBorrowedCharPointer>;
480
+ QTS_Eval: (ctx: JSContextPointer, js_code: BorrowedHeapCharPointer, js_code_length: number, filename: string, detectModule: EvalDetectModule, evalFlags: EvalFlags) => JSValuePointer;
481
+ QTS_Eval_MaybeAsync: (ctx: JSContextPointer, js_code: BorrowedHeapCharPointer, js_code_length: number, filename: string, detectModule: EvalDetectModule, evalFlags: EvalFlags) => JSValuePointer | Promise<JSValuePointer>;
482
+ QTS_GetModuleNamespace: (ctx: JSContextPointer, module_func_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer;
483
+ QTS_Typeof: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => OwnedHeapCharPointer;
484
+ QTS_GetLength: (ctx: JSContextPointer, out_len: UInt32Pointer, value: JSValuePointer | JSValueConstPointer) => number;
485
+ QTS_IsEqual: (ctx: JSContextPointer, a: JSValuePointer | JSValueConstPointer, b: JSValuePointer | JSValueConstPointer, op: IsEqualOp) => number;
486
+ QTS_GetGlobalObject: (ctx: JSContextPointer) => JSValuePointer;
487
+ QTS_NewPromiseCapability: (ctx: JSContextPointer, resolve_funcs_out: JSValuePointerPointer) => JSValuePointer;
488
+ QTS_PromiseState: (ctx: JSContextPointer, promise: JSValuePointer | JSValueConstPointer) => JSPromiseStateEnum;
489
+ QTS_PromiseResult: (ctx: JSContextPointer, promise: JSValuePointer | JSValueConstPointer) => JSValuePointer;
490
+ QTS_TestStringArg: (string: string) => void;
491
+ QTS_GetDebugLogEnabled: (rt: JSRuntimePointer) => number;
492
+ QTS_SetDebugLogEnabled: (rt: JSRuntimePointer, is_enabled: number) => void;
493
+ QTS_BuildIsDebug: () => number;
494
+ QTS_BuildIsAsyncify: () => number;
495
+ QTS_NewFunction: (ctx: JSContextPointer, func_id: number, name: string) => JSValuePointer;
496
+ QTS_ArgvGetJSValueConstPointer: (argv: JSValuePointer | JSValueConstPointer, index: number) => JSValueConstPointer;
497
+ QTS_RuntimeEnableInterruptHandler: (rt: JSRuntimePointer) => void;
498
+ QTS_RuntimeDisableInterruptHandler: (rt: JSRuntimePointer) => void;
499
+ QTS_RuntimeEnableModuleLoader: (rt: JSRuntimePointer, use_custom_normalize: number) => void;
500
+ QTS_RuntimeDisableModuleLoader: (rt: JSRuntimePointer) => void;
501
+ QTS_bjson_encode: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
502
+ QTS_bjson_decode: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSValuePointer;
503
+ QTS_EvalFunction: (ctx: JSContextPointer, fun_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer;
504
+ QTS_EvalFunction_MaybeAsync: (ctx: JSContextPointer, fun_obj: JSValuePointer | JSValueConstPointer) => JSValuePointer | Promise<JSValuePointer>;
505
+ QTS_EncodeBytecode: (ctx: JSContextPointer, val: JSValuePointer | JSValueConstPointer) => JSValuePointer;
506
+ QTS_DecodeBytecode: (ctx: JSContextPointer, data: JSValuePointer | JSValueConstPointer) => JSValuePointer;
507
+ }
508
+
509
+ type EmscriptenImport<T extends EmscriptenModule> = EmscriptenModuleLoader<T> | {
510
+ default: EmscriptenModuleLoader<T>;
511
+ } | {
512
+ default: {
513
+ default: EmscriptenModuleLoader<T>;
514
+ };
515
+ };
516
+ /**
517
+ * A standard (sync) build variant.
518
+ *
519
+ * quickjs-emscripten provides multiple build variants of the core WebAssembly
520
+ * module. These variants are each intended for a different use case.
521
+ *
522
+ * To create an instance of the library using a specific build variant, pass the
523
+ * build variant to {@link newQuickJSWASMModule} or {@link newQuickJSAsyncWASMModule}.
524
+ */
525
+ interface QuickJSSyncVariant {
526
+ readonly type: "sync";
527
+ readonly importFFI: () => Promise<new (module: QuickJSEmscriptenModule) => QuickJSFFI>;
528
+ readonly importModuleLoader: () => Promise<EmscriptenImport<QuickJSEmscriptenModule>>;
529
+ }
530
+ /**
531
+ * An ASYNCIFY build variant.
532
+ *
533
+ * quickjs-emscripten provides multiple build variants of the core WebAssembly
534
+ * module. These variants are each intended for a different use case.
535
+ *
536
+ * To create an instance of the library using a specific build variant, pass the
537
+ * build variant to {@link newQuickJSWASMModule} or {@link newQuickJSAsyncWASMModule}.
538
+ */
539
+ interface QuickJSAsyncVariant {
540
+ readonly type: "async";
541
+ readonly importFFI: () => Promise<new (module: QuickJSAsyncEmscriptenModule) => QuickJSAsyncFFI>;
542
+ readonly importModuleLoader: () => Promise<EmscriptenImport<QuickJSAsyncEmscriptenModule>>;
543
+ }
544
+ type QuickJSVariant = QuickJSSyncVariant | QuickJSAsyncVariant;
545
+ type EitherFFI = QuickJSFFI | QuickJSAsyncFFI;
546
+
547
+ export { type Asyncify, type AsyncifySleepResult, type BorrowedHeapCharPointer, type EitherFFI, type EitherModule, type EmscriptenModule, type EmscriptenModuleCallbacks, type EmscriptenModuleLoader, type EmscriptenModuleLoaderOptions, type EvalDetectModule, EvalFlags, GetOwnPropertyNamesFlags, IntrinsicsFlags, IsEqualOp, type JSBorrowedCharPointer, type JSContextPointer, type JSContextPointerPointer, type JSModuleDefPointer, JSPromiseStateEnum, type JSRuntimePointer, type JSValueConstPointer, type JSValueConstPointerPointer, type JSValuePointer, type JSValuePointerPointer, type JSValuePointerPointerPointer, type JSVoidPointer, type OwnedHeapCharPointer, type QTS_C_To_HostCallbackFuncPointer, type QTS_C_To_HostInterruptFuncPointer, type QTS_C_To_HostLoadModuleFuncPointer, type QuickJSAsyncEmscriptenModule, type QuickJSAsyncFFI, type QuickJSAsyncVariant, type QuickJSEmscriptenExtensions, type QuickJSEmscriptenModule, type QuickJSFFI, type QuickJSSyncVariant, type QuickJSVariant, type SourceMapData, type UInt32Pointer, assertSync };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var index_exports={};__export(index_exports,{EvalFlags:()=>EvalFlags,GetOwnPropertyNamesFlags:()=>GetOwnPropertyNamesFlags,IntrinsicsFlags:()=>IntrinsicsFlags,IsEqualOp:()=>IsEqualOp,JSPromiseStateEnum:()=>JSPromiseStateEnum,assertSync:()=>assertSync});module.exports=__toCommonJS(index_exports);function assertSync(fn){return function(...args){let result=fn(...args);if(result&&typeof result=="object"&&result instanceof Promise)throw new Error("Function unexpectedly returned a Promise");return result}}var EvalFlags={JS_EVAL_TYPE_GLOBAL:0,JS_EVAL_TYPE_MODULE:1,JS_EVAL_TYPE_DIRECT:2,JS_EVAL_TYPE_INDIRECT:3,JS_EVAL_TYPE_MASK:3,JS_EVAL_FLAG_STRICT:8,JS_EVAL_FLAG_STRIP:16,JS_EVAL_FLAG_COMPILE_ONLY:32,JS_EVAL_FLAG_BACKTRACE_BARRIER:64},IntrinsicsFlags={BaseObjects:1,Date:2,Eval:4,StringNormalize:8,RegExp:16,RegExpCompiler:32,JSON:64,Proxy:128,MapSet:256,TypedArrays:512,Promise:1024,BigInt:2048,BigFloat:4096,BigDecimal:8192,OperatorOverloading:16384,BignumExt:32768},JSPromiseStateEnum={Pending:0,Fulfilled:1,Rejected:2},GetOwnPropertyNamesFlags={JS_GPN_STRING_MASK:1,JS_GPN_SYMBOL_MASK:2,JS_GPN_PRIVATE_MASK:4,JS_GPN_ENUM_ONLY:16,JS_GPN_SET_ENUM:32,QTS_GPN_NUMBER_MASK:64,QTS_STANDARD_COMPLIANT_NUMBER:128},IsEqualOp={IsStrictlyEqual:0,IsSameValue:1,IsSameValueZero:2};0&&(module.exports={EvalFlags,GetOwnPropertyNamesFlags,IntrinsicsFlags,IsEqualOp,JSPromiseStateEnum,assertSync});
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/ffi-types.ts"],"sourcesContent":["export * from \"./emscripten-types\"\nexport * from \"./ffi-types\"\nexport * from \"./ffi\"\nexport * from \"./ffi-async\"\nexport * from \"./variant-types\"\n","/**\n * C pointer to type `CType`. Pointer types are used internally for FFI, but\n * are not intended for external use.\n *\n * @unstable This type is considered private and may change.\n */\ntype Pointer<CType extends string> = number & { ctype: CType }\n\ntype Brand<T, B> = T & { brand: B }\n\n/**\n * `JSRuntime*`.\n */\nexport type JSRuntimePointer = Pointer<\"JSRuntime\">\n\n/**\n * `JSContext*`.\n */\nexport type JSContextPointer = Pointer<\"JSContext\">\n\n/**\n * `JSContext**`. Used internally for execute pending jobs.\n */\nexport type JSContextPointerPointer = Pointer<\"JSContext\">\n\n/**\n * `JSModuleDef*`.\n */\nexport type JSModuleDefPointer = Pointer<\"JSModuleDef\">\n\n/**\n * `JSValue*`.\n * See {@link JSValue}.\n */\nexport type JSValuePointer = Pointer<\"JSValue\">\n\n/**\n * `JSValueConst*\n * See {@link JSValueConst} and {@link StaticJSValue}.\n */\nexport type JSValueConstPointer = Pointer<\"JSValueConst\">\n\n/**\n * Used internally for Javascript-to-C function calls.\n */\nexport type JSValuePointerPointer = Pointer<\"JSValue[]\">\n\n/**\n * Used internally for Javascript-to-C function calls.\n */\nexport type JSValuePointerPointerPointer = Pointer<\"*JSValue[]\">\n\n/**\n * Used internally for Javascript-to-C function calls.\n */\nexport type JSValueConstPointerPointer = Pointer<\"JSValueConst[]\">\n\n/**\n * Used internally for C-to-Javascript function calls.\n */\n// type JSCFunctionPointer = Pointer<'JSCFunction'>\n\n/**\n * Used internally for C-to-Javascript function calls.\n */\nexport type QTS_C_To_HostCallbackFuncPointer = Pointer<\"C_To_HostCallbackFunc\">\n\n/**\n * Used internally for C-to-Javascript interrupt handlers.\n */\nexport type QTS_C_To_HostInterruptFuncPointer = Pointer<\"C_To_HostInterruptFunc\">\n\n/**\n * Used internally for C-to-Javascript module loading.\n */\nexport type QTS_C_To_HostLoadModuleFuncPointer = Pointer<\"C_To_HostLoadModuleFunc\">\n\n/**\n * Used internally for Javascript-to-C calls that may contain strings too large\n * for the Emscripten stack.\n */\nexport type BorrowedHeapCharPointer = Pointer<\"const char\" | \"char\" | \"js const char\">\n\n/**\n * Used internally for Javascript-to-C calls that may contain strings too large\n * for the Emscripten stack.\n */\nexport type OwnedHeapCharPointer = Pointer<\"char\">\n\n/**\n * Used internally for Javascript-to-C calls that may contain strings too large\n * for the Emscripten stack.\n */\nexport type JSBorrowedCharPointer = Pointer<\"js const char\">\n\n/**\n * Opaque pointer that was allocated by js_malloc.\n */\nexport type JSVoidPointer = Pointer<any>\n\nexport type UInt32Pointer = Pointer<\"uint32_t\">\n\n/**\n * @private\n */\nexport type EvalFlags = Brand<number, \"EvalFlags\">\n\n/**\n * @private\n */\nexport type IntrinsicsFlags = Brand<number, \"IntrinsicsFlags\">\n\n/**\n * @private\n */\nexport type EvalDetectModule = Brand<number, \"EvalDetectModule\">\n\n/**\n * @private\n */\nexport type GetOwnPropertyNamesFlags = Brand<number, \"GetOwnPropertyNamesFlags\">\n\n/**\n * @private\n */\nexport type IsEqualOp = Brand<number, \"IsEqualOp\">\n\n/**\n * State of a promise.\n */\nexport type JSPromiseStateEnum = Brand<\n (typeof JSPromiseStateEnum)[keyof typeof JSPromiseStateEnum],\n \"JSPromiseStateEnum\"\n>\n\nexport function assertSync<Args extends any[], R>(fn: (...args: Args) => R): (...args: Args) => R {\n return function mustBeSync(...args: Args): R {\n const result = fn(...args)\n if (result && typeof result === \"object\" && result instanceof Promise) {\n throw new Error(\"Function unexpectedly returned a Promise\")\n }\n return result\n }\n}\n\n/** Bitfield options for JS_Eval() C function. */\nexport const EvalFlags = {\n /** global code (default) */\n JS_EVAL_TYPE_GLOBAL: 0 << 0,\n /** module code */\n JS_EVAL_TYPE_MODULE: 1 << 0,\n /** direct call (internal use) */\n JS_EVAL_TYPE_DIRECT: 2 << 0,\n /** indirect call (internal use) */\n JS_EVAL_TYPE_INDIRECT: 3 << 0,\n JS_EVAL_TYPE_MASK: 3 << 0,\n /** force 'strict' mode */\n JS_EVAL_FLAG_STRICT: 1 << 3,\n /** force 'strip' mode */\n JS_EVAL_FLAG_STRIP: 1 << 4,\n /**\n * compile but do not run. The result is an object with a\n * JS_TAG_FUNCTION_BYTECODE or JS_TAG_MODULE tag. It can be executed\n * with JS_EvalFunction().\n */\n JS_EVAL_FLAG_COMPILE_ONLY: 1 << 5,\n /** don't include the stack frames before this eval in the Error() backtraces */\n JS_EVAL_FLAG_BACKTRACE_BARRIER: 1 << 6,\n} as const\n\n/** Bitfield options for QTS_NewContext intrinsics */\nexport const IntrinsicsFlags = {\n BaseObjects: 1 << 0,\n Date: 1 << 1,\n Eval: 1 << 2,\n StringNormalize: 1 << 3,\n RegExp: 1 << 4,\n RegExpCompiler: 1 << 5,\n JSON: 1 << 6,\n Proxy: 1 << 7,\n MapSet: 1 << 8,\n TypedArrays: 1 << 9,\n Promise: 1 << 10,\n BigInt: 1 << 11,\n BigFloat: 1 << 12,\n BigDecimal: 1 << 13,\n OperatorOverloading: 1 << 14,\n BignumExt: 1 << 15,\n} as const\n\nexport const JSPromiseStateEnum = {\n Pending: 0,\n Fulfilled: 1,\n Rejected: 2,\n} as const\n\n/** Bitfield options for QTS_GetOwnPropertyNames */\nexport const GetOwnPropertyNamesFlags = {\n JS_GPN_STRING_MASK: 1 << 0,\n JS_GPN_SYMBOL_MASK: 1 << 1,\n JS_GPN_PRIVATE_MASK: 1 << 2,\n /* only include the enumerable properties */\n JS_GPN_ENUM_ONLY: 1 << 4,\n /* set theJSPropertyEnum.is_enumerable field */\n JS_GPN_SET_ENUM: 1 << 5,\n /* include numbers. when only this is set, we filter out strings */\n QTS_GPN_NUMBER_MASK: 1 << 6,\n /* Treat numbers as strings */\n QTS_STANDARD_COMPLIANT_NUMBER: 1 << 7,\n}\n\nexport const IsEqualOp = {\n IsStrictlyEqual: 0 as IsEqualOp,\n IsSameValue: 1 as IsEqualOp,\n IsSameValueZero: 2 as IsEqualOp,\n}\n"],"mappings":"wpBAAA,wSCuIO,SAAS,WAAkC,GAAgD,CAChG,OAAO,YAAuB,KAAe,CAC3C,IAAM,OAAS,GAAG,GAAG,IAAI,EACzB,GAAI,QAAU,OAAO,QAAW,UAAY,kBAAkB,QAC5D,MAAM,IAAI,MAAM,0CAA0C,EAE5D,OAAO,MACT,CACF,CAGO,IAAM,UAAY,CAEvB,oBAAqB,EAErB,oBAAqB,EAErB,oBAAqB,EAErB,sBAAuB,EACvB,kBAAmB,EAEnB,oBAAqB,EAErB,mBAAoB,GAMpB,0BAA2B,GAE3B,+BAAgC,EAClC,EAGa,gBAAkB,CAC7B,YAAa,EACb,KAAM,EACN,KAAM,EACN,gBAAiB,EACjB,OAAQ,GACR,eAAgB,GAChB,KAAM,GACN,MAAO,IACP,OAAQ,IACR,YAAa,IACb,QAAS,KACT,OAAQ,KACR,SAAU,KACV,WAAY,KACZ,oBAAqB,MACrB,UAAW,KACb,EAEa,mBAAqB,CAChC,QAAS,EACT,UAAW,EACX,SAAU,CACZ,EAGa,yBAA2B,CACtC,mBAAoB,EACpB,mBAAoB,EACpB,oBAAqB,EAErB,iBAAkB,GAElB,gBAAiB,GAEjB,oBAAqB,GAErB,8BAA+B,GACjC,EAEa,UAAY,CACvB,gBAAiB,EACjB,YAAa,EACb,gBAAiB,CACnB","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ function assertSync(fn){return function(...args){let result=fn(...args);if(result&&typeof result=="object"&&result instanceof Promise)throw new Error("Function unexpectedly returned a Promise");return result}}var EvalFlags={JS_EVAL_TYPE_GLOBAL:0,JS_EVAL_TYPE_MODULE:1,JS_EVAL_TYPE_DIRECT:2,JS_EVAL_TYPE_INDIRECT:3,JS_EVAL_TYPE_MASK:3,JS_EVAL_FLAG_STRICT:8,JS_EVAL_FLAG_STRIP:16,JS_EVAL_FLAG_COMPILE_ONLY:32,JS_EVAL_FLAG_BACKTRACE_BARRIER:64},IntrinsicsFlags={BaseObjects:1,Date:2,Eval:4,StringNormalize:8,RegExp:16,RegExpCompiler:32,JSON:64,Proxy:128,MapSet:256,TypedArrays:512,Promise:1024,BigInt:2048,BigFloat:4096,BigDecimal:8192,OperatorOverloading:16384,BignumExt:32768},JSPromiseStateEnum={Pending:0,Fulfilled:1,Rejected:2},GetOwnPropertyNamesFlags={JS_GPN_STRING_MASK:1,JS_GPN_SYMBOL_MASK:2,JS_GPN_PRIVATE_MASK:4,JS_GPN_ENUM_ONLY:16,JS_GPN_SET_ENUM:32,QTS_GPN_NUMBER_MASK:64,QTS_STANDARD_COMPLIANT_NUMBER:128},IsEqualOp={IsStrictlyEqual:0,IsSameValue:1,IsSameValueZero:2};export{EvalFlags,GetOwnPropertyNamesFlags,IntrinsicsFlags,IsEqualOp,JSPromiseStateEnum,assertSync};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ffi-types.ts"],"sourcesContent":["/**\n * C pointer to type `CType`. Pointer types are used internally for FFI, but\n * are not intended for external use.\n *\n * @unstable This type is considered private and may change.\n */\ntype Pointer<CType extends string> = number & { ctype: CType }\n\ntype Brand<T, B> = T & { brand: B }\n\n/**\n * `JSRuntime*`.\n */\nexport type JSRuntimePointer = Pointer<\"JSRuntime\">\n\n/**\n * `JSContext*`.\n */\nexport type JSContextPointer = Pointer<\"JSContext\">\n\n/**\n * `JSContext**`. Used internally for execute pending jobs.\n */\nexport type JSContextPointerPointer = Pointer<\"JSContext\">\n\n/**\n * `JSModuleDef*`.\n */\nexport type JSModuleDefPointer = Pointer<\"JSModuleDef\">\n\n/**\n * `JSValue*`.\n * See {@link JSValue}.\n */\nexport type JSValuePointer = Pointer<\"JSValue\">\n\n/**\n * `JSValueConst*\n * See {@link JSValueConst} and {@link StaticJSValue}.\n */\nexport type JSValueConstPointer = Pointer<\"JSValueConst\">\n\n/**\n * Used internally for Javascript-to-C function calls.\n */\nexport type JSValuePointerPointer = Pointer<\"JSValue[]\">\n\n/**\n * Used internally for Javascript-to-C function calls.\n */\nexport type JSValuePointerPointerPointer = Pointer<\"*JSValue[]\">\n\n/**\n * Used internally for Javascript-to-C function calls.\n */\nexport type JSValueConstPointerPointer = Pointer<\"JSValueConst[]\">\n\n/**\n * Used internally for C-to-Javascript function calls.\n */\n// type JSCFunctionPointer = Pointer<'JSCFunction'>\n\n/**\n * Used internally for C-to-Javascript function calls.\n */\nexport type QTS_C_To_HostCallbackFuncPointer = Pointer<\"C_To_HostCallbackFunc\">\n\n/**\n * Used internally for C-to-Javascript interrupt handlers.\n */\nexport type QTS_C_To_HostInterruptFuncPointer = Pointer<\"C_To_HostInterruptFunc\">\n\n/**\n * Used internally for C-to-Javascript module loading.\n */\nexport type QTS_C_To_HostLoadModuleFuncPointer = Pointer<\"C_To_HostLoadModuleFunc\">\n\n/**\n * Used internally for Javascript-to-C calls that may contain strings too large\n * for the Emscripten stack.\n */\nexport type BorrowedHeapCharPointer = Pointer<\"const char\" | \"char\" | \"js const char\">\n\n/**\n * Used internally for Javascript-to-C calls that may contain strings too large\n * for the Emscripten stack.\n */\nexport type OwnedHeapCharPointer = Pointer<\"char\">\n\n/**\n * Used internally for Javascript-to-C calls that may contain strings too large\n * for the Emscripten stack.\n */\nexport type JSBorrowedCharPointer = Pointer<\"js const char\">\n\n/**\n * Opaque pointer that was allocated by js_malloc.\n */\nexport type JSVoidPointer = Pointer<any>\n\nexport type UInt32Pointer = Pointer<\"uint32_t\">\n\n/**\n * @private\n */\nexport type EvalFlags = Brand<number, \"EvalFlags\">\n\n/**\n * @private\n */\nexport type IntrinsicsFlags = Brand<number, \"IntrinsicsFlags\">\n\n/**\n * @private\n */\nexport type EvalDetectModule = Brand<number, \"EvalDetectModule\">\n\n/**\n * @private\n */\nexport type GetOwnPropertyNamesFlags = Brand<number, \"GetOwnPropertyNamesFlags\">\n\n/**\n * @private\n */\nexport type IsEqualOp = Brand<number, \"IsEqualOp\">\n\n/**\n * State of a promise.\n */\nexport type JSPromiseStateEnum = Brand<\n (typeof JSPromiseStateEnum)[keyof typeof JSPromiseStateEnum],\n \"JSPromiseStateEnum\"\n>\n\nexport function assertSync<Args extends any[], R>(fn: (...args: Args) => R): (...args: Args) => R {\n return function mustBeSync(...args: Args): R {\n const result = fn(...args)\n if (result && typeof result === \"object\" && result instanceof Promise) {\n throw new Error(\"Function unexpectedly returned a Promise\")\n }\n return result\n }\n}\n\n/** Bitfield options for JS_Eval() C function. */\nexport const EvalFlags = {\n /** global code (default) */\n JS_EVAL_TYPE_GLOBAL: 0 << 0,\n /** module code */\n JS_EVAL_TYPE_MODULE: 1 << 0,\n /** direct call (internal use) */\n JS_EVAL_TYPE_DIRECT: 2 << 0,\n /** indirect call (internal use) */\n JS_EVAL_TYPE_INDIRECT: 3 << 0,\n JS_EVAL_TYPE_MASK: 3 << 0,\n /** force 'strict' mode */\n JS_EVAL_FLAG_STRICT: 1 << 3,\n /** force 'strip' mode */\n JS_EVAL_FLAG_STRIP: 1 << 4,\n /**\n * compile but do not run. The result is an object with a\n * JS_TAG_FUNCTION_BYTECODE or JS_TAG_MODULE tag. It can be executed\n * with JS_EvalFunction().\n */\n JS_EVAL_FLAG_COMPILE_ONLY: 1 << 5,\n /** don't include the stack frames before this eval in the Error() backtraces */\n JS_EVAL_FLAG_BACKTRACE_BARRIER: 1 << 6,\n} as const\n\n/** Bitfield options for QTS_NewContext intrinsics */\nexport const IntrinsicsFlags = {\n BaseObjects: 1 << 0,\n Date: 1 << 1,\n Eval: 1 << 2,\n StringNormalize: 1 << 3,\n RegExp: 1 << 4,\n RegExpCompiler: 1 << 5,\n JSON: 1 << 6,\n Proxy: 1 << 7,\n MapSet: 1 << 8,\n TypedArrays: 1 << 9,\n Promise: 1 << 10,\n BigInt: 1 << 11,\n BigFloat: 1 << 12,\n BigDecimal: 1 << 13,\n OperatorOverloading: 1 << 14,\n BignumExt: 1 << 15,\n} as const\n\nexport const JSPromiseStateEnum = {\n Pending: 0,\n Fulfilled: 1,\n Rejected: 2,\n} as const\n\n/** Bitfield options for QTS_GetOwnPropertyNames */\nexport const GetOwnPropertyNamesFlags = {\n JS_GPN_STRING_MASK: 1 << 0,\n JS_GPN_SYMBOL_MASK: 1 << 1,\n JS_GPN_PRIVATE_MASK: 1 << 2,\n /* only include the enumerable properties */\n JS_GPN_ENUM_ONLY: 1 << 4,\n /* set theJSPropertyEnum.is_enumerable field */\n JS_GPN_SET_ENUM: 1 << 5,\n /* include numbers. when only this is set, we filter out strings */\n QTS_GPN_NUMBER_MASK: 1 << 6,\n /* Treat numbers as strings */\n QTS_STANDARD_COMPLIANT_NUMBER: 1 << 7,\n}\n\nexport const IsEqualOp = {\n IsStrictlyEqual: 0 as IsEqualOp,\n IsSameValue: 1 as IsEqualOp,\n IsSameValueZero: 2 as IsEqualOp,\n}\n"],"mappings":"AAuIO,SAAS,WAAkC,GAAgD,CAChG,OAAO,YAAuB,KAAe,CAC3C,IAAM,OAAS,GAAG,GAAG,IAAI,EACzB,GAAI,QAAU,OAAO,QAAW,UAAY,kBAAkB,QAC5D,MAAM,IAAI,MAAM,0CAA0C,EAE5D,OAAO,MACT,CACF,CAGO,IAAM,UAAY,CAEvB,oBAAqB,EAErB,oBAAqB,EAErB,oBAAqB,EAErB,sBAAuB,EACvB,kBAAmB,EAEnB,oBAAqB,EAErB,mBAAoB,GAMpB,0BAA2B,GAE3B,+BAAgC,EAClC,EAGa,gBAAkB,CAC7B,YAAa,EACb,KAAM,EACN,KAAM,EACN,gBAAiB,EACjB,OAAQ,GACR,eAAgB,GAChB,KAAM,GACN,MAAO,IACP,OAAQ,IACR,YAAa,IACb,QAAS,KACT,OAAQ,KACR,SAAU,KACV,WAAY,KACZ,oBAAqB,MACrB,UAAW,KACb,EAEa,mBAAqB,CAChC,QAAS,EACT,UAAW,EACX,SAAU,CACZ,EAGa,yBAA2B,CACtC,mBAAoB,EACpB,mBAAoB,EACpB,oBAAqB,EAErB,iBAAkB,GAElB,gBAAiB,GAEjB,oBAAqB,GAErB,8BAA+B,GACjC,EAEa,UAAY,CACvB,gBAAiB,EACjB,YAAa,EACb,gBAAiB,CACnB","names":[]}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@componentor/quickjs-ffi-types",
3
+ "version": "0.31.0",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/componentor/quickjs-emscripten"
8
+ },
9
+ "author": {
10
+ "name": "Componentor"
11
+ },
12
+ "files": [
13
+ "LICENSE",
14
+ "dist/**/*"
15
+ ],
16
+ "types": "dist/index.d.ts",
17
+ "main": "dist/index.js",
18
+ "module": "dist/index.mjs",
19
+ "exports": {
20
+ "./package.json": "./package.json",
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.mjs",
24
+ "require": "./dist/index.js"
25
+ }
26
+ },
27
+ "devDependencies": {
28
+ "@jitl/tsconfig": "0.31.0"
29
+ },
30
+ "scripts": {
31
+ "check": "npx tsc --project . --noEmit",
32
+ "build": "npx tsup",
33
+ "clean": "git clean -fx dist"
34
+ }
35
+ }