@@ -14,10 +14,16 @@ JavaScript code can be compiled and run immediately or compiled, saved, and run
14
14
later.
15
15
16
16
## Class: Script
17
+ <!-- YAML
18
+ added: v0.3.1
19
+ -->
17
20
18
21
A class for holding precompiled scripts, and running them in specific sandboxes.
19
22
20
23
### new vm.Script(code, options)
24
+ <!-- YAML
25
+ added: v0.3.1
26
+ -->
21
27
22
28
Creating a new ` Script ` compiles ` code ` but does not run it. Instead, the
23
29
created ` vm.Script ` object represents this compiled code. This script can be run
@@ -40,6 +46,9 @@ The options when creating a script are:
40
46
execution. If execution is terminated, an [ ` Error ` ] [ ] will be thrown.
41
47
42
48
### script.runInContext(contextifiedSandbox[ , options] )
49
+ <!-- YAML
50
+ added: v0.3.1
51
+ -->
43
52
44
53
Similar to [ ` vm.runInContext() ` ] [ ] but a method of a precompiled ` Script `
45
54
object. ` script.runInContext() ` runs ` script ` 's compiled code in
@@ -78,6 +87,9 @@ Note that running untrusted code is a tricky business requiring great care.
78
87
requires a separate process.
79
88
80
89
### script.runInNewContext([ sandbox] [ , options ] )
90
+ <!-- YAML
91
+ added: v0.3.1
92
+ -->
81
93
82
94
Similar to [ ` vm.runInNewContext() ` ] [ ] but a method of a precompiled ` Script `
83
95
object. ` script.runInNewContext() ` contextifies ` sandbox ` if passed or creates a
@@ -114,6 +126,9 @@ Note that running untrusted code is a tricky business requiring great care.
114
126
requires a separate process.
115
127
116
128
### script.runInThisContext([ options] )
129
+ <!-- YAML
130
+ added: v0.3.1
131
+ -->
117
132
118
133
Similar to [ ` vm.runInThisContext() ` ] ( ) but a method of a precompiled ` Script `
119
134
object. ` script.runInThisContext() ` runs ` script ` 's compiled code and returns
@@ -155,6 +170,9 @@ The options for running a script are:
155
170
execution. If execution is terminated, an [ ` Error ` ] [ ] will be thrown.
156
171
157
172
## vm.createContext([ sandbox] )
173
+ <!-- YAML
174
+ added: v0.3.1
175
+ -->
158
176
159
177
If given a ` sandbox ` object, will "contextify" that sandbox so that it can be
160
178
used in calls to [ ` vm.runInContext() ` ] [ ] or [ ` script.runInContext() ` ] [ ] . Inside
@@ -172,6 +190,9 @@ single sandbox representing a window's global object, then run all `<script>`
172
190
tags together inside that sandbox.
173
191
174
192
## vm.isContext(sandbox)
193
+ <!-- YAML
194
+ added: v0.11.7
195
+ -->
175
196
176
197
Returns whether or not a sandbox object has been contextified by calling
177
198
[ ` vm.createContext() ` ] [ ] on it.
@@ -207,6 +228,9 @@ Note that running untrusted code is a tricky business requiring great care.
207
228
a separate process.
208
229
209
230
## vm.runInDebugContext(code)
231
+ <!-- YAML
232
+ added: v0.11.14
233
+ -->
210
234
211
235
` vm.runInDebugContext() ` compiles and executes ` code ` inside the V8 debug
212
236
context. The primary use case is to get access to the V8 debug object:
@@ -224,6 +248,9 @@ implementation and may change (or even get removed) without prior warning.
224
248
The debug object can also be exposed with the ` --expose_debug_as= ` switch.
225
249
226
250
## vm.runInNewContext(code[ , sandbox] [ , options ] )
251
+ <!-- YAML
252
+ added: v0.3.1
253
+ -->
227
254
228
255
` vm.runInNewContext() ` compiles ` code ` , contextifies ` sandbox ` if passed or
229
256
creates a new contextified sandbox if it's omitted, and then runs the code with
@@ -254,6 +281,9 @@ Note that running untrusted code is a tricky business requiring great care.
254
281
a separate process.
255
282
256
283
## vm.runInThisContext(code[ , options] )
284
+ <!-- YAML
285
+ added: v0.3.1
286
+ -->
257
287
258
288
` vm.runInThisContext() ` compiles ` code ` , runs it and returns the result. Running
259
289
code does not have access to local scope, but does have access to the current
0 commit comments