export default class JSInterpreter { read ( filename ) { } async run ( code ) { try { return this . runSync ( code ) ; } catch ( e ) { throw e ; } } runSync ( code ) { const disableVars = [ "window" , "print" , "document" ] ; const func = new Function ( "console" , ... disableVars , code ) ; const output = [ ] ; const fakeConsole = new FakeConsole ( output ) ; func ( fakeConsole , ... new Array ( disableVars . length ) ) ; return output ; } } class FakeConsole { output : string [ ] ; constructor ( output ) { this . output = output ; } log ( ... args ) { this . output . push ( args . map ( _ => { if ( typeof _ === "undefined" ) return _ ; return `${ _ }` ; } ) . join ( " " ) + "\n" ) ; } }