Skip to main content

Module state

Module state 

Source
Expand description

Runtime and context state: limits, GC, opaque pointers, context values, memory reporting and JS_PrintValue.

§Which of these are real and which are “accepted and recorded”

A limit that the engine does not enforce must not pretend to. JS_SetMemoryLimit and JS_SetMaxStackSize map onto Runtime::set_memory_limit/set_stack_size, which the allocator and the call-depth check already consult — so those are real. JS_SetGCThreshold maps onto the heap’s threshold, also real. JS_SetInterruptHandler is real but only checked where the engine already yields (docs/m15-plan.md §5: not between every opcode), and that limit is stated in the README. JS_SetCanBlock, JS_SetStripInfo and JS_SetRuntimeInfo are recorded and have no observable effect, which is stated at each one.

§Why the memory report is not a fabrication

JS_ComputeMemoryUsage fills a JSMemoryUsage whose fields a C program prints. Filling them with plausible-looking zeros would be worse than filling the ones that are actually known: a host that logs malloc_size and sees 0 knows the number is unavailable, whereas one that sees an invented 4096 believes it.

Every field is now measured by the engine’s own walk (engine::memory::compute), which visits the live heap blocks and downcasts — the same design as the reference’s JS_ComputeMemoryUsage, which walks its object lists. The one field pair left at zero is shape_count/shape_size: this engine has no hidden-class sharing, so there is nothing to count, and JS_DumpMemoryUsage prints it as (not modelled) rather than as a measured zero.

Functions§

JS_ComputeMemoryUsage⚠
JS_ComputeMemoryUsage: fill s with what this runtime occupies.
JS_DumpMemoryUsage⚠
JS_DumpMemoryUsage: print the report to fp.
JS_DupContext⚠
JS_DupContext: raise the context’s reference count and answer the same pointer.
JS_GetContextOpaque⚠
JS_GetContextOpaque.
JS_GetContextValue⚠
JS_GetContextValue: the value at slot idx, or undefined.
JS_GetRuntimeOpaque⚠
JS_GetRuntimeOpaque: the host’s pointer.
JS_GetStripInfo⚠
JS_GetStripInfo: the value last given to JS_SetStripInfo.
JS_HasException⚠
JS_HasException: whether a call left an exception behind.
JS_NewContextRaw⚠
JS_NewContextRaw: a context with no intrinsics installed.
JS_NewRuntime2⚠
JS_NewRuntime2: a runtime with the host’s allocator.
JS_PrintValue⚠
JS_PrintValue: render val through write_func.
JS_PrintValueRT⚠
JS_PrintValueRT: the same, found through a runtime rather than a context.
JS_PrintValueSetDefaultOptions⚠
JS_PrintValueSetDefaultOptions: the options a fresh JSPrintValueOptions should hold.
JS_RunGC⚠
JS_RunGC: collect now.
JS_SetCanBlock⚠
JS_SetCanBlock: whether a blocking operation (a synchronous Atomics.wait) is allowed.
JS_SetContextOpaque⚠
JS_SetContextOpaque.
JS_SetContextValue⚠
JS_SetContextValue: store a value at one of the context’s private slots.
JS_SetGCThreshold⚠
JS_SetGCThreshold: collect once the heap holds threshold bytes.
JS_SetInterruptHandler⚠
JS_SetInterruptHandler: call cb periodically while a script runs.
JS_SetMaxStackSize⚠
JS_SetMaxStackSize: cap the call depth, 0 to disable the check.
JS_SetMemoryLimit⚠
JS_SetMemoryLimit: refuse an allocation that would take the heap past limit bytes.
JS_SetRuntimeInfo⚠
JS_SetRuntimeInfo: a label for diagnostics.
JS_SetRuntimeOpaque⚠
JS_SetRuntimeOpaque.
JS_SetStripInfo⚠
JS_SetStripInfo: record how much debug info to keep.
JS_ThrowInternalError⚠
JS_ThrowInternalError. See JS_ThrowSyntaxError.
JS_ThrowOutOfMemory⚠
JS_ThrowOutOfMemory: raise the engine’s out-of-memory error.
JS_ThrowReferenceError⚠
JS_ThrowReferenceError. See JS_ThrowSyntaxError.
JS_ThrowSyntaxError⚠
JS_ThrowSyntaxError, JS_ThrowTypeError, JS_ThrowReferenceError, JS_ThrowInternalError: the four JS_Throw* spellings not already exported.
JS_ThrowTypeError⚠
JS_ThrowTypeError. See JS_ThrowSyntaxError.
JS_UpdateStackTop⚠
JS_UpdateStackTop: tell the engine where this thread’s stack starts.