Mercurial > spidermonkey-playground
annotate tcb.js @ 7:1b374020485b
Added more code to sample securableModule
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 19 Jun 2009 09:34:09 -0700 |
parents | 500e267ed094 |
children | e14f496e6e08 |
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 |
7
1b374020485b
Added more code to sample securableModule
Atul Varma <varmaa@toolness.com>
parents:
6
diff
changeset
|
35 var module = require("sample-module.js", {blop: "hello"}); |
6
500e267ed094
Added a really simple securableModule require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
36 |
500e267ed094
Added a really simple securableModule require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
37 print("module.foo() is " + module.foo()); |
500e267ed094
Added a really simple securableModule require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
38 |
2
1f3e9c8df4f0
Script is now read from tcb.js.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
39 var wrapped = wrap({}, {}); |