# js


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


### cycle_hook(callback) <sub>function</sub>


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() <sub>function</sub>


Use this for internal debugging of object shapes.


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


### dump_atoms() <sub>function</sub>


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() <sub>function</sub>


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() <sub>function</sub>


useful for debugging memory leaks or object lifetimes.


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


### dump_type_overheads() <sub>function</sub>


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() <sub>function</sub>


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) <sub>function</sub>



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() <sub>function</sub>


including total allocated bytes, object counts, and more.

Retrieve an overview of the runtime’s memory usage.


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


### mem_limit(bytes) <sub>function</sub>



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) <sub>function</sub>



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) <sub>function</sub>



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() <sub>function</sub>



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() <sub>function</sub>



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


**Returns**: None


### eval(src, filename) <sub>function</sub>



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.

