self.js 808 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. DATA CHUNK
  3. CHECK
  4. */
  5. var repl = require("repl");
  6. var rrepl = repl.start({
  7. prompt: "$ "
  8. });
  9. var context = rrepl.context;
  10. // Configure what’s available in the REPL
  11. var fs = require("fs");
  12. var vm = require('vm');
  13. var $lib = {};
  14. var sandbox = { console: console, require: require, PATH: process.env.PWD, "$lib": $lib, setTimeout: setTimeout };
  15. vm.createContext(sandbox); // Contextify the sandbox.
  16. var loadfil = process.argv.pop() ;
  17. loadfil = loadfil.indexOf("self.js") >-1 ? './tta.js' : loadfil;
  18. function reload(){
  19. var code = fs.readFileSync(loadfil,"utf8");
  20. // x and y are global variables in the sandboxed environment.
  21. // Initially, x has the value 2 because that is the value of sandbox.x.
  22. vm.runInContext(code, sandbox);
  23. }
  24. context.reload = reload
  25. context.$lib = $lib;
  26. reload();