Mercurial > spidermonkey-playground
annotate tcb.js @ 11:bde6607a3620
changed TCB/sample module code a bit.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 19 Jun 2009 15:07:12 -0700 |
parents | 16a605ff036c |
children | e14f433f3a58 |
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); |
bde6607a3620
changed TCB/sample module code a bit.
Atul Varma <varmaa@toolness.com>
parents:
10
diff
changeset
|
9 // TODO: this won't work for the 'caller' property, looks like we need |
bde6607a3620
changed TCB/sample module code a bit.
Atul Varma <varmaa@toolness.com>
parents:
10
diff
changeset
|
10 // to look it up ourselves. |
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
|
11 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
|
12 } |
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
|
13 |
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
|
14 // 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
|
15 // 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
|
16 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
|
17 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
|
18 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
|
19 } |
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 |
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
|
21 function printTraceback(frame) { |
4
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
22 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
|
23 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
|
24 frame = stack(); |
4
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
25 var lines = []; |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
26 while (frame) { |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
27 var line = (' File "' + frame.filename + '", line ' + |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
28 frame.lineNo + ', in ' + frame.functionName); |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
29 lines.splice(0, 0, line); |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
30 frame = frame.caller; |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
31 } |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
32 print(lines.join('\n')); |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
33 } |
71de19be1054
Added a native stack() function.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
34 |
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
|
35 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
|
36 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
|
37 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
|
38 } |
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 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
|
40 } |
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 |
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 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
|
43 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
|
44 } 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
|
45 } |
2
1f3e9c8df4f0
Script is now read from tcb.js.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
46 |
7
1b374020485b
Added more code to sample securableModule
Atul Varma <varmaa@toolness.com>
parents:
6
diff
changeset
|
47 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
|
48 |
500e267ed094
Added a really simple securableModule require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
49 print("module.foo() is " + module.foo()); |
500e267ed094
Added a really simple securableModule require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
50 |
2
1f3e9c8df4f0
Script is now read from tcb.js.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
51 var wrapped = wrap({}, {}); |