Sign in

    dowdiness/js_engine/interpreter does not have a README file

    JsException

    pub suberror JsException {
    JsException(Value)
    }

    ArrayData

    pub(all) struct ArrayData {
    elements : Array[Value]
    }

    Binding

    type Binding

    BindingKind

    pub(all) enum BindingKind {
    LetBinding
    ConstBinding
    VarBinding
    }

    impl Eq for BindingKind
    impl Show for BindingKind

    Callable

    pub(all) enum Callable {
    UserFunc(FuncData)
    ArrowFunc(FuncData)
    UserFuncExt(FuncDataExt)
    ArrowFuncExt(FuncDataExt)
    NativeCallable(String, (Array[Value]) -> Value raise)
    NonConstructableCallable(String, (Array[Value]) -> Value raise)
    BoundFunc(Value, Value, Array[Value])
    FuncCallMethod(Value)
    FuncApplyMethod(Value)
    MethodCallable(String, (Value, Array[Value]) -> Value raise)
    InterpreterCallable(String, (Interpreter, Value, Array[Value]) -> Value raise)
    ConstructorOnlyCallable(String, (Interpreter, Array[Value]) -> Value raise)
    ClassConstructor(String, Value, Value?, (Array[String], Array[
    Stmt
    ])?, Environment, Value)
    }

    Environment

    pub(all) struct Environment {
    bindings : Map[String, Binding]
    parent : Environment?
    }

    Environment::assign

    fn Environment::assign(self : Environment, name : String, value : Value) -> Unit raise

    Environment::def

    fn Environment::def(self : Environment, name : String, value : Value, kind : BindingKind) -> Unit raise

    Environment::def_builtin

    fn Environment::def_builtin(self : Environment, name : String, value : Value) -> Unit

    Environment::def_tdz

    fn Environment::def_tdz(self : Environment, name : String, kind : BindingKind) -> Unit raise

    Define a TDZ binding (let/const before initialization)

    Environment::get

    fn Environment::get(self : Environment, name : String) -> Value raise

    Environment::has

    fn Environment::has(self : Environment, name : String) -> Bool

    Environment::initialize

    fn Environment::initialize(self : Environment, name : String, value : Value) -> Unit raise

    Initialize a TDZ binding (when declaration is executed)

    Environment::new

    fn Environment::new(parent? : Environment?) -> Environment

    FuncData

    pub(all) struct FuncData {
    name : String?
    params : Array[String]
    body : Array[
    Stmt
    ]
    closure : Environment
    }

    FuncDataExt

    pub(all) struct FuncDataExt {
    name : String?
    params : Array[
    Param
    ]
    rest_param : String?
    body : Array[
    Stmt
    ]
    closure : Environment
    }

    Interpreter

    pub(all) struct Interpreter {
    output : Array[String]
    global : Environment
    global_this : Value
    strict : Bool
    microtask_queue : Array[Microtask]
    timer_queue : Array[TimerTask]
    timer_id_counter : Ref[Int]
    timer_insertion_counter : Ref[Int]
    cancelled_timer_ids : Map[Int, Bool]
    }

    Interpreter::enqueue_microtask

    fn Interpreter::enqueue_microtask(self : Interpreter, callback : Value, args : Array[Value]) -> Unit

    Enqueue a microtask to be executed when the current execution context completes This implements HostEnqueuePromiseJob from the ECMAScript spec

    Interpreter::new

    Interpreter::run

    Interpreter::run_microtasks

    fn Interpreter::run_microtasks(self : Interpreter) -> Unit raise

    Run all pending microtasks until the queue is empty This is called after each task (script execution) completes Implements the microtask checkpoint from WHATWG Event Loop spec

    Interpreter::run_timers

    fn Interpreter::run_timers(self : Interpreter) -> Unit raise

    Run the event loop: process all pending timer tasks with microtask checkpoints between each (per WHATWG event loop spec). Timers are sorted by (delay, insertion_order) so they fire in the correct relative order. After each timer callback, microtasks are drained before the next timer fires.

    For setInterval, the timer is re-enqueued after each invocation until cancelled. A safety limit prevents infinite loops.

    MapData

    pub(all) struct MapData {
    entries : Array[(Value, Value)]
    }

    Map data structure - stores key-value pairs with insertion order preservation Uses SameValueZero for key comparison (NaN === NaN, +0 === -0)

    Microtask

    pub(all) struct Microtask {
    callback : Value
    args : Array[Value]
    }

    Microtask record for the event loop microtask queue Stores a callback function and argument list to pass to it

    ObjectData

    pub(all) struct ObjectData {
    properties : Map[String, Value]
    symbol_properties : Map[Int, Value]
    prototype : Value
    callable : Callable?
    class_name : String
    descriptors : Map[String, PropDescriptor]
    symbol_descriptors : Map[Int, PropDescriptor]
    extensible : Bool
    }

    PromiseData

    pub(all) struct PromiseData {
    state : PromiseState
    result : Value
    fulfill_reactions : Array[PromiseReaction]
    reject_reactions : Array[PromiseReaction]
    is_handled : Bool
    properties : Map[String, Value]
    symbol_properties : Map[Int, Value]
    }

    Promise data structure per ECMAScript spec Promises have a state, result value, and queues of pending reactions

    PromiseReaction

    pub(all) struct PromiseReaction {
    handler : Value?
    resolve : Value
    reject : Value
    reaction_type : PromiseReactionType
    }

    Promise reaction record - stores callbacks for promise resolution Each reaction contains the handler (onFulfilled or onRejected) and the dependent promise's resolve/reject capabilities

    PromiseReactionType

    pub(all) enum PromiseReactionType {
    Fulfill
    Reject
    }

    PromiseState

    pub(all) enum PromiseState {
    Pending
    Fulfilled
    Rejected
    }

    Promise state per ECMAScript spec

    PropDescriptor

    pub(all) struct PropDescriptor {
    writable : Bool
    enumerable : Bool
    configurable : Bool
    }

    RegexMatch

    type RegexMatch

    SetData

    pub(all) struct SetData {
    values : Array[Value]
    }

    Set data structure - stores unique values with insertion order preservation Uses SameValueZero for value comparison (NaN === NaN, +0 === -0)

    Signal

    pub(all) enum Signal {
    Normal(Value)
    ReturnSignal(Value)
    BreakSignal(String?)
    ContinueSignal(String?)
    }

    SymbolData

    pub(all) struct SymbolData {
    id : Int
    description : String?
    }

    Symbol data structure - each symbol has a unique ID and optional description

    TimerTask

    pub(all) struct TimerTask {
    id : Int
    callback : Value
    args : Array[Value]
    delay : Int
    period : Int
    cancelled : Bool
    is_interval : Bool
    insertion_order : Int
    }

    Timer task for setTimeout/setInterval (task queue per WHATWG spec) Timers are processed one at a time with microtask checkpoints between each

    Value

    pub(all) enum Value {
    Number(Double)
    String_(String)
    Bool(Bool)
    Null
    Undefined
    Object(ObjectData)
    Array(ArrayData)
    Symbol(SymbolData)
    Map(MapData)
    Set(SetData)
    Promise(PromiseData)
    }

    impl Show for Value

    get_array_like_element

    fn get_array_like_element(val : Value, index : Int) -> Value

    Get indexed element from array-like value

    get_array_method

    fn get_array_method(data : ArrayData, prop : String) -> Value

    get_array_method_with_interp

    fn get_array_method_with_interp(data : ArrayData, prop : String) -> Value

    get_hasinstance_symbol

    fn get_hasinstance_symbol() -> SymbolData

    Get the well-known Symbol.hasInstance

    get_iterator_symbol

    fn get_iterator_symbol() -> SymbolData

    Get the well-known Symbol.iterator

    get_map_method

    fn get_map_method(_data : MapData, prop : String) -> Value

    Get Map.prototype methods for a Map instance

    get_number_method

    fn get_number_method(num_val : Value, prop : String) -> Value

    get_promise_method

    fn get_promise_method(_data : PromiseData, prop : String) -> Value

    Get Promise.prototype methods for a Promise instance

    get_set_method

    fn get_set_method(_data : SetData, prop : String) -> Value

    Get Set.prototype methods for a Set instance

    get_string_method

    fn get_string_method(s : String, prop : String) -> Value

    get_symbol_by_id

    fn get_symbol_by_id(id : Int) -> SymbolData?

    Get a symbol by its ID

    has_array_like_element

    fn has_array_like_element(val : Value, index : Int) -> Bool

    Check if array-like value has indexed property

    is_js_catchable_error

    fn is_js_catchable_error(err : Error) -> Bool

    Check if an error is a JavaScript catchable error

    is_truthy

    fn is_truthy(val : Value) -> Bool

    js_error_to_throw_value

    fn js_error_to_throw_value(err : Error) -> Value

    Convert a catchable error to the JS throw value used by this interpreter. Runtime engine errors are surfaced as strings like "TypeError: ...".

    js_error_to_value

    fn js_error_to_value(err : Error) -> Value

    Convert any catchable error to a JavaScript Error object Value

    js_error_to_value_with_env

    fn js_error_to_value_with_env(err : Error, env : Environment?) -> Value

    Convert any catchable error to a JavaScript Error object Value with proper prototype

    make_array_iterator_value

    fn make_array_iterator_value(arr : ArrayData) -> Value

    Create an array iterator object that iterates over array elements

    make_func

    fn make_func(data : FuncData) -> Value

    make_func_ext

    fn make_func_ext(data : FuncDataExt) -> Value

    make_native_func

    fn make_native_func(name : String, func : (Array[Value]) -> Value raise) -> Value

    make_object

    fn make_object(properties : Map[String, Value], prototype : Value, callable : Callable?, class_name : String, descriptors : Map[String, PropDescriptor], extensible : Bool) -> Value

    Helper to create a basic object with default empty symbol maps

    make_plain_object

    fn make_plain_object() -> Value

    Helper to create a plain object

    make_regexp_object

    fn make_regexp_object(pattern : String, flags : String) -> Value

    make_string_iterator_value

    fn make_string_iterator_value(s : String) -> Value

    Create a string iterator object that iterates over string characters Handles Unicode surrogate pairs correctly per ES6 spec

    new_promise_data

    fn new_promise_data() -> PromiseData

    Create a new pending promise data structure

    new_symbol

    fn new_symbol(description : String?) -> SymbolData

    Create a new symbol with a unique ID

    regex_match_at

    fn regex_match_at(pattern : String, flags : String, input : String, start_pos : Int) -> RegexMatch? raise

    fn regex_search(pattern : String, flags : String, input : String) -> RegexMatch? raise

    regex_search_all

    fn regex_search_all(pattern : String, flags : String, input : String) -> Array[RegexMatch] raise

    same_value

    fn same_value(a : Value, b : Value) -> Bool

    same_value_zero

    fn same_value_zero(a : Value, b : Value) -> Bool

    setup_builtins

    fn setup_builtins(env : Environment, output : Array[String]) -> Unit

    setup_map_set_builtins

    fn setup_map_set_builtins(env : Environment) -> Unit

    Setup Map and Set constructors and prototypes

    setup_object_builtins

    fn setup_object_builtins(env : Environment) -> Unit

    setup_promise

    fn setup_promise(env : Environment) -> Unit

    Setup Promise constructor and prototype methods

    setup_string_prototype

    fn setup_string_prototype(string_proto : Value) -> Unit

    Populate String.prototype with all string methods

    setup_timers

    fn setup_timers(env : Environment) -> Unit

    Setup timer builtins: setTimeout, clearTimeout, setInterval, clearInterval These implement the WHATWG Timer APIs Reference: https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers

    strict_equal_val

    fn strict_equal_val(a : Value, b : Value) -> Bool

    string_match_regex

    fn string_match_regex(s : String, pattern : String, flags : String) -> Value

    string_replace_regex

    fn string_replace_regex(s : String, pattern : String, flags : String, replacement : String) -> Value

    string_search_regex

    fn string_search_regex(s : String, pattern : String, flags : String) -> Value

    this_to_string

    fn this_to_string(this_val : Value) -> String raise

    Extract string from a this value (for String.prototype methods called via .call())

    to_array_like_length

    fn to_array_like_length(val : Value) -> Int

    ToLength: Get length from any value as per ECMAScript spec (array-like objects)

    to_int32

    fn to_int32(n : Double) -> Int

    to_number

    fn to_number(val : Value) -> Double raise

    type_of

    fn type_of(val : Value) -> String

    well_known_hasinstance_sym

    let well_known_hasinstance_sym : Ref[SymbolData?]

    Well-known Symbol.hasInstance - stored globally for instanceof operator support

    well_known_iterator_sym

    let well_known_iterator_sym : Ref[SymbolData?]

    Well-known Symbol.iterator - stored globally for iterator protocol support

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io