Files
prosperon/docs/api/modules/js.md
John Alanbrook 83b798e365 Add Hugo website and rewrite docs to match current engine
New Hugo site in website/ with prosperon.dev theme (blue/gold/castle
aesthetic), docs sidebar navigation, and content pages. Rewrote all
doc files to align with the actual codebase: compositor+film2d
rendering, use() modules (no global prosperon object), Pit language,
script+JSON entity model. Added entities.md, front matter to all
70+ API docs, and updated API index for current module architecture.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:09:55 -06:00

3.7 KiB
Raw Blame History

title, type
title type
js docs

js

Provides functions for introspecting and configuring the QuickJS runtime engine. Includes debug info, memory usage, GC controls, code evaluation, etc.

cycle_hook(callback) function

or undefined to remove the callback.

Register or remove a hook function that QuickJS calls once per execution cycle. If the callback is set, it receives a single argument (an optional object/value describing the cycle). If callback is undefined, the hook is removed.

callback: A function to call each time QuickJS completes a "cycle" (internal VM loop),

Returns: None

dump_shapes() function

Use this for internal debugging of object shapes.

Returns: A debug string describing the internal shape hierarchy used by QuickJS.

dump_atoms() function

known by QuickJS. Helpful for diagnosing memory usage or potential key collisions.

Returns: A debug string listing all currently registered atoms (internal property keys/symbols)

dump_class() function

Shows how many objects of each class exist, useful for advanced memory or performance profiling.

Returns: A debug string describing the distribution of JS object classes in the QuickJS runtime.

dump_objects() function

useful for debugging memory leaks or object lifetimes.

Returns: A debug string listing certain internal QuickJS objects and their references,

dump_type_overheads() function

Displays memory usage breakdown for different internal object types.

Returns: A debug string describing the overheads for various JS object types in QuickJS.

stack_info() function

Internal debugging utility to examine call stack details.

Returns: An object or string describing the runtime's current stack usage and capacity.

calc_mem(value) function

Compute the approximate size of a single JS value in memory. This is a best-effort estimate.

value: A JavaScript value to analyze.

Returns: Approximate memory usage (in bytes) of that single value.

mem() function

including total allocated bytes, object counts, and more.

Retrieve an overview of the runtimes memory usage.

Returns: An object containing a comprehensive snapshot of memory usage for the current QuickJS runtime,

mem_limit(bytes) function

Set the upper memory limit for the QuickJS runtime. Exceeding this limit may cause operations to fail or throw errors.

bytes: The maximum memory (in bytes) QuickJS is allowed to use.

Returns: None

gc_threshold(bytes) function

Set the threshold (in bytes) for QuickJS to perform an automatic GC pass when memory usage surpasses it.

bytes: The threshold (in bytes) at which the engine triggers automatic garbage collection.

Returns: None

max_stacksize(bytes) function

Set the maximum stack size for QuickJS. If exceeded, the runtime may throw a stack overflow error.

bytes: The maximum allowed stack size (in bytes) for QuickJS.

Returns: None

memstate() function

Gives a quick overview of the memory usage, including malloc size and other allocations.

Returns: A simpler memory usage object (malloc sizes, etc.) for the QuickJS runtime.

gc() function

Force an immediate, full garbage collection pass, reclaiming unreachable memory.

Returns: None

eval(src, filename) function

Execute a string of JavaScript code in the current QuickJS context.

src: A string of JavaScript source code to evaluate.

filename: (Optional) A string for the filename or label, used in debugging or stack traces.

Returns: The result of evaluating the given source code.