You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`code` is the JavaScript code you want to execute.
24
24
25
25
`context` is an object of methods and properties, these methods and properties are interpreted as global objects in `code`. Be careful about the objects you are passing to the context API, because they can completely defeat the purpose of `safe-eval`.
26
26
27
+
`options` is the [options object](https://nodejs.org/api/vm.html) for the vm executing the code.
28
+
27
29
### Examples
28
30
29
-
```
31
+
```js
30
32
// string concatenation
31
33
var code ='"app" + "le"'
32
34
var evaluated =safeEval(code) // "apple"
33
35
```
34
36
35
-
```
37
+
```js
36
38
// math
37
39
var code ='Math.floor(22/7)'
38
40
var evaluated =safeEval(code) // 3.142857142857143
39
41
```
40
42
41
-
```
43
+
```js
42
44
// JSON
43
45
var code ='{name: "Borat", hobbies: ["disco dance", "sunbathing"]}'
44
46
var evaluated =safeEval(code) // {name: "Borat", hobbies: ["disco dance", "sunbathing"]}
45
47
```
46
48
47
-
```
49
+
```js
48
50
// function expression
49
51
var code ='(function square(b) { return b * b; })(5)'
50
52
var evaluated =safeEval(code) // 25
51
53
```
52
54
53
-
```
55
+
```js
54
56
// no access to Node.js objects
55
57
var code ='process'
56
58
safeEval(code) // THROWS!
57
59
```
58
60
59
-
```
61
+
```js
60
62
// your own context API - access to Node's process object and a custom function
0 commit comments