Expand description
Node vm module — code compilation and evaluation reusing node-js’s own
engine.
Fidelity and honesty about scope: node-js runs on a single global heap with
one set of module-level globals (see host::JsHost). It has NO facility for a
second, isolated global object, so vm here provides genuine evaluation
but NOT the context isolation Node’s vm is designed around:
runInThisContext(code)— REAL: compilescodeand runs it on the current host through the exactcompile→load_merged→run_chunk_onpath the module loader and REPL use, returning the completion value (the value of the last expression). Code sees and mutates the current globals — which is precisely whatrunInThisContextis supposed to do.runInNewContext(code[, sandbox])— NOT ISOLATED (documented): there is no separate global object to create. As a pragmatic contextify emulation, the sandbox’s own properties are merged into the shared global scope before the run and copied back into the sandbox object afterward, so the commonrunInNewContext(src, sandbox)read/write pattern works. It does NOT hide the surrounding globals and does NOT restore them — this is stated plainly, never claimed as isolation.createContext(obj)— no-op passthrough: returnsobj(or a fresh object). node-js has no distinct context to contextify; this exists socreateContextcall sites don’t throw.isContext(obj)— returnstruefor any object (everything shares the one context here).Script— a compiled-code holder (@@native = "Script"):new Script(code)stores the source;.runInThisContext()/.runInNewContext([sandbox])run it on demand via the same paths as the free functions.
Constants§
- METHODS
- SCRIPT_
METHODS - Methods dispatched on an
@@native = "Script"object (reported to the parent forinstance_has_methodwiring).
Functions§
- call
- construct
new vm.Script(code)→ a Script object holding the source.- instance_
call - Dispatch a method on a Script instance (
@@native = "Script").