Skip to main content

Module repl

Module repl 

Source
Expand description

Node repl module — repl.start([options]).

node-js ALREADY has a real interactive REPL: crate::repl::run() (see src/repl.rs), the reedline-based loop that node --repl (and bare node on a TTY) drives from main.rs. It keeps one persistent host across lines, accumulates continuation lines while delimiters stay open, and evaluates each buffer via crate::compile + crate::run_compiled. repl.start() delegates straight to that loop — it is the SAME real REPL, not a reimplementation.

repl.start() blocks on stdin exactly like Node’s: it hands control to the interactive loop and only returns at EOF (Ctrl-D). This matches Node, where repl.start() is normally the terminal action of a REPL-launcher script.

LIMITATION (documented, never faked): crate::repl::run() calls host::reset_host() and drives its own fresh persistent host, so lines typed at the prompt do NOT see variables from the script that called start(), and heap handles created before start() are not shared with the interactive session. start() is therefore intended as the program’s final statement (the launcher pattern), which is how it is used in practice.

The returned REPLServer is a plain object tagged @@native = "REPLServer" carrying the resolved prompt/input/output/useColors options for fidelity and a hidden @@listeners map. Its close/on/once/write/ setPrompt methods dispatch through instance_call — BUT ONLY IF the parent stdlib::mod wires the "REPLServer" tag into instance_has_method + instance_call (see the report). Because start() has already returned from the (finished) interactive loop by the time these could be called, they are best-effort post-hoc no-ops: close fires any stored 'exit' listeners, on/once store the listener and return this, write writes to stdout.

Constants§

METHODS
REPLSERVER_METHODS
Methods dispatched on an @@native = "REPLServer" object (reported to the parent for instance_has_method / instance_call wiring). Without that wiring a property read of these names yields undefined.

Functions§

call
constant
A non-function member of the repl namespace, reachable via namespace_property IF the parent routes "repl" into stdlib::constant.
construct
new repl.REPLServer([options]) / new repl.Recoverable(err).
instance_call
Dispatch a method on a REPLServer instance (@@native = "REPLServer"). The interactive loop has already exited by the time these run, so they are best-effort. Requires parent wiring of the "REPLServer" tag to be reachable.