diff tcb.js @ 24:777839fbafeb

Added some documentation to the TCB.
author Atul Varma <varmaa@toolness.com>
date Mon, 22 Jun 2009 08:56:31 -0700
parents cd5faa0bb46c
children 69622f55fcf6
line wrap: on
line diff
--- a/tcb.js	Mon Jun 22 08:52:17 2009 -0700
+++ b/tcb.js	Mon Jun 22 08:56:31 2009 -0700
@@ -1,5 +1,11 @@
+// This script represents the Trusted Code Base (TCB) of the
+// playground; it alone has access to all privileged functionality and
+// can load SecurableModules as needed, exporting capabilities to them
+// as necessary.
+
 // This security function is called by the platform whenever a
 // particular property needs to be accessed on a particular object.
+
 function checkAccess(obj, id) {
   var frame = stack().caller;
   var isSuspicious = false;
@@ -24,11 +30,15 @@
 
 // This function is called by the platform whenever an uncaught exception
 // occurs.
+
 function handleError() {
   printTraceback(lastExceptionTraceback);
   print(lastException);
 }
 
+// This function uses the Python-inspired traceback functionality of the
+// playground to print a stack trace that looks much like Python's.
+
 function printTraceback(frame) {
   print("Traceback (most recent call last):");
   if (frame === undefined)
@@ -43,6 +53,9 @@
   print(lines.join('\n'));
 }
 
+// An example of some of the Python-inspired traceback functionality of
+// the playground.
+
 function throwError() {
   function innerThrowError() {
     var x = 1;
@@ -60,12 +73,16 @@
     print("  " + name + ": " + scopeChain[name]);
 }
 
+// Load a sample SecurableModule and run some code in it.
+
 var module = require("sample-module.js", {blop: "hello", print: print});
 
 (function() {
    print("module.foo() is " + module.foo());
    })();
 
+// Some unit tests.
+
 var wrapper = {};
 var wrappee = {};
 var wrapped = wrap(wrappee, wrapper);