index.d.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import type { QuickJSWASMModule } from "./module";
  2. import type { QuickJSRuntime, InterruptHandler } from "./runtime";
  3. import type { QuickJSContext } from "./context";
  4. export type { QuickJSWASMModule, QuickJSContext, QuickJSRuntime };
  5. import type { QuickJSAsyncWASMModule } from "./module-asyncify";
  6. import type { QuickJSAsyncRuntime } from "./runtime-asyncify";
  7. import type { QuickJSAsyncContext, AsyncFunctionImplementation } from "./context-asyncify";
  8. import { AsyncRuntimeOptions, ContextOptions } from "./types";
  9. export type { QuickJSAsyncContext, QuickJSAsyncRuntime, QuickJSAsyncWASMModule, AsyncFunctionImplementation, };
  10. import { newQuickJSWASMModule, newQuickJSAsyncWASMModule, DEBUG_ASYNC, DEBUG_SYNC, RELEASE_ASYNC, RELEASE_SYNC, SyncBuildVariant, AsyncBuildVariant } from "./variants";
  11. export { newQuickJSWASMModule, newQuickJSAsyncWASMModule, DEBUG_ASYNC, DEBUG_SYNC, RELEASE_ASYNC, RELEASE_SYNC, SyncBuildVariant, AsyncBuildVariant, };
  12. export * from "./vm-interface";
  13. export * from "./lifetime";
  14. /** Collects the informative errors this library may throw. */
  15. export * as errors from "./errors";
  16. export * from "./deferred-promise";
  17. export * from "./module-test";
  18. export type { StaticJSValue, JSValueConst, JSValue, QuickJSHandle, ContextOptions, ContextEvalOptions, RuntimeOptions, AsyncRuntimeOptions, RuntimeOptionsBase, JSModuleLoader, JSModuleLoadResult, JSModuleLoaderAsync, JSModuleLoadSuccess, JSModuleLoadFailure, JSModuleNormalizer, JSModuleNormalizerAsync, JSModuleNormalizeResult, JSModuleNormalizeFailure, JSModuleNormalizeSuccess, } from "./types";
  19. export type { ModuleEvalOptions } from "./module";
  20. export type { InterruptHandler, ExecutePendingJobsResult } from "./runtime";
  21. export type { QuickJSPropertyKey } from "./context";
  22. /**
  23. * Get a shared singleton {@link QuickJSWASMModule}. Use this to evaluate code
  24. * or create Javascript environments.
  25. *
  26. * This is the top-level entrypoint for the quickjs-emscripten library.
  27. *
  28. * If you need strictest possible isolation guarantees, you may create a
  29. * separate {@link QuickJSWASMModule} via {@link newQuickJSWASMModule}.
  30. *
  31. * To work with the asyncified version of this library, see these functions:
  32. *
  33. * - {@link newAsyncRuntime}.
  34. * - {@link newAsyncContext}.
  35. * - {@link newQuickJSAsyncWASMModule}.
  36. */
  37. export declare function getQuickJS(): Promise<QuickJSWASMModule>;
  38. /**
  39. * Provides synchronous access to the shared {@link QuickJSWASMModule} instance returned by {@link getQuickJS}, as long as
  40. * least once.
  41. * @throws If called before `getQuickJS` resolves.
  42. */
  43. export declare function getQuickJSSync(): QuickJSWASMModule;
  44. /**
  45. * Create a new [[QuickJSAsyncRuntime]] in a separate WebAssembly module.
  46. *
  47. * Each runtime is isolated in a separate WebAssembly module, so that errors in
  48. * one runtime cannot contaminate another runtime, and each runtime can execute
  49. * an asynchronous action without conflicts.
  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 newAsyncRuntime(options?: AsyncRuntimeOptions): Promise<QuickJSAsyncRuntime>;
  56. /**
  57. * Create a new [[QuickJSAsyncContext]] (with an associated runtime) in an
  58. * separate WebAssembly module.
  59. *
  60. * Each context is isolated in a separate WebAssembly module, so that errors in
  61. * one runtime cannot contaminate another runtime, and each runtime can execute
  62. * an asynchronous action without conflicts.
  63. *
  64. * Note that there is a hard limit on the number of WebAssembly modules in older
  65. * versions of v8:
  66. * https://bugs.chromium.org/p/v8/issues/detail?id=12076
  67. */
  68. export declare function newAsyncContext(options?: ContextOptions): Promise<QuickJSAsyncContext>;
  69. /**
  70. * Returns an interrupt handler that interrupts Javascript execution after a deadline time.
  71. *
  72. * @param deadline - Interrupt execution if it's still running after this time.
  73. * Number values are compared against `Date.now()`
  74. */
  75. export declare function shouldInterruptAfterDeadline(deadline: Date | number): InterruptHandler;