Class: QuickJSAsyncRuntime

February 16, 2026 ยท View on GitHub

quickjs-emscripten


quickjs-emscripten / quickjs-emscripten-core / QuickJSAsyncRuntime

Class: QuickJSAsyncRuntime

Defined in: packages/quickjs-emscripten-core/src/runtime-asyncify.ts:25

A runtime represents a Javascript runtime corresponding to an object heap. Several runtimes can exist at the same time but they cannot exchange objects. Inside a given runtime, no multi-threading is supported.

You can think of separate runtimes like different domains in a browser, and the contexts within a runtime like the different windows open to the same domain.

Create a runtime via QuickJSWASMModule.newRuntime.

You should create separate runtime instances for untrusted code from different sources for isolation. However, stronger isolation is also available (at the cost of memory usage), by creating separate WebAssembly modules to further isolate untrusted code. See newQuickJSWASMModule.

Implement memory and CPU constraints with setInterruptHandler (called regularly while the interpreter runs), setMemoryLimit, and setMaxStackSize. Use computeMemoryUsage or dumpMemoryUsage to guide memory limit tuning.

Configure ES module loading with setModuleLoader.

Contents

Extends

Properties

context

context: QuickJSAsyncContext | undefined

Defined in: packages/quickjs-emscripten-core/src/runtime-asyncify.ts:26

If this runtime was created as as part of a context, points to the context associated with the runtime.

If this runtime was created stand-alone, this may or may not contain a context. A context here may be allocated if one is needed by the runtime, eg for computeMemoryUsage.

Overrides

QuickJSRuntime.context

Accessors

alive

Get Signature

get alive(): boolean

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:128

Returns

boolean

true if the object is alive

Inherited from

QuickJSRuntime.alive

Methods

[dispose]()

[dispose](): void

Defined in: packages/quickjs-emscripten-core/src/lifetime.ts:47

Just calls the standard .dispose() method of this class.

Returns

void

Inherited from

QuickJSRuntime.[dispose]


assertOwned()

assertOwned(handle): void

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:330

Assert that handle is owned by this runtime.

Parameters

handle

QuickJSHandle

Returns

void

Throws

QuickJSWrongOwner if owned by a different runtime.

Inherited from

QuickJSRuntime.assertOwned


computeMemoryUsage()

computeMemoryUsage(): QuickJSHandle

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:299

Compute memory usage for this runtime. Returns the result as a handle to a JSValue object. Use QuickJSContext#dump to convert to a native object. Calling this method will allocate more memory inside the runtime. The information is accurate as of just before the call to computeMemoryUsage. For a human-digestible representation, see dumpMemoryUsage.

Returns

QuickJSHandle

Inherited from

QuickJSRuntime.computeMemoryUsage


debugLog()

debugLog(...msg): void

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:366

In debug mode, log the result of calling msg().

We take a function instead of a log message to avoid expensive string manipulation if debug logging is disabled.

Parameters

msg

...unknown[]

Returns

void

Inherited from

QuickJSRuntime.debugLog


dispose()

dispose(): void

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:132

Dispose of the underlying resources used by this object.

Returns

void

Inherited from

QuickJSRuntime.dispose


dumpMemoryUsage()

dumpMemoryUsage(): string

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:310

Returns

string

a human-readable description of memory usage in this runtime. For programmatic access to this information, see computeMemoryUsage.

Inherited from

QuickJSRuntime.dumpMemoryUsage


executePendingJobs()

executePendingJobs(maxJobsToExecute?): ExecutePendingJobsResult

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:246

Execute pendingJobs on the runtime until maxJobsToExecute jobs are executed (default all pendingJobs), the queue is exhausted, or the runtime encounters an exception.

In QuickJS, promises and async functions inside the runtime create pendingJobs. These do not execute immediately and need to triggered to run.

Parameters

maxJobsToExecute?

When negative, run all pending jobs. Otherwise execute at most maxJobsToExecute before returning.

number | void

Returns

ExecutePendingJobsResult

On success, the number of executed jobs. On error, the exception that stopped execution, and the context it occurred in. Note that executePendingJobs will not normally return errors thrown inside async functions or rejected promises. Those errors are available by calling QuickJSContext#resolvePromise on the promise handle returned by the async function.

Inherited from

QuickJSRuntime.executePendingJobs


hasPendingJob()

hasPendingJob(): boolean

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:197

In QuickJS, promises and async functions create pendingJobs. These do not execute immediately and need to be run by calling executePendingJobs.

Returns

boolean

true if there is at least one pendingJob queued up.

Inherited from

QuickJSRuntime.hasPendingJob


isDebugMode()

isDebugMode(): boolean

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:356

Returns

boolean

true if debug logging is enabled

Inherited from

QuickJSRuntime.isDebugMode


newContext()

newContext(options?): QuickJSAsyncContext

Defined in: packages/quickjs-emscripten-core/src/runtime-asyncify.ts:49

Create a new context within this runtime. Contexts have isolated globals, but you can explicitly share objects between contexts with the same runtime.

You should dispose a created context before disposing this runtime.

Parameters

options?

ContextOptions = {}

Returns

QuickJSAsyncContext

Overrides

QuickJSRuntime.newContext


removeInterruptHandler()

removeInterruptHandler(): void

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:222

Remove the interrupt handler, if any. See setInterruptHandler.

Returns

void

Inherited from

QuickJSRuntime.removeInterruptHandler


removeModuleLoader()

removeModuleLoader(): void

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:184

Remove the the loader set by setModuleLoader. This disables module loading.

Returns

void

Inherited from

QuickJSRuntime.removeModuleLoader


setDebugMode()

setDebugMode(enabled): void

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:346

Enable or disable debug logging.

If this module is a DEBUG variant, more logs will be printed from the C code.

Parameters

enabled

boolean

Returns

void

Inherited from

QuickJSRuntime.setDebugMode


setInterruptHandler()

setInterruptHandler(cb): void

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:210

Set a callback which is regularly called by the QuickJS engine when it is executing code. This callback can be used to implement an execution timeout.

The interrupt handler can be removed with removeInterruptHandler.

Parameters

cb

InterruptHandler

Returns

void

Inherited from

QuickJSRuntime.setInterruptHandler


setMaxStackSize()

setMaxStackSize(stackSize): void

Defined in: packages/quickjs-emscripten-core/src/runtime-asyncify.ts:92

Set the max stack size for this runtime in bytes. To remove the limit, set to 0.

Setting this limit also adjusts the global ASYNCIFY_STACK_SIZE for the entire QuickJSAsyncWASMModule. See the pull request for more details.

Parameters

stackSize

number

Returns

void

Overrides

QuickJSRuntime.setMaxStackSize


setMemoryLimit()

setMemoryLimit(limitBytes): void

Defined in: packages/quickjs-emscripten-core/src/runtime.ts:284

Set the max memory this runtime can allocate. To remove the limit, set to -1.

Parameters

limitBytes

number

Returns

void

Inherited from

QuickJSRuntime.setMemoryLimit


setModuleLoader()

setModuleLoader(moduleLoader, moduleNormalizer?): void

Defined in: packages/quickjs-emscripten-core/src/runtime-asyncify.ts:75

Set the loader for EcmaScript modules requested by any context in this runtime.

The loader can be removed with removeModuleLoader.

Parameters

moduleLoader

JSModuleLoaderAsync

moduleNormalizer?

JSModuleNormalizerAsync

Returns

void

Overrides

QuickJSRuntime.setModuleLoader