@@ -34,8 +34,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3434var USE_DOCKER_SANDBOX = false ;
3535
3636var assert = require ( 'assert' ) ;
37+ var child_process = require ( 'child_process' ) ;
3738var express = require ( 'express' ) ;
3839var serveStatic = require ( 'serve-static' ) ;
40+
41+
3942var app = express ( ) ;
4043
4144app . use ( serveStatic ( 'static/' ) ) ; // put all static files in here
@@ -44,10 +47,69 @@ app.get('/exec_py2', function(req, res) {
4447 if ( USE_DOCKER_SANDBOX ) {
4548 assert ( false ) ;
4649 } else {
47- res . send ( 'Hello World!' ) ;
50+ executePython ( 'python' , req , res ) ;
51+ }
52+ } ) ;
53+
54+ app . get ( '/exec_py3' , function ( req , res ) {
55+ if ( USE_DOCKER_SANDBOX ) {
56+ assert ( false ) ;
57+ } else {
58+ executePython ( 'python3' , req , res ) ;
59+ }
60+ } ) ;
61+
62+ app . get ( '/exec_js' , function ( req , res ) {
63+ if ( USE_DOCKER_SANDBOX ) {
64+ assert ( false ) ;
65+ } else {
66+ var usrCod = req . query . user_script ;
67+ var args = [ '--expose-debug-as=Debug' ,
68+ 'backends/javascript/jslogger.js' ,
69+ '--jsondump=true' ,
70+ '--code=' + usrCod ] ;
71+
72+ var child = child_process . spawn ( 'node' , args ) ;
73+ var stdoutDat = '' ;
74+ child . stdout . on ( 'data' , function ( data ) {
75+ stdoutDat += data ;
76+ } ) ;
77+ child . on ( 'close' , function ( code ) {
78+ res . send ( String ( stdoutDat ) ) ;
79+ } ) ;
4880 }
4981} ) ;
5082
83+ function executePython ( pythonExe , req , res ) {
84+ var parsedOptions = JSON . parse ( req . query . options_json ) ;
85+
86+ var usrCod = req . query . user_script ;
87+ var usrInputJson = req . query . raw_input_json ;
88+ var cumulativeMode = parsedOptions . cumulative_mode ;
89+ var heapPrimitives = parsedOptions . heap_primitives ;
90+
91+ var args = [ 'backends/python/generate_json_trace.py' ] ;
92+ if ( cumulativeMode ) {
93+ args . push ( '-c' ) ;
94+ }
95+ if ( heapPrimitives ) {
96+ args . push ( '-p' ) ;
97+ }
98+ if ( usrInputJson ) {
99+ args . push ( '--input=' + usrInputJson ) ;
100+ }
101+ args . push ( '--code=' + usrCod ) ;
102+
103+ var child = child_process . spawn ( pythonExe , args ) ;
104+ var stdoutDat = '' ;
105+ child . stdout . on ( 'data' , function ( data ) {
106+ stdoutDat += data ;
107+ } ) ;
108+ child . on ( 'close' , function ( code ) {
109+ res . send ( String ( stdoutDat ) ) ;
110+ } ) ;
111+ }
112+
51113var server = app . listen ( 3000 , function ( ) {
52114 var host = server . address ( ) . address ;
53115 var port = server . address ( ) . port ;
0 commit comments