JavaScript interop helpers for the embedded runtime.

Description

These functions abstract over the embedded JavaScript engine so that scripts and helpers can be bound, invoked, and marshalled without leaking engine‐specific types into the rest of the codebase.

## Implementation Notes (for Python/Lua integrations)

The current implementation uses JerryScript with the following design choices:

### Integer Limitations JerryScript only guarantees 32‐bit integer precision. Values outside the int32 range (approximately ±2 billion) are converted to strings when passed to JavaScript to avoid wraparound bugs. When reading values back, integers that fit in int64 are returned as integers; others remain as doubles.

### DOM ↔ JS Conversion Strategy ‐ Objects: Use lazy Proxy wrappers to avoid infinite recursion from circular references (e.g., Handlebars symbol contexts that reference parent symbols). Properties are converted on‐demand when accessed. ‐ Arrays: Converted eagerly (snapshot semantics) because they rarely contain circular references. This means JS mutations don't affect the original C++ array and vice versa. ‐ Functions: Wrapped bidirectionally so JS can call C++ functions and C++ can invoke JS functions through dom::Function.

### Thread Safety The Context mutex serializes all engine operations. Values can be safely copied across threads; the underlying handle operations are protected.

Types

Name

Description

Array

Lightweight handle to a JavaScript array.

Boolean

Boolean wrapper for JavaScript values.

Context

An instance of a JavaScript interpreter.

Object

Object wrapper for JavaScript values.

Scope

A JavaScript scope

String

String wrapper for JavaScript values.

Value

An ECMAScript value.

Enums

Name

Description

Type

Types of values.

Functions

Name

Description

operator&&

Return the first Value that is not truthy, or the last one.

operator||

Return the first Value that is truthy, or the last one.

registerHelper

Register a JavaScript helper function

swap

Swap two values.

toString

Return value as a string.

operator==

Compare two values for equality.

operator!=

Inequality operators

operator<=>

Compare two values for inequality.

Created with MrDocs