Class: QuickJSRuntime

February 16, 2026 ยท View on GitHub

quickjs-emscripten


quickjs-emscripten / quickjs-emscripten-core / QuickJSRuntime

Class: QuickJSRuntime

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

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

Extended by

Implements

Properties

context

context: QuickJSContext | undefined

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

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.

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

Implementation of

Disposable.alive

Overrides

UsingDisposable.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

Implementation of

Disposable.[dispose]

Inherited from

UsingDisposable.[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.


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


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


dispose()

dispose(): void

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

Dispose of the underlying resources used by this object.

Returns

void

Implementation of

Disposable.dispose

Overrides

UsingDisposable.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.


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.


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.


isDebugMode()

isDebugMode(): boolean

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

Returns

boolean

true if debug logging is enabled


newContext()

newContext(options?): QuickJSContext

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

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

QuickJSContext


removeInterruptHandler()

removeInterruptHandler(): void

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

Remove the interrupt handler, if any. See setInterruptHandler.

Returns

void


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


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


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


setMaxStackSize()

setMaxStackSize(stackSize): void

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

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

Parameters

stackSize

number

Returns

void


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


setModuleLoader()

setModuleLoader(moduleLoader, moduleNormalizer?): void

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

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

The loader can be removed with removeModuleLoader.

Parameters

moduleLoader

JSModuleLoader

moduleNormalizer?

JSModuleNormalizer

Returns

void