Skip to main content

Module host

Module host 

Source
Expand description

The JavaScript object heap and runtime, reached from fusevm through registered builtins (register_builtin) and the strict numeric hook.

node-js owns no VM and no JIT: the compiler lowers JS to fusevm::Chunk, and every JS-specific operation the VM can’t do natively is a builtin call that lands here. Local variables live in Rc<RefCell> environments chained parent-to-child, so a nested function/closure captures its enclosing scope by reference.

Value representation:

  • immediate: Value::Float (every JS number — one IEEE-754 f64 type), Value::Bool (true/false), Value::Undef (undefined);
  • heap Value::Obj(u32) handles: string, array, object, function, builtin-namespace, and the canonical null — the reference types.

Modules§

binop
Bitwise/shift op tags carried by ops::BINOP (JS ToInt32/ToUint32 rules).
member
DEF_MEMBER member-kind tags.
ops
Builtin ids emitted by the compiler and registered on every VM. The compiler (compiler.rs) and the handler table (builtins.rs::install) must agree on these exactly.
unop
Unary op tags carried by ops::UNARY.

Structs§

ClassVal
A live class constructor. The prototype object (holding instance methods) and the static-side own properties live on the heap; parent is the superclass constructor value (None for a base class).
EnvData
A local-variable environment, shared (by Rc) between a frame and any nested function that captures it.
Frame
One function activation.
FuncDef
A compiled function template: parameter shape + body chunk. Shared by every closure created from the same function/arrow.
FuncVal
A live closure value.
JsHost
The JavaScript runtime.
ParamSlot
One parameter slot. name is the simple bound name; a destructuring pattern is lowered to a synthetic .arg{i} name plus body prologue code.
PromiseCell
A Promise’s settled state and pending reactions.
RegExpObj
A RegExp object: the compiled fancy_regex::Regex plus the JS-visible source, flag booleans, and the mutable lastIndex cursor (used by g/y matching). fancy-regex adds lookaround + backreferences on top of the Rust regex fast path, so the JS grammar node-js can accept is a near-superset.
Timer
A scheduled macrotask (setTimeout/setImmediate). Ordering is by (delay, seq) — a deterministic virtual clock, never wall time.
TryDef
A compiled try/catch/finally block. Bodies are bare chunks run in the current scope.

Enums§

GenStep
Outcome of resuming a generator: a yielded value (not done), or the final completion value (done).
JsObj
A heap object.
MapKey
A Map/Set key under SameValueZero: NaN collapses to one key, -0 and +0 are the same key, primitives compare by value, objects by heap identity.
PromiseReaction
A pending Promise reaction: a user .then (JS handlers + a result promise) or a native continuation (Promise chaining / async await resumption).
PromiseState
Signal
A non-local control signal.
SuperRef
The result of resolving super.name: a getter to invoke (accessor property) or a directly-usable value (method / data property).
Task
A queued unit of work: either a JS callback invocation (queueMicrotask, nextTick, timer body) or a native step (Promise reaction / async resume).

Constants§

ERROR_NAMES
The set of builtin error constructor names forming the error hierarchy.

Functions§

array_index
If k is an array-index property key, return its numeric value. Per ECMAScript, a String property key P is an array index iff ToString(ToUint32(P)) === P and ToUint32(P) !== 2^32 - 1 — i.e. a canonical decimal (no leading zeros, no sign) in the range 0..=2^32-2.
async_step
One step of a for await loop: return a Promise that settles to a {value, done} record. For a native async iterator this is iter.next() (already a promise of the record). For the sync fallback it pops the next raw value, awaits it, and packages {value: resolved, done:false} (or {done:true} at exhaustion).
await_value
The AWAIT op body (runs inside the async coroutine): suspend, yielding the awaited value; on resume, unwrap the settlement packet (throwing on reject).
build_class
Build a class constructor value from its parts. The compiler emits (via MKCLASS) the evaluated parent (or undefined) and the constructor closure (or undefined for a default constructor); methods/getters/setters/statics/fields are installed afterward by DEF_MEMBER/DEF_FIELD.
call_method
recv.name(args).
call_named
Resolve a bare name and call it (f(args), parseInt(args)).
canonicalize_own_keys
Reorder an object’s own-property map into OrdinaryOwnPropertyKeys order in place: array-index keys ascending first, then the remaining keys in their existing (insertion) order. A no-op unless at least one index key is present, so the overwhelmingly common all-string-key object keeps its exact order and pays nothing. IndexMap::sort_by is a stable sort.
construct
Construct an instance with new — creates a fresh object, binds it as this, runs the constructor, and returns the object (unless the constructor returns its own object).
construct_nt
new with an explicit new.target (differs from ctor when a derived class calls super(...) — the target stays the originally-newed class).
define_field
Register an instance-field initializer thunk on a class (DEF_FIELD).
define_member
Install a method / getter / setter on a class (DEF_MEMBER). kind is a member::* tag; is_static targets the constructor side.
error_proto
error_proto_of
Error prototype lookup with a borrowed host (used inside a with_host block).
fmt_number
Format a JS number exactly as Number.prototype.toString does for the common range (no exponential-notation threshold handling for very large/small).
gen_close
Force a generator to completion (used by .return() and abandoned loops): marks it done without running further.
gen_resume
Resume a generator until its next yield or its body returns. Preserves the shared host: the coroutine is taken out so the body re-enters with_host freely, and the volatile context is swapped so the caller’s frames/signal survive the switch.
gen_return
generator.return(v): force the generator to complete, running any pending finally. If it is already done (or never started) it just reports {value:v, done:true} without executing the body.
gen_throw
generator.throw(e): inject a throw at the suspension point, running any pending finally and letting an enclosing try/catch in the body handle it.
gen_yield
yield v — suspend the running generator, handing v to the resumer; returns the value the next gen_resume(x) supplies (a .next(x) argument).
get_async_iterator
Obtain an async iterator for for await. If src has a Symbol.asyncIterator method, use it (its .next() returns a promise of {value, done}); otherwise fall back to the sync iterable, materialized into a JsObj::Iter whose values are awaited one at a time by async_step.
get_prop_chain
Property read that walks the prototype chain (used by iteration helpers).
instance_of
obj instanceof ctor — walk obj’s prototype chain looking for ctor.prototype.
invoke
Call any callable value.
is_callable
Whether h.get(v) is any callable kind.
iter_all
Fully materialize any iterable into a vector of values.
key_order_cmp
Compare two own-property keys for OrdinaryOwnPropertyKeys enumeration order: integer-index keys sort ascending-numeric and precede all string keys; two non-index keys compare Equal so a stable sort leaves them in insertion order. (Symbols are stored as @@…/#… string keys and are non-index, so they also fall into the stable-insertion-order tail.)
lookup_accessor
Find a getter/setter accessor for key on recv or up its prototype chain.
lookup_chain
Walk recv’s own props then its prototype chain for key, returning the stored value (methods, inherited data props). Does NOT invoke accessors.
map_key
Convert a Map/Set key value into a MapKey under SameValueZero.
parse_bigint_str
Parse a string to a BigInt under JS StringToBigInt rules: trimmed, empty → 0n, decimal or 0x/0o/0b prefixed; any junk → None.
promise_of
A promise for v: v itself if it is already a promise, else a promise resolved with v.
promise_then
Register a user .then reaction (JS handlers + result promise).
range_error
ref_error
reject_promise_val
reset_host
Reset the host to a clean slate (fresh module frame).
resolve_promise_val
The Promise “resolve” operation: adopt value’s state if it is a promise, else fulfill with it.
run_chunk_on
Register every node-js builtin + the numeric hook on a VM, then run it.
run_event_loop
Drive the event loop to quiescence.
run_main
Run the top-level program chunk, then drain the event loop (microtasks + timers) until quiescent — matching Node, which keeps the process alive while pending async work remains.
run_user_func
Execute a user function/closure body on a fresh frame.
run_user_func_nt
As run_user_func, but with an explicit new.target (set by new).
set_debug_mode
Enable/disable DAP debug execution (node --dap).
set_error_proto
Register a builtin error prototype (for instanceof Error etc.).
set_inspect_max_depth
Set the util.inspect depth for the next render (restore to 2 after).
subscribe_native
Register a native reaction on promise id (schedules immediately if already settled).
super_construct
Run a parent constructor as part of super(...): dispatch on the parent’s kind (class vs plain function vs builtin) using the existing instance.
take_exc_or_error
The JS value of a just-caught error: the live exc (a real thrown value) or a synthesized Error from the internal message.
to_string_value
ToString(v) with ToPrimitive method dispatch: an object with a user toString (or valueOf) on its prototype chain has it invoked; everything else uses the raw str_of. Returns a heap string value.
type_error
with_host
Run f with mutable access to the thread-local host.

Type Aliases§

Accessor
An accessor property: (getter, setter), either optional.
Env
IoTask
A unit of I/O work handed from a background I/O thread to the main-thread event loop. It is a boxed closure so host.rs stays agnostic of net/http: the I/O thread captures only plain Send data (bytes, ids, TcpStreams) and the closure runs the JS-touching dispatch on the main thread (where the thread-local host lives). I/O threads NEVER touch the host directly.