-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebug.html
More file actions
150 lines (137 loc) · 4.74 KB
/
Copy pathdebug.html
File metadata and controls
150 lines (137 loc) · 4.74 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<body>
<div style="position:absolute; left:0px; top:0px; right:0px; bottom:0px">
<input type="button" value="Step" id="step" style="position:absolute; left:8px; top:8px; width:80px; height:30px"/>
<input type="button" value="Continue" id="continue" style="position:absolute; left:96px; top:8px; width:80px; height:30px"/>
<select id="stack" style="position:absolute; left:184px; top:8px; right:8px; height:30px"></select>
<div id="src" style="position:absolute; left:8px; top:46px; right:8px; bottom:8px; border:solid 1px #000; white-space:pre; font-family:monospace; font-size:12px;">
</div>
</div>
<script>
var parent = window.dialogArguments[0];
var stack = window.dialogArguments[1];
var st = document.getElementById("stack");
var sources = parent.debug_sources || (parent.debug_sources = {});
var current_source = null;
var src = document.getElementById("src");
var step = document.getElementById("step");
var cont = document.getElementById("continue");
var chspan = document.createElement("span");
chspan.textContent = "XXXXXXXXXX";
src.appendChild(chspan);
var chw = chspan.offsetWidth / 10;
src.removeChild(chspan);
for (var i=stack.length-1; i>=0; i--)
{
var x = document.createElement("option");
x.value = i;
x.textContent = stack[i];
st.appendChild(x);
}
function linecol(text, pos)
{
var x = text.slice(0, pos).split("\n");
return {line: x.length-1,
col: x[x.length-1].length};
}
function source(name)
{
if (!sources[name])
{
var req = new XMLHttpRequest();
req.open("GET", name, false);
req.send(null);
var src = req.responseText;
var lines = src.split("\n");
var container = document.createElement("div");
container.style.position = "absolute";
container.style.left = "0px";
container.style.right = "0px";
container.style.top = "0px";
container.style.bottom = "0px";
container.style.overflow = "auto";
for (var i=0; i<lines.length; i++)
{
var L = document.createElement("div");
L.style.position = "relative";
L.style.minHeight = "1em";
L.textContent = lines[i];
var sel = document.createElement("div");
sel.style.position = "absolute";
sel.style.left = "0px";
sel.style.width = "0px";
sel.style.top = "0px";
sel.style.bottom = "0px";
sel.style.backgroundColor = "rgba(0, 255, 0, 0.25)";
L.appendChild(sel);
container.appendChild(L);
lines[i] = L;
}
sources[name] = {src: src, lines: lines, container: container};
}
return sources[name];
}
function select(location)
{
var s = source(location[0]);
var lines = s.lines;
if (current_source != location[0])
{
while (src.firstChild)
src.removeChild(src.firstChild);
current_source = location[0];
src.appendChild(s.container);
}
var LC0 = linecol(s.src, location[1]);
var LC1 = linecol(s.src, location[2]);
for (var i=0; i<lines.length; i++)
{
if (i < LC0.line || i > LC1.line)
{
lines[i].lastChild.style.width = "0px";
lines[i].lastChild.style.right = null;
}
else if (i == LC0.line && i == LC1.line)
{
lines[i].lastChild.style.left = chw*LC0.col + "px";
lines[i].lastChild.style.right = null;
lines[i].lastChild.style.width = chw*(LC1.col - LC0.col) + "px";
}
else if (i == LC0.line)
{
lines[i].lastChild.style.left = chw*LC0.col + "px";
lines[i].lastChild.style.width = null;
lines[i].lastChild.style.right = "0px";
}
else if (i == LC1.line)
{
lines[i].lastChild.style.left = "0px";
lines[i].lastChild.style.right = null;
lines[i].lastChild.style.width = chw*LC1.col + "px";
}
else
{
lines[i].lastChild.style.left = "0px";
lines[i].lastChild.style.width = null;
lines[i].lastChild.style.right = "0px";
}
}
s.container.scrollTop = Math.max(0, lines[LC0.line].offsetTop - s.container.offsetHeight/2);
}
select(stack[stack.length-1]);
function bye(x)
{
window.returnValue = x;
parent.debug_screenLeft = window.screenLeft;
parent.debug_screenTop = window.screenTop;
parent.debug_screenWidth = window.innerWidht;
parent.debug_screenHeight = window.innerHeight;
window.close();
}
step.onclick = function() { bye("step"); };
cont.onclick = function() { bye("cont"); };
st.onchange = function() { select(stack[st.options[st.selectedIndex].value]); }
</script>
</body>
</html>