variants.d.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import type { QuickJSFFI as ReleaseSyncFFI } from "./generated/ffi.WASM_RELEASE_SYNC";
  2. import type { EmscriptenModuleLoader, QuickJSEmscriptenModule, QuickJSAsyncEmscriptenModule } from "./emscripten-types";
  3. import type { QuickJSWASMModule } from "./module";
  4. import type { QuickJSAsyncWASMModule } from "./module-asyncify";
  5. /** @private */
  6. export type QuickJSFFI = ReleaseSyncFFI;
  7. /** @private */
  8. export type QuickJSFFIConstructor = typeof ReleaseSyncFFI;
  9. /** @private */
  10. export type QuickJSAsyncFFI = any;
  11. /** @private */
  12. export type QuickJSAsyncFFIConstructor = any;
  13. /**
  14. * quickjs-emscripten provides multiple build variants of the core WebAssembly
  15. * module. These variants are each intended for a different use case.
  16. *
  17. * To create an instance of the library using a specific build variant, pass the
  18. * build variant to {@link newQuickJSWASMModule} or {@link newQuickJSAsyncWASMModule}.
  19. *
  20. * Synchronous build variants:
  21. *
  22. * - {@link RELEASE_SYNC} - This is the default synchronous variant, for general purpose use.
  23. * - {@link DEBUG_SYNC} - Synchronous build variant for debugging memory leaks.
  24. */
  25. export interface SyncBuildVariant {
  26. type: "sync";
  27. importFFI: () => Promise<QuickJSFFIConstructor>;
  28. importModuleLoader: () => Promise<EmscriptenModuleLoader<QuickJSEmscriptenModule>>;
  29. }
  30. /**
  31. * quickjs-emscripten provides multiple build variants of the core WebAssembly
  32. * module. These variants are each intended for a different use case.
  33. *
  34. * To create an instance of the library using a specific build variant, pass the
  35. * build variant to {@link newQuickJSWASMModule} or {@link newQuickJSAsyncWASMModule}.
  36. *
  37. * Asyncified build variants:
  38. *
  39. * - {@link RELEASE_ASYNC} - This is the default asyncified build variant, for general purpose use.
  40. * - {@link DEBUG_ASYNC} - Asyncified build variant with debug logging.
  41. */
  42. export interface AsyncBuildVariant {
  43. type: "async";
  44. importFFI: () => Promise<QuickJSAsyncFFIConstructor>;
  45. importModuleLoader: () => Promise<EmscriptenModuleLoader<QuickJSAsyncEmscriptenModule>>;
  46. }
  47. /**
  48. * Create a new, completely isolated WebAssembly module containing the QuickJS library.
  49. * See the documentation on [[QuickJSWASMModule]].
  50. *
  51. * Note that there is a hard limit on the number of WebAssembly modules in older
  52. * versions of v8:
  53. * https://bugs.chromium.org/p/v8/issues/detail?id=12076
  54. */
  55. export declare function newQuickJSWASMModule(
  56. /**
  57. * Optionally, pass a {@link SyncBuildVariant} to construct a different WebAssembly module.
  58. */
  59. variant?: SyncBuildVariant): Promise<QuickJSWASMModule>;
  60. /**
  61. * Create a new, completely isolated WebAssembly module containing a version of the QuickJS library
  62. * compiled with Emscripten's [ASYNCIFY](https://emscripten.org/docs/porting/asyncify.html) transform.
  63. *
  64. * This version of the library offers features that enable synchronous code
  65. * inside the VM to interact with asynchronous code in the host environment.
  66. * See the documentation on [[QuickJSAsyncWASMModule]], [[QuickJSAsyncRuntime]],
  67. * and [[QuickJSAsyncContext]].
  68. *
  69. * Note that there is a hard limit on the number of WebAssembly modules in older
  70. * versions of v8:
  71. * https://bugs.chromium.org/p/v8/issues/detail?id=12076
  72. */
  73. export declare function newQuickJSAsyncWASMModule(
  74. /**
  75. * Optionally, pass a {@link AsyncBuildVariant} to construct a different WebAssembly module.
  76. */
  77. variant?: AsyncBuildVariant): Promise<QuickJSAsyncWASMModule>;
  78. /**
  79. * Helper intended to memoize the creation of a WebAssembly module.
  80. * ```typescript
  81. * const getDebugModule = memoizePromiseFactory(() => newQuickJSWASMModule(DEBUG_SYNC))
  82. * ```
  83. */
  84. export declare function memoizePromiseFactory<T>(fn: () => Promise<T>): () => Promise<T>;
  85. /**
  86. * This build variant is compiled with `-fsanitize=leak`. It instruments all
  87. * memory allocations and when combined with sourcemaps, can present stack trace
  88. * locations where memory leaks occur.
  89. *
  90. * See [[TestQuickJSWASMModule]] which provides access to the leak sanitizer via
  91. * {@link TestQuickJSWASMModule.assertNoMemoryAllocated}.
  92. *
  93. * The downside is that it's 100-1000x slower than the other variants.
  94. * Suggested use case: automated testing, regression testing, and interactive
  95. * debugging.
  96. */
  97. export declare const DEBUG_SYNC: SyncBuildVariant;
  98. /**
  99. * This is the default (synchronous) build variant.
  100. * {@link getQuickJS} returns a memoized instance of this build variant.
  101. */
  102. export declare const RELEASE_SYNC: SyncBuildVariant;
  103. /**
  104. * The async debug build variant may or may not have the sanitizer enabled.
  105. * It does print a lot of debug logs.
  106. *
  107. * Suggested use case: interactive debugging only.
  108. */
  109. export declare const DEBUG_ASYNC: AsyncBuildVariant;
  110. /**
  111. * This is the default asyncified build variant.
  112. */
  113. export declare const RELEASE_ASYNC: AsyncBuildVariant;