-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang2.html
104 lines (86 loc) · 2.73 KB
/
lang2.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!doctype html>
<title>Interpreter 2</title>
<script src="../build/libv86.js"></script>
<script>
"use strict";
window.onload = function()
{
var start = Date.now();
document.getElementById("status").textContent = "Loading ...";
setInterval(function()
{
document.getElementById("time").textContent = Math.round((Date.now() - start) / 1000);
}, 999);
if(location.host === "localhost")
{
var urlbase = "http://localhost/v86-images/";
}
else
{
var urlbase = "http://104.131.53.7:8086/";
}
var emulator = new V86Starter({
memory_size: 128 * 1024 * 1024,
vga_memory_size: 8 * 1024 * 1024,
screen_container: document.getElementById("screen_container"),
bios: {
url: "../bios/seabios.bin",
},
vga_bios: {
url: "../bios/vgabios.bin",
},
hda: {
url: urlbase + "arch3.img",
size: 8 * 1024 * 1024 * 1024,
async: true,
},
initial_state: {
url: urlbase + "v86state-node.bin",
},
filesystem: {
baseurl: urlbase + "arch/",
basefs: urlbase + "fs.json",
},
autostart: true,
});
window.emulator = emulator;
emulator.add_listener("emulator-ready", function()
{
document.getElementById("status").textContent = "Running code ...";
var code = "var fs = require('fs');\n" +
"module.exports = function() {\n" +
" fs.writeFileSync('/root/out.txt', 'The result is: ' + 2 * 3 * 4 * 5 * 6 * 7 * 8);\n" +
"}\n";
var buffer = new Uint8Array(code.length);
buffer.set(code.split("").map(function(chr) { return chr.charCodeAt(0); }));
emulator.create_file("/root/code.js", buffer, function(error)
{
if(error) throw error;
emulator.serial0_send('require("/root/code.js")()\n\n');
});
});
var interval = setInterval(function()
{
emulator.read_file("/root/out.txt", function(error, data)
{
if(error || !data)
{
return;
}
document.getElementById("status").textContent = "Done!";
document.getElementById("output").textContent = String.fromCharCode.apply(this, data);
clearInterval(interval);
});
}, 500);
}
</script>
<pre><span id=time>0</span>s -- <span id=status></span></pre>
<hr>
<pre id=output>
</pre>
<hr>
<!-- A minimal structure for the ScreenAdapter defined in browser/screen.js -->
<div id="screen_container">
<div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
<canvas style="display: none"></canvas>
</div>