1
- ## Executing JavaScript
1
+ # Executing JavaScript
2
+
3
+ <!-- name=vm-->
2
4
3
5
You can access this module with:
4
6
@@ -7,7 +9,7 @@ You can access this module with:
7
9
JavaScript code can be compiled and run immediately or compiled, saved, and run later.
8
10
9
11
10
- ### vm.runInThisContext(code, [ filename] )
12
+ ## vm.runInThisContext(code, [ filename] )
11
13
12
14
` vm.runInThisContext() ` compiles ` code ` , runs it and returns the result. Running
13
15
code does not have access to local scope. ` filename ` is optional, it's used only
@@ -37,7 +39,7 @@ In case of syntax error in `code`, `vm.runInThisContext` emits the syntax error
37
39
and throws an exception.
38
40
39
41
40
- ### vm.runInNewContext(code, [ sandbox] , [ filename] )
42
+ ## vm.runInNewContext(code, [ sandbox] , [ filename] )
41
43
42
44
` vm.runInNewContext ` compiles ` code ` , then runs it in ` sandbox ` and returns the
43
45
result. Running code does not have access to local scope. The object ` sandbox `
@@ -66,7 +68,7 @@ requires a separate process.
66
68
In case of syntax error in ` code ` , ` vm.runInNewContext ` emits the syntax error to stderr
67
69
and throws an exception.
68
70
69
- ### vm.runInContext(code, context, [ filename] )
71
+ ## vm.runInContext(code, context, [ filename] )
70
72
71
73
` vm.runInContext ` compiles ` code ` , then runs it in ` context ` and returns the
72
74
result. A (V8) context comprises a global object, together with a set of
@@ -100,14 +102,14 @@ requires a separate process.
100
102
In case of syntax error in ` code ` , ` vm.runInContext ` emits the syntax error to stderr
101
103
and throws an exception.
102
104
103
- ### vm.createContext([ initSandbox] )
105
+ ## vm.createContext([ initSandbox] )
104
106
105
107
` vm.createContext ` creates a new context which is suitable for use as the 2nd argument of a subsequent
106
108
call to ` vm.runInContext ` . A (V8) context comprises a global object together with a set of
107
109
build-in objects and functions. The optional argument ` initSandbox ` will be shallow-copied
108
110
to seed the initial contents of the global object used by the context.
109
111
110
- ### vm.createScript(code, [ filename] )
112
+ ## vm.createScript(code, [ filename] )
111
113
112
114
` createScript ` compiles ` code ` but does not run it. Instead, it returns a
113
115
` vm.Script ` object representing this compiled code. This script can be run
@@ -119,6 +121,10 @@ In case of syntax error in `code`, `createScript` prints the syntax error to std
119
121
and throws an exception.
120
122
121
123
124
+ ## Class: Script
125
+
126
+ A class for running scripts. Returned by vm.createScript.
127
+
122
128
### script.runInThisContext()
123
129
124
130
Similar to ` vm.runInThisContext ` but a method of a precompiled ` Script ` object.
0 commit comments