Mercurial > spidermonkey-playground
comparison memory_profiler_server.js @ 73:b87b6ebb6e86
Memory profiler server is now much better at reporting errors.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Thu, 25 Jun 2009 18:38:01 -0700 |
parents | a98e6a1144a9 |
children | 8cf72992387d |
comparison
equal
deleted
inserted
replaced
72:eca8642eed4a | 73:b87b6ebb6e86 |
---|---|
1 // This function is called by the platform whenever an uncaught exception | |
2 // occurs. | |
3 | |
4 function handleError() { | |
5 printTraceback(lastExceptionTraceback); | |
6 print(lastException); | |
7 } | |
8 | |
9 // This function uses the Python-inspired traceback functionality of the | |
10 // playground to print a stack trace that looks much like Python's. | |
11 | |
12 function printTraceback(frame) { | |
13 print("Traceback (most recent call last):"); | |
14 if (frame === undefined) | |
15 frame = stack(); | |
16 var lines = []; | |
17 while (frame) { | |
18 var line = (' File "' + frame.filename + '", line ' + | |
19 frame.lineNo + ', in ' + frame.functionName); | |
20 lines.splice(0, 0, line); | |
21 frame = frame.caller; | |
22 } | |
23 print(lines.join('\n')); | |
24 } | |
25 | |
1 // This is just a test to exercise the code a bit. | 26 // This is just a test to exercise the code a bit. |
2 JSON.stringify(getObjectInfo(getGCRoots()[0])); | 27 JSON.stringify(getObjectInfo(getGCRoots()[0])); |
3 | 28 |
4 var socket = new ServerSocket(); | 29 var socket = new ServerSocket(); |
5 | 30 |
56 // but Firefox doesn't let us browse a webserver this way, which is | 81 // but Firefox doesn't let us browse a webserver this way, which is |
57 // annoying, so we're just leaving it at text/plain for now. | 82 // annoying, so we're just leaving it at text/plain for now. |
58 | 83 |
59 if (path == "/") | 84 if (path == "/") |
60 toSend = HELP; | 85 toSend = HELP; |
61 | 86 |
62 if (path == "/gc-roots") | 87 if (path == "/gc-roots") |
63 toSend = JSON.stringify(getGCRoots()); | 88 toSend = JSON.stringify(getGCRoots()); |
64 | 89 |
65 if (path == "/stop") | 90 if (path == "/stop") |
66 toSend = "Stopping server now!"; | 91 toSend = "Stopping server now!"; |
67 | 92 |
68 var objNum = path.match(/^\/objects\/(\d+)$/); | 93 var objNum = path.match(/^\/objects\/(\d+)$/); |
69 if (objNum) { | 94 if (objNum) { |
95 throw new Error('wut'); | |
70 objNum = objNum[1]; | 96 objNum = objNum[1]; |
71 var objInfo = getObjectInfo(objNum); | 97 var objInfo = getObjectInfo(objNum); |
72 if (objInfo) { | 98 if (objInfo) { |
73 toSend = JSON.stringify(objInfo); | 99 toSend = JSON.stringify(objInfo); |
74 } else { | 100 } else { |
92 //print("response: " + uneval(response)); | 118 //print("response: " + uneval(response)); |
93 conn.send(response); | 119 conn.send(response); |
94 conn.close(); | 120 conn.close(); |
95 //print("response sent."); | 121 //print("response sent."); |
96 } catch (e) { | 122 } catch (e) { |
97 print(e.toString()); | 123 handleError(); |
98 try { conn.close(); } catch (e) {} | 124 try { conn.close(); } catch (e) {} |
99 } | 125 } |
100 if (path == "/stop") | 126 if (path == "/stop") |
101 return false; | 127 return false; |
102 return true; | 128 return true; |
103 } | 129 } |
104 | 130 |
105 while (processRequest(socket)) {} | 131 var keepGoing = true; |
132 | |
133 while (keepGoing) { | |
134 try { | |
135 keepGoing = processRequest(socket); | |
136 } catch (e) { | |
137 handleError(); | |
138 } | |
139 } | |
140 | |
106 socket.close(); | 141 socket.close(); |