-## Executing JavaScript
+# Executing JavaScript
+
+<!--name=vm-->
You can access this module with:
JavaScript code can be compiled and run immediately or compiled, saved, and run later.
-### vm.runInThisContext(code, [filename])
+## vm.runInThisContext(code, [filename])
`vm.runInThisContext()` compiles `code`, runs it and returns the result. Running
code does not have access to local scope. `filename` is optional, it's used only
and throws an exception.
-### vm.runInNewContext(code, [sandbox], [filename])
+## vm.runInNewContext(code, [sandbox], [filename])
`vm.runInNewContext` compiles `code`, then runs it in `sandbox` and returns the
result. Running code does not have access to local scope. The object `sandbox`
In case of syntax error in `code`, `vm.runInNewContext` emits the syntax error to stderr
and throws an exception.
-### vm.runInContext(code, context, [filename])
+## vm.runInContext(code, context, [filename])
`vm.runInContext` compiles `code`, then runs it in `context` and returns the
result. A (V8) context comprises a global object, together with a set of
In case of syntax error in `code`, `vm.runInContext` emits the syntax error to stderr
and throws an exception.
-### vm.createContext([initSandbox])
+## vm.createContext([initSandbox])
`vm.createContext` creates a new context which is suitable for use as the 2nd argument of a subsequent
call to `vm.runInContext`. A (V8) context comprises a global object together with a set of
build-in objects and functions. The optional argument `initSandbox` will be shallow-copied
to seed the initial contents of the global object used by the context.
-### vm.createScript(code, [filename])
+## vm.createScript(code, [filename])
`createScript` compiles `code` but does not run it. Instead, it returns a
`vm.Script` object representing this compiled code. This script can be run
and throws an exception.
+## Class: Script
+
+A class for running scripts. Returned by vm.createScript.
+
### script.runInThisContext()
Similar to `vm.runInThisContext` but a method of a precompiled `Script` object.