Skip to main content

Runtime Configuration

These functions allow you to configure runtime properties and attach custom data to a runtime instance.

JS_SetRuntimeInfo

Sets an informational string for the runtime.

Parameters

JSRuntime *
required
The runtime to configure.
const char *
required
Informational string describing the runtime. The pointer must remain valid for the lifetime of the runtime.

Description

Attaches a descriptive string to the runtime for debugging or identification purposes. This is useful when working with multiple runtimes to distinguish them in logs or debugging output.
The info string is not copied - the pointer is stored directly. You must ensure the string remains valid for the entire lifetime of the runtime. The string should typically be a string literal or statically allocated.

Example


JS_SetRuntimeOpaque

Attaches custom user data to a runtime.

Parameters

JSRuntime *
required
The runtime to attach data to.
void *
Pointer to user-defined data. Can be NULL.

Description

Stores a user-defined pointer in the runtime. This is useful for:
  • Associating application-specific data with the runtime
  • Passing context information to C functions
  • Implementing runtime-specific callbacks
  • Storing configuration or state data
The runtime does not manage this pointer - you are responsible for its lifecycle.

Example


JS_GetRuntimeOpaque

Retrieves custom user data from a runtime.

Parameters

JSRuntime *
required
The runtime to retrieve data from.

Returns

void *
The user-defined pointer previously set with JS_SetRuntimeOpaque(), or NULL if none was set.

Description

Retrieves the opaque pointer associated with a runtime. This is typically used in C functions to access application-specific context or state.

Example

Common Use Cases