annotate tcb.js @ 5:1f38f4f61768

added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
author Atul Varma <varmaa@toolness.com>
date Fri, 19 Jun 2009 03:49:44 -0700
parents 71de19be1054
children 500e267ed094
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
1 function printTraceback(frame) {
4
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
2 print("Traceback (most recent call last):");
5
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
3 if (frame === undefined)
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
4 frame = stack();
4
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
5 var lines = [];
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
6 while (frame) {
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
7 var line = (' File "' + frame.filename + '", line ' +
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
8 frame.lineNo + ', in ' + frame.functionName);
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
9 lines.splice(0, 0, line);
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
10 frame = frame.caller;
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
11 }
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
12 print(lines.join('\n'));
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
13 }
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
14
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
15 function showInfo() {
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
16 print("Hello World.");
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
17 }
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
18
5
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
19 function throwError() {
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
20 function innerThrowError() {
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
21 throw new Error("hi");
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
22 }
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
23 innerThrowError();
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
24 }
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
25
4
71de19be1054 Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
26 showInfo();
5
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
27 try {
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
28 print("about to throw.");
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
29 throwError();
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
30 } catch (e) {
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
31 printTraceback(lastExceptionTraceback);
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
32 print(e);
1f38f4f61768 added global lastException and lastExceptionTraceback properties to the TCB global, which are similar to python's exc_info().
Atul Varma <varmaa@toolness.com>
parents: 4
diff changeset
33 }
2
1f3e9c8df4f0 Script is now read from tcb.js.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
34
1f3e9c8df4f0 Script is now read from tcb.js.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
35 var wrapped = wrap({}, {});