Menu

[r4]: / trunk / JavaScript / Debugger / ContextInspector.cs  Maximize  Restore  History

Download this file

207 lines (193 with data), 5.0 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace JavaScript.Debugger
{
public partial class ContextInspector : Form
{
protected DebugWindow m_debugger;
protected Stack<StackFrame> m_frames;
protected TreeNode[] m_roots;
public ContextInspector(DebugWindow debugger, Stack<StackFrame> frames)
{
InitializeComponent();
m_debugger = debugger;
m_frames = frames;
Rebuild();
treeContexts.ExpandAll();
ListStackFrameProps(m_frames.Peek());
}
public void DebuggerStepped()
{
object selected = (treeContexts.SelectedNode == null)? null : treeContexts.SelectedNode.Tag;
bool redisplay = false;
// the debugger has stepped, so check for changes
if (m_roots.Length != m_frames.Count)
{
// a stack frame has been entered
treeContexts.Nodes.Clear();
Rebuild();
redisplay = true;
}
StackFrame[] sframes = m_frames.ToArray();
for (int x = 0; x < m_roots.Length; x++)
{
if (m_roots[x].Nodes.Count != sframes[x].Context.Count)
{
treeContexts.Nodes.Clear();
Rebuild();
redisplay = true;
break;
}
else
{
// properties
for (int y = 0; y < m_roots[x].Nodes.Count; y++)
{
if (m_roots[x].Nodes[y].Nodes.Count != sframes[x].Context[y].Properties.Count)
{
treeContexts.Nodes.Clear();
Rebuild();
redisplay = true;
break;
}
}
}
}
if (redisplay)
{
//treeContexts.ExpandAll();
for (int x = 0; x < treeContexts.Nodes.Count; x++)
{
if (treeContexts.Nodes[x].Tag == selected)
{
treeContexts.SelectedNode = treeContexts.Nodes[x];
break;
}
}
lstProps.Items.Clear();
if (selected is StackFrame)
{
ListStackFrameProps((StackFrame)selected);
}
else if (selected is JsObject)
{
ListContextProps((JsObject)selected);
}
else if (selected is LValue)
{
ListLValProps((LValue)selected);
}
}
}
private void Rebuild()
{
StackFrame[] sframes = m_frames.ToArray();
m_roots = new TreeNode[sframes.Length];
for (int x = 0; x < m_roots.Length; x++)
{
TreeNode node = new TreeNode(sframes[x].ToString(), ContextObjects(sframes[x]));
m_roots[x] = node;
node.Tag = sframes[x];
treeContexts.Nodes.Add(node);
}
}
private TreeNode[] ContextObjects(StackFrame frame)
{
List<TreeNode> nodes = new List<TreeNode>();
ArrayListStack<JsObject> ctx = frame.Context;
for (int x = ctx.Count-1; x > -1; x--)
{
TreeNode node = new TreeNode(ctx[x].TypeName, ContextObjectProperties(ctx[x]));
node.Tag = ctx[x];
nodes.Add(node);
}
return nodes.ToArray();
}
private TreeNode[] ContextObjectProperties(JsObject ctxo)
{
List<LValue> props = ctxo.Properties;
List<TreeNode> nodes = new List<TreeNode>();
foreach (LValue lv in props)
{
TreeNode node = new TreeNode(lv.Name + "=" + lv.Get().Name);
node.Tag = lv;
nodes.Add(node);
}
return nodes.ToArray();
}
private void ListStackFrameProps(StackFrame frame)
{
if (frame.Stack.Count == 0)
{
lstProps.Items.Add("<<STACK EMPTY>>");
return;
}
object[] stk = frame.Stack.ToArray();
for (int x = 0; x < stk.Length; x++)
{
if (stk[x] is LValue)
{
lstProps.Items.Add( stk[x].ToString() );
}
else if (stk[x] is JsObject)
{
lstProps.Items.Add(stk[x].ToString());
}
}
}
private void ListContextProps(JsObject ctx)
{
List<LValue> props = ctx.Properties;
for (int x = 0; x < props.Count; x++)
{
lstProps.Items.Add(props[x].Name + "=" + props[x].Get().ToString());
}
}
private void ListLValProps(LValue lv)
{
List<LValue> props = lv.Get().Properties;
for (int x = 0; x < props.Count; x++)
{
lstProps.Items.Add(props[x].Name + "=" + props[x].Get().ToString());
}
if (lv.Get() is TypeArray)
{
TypeArray arr = (TypeArray)lv.Get();
string[] keys = arr.Keys;
for (int x = 0; x < keys.Length; x++)
{
lstProps.Items.Add(keys[x] + "=" + arr.GetProperty(keys[x]).ToString());
}
}
}
private void treeContexts_AfterSelect(object sender, TreeViewEventArgs e)
{
lstProps.Items.Clear();
if (e.Node.Tag is StackFrame)
{
// stack frame
ListStackFrameProps((StackFrame)e.Node.Tag);
}
else if (e.Node.Tag is JsObject)
{
// context
ListContextProps((JsObject)e.Node.Tag);
}
else if (e.Node.Tag is LValue)
{
// property
ListLValProps((LValue)e.Node.Tag);
}
}
private void ContextInspector_KeyDown(object sender, KeyEventArgs e)
{
m_debugger.DebugWindow_KeyDown(sender, e);
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.