node:vm stellt APIs zur Skriptkompilierung und für Kontexte in der Form von Node
bereit.
Ein Kontext ist keine Sicherheitsgrenze. Intrinsics werden mit dem Host-Realm geteilt. Verwenden Sie für nicht vertrauenswürdigen Code Prozess- und Dateisystemisolation.
| Export | Zweck |
|---|---|
Script | Code kompilieren und in diesem Kontext oder einem Sandbox-Kontext ausführen. |
createContext() / isContext() | Ein Objekt kontextualisieren und seine Markierung prüfen. |
compileFunction() | Einen Funktionsrumpf kompilieren. |
runInThisContext() | Im aktuellen globalen Gültigkeitsbereich auswerten. |
runInContext() | Gegen ein kontextualisiertes Objekt auswerten. |
runInNewContext() | Gegen ein neues Sandbox-Objekt auswerten. |
measureMemory() | Ein Promise für ein Speicherergebnis zurückgeben. |
constants | VM-Konstanten. |
const vm = require("node:vm");
const sandbox = { x: 2 };
vm.createContext(sandbox);
vm.runInContext("x + 3", sandbox); // 5SourceTextModule stellt nur einen eingeschränkten Lebenszyklus bereit und bietet
kein vollständiges Verknüpfen und Auswerten von Modulen.
Siehe auch
Reference
Status: Full · 80 of 95 suite tests pass (84.2%) · since 1.1.0
Exports
| Export | Kind | Status | Notes |
|---|---|---|---|
Script | class | Full | runInThisContext(), runInNewContext() |
createContext() | function | Full | Creates a new execution context (sandbox) |
runInNewContext() | function | Full | Compiles code, creates a new context, and runs the code in that context |
runInThisContext() | function | Full | Compiles and runs code within the current global context |
isContext() | function | Full | Returns whether the given object is a contextified sandbox |
Tests: node-api node:vm: 80 pass, 15 fail, 0 error, 3 skipped. Failing: test-vm-basic.js, test-vm-codegen.js, test-vm-context-dont-contextify.js, test-vm-function-declaration.js, test-vm-global-property-prototype.js, test-vm-global-setter.js, test-vm-harmony-symbols.js, test-vm-module-after-evaluate.js, and 7 more.