-
Notifications
You must be signed in to change notification settings - Fork 115
/
thread.js
61 lines (42 loc) · 1.21 KB
/
thread.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* @author Niklas von Hertzen <niklas at hertzen.com>
* @created 23.7.2012
* @website http://hertzen.com
*/
function writeFile( path, obj ) {
Object.keys( obj ).forEach(function( file ) {
if ( obj[ file ] === "js" ) {
importScripts(path + file + '.js');
} else {
writeFile( path + file + "/", obj[ file ] );
}
});
}
var console = {
log: function() {}
};
self.addEventListener('message', function(e) {
switch( e.data.type ) {
case "import":
writeFile( "", e.data.content);
break;
case "run":
var vm = new PHP.VM( e.data.content[ 0 ], e.data.content[ 1 ] );
vm.Run();
self.postMessage({
type: "complete",
content: {
OUTPUT_BUFFER:vm.OUTPUT_BUFFER
}
});
break;
case "stop":
self.postMessage({
type: "unknown",
content: {
OUTPUT_BUFFER:vm.OUTPUT_BUFFER
}
});
break;
}
}, false);