mrdocs::js::Scope

A JavaScript scope for value lifetime management.

Synopsis

Declared in <mrdocs/Support/JavaScript.hpp>

class Scope;

Description

Scope serves two purposes:

1. Value batch tracking: Tracks JavaScript values created within the scope and releases one reference to each when the scope ends. Values that were copied elsewhere (e.g., returned from functions, stored in containers) survive because they hold their own references. Values that remained local to the scope are freed.

2. Thread safety: Each Scope operation briefly locks the Context's mutex and activates the context (sets TLS). This allows multiple threads to share a Context while serializing access to the interpreter. Values obtained from a Scope can be used from other threads; they will acquire the lock as needed.

This provides deterministic cleanup similar to stack‐based engines (Lua, Duktape) while working with JerryScript's reference‐counted heap.

Multiple Scopes can exist for the same Context (even in different threads), but operations are serialized by the Context's mutex.

Member Functions

Name

Description

Scope [constructor]

Constructor.

~Scope [destructor]

Destructor.

compile_function

Compile a script and push results to stack.

compile_script

Compile a script and push results to stack.

eval

Compile and run a expression.

getGlobal

Return a global object if it exists.

getGlobalObject

Return the global object.

pushArray

Push a new array to the stack

pushBoolean

Push a boolean to the stack

pushDouble

Push a double to the stack

pushInteger

Push an integer to the stack

pushObject

Push a new object to the stack

pushString

Push a string to the stack

script

Compile and run a script.

setGlobal

Set a global object.

Created with MrDocs