js
Run JavaScript through a Node.js subprocess.
Backend: native — stdlib/js.so, built from stdlib/js.cpp. Import: import("js") → global.js.*
Requires node on PATH; when it is missing, every runner returns "Error: node not found on PATH". A program is killed after a timeout (LYNXER_JS_TIMEOUT seconds, default 30) and answers "Error: node timed out after <n>s"; a program's stderr is captured into the result rather than inherited. A non-zero exit with no output reports "Error: node exited with status <n>". Source strings run through node -e without creating a script file. The timeout kills the command's process group, including subprocesses it started.
| Function | Signature | Notes |
|---|---|---|
runJS | (str code) -> str | Writes the code to a temporary .js file, runs it, returns stdout |
runJSFile | (str path) -> str | Runs a .js file and returns stdout |
evalJS | (str expr) -> str | Wraps expr in console.log(...), returns the trimmed result |
nodeVersion | () -> str | node --version, or "" |
nodeExists | () -> int | 1 when node runs |
Example
global setup(){ import("js"); }
global main(){
println(global.js.evalJS("1 + 2"));
println(global.js.runJS("console.log('hello from js');"));
}
See also
- stdlib-contracts — the contract this module implements, including the error sentinel family it uses.
- builtins — the functions the interpreter implements itself.
- limitations — the full divergence register.