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 canonicalnull— the reference types.
Modules§
- binop
- Bitwise/shift op tags carried by
ops::BINOP(JS ToInt32/ToUint32 rules). - member
DEF_MEMBERmember-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§
- Class
Val - A live class constructor. The prototype object (holding instance methods) and
the static-side own properties live on the heap;
parentis the superclass constructor value (Nonefor 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.
- Param
Slot - One parameter slot.
nameis the simple bound name; a destructuring pattern is lowered to a synthetic.arg{i}name plus body prologue code. - Promise
Cell - A Promise’s settled state and pending reactions.
- RegExp
Obj - A
RegExpobject: the compiledfancy_regex::Regexplus the JS-visible source, flag booleans, and the mutablelastIndexcursor (used byg/ymatching). fancy-regex adds lookaround + backreferences on top of the Rustregexfast 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/finallyblock. 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/Setkey under SameValueZero:NaNcollapses to one key,-0and+0are the same key, primitives compare by value, objects by heap identity. - Promise
Reaction - A pending Promise reaction: a user
.then(JS handlers + a result promise) or a native continuation (Promise chaining / asyncawaitresumption). - Promise
State - Signal
- A non-local control signal.
- Super
Ref - 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
kis an array-index property key, return its numeric value. Per ECMAScript, a String property keyPis an array index iffToString(ToUint32(P)) === PandToUint32(P) !== 2^32 - 1— i.e. a canonical decimal (no leading zeros, no sign) in the range0..=2^32-2. - async_
step - One step of a
for awaitloop: return a Promise that settles to a{value, done}record. For a native async iterator this isiter.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 byDEF_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
OrdinaryOwnPropertyKeysorder 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_byis a stable sort. - construct
- Construct an instance with
new— creates a fresh object, binds it asthis, runs the constructor, and returns the object (unless the constructor returns its own object). - construct_
nt newwith an explicitnew.target(differs fromctorwhen a derived class callssuper(...)— 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).kindis amember::*tag;is_statictargets the constructor side. - error_
proto - error_
proto_ of - Error prototype lookup with a borrowed host (used inside a
with_hostblock). - fmt_
number - Format a JS number exactly as
Number.prototype.toStringdoes 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
yieldor its body returns. Preserves the shared host: the coroutine is taken out so the body re-enterswith_hostfreely, 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 pendingfinally. 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 pendingfinallyand letting an enclosingtry/catchin the body handle it.- gen_
yield yield v— suspend the running generator, handingvto the resumer; returns the value the nextgen_resume(x)supplies (a.next(x)argument).- get_
async_ iterator - Obtain an async iterator for
for await. Ifsrchas aSymbol.asyncIteratormethod, use it (its.next()returns a promise of{value, done}); otherwise fall back to the sync iterable, materialized into aJsObj::Iterwhose values are awaited one at a time byasync_step. - get_
prop_ chain - Property read that walks the prototype chain (used by iteration helpers).
- instance_
of obj instanceof ctor— walkobj’s prototype chain looking forctor.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
OrdinaryOwnPropertyKeysenumeration order: integer-index keys sort ascending-numeric and precede all string keys; two non-index keys compareEqualso 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
keyonrecvor up its prototype chain. - lookup_
chain - Walk
recv’s own props then its prototype chain forkey, returning the stored value (methods, inherited data props). Does NOT invoke accessors. - map_key
- Convert a Map/Set key value into a
MapKeyunder SameValueZero. - parse_
bigint_ str - Parse a string to a BigInt under JS
StringToBigIntrules: trimmed, empty →0n, decimal or0x/0o/0bprefixed; any junk →None. - promise_
of - A promise for
v:vitself if it is already a promise, else a promise resolved withv. - promise_
then - Register a user
.thenreaction (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 explicitnew.target(set bynew). - set_
debug_ mode - Enable/disable DAP debug execution (
node --dap). - set_
error_ proto - Register a builtin error prototype (for
instanceof Erroretc.). - set_
inspect_ max_ depth - Set the
util.inspectdepth 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 synthesizedErrorfrom the internal message. - to_
string_ value ToString(v)withToPrimitivemethod dispatch: an object with a usertoString(orvalueOf) on its prototype chain has it invoked; everything else uses the rawstr_of. Returns a heap string value.- type_
error - with_
host - Run
fwith 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.rsstays agnostic ofnet/http: the I/O thread captures only plainSenddata (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.