Mercurial > spidermonkey-playground
annotate tcb.js @ 12:e14f433f3a58
Function objects are now attached to stack frames returned by stack().
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 19 Jun 2009 15:16:11 -0700 |
parents | bde6607a3620 |
children | d200a8158bd5 |
rev | line source |
---|---|
10
16a605ff036c
The TCB can now define a global checkAccess() handler. It also has access to a lookupProperty() function that can retrieve an attribute of an object without initiating security checks or property getters.
Atul Varma <varmaa@toolness.com>
parents:
8
diff
changeset
|
1 // This security function is called by the platform whenever a |
16a605ff036c
The TCB can now define a global checkAccess() handler. It also has access to a lookupProperty() function that can retrieve an attribute of an object without initiating security checks or property getters.
Atul Varma <varmaa@toolness.com>
parents:
8
diff
changeset
|
2 // particular property needs to be accessed on a particular object. |
16a605ff036c
The TCB can now define a global checkAccess() handler. It also has access to a lookupProperty() function that can retrieve an attribute of an object without initiating security checks or property getters.
Atul Varma <varmaa@toolness.com>
parents:
8
diff
changeset
|
3 function checkAccess(obj, id) { |
11
bde6607a3620
changed TCB/sample module code a bit.
Atul Varma <varmaa@toolness.com>
parents:
10
diff
changeset
|
4 var frame = stack().caller; |
bde6607a3620
changed TCB/sample module code a bit.
Atul Varma <varmaa@toolness.com>
parents:
10
diff
changeset
|
5 if (!(frame.filename == null || |
bde6607a3620
changed TCB/sample module code a bit.
Atul Varma <varmaa@toolness.com>
parents:
10
diff
changeset
|
6 frame.filename == "tcb.js")) |
bde6607a3620
changed TCB/sample module code a bit.
Atul Varma <varmaa@toolness.com>
parents:
10
diff
changeset
|
7 print("access request from " + frame.filename + " on property '" + id + |
bde6607a3620
changed TCB/sample module code a bit.
Atul Varma <varmaa@toolness.com>
parents:
10
diff
changeset
|
8 "' of " + obj); |
12
e14f433f3a58
Function objects are now attached to stack frames returned by stack().
Atul Varma <varmaa@toolness.com>
parents:
11
diff
changeset
|
9 if (id == 'caller') { |
e14f433f3a58
Function objects are now attached to stack frames returned by stack().
Atul Varma <varmaa@toolness.com>
parents:
11
diff
changeset
|
10 if (frame.caller) |
e14f433f3a58
Function objects are now attached to stack frames returned by stack().
Atul Varma <varmaa@toolness.com>
parents:
11
diff
changeset
|
11 return frame.caller.functionObject; |
e14f433f3a58
Function objects are now attached to stack frames returned by stack().
Atul Varma <varmaa@toolness.com>
parents:
11
diff
changeset
|
12 else |
e14f433f3a58
Function objects are now attached to stack frames returned by stack().
Atul Varma <varmaa@toolness.com>
parents:
11
diff
changeset
|
13 return null; |
e14f433f3a58
Function objects are now attached to stack frames returned by stack().
Atul Varma <varmaa@toolness.com>
parents:
11
diff
changeset
|
14 } |
10
16a605ff036c
The TCB can now define a global checkAccess() handler. It also has access to a lookupProperty() function that can retrieve an attribute of an object without initiating security checks or property getters.
Atul Varma <varmaa@toolness.com>
parents:
8
diff
changeset
|
15 return lookupProperty(obj, id); |
16a605ff036c
The TCB can now define a global checkAccess() handler. It also has access to a lookupProperty() function that can retrieve an attribute of an object without initiating security checks or property getters.
Atul Varma <varmaa@toolness.com>
parents:
8
diff
changeset
|
16 } |
16a605ff036c
The TCB can now define a global checkAccess() handler. It also has access to a lookupProperty() function that can retrieve an attribute of an object without initiating security checks or property getters.
Atul Varma <varmaa@toolness.com>
parents:
8
diff
changeset
|
17 |
8
e14f496e6e08
added a handleError() function to the TCB, which is called whenever an unhandled exception occurs. Also fixed a bug in the setting of lastException.
Atul Varma <varmaa@toolness.com>
parents:
7
diff
changeset
|
18 // This function is called by the platform whenever an uncaught exception |
e14f496e6e08
added a handleError() function to the TCB, which is called whenever an unhandled exception occurs. Also fixed a bug in the setting of lastException.
Atul Varma <varmaa@toolness.com>
parents:
7
diff
changeset
|
19 // occurs. |
e14f496e6e08
added a handleError() function to the TCB, which is called whenever an unhandled exception occurs. Also fixed a bug in the setting of lastException.
Atul Varma <varmaa@toolness.com>
parents:
7
diff
changeset
|
20 function handleError() { |
e14f496e6e08
added a handleError() function to the TCB, which is called whenever an unhandled exception occurs. Also fixed a bug in the setting of lastException.
Atul Varma <varmaa@toolness.com>
parents:
7
diff
changeset
|
21 printTraceback(lastExceptionTraceback); |
e14f496e6e08
added a handleError() function to the TCB, which is called whenever an unhandled exception occurs. Also fixed a bug in the setting of lastException.
Atul Varma <varmaa@toolness.com>
parents:
7
diff
changeset
|
22 print(lastException); |
e14f496e6e08
added a handleError() function to the TCB, which is called whenever an unhandled exception occurs. Also fixed a bug in the setting of lastException.
Atul Varma <varmaa@toolness.com>
parents:
7
diff
changeset
|
23 } |
e14f496e6e08
added a handleError() function to the TCB, which is called whenever an unhandled exception occurs. Also fixed a bug in the setting of lastException.
Atul Varma <varmaa@toolness.com>
parents:
7
diff
changeset
|
24 |
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
|
25 function printTraceback(frame) { |
4
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
26 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
|
27 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
|
28 frame = stack(); |
4
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
29 var lines = []; |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
30 while (frame) { |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
31 var line = (' File "' + frame.filename + '", line ' + |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
32 frame.lineNo + ', in ' + frame.functionName); |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
33 lines.splice(0, 0, line); |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
34 frame = frame.caller; |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
35 } |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
36 print(lines.join('\n')); |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
37 } |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
38 |
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
|
39 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
|
40 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
|
41 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
|
42 } |
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
|
43 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
|
44 } |
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
|
45 |
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
|
46 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
|
47 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
|
48 } 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
|
49 } |
2
1f3e9c8df4f0
Script is now read from tcb.js.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
50 |
7
1b374020485b
Added more code to sample securableModule
Atul Varma <varmaa@toolness.com>
parents:
6
diff
changeset
|
51 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
|
52 |
500e267ed094
Added a really simple securableModule require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
53 print("module.foo() is " + module.foo()); |
500e267ed094
Added a really simple securableModule require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
54 |
2
1f3e9c8df4f0
Script is now read from tcb.js.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
55 var wrapped = wrap({}, {}); |