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
A very tiny JS-like script interpreter implemented throw JS.
4
+
5
+
Less than 10KB (gziped)
6
+
7
+
The primary purpose of TrashScript is to execute scripts in environments where ```eval``` and ```new Function``` are restricted, such as in browser extensions.
8
+
9
+
TrashScript was originally designed for modules in the
10
+
"[filecxx browser extension](https://github.com/filecxx/FileCentipede)" such as "Third-Party Query Interfaces," which can run custom scripts.
11
+
12
+
While not all JavaScript syntax has been implemented, the majority of commonly used syntax is available.
13
+
14
+
###Keywords: How to allow eval in chrome extension
15
+
16
+
17
+
##Usage examples:
18
+
19
+
###Config
20
+
```
21
+
TrashScript.config = {
22
+
max_exec_limit:1000000 //default
23
+
}
24
+
```
25
+
26
+
###Basic
27
+
```
28
+
var executor = TrashScript("Source code",function(e)
29
+
{
30
+
if(e.status === "error"){
31
+
console.log(e);
32
+
}else if(e.status === "complete"){
33
+
console.log(e.result);
34
+
}
35
+
});
36
+
executor.exec();
37
+
```
38
+
39
+
###Bind existing JavaScript functions or objects
40
+
```
41
+
TrashScript.bind("alert",function(arg){
42
+
window.alert(arg);
43
+
});
44
+
```
45
+
```
46
+
TrashScript.bind({
47
+
console:console,
48
+
test:function(){},
49
+
print:console.log,
50
+
alert:alert,
51
+
JSON:JSON
52
+
});
53
+
```
54
+
55
+
###Context object for 'this'
56
+
```
57
+
var executor = TrashScript("function aaa(){alert(this)};return aaa()",function(e){...});
58
+
executor.exec(window); //'this' is window
59
+
```
60
+
```
61
+
var executor = TrashScript("function aaa(){alert(this)};return aaa()",function(e){...});
0 commit comments